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:
Sebastian Dröge 2018-05-09 12:20:59 +03:00
parent 5cb03ab2ef
commit 3282c77a6d
14 changed files with 174 additions and 62 deletions

View file

@ -439,6 +439,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]
@ -708,11 +713,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"
@ -832,6 +845,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]

View file

@ -64,3 +64,8 @@ trait = false
name = "GstNet.NetTimeProvider"
status = "generate"
trait = false
[[object.function]]
name = "new"
# Floating reference handling
ignore = true

View file

@ -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());

View file

@ -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;

View 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))
}
}
}
}

View file

@ -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 {}

View file

@ -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 {}

View file

@ -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 {

View file

@ -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 {

View file

@ -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>;

View 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()
}
}

View file

@ -128,6 +128,7 @@ mod ghost_pad;
mod child_proxy;
mod tag_setter;
mod iterator;
mod device_monitor;
mod device_provider;
mod parse_context;
mod enums;
@ -169,6 +170,8 @@ pub use clock_time::ClockTime;
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
View 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()))
}
}
}
}

View file

@ -8,6 +8,8 @@
use StreamCollection;
use Stream;
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)
}