mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 03:21:03 +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
5cb03ab2ef
commit
3282c77a6d
14 changed files with 174 additions and 62 deletions
18
Gir_Gst.toml
18
Gir_Gst.toml
|
@ -439,6 +439,11 @@ status = "generate"
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "Gst.DeviceMonitor"
|
name = "Gst.DeviceMonitor"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
|
[[object.function]]
|
||||||
|
name = "new"
|
||||||
|
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
name = "get_bus"
|
name = "get_bus"
|
||||||
[object.function.return]
|
[object.function.return]
|
||||||
|
@ -708,11 +713,19 @@ status = "generate"
|
||||||
name = "Gst.Stream"
|
name = "Gst.Stream"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
trait = false
|
trait = false
|
||||||
|
[[object.function]]
|
||||||
|
name = "new"
|
||||||
|
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "Gst.StreamCollection"
|
name = "Gst.StreamCollection"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
trait = false
|
trait = false
|
||||||
|
[[object.function]]
|
||||||
|
name = "new"
|
||||||
|
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "Gst.Plugin"
|
name = "Gst.Plugin"
|
||||||
|
@ -832,6 +845,11 @@ status = "generate"
|
||||||
# Takes ownership
|
# Takes ownership
|
||||||
ignore = true
|
ignore = true
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "new"
|
||||||
|
# Work-around for 1.14 switch from transfer-floating to transfer-full
|
||||||
|
ignore = true
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
name = "set_active"
|
name = "set_active"
|
||||||
[object.function.return]
|
[object.function.return]
|
||||||
|
|
|
@ -64,3 +64,8 @@ trait = false
|
||||||
name = "GstNet.NetTimeProvider"
|
name = "GstNet.NetTimeProvider"
|
||||||
status = "generate"
|
status = "generate"
|
||||||
trait = false
|
trait = false
|
||||||
|
|
||||||
|
[[object.function]]
|
||||||
|
name = "new"
|
||||||
|
# Floating reference handling
|
||||||
|
ignore = true
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
use ffi;
|
use ffi;
|
||||||
use glib::StaticType;
|
use glib::StaticType;
|
||||||
use glib::Value;
|
use glib::Value;
|
||||||
use glib::object::IsA;
|
|
||||||
use glib::signal::SignalHandlerId;
|
use glib::signal::SignalHandlerId;
|
||||||
use glib::signal::connect;
|
use glib::signal::connect;
|
||||||
use glib::translate::*;
|
use glib::translate::*;
|
||||||
|
@ -29,15 +28,6 @@ glib_wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetTimeProvider {
|
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 {
|
pub fn get_property_active(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut value = Value::from_type(<bool as StaticType>::static_type());
|
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;
|
mod auto;
|
||||||
pub use auto::*;
|
pub use auto::*;
|
||||||
mod net_client_clock;
|
mod net_client_clock;
|
||||||
|
mod net_time_provider;
|
||||||
mod ntp_clock;
|
mod ntp_clock;
|
||||||
mod ptp_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 Send for BufferPool {}
|
||||||
unsafe impl Sync 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 Send for DeviceMonitor {}
|
||||||
unsafe impl Sync for DeviceMonitor {}
|
unsafe impl Sync for DeviceMonitor {}
|
||||||
|
|
||||||
|
|
|
@ -29,18 +29,6 @@ glib_wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Stream {
|
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"))]
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||||
pub fn get_caps(&self) -> Option<Caps> {
|
pub fn get_caps(&self) -> Option<Caps> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -27,16 +27,6 @@ glib_wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StreamCollection {
|
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"))]
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||||
pub fn add_stream(&self, stream: &Stream) -> bool {
|
pub fn add_stream(&self, stream: &Stream) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -205,6 +205,29 @@ impl PartialEq for BufferPoolAcquireParams {
|
||||||
|
|
||||||
impl Eq 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 {
|
pub trait BufferPoolExtManual {
|
||||||
fn get_config(&self) -> BufferPoolConfig;
|
fn get_config(&self) -> BufferPoolConfig;
|
||||||
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError>;
|
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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -128,6 +128,7 @@ mod ghost_pad;
|
||||||
mod child_proxy;
|
mod child_proxy;
|
||||||
mod tag_setter;
|
mod tag_setter;
|
||||||
mod iterator;
|
mod iterator;
|
||||||
|
mod device_monitor;
|
||||||
mod device_provider;
|
mod device_provider;
|
||||||
mod parse_context;
|
mod parse_context;
|
||||||
mod enums;
|
mod enums;
|
||||||
|
@ -169,6 +170,8 @@ pub use clock_time::ClockTime;
|
||||||
mod plugin;
|
mod plugin;
|
||||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||||
pub mod stream_collection;
|
pub mod stream_collection;
|
||||||
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||||
|
mod stream;
|
||||||
|
|
||||||
mod typefind;
|
mod typefind;
|
||||||
pub use 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 StreamCollection;
|
use StreamCollection;
|
||||||
use Stream;
|
use Stream;
|
||||||
|
use ffi;
|
||||||
|
use glib::translate::*;
|
||||||
|
|
||||||
pub struct Iter<'a> {
|
pub struct Iter<'a> {
|
||||||
collection: &'a StreamCollection,
|
collection: &'a StreamCollection,
|
||||||
|
@ -65,6 +67,23 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
|
||||||
impl<'a> ExactSizeIterator for Iter<'a> {}
|
impl<'a> ExactSizeIterator for Iter<'a> {}
|
||||||
|
|
||||||
impl StreamCollection {
|
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 {
|
pub fn iter(&self) -> Iter {
|
||||||
Iter::new(self)
|
Iter::new(self)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue