Change various mini object references to references to the refcounted object

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/204
This commit is contained in:
Sebastian Dröge 2019-05-23 14:28:09 +03:00 committed by Sebastian Dröge
parent e6f65a5032
commit 6cef32a4dd
15 changed files with 264 additions and 227 deletions

View file

@ -641,7 +641,7 @@ fn main_loop(mut app: App) -> Result<glutin::WindowedContext<glutin::PossiblyCur
// get the last frame in channel
if let Some(sample) = receiver.try_iter().last() {
let buffer = sample.get_buffer().unwrap();
let buffer = sample.get_buffer_owned().unwrap();
let info = sample
.get_caps()
.and_then(|caps| gst_video::VideoInfo::from_caps(caps))
@ -660,9 +660,7 @@ fn main_loop(mut app: App) -> Result<glutin::WindowedContext<glutin::PossiblyCur
sync_meta.set_sync_point(gst_gl_context.as_ref().unwrap());
}
if let Ok(frame) =
gst_video::VideoFrame::from_buffer_readable_gl(buffer.to_owned(), &info)
{
if let Ok(frame) = gst_video::VideoFrame::from_buffer_readable_gl(buffer, &info) {
curr_frame = Some(frame);
}
}

View file

@ -105,7 +105,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl + Send + Sync + 'stati
aggregator: &Aggregator,
templ: &gst::PadTemplate,
req_name: Option<&str>,
caps: Option<&gst::CapsRef>,
caps: Option<&gst::Caps>,
) -> Option<AggregatorPad> {
self.parent_create_new_pad(aggregator, templ, req_name, caps)
}
@ -113,7 +113,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl + Send + Sync + 'stati
fn update_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::FlowError> {
self.parent_update_src_caps(aggregator, caps)
}
@ -125,7 +125,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl + Send + Sync + 'stati
fn negotiated_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
self.parent_negotiated_src_caps(aggregator, caps)
}
@ -189,13 +189,13 @@ pub trait AggregatorImplExt {
aggregator: &Aggregator,
templ: &gst::PadTemplate,
req_name: Option<&str>,
caps: Option<&gst::CapsRef>,
caps: Option<&gst::Caps>,
) -> Option<AggregatorPad>;
fn parent_update_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::FlowError>;
fn parent_fixate_src_caps(&self, aggregator: &Aggregator, caps: gst::Caps) -> gst::Caps;
@ -203,7 +203,7 @@ pub trait AggregatorImplExt {
fn parent_negotiated_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
}
@ -426,7 +426,7 @@ impl<T: AggregatorImpl + ObjectImpl> AggregatorImplExt for T {
aggregator: &Aggregator,
templ: &gst::PadTemplate,
req_name: Option<&str>,
caps: Option<&gst::CapsRef>,
caps: Option<&gst::Caps>,
) -> Option<AggregatorPad> {
unsafe {
let data = self.get_type_data();
@ -439,7 +439,7 @@ impl<T: AggregatorImpl + ObjectImpl> AggregatorImplExt for T {
aggregator.to_glib_none().0,
templ.to_glib_none().0,
req_name.to_glib_none().0,
caps.map(|c| c.as_ptr()).unwrap_or(ptr::null()),
caps.to_glib_none().0,
))
}
}
@ -447,7 +447,7 @@ impl<T: AggregatorImpl + ObjectImpl> AggregatorImplExt for T {
fn parent_update_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -483,7 +483,7 @@ impl<T: AggregatorImpl + ObjectImpl> AggregatorImplExt for T {
fn parent_negotiated_src_caps(
&self,
aggregator: &Aggregator,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe {
let data = self.get_type_data();
@ -493,7 +493,7 @@ impl<T: AggregatorImpl + ObjectImpl> AggregatorImplExt for T {
.negotiated_src_caps
.map(|f| {
gst_result_from_gboolean!(
f(aggregator.to_glib_none().0, caps.as_mut_ptr()),
f(aggregator.to_glib_none().0, caps.to_glib_none().0),
gst::CAT_RUST,
"Parent function `negotiated_src_caps` failed"
)
@ -822,11 +822,7 @@ where
&wrap,
&from_glib_borrow(templ),
req_name,
if caps.is_null() {
None
} else {
Some(gst::CapsRef::from_ptr(caps))
},
Option::<gst::Caps>::from_glib_borrow(caps).as_ref(),
)
})
.to_glib_full()
@ -849,7 +845,7 @@ where
*res = ptr::null_mut();
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
match imp.update_src_caps(&wrap, gst::CapsRef::from_ptr(caps)) {
match imp.update_src_caps(&wrap, &from_glib_borrow(caps)) {
Ok(res_caps) => {
*res = res_caps.into_ptr();
gst::FlowReturn::Ok
@ -893,7 +889,7 @@ where
let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.negotiated_src_caps(&wrap, gst::CapsRef::from_ptr(caps)) {
match imp.negotiated_src_caps(&wrap, &from_glib_borrow(caps)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);

View file

@ -34,7 +34,7 @@ pub trait AggregatorPadImpl: AggregatorPadImplExt + PadImpl + Send + Sync + 'sta
&self,
aggregator_pad: &AggregatorPad,
aggregator: &Aggregator,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> bool {
self.parent_skip_buffer(aggregator_pad, aggregator, buffer)
}
@ -51,7 +51,7 @@ pub trait AggregatorPadImplExt {
&self,
aggregator_pad: &AggregatorPad,
aggregator: &Aggregator,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> bool;
}
@ -82,7 +82,7 @@ impl<T: AggregatorPadImpl + ObjectImpl> AggregatorPadImplExt for T {
&self,
aggregator_pad: &AggregatorPad,
aggregator: &Aggregator,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> bool {
unsafe {
let data = self.get_type_data();
@ -94,7 +94,7 @@ impl<T: AggregatorPadImpl + ObjectImpl> AggregatorPadImplExt for T {
from_glib(f(
aggregator_pad.to_glib_none().0,
aggregator.to_glib_none().0,
buffer.as_mut_ptr(),
buffer.to_glib_none().0,
))
})
.unwrap_or(false)
@ -144,7 +144,7 @@ where
imp.skip_buffer(
&wrap,
&from_glib_borrow(aggregator),
gst::BufferRef::from_ptr(buffer),
&from_glib_borrow(buffer),
)
.to_glib()
}

View file

@ -34,13 +34,13 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl + Send + Sync + 'static {
fn render(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn prepare(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_prepare(element, buffer)
}
@ -48,7 +48,7 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl + Send + Sync + 'static {
fn render_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_render_list(element, list)
}
@ -56,7 +56,7 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl + Send + Sync + 'static {
fn prepare_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_prepare_list(element, list)
}
@ -69,11 +69,11 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl + Send + Sync + 'static {
self.parent_event(element, event)
}
fn get_caps(&self, element: &BaseSink, filter: Option<&gst::CapsRef>) -> Option<gst::Caps> {
fn get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
self.parent_get_caps(element, filter)
}
fn set_caps(&self, element: &BaseSink, caps: &gst::CapsRef) -> Result<(), gst::LoggableError> {
fn set_caps(&self, element: &BaseSink, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps)
}
@ -98,41 +98,37 @@ pub trait BaseSinkImplExt {
fn parent_render(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_prepare(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_render_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_prepare_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool;
fn parent_event(&self, element: &BaseSink, event: gst::Event) -> bool;
fn parent_get_caps(
&self,
element: &BaseSink,
filter: Option<&gst::CapsRef>,
) -> Option<gst::Caps>;
fn parent_get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
fn parent_set_caps(
&self,
element: &BaseSink,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_fixate(&self, element: &BaseSink, caps: gst::Caps) -> gst::Caps;
@ -188,7 +184,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
fn parent_render(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -197,7 +193,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
(*parent_class)
.render
.map(|f| {
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buffer.as_mut_ptr()))
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buffer.to_glib_none().0))
})
.unwrap_or(gst::FlowReturn::Ok)
.into_result()
@ -207,7 +203,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
fn parent_prepare(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -215,7 +211,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
(*parent_class)
.prepare
.map(|f| from_glib(f(element.to_glib_none().0, buffer.as_mut_ptr())))
.map(|f| from_glib(f(element.to_glib_none().0, buffer.to_glib_none().0)))
.unwrap_or(gst::FlowReturn::Ok)
.into_result()
}
@ -224,7 +220,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
fn parent_render_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -233,12 +229,12 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
(*parent_class)
.render_list
.map(|f| {
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.as_mut_ptr()))
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.to_glib_none().0))
.into_result()
})
.unwrap_or_else(|| {
for buffer in list.iter() {
self.render(element, buffer)?;
self.render(element, &from_glib_borrow(buffer.as_ptr()))?;
}
Ok(gst::FlowSuccess::Ok)
})
@ -248,7 +244,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
fn parent_prepare_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -257,12 +253,12 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
(*parent_class)
.prepare_list
.map(|f| {
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.as_mut_ptr()))
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.to_glib_none().0))
.into_result()
})
.unwrap_or_else(|| {
for buffer in list.iter() {
self.prepare(element, buffer)?;
self.prepare(element, &from_glib_borrow(buffer.as_ptr()))?;
}
Ok(gst::FlowSuccess::Ok)
})
@ -293,24 +289,15 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
}
}
fn parent_get_caps(
&self,
element: &BaseSink,
filter: Option<&gst::CapsRef>,
) -> Option<gst::Caps> {
fn parent_get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
unsafe {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
let filter_ptr = if let Some(filter) = filter {
filter.as_mut_ptr()
} else {
ptr::null_mut()
};
(*parent_class)
.get_caps
.map(|f| from_glib_full(f(element.to_glib_none().0, filter_ptr)))
.map(|f| from_glib_full(f(element.to_glib_none().0, filter.to_glib_none().0)))
.unwrap_or(None)
}
}
@ -318,7 +305,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
fn parent_set_caps(
&self,
element: &BaseSink,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe {
let data = self.get_type_data();
@ -328,7 +315,7 @@ impl<T: BaseSinkImpl + ObjectImpl> BaseSinkImplExt for T {
.set_caps
.map(|f| {
gst_result_from_gboolean!(
f(element.to_glib_none().0, caps.as_mut_ptr()),
f(element.to_glib_none().0, caps.to_glib_none().0),
gst::CAT_RUST,
"Parent function `set_caps` failed"
)
@ -478,10 +465,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_ptr(buffer);
let buffer = from_glib_borrow(buffer);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.render(&wrap, buffer).into()
imp.render(&wrap, &buffer).into()
})
.to_glib()
}
@ -498,10 +485,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_ptr(buffer);
let buffer = from_glib_borrow(buffer);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.prepare(&wrap, buffer).into()
imp.prepare(&wrap, &buffer).into()
})
.to_glib()
}
@ -518,10 +505,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let list = gst::BufferListRef::from_ptr(list);
let list = from_glib_borrow(list);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.render_list(&wrap, list).into()
imp.render_list(&wrap, &list).into()
})
.to_glib()
}
@ -538,10 +525,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let list = gst::BufferListRef::from_ptr(list);
let list = from_glib_borrow(list);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.prepare_list(&wrap, list).into()
imp.prepare_list(&wrap, &list).into()
})
.to_glib()
}
@ -597,14 +584,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let filter = if filter.is_null() {
None
} else {
Some(gst::CapsRef::from_ptr(filter))
};
let filter = Option::<gst::Caps>::from_glib_borrow(filter);
gst_panic_to_error!(&wrap, &instance.panicked(), None, {
imp.get_caps(&wrap, filter)
imp.get_caps(&wrap, filter.as_ref())
})
.map(|caps| caps.into_ptr())
.unwrap_or(ptr::null_mut())
@ -622,10 +605,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSink = from_glib_borrow(ptr);
let caps = gst::CapsRef::from_ptr(caps);
let caps = from_glib_borrow(caps);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_caps(&wrap, caps) {
match imp.set_caps(&wrap, &caps) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);

View file

@ -70,7 +70,7 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl + Send + Sync + 'static {
self.parent_event(element, event)
}
fn get_caps(&self, element: &BaseSrc, filter: Option<&gst::CapsRef>) -> Option<gst::Caps> {
fn get_caps(&self, element: &BaseSrc, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
self.parent_get_caps(element, filter)
}
@ -78,7 +78,7 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl + Send + Sync + 'static {
self.parent_negotiate(element)
}
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> Result<(), gst::LoggableError> {
fn set_caps(&self, element: &BaseSrc, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps)
}
@ -125,18 +125,14 @@ pub trait BaseSrcImplExt {
fn parent_event(&self, element: &BaseSrc, event: &gst::Event) -> bool;
fn parent_get_caps(
&self,
element: &BaseSrc,
filter: Option<&gst::CapsRef>,
) -> Option<gst::Caps>;
fn parent_get_caps(&self, element: &BaseSrc, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
fn parent_negotiate(&self, element: &BaseSrc) -> Result<(), gst::LoggableError>;
fn parent_set_caps(
&self,
element: &BaseSrc,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps;
@ -308,24 +304,15 @@ impl<T: BaseSrcImpl + ObjectImpl> BaseSrcImplExt for T {
}
}
fn parent_get_caps(
&self,
element: &BaseSrc,
filter: Option<&gst::CapsRef>,
) -> Option<gst::Caps> {
fn parent_get_caps(&self, element: &BaseSrc, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
unsafe {
let data = self.get_type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSrcClass;
let filter_ptr = if let Some(filter) = filter {
filter.as_mut_ptr()
} else {
ptr::null_mut()
};
(*parent_class)
.get_caps
.map(|f| from_glib_full(f(element.to_glib_none().0, filter_ptr)))
.map(|f| from_glib_full(f(element.to_glib_none().0, filter.to_glib_none().0)))
.unwrap_or(None)
}
}
@ -351,7 +338,7 @@ impl<T: BaseSrcImpl + ObjectImpl> BaseSrcImplExt for T {
fn parent_set_caps(
&self,
element: &BaseSrc,
caps: &gst::CapsRef,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe {
let data = self.get_type_data();
@ -361,7 +348,7 @@ impl<T: BaseSrcImpl + ObjectImpl> BaseSrcImplExt for T {
.set_caps
.map(|f| {
gst_result_from_gboolean!(
f(element.to_glib_none().0, caps.as_mut_ptr()),
f(element.to_glib_none().0, caps.to_glib_none().0),
gst::CAT_RUST,
"Parent function `set_caps` failed"
)
@ -666,14 +653,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSrc = from_glib_borrow(ptr);
let filter = if filter.is_null() {
None
} else {
Some(gst::CapsRef::from_ptr(filter))
};
let filter = Option::<gst::Caps>::from_glib_borrow(filter);
gst_panic_to_error!(&wrap, &instance.panicked(), None, {
imp.get_caps(&wrap, filter)
imp.get_caps(&wrap, filter.as_ref())
})
.map(|caps| caps.into_ptr())
.unwrap_or(ptr::null_mut())
@ -715,10 +698,10 @@ where
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: BaseSrc = from_glib_borrow(ptr);
let caps = gst::CapsRef::from_ptr(caps);
let caps = from_glib_borrow(caps);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_caps(&wrap, caps) {
match imp.set_caps(&wrap, &caps) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&wrap);

View file

@ -114,7 +114,7 @@ pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl + Send + Sync +
fn transform_ip_passthrough(
&self,
element: &BaseTransform,
buf: &gst::BufferRef,
buf: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_transform_ip_passthrough(element, buf)
}
@ -193,7 +193,7 @@ pub trait BaseTransformImplExt {
fn parent_transform_ip_passthrough(
&self,
element: &BaseTransform,
buf: &gst::BufferRef,
buf: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
}
@ -503,7 +503,7 @@ impl<T: BaseTransformImpl + ObjectImpl> BaseTransformImplExt for T {
}
});
gst::FlowReturn::from_glib(f(element.to_glib_none().0, &mut buf.as_mut_ptr()))
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buf.as_mut_ptr() as *mut _))
.into_result()
}
}
@ -511,7 +511,7 @@ impl<T: BaseTransformImpl + ObjectImpl> BaseTransformImplExt for T {
fn parent_transform_ip_passthrough(
&self,
element: &BaseTransform,
buf: &gst::BufferRef,
buf: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
@ -531,8 +531,9 @@ impl<T: BaseTransformImpl + ObjectImpl> BaseTransformImplExt for T {
}
});
gst::FlowReturn::from_glib(f(element.to_glib_none().0, &mut buf.as_mut_ptr()))
.into_result()
// FIXME: Wrong signature in FFI
let buf: *mut gst_sys::GstBuffer = buf.to_glib_none().0;
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buf as *mut _)).into_result()
}
}
}
@ -920,7 +921,7 @@ where
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
if from_glib(gst_base_sys::gst_base_transform_is_passthrough(ptr)) {
imp.transform_ip_passthrough(&wrap, gst::BufferRef::from_ptr(buf))
imp.transform_ip_passthrough(&wrap, &from_glib_borrow(buf))
.into()
} else {
imp.transform_ip(&wrap, gst::BufferRef::from_mut_ptr(buf))

View file

@ -9,7 +9,7 @@
use std::fmt;
use glib;
use glib::translate::{from_glib, ToGlib};
use glib::translate::{from_glib, from_glib_none, ToGlib};
use gst;
use gst::prelude::*;
use gst_sys;
@ -154,6 +154,10 @@ impl VideoOverlayCompositionMeta {
unsafe { ::VideoOverlayCompositionRef::from_ptr(self.0.overlay) }
}
pub fn get_overlay_owned(&self) -> ::VideoOverlayComposition {
unsafe { from_glib_none(self.get_overlay().as_ptr()) }
}
pub fn set_overlay(&mut self, overlay: &::VideoOverlayComposition) {
#![allow(clippy::cast_ptr_alignment)]
unsafe {

View file

@ -13,7 +13,7 @@ use gst::miniobject::*;
use gst_video_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib};
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
gst_define_mini_object_wrapper!(
VideoOverlayRectangle,
@ -35,7 +35,7 @@ impl fmt::Debug for VideoOverlayRectangleRef {
impl VideoOverlayRectangle {
pub fn new_raw(
buffer: &gst::BufferRef,
buffer: &gst::Buffer,
render_x: i32,
render_y: i32,
render_width: u32,
@ -45,7 +45,7 @@ impl VideoOverlayRectangle {
assert!(buffer.get_meta::<::VideoMeta>().is_some());
unsafe {
from_glib_full(gst_video_sys::gst_video_overlay_rectangle_new_raw(
buffer.as_mut_ptr(),
buffer.to_glib_none().0,
render_x,
render_y,
render_width,

View file

@ -7,7 +7,7 @@
// except according to those terms.
use glib;
use glib::translate::from_glib_full;
use glib::translate::{from_glib_full, from_glib_none};
use gst_sys;
use std::fmt;
@ -65,6 +65,13 @@ impl BufferListRef {
}
}
pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
unsafe {
let ptr = gst_sys::gst_buffer_list_get(self.as_mut_ptr(), idx);
from_glib_none(ptr)
}
}
#[cfg(any(feature = "v1_14", feature = "dox"))]
pub fn get_writable(&mut self, idx: u32) -> Option<&mut BufferRef> {
unsafe {
@ -93,6 +100,10 @@ impl BufferListRef {
pub fn iter(&self) -> Iter {
Iter::new(self)
}
pub fn iter_owned(&self) -> IterOwned {
IterOwned::new(self)
}
}
impl Default for BufferList {
@ -119,17 +130,19 @@ impl fmt::Debug for BufferListRef {
}
}
macro_rules! define_iter(
($name:ident, $styp:ty, $get_item:expr) => {
#[derive(Debug)]
pub struct Iter<'a> {
pub struct $name<'a> {
list: &'a BufferListRef,
idx: u32,
size: u32,
}
impl<'a> Iter<'a> {
fn new(list: &'a BufferListRef) -> Iter<'a> {
impl<'a> $name<'a> {
fn new(list: &'a BufferListRef) -> $name<'a> {
skip_assert_initialized!();
Iter {
$name {
list,
idx: 0,
size: list.len() as u32,
@ -137,18 +150,18 @@ impl<'a> Iter<'a> {
}
}
impl<'a> Iterator for Iter<'a> {
type Item = &'a BufferRef;
impl<'a> Iterator for $name<'a> {
type Item = $styp;
fn next(&mut self) -> Option<Self::Item> {
if self.idx >= self.size {
return None;
}
let item = self.list.get(self.idx);
let item = $get_item(self.list, self.idx)?;
self.idx += 1;
item
Some(item)
}
fn size_hint(&self) -> (usize, Option<usize>) {
@ -162,15 +175,25 @@ impl<'a> Iterator for Iter<'a> {
}
}
impl<'a> DoubleEndedIterator for Iter<'a> {
impl<'a> DoubleEndedIterator for $name<'a> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.idx == self.size {
return None;
}
self.size -= 1;
self.list.get(self.size)
$get_item(self.list, self.size)
}
}
impl<'a> ExactSizeIterator for Iter<'a> {}
impl<'a> ExactSizeIterator for $name<'a> {}
}
);
define_iter!(Iter, &'a BufferRef, |list: &'a BufferListRef, idx| {
list.get(idx)
});
define_iter!(IterOwned, Buffer, |list: &BufferListRef, idx| {
list.get_owned(idx)
});

View file

@ -19,7 +19,7 @@ use std::ops::Deref;
use std::ptr;
use glib;
use glib::translate::{from_glib, from_glib_full, FromGlib, ToGlib, ToGlibPtr};
use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlib, ToGlib, ToGlibPtr};
use glib::value::ToSendValue;
#[cfg(any(feature = "v1_10", feature = "dox"))]
@ -571,6 +571,10 @@ impl<'a> Caps<'a> {
::CapsRef::from_ptr(caps)
}
}
pub fn get_caps_owned(&self) -> ::Caps {
unsafe { from_glib_none(self.get_caps().as_ptr()) }
}
}
declare_concrete_event!(Segment);
@ -608,6 +612,10 @@ impl<'a> Tag<'a> {
::TagListRef::from_ptr(tags)
}
}
pub fn get_tag_owned(&self) -> ::TagList {
unsafe { from_glib_none(self.get_tag().as_ptr()) }
}
}
declare_concrete_event!(BufferSize);
@ -674,6 +682,13 @@ impl<'a> Toc<'a> {
(::TocRef::from_ptr(toc), from_glib(updated))
}
}
pub fn get_toc_owned(&self) -> (::Toc, bool) {
unsafe {
let (toc, updated) = self.get_toc();
(from_glib_none(toc.as_ptr()), updated)
}
}
}
declare_concrete_event!(Protection);
@ -702,6 +717,13 @@ impl<'a> Protection<'a> {
)
}
}
pub fn get_owned(&self) -> (&'a str, ::Buffer, Option<&'a str>) {
unsafe {
let (system_id, buffer, origin) = self.get();
(system_id, from_glib_none(buffer.as_ptr()), origin)
}
}
}
declare_concrete_event!(SegmentDone);

View file

@ -11,10 +11,11 @@ use std::marker::PhantomData;
use std::ops;
use miniobject::MiniObject;
use Buffer;
use BufferRef;
use glib;
use glib::translate::{from_glib, FromGlib};
use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr};
use glib_sys;
use gst_sys;
@ -227,14 +228,11 @@ impl fmt::Debug for Meta {
pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta);
impl ParentBufferMeta {
pub fn add<'a>(
buffer: &'a mut BufferRef,
parent: &BufferRef,
) -> MetaRefMut<'a, Self, Standalone> {
pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> {
unsafe {
let meta = gst_sys::gst_buffer_add_parent_buffer_meta(
buffer.as_mut_ptr(),
parent.as_mut_ptr(),
parent.to_glib_none().0,
);
Self::from_mut_ptr(buffer, meta)
@ -244,6 +242,10 @@ impl ParentBufferMeta {
pub fn get_parent(&self) -> &BufferRef {
unsafe { BufferRef::from_ptr(self.0.buffer) }
}
pub fn get_parent_owned(&self) -> Buffer {
unsafe { from_glib_none(self.0.buffer) }
}
}
unsafe impl MetaAPI for ParentBufferMeta {
@ -273,7 +275,7 @@ mod tests {
let mut buffer = ::Buffer::new();
let parent = ::Buffer::new();
{
let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &*parent);
let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &parent);
unsafe {
assert_eq!(meta.get_parent().as_ptr(), parent.as_ptr());
}

View file

@ -914,6 +914,13 @@ impl<T: AsPtr> Allocation<T> {
}
}
pub fn get_owned(&self) -> (::Caps, bool) {
unsafe {
let (caps, need_pool) = self.get();
(from_glib_none(caps.as_ptr()), need_pool)
}
}
pub fn get_allocation_pools(&self) -> Vec<(Option<::BufferPool>, u32, u32, u32)> {
unsafe {
let n = gst_sys::gst_query_get_n_allocation_pools(self.0.as_ptr());
@ -1141,6 +1148,10 @@ impl<T: AsPtr> AcceptCaps<T> {
}
}
pub fn get_caps_owned(&self) -> ::Caps {
unsafe { from_glib_none(self.get_caps().as_ptr()) }
}
pub fn get_result(&self) -> bool {
unsafe {
let mut accepted = mem::uninitialized();
@ -1172,6 +1183,10 @@ impl<T: AsPtr> Caps<T> {
}
}
pub fn get_filter_owned(&self) -> Option<::Caps> {
unsafe { self.get_filter().map(|caps| from_glib_none(caps.as_ptr())) }
}
pub fn get_result(&self) -> Option<&::CapsRef> {
unsafe {
let mut caps = ptr::null_mut();
@ -1183,6 +1198,10 @@ impl<T: AsPtr> Caps<T> {
}
}
}
pub fn get_result_owned(&self) -> Option<::Caps> {
unsafe { self.get_result().map(|caps| from_glib_none(caps.as_ptr())) }
}
}
impl<T: AsMutPtr> Caps<T> {
@ -1209,6 +1228,13 @@ impl<T: AsPtr> Context<T> {
}
}
pub fn get_context_owned(&self) -> Option<::Context> {
unsafe {
self.get_context()
.map(|context| from_glib_none(context.as_ptr()))
}
}
pub fn get_context_type(&self) -> &str {
unsafe {
let mut context_type = ptr::null();

View file

@ -15,8 +15,11 @@ use glib;
use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr};
use miniobject::*;
use Buffer;
use BufferList;
use BufferListRef;
use BufferRef;
use Caps;
use CapsRef;
use FormattedSegment;
use FormattedValue;
@ -30,8 +33,8 @@ gst_define_mini_object_wrapper!(Sample, SampleRef, gst_sys::GstSample, [Debug,],
impl Sample {
pub fn new<F: FormattedValue>(
buffer: Option<&BufferRef>,
caps: Option<&CapsRef>,
buffer: Option<&Buffer>,
caps: Option<&Caps>,
segment: Option<&FormattedSegment<F>>,
info: Option<Structure>,
) -> Self {
@ -40,11 +43,8 @@ impl Sample {
let info = info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut());
from_glib_full(gst_sys::gst_sample_new(
buffer
.map(|buffer| buffer.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
caps.map(|caps| caps.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
buffer.to_glib_none().0,
caps.to_glib_none().0,
segment.to_glib_none().0,
mut_override(info),
))
@ -52,8 +52,8 @@ impl Sample {
}
pub fn with_buffer_list<F: FormattedValue>(
buffer_list: Option<&BufferListRef>,
caps: Option<&CapsRef>,
buffer_list: Option<&BufferList>,
caps: Option<&Caps>,
segment: Option<&FormattedSegment<F>>,
info: Option<Structure>,
) -> Self {
@ -62,9 +62,7 @@ impl Sample {
unsafe {
gst_sys::gst_sample_set_buffer_list(
sample.to_glib_none().0,
buffer_list
.map(|buffer_list| buffer_list.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
buffer_list.to_glib_none().0,
);
}
sample
@ -83,6 +81,13 @@ impl SampleRef {
}
}
pub fn get_buffer_owned(&self) -> Option<Buffer> {
unsafe {
self.get_buffer()
.map(|buffer| from_glib_none(buffer.as_ptr()))
}
}
pub fn get_buffer_list(&self) -> Option<&BufferListRef> {
unsafe {
let ptr = gst_sys::gst_sample_get_buffer_list(self.as_mut_ptr());
@ -94,6 +99,13 @@ impl SampleRef {
}
}
pub fn get_buffer_list_owned(&self) -> Option<BufferList> {
unsafe {
self.get_buffer_list()
.map(|list| from_glib_none(list.as_ptr()))
}
}
pub fn get_caps(&self) -> Option<&CapsRef> {
unsafe {
let ptr = gst_sys::gst_sample_get_caps(self.as_mut_ptr());
@ -105,6 +117,10 @@ impl SampleRef {
}
}
pub fn get_caps_owned(&self) -> Option<Caps> {
unsafe { self.get_caps().map(|caps| from_glib_none(caps.as_ptr())) }
}
pub fn get_segment(&self) -> Option<Segment> {
unsafe { from_glib_none(gst_sys::gst_sample_get_segment(self.as_mut_ptr())) }
}
@ -121,38 +137,20 @@ impl SampleRef {
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn set_buffer(&mut self, buffer: Option<&BufferRef>) {
pub fn set_buffer(&mut self, buffer: Option<&Buffer>) {
unsafe { gst_sys::gst_sample_set_buffer(self.as_mut_ptr(), buffer.to_glib_none().0) }
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn set_buffer_list(&mut self, buffer_list: Option<&BufferList>) {
unsafe {
gst_sys::gst_sample_set_buffer(
self.as_mut_ptr(),
buffer
.map(|buffer| buffer.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
)
gst_sys::gst_sample_set_buffer_list(self.as_mut_ptr(), buffer_list.to_glib_none().0)
}
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn set_buffer_list(&mut self, buffer_list: Option<&BufferListRef>) {
unsafe {
gst_sys::gst_sample_set_buffer_list(
self.as_mut_ptr(),
buffer_list
.map(|buffer_list| buffer_list.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
)
}
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn set_caps(&mut self, caps: Option<&CapsRef>) {
unsafe {
gst_sys::gst_sample_set_caps(
self.as_mut_ptr(),
caps.map(|caps| caps.as_mut_ptr())
.unwrap_or(ptr::null_mut()),
)
}
pub fn set_caps(&mut self, caps: Option<&Caps>) {
unsafe { gst_sys::gst_sample_set_caps(self.as_mut_ptr(), caps.to_glib_none().0) }
}
#[cfg(any(feature = "v1_16", feature = "dox"))]

View file

@ -42,7 +42,7 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync + 'static {
element: &::Element,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::CapsRef>,
caps: Option<&::Caps>,
) -> Option<::Pad> {
self.parent_request_new_pad(element, templ, name, caps)
}
@ -76,7 +76,7 @@ pub trait ElementImplExt {
element: &::Element,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::CapsRef>,
caps: Option<&::Caps>,
) -> Option<::Pad>;
fn parent_release_pad(&self, element: &::Element, pad: &::Pad);
@ -132,7 +132,7 @@ where
element: &::Element,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::CapsRef>,
caps: Option<&::Caps>,
) -> Option<::Pad> {
unsafe {
let data = self.get_type_data();
@ -145,7 +145,7 @@ where
element.to_glib_none().0,
templ.to_glib_none().0,
name.to_glib_full(),
caps.map(|caps| caps.as_ptr()).unwrap_or(std::ptr::null()),
caps.to_glib_none().0,
))
})
.unwrap_or(None)
@ -336,16 +336,17 @@ where
let imp = instance.get_impl();
let wrap: Element = from_glib_borrow(ptr);
let caps = if caps.is_null() {
None
} else {
Some(::CapsRef::from_ptr(caps))
};
let caps = Option::<::Caps>::from_glib_borrow(caps);
// XXX: This is effectively unsafe but the best we can do
// See https://bugzilla.gnome.org/show_bug.cgi?id=791193
let pad = gst_panic_to_error!(&wrap, &instance.panicked(), None, {
imp.request_new_pad(&wrap, &from_glib_borrow(templ), from_glib_none(name), caps)
imp.request_new_pad(
&wrap,
&from_glib_borrow(templ),
from_glib_none(name),
caps.as_ref(),
)
});
// Ensure that the pad is owned by the element now, if a pad was returned

View file

@ -99,7 +99,7 @@ fn tutorial_main() {
.expect("Unable to set the playbin to the `Null` state");
}
fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef>) {
fn handle_message(custom_data: &mut CustomData, msg: &gst::Message) {
match msg.view() {
MessageView::Error(err) => {
println!(