mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +00:00
Further work-arounds for floating reference handling changes between 1.12 and 1.14
This fixes various memory-safety issues caused by broken reference counting. We have to handle pre-1.14 and post-1.14 differently in constructors. See https://bugzilla.gnome.org/show_bug.cgi?id=743062#c30
This commit is contained in:
parent
2cefd9aea6
commit
c31921e093
14 changed files with 174 additions and 62 deletions
18
Gir_Gst.toml
18
Gir_Gst.toml
|
@ -440,6 +440,11 @@ status = "generate"
|
|||
[[object]]
|
||||
name = "Gst.DeviceMonitor"
|
||||
status = "generate"
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "get_bus"
|
||||
[object.function.return]
|
||||
|
@ -709,11 +714,19 @@ status = "generate"
|
|||
name = "Gst.Stream"
|
||||
status = "generate"
|
||||
trait = false
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||
ignore = true
|
||||
|
||||
[[object]]
|
||||
name = "Gst.StreamCollection"
|
||||
status = "generate"
|
||||
trait = false
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||
ignore = true
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Plugin"
|
||||
|
@ -833,6 +846,11 @@ status = "generate"
|
|||
# Takes ownership
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "set_active"
|
||||
[object.function.return]
|
||||
|
|
|
@ -65,3 +65,8 @@ trait = false
|
|||
name = "GstNet.NetTimeProvider"
|
||||
status = "generate"
|
||||
trait = false
|
||||
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
# Floating reference handling
|
||||
ignore = true
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use ffi;
|
||||
use glib::StaticType;
|
||||
use glib::Value;
|
||||
use glib::object::IsA;
|
||||
use glib::signal::SignalHandlerId;
|
||||
use glib::signal::connect;
|
||||
use glib::translate::*;
|
||||
|
@ -29,15 +28,6 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl NetTimeProvider {
|
||||
pub fn new<'a, P: IsA<gst::Clock>, Q: Into<Option<&'a str>>>(clock: &P, address: Q, port: i32) -> NetTimeProvider {
|
||||
assert_initialized_main_thread!();
|
||||
let address = address.into();
|
||||
let address = address.to_glib_none();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_net_time_provider_new(clock.to_glib_none().0, address.0, port))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_property_active(&self) -> bool {
|
||||
unsafe {
|
||||
let mut value = Value::from_type(<bool as StaticType>::static_type());
|
||||
|
|
|
@ -38,6 +38,7 @@ pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue
|
|||
mod auto;
|
||||
pub use auto::*;
|
||||
mod net_client_clock;
|
||||
mod net_time_provider;
|
||||
mod ntp_clock;
|
||||
mod ptp_clock;
|
||||
|
||||
|
|
34
gstreamer-net/src/net_time_provider.rs
Normal file
34
gstreamer-net/src/net_time_provider.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use ffi;
|
||||
use NetTimeProvider;
|
||||
|
||||
use glib::IsA;
|
||||
use glib::translate::*;
|
||||
use gst;
|
||||
|
||||
impl NetTimeProvider {
|
||||
pub fn new<'a, P: IsA<gst::Clock>, Q: Into<Option<&'a str>>>(clock: &P, address: Q, port: i32) -> NetTimeProvider {
|
||||
assert_initialized_main_thread!();
|
||||
let address = address.into();
|
||||
let address = address.to_glib_none();
|
||||
|
||||
let (major, minor, _, _) = gst::version();
|
||||
if (major, minor) > (1, 12) {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_net_time_provider_new(clock.to_glib_none().0, address.0, port))
|
||||
}
|
||||
} else {
|
||||
// Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_net_time_provider_new(clock.to_glib_none().0, address.0, port))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,21 +20,6 @@ glib_wrapper! {
|
|||
}
|
||||
}
|
||||
|
||||
impl BufferPool {
|
||||
pub fn new() -> BufferPool {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_buffer_pool_new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BufferPool {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for BufferPool {}
|
||||
unsafe impl Sync for BufferPool {}
|
||||
|
||||
|
|
|
@ -30,21 +30,6 @@ glib_wrapper! {
|
|||
}
|
||||
}
|
||||
|
||||
impl DeviceMonitor {
|
||||
pub fn new() -> DeviceMonitor {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_device_monitor_new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DeviceMonitor {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for DeviceMonitor {}
|
||||
unsafe impl Sync for DeviceMonitor {}
|
||||
|
||||
|
|
|
@ -29,18 +29,6 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl Stream {
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(stream_id: P, caps: Q, type_: StreamType, flags: StreamFlags) -> Stream {
|
||||
assert_initialized_main_thread!();
|
||||
let stream_id = stream_id.into();
|
||||
let stream_id = stream_id.to_glib_none();
|
||||
let caps = caps.into();
|
||||
let caps = caps.to_glib_none();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_stream_new(stream_id.0, caps.0, type_.to_glib(), flags.to_glib()))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub fn get_caps(&self) -> Option<Caps> {
|
||||
unsafe {
|
||||
|
|
|
@ -27,16 +27,6 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl StreamCollection {
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub fn new<'a, P: Into<Option<&'a str>>>(upstream_id: P) -> StreamCollection {
|
||||
assert_initialized_main_thread!();
|
||||
let upstream_id = upstream_id.into();
|
||||
let upstream_id = upstream_id.to_glib_none();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_stream_collection_new(upstream_id.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub fn add_stream(&self, stream: &Stream) -> bool {
|
||||
unsafe {
|
||||
|
|
|
@ -205,6 +205,29 @@ impl PartialEq for BufferPoolAcquireParams {
|
|||
|
||||
impl Eq for BufferPoolAcquireParams {}
|
||||
|
||||
impl BufferPool {
|
||||
pub fn new() -> BufferPool {
|
||||
assert_initialized_main_thread!();
|
||||
let (major, minor, _, _) = ::version();
|
||||
if (major, minor) > (1, 12) {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_buffer_pool_new())
|
||||
}
|
||||
} else {
|
||||
// Work-around for 1.14 switching from transfer-floating to transfer-full
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_buffer_pool_new())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BufferPool {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BufferPoolExtManual {
|
||||
fn get_config(&self) -> BufferPoolConfig;
|
||||
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError>;
|
||||
|
|
34
gstreamer/src/device_monitor.rs
Normal file
34
gstreamer/src/device_monitor.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use DeviceMonitor;
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
impl DeviceMonitor {
|
||||
pub fn new() -> DeviceMonitor {
|
||||
assert_initialized_main_thread!();
|
||||
let (major, minor, _, _) = ::version();
|
||||
if (major, minor) > (1, 12) {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_device_monitor_new())
|
||||
}
|
||||
} else {
|
||||
// Work-around for 1.14 switching from transfer-floating to transfer-full
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_device_monitor_new())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DeviceMonitor {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
|
@ -122,6 +122,7 @@ cfg_if! {
|
|||
mod child_proxy;
|
||||
mod clock_time;
|
||||
mod date_time;
|
||||
mod device_monitor;
|
||||
mod device_provider;
|
||||
mod enums;
|
||||
mod ghost_pad;
|
||||
|
@ -168,6 +169,8 @@ pub use tag_setter::TagSetterExtManual;
|
|||
mod plugin;
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub mod stream_collection;
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
mod stream;
|
||||
|
||||
mod typefind;
|
||||
pub use typefind::*;
|
||||
|
|
37
gstreamer/src/stream.rs
Normal file
37
gstreamer/src/stream.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use Stream;
|
||||
use StreamFlags;
|
||||
use StreamType;
|
||||
use Caps;
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
impl Stream {
|
||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||
pub fn new<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(stream_id: P, caps: Q, type_: StreamType, flags: StreamFlags) -> Stream {
|
||||
assert_initialized_main_thread!();
|
||||
let stream_id = stream_id.into();
|
||||
let stream_id = stream_id.to_glib_none();
|
||||
let caps = caps.into();
|
||||
let caps = caps.to_glib_none();
|
||||
|
||||
let (major, minor, _, _) = ::version();
|
||||
if (major, minor) > (1, 12) {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_stream_new(stream_id.0, caps.0, type_.to_glib(), flags.to_glib()))
|
||||
}
|
||||
} else {
|
||||
// Work-around for 1.14 switching from transfer-floating to transfer-full
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_stream_new(stream_id.0, caps.0, type_.to_glib(), flags.to_glib()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
use Stream;
|
||||
use StreamCollection;
|
||||
use ffi;
|
||||
use glib::translate::*;
|
||||
|
||||
pub struct Iter<'a> {
|
||||
collection: &'a StreamCollection,
|
||||
|
@ -65,6 +67,23 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
|
|||
impl<'a> ExactSizeIterator for Iter<'a> {}
|
||||
|
||||
impl StreamCollection {
|
||||
pub fn new<'a, P: Into<Option<&'a str>>>(upstream_id: P) -> StreamCollection {
|
||||
assert_initialized_main_thread!();
|
||||
let upstream_id = upstream_id.into();
|
||||
let upstream_id = upstream_id.to_glib_none();
|
||||
let (major, minor, _, _) = ::version();
|
||||
if (major, minor) > (1, 12) {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_stream_collection_new(upstream_id.0))
|
||||
}
|
||||
} else {
|
||||
// Work-around for 1.14 switching from transfer-floating to transfer-full
|
||||
unsafe {
|
||||
from_glib_none(ffi::gst_stream_collection_new(upstream_id.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> Iter {
|
||||
Iter::new(self)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue