Change *Impl trait methods to only take &self and not Self::Type in addition

This commit is contained in:
Sebastian Dröge 2022-10-08 21:50:06 +03:00
parent 25c53c4276
commit f17781e188
52 changed files with 2979 additions and 3899 deletions

View file

@ -73,13 +73,7 @@ mod cairo_compositor {
} }
// Called by the application whenever the value of a property should be changed. // Called by the application whenever the value of a property should be changed.
fn set_property( fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
&self,
_obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
) {
let mut settings = self.settings.lock().unwrap(); let mut settings = self.settings.lock().unwrap();
match pspec.name() { match pspec.name() {
@ -91,12 +85,7 @@ mod cairo_compositor {
} }
// Called by the application whenever the value of a property should be retrieved. // Called by the application whenever the value of a property should be retrieved.
fn property( fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
&self,
_obj: &Self::Type,
_id: usize,
pspec: &glib::ParamSpec,
) -> glib::Value {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
match pspec.name() { match pspec.name() {
@ -180,19 +169,20 @@ mod cairo_compositor {
// Notify via the child proxy interface whenever a new pad is added or removed. // Notify via the child proxy interface whenever a new pad is added or removed.
fn request_new_pad( fn request_new_pad(
&self, &self,
element: &Self::Type,
templ: &gst::PadTemplate, templ: &gst::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&gst::Caps>, caps: Option<&gst::Caps>,
) -> Option<gst::Pad> { ) -> Option<gst::Pad> {
let pad = self.parent_request_new_pad(element, templ, name, caps)?; let element = self.instance();
let pad = self.parent_request_new_pad(templ, name, caps)?;
element.child_added(&pad, &pad.name()); element.child_added(&pad, &pad.name());
Some(pad) Some(pad)
} }
fn release_pad(&self, element: &Self::Type, pad: &gst::Pad) { fn release_pad(&self, pad: &gst::Pad) {
let element = self.instance();
element.child_removed(pad, &pad.name()); element.child_removed(pad, &pad.name());
self.parent_release_pad(element, pad); self.parent_release_pad(pad);
} }
} }
@ -201,7 +191,6 @@ mod cairo_compositor {
// Called whenever a query arrives at the given sink pad of the compositor. // Called whenever a query arrives at the given sink pad of the compositor.
fn sink_query( fn sink_query(
&self, &self,
aggregator: &Self::Type,
aggregator_pad: &gst_base::AggregatorPad, aggregator_pad: &gst_base::AggregatorPad,
query: &mut gst::QueryRef, query: &mut gst::QueryRef,
) -> bool { ) -> bool {
@ -232,7 +221,7 @@ mod cairo_compositor {
true true
} }
_ => self.parent_sink_query(aggregator, aggregator_pad, query), _ => self.parent_sink_query(aggregator_pad, query),
} }
} }
} }
@ -242,7 +231,6 @@ mod cairo_compositor {
// Called by videoaggregator whenever the output format should be determined. // Called by videoaggregator whenever the output format should be determined.
fn find_best_format( fn find_best_format(
&self, &self,
_element: &Self::Type,
_downstream_caps: &gst::Caps, _downstream_caps: &gst::Caps,
) -> Option<(gst_video::VideoInfo, bool)> { ) -> Option<(gst_video::VideoInfo, bool)> {
// Let videoaggregator select whatever format downstream wants. // Let videoaggregator select whatever format downstream wants.
@ -257,10 +245,10 @@ mod cairo_compositor {
// time. // time.
fn aggregate_frames( fn aggregate_frames(
&self, &self,
element: &Self::Type,
token: &gst_video::subclass::AggregateFramesToken, token: &gst_video::subclass::AggregateFramesToken,
outbuf: &mut gst::BufferRef, outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let element = self.instance();
let pads = element.sink_pads(); let pads = element.sink_pads();
// Map the output frame writable. // Map the output frame writable.
@ -326,11 +314,13 @@ mod cairo_compositor {
// //
// This allows accessing the pads and their properties from e.g. gst-launch. // This allows accessing the pads and their properties from e.g. gst-launch.
impl ChildProxyImpl for CairoCompositor { impl ChildProxyImpl for CairoCompositor {
fn children_count(&self, object: &Self::Type) -> u32 { fn children_count(&self) -> u32 {
let object = self.instance();
object.num_pads() as u32 object.num_pads() as u32
} }
fn child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> { fn child_by_name(&self, name: &str) -> Option<glib::Object> {
let object = self.instance();
object object
.pads() .pads()
.into_iter() .into_iter()
@ -338,7 +328,8 @@ mod cairo_compositor {
.map(|p| p.upcast()) .map(|p| p.upcast())
} }
fn child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object> { fn child_by_index(&self, index: u32) -> Option<glib::Object> {
let object = self.instance();
object object
.pads() .pads()
.into_iter() .into_iter()
@ -522,13 +513,7 @@ mod cairo_compositor {
} }
// Called by the application whenever the value of a property should be changed. // Called by the application whenever the value of a property should be changed.
fn set_property( fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
&self,
_obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
) {
let mut settings = self.settings.lock().unwrap(); let mut settings = self.settings.lock().unwrap();
match pspec.name() { match pspec.name() {
@ -552,12 +537,7 @@ mod cairo_compositor {
} }
// Called by the application whenever the value of a property should be retrieved. // Called by the application whenever the value of a property should be retrieved.
fn property( fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
&self,
_obj: &Self::Type,
_id: usize,
pspec: &glib::ParamSpec,
) -> glib::Value {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
match pspec.name() { match pspec.name() {

View file

@ -389,16 +389,9 @@ mod video_filter {
use std::{cmp, mem::ManuallyDrop, os::unix::prelude::FromRawFd}; use std::{cmp, mem::ManuallyDrop, os::unix::prelude::FromRawFd};
use anyhow::Error; use anyhow::Error;
use glib::subclass::{object::ObjectImpl, types::ObjectSubclass}; use gst::{subclass::prelude::*, PadDirection, PadPresence, PadTemplate};
use gst::{
subclass::prelude::{ElementImpl, GstObjectImpl},
PadDirection, PadPresence, PadTemplate,
};
use gst_app::gst_base::subclass::BaseTransformMode; use gst_app::gst_base::subclass::BaseTransformMode;
use gst_video::{ use gst_video::{subclass::prelude::*, VideoFrameRef};
subclass::prelude::{BaseTransformImpl, VideoFilterImpl},
VideoFrameRef,
};
use memmap2::MmapMut; use memmap2::MmapMut;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -490,11 +483,10 @@ mod video_filter {
impl VideoFilterImpl for FdMemoryFadeInVideoFilter { impl VideoFilterImpl for FdMemoryFadeInVideoFilter {
fn transform_frame_ip( fn transform_frame_ip(
&self, &self,
element: &Self::Type,
frame: &mut VideoFrameRef<&mut gst::BufferRef>, frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.transform_fd_mem_ip(frame).map_err(|err| { self.transform_fd_mem_ip(frame).map_err(|err| {
gst::error!(CAT, obj: element, "Failed to transform frame`: {}", err); gst::error!(CAT, imp: self, "Failed to transform frame`: {}", err);
gst::FlowError::Error gst::FlowError::Error
})?; })?;

View file

@ -67,11 +67,7 @@ mod mirror {
} }
impl GLMirrorFilter { impl GLMirrorFilter {
fn create_shader( fn create_shader(&self, context: &GLContext) -> Result<(), gst::LoggableError> {
&self,
filter: &<Self as ObjectSubclass>::Type,
context: &GLContext,
) -> Result<(), gst::LoggableError> {
let shader = GLShader::new(context); let shader = GLShader::new(context);
let vertex = GLSLStage::new_default_vertex(context); let vertex = GLSLStage::new_default_vertex(context);
@ -80,7 +76,7 @@ mod mirror {
gst::debug!( gst::debug!(
CAT, CAT,
obj: filter, imp: self,
"Compiling fragment shader {}", "Compiling fragment shader {}",
FRAGMENT_SHADER FRAGMENT_SHADER
); );
@ -99,7 +95,7 @@ mod mirror {
gst::debug!( gst::debug!(
CAT, CAT,
obj: filter, imp: self,
"Successfully compiled and linked {:?}", "Successfully compiled and linked {:?}",
shader shader
); );
@ -127,12 +123,14 @@ mod mirror {
const TRANSFORM_IP_ON_PASSTHROUGH: bool = false; const TRANSFORM_IP_ON_PASSTHROUGH: bool = false;
} }
impl GLBaseFilterImpl for GLMirrorFilter { impl GLBaseFilterImpl for GLMirrorFilter {
fn gl_start(&self, filter: &Self::Type) -> Result<(), gst::LoggableError> { fn gl_start(&self) -> Result<(), gst::LoggableError> {
let filter = self.instance();
// Create a shader when GL is started, knowing that the OpenGL context is // Create a shader when GL is started, knowing that the OpenGL context is
// available. // available.
let context = GLBaseFilterExt::context(filter).unwrap(); let context = GLBaseFilterExt::context(&*filter).unwrap();
self.create_shader(filter, &context)?; self.create_shader(&context)?;
self.parent_gl_start(filter) self.parent_gl_start()
} }
} }
impl GLFilterImpl for GLMirrorFilter { impl GLFilterImpl for GLMirrorFilter {
@ -140,10 +138,11 @@ mod mirror {
fn filter_texture( fn filter_texture(
&self, &self,
filter: &Self::Type,
input: &gst_gl::GLMemory, input: &gst_gl::GLMemory,
output: &gst_gl::GLMemory, output: &gst_gl::GLMemory,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
let filter = self.instance();
let shader = self.shader.lock().unwrap(); let shader = self.shader.lock().unwrap();
// Use the underlying filter implementation to transform the input texture into // Use the underlying filter implementation to transform the input texture into
// an output texture with the shader. // an output texture with the shader.
@ -154,7 +153,7 @@ mod mirror {
.as_ref() .as_ref()
.expect("No shader, call `create_shader` first!"), .expect("No shader, call `create_shader` first!"),
); );
self.parent_filter_texture(filter, input, output) self.parent_filter_texture(input, output)
} }
} }
} }

View file

@ -105,9 +105,10 @@ mod media_factory {
// Implementation of glib::Object virtual methods // Implementation of glib::Object virtual methods
impl ObjectImpl for Factory { impl ObjectImpl for Factory {
fn constructed(&self, factory: &Self::Type) { fn constructed(&self) {
self.parent_constructed(factory); self.parent_constructed();
let factory = self.instance();
// All media created by this factory are our custom media type. This would // All media created by this factory are our custom media type. This would
// not require a media factory subclass and can also be called on the normal // not require a media factory subclass and can also be called on the normal
// RTSPMediaFactory. // RTSPMediaFactory.
@ -117,11 +118,7 @@ mod media_factory {
// Implementation of gst_rtsp_server::RTSPMediaFactory virtual methods // Implementation of gst_rtsp_server::RTSPMediaFactory virtual methods
impl RTSPMediaFactoryImpl for Factory { impl RTSPMediaFactoryImpl for Factory {
fn create_element( fn create_element(&self, _url: &gst_rtsp::RTSPUrl) -> Option<gst::Element> {
&self,
_factory: &Self::Type,
_url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> {
// Create a simple VP8 videotestsrc input // Create a simple VP8 videotestsrc input
let bin = gst::Bin::new(None); let bin = gst::Bin::new(None);
let src = gst::ElementFactory::make("videotestsrc", None).unwrap(); let src = gst::ElementFactory::make("videotestsrc", None).unwrap();
@ -187,11 +184,10 @@ mod media {
impl RTSPMediaImpl for Media { impl RTSPMediaImpl for Media {
fn setup_sdp( fn setup_sdp(
&self, &self,
media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &gst_rtsp_server::subclass::SDPInfo, info: &gst_rtsp_server::subclass::SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_setup_sdp(media, sdp, info)?; self.parent_setup_sdp(sdp, info)?;
sdp.add_attribute("my-custom-attribute", Some("has-a-value")); sdp.add_attribute("my-custom-attribute", Some("has-a-value"));
@ -237,7 +233,8 @@ mod server {
// Implementation of gst_rtsp_server::RTSPServer virtual methods // Implementation of gst_rtsp_server::RTSPServer virtual methods
impl RTSPServerImpl for Server { impl RTSPServerImpl for Server {
fn create_client(&self, server: &Self::Type) -> Option<gst_rtsp_server::RTSPClient> { fn create_client(&self) -> Option<gst_rtsp_server::RTSPClient> {
let server = self.instance();
let client = super::client::Client::default(); let client = super::client::Client::default();
// Duplicated from the default implementation // Duplicated from the default implementation
@ -249,8 +246,8 @@ mod server {
Some(client.upcast()) Some(client.upcast())
} }
fn client_connected(&self, server: &Self::Type, client: &gst_rtsp_server::RTSPClient) { fn client_connected(&self, client: &gst_rtsp_server::RTSPClient) {
self.parent_client_connected(server, client); self.parent_client_connected(client);
println!("Client {:?} connected", client); println!("Client {:?} connected", client);
} }
} }
@ -297,8 +294,9 @@ mod client {
// Implementation of gst_rtsp_server::RTSPClient virtual methods // Implementation of gst_rtsp_server::RTSPClient virtual methods
impl RTSPClientImpl for Client { impl RTSPClientImpl for Client {
fn closed(&self, client: &Self::Type) { fn closed(&self) {
self.parent_closed(client); let client = self.instance();
self.parent_closed();
println!("Client {:?} closed", client); println!("Client {:?} closed", client);
} }
} }
@ -343,13 +341,9 @@ mod mount_points {
// Implementation of gst_rtsp_server::RTSPClient virtual methods // Implementation of gst_rtsp_server::RTSPClient virtual methods
impl RTSPMountPointsImpl for MountPoints { impl RTSPMountPointsImpl for MountPoints {
fn make_path( fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
&self,
mount_points: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
println!("Make path called for {:?} ", url); println!("Make path called for {:?} ", url);
self.parent_make_path(mount_points, url) self.parent_make_path(url)
} }
} }
} }

View file

@ -135,18 +135,18 @@ mod fir_filter {
// Returns the size of one processing unit (i.e. a frame in our case) corresponding // Returns the size of one processing unit (i.e. a frame in our case) corresponding
// to the given caps. This is used for allocating a big enough output buffer and // to the given caps. This is used for allocating a big enough output buffer and
// sanity checking the input buffer size, among other things. // sanity checking the input buffer size, among other things.
fn unit_size(&self, _element: &Self::Type, caps: &gst::Caps) -> Option<usize> { fn unit_size(&self, caps: &gst::Caps) -> Option<usize> {
let audio_info = gst_audio::AudioInfo::from_caps(caps).ok(); let audio_info = gst_audio::AudioInfo::from_caps(caps).ok();
audio_info.map(|info| info.bpf() as usize) audio_info.map(|info| info.bpf() as usize)
} }
// Called when shutting down the element so we can release all stream-related state // Called when shutting down the element so we can release all stream-related state
// There's also start(), which is called whenever starting the element again // There's also start(), which is called whenever starting the element again
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
// Drop state // Drop state
self.history.lock().unwrap().clear(); self.history.lock().unwrap().clear();
gst::info!(CAT, obj: element, "Stopped"); gst::info!(CAT, imp: self, "Stopped");
Ok(()) Ok(())
} }
@ -154,9 +154,10 @@ mod fir_filter {
// Does the actual transformation of the input buffer to the output buffer // Does the actual transformation of the input buffer to the output buffer
fn transform_ip( fn transform_ip(
&self, &self,
element: &Self::Type,
buf: &mut gst::BufferRef, buf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let element = self.instance();
// Get coefficients and return directly if we have none // Get coefficients and return directly if we have none
let coeffs = self.coeffs.lock().unwrap(); let coeffs = self.coeffs.lock().unwrap();
if coeffs.is_empty() { if coeffs.is_empty() {

View file

@ -11,14 +11,13 @@ use crate::AudioAggregator;
use crate::AudioAggregatorPad; use crate::AudioAggregatorPad;
pub trait AudioAggregatorImpl: AudioAggregatorImplExt + AggregatorImpl { pub trait AudioAggregatorImpl: AudioAggregatorImplExt + AggregatorImpl {
fn create_output_buffer(&self, element: &Self::Type, num_frames: u32) -> Option<gst::Buffer> { fn create_output_buffer(&self, num_frames: u32) -> Option<gst::Buffer> {
self.parent_create_output_buffer(element, num_frames) self.parent_create_output_buffer(num_frames)
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn aggregate_one_buffer( fn aggregate_one_buffer(
&self, &self,
element: &Self::Type,
pad: &AudioAggregatorPad, pad: &AudioAggregatorPad,
inbuf: &gst::BufferRef, inbuf: &gst::BufferRef,
in_offset: u32, in_offset: u32,
@ -26,23 +25,16 @@ pub trait AudioAggregatorImpl: AudioAggregatorImplExt + AggregatorImpl {
out_offset: u32, out_offset: u32,
num_frames: u32, num_frames: u32,
) -> bool { ) -> bool {
self.parent_aggregate_one_buffer( self.parent_aggregate_one_buffer(pad, inbuf, in_offset, outbuf, out_offset, num_frames)
element, pad, inbuf, in_offset, outbuf, out_offset, num_frames,
)
} }
} }
pub trait AudioAggregatorImplExt: ObjectSubclass { pub trait AudioAggregatorImplExt: ObjectSubclass {
fn parent_create_output_buffer( fn parent_create_output_buffer(&self, num_frames: u32) -> Option<gst::Buffer>;
&self,
element: &Self::Type,
num_frames: u32,
) -> Option<gst::Buffer>;
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn parent_aggregate_one_buffer( fn parent_aggregate_one_buffer(
&self, &self,
element: &Self::Type,
pad: &AudioAggregatorPad, pad: &AudioAggregatorPad,
inbuf: &gst::BufferRef, inbuf: &gst::BufferRef,
in_offset: u32, in_offset: u32,
@ -53,11 +45,7 @@ pub trait AudioAggregatorImplExt: ObjectSubclass {
} }
impl<T: AudioAggregatorImpl> AudioAggregatorImplExt for T { impl<T: AudioAggregatorImpl> AudioAggregatorImplExt for T {
fn parent_create_output_buffer( fn parent_create_output_buffer(&self, num_frames: u32) -> Option<gst::Buffer> {
&self,
element: &Self::Type,
num_frames: u32,
) -> Option<gst::Buffer> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorClass;
@ -66,7 +54,7 @@ impl<T: AudioAggregatorImpl> AudioAggregatorImplExt for T {
.expect("Missing parent function `create_output_buffer`"); .expect("Missing parent function `create_output_buffer`");
from_glib_full(f( from_glib_full(f(
element self.instance()
.unsafe_cast_ref::<AudioAggregator>() .unsafe_cast_ref::<AudioAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -77,7 +65,6 @@ impl<T: AudioAggregatorImpl> AudioAggregatorImplExt for T {
fn parent_aggregate_one_buffer( fn parent_aggregate_one_buffer(
&self, &self,
element: &Self::Type,
pad: &AudioAggregatorPad, pad: &AudioAggregatorPad,
inbuf: &gst::BufferRef, inbuf: &gst::BufferRef,
in_offset: u32, in_offset: u32,
@ -93,7 +80,7 @@ impl<T: AudioAggregatorImpl> AudioAggregatorImplExt for T {
.expect("Missing parent function `aggregate_one_buffer`"); .expect("Missing parent function `aggregate_one_buffer`");
from_glib(f( from_glib(f(
element self.instance()
.unsafe_cast_ref::<AudioAggregator>() .unsafe_cast_ref::<AudioAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -124,13 +111,10 @@ unsafe extern "C" fn audio_aggregator_create_output_buffer<T: AudioAggregatorImp
) -> *mut gst::ffi::GstBuffer { ) -> *mut gst::ffi::GstBuffer {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), None, { gst::panic_to_error!(imp, None, { imp.create_output_buffer(num_frames) })
imp.create_output_buffer(wrap.unsafe_cast_ref(), num_frames) .map(|buffer| buffer.into_glib_ptr())
}) .unwrap_or(ptr::null_mut())
.map(|buffer| buffer.into_glib_ptr())
.unwrap_or(ptr::null_mut())
} }
unsafe extern "C" fn audio_aggregator_aggregate_one_buffer<T: AudioAggregatorImpl>( unsafe extern "C" fn audio_aggregator_aggregate_one_buffer<T: AudioAggregatorImpl>(
@ -144,11 +128,9 @@ unsafe extern "C" fn audio_aggregator_aggregate_one_buffer<T: AudioAggregatorImp
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), true, { gst::panic_to_error!(imp, true, {
imp.aggregate_one_buffer( imp.aggregate_one_buffer(
wrap.unsafe_cast_ref(),
&from_glib_borrow(pad), &from_glib_borrow(pad),
gst::BufferRef::from_ptr(inbuf), gst::BufferRef::from_ptr(inbuf),
in_offset, in_offset,

View file

@ -12,27 +12,25 @@ use crate::AudioAggregatorPad;
pub trait AudioAggregatorPadImpl: AudioAggregatorPadImplExt + AggregatorPadImpl { pub trait AudioAggregatorPadImpl: AudioAggregatorPadImplExt + AggregatorPadImpl {
const HANDLE_CONVERSION: bool = false; const HANDLE_CONVERSION: bool = false;
fn update_conversion_info(&self, pad: &Self::Type) { fn update_conversion_info(&self) {
self.parent_update_conversion_info(pad) self.parent_update_conversion_info()
} }
fn convert_buffer( fn convert_buffer(
&self, &self,
pad: &Self::Type,
in_info: &crate::AudioInfo, in_info: &crate::AudioInfo,
out_info: &crate::AudioInfo, out_info: &crate::AudioInfo,
buffer: &gst::Buffer, buffer: &gst::Buffer,
) -> Option<gst::Buffer> { ) -> Option<gst::Buffer> {
self.parent_convert_buffer(pad, in_info, out_info, buffer) self.parent_convert_buffer(in_info, out_info, buffer)
} }
} }
pub trait AudioAggregatorPadImplExt: ObjectSubclass { pub trait AudioAggregatorPadImplExt: ObjectSubclass {
fn parent_update_conversion_info(&self, pad: &Self::Type); fn parent_update_conversion_info(&self);
fn parent_convert_buffer( fn parent_convert_buffer(
&self, &self,
pad: &Self::Type,
in_info: &crate::AudioInfo, in_info: &crate::AudioInfo,
out_info: &crate::AudioInfo, out_info: &crate::AudioInfo,
buffer: &gst::Buffer, buffer: &gst::Buffer,
@ -40,19 +38,22 @@ pub trait AudioAggregatorPadImplExt: ObjectSubclass {
} }
impl<T: AudioAggregatorPadImpl> AudioAggregatorPadImplExt for T { impl<T: AudioAggregatorPadImpl> AudioAggregatorPadImplExt for T {
fn parent_update_conversion_info(&self, pad: &Self::Type) { fn parent_update_conversion_info(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorPadClass;
if let Some(f) = (*parent_class).update_conversion_info { if let Some(f) = (*parent_class).update_conversion_info {
f(pad.unsafe_cast_ref::<AudioAggregatorPad>().to_glib_none().0); f(self
.instance()
.unsafe_cast_ref::<AudioAggregatorPad>()
.to_glib_none()
.0);
} }
} }
} }
fn parent_convert_buffer( fn parent_convert_buffer(
&self, &self,
pad: &Self::Type,
in_info: &crate::AudioInfo, in_info: &crate::AudioInfo,
out_info: &crate::AudioInfo, out_info: &crate::AudioInfo,
buffer: &gst::Buffer, buffer: &gst::Buffer,
@ -64,7 +65,10 @@ impl<T: AudioAggregatorPadImpl> AudioAggregatorPadImplExt for T {
.convert_buffer .convert_buffer
.expect("Missing parent function `convert_buffer`"); .expect("Missing parent function `convert_buffer`");
from_glib_full(f( from_glib_full(f(
pad.unsafe_cast_ref::<AudioAggregatorPad>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioAggregatorPad>()
.to_glib_none()
.0,
mut_override(in_info.to_glib_none().0), mut_override(in_info.to_glib_none().0),
mut_override(out_info.to_glib_none().0), mut_override(out_info.to_glib_none().0),
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
@ -90,9 +94,8 @@ unsafe extern "C" fn audio_aggregator_pad_update_conversion_info<T: AudioAggrega
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioAggregatorPad> = from_glib_borrow(ptr);
imp.update_conversion_info(wrap.unsafe_cast_ref()); imp.update_conversion_info();
} }
unsafe extern "C" fn audio_aggregator_pad_convert_buffer<T: AudioAggregatorPadImpl>( unsafe extern "C" fn audio_aggregator_pad_convert_buffer<T: AudioAggregatorPadImpl>(
@ -103,10 +106,8 @@ unsafe extern "C" fn audio_aggregator_pad_convert_buffer<T: AudioAggregatorPadIm
) -> *mut gst::ffi::GstBuffer { ) -> *mut gst::ffi::GstBuffer {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioAggregatorPad> = from_glib_borrow(ptr);
imp.convert_buffer( imp.convert_buffer(
wrap.unsafe_cast_ref(),
&from_glib_none(in_info), &from_glib_none(in_info),
&from_glib_none(out_info), &from_glib_none(out_info),
&from_glib_borrow(buffer), &from_glib_borrow(buffer),

View file

@ -12,164 +12,139 @@ use crate::prelude::*;
use crate::AudioDecoder; use crate::AudioDecoder;
pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl { pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self) -> Result<(), gst::ErrorMessage> {
self.parent_open(element) self.parent_open()
} }
fn close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn close(&self) -> Result<(), gst::ErrorMessage> {
self.parent_close(element) self.parent_close()
} }
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn set_format(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> { fn set_format(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_format(element, caps) self.parent_set_format(caps)
} }
fn parse( fn parse(&self, adapter: &gst_base::Adapter) -> Result<(u32, u32), gst::FlowError> {
&self, self.parent_parse(adapter)
element: &Self::Type,
adapter: &gst_base::Adapter,
) -> Result<(u32, u32), gst::FlowError> {
self.parent_parse(element, adapter)
} }
fn handle_frame( fn handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_handle_frame(element, buffer) self.parent_handle_frame(buffer)
} }
fn pre_push( fn pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self, self.parent_pre_push(buffer)
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
self.parent_pre_push(element, buffer)
} }
fn flush(&self, element: &Self::Type, hard: bool) { fn flush(&self, hard: bool) {
self.parent_flush(element, hard) self.parent_flush(hard)
} }
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn negotiate(&self) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate()
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn sink_event(&self, event: gst::Event) -> bool {
self.parent_sink_event(element, event) self.parent_sink_event(event)
} }
fn sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_sink_query(element, query) self.parent_sink_query(query)
} }
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn src_event(&self, event: gst::Event) -> bool {
self.parent_src_event(element, event) self.parent_src_event(event)
} }
fn src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn src_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_src_query(element, query) self.parent_src_query(query)
} }
fn propose_allocation( fn propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_propose_allocation(element, query) self.parent_propose_allocation(query)
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
} }
pub trait AudioDecoderImplExt: ObjectSubclass { pub trait AudioDecoderImplExt: ObjectSubclass {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_open(&self) -> Result<(), gst::ErrorMessage>;
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_close(&self) -> Result<(), gst::ErrorMessage>;
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_set_format( fn parent_set_format(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_parse( fn parent_parse(&self, adapter: &gst_base::Adapter) -> Result<(u32, u32), gst::FlowError>;
&self,
element: &Self::Type,
adapter: &gst_base::Adapter,
) -> Result<(u32, u32), gst::FlowError>;
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_pre_push( fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError>;
&self,
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError>;
fn parent_flush(&self, element: &Self::Type, hard: bool); fn parent_flush(&self, hard: bool);
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>; fn parent_negotiate(&self) -> Result<(), gst::LoggableError>;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps; fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps;
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_sink_event(&self, event: gst::Event) -> bool;
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_src_event(&self, event: gst::Event) -> bool;
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: AudioDecoderImpl> AudioDecoderImplExt for T { impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioDecoder>() .unsafe_cast_ref::<AudioDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -186,14 +161,15 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioDecoder>() .unsafe_cast_ref::<AudioDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -210,14 +186,15 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioDecoder>() .unsafe_cast_ref::<AudioDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -234,14 +211,15 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioDecoder>() .unsafe_cast_ref::<AudioDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -258,11 +236,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_set_format( fn parent_set_format(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -271,7 +245,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
caps.to_glib_none().0 caps.to_glib_none().0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -282,11 +259,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_parse( fn parent_parse(&self, adapter: &gst_base::Adapter) -> Result<(u32, u32), gst::FlowError> {
&self,
element: &Self::Type,
adapter: &gst_base::Adapter,
) -> Result<(u32, u32), gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -296,7 +269,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
let mut offset = mem::MaybeUninit::uninit(); let mut offset = mem::MaybeUninit::uninit();
let mut len = mem::MaybeUninit::uninit(); let mut len = mem::MaybeUninit::uninit();
gst::FlowSuccess::try_from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
adapter.to_glib_none().0, adapter.to_glib_none().0,
offset.as_mut_ptr(), offset.as_mut_ptr(),
len.as_mut_ptr(), len.as_mut_ptr(),
@ -315,7 +291,6 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -325,7 +300,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.handle_frame .handle_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
@ -335,18 +313,17 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_pre_push( fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self,
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_glib_ptr(); let mut buffer = buffer.into_glib_ptr();
gst::FlowSuccess::try_from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
&mut buffer, &mut buffer,
)) ))
.map(|_| from_glib_full(buffer)) .map(|_| from_glib_full(buffer))
@ -356,7 +333,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_flush(&self, element: &Self::Type, hard: bool) { fn parent_flush(&self, hard: bool) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -364,7 +341,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.flush .flush
.map(|f| { .map(|f| {
f( f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
hard.into_glib(), hard.into_glib(),
) )
}) })
@ -372,7 +352,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -380,7 +360,11 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.negotiate .negotiate
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
) )
@ -389,7 +373,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -397,19 +381,22 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.getcaps .getcaps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
element self.instance()
.unsafe_cast_ref::<AudioDecoder>() .unsafe_cast_ref::<AudioDecoder>()
.proxy_getcaps(None, filter) .proxy_getcaps(None, filter)
}) })
} }
} }
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -417,13 +404,16 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -431,13 +421,16 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
} }
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -445,13 +438,16 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
@ -459,7 +455,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
@ -467,7 +466,6 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -478,7 +476,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -491,7 +492,6 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -502,7 +502,10 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -543,13 +546,12 @@ unsafe extern "C" fn audio_decoder_open<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -562,13 +564,12 @@ unsafe extern "C" fn audio_decoder_close<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -581,13 +582,12 @@ unsafe extern "C" fn audio_decoder_start<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -600,13 +600,12 @@ unsafe extern "C" fn audio_decoder_stop<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -620,13 +619,12 @@ unsafe extern "C" fn audio_decoder_set_format<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_borrow(caps)) { match imp.set_format(&from_glib_borrow(caps)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -642,10 +640,9 @@ unsafe extern "C" fn audio_decoder_parse<T: AudioDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.parse(wrap.unsafe_cast_ref(), &from_glib_borrow(adapter)) { match imp.parse(&from_glib_borrow(adapter)) {
Ok((new_offset, new_len)) => { Ok((new_offset, new_len)) => {
assert!(new_offset <= std::i32::MAX as u32); assert!(new_offset <= std::i32::MAX as u32);
assert!(new_len <= std::i32::MAX as u32); assert!(new_len <= std::i32::MAX as u32);
@ -668,14 +665,10 @@ unsafe extern "C" fn audio_decoder_handle_frame<T: AudioDecoderImpl>(
let buffer = buffer as *mut gst::ffi::GstBuffer; let buffer = buffer as *mut gst::ffi::GstBuffer;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.handle_frame( imp.handle_frame(Option::<gst::Buffer>::from_glib_none(buffer).as_ref())
wrap.unsafe_cast_ref(), .into()
Option::<gst::Buffer>::from_glib_none(buffer).as_ref(),
)
.into()
}) })
.into_glib() .into_glib()
} }
@ -686,10 +679,9 @@ unsafe extern "C" fn audio_decoder_pre_push<T: AudioDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) { match imp.pre_push(from_glib_full(*buffer)) {
Ok(Some(new_buffer)) => { Ok(Some(new_buffer)) => {
*buffer = new_buffer.into_glib_ptr(); *buffer = new_buffer.into_glib_ptr();
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
@ -711,11 +703,8 @@ unsafe extern "C" fn audio_decoder_flush<T: AudioDecoderImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), { AudioDecoderImpl::flush(imp, from_glib(hard)) })
AudioDecoderImpl::flush(imp, wrap.unsafe_cast_ref(), from_glib(hard))
})
} }
unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>(
@ -723,13 +712,12 @@ unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -743,12 +731,10 @@ unsafe extern "C" fn audio_decoder_getcaps<T: AudioDecoderImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), {
AudioDecoderImpl::caps( AudioDecoderImpl::caps(
imp, imp,
wrap.unsafe_cast_ref(),
Option::<gst::Caps>::from_glib_borrow(filter) Option::<gst::Caps>::from_glib_borrow(filter)
.as_ref() .as_ref()
.as_ref(), .as_ref(),
@ -763,12 +749,8 @@ unsafe extern "C" fn audio_decoder_sink_event<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>(
@ -777,10 +759,9 @@ unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -791,12 +772,8 @@ unsafe extern "C" fn audio_decoder_src_event<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>(
@ -805,10 +782,9 @@ unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -819,17 +795,16 @@ unsafe extern "C" fn audio_decoder_propose_allocation<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -843,17 +818,16 @@ unsafe extern "C" fn audio_decoder_decide_allocation<T: AudioDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -12,150 +12,133 @@ use crate::AudioEncoder;
use crate::AudioInfo; use crate::AudioInfo;
pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl { pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self) -> Result<(), gst::ErrorMessage> {
self.parent_open(element) self.parent_open()
} }
fn close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn close(&self) -> Result<(), gst::ErrorMessage> {
self.parent_close(element) self.parent_close()
} }
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn set_format(&self, element: &Self::Type, info: &AudioInfo) -> Result<(), gst::LoggableError> { fn set_format(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
self.parent_set_format(element, info) self.parent_set_format(info)
} }
fn handle_frame( fn handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_handle_frame(element, buffer) self.parent_handle_frame(buffer)
} }
fn pre_push( fn pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self, self.parent_pre_push(buffer)
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
self.parent_pre_push(element, buffer)
} }
fn flush(&self, element: &Self::Type) { fn flush(&self) {
self.parent_flush(element) self.parent_flush()
} }
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn negotiate(&self) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate()
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn sink_event(&self, event: gst::Event) -> bool {
self.parent_sink_event(element, event) self.parent_sink_event(event)
} }
fn sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_sink_query(element, query) self.parent_sink_query(query)
} }
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn src_event(&self, event: gst::Event) -> bool {
self.parent_src_event(element, event) self.parent_src_event(event)
} }
fn src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn src_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_src_query(element, query) self.parent_src_query(query)
} }
fn propose_allocation( fn propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_propose_allocation(element, query) self.parent_propose_allocation(query)
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
} }
pub trait AudioEncoderImplExt: ObjectSubclass { pub trait AudioEncoderImplExt: ObjectSubclass {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_open(&self) -> Result<(), gst::ErrorMessage>;
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_close(&self) -> Result<(), gst::ErrorMessage>;
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_set_format( fn parent_set_format(&self, info: &AudioInfo) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
info: &AudioInfo,
) -> Result<(), gst::LoggableError>;
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_pre_push( fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError>;
&self,
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError>;
fn parent_flush(&self, element: &Self::Type); fn parent_flush(&self);
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>; fn parent_negotiate(&self) -> Result<(), gst::LoggableError>;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps; fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps;
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_sink_event(&self, event: gst::Event) -> bool;
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_src_event(&self, event: gst::Event) -> bool;
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: AudioEncoderImpl> AudioEncoderImplExt for T { impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>() .unsafe_cast_ref::<AudioEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -172,14 +155,15 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>() .unsafe_cast_ref::<AudioEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -196,14 +180,15 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>() .unsafe_cast_ref::<AudioEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -220,14 +205,15 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>() .unsafe_cast_ref::<AudioEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -244,11 +230,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_set_format( fn parent_set_format(&self, info: &AudioInfo) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
info: &AudioInfo,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -257,7 +239,10 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
info.to_glib_none().0 as *mut _ info.to_glib_none().0 as *mut _
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -270,7 +255,6 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
buffer: Option<&gst::Buffer>, buffer: Option<&gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -280,7 +264,10 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.handle_frame .handle_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
@ -290,18 +277,17 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_pre_push( fn parent_pre_push(&self, buffer: gst::Buffer) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self,
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_glib_ptr(); let mut buffer = buffer.into_glib_ptr();
gst::FlowSuccess::try_from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
&mut buffer, &mut buffer,
)) ))
.map(|_| from_glib_full(buffer)) .map(|_| from_glib_full(buffer))
@ -311,18 +297,24 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_flush(&self, element: &Self::Type) { fn parent_flush(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.flush .flush
.map(|f| f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0)) .map(|f| {
f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0)
})
.unwrap_or(()) .unwrap_or(())
} }
} }
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -330,7 +322,11 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.negotiate .negotiate
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
) )
@ -339,7 +335,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -347,19 +343,22 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.getcaps .getcaps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
element self.instance()
.unsafe_cast_ref::<AudioEncoder>() .unsafe_cast_ref::<AudioEncoder>()
.proxy_getcaps(None, filter) .proxy_getcaps(None, filter)
}) })
} }
} }
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -367,13 +366,16 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -381,13 +383,16 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
} }
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -395,13 +400,16 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
@ -409,7 +417,10 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
@ -417,7 +428,6 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -428,7 +438,10 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -441,7 +454,6 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -452,7 +464,10 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -492,13 +507,12 @@ unsafe extern "C" fn audio_encoder_open<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -511,13 +525,12 @@ unsafe extern "C" fn audio_encoder_close<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -530,13 +543,12 @@ unsafe extern "C" fn audio_encoder_start<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -549,13 +561,12 @@ unsafe extern "C" fn audio_encoder_stop<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -569,13 +580,12 @@ unsafe extern "C" fn audio_encoder_set_format<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_none(info)) { match imp.set_format(&from_glib_none(info)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -591,14 +601,10 @@ unsafe extern "C" fn audio_encoder_handle_frame<T: AudioEncoderImpl>(
let buffer = buffer as *mut gst::ffi::GstBuffer; let buffer = buffer as *mut gst::ffi::GstBuffer;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.handle_frame( imp.handle_frame(Option::<gst::Buffer>::from_glib_none(buffer).as_ref())
wrap.unsafe_cast_ref(), .into()
Option::<gst::Buffer>::from_glib_none(buffer).as_ref(),
)
.into()
}) })
.into_glib() .into_glib()
} }
@ -609,10 +615,9 @@ unsafe extern "C" fn audio_encoder_pre_push<T: AudioEncoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) { match imp.pre_push(from_glib_full(*buffer)) {
Ok(Some(new_buffer)) => { Ok(Some(new_buffer)) => {
*buffer = new_buffer.into_glib_ptr(); *buffer = new_buffer.into_glib_ptr();
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
@ -631,11 +636,8 @@ unsafe extern "C" fn audio_encoder_pre_push<T: AudioEncoderImpl>(
unsafe extern "C" fn audio_encoder_flush<T: AudioEncoderImpl>(ptr: *mut ffi::GstAudioEncoder) { unsafe extern "C" fn audio_encoder_flush<T: AudioEncoderImpl>(ptr: *mut ffi::GstAudioEncoder) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), { AudioEncoderImpl::flush(imp,) })
AudioEncoderImpl::flush(imp, wrap.unsafe_cast_ref())
})
} }
unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>(
@ -643,13 +645,12 @@ unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -663,12 +664,10 @@ unsafe extern "C" fn audio_encoder_getcaps<T: AudioEncoderImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), {
AudioEncoderImpl::caps( AudioEncoderImpl::caps(
imp, imp,
wrap.unsafe_cast_ref(),
Option::<gst::Caps>::from_glib_borrow(filter) Option::<gst::Caps>::from_glib_borrow(filter)
.as_ref() .as_ref()
.as_ref(), .as_ref(),
@ -683,12 +682,8 @@ unsafe extern "C" fn audio_encoder_sink_event<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>(
@ -697,10 +692,9 @@ unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -711,12 +705,8 @@ unsafe extern "C" fn audio_encoder_src_event<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>(
@ -725,10 +715,9 @@ unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -739,17 +728,16 @@ unsafe extern "C" fn audio_encoder_propose_allocation<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -763,17 +751,16 @@ unsafe extern "C" fn audio_encoder_decide_allocation<T: AudioEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -11,55 +11,47 @@ use crate::AudioRingBufferSpec;
use crate::AudioSink; use crate::AudioSink;
pub trait AudioSinkImpl: AudioSinkImplExt + AudioBaseSinkImpl { pub trait AudioSinkImpl: AudioSinkImplExt + AudioBaseSinkImpl {
fn close(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn close(&self) -> Result<(), LoggableError> {
self.parent_close(sink) self.parent_close()
} }
fn delay(&self, sink: &Self::Type) -> u32 { fn delay(&self) -> u32 {
self.parent_delay(sink) self.parent_delay()
} }
fn open(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn open(&self) -> Result<(), LoggableError> {
self.parent_open(sink) self.parent_open()
} }
fn prepare( fn prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError> {
&self, AudioSinkImplExt::parent_prepare(self, spec)
sink: &Self::Type,
spec: &mut AudioRingBufferSpec,
) -> Result<(), LoggableError> {
AudioSinkImplExt::parent_prepare(self, sink, spec)
} }
fn unprepare(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn unprepare(&self) -> Result<(), LoggableError> {
self.parent_unprepare(sink) self.parent_unprepare()
} }
fn write(&self, sink: &Self::Type, audio_data: &[u8]) -> Result<i32, LoggableError> { fn write(&self, audio_data: &[u8]) -> Result<i32, LoggableError> {
self.parent_write(sink, audio_data) self.parent_write(audio_data)
} }
fn reset(&self, sink: &Self::Type) { fn reset(&self) {
self.parent_reset(sink) self.parent_reset()
} }
} }
pub trait AudioSinkImplExt: ObjectSubclass { pub trait AudioSinkImplExt: ObjectSubclass {
fn parent_close(&self, sink: &Self::Type) -> Result<(), LoggableError>; fn parent_close(&self) -> Result<(), LoggableError>;
fn parent_delay(&self, sink: &Self::Type) -> u32; fn parent_delay(&self) -> u32;
fn parent_open(&self, sink: &Self::Type) -> Result<(), LoggableError>; fn parent_open(&self) -> Result<(), LoggableError>;
fn parent_prepare( fn parent_prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError>;
&self, fn parent_unprepare(&self) -> Result<(), LoggableError>;
sink: &Self::Type, fn parent_write(&self, audio_data: &[u8]) -> Result<i32, LoggableError>;
spec: &mut AudioRingBufferSpec, fn parent_reset(&self);
) -> Result<(), LoggableError>;
fn parent_unprepare(&self, sink: &Self::Type) -> Result<(), LoggableError>;
fn parent_write(&self, sink: &Self::Type, audio_data: &[u8]) -> Result<i32, LoggableError>;
fn parent_reset(&self, sink: &Self::Type);
} }
impl<T: AudioSinkImpl> AudioSinkImplExt for T { impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_close(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_close(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -68,14 +60,18 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
Some(f) => f, Some(f) => f,
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to close element using the parent function" "Failed to close element using the parent function"
) )
} }
} }
fn parent_delay(&self, sink: &Self::Type) -> u32 { fn parent_delay(&self) -> u32 {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -83,11 +79,15 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
Some(f) => f, Some(f) => f,
None => return 0, None => return 0,
}; };
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0)
} }
} }
fn parent_open(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_open(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -96,18 +96,18 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
None => return Ok(()), None => return Ok(()),
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to open element using the parent function" "Failed to open element using the parent function"
) )
} }
} }
fn parent_prepare( fn parent_prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError> {
&self,
sink: &Self::Type,
spec: &mut AudioRingBufferSpec,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -117,7 +117,10 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0,
&mut spec.0 &mut spec.0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -126,7 +129,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
} }
} }
fn parent_unprepare(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_unprepare(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -140,14 +143,18 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
} }
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to unprepare element using the parent function" "Failed to unprepare element using the parent function"
) )
} }
} }
fn parent_write(&self, sink: &Self::Type, buffer: &[u8]) -> Result<i32, LoggableError> { fn parent_write(&self, buffer: &[u8]) -> Result<i32, LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
@ -157,7 +164,10 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
}; };
let buffer_ptr = buffer.as_ptr() as *const _ as *mut _; let buffer_ptr = buffer.as_ptr() as *const _ as *mut _;
let ret = f( let ret = f(
sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0,
buffer_ptr, buffer_ptr,
buffer.len() as u32, buffer.len() as u32,
); );
@ -172,12 +182,16 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
} }
} }
fn parent_reset(&self, sink: &Self::Type) { fn parent_reset(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSinkClass;
if let Some(f) = (*parent_class).reset { if let Some(f) = (*parent_class).reset {
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<AudioSink>()
.to_glib_none()
.0)
} }
} }
} }
@ -202,13 +216,12 @@ unsafe extern "C" fn audiosink_close<T: AudioSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -219,11 +232,8 @@ unsafe extern "C" fn audiosink_close<T: AudioSinkImpl>(
unsafe extern "C" fn audiosink_delay<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink) -> u32 { unsafe extern "C" fn audiosink_delay<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink) -> u32 {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), 0, { gst::panic_to_error!(imp, 0, { imp.delay() })
imp.delay(wrap.unsafe_cast_ref())
})
} }
unsafe extern "C" fn audiosink_open<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_open<T: AudioSinkImpl>(
@ -231,13 +241,12 @@ unsafe extern "C" fn audiosink_open<T: AudioSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -251,15 +260,14 @@ unsafe extern "C" fn audiosink_prepare<T: AudioSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
let spec = &mut *(spec as *mut AudioRingBufferSpec); let spec = &mut *(spec as *mut AudioRingBufferSpec);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match AudioSinkImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) { match AudioSinkImpl::prepare(imp, spec) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -272,13 +280,12 @@ unsafe extern "C" fn audiosink_unprepare<T: AudioSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unprepare(wrap.unsafe_cast_ref()) { match imp.unprepare() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -293,24 +300,20 @@ unsafe extern "C" fn audiosink_write<T: AudioSinkImpl>(
) -> i32 { ) -> i32 {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
let data_slice = if length == 0 { let data_slice = if length == 0 {
&[] &[]
} else { } else {
std::slice::from_raw_parts(data as *const u8, length as usize) std::slice::from_raw_parts(data as *const u8, length as usize)
}; };
gst::panic_to_error!(&wrap, imp.panicked(), -1, { gst::panic_to_error!(imp, -1, { imp.write(data_slice).unwrap_or(-1) })
imp.write(wrap.unsafe_cast_ref(), data_slice).unwrap_or(-1)
})
} }
unsafe extern "C" fn audiosink_reset<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink) { unsafe extern "C" fn audiosink_reset<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), {
imp.reset(wrap.unsafe_cast_ref()); imp.reset();
}); });
} }

View file

@ -13,63 +13,50 @@ use crate::AudioRingBufferSpec;
use crate::AudioSrc; use crate::AudioSrc;
pub trait AudioSrcImpl: AudioSrcImplExt + AudioBaseSrcImpl { pub trait AudioSrcImpl: AudioSrcImplExt + AudioBaseSrcImpl {
fn close(&self, src: &Self::Type) -> Result<(), LoggableError> { fn close(&self) -> Result<(), LoggableError> {
self.parent_close(src) self.parent_close()
} }
fn delay(&self, src: &Self::Type) -> u32 { fn delay(&self) -> u32 {
self.parent_delay(src) self.parent_delay()
} }
fn open(&self, src: &Self::Type) -> Result<(), LoggableError> { fn open(&self) -> Result<(), LoggableError> {
self.parent_open(src) self.parent_open()
} }
fn prepare( fn prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError> {
&self, AudioSrcImplExt::parent_prepare(self, spec)
src: &Self::Type,
spec: &mut AudioRingBufferSpec,
) -> Result<(), LoggableError> {
AudioSrcImplExt::parent_prepare(self, src, spec)
} }
fn unprepare(&self, src: &Self::Type) -> Result<(), LoggableError> { fn unprepare(&self) -> Result<(), LoggableError> {
self.parent_unprepare(src) self.parent_unprepare()
} }
fn read( fn read(&self, audio_data: &mut [u8]) -> Result<(u32, Option<gst::ClockTime>), LoggableError> {
&self, self.parent_read(audio_data)
src: &Self::Type,
audio_data: &mut [u8],
) -> Result<(u32, Option<gst::ClockTime>), LoggableError> {
self.parent_read(src, audio_data)
} }
fn reset(&self, src: &Self::Type) { fn reset(&self) {
self.parent_reset(src) self.parent_reset()
} }
} }
pub trait AudioSrcImplExt: ObjectSubclass { pub trait AudioSrcImplExt: ObjectSubclass {
fn parent_close(&self, src: &Self::Type) -> Result<(), LoggableError>; fn parent_close(&self) -> Result<(), LoggableError>;
fn parent_delay(&self, src: &Self::Type) -> u32; fn parent_delay(&self) -> u32;
fn parent_open(&self, src: &Self::Type) -> Result<(), LoggableError>; fn parent_open(&self) -> Result<(), LoggableError>;
fn parent_prepare( fn parent_prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError>;
&self, fn parent_unprepare(&self) -> Result<(), LoggableError>;
src: &Self::Type,
spec: &mut AudioRingBufferSpec,
) -> Result<(), LoggableError>;
fn parent_unprepare(&self, src: &Self::Type) -> Result<(), LoggableError>;
fn parent_read( fn parent_read(
&self, &self,
src: &Self::Type,
audio_data: &mut [u8], audio_data: &mut [u8],
) -> Result<(u32, Option<gst::ClockTime>), LoggableError>; ) -> Result<(u32, Option<gst::ClockTime>), LoggableError>;
fn parent_reset(&self, src: &Self::Type); fn parent_reset(&self);
} }
impl<T: AudioSrcImpl> AudioSrcImplExt for T { impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_close(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_close(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
@ -78,14 +65,18 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
Some(f) => f, Some(f) => f,
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to close element using the parent function" "Failed to close element using the parent function"
) )
} }
} }
fn parent_delay(&self, src: &Self::Type) -> u32 { fn parent_delay(&self) -> u32 {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
@ -93,11 +84,15 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
Some(f) => f, Some(f) => f,
None => return 0, None => return 0,
}; };
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0)
} }
} }
fn parent_open(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_open(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
@ -106,18 +101,18 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
None => return Ok(()), None => return Ok(()),
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to open element using the parent function" "Failed to open element using the parent function"
) )
} }
} }
fn parent_prepare( fn parent_prepare(&self, spec: &mut AudioRingBufferSpec) -> Result<(), LoggableError> {
&self,
src: &Self::Type,
spec: &mut AudioRingBufferSpec,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
@ -127,7 +122,10 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0,
&mut spec.0 &mut spec.0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -136,7 +134,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
} }
} }
fn parent_unprepare(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_unprepare(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
@ -150,7 +148,11 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
} }
}; };
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to unprepare element using the parent function" "Failed to unprepare element using the parent function"
) )
@ -159,7 +161,6 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_read( fn parent_read(
&self, &self,
src: &Self::Type,
buffer: &mut [u8], buffer: &mut [u8],
) -> Result<(u32, Option<gst::ClockTime>), LoggableError> { ) -> Result<(u32, Option<gst::ClockTime>), LoggableError> {
unsafe { unsafe {
@ -172,7 +173,10 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
let buffer_ptr = buffer.as_mut_ptr() as *mut _; let buffer_ptr = buffer.as_mut_ptr() as *mut _;
let mut timestamp = mem::MaybeUninit::uninit(); let mut timestamp = mem::MaybeUninit::uninit();
let ret = f( let ret = f(
src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0,
buffer_ptr, buffer_ptr,
buffer.len() as u32, buffer.len() as u32,
timestamp.as_mut_ptr(), timestamp.as_mut_ptr(),
@ -188,12 +192,16 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
} }
} }
fn parent_reset(&self, src: &Self::Type) { fn parent_reset(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass;
if let Some(f) = (*parent_class).reset { if let Some(f) = (*parent_class).reset {
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<AudioSrc>()
.to_glib_none()
.0)
} }
} }
} }
@ -218,13 +226,12 @@ unsafe extern "C" fn audiosrc_close<T: AudioSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -235,11 +242,8 @@ unsafe extern "C" fn audiosrc_close<T: AudioSrcImpl>(
unsafe extern "C" fn audiosrc_delay<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc) -> u32 { unsafe extern "C" fn audiosrc_delay<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc) -> u32 {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), 0, { gst::panic_to_error!(imp, 0, { imp.delay() })
imp.delay(wrap.unsafe_cast_ref())
})
} }
unsafe extern "C" fn audiosrc_open<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_open<T: AudioSrcImpl>(
@ -247,13 +251,12 @@ unsafe extern "C" fn audiosrc_open<T: AudioSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -267,15 +270,14 @@ unsafe extern "C" fn audiosrc_prepare<T: AudioSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
let spec = &mut *(spec as *mut AudioRingBufferSpec); let spec = &mut *(spec as *mut AudioRingBufferSpec);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match AudioSrcImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) { match AudioSrcImpl::prepare(imp, spec) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -288,13 +290,12 @@ unsafe extern "C" fn audiosrc_unprepare<T: AudioSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unprepare(wrap.unsafe_cast_ref()) { match imp.unprepare() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -310,17 +311,14 @@ unsafe extern "C" fn audiosrc_read<T: AudioSrcImpl>(
) -> u32 { ) -> u32 {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
let data_slice = if length == 0 { let data_slice = if length == 0 {
&mut [] &mut []
} else { } else {
std::slice::from_raw_parts_mut(data as *mut u8, length as usize) std::slice::from_raw_parts_mut(data as *mut u8, length as usize)
}; };
gst::panic_to_error!(&wrap, imp.panicked(), 0, { gst::panic_to_error!(imp, 0, {
let (res, timestamp_res) = imp let (res, timestamp_res) = imp.read(data_slice).unwrap_or((0, gst::ClockTime::NONE));
.read(wrap.unsafe_cast_ref(), data_slice)
.unwrap_or((0, gst::ClockTime::NONE));
*timestamp = timestamp_res.into_glib(); *timestamp = timestamp_res.into_glib();
res res
@ -330,9 +328,8 @@ unsafe extern "C" fn audiosrc_read<T: AudioSrcImpl>(
unsafe extern "C" fn audiosrc_reset<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc) { unsafe extern "C" fn audiosrc_reset<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), {
imp.reset(wrap.unsafe_cast_ref()); imp.reset();
}); });
} }

File diff suppressed because it is too large Load diff

View file

@ -9,45 +9,23 @@ use crate::Aggregator;
use crate::AggregatorPad; use crate::AggregatorPad;
pub trait AggregatorPadImpl: AggregatorPadImplExt + PadImpl { pub trait AggregatorPadImpl: AggregatorPadImplExt + PadImpl {
fn flush( fn flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_flush(aggregator)
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_flush(aggregator_pad, aggregator)
} }
fn skip_buffer( fn skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
&self, self.parent_skip_buffer(aggregator, buffer)
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
buffer: &gst::Buffer,
) -> bool {
self.parent_skip_buffer(aggregator_pad, aggregator, buffer)
} }
} }
pub trait AggregatorPadImplExt: ObjectSubclass { pub trait AggregatorPadImplExt: ObjectSubclass {
fn parent_flush( fn parent_flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError>;
&self,
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_skip_buffer( fn parent_skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool;
&self,
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
buffer: &gst::Buffer,
) -> bool;
} }
impl<T: AggregatorPadImpl> AggregatorPadImplExt for T { impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
fn parent_flush( fn parent_flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
&self,
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
@ -55,7 +33,7 @@ impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
.flush .flush
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
aggregator_pad self.instance()
.unsafe_cast_ref::<AggregatorPad>() .unsafe_cast_ref::<AggregatorPad>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -66,12 +44,7 @@ impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
} }
} }
fn parent_skip_buffer( fn parent_skip_buffer(&self, aggregator: &Aggregator, buffer: &gst::Buffer) -> bool {
&self,
aggregator_pad: &Self::Type,
aggregator: &Aggregator,
buffer: &gst::Buffer,
) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorPadClass;
@ -79,7 +52,7 @@ impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
.skip_buffer .skip_buffer
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
aggregator_pad self.instance()
.unsafe_cast_ref::<AggregatorPad>() .unsafe_cast_ref::<AggregatorPad>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -106,11 +79,8 @@ unsafe extern "C" fn aggregator_pad_flush<T: AggregatorPadImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AggregatorPad> = from_glib_borrow(ptr);
let res: gst::FlowReturn = imp let res: gst::FlowReturn = imp.flush(&from_glib_borrow(aggregator)).into();
.flush(wrap.unsafe_cast_ref(), &from_glib_borrow(aggregator))
.into();
res.into_glib() res.into_glib()
} }
@ -121,12 +91,7 @@ unsafe extern "C" fn aggregator_pad_skip_buffer<T: AggregatorPadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AggregatorPad> = from_glib_borrow(ptr);
imp.skip_buffer( imp.skip_buffer(&from_glib_borrow(aggregator), &from_glib_borrow(buffer))
wrap.unsafe_cast_ref(), .into_glib()
&from_glib_borrow(aggregator),
&from_glib_borrow(buffer),
)
.into_glib()
} }

View file

@ -12,74 +12,67 @@ use crate::BaseParse;
use crate::BaseParseFrame; use crate::BaseParseFrame;
pub trait BaseParseImpl: BaseParseImplExt + ElementImpl { pub trait BaseParseImpl: BaseParseImplExt + ElementImpl {
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn set_sink_caps( fn set_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_sink_caps(caps)
}
fn handle_frame(
&self, &self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
self.parent_set_sink_caps(element, caps)
}
fn handle_frame<'a>(
&'a self,
element: &Self::Type,
frame: BaseParseFrame, frame: BaseParseFrame,
) -> Result<(gst::FlowSuccess, u32), gst::FlowError> { ) -> Result<(gst::FlowSuccess, u32), gst::FlowError> {
self.parent_handle_frame(element, frame) self.parent_handle_frame(frame)
} }
fn convert( fn convert(
&self, &self,
element: &Self::Type,
src_val: impl gst::FormattedValue, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
self.parent_convert(element, src_val, dest_format) self.parent_convert(src_val, dest_format)
} }
} }
pub trait BaseParseImplExt: ObjectSubclass { pub trait BaseParseImplExt: ObjectSubclass {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_set_sink_caps( fn parent_set_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
fn parent_handle_frame(
&self, &self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_handle_frame<'a>(
&'a self,
element: &Self::Type,
frame: BaseParseFrame, frame: BaseParseFrame,
) -> Result<(gst::FlowSuccess, u32), gst::FlowError>; ) -> Result<(gst::FlowSuccess, u32), gst::FlowError>;
fn parent_convert( fn parent_convert(
&self, &self,
element: &Self::Type,
src_val: impl gst::FormattedValue, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue>; ) -> Option<gst::GenericFormattedValue>;
} }
impl<T: BaseParseImpl> BaseParseImplExt for T { impl<T: BaseParseImpl> BaseParseImplExt for T {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseParse>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseParse>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -92,14 +85,19 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseParse>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseParse>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -112,11 +110,7 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
} }
} }
fn parent_set_sink_caps( fn parent_set_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass;
@ -125,7 +119,10 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<BaseParse>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseParse>()
.to_glib_none()
.0,
caps.to_glib_none().0, caps.to_glib_none().0,
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -136,9 +133,8 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
} }
} }
fn parent_handle_frame<'a>( fn parent_handle_frame(
&'a self, &self,
element: &'a Self::Type,
frame: BaseParseFrame, frame: BaseParseFrame,
) -> Result<(gst::FlowSuccess, u32), gst::FlowError> { ) -> Result<(gst::FlowSuccess, u32), gst::FlowError> {
unsafe { unsafe {
@ -149,7 +145,10 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
.handle_frame .handle_frame
.map(|f| { .map(|f| {
let res = try_from_glib(f( let res = try_from_glib(f(
element.unsafe_cast_ref::<BaseParse>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseParse>()
.to_glib_none()
.0,
frame.to_glib_none().0, frame.to_glib_none().0,
&mut skipsize, &mut skipsize,
)); ));
@ -161,7 +160,6 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
fn parent_convert( fn parent_convert(
&self, &self,
element: &Self::Type,
src_val: impl gst::FormattedValue, src_val: impl gst::FormattedValue,
dest_format: gst::Format, dest_format: gst::Format,
) -> Option<gst::GenericFormattedValue> { ) -> Option<gst::GenericFormattedValue> {
@ -172,7 +170,10 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let res = from_glib(f( let res = from_glib(f(
element.unsafe_cast_ref::<BaseParse>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseParse>()
.to_glib_none()
.0,
src_val.format().into_glib(), src_val.format().into_glib(),
src_val.into_raw_value(), src_val.into_raw_value(),
dest_format.into_glib(), dest_format.into_glib(),
@ -209,13 +210,12 @@ unsafe extern "C" fn base_parse_start<T: BaseParseImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseParse> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -228,13 +228,12 @@ unsafe extern "C" fn base_parse_stop<T: BaseParseImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseParse> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -248,14 +247,13 @@ unsafe extern "C" fn base_parse_set_sink_caps<T: BaseParseImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseParse> = from_glib_borrow(ptr);
let caps: Borrowed<gst::Caps> = from_glib_borrow(caps); let caps: Borrowed<gst::Caps> = from_glib_borrow(caps);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_sink_caps(wrap.unsafe_cast_ref(), &caps) { match imp.set_sink_caps(&caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -270,11 +268,12 @@ unsafe extern "C" fn base_parse_handle_frame<T: BaseParseImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseParse> = from_glib_borrow(ptr); let instance = imp.instance();
let wrap_frame = BaseParseFrame::new(frame, &wrap); let instance = instance.unsafe_cast_ref::<BaseParse>();
let wrap_frame = BaseParseFrame::new(frame, instance);
let res = gst::panic_to_error!(&wrap, imp.panicked(), Err(gst::FlowError::Error), { let res = gst::panic_to_error!(imp, Err(gst::FlowError::Error), {
imp.handle_frame(wrap.unsafe_cast_ref(), wrap_frame) imp.handle_frame(wrap_frame)
}); });
match res { match res {
@ -296,12 +295,9 @@ unsafe extern "C" fn base_parse_convert<T: BaseParseImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseParse> = from_glib_borrow(ptr);
let source = gst::GenericFormattedValue::new(from_glib(source_format), source_value); let source = gst::GenericFormattedValue::new(from_glib(source_format), source_value);
let res = gst::panic_to_error!(&wrap, imp.panicked(), None, { let res = gst::panic_to_error!(imp, None, { imp.convert(source, from_glib(dest_format)) });
imp.convert(wrap.unsafe_cast_ref(), source, from_glib(dest_format))
});
match res { match res {
Some(dest) => { Some(dest) => {

View file

@ -10,146 +10,119 @@ use std::ptr;
use crate::BaseSink; use crate::BaseSink;
pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl { pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl {
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn render( fn render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_render(buffer)
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_render(element, buffer)
} }
fn prepare( fn prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_prepare(buffer)
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_prepare(element, buffer)
} }
fn render_list( fn render_list(&self, list: &gst::BufferList) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_render_list(list)
element: &Self::Type,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_render_list(element, list)
} }
fn prepare_list( fn prepare_list(&self, list: &gst::BufferList) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_prepare_list(list)
element: &Self::Type,
list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_prepare_list(element, list)
} }
fn query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn query(&self, query: &mut gst::QueryRef) -> bool {
BaseSinkImplExt::parent_query(self, element, query) BaseSinkImplExt::parent_query(self, query)
} }
fn event(&self, element: &Self::Type, event: gst::Event) -> bool { fn event(&self, event: gst::Event) -> bool {
self.parent_event(element, event) self.parent_event(event)
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps> { fn caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> { fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(caps)
} }
fn fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps { fn fixate(&self, caps: gst::Caps) -> gst::Caps {
self.parent_fixate(element, caps) self.parent_fixate(caps)
} }
fn unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock(&self) -> Result<(), gst::ErrorMessage> {
self.parent_unlock(element) self.parent_unlock()
} }
fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_unlock_stop(element) self.parent_unlock_stop()
} }
fn propose_allocation( fn propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_propose_allocation(element, query) self.parent_propose_allocation(query)
} }
} }
pub trait BaseSinkImplExt: ObjectSubclass { pub trait BaseSinkImplExt: ObjectSubclass {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_render( fn parent_render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_prepare( fn parent_prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_render_list( fn parent_render_list(
&self, &self,
element: &Self::Type,
list: &gst::BufferList, list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_prepare_list( fn parent_prepare_list(
&self, &self,
element: &Self::Type,
list: &gst::BufferList, list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_event(&self, event: gst::Event) -> bool;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps>; fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps; fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps;
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock(&self) -> Result<(), gst::ErrorMessage>;
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: BaseSinkImpl> BaseSinkImplExt for T { impl<T: BaseSinkImpl> BaseSinkImplExt for T {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSink>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -162,14 +135,19 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSink>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -182,11 +160,7 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_render( fn parent_render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -194,7 +168,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.render .render
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
@ -202,11 +179,7 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_prepare( fn parent_prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -214,7 +187,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.prepare .prepare
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
@ -224,7 +200,6 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
fn parent_render_list( fn parent_render_list(
&self, &self,
element: &Self::Type,
list: &gst::BufferList, list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -234,13 +209,16 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.render_list .render_list
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
list.to_glib_none().0, list.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
for buffer in list.iter() { for buffer in list.iter() {
self.render(element, &from_glib_borrow(buffer.as_ptr()))?; self.render(&from_glib_borrow(buffer.as_ptr()))?;
} }
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
}) })
@ -249,7 +227,6 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
fn parent_prepare_list( fn parent_prepare_list(
&self, &self,
element: &Self::Type,
list: &gst::BufferList, list: &gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -259,20 +236,23 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.prepare_list .prepare_list
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
list.to_glib_none().0, list.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
for buffer in list.iter() { for buffer in list.iter() {
self.prepare(element, &from_glib_borrow(buffer.as_ptr()))?; self.prepare(&from_glib_borrow(buffer.as_ptr()))?;
} }
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
}) })
} }
} }
fn parent_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -280,7 +260,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.query .query
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
}) })
@ -288,7 +271,7 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -296,7 +279,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.event .event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
}) })
@ -304,7 +290,7 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps> { fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -313,7 +299,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.get_caps .get_caps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
@ -321,11 +310,7 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
@ -334,7 +319,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
caps.to_glib_none().0 caps.to_glib_none().0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -345,14 +333,17 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps { fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
match (*parent_class).fixate { match (*parent_class).fixate {
Some(fixate) => from_glib_full(fixate( Some(fixate) => from_glib_full(fixate(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
caps.into_glib_ptr(), caps.into_glib_ptr(),
)), )),
None => caps, None => caps,
@ -360,14 +351,19 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_unlock(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class) (*parent_class)
.unlock .unlock
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSink>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -380,14 +376,19 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
} }
} }
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
(*parent_class) (*parent_class)
.unlock_stop .unlock_stop
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSink>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -402,7 +403,6 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -413,7 +413,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSink>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -451,13 +454,12 @@ unsafe extern "C" fn base_sink_start<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -470,13 +472,12 @@ unsafe extern "C" fn base_sink_stop<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -490,13 +491,9 @@ unsafe extern "C" fn base_sink_render<T: BaseSinkImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let buffer = from_glib_borrow(buffer); let buffer = from_glib_borrow(buffer);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.render(&buffer).into() }).into_glib()
imp.render(wrap.unsafe_cast_ref(), &buffer).into()
})
.into_glib()
} }
unsafe extern "C" fn base_sink_prepare<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_prepare<T: BaseSinkImpl>(
@ -505,13 +502,9 @@ unsafe extern "C" fn base_sink_prepare<T: BaseSinkImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let buffer = from_glib_borrow(buffer); let buffer = from_glib_borrow(buffer);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.prepare(&buffer).into() }).into_glib()
imp.prepare(wrap.unsafe_cast_ref(), &buffer).into()
})
.into_glib()
} }
unsafe extern "C" fn base_sink_render_list<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_render_list<T: BaseSinkImpl>(
@ -520,11 +513,10 @@ unsafe extern "C" fn base_sink_render_list<T: BaseSinkImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let list = from_glib_borrow(list); let list = from_glib_borrow(list);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.render_list(wrap.unsafe_cast_ref(), &list).into() imp.render_list(&list).into()
}) })
.into_glib() .into_glib()
} }
@ -535,11 +527,10 @@ unsafe extern "C" fn base_sink_prepare_list<T: BaseSinkImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let list = from_glib_borrow(list); let list = from_glib_borrow(list);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.prepare_list(wrap.unsafe_cast_ref(), &list).into() imp.prepare_list(&list).into()
}) })
.into_glib() .into_glib()
} }
@ -550,13 +541,9 @@ unsafe extern "C" fn base_sink_query<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query_ptr); let query = gst::QueryRef::from_mut_ptr(query_ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { BaseSinkImpl::query(imp, query) }).into_glib()
BaseSinkImpl::query(imp, wrap.unsafe_cast_ref(), query)
})
.into_glib()
} }
unsafe extern "C" fn base_sink_event<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_event<T: BaseSinkImpl>(
@ -565,12 +552,8 @@ unsafe extern "C" fn base_sink_event<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.event(from_glib_full(event_ptr)) }).into_glib()
imp.event(wrap.unsafe_cast_ref(), from_glib_full(event_ptr))
})
.into_glib()
} }
unsafe extern "C" fn base_sink_get_caps<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_get_caps<T: BaseSinkImpl>(
@ -579,14 +562,11 @@ unsafe extern "C" fn base_sink_get_caps<T: BaseSinkImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let filter = Option::<gst::Caps>::from_glib_borrow(filter); let filter = Option::<gst::Caps>::from_glib_borrow(filter);
gst::panic_to_error!(&wrap, imp.panicked(), None, { gst::panic_to_error!(imp, None, { imp.caps(filter.as_ref().as_ref()) })
imp.caps(wrap.unsafe_cast_ref(), filter.as_ref().as_ref()) .map(|caps| caps.into_glib_ptr())
}) .unwrap_or(ptr::null_mut())
.map(|caps| caps.into_glib_ptr())
.unwrap_or(ptr::null_mut())
} }
unsafe extern "C" fn base_sink_set_caps<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_set_caps<T: BaseSinkImpl>(
@ -595,14 +575,13 @@ unsafe extern "C" fn base_sink_set_caps<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let caps = from_glib_borrow(caps); let caps = from_glib_borrow(caps);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_caps(wrap.unsafe_cast_ref(), &caps) { match imp.set_caps(&caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -616,13 +595,9 @@ unsafe extern "C" fn base_sink_fixate<T: BaseSinkImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let caps = from_glib_full(caps); let caps = from_glib_full(caps);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), { imp.fixate(caps) }).into_glib_ptr()
imp.fixate(wrap.unsafe_cast_ref(), caps)
})
.into_glib_ptr()
} }
unsafe extern "C" fn base_sink_unlock<T: BaseSinkImpl>( unsafe extern "C" fn base_sink_unlock<T: BaseSinkImpl>(
@ -630,13 +605,12 @@ unsafe extern "C" fn base_sink_unlock<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unlock(wrap.unsafe_cast_ref()) { match imp.unlock() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -649,13 +623,12 @@ unsafe extern "C" fn base_sink_unlock_stop<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unlock_stop(wrap.unsafe_cast_ref()) { match imp.unlock_stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -669,17 +642,16 @@ unsafe extern "C" fn base_sink_propose_allocation<T: BaseSinkImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -27,181 +27,161 @@ pub enum CreateSuccess {
} }
pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl { pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl {
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn is_seekable(&self, element: &Self::Type) -> bool { fn is_seekable(&self) -> bool {
self.parent_is_seekable(element) self.parent_is_seekable()
} }
fn size(&self, element: &Self::Type) -> Option<u64> { fn size(&self) -> Option<u64> {
self.parent_size(element) self.parent_size()
} }
#[doc(alias = "get_times")] #[doc(alias = "get_times")]
fn times( fn times(&self, buffer: &gst::BufferRef) -> (Option<gst::ClockTime>, Option<gst::ClockTime>) {
&self, self.parent_times(buffer)
element: &Self::Type,
buffer: &gst::BufferRef,
) -> (Option<gst::ClockTime>, Option<gst::ClockTime>) {
self.parent_times(element, buffer)
} }
fn fill( fn fill(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
length: u32, length: u32,
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_fill(element, offset, length, buffer) self.parent_fill(offset, length, buffer)
} }
fn alloc( fn alloc(&self, offset: u64, length: u32) -> Result<gst::Buffer, gst::FlowError> {
&self, self.parent_alloc(offset, length)
element: &Self::Type,
offset: u64,
length: u32,
) -> Result<gst::Buffer, gst::FlowError> {
self.parent_alloc(element, offset, length)
} }
fn create( fn create(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
buffer: Option<&mut gst::BufferRef>, buffer: Option<&mut gst::BufferRef>,
length: u32, length: u32,
) -> Result<CreateSuccess, gst::FlowError> { ) -> Result<CreateSuccess, gst::FlowError> {
self.parent_create(element, offset, buffer, length) self.parent_create(offset, buffer, length)
} }
fn do_seek(&self, element: &Self::Type, segment: &mut gst::Segment) -> bool { fn do_seek(&self, segment: &mut gst::Segment) -> bool {
self.parent_do_seek(element, segment) self.parent_do_seek(segment)
} }
fn query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn query(&self, query: &mut gst::QueryRef) -> bool {
BaseSrcImplExt::parent_query(self, element, query) BaseSrcImplExt::parent_query(self, query)
} }
fn event(&self, element: &Self::Type, event: &gst::Event) -> bool { fn event(&self, event: &gst::Event) -> bool {
self.parent_event(element, event) self.parent_event(event)
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps> { fn caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn negotiate(&self) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate()
} }
fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> { fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(caps)
} }
fn fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps { fn fixate(&self, caps: gst::Caps) -> gst::Caps {
self.parent_fixate(element, caps) self.parent_fixate(caps)
} }
fn unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock(&self) -> Result<(), gst::ErrorMessage> {
self.parent_unlock(element) self.parent_unlock()
} }
fn unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_unlock_stop(element) self.parent_unlock_stop()
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
} }
pub trait BaseSrcImplExt: ObjectSubclass { pub trait BaseSrcImplExt: ObjectSubclass {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_is_seekable(&self, element: &Self::Type) -> bool; fn parent_is_seekable(&self) -> bool;
fn parent_size(&self, element: &Self::Type) -> Option<u64>; fn parent_size(&self) -> Option<u64>;
fn parent_times( fn parent_times(
&self, &self,
element: &Self::Type,
buffer: &gst::BufferRef, buffer: &gst::BufferRef,
) -> (Option<gst::ClockTime>, Option<gst::ClockTime>); ) -> (Option<gst::ClockTime>, Option<gst::ClockTime>);
fn parent_fill( fn parent_fill(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
length: u32, length: u32,
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_alloc( fn parent_alloc(&self, offset: u64, length: u32) -> Result<gst::Buffer, gst::FlowError>;
&self,
element: &Self::Type,
offset: u64,
length: u32,
) -> Result<gst::Buffer, gst::FlowError>;
fn parent_create( fn parent_create(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
buffer: Option<&mut gst::BufferRef>, buffer: Option<&mut gst::BufferRef>,
length: u32, length: u32,
) -> Result<CreateSuccess, gst::FlowError>; ) -> Result<CreateSuccess, gst::FlowError>;
fn parent_do_seek(&self, element: &Self::Type, segment: &mut gst::Segment) -> bool; fn parent_do_seek(&self, segment: &mut gst::Segment) -> bool;
fn parent_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_event(&self, element: &Self::Type, event: &gst::Event) -> bool; fn parent_event(&self, event: &gst::Event) -> bool;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps>; fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>; fn parent_negotiate(&self) -> Result<(), gst::LoggableError>;
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps; fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps;
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock(&self) -> Result<(), gst::ErrorMessage>;
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: BaseSrcImpl> BaseSrcImplExt for T { impl<T: BaseSrcImpl> BaseSrcImplExt for T {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -214,14 +194,19 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -234,18 +219,24 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_is_seekable(&self, element: &Self::Type) -> bool { fn parent_is_seekable(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) (*parent_class)
.is_seekable .is_seekable
.map(|f| from_glib(f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0))) .map(|f| {
from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0))
})
.unwrap_or(false) .unwrap_or(false)
} }
} }
fn parent_size(&self, element: &Self::Type) -> Option<u64> { fn parent_size(&self) -> Option<u64> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -254,7 +245,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.map(|f| { .map(|f| {
let mut size = mem::MaybeUninit::uninit(); let mut size = mem::MaybeUninit::uninit();
if from_glib(f( if from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
size.as_mut_ptr(), size.as_mut_ptr(),
)) { )) {
Some(size.assume_init()) Some(size.assume_init())
@ -268,7 +262,6 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
fn parent_times( fn parent_times(
&self, &self,
element: &Self::Type,
buffer: &gst::BufferRef, buffer: &gst::BufferRef,
) -> (Option<gst::ClockTime>, Option<gst::ClockTime>) { ) -> (Option<gst::ClockTime>, Option<gst::ClockTime>) {
unsafe { unsafe {
@ -280,7 +273,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
let mut start = mem::MaybeUninit::uninit(); let mut start = mem::MaybeUninit::uninit();
let mut stop = mem::MaybeUninit::uninit(); let mut stop = mem::MaybeUninit::uninit();
f( f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
start.as_mut_ptr(), start.as_mut_ptr(),
stop.as_mut_ptr(), stop.as_mut_ptr(),
@ -296,7 +292,6 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
fn parent_fill( fn parent_fill(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
length: u32, length: u32,
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
@ -308,7 +303,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.fill .fill
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
offset, offset,
length, length,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
@ -318,12 +316,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_alloc( fn parent_alloc(&self, offset: u64, length: u32) -> Result<gst::Buffer, gst::FlowError> {
&self,
element: &Self::Type,
offset: u64,
length: u32,
) -> Result<gst::Buffer, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -337,7 +330,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
gst::FlowSuccess::try_from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
offset, offset,
length, length,
buffer_ref, buffer_ref,
@ -350,7 +346,6 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
fn parent_create( fn parent_create(
&self, &self,
element: &Self::Type,
offset: u64, offset: u64,
mut buffer: Option<&mut gst::BufferRef>, mut buffer: Option<&mut gst::BufferRef>,
length: u32, length: u32,
@ -361,6 +356,8 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
(*parent_class) (*parent_class)
.create .create
.map(|f| { .map(|f| {
let instance = self.instance();
let instance = instance.unsafe_cast_ref::<BaseSrc>();
let orig_buffer_ptr = buffer let orig_buffer_ptr = buffer
.as_mut() .as_mut()
.map(|b| b.as_mut_ptr()) .map(|b| b.as_mut_ptr())
@ -375,7 +372,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
if let Err(err) = gst::FlowSuccess::try_from_glib( if let Err(err) = gst::FlowSuccess::try_from_glib(
f( f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, instance.to_glib_none().0,
offset, offset,
length, length,
buffer_ref, buffer_ref,
@ -387,14 +384,14 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
let pending_buffer_list = instance_data.pending_buffer_list.borrow_mut().take(); let pending_buffer_list = instance_data.pending_buffer_list.borrow_mut().take();
if pending_buffer_list.is_some() && if pending_buffer_list.is_some() &&
(buffer.is_some() || element.unsafe_cast_ref::<BaseSrc>().src_pad().mode() == gst::PadMode::Pull) { (buffer.is_some() || instance.src_pad().mode() == gst::PadMode::Pull) {
panic!("Buffer lists can only be returned in push mode"); panic!("Buffer lists can only be returned in push mode");
} }
if buffer_ptr.is_null() && pending_buffer_list.is_none() { if buffer_ptr.is_null() && pending_buffer_list.is_none() {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<BaseSrc>(), obj: instance,
"No buffer and no buffer list returned" "No buffer and no buffer list returned"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -403,7 +400,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
if !buffer_ptr.is_null() && pending_buffer_list.is_some() { if !buffer_ptr.is_null() && pending_buffer_list.is_some() {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<BaseSrc>(), obj: instance,
"Both buffer and buffer list returned" "Both buffer and buffer list returned"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -415,7 +412,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
gst::debug!( gst::debug!(
gst::CAT_PERFORMANCE, gst::CAT_PERFORMANCE,
obj: element.unsafe_cast_ref::<BaseSrc>(), obj: instance,
"Returned new buffer from parent create function, copying into passed buffer" "Returned new buffer from parent create function, copying into passed buffer"
); );
@ -424,7 +421,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<BaseSrc>(), obj: instance,
"Failed to map passed buffer writable" "Failed to map passed buffer writable"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -443,7 +440,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<BaseSrc>(), obj: instance,
"Failed to copy buffer metadata" "Failed to copy buffer metadata"
); );
@ -463,7 +460,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_do_seek(&self, element: &Self::Type, segment: &mut gst::Segment) -> bool { fn parent_do_seek(&self, segment: &mut gst::Segment) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -471,7 +468,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.do_seek .do_seek
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
segment.to_glib_none_mut().0, segment.to_glib_none_mut().0,
)) ))
}) })
@ -479,7 +479,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -487,7 +487,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.query .query
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
}) })
@ -495,7 +498,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_event(&self, element: &Self::Type, event: &gst::Event) -> bool { fn parent_event(&self, event: &gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -503,7 +506,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.event .event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
event.to_glib_none().0, event.to_glib_none().0,
)) ))
}) })
@ -511,7 +517,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> Option<gst::Caps> { fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -520,7 +526,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.get_caps .get_caps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
@ -528,7 +537,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -536,7 +545,11 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.negotiate .negotiate
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
) )
@ -545,11 +558,7 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
@ -558,7 +567,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
caps.to_glib_none().0 caps.to_glib_none().0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -569,14 +581,17 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_fixate(&self, element: &Self::Type, caps: gst::Caps) -> gst::Caps { fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
match (*parent_class).fixate { match (*parent_class).fixate {
Some(fixate) => from_glib_full(fixate( Some(fixate) => from_glib_full(fixate(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
caps.into_glib_ptr(), caps.into_glib_ptr(),
)), )),
None => caps, None => caps,
@ -584,14 +599,19 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_unlock(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_unlock(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) (*parent_class)
.unlock .unlock
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -604,14 +624,19 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
} }
} }
fn parent_unlock_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass;
(*parent_class) (*parent_class)
.unlock_stop .unlock_stop
.map(|f| { .map(|f| {
if from_glib(f(element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0)) { if from_glib(f(self
.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0))
{
Ok(()) Ok(())
} else { } else {
Err(gst::error_msg!( Err(gst::error_msg!(
@ -626,7 +651,6 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -637,7 +661,10 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<BaseSrc>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -685,13 +712,12 @@ unsafe extern "C" fn base_src_start<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -704,13 +730,12 @@ unsafe extern "C" fn base_src_stop<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -723,12 +748,8 @@ unsafe extern "C" fn base_src_is_seekable<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.is_seekable() }).into_glib()
imp.is_seekable(wrap.unsafe_cast_ref())
})
.into_glib()
} }
unsafe extern "C" fn base_src_get_size<T: BaseSrcImpl>( unsafe extern "C" fn base_src_get_size<T: BaseSrcImpl>(
@ -737,10 +758,9 @@ unsafe extern "C" fn base_src_get_size<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.size(wrap.unsafe_cast_ref()) { match imp.size() {
Some(s) => { Some(s) => {
*size = s; *size = s;
true true
@ -759,14 +779,13 @@ unsafe extern "C" fn base_src_get_times<T: BaseSrcImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_ptr(buffer); let buffer = gst::BufferRef::from_ptr(buffer);
*start = gst::ffi::GST_CLOCK_TIME_NONE; *start = gst::ffi::GST_CLOCK_TIME_NONE;
*stop = gst::ffi::GST_CLOCK_TIME_NONE; *stop = gst::ffi::GST_CLOCK_TIME_NONE;
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), {
let (start_, stop_) = imp.times(wrap.unsafe_cast_ref(), buffer); let (start_, stop_) = imp.times(buffer);
*start = start_.into_glib(); *start = start_.into_glib();
*stop = stop_.into_glib(); *stop = stop_.into_glib();
}); });
@ -780,12 +799,10 @@ unsafe extern "C" fn base_src_fill<T: BaseSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_mut_ptr(buffer); let buffer = gst::BufferRef::from_mut_ptr(buffer);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.fill(wrap.unsafe_cast_ref(), offset, length, buffer) imp.fill(offset, length, buffer).into()
.into()
}) })
.into_glib() .into_glib()
} }
@ -798,13 +815,12 @@ unsafe extern "C" fn base_src_alloc<T: BaseSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
// FIXME: Wrong signature in -sys bindings // FIXME: Wrong signature in -sys bindings
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer; let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer;
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.alloc(wrap.unsafe_cast_ref(), offset, length) { match imp.alloc(offset, length) {
Ok(buffer) => { Ok(buffer) => {
*buffer_ptr = buffer.into_glib_ptr(); *buffer_ptr = buffer.into_glib_ptr();
gst::FlowReturn::Ok gst::FlowReturn::Ok
@ -824,7 +840,8 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr); let instance = imp.instance();
let instance = instance.unsafe_cast_ref::<BaseSrc>();
// FIXME: Wrong signature in -sys bindings // FIXME: Wrong signature in -sys bindings
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer; let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer;
@ -840,23 +857,18 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
.unwrap(); .unwrap();
// If there is a pending buffer list at this point then unset it. // If there is a pending buffer list at this point then unset it.
if wrap.type_() == T::Type::static_type() { if instance.type_() == T::Type::static_type() {
*instance_data.pending_buffer_list.borrow_mut() = None; *instance_data.pending_buffer_list.borrow_mut() = None;
} }
let res = gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { let res = gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.create( match imp.create(offset, buffer.as_deref_mut(), length) {
wrap.unsafe_cast_ref(),
offset,
buffer.as_deref_mut(),
length,
) {
Ok(CreateSuccess::NewBuffer(new_buffer)) => { Ok(CreateSuccess::NewBuffer(new_buffer)) => {
if let Some(passed_buffer) = buffer { if let Some(passed_buffer) = buffer {
if passed_buffer.as_ptr() != new_buffer.as_ptr() { if passed_buffer.as_ptr() != new_buffer.as_ptr() {
gst::debug!( gst::debug!(
gst::CAT_PERFORMANCE, gst::CAT_PERFORMANCE,
obj: &*wrap, obj: instance,
"Returned new buffer from create function, copying into passed buffer" "Returned new buffer from create function, copying into passed buffer"
); );
@ -865,7 +877,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: &*wrap, obj: instance,
"Failed to map passed buffer writable" "Failed to map passed buffer writable"
); );
return gst::FlowReturn::Error; return gst::FlowReturn::Error;
@ -889,7 +901,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: &*wrap, obj: instance,
"Failed to copy buffer metadata" "Failed to copy buffer metadata"
); );
@ -905,9 +917,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
} }
} }
Ok(CreateSuccess::NewBufferList(new_buffer_list)) => { Ok(CreateSuccess::NewBufferList(new_buffer_list)) => {
if buffer.is_some() if buffer.is_some() || instance.src_pad().mode() == gst::PadMode::Pull {
|| wrap.unsafe_cast_ref::<BaseSrc>().src_pad().mode() == gst::PadMode::Pull
{
panic!("Buffer lists can only be returned in push mode"); panic!("Buffer lists can only be returned in push mode");
} }
@ -916,9 +926,9 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
// If this is the final type then submit the buffer list. This can only be done // If this is the final type then submit the buffer list. This can only be done
// once so can only really be done here. // once so can only really be done here.
// FIXME: This won't work if a non-Rust subclass of a Rust subclass is created. // FIXME: This won't work if a non-Rust subclass of a Rust subclass is created.
if wrap.type_() == T::Type::static_type() { if instance.type_() == T::Type::static_type() {
ffi::gst_base_src_submit_buffer_list( ffi::gst_base_src_submit_buffer_list(
wrap.to_glib_none().0, instance.to_glib_none().0,
new_buffer_list.into_glib_ptr(), new_buffer_list.into_glib_ptr(),
); );
} else { } else {
@ -934,7 +944,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcImpl>(
.into_glib(); .into_glib();
// If there is a pending buffer list at this point then unset it. // If there is a pending buffer list at this point then unset it.
if wrap.type_() == T::Type::static_type() { if instance.type_() == T::Type::static_type() {
*instance_data.pending_buffer_list.borrow_mut() = None; *instance_data.pending_buffer_list.borrow_mut() = None;
} }
@ -947,11 +957,10 @@ unsafe extern "C" fn base_src_do_seek<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
let mut s = from_glib_none(segment); let mut s = from_glib_none(segment);
let res = imp.do_seek(wrap.unsafe_cast_ref(), &mut s); let res = imp.do_seek(&mut s);
ptr::write(segment, *(s.to_glib_none().0)); ptr::write(segment, *(s.to_glib_none().0));
res res
@ -965,13 +974,9 @@ unsafe extern "C" fn base_src_query<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query_ptr); let query = gst::QueryRef::from_mut_ptr(query_ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { BaseSrcImpl::query(imp, query) }).into_glib()
BaseSrcImpl::query(imp, wrap.unsafe_cast_ref(), query)
})
.into_glib()
} }
unsafe extern "C" fn base_src_event<T: BaseSrcImpl>( unsafe extern "C" fn base_src_event<T: BaseSrcImpl>(
@ -980,12 +985,8 @@ unsafe extern "C" fn base_src_event<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.event(&from_glib_borrow(event_ptr)) }).into_glib()
imp.event(wrap.unsafe_cast_ref(), &from_glib_borrow(event_ptr))
})
.into_glib()
} }
unsafe extern "C" fn base_src_get_caps<T: BaseSrcImpl>( unsafe extern "C" fn base_src_get_caps<T: BaseSrcImpl>(
@ -994,14 +995,11 @@ unsafe extern "C" fn base_src_get_caps<T: BaseSrcImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let filter = Option::<gst::Caps>::from_glib_borrow(filter); let filter = Option::<gst::Caps>::from_glib_borrow(filter);
gst::panic_to_error!(&wrap, imp.panicked(), None, { gst::panic_to_error!(imp, None, { imp.caps(filter.as_ref().as_ref()) })
imp.caps(wrap.unsafe_cast_ref(), filter.as_ref().as_ref()) .map(|caps| caps.into_glib_ptr())
}) .unwrap_or(ptr::null_mut())
.map(|caps| caps.into_glib_ptr())
.unwrap_or(ptr::null_mut())
} }
unsafe extern "C" fn base_src_negotiate<T: BaseSrcImpl>( unsafe extern "C" fn base_src_negotiate<T: BaseSrcImpl>(
@ -1009,13 +1007,12 @@ unsafe extern "C" fn base_src_negotiate<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -1029,14 +1026,13 @@ unsafe extern "C" fn base_src_set_caps<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let caps = from_glib_borrow(caps); let caps = from_glib_borrow(caps);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_caps(wrap.unsafe_cast_ref(), &caps) { match imp.set_caps(&caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -1050,13 +1046,9 @@ unsafe extern "C" fn base_src_fixate<T: BaseSrcImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let caps = from_glib_full(caps); let caps = from_glib_full(caps);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), { imp.fixate(caps) }).into_glib_ptr()
imp.fixate(wrap.unsafe_cast_ref(), caps)
})
.into_glib_ptr()
} }
unsafe extern "C" fn base_src_unlock<T: BaseSrcImpl>( unsafe extern "C" fn base_src_unlock<T: BaseSrcImpl>(
@ -1064,13 +1056,12 @@ unsafe extern "C" fn base_src_unlock<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unlock(wrap.unsafe_cast_ref()) { match imp.unlock() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -1083,13 +1074,12 @@ unsafe extern "C" fn base_src_unlock_stop<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.unlock_stop(wrap.unsafe_cast_ref()) { match imp.unlock_stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -1103,17 +1093,16 @@ unsafe extern "C" fn base_src_decide_allocation<T: BaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BaseSrc> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -12,49 +12,32 @@ use crate::prelude::BaseSrcExtManual;
use crate::PushSrc; use crate::PushSrc;
pub trait PushSrcImpl: PushSrcImplExt + BaseSrcImpl { pub trait PushSrcImpl: PushSrcImplExt + BaseSrcImpl {
fn fill( fn fill(&self, buffer: &mut gst::BufferRef) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, PushSrcImplExt::parent_fill(self, buffer)
element: &Self::Type,
buffer: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
PushSrcImplExt::parent_fill(self, element, buffer)
} }
fn alloc(&self, element: &Self::Type) -> Result<gst::Buffer, gst::FlowError> { fn alloc(&self) -> Result<gst::Buffer, gst::FlowError> {
PushSrcImplExt::parent_alloc(self, element) PushSrcImplExt::parent_alloc(self)
} }
fn create( fn create(&self, buffer: Option<&mut gst::BufferRef>) -> Result<CreateSuccess, gst::FlowError> {
&self, PushSrcImplExt::parent_create(self, buffer)
element: &Self::Type,
buffer: Option<&mut gst::BufferRef>,
) -> Result<CreateSuccess, gst::FlowError> {
PushSrcImplExt::parent_create(self, element, buffer)
} }
} }
pub trait PushSrcImplExt: ObjectSubclass { pub trait PushSrcImplExt: ObjectSubclass {
fn parent_fill( fn parent_fill(&self, buffer: &mut gst::BufferRef) -> Result<gst::FlowSuccess, gst::FlowError>;
&self,
element: &Self::Type,
buffer: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_alloc(&self, element: &Self::Type) -> Result<gst::Buffer, gst::FlowError>; fn parent_alloc(&self) -> Result<gst::Buffer, gst::FlowError>;
fn parent_create( fn parent_create(
&self, &self,
element: &Self::Type,
buffer: Option<&mut gst::BufferRef>, buffer: Option<&mut gst::BufferRef>,
) -> Result<CreateSuccess, gst::FlowError>; ) -> Result<CreateSuccess, gst::FlowError>;
} }
impl<T: PushSrcImpl> PushSrcImplExt for T { impl<T: PushSrcImpl> PushSrcImplExt for T {
fn parent_fill( fn parent_fill(&self, buffer: &mut gst::BufferRef) -> Result<gst::FlowSuccess, gst::FlowError> {
&self,
element: &Self::Type,
buffer: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstPushSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstPushSrcClass;
@ -62,7 +45,10 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
.fill .fill
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<PushSrc>()
.to_glib_none()
.0,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
)) ))
}) })
@ -70,7 +56,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
} }
} }
fn parent_alloc(&self, element: &Self::Type) -> Result<gst::Buffer, gst::FlowError> { fn parent_alloc(&self) -> Result<gst::Buffer, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstPushSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstPushSrcClass;
@ -84,7 +70,10 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
gst::FlowSuccess::try_from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<PushSrc>()
.to_glib_none()
.0,
buffer_ref, buffer_ref,
)) ))
.map(|_| from_glib_full(buffer_ref)) .map(|_| from_glib_full(buffer_ref))
@ -95,7 +84,6 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
fn parent_create( fn parent_create(
&self, &self,
element: &Self::Type,
mut buffer: Option<&mut gst::BufferRef>, mut buffer: Option<&mut gst::BufferRef>,
) -> Result<CreateSuccess, gst::FlowError> { ) -> Result<CreateSuccess, gst::FlowError> {
unsafe { unsafe {
@ -104,6 +92,8 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
(*parent_class) (*parent_class)
.create .create
.map(|f| { .map(|f| {
let instance = self.instance();
let instance = instance.unsafe_cast_ref::<PushSrc>();
let orig_buffer_ptr = buffer let orig_buffer_ptr = buffer
.as_mut() .as_mut()
.map(|b| b.as_mut_ptr()) .map(|b| b.as_mut_ptr())
@ -117,7 +107,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
if let Err(err) = gst::FlowSuccess::try_from_glib( if let Err(err) = gst::FlowSuccess::try_from_glib(
f( f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, instance.to_glib_none().0,
buffer_ref, buffer_ref,
) )
) { ) {
@ -127,7 +117,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
let pending_buffer_list = instance_data.pending_buffer_list.borrow_mut().take(); let pending_buffer_list = instance_data.pending_buffer_list.borrow_mut().take();
if pending_buffer_list.is_some() && if pending_buffer_list.is_some() &&
(buffer.is_some() || element.unsafe_cast_ref::<PushSrc>().src_pad().mode() == gst::PadMode::Pull) { (buffer.is_some() || instance.src_pad().mode() == gst::PadMode::Pull) {
panic!("Buffer lists can only be returned in push mode"); panic!("Buffer lists can only be returned in push mode");
} }
@ -135,7 +125,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
if buffer_ptr.is_null() && pending_buffer_list.is_none() { if buffer_ptr.is_null() && pending_buffer_list.is_none() {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<PushSrc>(), obj: instance,
"No buffer and no buffer list returned" "No buffer and no buffer list returned"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -144,7 +134,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
if !buffer_ptr.is_null() && pending_buffer_list.is_some() { if !buffer_ptr.is_null() && pending_buffer_list.is_some() {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<PushSrc>(), obj: instance,
"Both buffer and buffer list returned" "Both buffer and buffer list returned"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -156,7 +146,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
gst::debug!( gst::debug!(
gst::CAT_PERFORMANCE, gst::CAT_PERFORMANCE,
obj: element.unsafe_cast_ref::<PushSrc>(), obj: instance,
"Returned new buffer from parent create function, copying into passed buffer" "Returned new buffer from parent create function, copying into passed buffer"
); );
@ -165,7 +155,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<PushSrc>(), obj: instance,
"Failed to map passed buffer writable" "Failed to map passed buffer writable"
); );
return Err(gst::FlowError::Error); return Err(gst::FlowError::Error);
@ -184,7 +174,7 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: element.unsafe_cast_ref::<PushSrc>(), obj: instance,
"Failed to copy buffer metadata" "Failed to copy buffer metadata"
); );
@ -221,11 +211,10 @@ unsafe extern "C" fn push_src_fill<T: PushSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<PushSrc> = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_mut_ptr(buffer); let buffer = gst::BufferRef::from_mut_ptr(buffer);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
PushSrcImpl::fill(imp, wrap.unsafe_cast_ref(), buffer).into() PushSrcImpl::fill(imp, buffer).into()
}) })
.into_glib() .into_glib()
} }
@ -236,13 +225,12 @@ unsafe extern "C" fn push_src_alloc<T: PushSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<PushSrc> = from_glib_borrow(ptr);
// FIXME: Wrong signature in -sys bindings // FIXME: Wrong signature in -sys bindings
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer; let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer;
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match PushSrcImpl::alloc(imp, wrap.unsafe_cast_ref()) { match PushSrcImpl::alloc(imp) {
Ok(buffer) => { Ok(buffer) => {
*buffer_ptr = buffer.into_glib_ptr(); *buffer_ptr = buffer.into_glib_ptr();
gst::FlowReturn::Ok gst::FlowReturn::Ok
@ -260,7 +248,6 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<PushSrc> = from_glib_borrow(ptr);
// FIXME: Wrong signature in -sys bindings // FIXME: Wrong signature in -sys bindings
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer; let buffer_ptr = buffer_ptr as *mut *mut gst::ffi::GstBuffer;
@ -275,8 +262,8 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
.instance_data::<super::base_src::InstanceData>(crate::BaseSrc::static_type()) .instance_data::<super::base_src::InstanceData>(crate::BaseSrc::static_type())
.unwrap(); .unwrap();
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match PushSrcImpl::create(imp, wrap.unsafe_cast_ref(), buffer.as_deref_mut()) { match PushSrcImpl::create(imp, buffer.as_deref_mut()) {
Ok(CreateSuccess::NewBuffer(new_buffer)) => { Ok(CreateSuccess::NewBuffer(new_buffer)) => {
// Clear any pending buffer list // Clear any pending buffer list
*instance_data.pending_buffer_list.borrow_mut() = None; *instance_data.pending_buffer_list.borrow_mut() = None;
@ -285,7 +272,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
if passed_buffer.as_ptr() != new_buffer.as_ptr() { if passed_buffer.as_ptr() != new_buffer.as_ptr() {
gst::debug!( gst::debug!(
gst::CAT_PERFORMANCE, gst::CAT_PERFORMANCE,
obj: &*wrap, imp: imp,
"Returned new buffer from create function, copying into passed buffer" "Returned new buffer from create function, copying into passed buffer"
); );
@ -294,7 +281,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: &*wrap, imp: imp,
"Failed to map passed buffer writable" "Failed to map passed buffer writable"
); );
return gst::FlowReturn::Error; return gst::FlowReturn::Error;
@ -318,7 +305,7 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
Err(_) => { Err(_) => {
gst::error!( gst::error!(
gst::CAT_RUST, gst::CAT_RUST,
obj: &*wrap, imp: imp,
"Failed to copy buffer metadata" "Failed to copy buffer metadata"
); );
@ -335,7 +322,8 @@ unsafe extern "C" fn push_src_create<T: PushSrcImpl>(
} }
Ok(CreateSuccess::NewBufferList(new_buffer_list)) => { Ok(CreateSuccess::NewBufferList(new_buffer_list)) => {
if buffer.is_some() if buffer.is_some()
|| wrap.unsafe_cast_ref::<PushSrc>().src_pad().mode() == gst::PadMode::Pull || imp.instance().unsafe_cast_ref::<PushSrc>().src_pad().mode()
== gst::PadMode::Pull
{ {
panic!("Buffer lists can only be returned in push mode"); panic!("Buffer lists can only be returned in push mode");
} }

View file

@ -11,44 +11,29 @@ use gst_base::subclass::prelude::*;
use crate::GLBaseFilter; use crate::GLBaseFilter;
pub trait GLBaseFilterImpl: GLBaseFilterImplExt + BaseTransformImpl { pub trait GLBaseFilterImpl: GLBaseFilterImplExt + BaseTransformImpl {
fn gl_set_caps( fn gl_set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError> {
&self, self.parent_gl_set_caps(incaps, outcaps)
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError> {
self.parent_gl_set_caps(filter, incaps, outcaps)
} }
fn gl_start(&self, filter: &Self::Type) -> Result<(), LoggableError> { fn gl_start(&self) -> Result<(), LoggableError> {
self.parent_gl_start(filter) self.parent_gl_start()
} }
fn gl_stop(&self, filter: &Self::Type) { fn gl_stop(&self) {
self.parent_gl_stop(filter) self.parent_gl_stop()
} }
} }
pub trait GLBaseFilterImplExt: ObjectSubclass { pub trait GLBaseFilterImplExt: ObjectSubclass {
fn parent_gl_set_caps( fn parent_gl_set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError>;
&self,
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError>;
fn parent_gl_start(&self, filter: &Self::Type) -> Result<(), LoggableError>; fn parent_gl_start(&self) -> Result<(), LoggableError>;
fn parent_gl_stop(&self, filter: &Self::Type); fn parent_gl_stop(&self);
} }
impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T { impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T {
fn parent_gl_set_caps( fn parent_gl_set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError> {
&self,
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass;
@ -58,7 +43,10 @@ impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
filter.unsafe_cast_ref::<GLBaseFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLBaseFilter>()
.to_glib_none()
.0,
incaps.to_glib_none().0, incaps.to_glib_none().0,
outcaps.to_glib_none().0, outcaps.to_glib_none().0,
), ),
@ -70,7 +58,7 @@ impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T {
} }
} }
fn parent_gl_start(&self, filter: &Self::Type) -> Result<(), LoggableError> { fn parent_gl_start(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass;
@ -79,7 +67,11 @@ impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T {
.gl_start .gl_start
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f(filter.unsafe_cast_ref::<GLBaseFilter>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<GLBaseFilter>()
.to_glib_none()
.0),
CAT_RUST, CAT_RUST,
"Parent function `gl_start` failed", "Parent function `gl_start` failed",
) )
@ -88,13 +80,17 @@ impl<T: GLBaseFilterImpl> GLBaseFilterImplExt for T {
} }
} }
fn parent_gl_stop(&self, filter: &Self::Type) { fn parent_gl_stop(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseFilterClass;
if let Some(f) = (*parent_class).gl_stop { if let Some(f) = (*parent_class).gl_stop {
f(filter.unsafe_cast_ref::<GLBaseFilter>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<GLBaseFilter>()
.to_glib_none()
.0)
} }
} }
} }
@ -117,17 +113,12 @@ unsafe extern "C" fn gl_set_caps<T: GLBaseFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.gl_set_caps( match imp.gl_set_caps(&from_glib_borrow(incaps), &from_glib_borrow(outcaps)) {
wrap.unsafe_cast_ref(),
&from_glib_borrow(incaps),
&from_glib_borrow(outcaps),
) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -140,13 +131,12 @@ unsafe extern "C" fn gl_start<T: GLBaseFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.gl_start(wrap.unsafe_cast_ref()) { match imp.gl_start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -157,9 +147,6 @@ unsafe extern "C" fn gl_start<T: GLBaseFilterImpl>(
unsafe extern "C" fn gl_stop<T: GLBaseFilterImpl>(ptr: *mut GstGLBaseFilter) { unsafe extern "C" fn gl_stop<T: GLBaseFilterImpl>(ptr: *mut GstGLBaseFilter) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), { imp.gl_stop() })
imp.gl_stop(wrap.unsafe_cast_ref())
})
} }

View file

@ -12,33 +12,29 @@ use crate::{GLBaseSrc, GLMemory, GLAPI};
pub trait GLBaseSrcImpl: GLBaseSrcImplExt + PushSrcImpl { pub trait GLBaseSrcImpl: GLBaseSrcImplExt + PushSrcImpl {
const SUPPORTED_GL_API: GLAPI; const SUPPORTED_GL_API: GLAPI;
fn gl_start(&self, element: &Self::Type) -> Result<(), LoggableError> { fn gl_start(&self) -> Result<(), LoggableError> {
self.parent_gl_start(element) self.parent_gl_start()
} }
fn gl_stop(&self, element: &Self::Type) { fn gl_stop(&self) {
self.parent_gl_stop(element) self.parent_gl_stop()
} }
fn fill_gl_memory(&self, element: &Self::Type, memory: &GLMemory) -> Result<(), LoggableError> { fn fill_gl_memory(&self, memory: &GLMemory) -> Result<(), LoggableError> {
self.parent_fill_gl_memory(element, memory) self.parent_fill_gl_memory(memory)
} }
} }
pub trait GLBaseSrcImplExt: ObjectSubclass { pub trait GLBaseSrcImplExt: ObjectSubclass {
fn parent_gl_start(&self, element: &Self::Type) -> Result<(), LoggableError>; fn parent_gl_start(&self) -> Result<(), LoggableError>;
fn parent_gl_stop(&self, element: &Self::Type); fn parent_gl_stop(&self);
fn parent_fill_gl_memory( fn parent_fill_gl_memory(&self, memory: &GLMemory) -> Result<(), LoggableError>;
&self,
element: &Self::Type,
memory: &GLMemory,
) -> Result<(), LoggableError>;
} }
impl<T: GLBaseSrcImpl> GLBaseSrcImplExt for T { impl<T: GLBaseSrcImpl> GLBaseSrcImplExt for T {
fn parent_gl_start(&self, element: &Self::Type) -> Result<(), LoggableError> { fn parent_gl_start(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass;
@ -47,7 +43,11 @@ impl<T: GLBaseSrcImpl> GLBaseSrcImplExt for T {
.gl_start .gl_start
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f(element.unsafe_cast_ref::<GLBaseSrc>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<GLBaseSrc>()
.to_glib_none()
.0),
CAT_RUST, CAT_RUST,
"Parent function `gl_start` failed", "Parent function `gl_start` failed",
) )
@ -56,22 +56,22 @@ impl<T: GLBaseSrcImpl> GLBaseSrcImplExt for T {
} }
} }
fn parent_gl_stop(&self, element: &Self::Type) { fn parent_gl_stop(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass;
if let Some(f) = (*parent_class).gl_stop { if let Some(f) = (*parent_class).gl_stop {
f(element.unsafe_cast_ref::<GLBaseSrc>().to_glib_none().0) f(self
.instance()
.unsafe_cast_ref::<GLBaseSrc>()
.to_glib_none()
.0)
} }
} }
} }
fn parent_fill_gl_memory( fn parent_fill_gl_memory(&self, memory: &GLMemory) -> Result<(), LoggableError> {
&self,
element: &Self::Type,
memory: &GLMemory,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstGLBaseSrcClass;
@ -81,7 +81,10 @@ impl<T: GLBaseSrcImpl> GLBaseSrcImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<GLBaseSrc>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLBaseSrc>()
.to_glib_none()
.0,
mut_override(memory.to_glib_none().0), mut_override(memory.to_glib_none().0),
), ),
CAT_RUST, CAT_RUST,
@ -107,13 +110,12 @@ unsafe impl<T: GLBaseSrcImpl> IsSubclassable<T> for GLBaseSrc {
unsafe extern "C" fn gl_start<T: GLBaseSrcImpl>(ptr: *mut GstGLBaseSrc) -> glib::ffi::gboolean { unsafe extern "C" fn gl_start<T: GLBaseSrcImpl>(ptr: *mut GstGLBaseSrc) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.gl_start(wrap.unsafe_cast_ref()) { match imp.gl_start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -124,11 +126,8 @@ unsafe extern "C" fn gl_start<T: GLBaseSrcImpl>(ptr: *mut GstGLBaseSrc) -> glib:
unsafe extern "C" fn gl_stop<T: GLBaseSrcImpl>(ptr: *mut GstGLBaseSrc) { unsafe extern "C" fn gl_stop<T: GLBaseSrcImpl>(ptr: *mut GstGLBaseSrc) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), { imp.gl_stop() })
imp.gl_stop(wrap.unsafe_cast_ref())
})
} }
unsafe extern "C" fn fill_gl_memory<T: GLBaseSrcImpl>( unsafe extern "C" fn fill_gl_memory<T: GLBaseSrcImpl>(
@ -137,13 +136,12 @@ unsafe extern "C" fn fill_gl_memory<T: GLBaseSrcImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLBaseSrc> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.fill_gl_memory(wrap.unsafe_cast_ref(), &from_glib_borrow(memory)) { match imp.fill_gl_memory(&from_glib_borrow(memory)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -24,75 +24,47 @@ pub trait GLFilterImpl: GLFilterImplExt + GLBaseFilterImpl {
/// in [`GLFilter::class_init`] if [`true`]. /// in [`GLFilter::class_init`] if [`true`].
const ADD_RGBA_PAD_TEMPLATES: bool = true; const ADD_RGBA_PAD_TEMPLATES: bool = true;
fn set_caps( fn set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError> {
&self, GLFilterImplExt::parent_set_caps(self, incaps, outcaps)
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError> {
GLFilterImplExt::parent_set_caps(self, filter, incaps, outcaps)
} }
fn filter( fn filter(&self, input: &Buffer, output: &Buffer) -> Result<(), LoggableError> {
&self, self.parent_filter(input, output)
filter: &Self::Type,
input: &Buffer,
output: &Buffer,
) -> Result<(), LoggableError> {
self.parent_filter(filter, input, output)
} }
fn filter_texture( fn filter_texture(&self, input: &GLMemory, output: &GLMemory) -> Result<(), LoggableError> {
&self, self.parent_filter_texture(input, output)
filter: &Self::Type,
input: &GLMemory,
output: &GLMemory,
) -> Result<(), LoggableError> {
self.parent_filter_texture(filter, input, output)
} }
fn init_fbo(&self, filter: &Self::Type) -> Result<(), LoggableError> { fn init_fbo(&self) -> Result<(), LoggableError> {
self.parent_init_fbo(filter) self.parent_init_fbo()
} }
fn transform_internal_caps( fn transform_internal_caps(
&self, &self,
filter: &Self::Type,
direction: PadDirection, direction: PadDirection,
caps: &Caps, caps: &Caps,
filter_caps: Option<&Caps>, filter_caps: Option<&Caps>,
) -> Option<Caps> { ) -> Option<Caps> {
self.parent_transform_internal_caps(filter, direction, caps, filter_caps) self.parent_transform_internal_caps(direction, caps, filter_caps)
} }
} }
pub trait GLFilterImplExt: ObjectSubclass { pub trait GLFilterImplExt: ObjectSubclass {
fn parent_set_caps( fn parent_set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError>;
&self,
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError>;
fn parent_filter( fn parent_filter(&self, input: &Buffer, output: &Buffer) -> Result<(), LoggableError>;
&self,
filter: &Self::Type,
input: &Buffer,
output: &Buffer,
) -> Result<(), LoggableError>;
fn parent_filter_texture( fn parent_filter_texture(
&self, &self,
filter: &Self::Type,
input: &GLMemory, input: &GLMemory,
output: &GLMemory, output: &GLMemory,
) -> Result<(), LoggableError>; ) -> Result<(), LoggableError>;
fn parent_init_fbo(&self, filter: &Self::Type) -> Result<(), LoggableError>; fn parent_init_fbo(&self) -> Result<(), LoggableError>;
fn parent_transform_internal_caps( fn parent_transform_internal_caps(
&self, &self,
filter: &Self::Type,
direction: PadDirection, direction: PadDirection,
caps: &Caps, caps: &Caps,
filter_caps: Option<&Caps>, filter_caps: Option<&Caps>,
@ -100,12 +72,7 @@ pub trait GLFilterImplExt: ObjectSubclass {
} }
impl<T: GLFilterImpl> GLFilterImplExt for T { impl<T: GLFilterImpl> GLFilterImplExt for T {
fn parent_set_caps( fn parent_set_caps(&self, incaps: &Caps, outcaps: &Caps) -> Result<(), LoggableError> {
&self,
filter: &Self::Type,
incaps: &Caps,
outcaps: &Caps,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass; let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass;
@ -115,7 +82,10 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
filter.unsafe_cast_ref::<GLFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLFilter>()
.to_glib_none()
.0,
incaps.to_glib_none().0, incaps.to_glib_none().0,
outcaps.to_glib_none().0, outcaps.to_glib_none().0,
), ),
@ -127,12 +97,7 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
} }
} }
fn parent_filter( fn parent_filter(&self, input: &Buffer, output: &Buffer) -> Result<(), LoggableError> {
&self,
filter: &Self::Type,
input: &Buffer,
output: &Buffer,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass; let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass;
@ -142,7 +107,10 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
filter.unsafe_cast_ref::<GLFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLFilter>()
.to_glib_none()
.0,
input.to_glib_none().0, input.to_glib_none().0,
output.to_glib_none().0, output.to_glib_none().0,
), ),
@ -156,7 +124,6 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
fn parent_filter_texture( fn parent_filter_texture(
&self, &self,
filter: &Self::Type,
input: &GLMemory, input: &GLMemory,
output: &GLMemory, output: &GLMemory,
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
@ -169,7 +136,10 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
filter.unsafe_cast_ref::<GLFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLFilter>()
.to_glib_none()
.0,
input.to_glib_none().0, input.to_glib_none().0,
output.to_glib_none().0, output.to_glib_none().0,
), ),
@ -181,7 +151,7 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
} }
} }
fn parent_init_fbo(&self, filter: &Self::Type) -> Result<(), LoggableError> { fn parent_init_fbo(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass; let parent_class = data.as_ref().parent_class() as *mut GstGLFilterClass;
@ -190,7 +160,11 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
.init_fbo .init_fbo
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f(filter.unsafe_cast_ref::<GLFilter>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<GLFilter>()
.to_glib_none()
.0),
CAT_RUST, CAT_RUST,
"Parent function `init_fbo` failed" "Parent function `init_fbo` failed"
) )
@ -200,7 +174,6 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
} }
fn parent_transform_internal_caps( fn parent_transform_internal_caps(
&self, &self,
filter: &Self::Type,
direction: PadDirection, direction: PadDirection,
caps: &Caps, caps: &Caps,
filter_caps: Option<&Caps>, filter_caps: Option<&Caps>,
@ -214,7 +187,10 @@ impl<T: GLFilterImpl> GLFilterImplExt for T {
.expect("Missing parent function `transform_internal_caps`"); .expect("Missing parent function `transform_internal_caps`");
from_glib_full(f( from_glib_full(f(
filter.unsafe_cast_ref::<GLFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<GLFilter>()
.to_glib_none()
.0,
direction.into_glib(), direction.into_glib(),
caps.to_glib_none().0, caps.to_glib_none().0,
filter_caps.to_glib_none().0, filter_caps.to_glib_none().0,
@ -255,17 +231,12 @@ unsafe extern "C" fn filter<T: GLFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.filter( match imp.filter(&from_glib_borrow(input), &from_glib_borrow(output)) {
wrap.unsafe_cast_ref(),
&from_glib_borrow(input),
&from_glib_borrow(output),
) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -280,17 +251,12 @@ unsafe extern "C" fn filter_texture<T: GLFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.filter_texture( match imp.filter_texture(&from_glib_borrow(input), &from_glib_borrow(output)) {
wrap.unsafe_cast_ref(),
&from_glib_borrow(input),
&from_glib_borrow(output),
) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -301,13 +267,12 @@ unsafe extern "C" fn filter_texture<T: GLFilterImpl>(
unsafe extern "C" fn init_fbo<T: GLFilterImpl>(ptr: *mut GstGLFilter) -> glib::ffi::gboolean { unsafe extern "C" fn init_fbo<T: GLFilterImpl>(ptr: *mut GstGLFilter) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.init_fbo(wrap.unsafe_cast_ref()) { match imp.init_fbo() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -322,18 +287,12 @@ unsafe extern "C" fn set_caps<T: GLFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match GLFilterImpl::set_caps( match GLFilterImpl::set_caps(imp, &from_glib_borrow(incaps), &from_glib_borrow(outcaps)) {
imp,
wrap.unsafe_cast_ref(),
&from_glib_borrow(incaps),
&from_glib_borrow(outcaps),
) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -349,13 +308,11 @@ unsafe extern "C" fn transform_internal_caps<T: GLFilterImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<GLFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), None, { gst::panic_to_error!(imp, None, {
let filter_caps: Borrowed<Option<Caps>> = from_glib_borrow(filter_caps); let filter_caps: Borrowed<Option<Caps>> = from_glib_borrow(filter_caps);
imp.transform_internal_caps( imp.transform_internal_caps(
wrap.unsafe_cast_ref(),
from_glib(direction), from_glib(direction),
&from_glib_borrow(caps), &from_glib_borrow(caps),
filter_caps.as_ref().as_ref(), filter_caps.as_ref().as_ref(),

View file

@ -10,61 +10,45 @@ use crate::AudioVisualizer;
pub struct AudioVisualizerSetupToken<'a>(pub(crate) &'a AudioVisualizer); pub struct AudioVisualizerSetupToken<'a>(pub(crate) &'a AudioVisualizer);
pub trait AudioVisualizerImpl: AudioVisualizerImplExt + ElementImpl { pub trait AudioVisualizerImpl: AudioVisualizerImplExt + ElementImpl {
fn setup( fn setup(&self, token: &AudioVisualizerSetupToken) -> Result<(), LoggableError> {
&self, self.parent_setup(token)
element: &Self::Type,
token: &AudioVisualizerSetupToken,
) -> Result<(), LoggableError> {
self.parent_setup(element, token)
} }
fn render( fn render(
&self, &self,
element: &Self::Type,
audio_buffer: &gst::BufferRef, audio_buffer: &gst::BufferRef,
video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>, video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>,
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
self.parent_render(element, audio_buffer, video_frame) self.parent_render(audio_buffer, video_frame)
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
} }
pub trait AudioVisualizerImplExt: ObjectSubclass { pub trait AudioVisualizerImplExt: ObjectSubclass {
fn parent_setup( fn parent_setup(&self, token: &AudioVisualizerSetupToken) -> Result<(), LoggableError>;
&self,
element: &Self::Type,
token: &AudioVisualizerSetupToken,
) -> Result<(), LoggableError>;
fn parent_render( fn parent_render(
&self, &self,
element: &Self::Type,
audio_buffer: &gst::BufferRef, audio_buffer: &gst::BufferRef,
video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>, video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>,
) -> Result<(), LoggableError>; ) -> Result<(), LoggableError>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T { impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
fn parent_setup( fn parent_setup(&self, token: &AudioVisualizerSetupToken) -> Result<(), LoggableError> {
&self,
element: &Self::Type,
token: &AudioVisualizerSetupToken,
) -> Result<(), LoggableError> {
assert_eq!( assert_eq!(
element.as_ptr() as *mut ffi::GstAudioVisualizer, self.instance().as_ptr() as *mut ffi::GstAudioVisualizer,
token.0.as_ptr() as *mut ffi::GstAudioVisualizer token.0.as_ptr() as *mut ffi::GstAudioVisualizer
); );
@ -75,7 +59,8 @@ impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
.setup .setup
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f(element f(self
.instance()
.unsafe_cast_ref::<AudioVisualizer>() .unsafe_cast_ref::<AudioVisualizer>()
.to_glib_none() .to_glib_none()
.0,), .0,),
@ -89,7 +74,6 @@ impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
fn parent_render( fn parent_render(
&self, &self,
element: &Self::Type,
audio_buffer: &gst::BufferRef, audio_buffer: &gst::BufferRef,
video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>, video_frame: &mut gst_video::VideoFrameRef<&mut gst::BufferRef>,
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
@ -101,7 +85,7 @@ impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
.map(|f| { .map(|f| {
result_from_gboolean!( result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<AudioVisualizer>() .unsafe_cast_ref::<AudioVisualizer>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -118,7 +102,6 @@ impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -129,7 +112,7 @@ impl<T: AudioVisualizerImpl> AudioVisualizerImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<AudioVisualizer>() .unsafe_cast_ref::<AudioVisualizer>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -159,15 +142,16 @@ unsafe extern "C" fn audio_visualizer_setup<T: AudioVisualizerImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioVisualizer> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
let token = AudioVisualizerSetupToken(&*wrap); let instance = imp.instance();
let instance = instance.unsafe_cast_ref::<AudioVisualizer>();
let token = AudioVisualizerSetupToken(instance);
match imp.setup(wrap.unsafe_cast_ref(), &token) { match imp.setup(&token) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -182,18 +166,16 @@ unsafe extern "C" fn audio_visualizer_render<T: AudioVisualizerImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioVisualizer> = from_glib_borrow(ptr);
let buffer = gst::BufferRef::from_ptr(audio_buffer); let buffer = gst::BufferRef::from_ptr(audio_buffer);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.render( match imp.render(
wrap.unsafe_cast_ref(),
buffer, buffer,
&mut gst_video::VideoFrameRef::from_glib_borrow_mut(video_frame), &mut gst_video::VideoFrameRef::from_glib_borrow_mut(video_frame),
) { ) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -207,17 +189,16 @@ unsafe extern "C" fn audio_visualizer_decide_allocation<T: AudioVisualizerImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<AudioVisualizer> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -7,7 +7,7 @@ use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
pub trait PlayVideoRendererImpl: ObjectImpl { pub trait PlayVideoRendererImpl: ObjectImpl {
fn create_video_sink(&self, video_renderer: &Self::Type, play: &Play) -> gst::Element; fn create_video_sink(&self, play: &Play) -> gst::Element;
} }
unsafe impl<T: PlayVideoRendererImpl> IsImplementable<T> for PlayVideoRenderer { unsafe impl<T: PlayVideoRendererImpl> IsImplementable<T> for PlayVideoRenderer {
@ -19,11 +19,11 @@ unsafe impl<T: PlayVideoRendererImpl> IsImplementable<T> for PlayVideoRenderer {
} }
pub trait PlayVideoRendererImplExt: ObjectSubclass { pub trait PlayVideoRendererImplExt: ObjectSubclass {
fn parent_create_video_sink(&self, video_renderer: &Self::Type, play: &Play) -> gst::Element; fn parent_create_video_sink(&self, play: &Play) -> gst::Element;
} }
impl<T: PlayVideoRendererImpl> PlayVideoRendererImplExt for T { impl<T: PlayVideoRendererImpl> PlayVideoRendererImplExt for T {
fn parent_create_video_sink(&self, video_renderer: &Self::Type, play: &Play) -> gst::Element { fn parent_create_video_sink(&self, play: &Play) -> gst::Element {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<PlayVideoRenderer>() let parent_iface = type_data.as_ref().parent_interface::<PlayVideoRenderer>()
@ -33,7 +33,7 @@ impl<T: PlayVideoRendererImpl> PlayVideoRendererImplExt for T {
.create_video_sink .create_video_sink
.expect("no parent \"create_video_sink\" implementation"); .expect("no parent \"create_video_sink\" implementation");
let ret = func( let ret = func(
video_renderer self.instance()
.unsafe_cast_ref::<PlayVideoRenderer>() .unsafe_cast_ref::<PlayVideoRenderer>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -55,10 +55,7 @@ unsafe extern "C" fn video_renderer_create_video_sink<T: PlayVideoRendererImpl>(
let instance = &*(video_renderer as *mut T::Instance); let instance = &*(video_renderer as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let sink = imp.create_video_sink( let sink = imp.create_video_sink(&Play::from_glib_borrow(play));
from_glib_borrow::<_, PlayVideoRenderer>(video_renderer).unsafe_cast_ref(),
&Play::from_glib_borrow(play),
);
let sink_ptr: *mut gst::ffi::GstElement = sink.to_glib_none().0; let sink_ptr: *mut gst::ffi::GstElement = sink.to_glib_none().0;

View file

@ -7,7 +7,7 @@ use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
pub trait PlayerVideoRendererImpl: ObjectImpl { pub trait PlayerVideoRendererImpl: ObjectImpl {
fn create_video_sink(&self, video_renderer: &Self::Type, player: &Player) -> gst::Element; fn create_video_sink(&self, player: &Player) -> gst::Element;
} }
unsafe impl<T: PlayerVideoRendererImpl> IsImplementable<T> for PlayerVideoRenderer { unsafe impl<T: PlayerVideoRendererImpl> IsImplementable<T> for PlayerVideoRenderer {
@ -19,19 +19,11 @@ unsafe impl<T: PlayerVideoRendererImpl> IsImplementable<T> for PlayerVideoRender
} }
pub trait PlayerVideoRendererImplExt: ObjectSubclass { pub trait PlayerVideoRendererImplExt: ObjectSubclass {
fn parent_create_video_sink( fn parent_create_video_sink(&self, player: &Player) -> gst::Element;
&self,
video_renderer: &Self::Type,
player: &Player,
) -> gst::Element;
} }
impl<T: PlayerVideoRendererImpl> PlayerVideoRendererImplExt for T { impl<T: PlayerVideoRendererImpl> PlayerVideoRendererImplExt for T {
fn parent_create_video_sink( fn parent_create_video_sink(&self, player: &Player) -> gst::Element {
&self,
video_renderer: &Self::Type,
player: &Player,
) -> gst::Element {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<PlayerVideoRenderer>() let parent_iface = type_data.as_ref().parent_interface::<PlayerVideoRenderer>()
@ -41,7 +33,7 @@ impl<T: PlayerVideoRendererImpl> PlayerVideoRendererImplExt for T {
.create_video_sink .create_video_sink
.expect("no parent \"create_video_sink\" implementation"); .expect("no parent \"create_video_sink\" implementation");
let ret = func( let ret = func(
video_renderer self.instance()
.unsafe_cast_ref::<PlayerVideoRenderer>() .unsafe_cast_ref::<PlayerVideoRenderer>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -63,10 +55,7 @@ unsafe extern "C" fn video_renderer_create_video_sink<T: PlayerVideoRendererImpl
let instance = &*(video_renderer as *mut T::Instance); let instance = &*(video_renderer as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let sink = imp.create_video_sink( let sink = imp.create_video_sink(&from_glib_borrow::<_, Player>(player));
from_glib_borrow::<_, PlayerVideoRenderer>(video_renderer).unsafe_cast_ref(),
&Player::from_glib_borrow(player),
);
let sink_ptr: *mut gst::ffi::GstElement = sink.to_glib_none().0; let sink_ptr: *mut gst::ffi::GstElement = sink.to_glib_none().0;

View file

@ -9,51 +9,41 @@ use crate::RTPBaseDepayload;
use std::ptr; use std::ptr;
pub trait RTPBaseDepayloadImpl: RTPBaseDepayloadImplExt + ElementImpl { pub trait RTPBaseDepayloadImpl: RTPBaseDepayloadImplExt + ElementImpl {
fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> { fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(caps)
} }
fn handle_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn handle_event(&self, event: gst::Event) -> bool {
self.parent_handle_event(element, event) self.parent_handle_event(event)
} }
fn packet_lost(&self, element: &Self::Type, event: &gst::EventRef) -> bool { fn packet_lost(&self, event: &gst::EventRef) -> bool {
self.parent_packet_lost(element, event) self.parent_packet_lost(event)
} }
fn process_rtp_packet( fn process_rtp_packet(
&self, &self,
element: &Self::Type,
rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>, rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>,
) -> Option<gst::Buffer> { ) -> Option<gst::Buffer> {
self.parent_process_rtp_packet(element, rtp_buffer) self.parent_process_rtp_packet(rtp_buffer)
} }
} }
pub trait RTPBaseDepayloadImplExt: ObjectSubclass { pub trait RTPBaseDepayloadImplExt: ObjectSubclass {
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_handle_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_handle_event(&self, event: gst::Event) -> bool;
fn parent_packet_lost(&self, element: &Self::Type, event: &gst::EventRef) -> bool; fn parent_packet_lost(&self, event: &gst::EventRef) -> bool;
fn parent_process_rtp_packet( fn parent_process_rtp_packet(
&self, &self,
element: &Self::Type,
rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>, rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>,
) -> Option<gst::Buffer>; ) -> Option<gst::Buffer>;
} }
impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T { impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass;
@ -62,7 +52,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<RTPBaseDepayload>() .unsafe_cast_ref::<RTPBaseDepayload>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -76,7 +66,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
} }
} }
fn parent_handle_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_handle_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass;
@ -84,7 +74,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
.handle_event .handle_event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element self.instance()
.unsafe_cast_ref::<RTPBaseDepayload>() .unsafe_cast_ref::<RTPBaseDepayload>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -95,7 +85,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
} }
} }
fn parent_packet_lost(&self, element: &Self::Type, event: &gst::EventRef) -> bool { fn parent_packet_lost(&self, event: &gst::EventRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBaseDepayloadClass;
@ -103,7 +93,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
.packet_lost .packet_lost
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element self.instance()
.unsafe_cast_ref::<RTPBaseDepayload>() .unsafe_cast_ref::<RTPBaseDepayload>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -116,7 +106,6 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
fn parent_process_rtp_packet( fn parent_process_rtp_packet(
&self, &self,
element: &Self::Type,
rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>, rtp_buffer: &crate::RTPBuffer<crate::rtp_buffer::Readable>,
) -> Option<gst::Buffer> { ) -> Option<gst::Buffer> {
unsafe { unsafe {
@ -128,7 +117,7 @@ impl<T: RTPBaseDepayloadImpl> RTPBaseDepayloadImplExt for T {
.expect("no parent \"process\" implementation"); .expect("no parent \"process\" implementation");
from_glib_full(f( from_glib_full(f(
element self.instance()
.unsafe_cast_ref::<crate::RTPBaseDepayload>() .unsafe_cast_ref::<crate::RTPBaseDepayload>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -157,14 +146,13 @@ unsafe extern "C" fn rtp_base_depayload_set_caps<T: RTPBaseDepayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBaseDepayload> = from_glib_borrow(ptr);
let caps = from_glib_borrow(caps); let caps = from_glib_borrow(caps);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_caps(wrap.unsafe_cast_ref(), &caps) { match imp.set_caps(&caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -178,12 +166,8 @@ unsafe extern "C" fn rtp_base_depayload_handle_event<T: RTPBaseDepayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBaseDepayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.handle_event(from_glib_full(event)) }).into_glib()
imp.handle_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn rtp_base_depayload_packet_lost<T: RTPBaseDepayloadImpl>( unsafe extern "C" fn rtp_base_depayload_packet_lost<T: RTPBaseDepayloadImpl>(
@ -192,10 +176,9 @@ unsafe extern "C" fn rtp_base_depayload_packet_lost<T: RTPBaseDepayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBaseDepayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.packet_lost(wrap.unsafe_cast_ref(), gst::EventRef::from_ptr(event)) imp.packet_lost(gst::EventRef::from_ptr(event))
}) })
.into_glib() .into_glib()
} }
@ -206,12 +189,11 @@ unsafe extern "C" fn rtp_base_depayload_process_rtp_packet<T: RTPBaseDepayloadIm
) -> *mut gst::ffi::GstBuffer { ) -> *mut gst::ffi::GstBuffer {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPBaseDepayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), ptr::null_mut(), { gst::panic_to_error!(imp, ptr::null_mut(), {
let bufwrap = crate::RTPBuffer::<crate::rtp_buffer::Readable>::from_glib_borrow(rtp_packet); let bufwrap = crate::RTPBuffer::<crate::rtp_buffer::Readable>::from_glib_borrow(rtp_packet);
imp.process_rtp_packet(wrap.unsafe_cast_ref(), &bufwrap) imp.process_rtp_packet(&bufwrap)
.map(|buffer| buffer.into_glib_ptr()) .map(|buffer| buffer.into_glib_ptr())
.unwrap_or(ptr::null_mut()) .unwrap_or(ptr::null_mut())
}) })

View file

@ -8,70 +8,48 @@ use crate::prelude::*;
use crate::RTPBasePayload; use crate::RTPBasePayload;
pub trait RTPBasePayloadImpl: RTPBasePayloadImplExt + ElementImpl { pub trait RTPBasePayloadImpl: RTPBasePayloadImplExt + ElementImpl {
fn caps(&self, element: &Self::Type, pad: &gst::Pad, filter: Option<&gst::Caps>) -> gst::Caps { fn caps(&self, pad: &gst::Pad, filter: Option<&gst::Caps>) -> gst::Caps {
self.parent_caps(element, pad, filter) self.parent_caps(pad, filter)
} }
fn set_caps(&self, element: &Self::Type, caps: &gst::Caps) -> Result<(), gst::LoggableError> { fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
self.parent_set_caps(element, caps) self.parent_set_caps(caps)
} }
fn handle_buffer( fn handle_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_handle_buffer(buffer)
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_handle_buffer(element, buffer)
} }
fn query(&self, element: &Self::Type, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool { fn query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool {
RTPBasePayloadImplExt::parent_query(self, element, pad, query) RTPBasePayloadImplExt::parent_query(self, pad, query)
} }
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn sink_event(&self, event: gst::Event) -> bool {
self.parent_sink_event(element, event) self.parent_sink_event(event)
} }
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn src_event(&self, event: gst::Event) -> bool {
self.parent_src_event(element, event) self.parent_src_event(event)
} }
} }
pub trait RTPBasePayloadImplExt: ObjectSubclass { pub trait RTPBasePayloadImplExt: ObjectSubclass {
fn parent_caps( fn parent_caps(&self, pad: &gst::Pad, filter: Option<&gst::Caps>) -> gst::Caps;
&self,
element: &Self::Type,
pad: &gst::Pad,
filter: Option<&gst::Caps>,
) -> gst::Caps;
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_handle_buffer( fn parent_handle_buffer(&self, buffer: gst::Buffer)
&self, -> Result<gst::FlowSuccess, gst::FlowError>;
element: &Self::Type,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_query(&self, element: &Self::Type, pad: &gst::Pad, query: &mut gst::QueryRef) fn parent_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool;
-> bool;
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_sink_event(&self, event: gst::Event) -> bool;
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_src_event(&self, event: gst::Event) -> bool;
} }
impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T { impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
fn parent_caps( fn parent_caps(&self, pad: &gst::Pad, filter: Option<&gst::Caps>) -> gst::Caps {
&self,
element: &Self::Type,
pad: &gst::Pad,
filter: Option<&gst::Caps>,
) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass;
@ -79,18 +57,17 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.get_caps .get_caps
.expect("Missing parent function `get_caps`"); .expect("Missing parent function `get_caps`");
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
pad.to_glib_none().0, pad.to_glib_none().0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
} }
} }
fn parent_set_caps( fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass;
@ -99,7 +76,10 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
caps.to_glib_none().0 caps.to_glib_none().0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -108,7 +88,7 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
// Trigger negotiation as the base class does // Trigger negotiation as the base class does
element self.instance()
.unsafe_cast_ref::<RTPBasePayload>() .unsafe_cast_ref::<RTPBasePayload>()
.set_outcaps(None) .set_outcaps(None)
.map_err(|_| gst::loggable_error!(gst::CAT_RUST, "Failed to negotiate")) .map_err(|_| gst::loggable_error!(gst::CAT_RUST, "Failed to negotiate"))
@ -118,7 +98,6 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
fn parent_handle_buffer( fn parent_handle_buffer(
&self, &self,
element: &Self::Type,
buffer: gst::Buffer, buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -128,7 +107,10 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.handle_buffer .handle_buffer
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
buffer.into_glib_ptr(), buffer.into_glib_ptr(),
)) ))
}) })
@ -136,12 +118,7 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
} }
} }
fn parent_query( fn parent_query(&self, pad: &gst::Pad, query: &mut gst::QueryRef) -> bool {
&self,
element: &Self::Type,
pad: &gst::Pad,
query: &mut gst::QueryRef,
) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass;
@ -149,7 +126,10 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.query .query
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
pad.to_glib_none().0, pad.to_glib_none().0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
@ -158,7 +138,7 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
} }
} }
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass;
@ -166,7 +146,10 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.sink_event .sink_event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
}) })
@ -174,7 +157,7 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
} }
} }
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPBasePayloadClass;
@ -182,7 +165,10 @@ impl<T: RTPBasePayloadImpl> RTPBasePayloadImplExt for T {
.src_event .src_event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<RTPBasePayload>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTPBasePayload>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
}) })
@ -211,12 +197,10 @@ unsafe extern "C" fn rtp_base_payload_get_caps<T: RTPBasePayloadImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), {
RTPBasePayloadImpl::caps( RTPBasePayloadImpl::caps(
imp, imp,
wrap.unsafe_cast_ref(),
&from_glib_borrow(pad), &from_glib_borrow(pad),
Option::<gst::Caps>::from_glib_borrow(filter) Option::<gst::Caps>::from_glib_borrow(filter)
.as_ref() .as_ref()
@ -232,14 +216,13 @@ unsafe extern "C" fn rtp_base_payload_set_caps<T: RTPBasePayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
let caps = from_glib_borrow(caps); let caps = from_glib_borrow(caps);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_caps(wrap.unsafe_cast_ref(), &caps) { match imp.set_caps(&caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -253,11 +236,9 @@ unsafe extern "C" fn rtp_base_payload_handle_buffer<T: RTPBasePayloadImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.handle_buffer(wrap.unsafe_cast_ref(), from_glib_full(buffer)) imp.handle_buffer(from_glib_full(buffer)).into()
.into()
}) })
.into_glib() .into_glib()
} }
@ -269,12 +250,10 @@ unsafe extern "C" fn rtp_base_payload_query<T: RTPBasePayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
RTPBasePayloadImpl::query( RTPBasePayloadImpl::query(
imp, imp,
wrap.unsafe_cast_ref(),
&from_glib_borrow(pad), &from_glib_borrow(pad),
gst::QueryRef::from_mut_ptr(query), gst::QueryRef::from_mut_ptr(query),
) )
@ -288,12 +267,8 @@ unsafe extern "C" fn rtp_base_payload_sink_event<T: RTPBasePayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn rtp_base_payload_src_event<T: RTPBasePayloadImpl>( unsafe extern "C" fn rtp_base_payload_src_event<T: RTPBasePayloadImpl>(
@ -302,10 +277,6 @@ unsafe extern "C" fn rtp_base_payload_src_event<T: RTPBasePayloadImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTPBasePayload> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }

View file

@ -8,75 +8,59 @@ use glib::translate::*;
pub trait RTPHeaderExtensionImpl: RTPHeaderExtensionImplExt + ElementImpl { pub trait RTPHeaderExtensionImpl: RTPHeaderExtensionImplExt + ElementImpl {
const URI: &'static str; const URI: &'static str;
fn supported_flags(&self, element: &Self::Type) -> crate::RTPHeaderExtensionFlags { fn supported_flags(&self) -> crate::RTPHeaderExtensionFlags {
self.parent_supported_flags(element) self.parent_supported_flags()
} }
fn max_size(&self, element: &Self::Type, input: &gst::BufferRef) -> usize { fn max_size(&self, input: &gst::BufferRef) -> usize {
self.parent_max_size(element, input) self.parent_max_size(input)
} }
fn write( fn write(
&self, &self,
element: &Self::Type,
input: &gst::BufferRef, input: &gst::BufferRef,
write_flags: crate::RTPHeaderExtensionFlags, write_flags: crate::RTPHeaderExtensionFlags,
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
output_data: &mut [u8], output_data: &mut [u8],
) -> Result<usize, gst::LoggableError> { ) -> Result<usize, gst::LoggableError> {
self.parent_write(element, input, write_flags, output, output_data) self.parent_write(input, write_flags, output, output_data)
} }
fn read( fn read(
&self, &self,
element: &Self::Type,
read_flags: crate::RTPHeaderExtensionFlags, read_flags: crate::RTPHeaderExtensionFlags,
input_data: &[u8], input_data: &[u8],
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_read(element, read_flags, input_data, output) self.parent_read(read_flags, input_data, output)
} }
fn set_non_rtp_sink_caps( fn set_non_rtp_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self, self.parent_set_non_rtp_sink_caps(caps)
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
self.parent_set_non_rtp_sink_caps(element, caps)
} }
fn update_non_rtp_src_caps( fn update_non_rtp_src_caps(&self, caps: &mut gst::CapsRef) -> Result<(), gst::LoggableError> {
&self, self.parent_update_non_rtp_src_caps(caps)
element: &Self::Type,
caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError> {
self.parent_update_non_rtp_src_caps(element, caps)
} }
fn set_attributes( fn set_attributes(
&self, &self,
element: &Self::Type,
direction: crate::RTPHeaderExtensionDirection, direction: crate::RTPHeaderExtensionDirection,
attributes: &str, attributes: &str,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_set_attributes(element, direction, attributes) self.parent_set_attributes(direction, attributes)
} }
fn set_caps_from_attributes( fn set_caps_from_attributes(&self, caps: &mut gst::CapsRef) -> Result<(), gst::LoggableError> {
&self, self.parent_set_caps_from_attributes(caps)
element: &Self::Type,
caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError> {
self.parent_set_caps_from_attributes(element, caps)
} }
} }
pub trait RTPHeaderExtensionImplExt: ObjectSubclass { pub trait RTPHeaderExtensionImplExt: ObjectSubclass {
fn parent_supported_flags(&self, element: &Self::Type) -> crate::RTPHeaderExtensionFlags; fn parent_supported_flags(&self) -> crate::RTPHeaderExtensionFlags;
fn parent_max_size(&self, element: &Self::Type, input: &gst::BufferRef) -> usize; fn parent_max_size(&self, input: &gst::BufferRef) -> usize;
fn parent_write( fn parent_write(
&self, &self,
element: &Self::Type,
input: &gst::BufferRef, input: &gst::BufferRef,
write_flags: crate::RTPHeaderExtensionFlags, write_flags: crate::RTPHeaderExtensionFlags,
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
@ -84,50 +68,43 @@ pub trait RTPHeaderExtensionImplExt: ObjectSubclass {
) -> Result<usize, gst::LoggableError>; ) -> Result<usize, gst::LoggableError>;
fn parent_read( fn parent_read(
&self, &self,
element: &Self::Type,
read_flags: crate::RTPHeaderExtensionFlags, read_flags: crate::RTPHeaderExtensionFlags,
input_data: &[u8], input_data: &[u8],
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_set_non_rtp_sink_caps( fn parent_set_non_rtp_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError>;
fn parent_update_non_rtp_src_caps( fn parent_update_non_rtp_src_caps(
&self, &self,
element: &Self::Type,
caps: &mut gst::CapsRef, caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_set_attributes( fn parent_set_attributes(
&self, &self,
element: &Self::Type,
direction: crate::RTPHeaderExtensionDirection, direction: crate::RTPHeaderExtensionDirection,
attributes: &str, attributes: &str,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_set_caps_from_attributes( fn parent_set_caps_from_attributes(
&self, &self,
element: &Self::Type,
caps: &mut gst::CapsRef, caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T { impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_supported_flags(&self, element: &Self::Type) -> crate::RTPHeaderExtensionFlags { fn parent_supported_flags(&self) -> crate::RTPHeaderExtensionFlags {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass;
let f = (*parent_class) let f = (*parent_class)
.get_supported_flags .get_supported_flags
.expect("no parent \"get_supported_flags\" implementation"); .expect("no parent \"get_supported_flags\" implementation");
from_glib(f(element from_glib(f(self
.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0)) .0))
} }
} }
fn parent_max_size(&self, element: &Self::Type, input: &gst::BufferRef) -> usize { fn parent_max_size(&self, input: &gst::BufferRef) -> usize {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass;
@ -135,7 +112,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
.get_max_size .get_max_size
.expect("no parent \"get_max_size\" implementation"); .expect("no parent \"get_max_size\" implementation");
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -146,7 +123,6 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_write( fn parent_write(
&self, &self,
element: &Self::Type,
input: &gst::BufferRef, input: &gst::BufferRef,
write_flags: crate::RTPHeaderExtensionFlags, write_flags: crate::RTPHeaderExtensionFlags,
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
@ -160,7 +136,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
.expect("no parent \"write\" implementation"); .expect("no parent \"write\" implementation");
let res = f( let res = f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -184,7 +160,6 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_read( fn parent_read(
&self, &self,
element: &Self::Type,
read_flags: crate::RTPHeaderExtensionFlags, read_flags: crate::RTPHeaderExtensionFlags,
input_data: &[u8], input_data: &[u8],
output: &mut gst::BufferRef, output: &mut gst::BufferRef,
@ -198,7 +173,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -213,18 +188,14 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
} }
} }
fn parent_set_non_rtp_sink_caps( fn parent_set_non_rtp_sink_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTPHeaderExtensionClass;
if let Some(f) = (*parent_class).set_non_rtp_sink_caps { if let Some(f) = (*parent_class).set_non_rtp_sink_caps {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -241,7 +212,6 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_update_non_rtp_src_caps( fn parent_update_non_rtp_src_caps(
&self, &self,
element: &Self::Type,
caps: &mut gst::CapsRef, caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -250,7 +220,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
if let Some(f) = (*parent_class).update_non_rtp_src_caps { if let Some(f) = (*parent_class).update_non_rtp_src_caps {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -267,7 +237,6 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_set_attributes( fn parent_set_attributes(
&self, &self,
element: &Self::Type,
direction: crate::RTPHeaderExtensionDirection, direction: crate::RTPHeaderExtensionDirection,
attributes: &str, attributes: &str,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -277,7 +246,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
if let Some(f) = (*parent_class).set_attributes { if let Some(f) = (*parent_class).set_attributes {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -295,7 +264,6 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
fn parent_set_caps_from_attributes( fn parent_set_caps_from_attributes(
&self, &self,
element: &Self::Type,
caps: &mut gst::CapsRef, caps: &mut gst::CapsRef,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -307,7 +275,7 @@ impl<T: RTPHeaderExtensionImpl> RTPHeaderExtensionImplExt for T {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element self.instance()
.unsafe_cast_ref::<crate::RTPHeaderExtension>() .unsafe_cast_ref::<crate::RTPHeaderExtension>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -344,14 +312,10 @@ unsafe extern "C" fn get_supported_flags<T: RTPHeaderExtensionImpl>(
) -> ffi::GstRTPHeaderExtensionFlags { ) -> ffi::GstRTPHeaderExtensionFlags {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!( gst::panic_to_error!(imp, crate::RTPHeaderExtensionFlags::empty(), {
&wrap, imp.supported_flags()
imp.panicked(), })
crate::RTPHeaderExtensionFlags::empty(),
{ imp.supported_flags(wrap.unsafe_cast_ref()) }
)
.into_glib() .into_glib()
} }
@ -361,11 +325,8 @@ unsafe extern "C" fn get_max_size<T: RTPHeaderExtensionImpl>(
) -> usize { ) -> usize {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), 0, { gst::panic_to_error!(imp, 0, { imp.max_size(gst::BufferRef::from_ptr(input)) })
imp.max_size(wrap.unsafe_cast_ref(), gst::BufferRef::from_ptr(input))
})
} }
unsafe extern "C" fn write<T: RTPHeaderExtensionImpl>( unsafe extern "C" fn write<T: RTPHeaderExtensionImpl>(
@ -378,11 +339,9 @@ unsafe extern "C" fn write<T: RTPHeaderExtensionImpl>(
) -> isize { ) -> isize {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), -1, { gst::panic_to_error!(imp, -1, {
match imp.write( match imp.write(
wrap.unsafe_cast_ref(),
gst::BufferRef::from_ptr(input), gst::BufferRef::from_ptr(input),
from_glib(write_flags), from_glib(write_flags),
gst::BufferRef::from_mut_ptr(output), gst::BufferRef::from_mut_ptr(output),
@ -394,7 +353,7 @@ unsafe extern "C" fn write<T: RTPHeaderExtensionImpl>(
) { ) {
Ok(len) => len as isize, Ok(len) => len as isize,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
-1 -1
} }
} }
@ -410,11 +369,9 @@ unsafe extern "C" fn read<T: RTPHeaderExtensionImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.read( match imp.read(
wrap.unsafe_cast_ref(),
from_glib(read_flags), from_glib(read_flags),
if input_data_len == 0 { if input_data_len == 0 {
&[] &[]
@ -425,7 +382,7 @@ unsafe extern "C" fn read<T: RTPHeaderExtensionImpl>(
) { ) {
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -439,13 +396,12 @@ unsafe extern "C" fn set_non_rtp_sink_caps<T: RTPHeaderExtensionImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_non_rtp_sink_caps(wrap.unsafe_cast_ref(), &from_glib_borrow(caps)) { match imp.set_non_rtp_sink_caps(&from_glib_borrow(caps)) {
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -459,14 +415,12 @@ unsafe extern "C" fn update_non_rtp_src_caps<T: RTPHeaderExtensionImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.update_non_rtp_src_caps(wrap.unsafe_cast_ref(), gst::CapsRef::from_mut_ptr(caps)) match imp.update_non_rtp_src_caps(gst::CapsRef::from_mut_ptr(caps)) {
{
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -481,17 +435,15 @@ unsafe extern "C" fn set_attributes<T: RTPHeaderExtensionImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_attributes( match imp.set_attributes(
wrap.unsafe_cast_ref(),
from_glib(direction), from_glib(direction),
&glib::GString::from_glib_borrow(attributes), &glib::GString::from_glib_borrow(attributes),
) { ) {
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -505,14 +457,12 @@ unsafe extern "C" fn set_caps_from_attributes<T: RTPHeaderExtensionImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<crate::RTPHeaderExtension> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_caps_from_attributes(wrap.unsafe_cast_ref(), gst::CapsRef::from_mut_ptr(caps)) match imp.set_caps_from_attributes(gst::CapsRef::from_mut_ptr(caps)) {
{
Ok(_) => true, Ok(_) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -26,137 +26,118 @@ impl SDPInfo {
} }
pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync { pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync {
fn handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool { fn handle_message(&self, message: &gst::MessageRef) -> bool {
self.parent_handle_message(media, message) self.parent_handle_message(message)
} }
fn prepare(&self, media: &Self::Type, thread: &RTSPThread) -> Result<(), gst::LoggableError> { fn prepare(&self, thread: &RTSPThread) -> Result<(), gst::LoggableError> {
self.parent_prepare(media, thread) self.parent_prepare(thread)
} }
fn unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn unprepare(&self) -> Result<(), gst::LoggableError> {
self.parent_unprepare(media) self.parent_unprepare()
} }
fn suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn suspend(&self) -> Result<(), gst::LoggableError> {
self.parent_suspend(media) self.parent_suspend()
} }
fn unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn unsuspend(&self) -> Result<(), gst::LoggableError> {
self.parent_unsuspend(media) self.parent_unsuspend()
} }
// TODO missing: convert_range // TODO missing: convert_range
fn query_position(&self, media: &Self::Type) -> Option<gst::ClockTime> { fn query_position(&self) -> Option<gst::ClockTime> {
self.parent_query_position(media) self.parent_query_position()
} }
fn query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime> { fn query_stop(&self) -> Option<gst::ClockTime> {
self.parent_query_stop(media) self.parent_query_stop()
} }
fn create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element> { fn create_rtpbin(&self) -> Option<gst::Element> {
self.parent_create_rtpbin(media) self.parent_create_rtpbin()
} }
fn setup_rtpbin( fn setup_rtpbin(&self, rtpbin: &gst::Element) -> Result<(), gst::LoggableError> {
&self, self.parent_setup_rtpbin(rtpbin)
media: &Self::Type,
rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError> {
self.parent_setup_rtpbin(media, rtpbin)
} }
fn setup_sdp( fn setup_sdp(
&self, &self,
media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_setup_sdp(media, sdp, info) self.parent_setup_sdp(sdp, info)
} }
fn new_stream(&self, media: &Self::Type, stream: &crate::RTSPStream) { fn new_stream(&self, stream: &crate::RTSPStream) {
self.parent_new_stream(media, stream); self.parent_new_stream(stream);
} }
fn removed_stream(&self, media: &Self::Type, stream: &crate::RTSPStream) { fn removed_stream(&self, stream: &crate::RTSPStream) {
self.parent_removed_stream(media, stream); self.parent_removed_stream(stream);
} }
fn prepared(&self, media: &Self::Type) { fn prepared(&self) {
self.parent_prepared(media); self.parent_prepared();
} }
fn unprepared(&self, media: &Self::Type) { fn unprepared(&self) {
self.parent_unprepared(media); self.parent_unprepared();
} }
fn target_state(&self, media: &Self::Type, state: gst::State) { fn target_state(&self, state: gst::State) {
self.parent_target_state(media, state); self.parent_target_state(state);
} }
fn new_state(&self, media: &Self::Type, state: gst::State) { fn new_state(&self, state: gst::State) {
self.parent_new_state(media, state); self.parent_new_state(state);
} }
fn handle_sdp( fn handle_sdp(&self, sdp: &gst_sdp::SDPMessageRef) -> Result<(), gst::LoggableError> {
&self, self.parent_handle_sdp(sdp)
media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError> {
self.parent_handle_sdp(media, sdp)
} }
} }
pub trait RTSPMediaImplExt: ObjectSubclass { pub trait RTSPMediaImplExt: ObjectSubclass {
fn parent_handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool; fn parent_handle_message(&self, message: &gst::MessageRef) -> bool;
fn parent_prepare( fn parent_prepare(&self, thread: &RTSPThread) -> Result<(), gst::LoggableError>;
&self, fn parent_unprepare(&self) -> Result<(), gst::LoggableError>;
media: &Self::Type, fn parent_suspend(&self) -> Result<(), gst::LoggableError>;
thread: &RTSPThread, fn parent_unsuspend(&self) -> Result<(), gst::LoggableError>;
) -> Result<(), gst::LoggableError>;
fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
// TODO missing: convert_range // TODO missing: convert_range
fn parent_query_position(&self, media: &Self::Type) -> Option<gst::ClockTime>; fn parent_query_position(&self) -> Option<gst::ClockTime>;
fn parent_query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime>; fn parent_query_stop(&self) -> Option<gst::ClockTime>;
fn parent_create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element>; fn parent_create_rtpbin(&self) -> Option<gst::Element>;
fn parent_setup_rtpbin( fn parent_setup_rtpbin(&self, rtpbin: &gst::Element) -> Result<(), gst::LoggableError>;
&self,
media: &Self::Type,
rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError>;
fn parent_setup_sdp( fn parent_setup_sdp(
&self, &self,
media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_new_stream(&self, media: &Self::Type, stream: &crate::RTSPStream); fn parent_new_stream(&self, stream: &crate::RTSPStream);
fn parent_removed_stream(&self, media: &Self::Type, stream: &crate::RTSPStream); fn parent_removed_stream(&self, stream: &crate::RTSPStream);
fn parent_prepared(&self, media: &Self::Type); fn parent_prepared(&self);
fn parent_unprepared(&self, media: &Self::Type); fn parent_unprepared(&self);
fn parent_target_state(&self, media: &Self::Type, state: gst::State); fn parent_target_state(&self, state: gst::State);
fn parent_new_state(&self, media: &Self::Type, state: gst::State); fn parent_new_state(&self, state: gst::State);
fn parent_handle_sdp( fn parent_handle_sdp(&self, sdp: &gst_sdp::SDPMessageRef) -> Result<(), gst::LoggableError>;
&self,
media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError>;
} }
impl<T: RTSPMediaImpl> RTSPMediaImplExt for T { impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
fn parent_handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool { fn parent_handle_message(&self, message: &gst::MessageRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).handle_message { if let Some(f) = (*parent_class).handle_message {
from_glib(f( from_glib(f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
message.as_ptr() as *mut _, message.as_ptr() as *mut _,
)) ))
} else { } else {
@ -165,18 +146,17 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_prepare( fn parent_prepare(&self, thread: &RTSPThread) -> Result<(), gst::LoggableError> {
&self,
media: &Self::Type,
thread: &RTSPThread,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).prepare { if let Some(f) = (*parent_class).prepare {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
thread.to_glib_none().0 thread.to_glib_none().0
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -188,13 +168,17 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_unprepare(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unprepare { if let Some(f) = (*parent_class).unprepare {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `unprepare` failed" "Parent function `unprepare` failed"
) )
@ -204,13 +188,17 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_suspend(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).suspend { if let Some(f) = (*parent_class).suspend {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `suspend` failed" "Parent function `suspend` failed"
) )
@ -220,13 +208,17 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_unsuspend(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unsuspend { if let Some(f) = (*parent_class).unsuspend {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `unsuspend` failed" "Parent function `unsuspend` failed"
) )
@ -238,7 +230,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
// TODO missing: convert_range // TODO missing: convert_range
fn parent_query_position(&self, media: &Self::Type) -> Option<gst::ClockTime> { fn parent_query_position(&self) -> Option<gst::ClockTime> {
unsafe { unsafe {
use std::mem; use std::mem;
@ -247,7 +239,10 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
if let Some(f) = (*parent_class).query_position { if let Some(f) = (*parent_class).query_position {
let mut position = mem::MaybeUninit::uninit(); let mut position = mem::MaybeUninit::uninit();
if f( if f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
position.as_mut_ptr(), position.as_mut_ptr(),
) == glib::ffi::GFALSE ) == glib::ffi::GFALSE
{ {
@ -261,7 +256,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime> { fn parent_query_stop(&self) -> Option<gst::ClockTime> {
unsafe { unsafe {
use std::mem; use std::mem;
@ -270,7 +265,10 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
if let Some(f) = (*parent_class).query_stop { if let Some(f) = (*parent_class).query_stop {
let mut stop = mem::MaybeUninit::uninit(); let mut stop = mem::MaybeUninit::uninit();
if f( if f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
stop.as_mut_ptr(), stop.as_mut_ptr(),
) == glib::ffi::GFALSE ) == glib::ffi::GFALSE
{ {
@ -284,7 +282,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element> { fn parent_create_rtpbin(&self) -> Option<gst::Element> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
@ -292,15 +290,15 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
.create_rtpbin .create_rtpbin
.expect("No `create_rtpbin` virtual method implementation in parent class"); .expect("No `create_rtpbin` virtual method implementation in parent class");
from_glib_none(f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0)) from_glib_none(f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0))
} }
} }
fn parent_setup_rtpbin( fn parent_setup_rtpbin(&self, rtpbin: &gst::Element) -> Result<(), gst::LoggableError> {
&self,
media: &Self::Type,
rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
@ -311,7 +309,13 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
glib::gobject_ffi::g_object_force_floating(ptr as *mut _); glib::gobject_ffi::g_object_force_floating(ptr as *mut _);
let res = gst::result_from_gboolean!( let res = gst::result_from_gboolean!(
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, ptr), f(
self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
ptr
),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `setup_sdp` failed" "Parent function `setup_sdp` failed"
); );
@ -332,7 +336,6 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
fn parent_setup_sdp( fn parent_setup_sdp(
&self, &self,
media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -345,7 +348,10 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
sdp as *mut _ as *mut gst_sdp::ffi::GstSDPMessage, sdp as *mut _ as *mut gst_sdp::ffi::GstSDPMessage,
info.0.as_ptr() info.0.as_ptr()
), ),
@ -355,83 +361,99 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_new_stream(&self, media: &Self::Type, stream: &crate::RTSPStream) { fn parent_new_stream(&self, stream: &crate::RTSPStream) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).new_stream { if let Some(f) = (*parent_class).new_stream {
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
stream.to_glib_none().0, stream.to_glib_none().0,
); );
} }
} }
} }
fn parent_removed_stream(&self, media: &Self::Type, stream: &crate::RTSPStream) { fn parent_removed_stream(&self, stream: &crate::RTSPStream) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).removed_stream { if let Some(f) = (*parent_class).removed_stream {
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
stream.to_glib_none().0, stream.to_glib_none().0,
); );
} }
} }
} }
fn parent_prepared(&self, media: &Self::Type) { fn parent_prepared(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).prepared { if let Some(f) = (*parent_class).prepared {
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0); f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0);
} }
} }
} }
fn parent_unprepared(&self, media: &Self::Type) { fn parent_unprepared(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unprepared { if let Some(f) = (*parent_class).unprepared {
f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0); f(self
.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0);
} }
} }
} }
fn parent_target_state(&self, media: &Self::Type, state: gst::State) { fn parent_target_state(&self, state: gst::State) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).target_state { if let Some(f) = (*parent_class).target_state {
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
state.into_glib(), state.into_glib(),
); );
} }
} }
} }
fn parent_new_state(&self, media: &Self::Type, state: gst::State) { fn parent_new_state(&self, state: gst::State) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
if let Some(f) = (*parent_class).new_state { if let Some(f) = (*parent_class).new_state {
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
state.into_glib(), state.into_glib(),
); );
} }
} }
} }
fn parent_handle_sdp( fn parent_handle_sdp(&self, sdp: &gst_sdp::SDPMessageRef) -> Result<(), gst::LoggableError> {
&self,
media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaClass;
@ -441,7 +463,10 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPMedia>()
.to_glib_none()
.0,
sdp as *const _ as *mut gst_sdp::ffi::GstSDPMessage sdp as *const _ as *mut gst_sdp::ffi::GstSDPMessage
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -480,9 +505,8 @@ unsafe extern "C" fn media_handle_message<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.handle_message(wrap.unsafe_cast_ref(), gst::MessageRef::from_ptr(message)) imp.handle_message(gst::MessageRef::from_ptr(message))
.into_glib() .into_glib()
} }
@ -492,12 +516,11 @@ unsafe extern "C" fn media_prepare<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.prepare(wrap.unsafe_cast_ref(), &from_glib_borrow(thread)) { match imp.prepare(&from_glib_borrow(thread)) {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }
@ -508,12 +531,11 @@ unsafe extern "C" fn media_unprepare<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.unprepare(wrap.unsafe_cast_ref()) { match imp.unprepare() {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }
@ -524,12 +546,11 @@ unsafe extern "C" fn media_suspend<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.suspend(wrap.unsafe_cast_ref()) { match imp.suspend() {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }
@ -540,12 +561,11 @@ unsafe extern "C" fn media_unsuspend<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.unsuspend(wrap.unsafe_cast_ref()) { match imp.unsuspend() {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }
@ -557,9 +577,8 @@ unsafe extern "C" fn media_query_position<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.query_position(wrap.unsafe_cast_ref()) { match imp.query_position() {
Some(pos) => { Some(pos) => {
*position = pos.into_glib() as i64; *position = pos.into_glib() as i64;
glib::ffi::GTRUE glib::ffi::GTRUE
@ -574,9 +593,8 @@ unsafe extern "C" fn media_query_stop<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.query_stop(wrap.unsafe_cast_ref()) { match imp.query_stop() {
Some(s) => { Some(s) => {
*stop = s.into_glib() as i64; *stop = s.into_glib() as i64;
glib::ffi::GTRUE glib::ffi::GTRUE
@ -590,9 +608,8 @@ unsafe extern "C" fn media_create_rtpbin<T: RTSPMediaImpl>(
) -> *mut gst::ffi::GstElement { ) -> *mut gst::ffi::GstElement {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
let res: *mut gst::ffi::GstElement = imp.create_rtpbin(wrap.unsafe_cast_ref()).to_glib_full(); let res: *mut gst::ffi::GstElement = imp.create_rtpbin().to_glib_full();
if !res.is_null() { if !res.is_null() {
glib::gobject_ffi::g_object_force_floating(res as *mut _); glib::gobject_ffi::g_object_force_floating(res as *mut _);
@ -607,7 +624,6 @@ unsafe extern "C" fn media_setup_rtpbin<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
// If the rtpbin was floating before make sure it is not anymore for now so // If the rtpbin was floating before make sure it is not anymore for now so
// we don't accidentally take ownership of it somewhere along the line // we don't accidentally take ownership of it somewhere along the line
@ -615,10 +631,10 @@ unsafe extern "C" fn media_setup_rtpbin<T: RTSPMediaImpl>(
glib::gobject_ffi::g_object_ref_sink(rtpbin as *mut _); glib::gobject_ffi::g_object_ref_sink(rtpbin as *mut _);
} }
let res = match imp.setup_rtpbin(wrap.unsafe_cast_ref(), &from_glib_borrow(rtpbin)) { let res = match imp.setup_rtpbin(&from_glib_borrow(rtpbin)) {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
}; };
@ -636,16 +652,14 @@ unsafe extern "C" fn media_setup_sdp<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.setup_sdp( match imp.setup_sdp(
wrap.unsafe_cast_ref(),
&mut *(sdp as *mut gst_sdp::SDPMessageRef), &mut *(sdp as *mut gst_sdp::SDPMessageRef),
&SDPInfo(ptr::NonNull::new(info).expect("NULL SDPInfo")), &SDPInfo(ptr::NonNull::new(info).expect("NULL SDPInfo")),
) { ) {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }
@ -657,9 +671,8 @@ unsafe extern "C" fn media_new_stream<T: RTSPMediaImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.new_stream(wrap.unsafe_cast_ref(), &from_glib_borrow(stream)); imp.new_stream(&from_glib_borrow(stream));
} }
unsafe extern "C" fn media_removed_stream<T: RTSPMediaImpl>( unsafe extern "C" fn media_removed_stream<T: RTSPMediaImpl>(
@ -668,25 +681,22 @@ unsafe extern "C" fn media_removed_stream<T: RTSPMediaImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.removed_stream(wrap.unsafe_cast_ref(), &from_glib_borrow(stream)); imp.removed_stream(&from_glib_borrow(stream));
} }
unsafe extern "C" fn media_prepared<T: RTSPMediaImpl>(ptr: *mut ffi::GstRTSPMedia) { unsafe extern "C" fn media_prepared<T: RTSPMediaImpl>(ptr: *mut ffi::GstRTSPMedia) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.prepared(wrap.unsafe_cast_ref()); imp.prepared();
} }
unsafe extern "C" fn media_unprepared<T: RTSPMediaImpl>(ptr: *mut ffi::GstRTSPMedia) { unsafe extern "C" fn media_unprepared<T: RTSPMediaImpl>(ptr: *mut ffi::GstRTSPMedia) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.unprepared(wrap.unsafe_cast_ref()); imp.unprepared();
} }
unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>( unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>(
@ -695,9 +705,8 @@ unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.target_state(wrap.unsafe_cast_ref(), from_glib(state)); imp.target_state(from_glib(state));
} }
unsafe extern "C" fn media_new_state<T: RTSPMediaImpl>( unsafe extern "C" fn media_new_state<T: RTSPMediaImpl>(
@ -706,9 +715,8 @@ unsafe extern "C" fn media_new_state<T: RTSPMediaImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.new_state(wrap.unsafe_cast_ref(), from_glib(state)); imp.new_state(from_glib(state));
} }
unsafe extern "C" fn media_handle_sdp<T: RTSPMediaImpl>( unsafe extern "C" fn media_handle_sdp<T: RTSPMediaImpl>(
@ -717,15 +725,11 @@ unsafe extern "C" fn media_handle_sdp<T: RTSPMediaImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.handle_sdp( match imp.handle_sdp(&*(sdp as *const gst_sdp::SDPMessageRef)) {
wrap.unsafe_cast_ref(),
&*(sdp as *const gst_sdp::SDPMessageRef),
) {
Ok(()) => glib::ffi::GTRUE, Ok(()) => glib::ffi::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
glib::ffi::GFALSE glib::ffi::GFALSE
} }
} }

View file

@ -9,80 +9,52 @@ use crate::RTSPMediaFactory;
use std::mem::transmute; use std::mem::transmute;
pub trait RTSPMediaFactoryImpl: RTSPMediaFactoryImplExt + ObjectImpl + Send + Sync { pub trait RTSPMediaFactoryImpl: RTSPMediaFactoryImplExt + ObjectImpl + Send + Sync {
fn gen_key(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> { fn gen_key(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
self.parent_gen_key(factory, url) self.parent_gen_key(url)
} }
fn create_element( fn create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option<gst::Element> {
&self, self.parent_create_element(url)
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> {
self.parent_create_element(factory, url)
} }
fn construct(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option<crate::RTSPMedia> { fn construct(&self, url: &gst_rtsp::RTSPUrl) -> Option<crate::RTSPMedia> {
self.parent_construct(factory, url) self.parent_construct(url)
} }
fn create_pipeline( fn create_pipeline(&self, media: &crate::RTSPMedia) -> Option<gst::Pipeline> {
&self, self.parent_create_pipeline(media)
factory: &Self::Type,
media: &crate::RTSPMedia,
) -> Option<gst::Pipeline> {
self.parent_create_pipeline(factory, media)
} }
fn configure(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn configure(&self, media: &crate::RTSPMedia) {
self.parent_configure(factory, media) self.parent_configure(media)
} }
fn media_constructed(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn media_constructed(&self, media: &crate::RTSPMedia) {
self.parent_media_constructed(factory, media) self.parent_media_constructed(media)
} }
fn media_configure(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn media_configure(&self, media: &crate::RTSPMedia) {
self.parent_media_configure(factory, media) self.parent_media_configure(media)
} }
} }
pub trait RTSPMediaFactoryImplExt: ObjectSubclass { pub trait RTSPMediaFactoryImplExt: ObjectSubclass {
fn parent_gen_key( fn parent_gen_key(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString>;
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString>;
fn parent_create_element( fn parent_create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option<gst::Element>;
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element>;
fn parent_construct( fn parent_construct(&self, url: &gst_rtsp::RTSPUrl) -> Option<crate::RTSPMedia>;
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<crate::RTSPMedia>;
fn parent_create_pipeline( fn parent_create_pipeline(&self, media: &crate::RTSPMedia) -> Option<gst::Pipeline>;
&self,
factory: &Self::Type,
media: &crate::RTSPMedia,
) -> Option<gst::Pipeline>;
fn parent_configure(&self, factory: &Self::Type, media: &crate::RTSPMedia); fn parent_configure(&self, media: &crate::RTSPMedia);
fn parent_media_constructed(&self, factory: &Self::Type, media: &crate::RTSPMedia); fn parent_media_constructed(&self, media: &crate::RTSPMedia);
fn parent_media_configure(&self, factory: &Self::Type, media: &crate::RTSPMedia); fn parent_media_configure(&self, media: &crate::RTSPMedia);
} }
impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T { impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
fn parent_gen_key( fn parent_gen_key(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
@ -90,7 +62,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
.gen_key .gen_key
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -101,11 +73,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_create_element( fn parent_create_element(&self, url: &gst_rtsp::RTSPUrl) -> Option<gst::Element> {
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
@ -113,7 +81,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
.create_element .create_element
.map(|f| { .map(|f| {
from_glib_none(f( from_glib_none(f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -124,11 +92,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_construct( fn parent_construct(&self, url: &gst_rtsp::RTSPUrl) -> Option<crate::RTSPMedia> {
&self,
factory: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<crate::RTSPMedia> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
@ -136,7 +100,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
.construct .construct
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -147,11 +111,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_create_pipeline( fn parent_create_pipeline(&self, media: &crate::RTSPMedia) -> Option<gst::Pipeline> {
&self,
factory: &Self::Type,
media: &crate::RTSPMedia,
) -> Option<gst::Pipeline> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
@ -159,7 +119,7 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
.create_pipeline .create_pipeline
.map(|f| { .map(|f| {
let ptr = f( let ptr = f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -176,13 +136,13 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_configure(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn parent_configure(&self, media: &crate::RTSPMedia) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).configure { if let Some(f) = (*parent_class).configure {
f( f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -192,13 +152,13 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_media_constructed(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn parent_media_constructed(&self, media: &crate::RTSPMedia) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).media_constructed { if let Some(f) = (*parent_class).media_constructed {
f( f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -208,13 +168,13 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_media_configure(&self, factory: &Self::Type, media: &crate::RTSPMedia) { fn parent_media_configure(&self, media: &crate::RTSPMedia) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).media_configure { if let Some(f) = (*parent_class).media_configure {
f( f(
factory self.instance()
.unsafe_cast_ref::<RTSPMediaFactory>() .unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -244,10 +204,8 @@ unsafe extern "C" fn factory_gen_key<T: RTSPMediaFactoryImpl>(
) -> *mut std::os::raw::c_char { ) -> *mut std::os::raw::c_char {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.gen_key(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) imp.gen_key(&from_glib_borrow(url)).to_glib_full()
.to_glib_full()
} }
unsafe extern "C" fn factory_create_element<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_create_element<T: RTSPMediaFactoryImpl>(
@ -256,11 +214,8 @@ unsafe extern "C" fn factory_create_element<T: RTSPMediaFactoryImpl>(
) -> *mut gst::ffi::GstElement { ) -> *mut gst::ffi::GstElement {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
let element = imp let element = imp.create_element(&from_glib_borrow(url)).to_glib_full();
.create_element(wrap.unsafe_cast_ref(), &from_glib_borrow(url))
.to_glib_full();
glib::gobject_ffi::g_object_force_floating(element as *mut _); glib::gobject_ffi::g_object_force_floating(element as *mut _);
element element
} }
@ -271,10 +226,8 @@ unsafe extern "C" fn factory_construct<T: RTSPMediaFactoryImpl>(
) -> *mut ffi::GstRTSPMedia { ) -> *mut ffi::GstRTSPMedia {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.construct(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) imp.construct(&from_glib_borrow(url)).to_glib_full()
.to_glib_full()
} }
unsafe extern "C" fn factory_create_pipeline<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_create_pipeline<T: RTSPMediaFactoryImpl>(
@ -288,11 +241,9 @@ unsafe extern "C" fn factory_create_pipeline<T: RTSPMediaFactoryImpl>(
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
let pipeline: *mut gst::ffi::GstPipeline = imp let pipeline: *mut gst::ffi::GstPipeline =
.create_pipeline(wrap.unsafe_cast_ref(), &from_glib_borrow(media)) imp.create_pipeline(&from_glib_borrow(media)).to_glib_full();
.to_glib_full();
// FIXME We somehow need to ensure the pipeline actually stays alive... // FIXME We somehow need to ensure the pipeline actually stays alive...
glib::gobject_ffi::g_object_set_qdata_full( glib::gobject_ffi::g_object_set_qdata_full(
@ -313,9 +264,8 @@ unsafe extern "C" fn factory_configure<T: RTSPMediaFactoryImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.configure(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); imp.configure(&from_glib_borrow(media));
} }
unsafe extern "C" fn factory_media_constructed<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_media_constructed<T: RTSPMediaFactoryImpl>(
@ -324,9 +274,8 @@ unsafe extern "C" fn factory_media_constructed<T: RTSPMediaFactoryImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.media_constructed(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); imp.media_constructed(&from_glib_borrow(media));
} }
unsafe extern "C" fn factory_media_configure<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_media_configure<T: RTSPMediaFactoryImpl>(
@ -335,7 +284,6 @@ unsafe extern "C" fn factory_media_configure<T: RTSPMediaFactoryImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.media_configure(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); imp.media_configure(&from_glib_borrow(media));
} }

View file

@ -8,29 +8,17 @@ use gst_rtsp::ffi::GstRTSPUrl;
use crate::RTSPMountPoints; use crate::RTSPMountPoints;
pub trait RTSPMountPointsImpl: RTSPMountPointsImplExt + ObjectImpl + Send + Sync { pub trait RTSPMountPointsImpl: RTSPMountPointsImplExt + ObjectImpl + Send + Sync {
fn make_path( fn make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
&self, self.parent_make_path(url)
mount_points: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
self.parent_make_path(mount_points, url)
} }
} }
pub trait RTSPMountPointsImplExt: ObjectSubclass { pub trait RTSPMountPointsImplExt: ObjectSubclass {
fn parent_make_path( fn parent_make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString>;
&self,
mount_points: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString>;
} }
impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T { impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {
fn parent_make_path( fn parent_make_path(&self, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
&self,
mount_points: &Self::Type,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass;
@ -38,7 +26,7 @@ impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {
.make_path .make_path
.expect("No `make_path` virtual method implementation in parent class"); .expect("No `make_path` virtual method implementation in parent class");
from_glib_full(f( from_glib_full(f(
mount_points self.instance()
.unsafe_cast_ref::<RTSPMountPoints>() .unsafe_cast_ref::<RTSPMountPoints>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -62,8 +50,6 @@ unsafe extern "C" fn mount_points_make_path<T: RTSPMountPointsImpl>(
) -> *mut std::os::raw::c_char { ) -> *mut std::os::raw::c_char {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPMountPoints> = from_glib_borrow(ptr);
imp.make_path(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) imp.make_path(&from_glib_borrow(url)).to_glib_full()
.to_glib_full()
} }

View file

@ -10,17 +10,17 @@ use crate::RTSPOnvifMediaFactory;
pub trait RTSPOnvifMediaFactoryImpl: pub trait RTSPOnvifMediaFactoryImpl:
RTSPMediaFactoryImplExt + RTSPMediaFactoryImpl + Send + Sync RTSPMediaFactoryImplExt + RTSPMediaFactoryImpl + Send + Sync
{ {
fn has_backchannel_support(&self, factory: &Self::Type) -> bool { fn has_backchannel_support(&self) -> bool {
self.parent_has_backchannel_support(factory) self.parent_has_backchannel_support()
} }
} }
pub trait RTSPOnvifMediaFactoryImplExt: ObjectSubclass { pub trait RTSPOnvifMediaFactoryImplExt: ObjectSubclass {
fn parent_has_backchannel_support(&self, factory: &Self::Type) -> bool; fn parent_has_backchannel_support(&self) -> bool;
} }
impl<T: RTSPOnvifMediaFactoryImpl> RTSPOnvifMediaFactoryImplExt for T { impl<T: RTSPOnvifMediaFactoryImpl> RTSPOnvifMediaFactoryImplExt for T {
fn parent_has_backchannel_support(&self, factory: &Self::Type) -> bool { fn parent_has_backchannel_support(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = let parent_class =
@ -28,7 +28,8 @@ impl<T: RTSPOnvifMediaFactoryImpl> RTSPOnvifMediaFactoryImplExt for T {
(*parent_class) (*parent_class)
.has_backchannel_support .has_backchannel_support
.map(|f| { .map(|f| {
from_glib(f(factory from_glib(f(self
.instance()
.unsafe_cast_ref::<RTSPOnvifMediaFactory>() .unsafe_cast_ref::<RTSPOnvifMediaFactory>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -51,8 +52,6 @@ unsafe extern "C" fn factory_has_backchannel_support<T: RTSPOnvifMediaFactoryImp
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPOnvifMediaFactory> = from_glib_borrow(ptr);
imp.has_backchannel_support(wrap.unsafe_cast_ref()) imp.has_backchannel_support().into_glib()
.into_glib()
} }

View file

@ -7,40 +7,47 @@ use glib::translate::*;
use crate::RTSPServer; use crate::RTSPServer;
pub trait RTSPServerImpl: RTSPServerImplExt + ObjectImpl + Send + Sync { pub trait RTSPServerImpl: RTSPServerImplExt + ObjectImpl + Send + Sync {
fn create_client(&self, server: &Self::Type) -> Option<crate::RTSPClient> { fn create_client(&self) -> Option<crate::RTSPClient> {
self.parent_create_client(server) self.parent_create_client()
} }
fn client_connected(&self, server: &Self::Type, client: &crate::RTSPClient) { fn client_connected(&self, client: &crate::RTSPClient) {
self.parent_client_connected(server, client); self.parent_client_connected(client);
} }
} }
pub trait RTSPServerImplExt: ObjectSubclass { pub trait RTSPServerImplExt: ObjectSubclass {
fn parent_create_client(&self, server: &Self::Type) -> Option<crate::RTSPClient>; fn parent_create_client(&self) -> Option<crate::RTSPClient>;
fn parent_client_connected(&self, server: &Self::Type, client: &crate::RTSPClient); fn parent_client_connected(&self, client: &crate::RTSPClient);
} }
impl<T: RTSPServerImpl> RTSPServerImplExt for T { impl<T: RTSPServerImpl> RTSPServerImplExt for T {
fn parent_create_client(&self, server: &Self::Type) -> Option<crate::RTSPClient> { fn parent_create_client(&self) -> Option<crate::RTSPClient> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPServerClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPServerClass;
let f = (*parent_class) let f = (*parent_class)
.create_client .create_client
.expect("No `create_client` virtual method implementation in parent class"); .expect("No `create_client` virtual method implementation in parent class");
from_glib_full(f(server.unsafe_cast_ref::<RTSPServer>().to_glib_none().0)) from_glib_full(f(self
.instance()
.unsafe_cast_ref::<RTSPServer>()
.to_glib_none()
.0))
} }
} }
fn parent_client_connected(&self, server: &Self::Type, client: &crate::RTSPClient) { fn parent_client_connected(&self, client: &crate::RTSPClient) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPServerClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPServerClass;
if let Some(f) = (*parent_class).client_connected { if let Some(f) = (*parent_class).client_connected {
f( f(
server.unsafe_cast_ref::<RTSPServer>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<RTSPServer>()
.to_glib_none()
.0,
client.to_glib_none().0, client.to_glib_none().0,
) )
} }
@ -61,9 +68,8 @@ unsafe extern "C" fn server_create_client<T: RTSPServerImpl>(
) -> *mut ffi::GstRTSPClient { ) -> *mut ffi::GstRTSPClient {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPServer> = from_glib_borrow(ptr);
imp.create_client(wrap.unsafe_cast_ref()).to_glib_full() imp.create_client().to_glib_full()
} }
unsafe extern "C" fn server_client_connected<T: RTSPServerImpl>( unsafe extern "C" fn server_client_connected<T: RTSPServerImpl>(
@ -72,7 +78,6 @@ unsafe extern "C" fn server_client_connected<T: RTSPServerImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<RTSPServer> = from_glib_borrow(ptr);
imp.client_connected(wrap.unsafe_cast_ref(), &from_glib_borrow(client)); imp.client_connected(&from_glib_borrow(client));
} }

View file

@ -8,31 +8,31 @@ use glib::subclass::prelude::*;
use crate::Navigation; use crate::Navigation;
pub trait NavigationImpl: ObjectImpl { pub trait NavigationImpl: ObjectImpl {
fn send_event(&self, nav: &Self::Type, structure: gst::Structure); fn send_event(&self, structure: gst::Structure);
#[cfg(any(feature = "v1_22", feature = "dox"))] #[cfg(any(feature = "v1_22", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))]
fn send_event_simple(&self, nav: &Self::Type, event: gst::Event) { fn send_event_simple(&self, event: gst::Event) {
if let Some(structure) = event.structure() { if let Some(structure) = event.structure() {
self.send_event(nav, structure.to_owned()); self.send_event(structure.to_owned());
} }
} }
} }
pub trait NavigationImplExt: ObjectSubclass { pub trait NavigationImplExt: ObjectSubclass {
fn parent_send_event(&self, nav: &Self::Type, structure: gst::Structure); fn parent_send_event(&self, structure: gst::Structure);
#[cfg(any(feature = "v1_22", feature = "dox"))] #[cfg(any(feature = "v1_22", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))]
fn parent_send_event_simple(&self, nav: &Self::Type, event: gst::Event) { fn parent_send_event_simple(&self, event: gst::Event) {
if let Some(structure) = event.structure() { if let Some(structure) = event.structure() {
self.parent_send_event(nav, structure.to_owned()); self.parent_send_event(structure.to_owned());
} }
} }
} }
impl<T: NavigationImpl> NavigationImplExt for T { impl<T: NavigationImpl> NavigationImplExt for T {
fn parent_send_event(&self, nav: &Self::Type, structure: gst::Structure) { fn parent_send_event(&self, structure: gst::Structure) {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<Navigation>() let parent_iface = type_data.as_ref().parent_interface::<Navigation>()
@ -44,7 +44,10 @@ impl<T: NavigationImpl> NavigationImplExt for T {
}; };
func( func(
nav.unsafe_cast_ref::<Navigation>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Navigation>()
.to_glib_none()
.0,
structure.into_glib_ptr(), structure.into_glib_ptr(),
); );
} }
@ -52,7 +55,7 @@ impl<T: NavigationImpl> NavigationImplExt for T {
#[cfg(any(feature = "v1_22", feature = "dox"))] #[cfg(any(feature = "v1_22", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_22")))]
fn parent_send_event_simple(&self, nav: &Self::Type, event: gst::Event) { fn parent_send_event_simple(&self, event: gst::Event) {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<Navigation>() let parent_iface = type_data.as_ref().parent_interface::<Navigation>()
@ -64,7 +67,10 @@ impl<T: NavigationImpl> NavigationImplExt for T {
}; };
func( func(
nav.unsafe_cast_ref::<Navigation>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Navigation>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
); );
} }
@ -96,10 +102,7 @@ unsafe extern "C" fn navigation_send_event<T: NavigationImpl>(
let instance = &*(nav as *mut T::Instance); let instance = &*(nav as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.send_event( imp.send_event(from_glib_full(structure));
from_glib_borrow::<_, Navigation>(nav).unsafe_cast_ref(),
from_glib_full(structure),
);
} }
#[cfg(any(feature = "v1_22", feature = "dox"))] #[cfg(any(feature = "v1_22", feature = "dox"))]
@ -111,8 +114,5 @@ unsafe extern "C" fn navigation_send_event_simple<T: NavigationImpl>(
let instance = &*(nav as *mut T::Instance); let instance = &*(nav as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.send_event_simple( imp.send_event_simple(from_glib_full(event));
from_glib_borrow::<_, Navigation>(nav).unsafe_cast_ref(),
from_glib_full(event),
);
} }

View file

@ -13,71 +13,46 @@ use crate::VideoAggregator;
pub struct AggregateFramesToken<'a>(pub(crate) &'a VideoAggregator); pub struct AggregateFramesToken<'a>(pub(crate) &'a VideoAggregator);
pub trait VideoAggregatorImpl: VideoAggregatorImplExt + AggregatorImpl { pub trait VideoAggregatorImpl: VideoAggregatorImplExt + AggregatorImpl {
fn update_caps( fn update_caps(&self, caps: &gst::Caps) -> Result<gst::Caps, gst::LoggableError> {
&self, self.parent_update_caps(caps)
element: &Self::Type,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::LoggableError> {
self.parent_update_caps(element, caps)
} }
fn aggregate_frames( fn aggregate_frames(
&self, &self,
element: &Self::Type,
token: &AggregateFramesToken, token: &AggregateFramesToken,
outbuf: &mut gst::BufferRef, outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_aggregate_frames(element, token, outbuf) self.parent_aggregate_frames(token, outbuf)
} }
fn create_output_buffer( fn create_output_buffer(&self) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self, self.parent_create_output_buffer()
element: &Self::Type,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
self.parent_create_output_buffer(element)
} }
fn find_best_format( fn find_best_format(&self, downstream_caps: &gst::Caps) -> Option<(crate::VideoInfo, bool)> {
&self, self.parent_find_best_format(downstream_caps)
element: &Self::Type,
downstream_caps: &gst::Caps,
) -> Option<(crate::VideoInfo, bool)> {
self.parent_find_best_format(element, downstream_caps)
} }
} }
pub trait VideoAggregatorImplExt: ObjectSubclass { pub trait VideoAggregatorImplExt: ObjectSubclass {
fn parent_update_caps( fn parent_update_caps(&self, caps: &gst::Caps) -> Result<gst::Caps, gst::LoggableError>;
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::LoggableError>;
fn parent_aggregate_frames( fn parent_aggregate_frames(
&self, &self,
element: &Self::Type,
token: &AggregateFramesToken, token: &AggregateFramesToken,
outbuf: &mut gst::BufferRef, outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_create_output_buffer( fn parent_create_output_buffer(&self) -> Result<Option<gst::Buffer>, gst::FlowError>;
&self,
element: &Self::Type,
) -> Result<Option<gst::Buffer>, gst::FlowError>;
fn parent_find_best_format( fn parent_find_best_format(
&self, &self,
element: &Self::Type,
downstream_caps: &gst::Caps, downstream_caps: &gst::Caps,
) -> Option<(crate::VideoInfo, bool)>; ) -> Option<(crate::VideoInfo, bool)>;
} }
impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T { impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
fn parent_update_caps( fn parent_update_caps(&self, caps: &gst::Caps) -> Result<gst::Caps, gst::LoggableError> {
&self,
element: &Self::Type,
caps: &gst::Caps,
) -> Result<gst::Caps, gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorClass;
@ -86,7 +61,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
.expect("Missing parent function `update_caps`"); .expect("Missing parent function `update_caps`");
Option::<_>::from_glib_full(f( Option::<_>::from_glib_full(f(
element self.instance()
.unsafe_cast_ref::<VideoAggregator>() .unsafe_cast_ref::<VideoAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -100,12 +75,11 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
fn parent_aggregate_frames( fn parent_aggregate_frames(
&self, &self,
element: &Self::Type,
token: &AggregateFramesToken, token: &AggregateFramesToken,
outbuf: &mut gst::BufferRef, outbuf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
assert_eq!( assert_eq!(
element.as_ptr() as *mut ffi::GstVideoAggregator, self.instance().as_ptr() as *mut ffi::GstVideoAggregator,
token.0.as_ptr() as *mut ffi::GstVideoAggregator token.0.as_ptr() as *mut ffi::GstVideoAggregator
); );
@ -117,7 +91,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
.expect("Missing parent function `aggregate_frames`"); .expect("Missing parent function `aggregate_frames`");
try_from_glib(f( try_from_glib(f(
element self.instance()
.unsafe_cast_ref::<VideoAggregator>() .unsafe_cast_ref::<VideoAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -127,10 +101,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
} }
} }
fn parent_create_output_buffer( fn parent_create_output_buffer(&self) -> Result<Option<gst::Buffer>, gst::FlowError> {
&self,
element: &Self::Type,
) -> Result<Option<gst::Buffer>, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorClass;
@ -140,7 +111,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
let mut buffer = ptr::null_mut(); let mut buffer = ptr::null_mut();
try_from_glib(f( try_from_glib(f(
element self.instance()
.unsafe_cast_ref::<VideoAggregator>() .unsafe_cast_ref::<VideoAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -152,7 +123,6 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
fn parent_find_best_format( fn parent_find_best_format(
&self, &self,
element: &Self::Type,
downstream_caps: &gst::Caps, downstream_caps: &gst::Caps,
) -> Option<(crate::VideoInfo, bool)> { ) -> Option<(crate::VideoInfo, bool)> {
unsafe { unsafe {
@ -166,7 +136,7 @@ impl<T: VideoAggregatorImpl> VideoAggregatorImplExt for T {
let mut at_least_one_alpha = glib::ffi::GFALSE; let mut at_least_one_alpha = glib::ffi::GFALSE;
f( f(
element self.instance()
.unsafe_cast_ref::<VideoAggregator>() .unsafe_cast_ref::<VideoAggregator>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -206,13 +176,12 @@ unsafe extern "C" fn video_aggregator_update_caps<T: VideoAggregatorImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), ptr::null_mut(), { gst::panic_to_error!(imp, ptr::null_mut(), {
match imp.update_caps(wrap.unsafe_cast_ref(), &from_glib_borrow(caps)) { match imp.update_caps(&from_glib_borrow(caps)) {
Ok(caps) => caps.into_glib_ptr(), Ok(caps) => caps.into_glib_ptr(),
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
ptr::null_mut() ptr::null_mut()
} }
} }
@ -225,13 +194,13 @@ unsafe extern "C" fn video_aggregator_aggregate_frames<T: VideoAggregatorImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
let token = AggregateFramesToken(&*wrap); let instance = imp.instance();
let instance = instance.unsafe_cast_ref::<VideoAggregator>();
let token = AggregateFramesToken(instance);
imp.aggregate_frames( imp.aggregate_frames(
wrap.unsafe_cast_ref(),
&token, &token,
gst::BufferRef::from_mut_ptr( gst::BufferRef::from_mut_ptr(
// Wrong pointer type // Wrong pointer type
@ -249,10 +218,9 @@ unsafe extern "C" fn video_aggregator_create_output_buffer<T: VideoAggregatorImp
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
match imp.create_output_buffer(wrap.unsafe_cast_ref()) { match imp.create_output_buffer() {
Ok(buffer) => { Ok(buffer) => {
*outbuf = buffer.map(|b| b.into_glib_ptr()).unwrap_or(ptr::null_mut()); *outbuf = buffer.map(|b| b.into_glib_ptr()).unwrap_or(ptr::null_mut());
Ok(gst::FlowSuccess::Ok) Ok(gst::FlowSuccess::Ok)
@ -275,10 +243,9 @@ unsafe extern "C" fn video_aggregator_find_best_format<T: VideoAggregatorImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregator> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), (), { gst::panic_to_error!(imp, (), {
match imp.find_best_format(wrap.unsafe_cast_ref(), &from_glib_borrow(downstream_caps)) { match imp.find_best_format(&from_glib_borrow(downstream_caps)) {
None => (), None => (),
Some((info, alpha)) => { Some((info, alpha)) => {
*best_info = *info.to_glib_none().0; *best_info = *info.to_glib_none().0;

View file

@ -13,37 +13,34 @@ use crate::VideoAggregator;
use crate::VideoAggregatorPad; use crate::VideoAggregatorPad;
pub trait VideoAggregatorPadImpl: VideoAggregatorPadImplExt + AggregatorPadImpl { pub trait VideoAggregatorPadImpl: VideoAggregatorPadImplExt + AggregatorPadImpl {
fn update_conversion_info(&self, pad: &Self::Type) { fn update_conversion_info(&self) {
self.parent_update_conversion_info(pad) self.parent_update_conversion_info()
} }
fn prepare_frame( fn prepare_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
buffer: &gst::Buffer, buffer: &gst::Buffer,
) -> Option<crate::VideoFrame<crate::video_frame::Readable>> { ) -> Option<crate::VideoFrame<crate::video_frame::Readable>> {
self.parent_prepare_frame(pad, aggregator, token, buffer) self.parent_prepare_frame(aggregator, token, buffer)
} }
fn clean_frame( fn clean_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
frame: Option<crate::VideoFrame<crate::video_frame::Readable>>, frame: Option<crate::VideoFrame<crate::video_frame::Readable>>,
) { ) {
self.parent_clean_frame(pad, aggregator, token, frame) self.parent_clean_frame(aggregator, token, frame)
} }
} }
pub trait VideoAggregatorPadImplExt: ObjectSubclass { pub trait VideoAggregatorPadImplExt: ObjectSubclass {
fn parent_update_conversion_info(&self, pad: &Self::Type); fn parent_update_conversion_info(&self);
fn parent_prepare_frame( fn parent_prepare_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
buffer: &gst::Buffer, buffer: &gst::Buffer,
@ -51,7 +48,6 @@ pub trait VideoAggregatorPadImplExt: ObjectSubclass {
fn parent_clean_frame( fn parent_clean_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
frame: Option<crate::VideoFrame<crate::video_frame::Readable>>, frame: Option<crate::VideoFrame<crate::video_frame::Readable>>,
@ -59,19 +55,22 @@ pub trait VideoAggregatorPadImplExt: ObjectSubclass {
} }
impl<T: VideoAggregatorPadImpl> VideoAggregatorPadImplExt for T { impl<T: VideoAggregatorPadImpl> VideoAggregatorPadImplExt for T {
fn parent_update_conversion_info(&self, pad: &Self::Type) { fn parent_update_conversion_info(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoAggregatorPadClass;
if let Some(f) = (*parent_class).update_conversion_info { if let Some(f) = (*parent_class).update_conversion_info {
f(pad.unsafe_cast_ref::<VideoAggregatorPad>().to_glib_none().0); f(self
.instance()
.unsafe_cast_ref::<VideoAggregatorPad>()
.to_glib_none()
.0);
} }
} }
} }
fn parent_prepare_frame( fn parent_prepare_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
buffer: &gst::Buffer, buffer: &gst::Buffer,
@ -88,7 +87,10 @@ impl<T: VideoAggregatorPadImpl> VideoAggregatorPadImplExt for T {
let mut prepared_frame = mem::MaybeUninit::zeroed(); let mut prepared_frame = mem::MaybeUninit::zeroed();
f( f(
pad.unsafe_cast_ref::<VideoAggregatorPad>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoAggregatorPad>()
.to_glib_none()
.0,
aggregator.to_glib_none().0, aggregator.to_glib_none().0,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
prepared_frame.as_mut_ptr(), prepared_frame.as_mut_ptr(),
@ -108,7 +110,6 @@ impl<T: VideoAggregatorPadImpl> VideoAggregatorPadImplExt for T {
fn parent_clean_frame( fn parent_clean_frame(
&self, &self,
pad: &Self::Type,
aggregator: &crate::VideoAggregator, aggregator: &crate::VideoAggregator,
token: &AggregateFramesToken, token: &AggregateFramesToken,
frame: Option<crate::VideoFrame<crate::video_frame::Readable>>, frame: Option<crate::VideoFrame<crate::video_frame::Readable>>,
@ -129,7 +130,10 @@ impl<T: VideoAggregatorPadImpl> VideoAggregatorPadImplExt for T {
}; };
f( f(
pad.unsafe_cast_ref::<VideoAggregatorPad>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoAggregatorPad>()
.to_glib_none()
.0,
aggregator.to_glib_none().0, aggregator.to_glib_none().0,
&mut prepared_frame, &mut prepared_frame,
); );
@ -154,9 +158,8 @@ unsafe extern "C" fn video_aggregator_pad_update_conversion_info<T: VideoAggrega
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregatorPad> = from_glib_borrow(ptr);
imp.update_conversion_info(wrap.unsafe_cast_ref()); imp.update_conversion_info();
} }
unsafe extern "C" fn video_aggregator_pad_prepare_frame<T: VideoAggregatorPadImpl>( unsafe extern "C" fn video_aggregator_pad_prepare_frame<T: VideoAggregatorPadImpl>(
@ -167,17 +170,11 @@ unsafe extern "C" fn video_aggregator_pad_prepare_frame<T: VideoAggregatorPadImp
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregatorPad> = from_glib_borrow(ptr);
let aggregator: Borrowed<VideoAggregator> = from_glib_borrow(aggregator); let aggregator: Borrowed<VideoAggregator> = from_glib_borrow(aggregator);
let token = AggregateFramesToken(&*aggregator); let token = AggregateFramesToken(&*aggregator);
match imp.prepare_frame( match imp.prepare_frame(&aggregator, &token, &from_glib_borrow(buffer)) {
wrap.unsafe_cast_ref(),
&aggregator,
&token,
&from_glib_borrow(buffer),
) {
Some(frame) => { Some(frame) => {
*prepared_frame = frame.into_raw(); *prepared_frame = frame.into_raw();
} }
@ -196,7 +193,6 @@ unsafe extern "C" fn video_aggregator_pad_clean_frame<T: VideoAggregatorPadImpl>
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoAggregatorPad> = from_glib_borrow(ptr);
let aggregator: Borrowed<VideoAggregator> = from_glib_borrow(aggregator); let aggregator: Borrowed<VideoAggregator> = from_glib_borrow(aggregator);
let token = AggregateFramesToken(&*aggregator); let token = AggregateFramesToken(&*aggregator);
@ -209,5 +205,5 @@ unsafe extern "C" fn video_aggregator_pad_clean_frame<T: VideoAggregatorPadImpl>
Some(frame) Some(frame)
}; };
imp.clean_frame(wrap.unsafe_cast_ref(), &aggregator, &token, frame); imp.clean_frame(&aggregator, &token, frame);
} }

View file

@ -10,134 +10,123 @@ use crate::VideoCodecFrame;
use crate::VideoDecoder; use crate::VideoDecoder;
pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl { pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self) -> Result<(), gst::ErrorMessage> {
self.parent_open(element) self.parent_open()
} }
fn close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn close(&self) -> Result<(), gst::ErrorMessage> {
self.parent_close(element) self.parent_close()
} }
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn finish(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_finish(element) self.parent_finish()
} }
fn drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn drain(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_drain(element) self.parent_drain()
} }
fn set_format( fn set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_set_format(element, state) self.parent_set_format(state)
} }
fn parse( fn parse(
&self, &self,
element: &Self::Type,
frame: &VideoCodecFrame, frame: &VideoCodecFrame,
adapter: &gst_base::Adapter, adapter: &gst_base::Adapter,
at_eos: bool, at_eos: bool,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_parse(element, frame, adapter, at_eos) self.parent_parse(frame, adapter, at_eos)
} }
fn handle_frame( fn handle_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_handle_frame(frame)
element: &Self::Type,
frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_handle_frame(element, frame)
} }
fn flush(&self, element: &Self::Type) -> bool { fn flush(&self) -> bool {
self.parent_flush(element) self.parent_flush()
} }
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn negotiate(&self) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate()
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn sink_event(&self, event: gst::Event) -> bool {
self.parent_sink_event(element, event) self.parent_sink_event(event)
} }
fn sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_sink_query(element, query) self.parent_sink_query(query)
} }
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn src_event(&self, event: gst::Event) -> bool {
self.parent_src_event(element, event) self.parent_src_event(event)
} }
fn src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn src_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_src_query(element, query) self.parent_src_query(query)
} }
fn propose_allocation( fn propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_propose_allocation(element, query) self.parent_propose_allocation(query)
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
#[cfg(any(feature = "v1_20", feature = "dox"))] #[cfg(any(feature = "v1_20", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
fn handle_missing_data( fn handle_missing_data(
&self, &self,
element: &Self::Type,
timestamp: gst::ClockTime, timestamp: gst::ClockTime,
duration: Option<gst::ClockTime>, duration: Option<gst::ClockTime>,
) -> bool { ) -> bool {
self.parent_handle_missing_data(element, timestamp, duration) self.parent_handle_missing_data(timestamp, duration)
} }
} }
pub trait VideoDecoderImplExt: ObjectSubclass { pub trait VideoDecoderImplExt: ObjectSubclass {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_open(&self) -> Result<(), gst::ErrorMessage>;
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_close(&self) -> Result<(), gst::ErrorMessage>;
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError>; fn parent_finish(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError>; fn parent_drain(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_set_format( fn parent_set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_parse( fn parent_parse(
&self, &self,
element: &Self::Type,
frame: &VideoCodecFrame, frame: &VideoCodecFrame,
adapter: &gst_base::Adapter, adapter: &gst_base::Adapter,
at_eos: bool, at_eos: bool,
@ -145,33 +134,30 @@ pub trait VideoDecoderImplExt: ObjectSubclass {
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
frame: VideoCodecFrame, frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_flush(&self, element: &Self::Type) -> bool; fn parent_flush(&self) -> bool;
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>; fn parent_negotiate(&self) -> Result<(), gst::LoggableError>;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps; fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps;
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_sink_event(&self, event: gst::Event) -> bool;
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_src_event(&self, event: gst::Event) -> bool;
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
@ -179,21 +165,21 @@ pub trait VideoDecoderImplExt: ObjectSubclass {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
fn parent_handle_missing_data( fn parent_handle_missing_data(
&self, &self,
element: &Self::Type,
timestamp: gst::ClockTime, timestamp: gst::ClockTime,
duration: Option<gst::ClockTime>, duration: Option<gst::ClockTime>,
) -> bool; ) -> bool;
} }
impl<T: VideoDecoderImpl> VideoDecoderImplExt for T { impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -210,14 +196,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -234,14 +221,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -258,14 +246,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -282,14 +271,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn parent_finish(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.finish .finish
.map(|f| { .map(|f| {
try_from_glib(f(element try_from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -298,14 +288,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn parent_drain(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.drain .drain
.map(|f| { .map(|f| {
try_from_glib(f(element try_from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -316,7 +307,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_set_format( fn parent_set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -327,7 +317,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
state.as_mut_ptr() state.as_mut_ptr()
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -340,7 +333,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_parse( fn parent_parse(
&self, &self,
element: &Self::Type,
frame: &VideoCodecFrame, frame: &VideoCodecFrame,
adapter: &gst_base::Adapter, adapter: &gst_base::Adapter,
at_eos: bool, at_eos: bool,
@ -352,7 +344,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.parse .parse
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
frame.to_glib_none().0, frame.to_glib_none().0,
adapter.to_glib_none().0, adapter.to_glib_none().0,
at_eos.into_glib(), at_eos.into_glib(),
@ -364,7 +359,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
frame: VideoCodecFrame, frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -374,7 +368,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.handle_frame .handle_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
frame.to_glib_none().0, frame.to_glib_none().0,
)) ))
}) })
@ -382,14 +379,15 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_flush(&self, element: &Self::Type) -> bool { fn parent_flush(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
(*parent_class) (*parent_class)
.flush .flush
.map(|f| { .map(|f| {
from_glib(f(element from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -398,7 +396,7 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -406,7 +404,11 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.negotiate .negotiate
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
) )
@ -415,7 +417,7 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -423,19 +425,22 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.getcaps .getcaps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
element self.instance()
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.proxy_getcaps(None, filter) .proxy_getcaps(None, filter)
}) })
} }
} }
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -443,13 +448,16 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -457,13 +465,16 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
} }
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -471,13 +482,16 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoDecoderClass;
@ -485,7 +499,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
@ -493,7 +510,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -504,7 +520,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -517,7 +536,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -528,7 +546,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -543,7 +564,6 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_20")))]
fn parent_handle_missing_data( fn parent_handle_missing_data(
&self, &self,
element: &Self::Type,
timestamp: gst::ClockTime, timestamp: gst::ClockTime,
duration: Option<gst::ClockTime>, duration: Option<gst::ClockTime>,
) -> bool { ) -> bool {
@ -554,7 +574,10 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
.handle_missing_data .handle_missing_data
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoDecoder>()
.to_glib_none()
.0,
timestamp.into_glib(), timestamp.into_glib(),
duration.into_glib(), duration.into_glib(),
)) ))
@ -598,13 +621,12 @@ unsafe extern "C" fn video_decoder_open<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -617,13 +639,12 @@ unsafe extern "C" fn video_decoder_close<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -636,13 +657,12 @@ unsafe extern "C" fn video_decoder_start<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -655,13 +675,12 @@ unsafe extern "C" fn video_decoder_stop<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -674,12 +693,8 @@ unsafe extern "C" fn video_decoder_finish<T: VideoDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.finish().into() }).into_glib()
imp.finish(wrap.unsafe_cast_ref()).into()
})
.into_glib()
} }
unsafe extern "C" fn video_decoder_drain<T: VideoDecoderImpl>( unsafe extern "C" fn video_decoder_drain<T: VideoDecoderImpl>(
@ -687,12 +702,8 @@ unsafe extern "C" fn video_decoder_drain<T: VideoDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.drain().into() }).into_glib()
imp.drain(wrap.unsafe_cast_ref()).into()
})
.into_glib()
} }
unsafe extern "C" fn video_decoder_set_format<T: VideoDecoderImpl>( unsafe extern "C" fn video_decoder_set_format<T: VideoDecoderImpl>(
@ -701,15 +712,14 @@ unsafe extern "C" fn video_decoder_set_format<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
ffi::gst_video_codec_state_ref(state); ffi::gst_video_codec_state_ref(state);
let wrap_state = VideoCodecState::<Readable>::new(state); let wrap_state = VideoCodecState::<Readable>::new(state);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_format(wrap.unsafe_cast_ref(), &wrap_state) { match imp.set_format(&wrap_state) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -725,15 +735,15 @@ unsafe extern "C" fn video_decoder_parse<T: VideoDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
ffi::gst_video_codec_frame_ref(frame); ffi::gst_video_codec_frame_ref(frame);
let wrap_frame = VideoCodecFrame::new(frame, &*wrap); let instance = imp.instance();
let instance = instance.unsafe_cast_ref::<VideoDecoder>();
let wrap_frame = VideoCodecFrame::new(frame, instance);
let wrap_adapter: Borrowed<gst_base::Adapter> = from_glib_borrow(adapter); let wrap_adapter: Borrowed<gst_base::Adapter> = from_glib_borrow(adapter);
let at_eos: bool = from_glib(at_eos); let at_eos: bool = from_glib(at_eos);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.parse(wrap.unsafe_cast_ref(), &wrap_frame, &wrap_adapter, at_eos) imp.parse(&wrap_frame, &wrap_adapter, at_eos).into()
.into()
}) })
.into_glib() .into_glib()
} }
@ -744,11 +754,12 @@ unsafe extern "C" fn video_decoder_handle_frame<T: VideoDecoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr); let instance = imp.instance();
let wrap_frame = VideoCodecFrame::new(frame, &*wrap); let instance = instance.unsafe_cast_ref::<VideoDecoder>();
let wrap_frame = VideoCodecFrame::new(frame, instance);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.handle_frame(wrap.unsafe_cast_ref(), wrap_frame).into() imp.handle_frame(wrap_frame).into()
}) })
.into_glib() .into_glib()
} }
@ -758,12 +769,8 @@ unsafe extern "C" fn video_decoder_flush<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { VideoDecoderImpl::flush(imp) }).into_glib()
VideoDecoderImpl::flush(imp, wrap.unsafe_cast_ref())
})
.into_glib()
} }
unsafe extern "C" fn video_decoder_negotiate<T: VideoDecoderImpl>( unsafe extern "C" fn video_decoder_negotiate<T: VideoDecoderImpl>(
@ -771,13 +778,12 @@ unsafe extern "C" fn video_decoder_negotiate<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -791,12 +797,10 @@ unsafe extern "C" fn video_decoder_getcaps<T: VideoDecoderImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), {
VideoDecoderImpl::caps( VideoDecoderImpl::caps(
imp, imp,
wrap.unsafe_cast_ref(),
Option::<gst::Caps>::from_glib_borrow(filter) Option::<gst::Caps>::from_glib_borrow(filter)
.as_ref() .as_ref()
.as_ref(), .as_ref(),
@ -811,12 +815,8 @@ unsafe extern "C" fn video_decoder_sink_event<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn video_decoder_sink_query<T: VideoDecoderImpl>( unsafe extern "C" fn video_decoder_sink_query<T: VideoDecoderImpl>(
@ -825,10 +825,9 @@ unsafe extern "C" fn video_decoder_sink_query<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -839,12 +838,8 @@ unsafe extern "C" fn video_decoder_src_event<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn video_decoder_src_query<T: VideoDecoderImpl>( unsafe extern "C" fn video_decoder_src_query<T: VideoDecoderImpl>(
@ -853,10 +848,9 @@ unsafe extern "C" fn video_decoder_src_query<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -867,17 +861,16 @@ unsafe extern "C" fn video_decoder_propose_allocation<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -891,17 +884,16 @@ unsafe extern "C" fn video_decoder_decide_allocation<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -917,11 +909,9 @@ unsafe extern "C" fn video_decoder_handle_missing_data<T: VideoDecoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoDecoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), true, { gst::panic_to_error!(imp, true, {
imp.handle_missing_data( imp.handle_missing_data(
wrap.unsafe_cast_ref(),
Option::<gst::ClockTime>::from_glib(timestamp).unwrap(), Option::<gst::ClockTime>::from_glib(timestamp).unwrap(),
from_glib(duration), from_glib(duration),
) )

View file

@ -10,146 +10,136 @@ use crate::VideoCodecFrame;
use crate::VideoEncoder; use crate::VideoEncoder;
pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl { pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self) -> Result<(), gst::ErrorMessage> {
self.parent_open(element) self.parent_open()
} }
fn close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn close(&self) -> Result<(), gst::ErrorMessage> {
self.parent_close(element) self.parent_close()
} }
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn start(&self) -> Result<(), gst::ErrorMessage> {
self.parent_start(element) self.parent_start()
} }
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn stop(&self) -> Result<(), gst::ErrorMessage> {
self.parent_stop(element) self.parent_stop()
} }
fn finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn finish(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_finish(element) self.parent_finish()
} }
fn set_format( fn set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_set_format(element, state) self.parent_set_format(state)
} }
fn handle_frame( fn handle_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_handle_frame(frame)
element: &Self::Type,
frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_handle_frame(element, frame)
} }
fn flush(&self, element: &Self::Type) -> bool { fn flush(&self) -> bool {
self.parent_flush(element) self.parent_flush()
} }
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn negotiate(&self) -> Result<(), gst::LoggableError> {
self.parent_negotiate(element) self.parent_negotiate()
} }
fn caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
self.parent_caps(element, filter) self.parent_caps(filter)
} }
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn sink_event(&self, event: gst::Event) -> bool {
self.parent_sink_event(element, event) self.parent_sink_event(event)
} }
fn sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn sink_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_sink_query(element, query) self.parent_sink_query(query)
} }
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn src_event(&self, event: gst::Event) -> bool {
self.parent_src_event(element, event) self.parent_src_event(event)
} }
fn src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn src_query(&self, query: &mut gst::QueryRef) -> bool {
self.parent_src_query(element, query) self.parent_src_query(query)
} }
fn propose_allocation( fn propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_propose_allocation(element, query) self.parent_propose_allocation(query)
} }
fn decide_allocation( fn decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_decide_allocation(element, query) self.parent_decide_allocation(query)
} }
} }
pub trait VideoEncoderImplExt: ObjectSubclass { pub trait VideoEncoderImplExt: ObjectSubclass {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_open(&self) -> Result<(), gst::ErrorMessage>;
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_close(&self) -> Result<(), gst::ErrorMessage>;
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>; fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError>; fn parent_finish(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_set_format( fn parent_set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
frame: VideoCodecFrame, frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_flush(&self, element: &Self::Type) -> bool; fn parent_flush(&self) -> bool;
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>; fn parent_negotiate(&self) -> Result<(), gst::LoggableError>;
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps; fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps;
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_sink_event(&self, event: gst::Event) -> bool;
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool; fn parent_src_event(&self, event: gst::Event) -> bool;
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool; fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool;
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: VideoEncoderImpl> VideoEncoderImplExt for T { impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -166,14 +156,15 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -190,14 +181,15 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -214,14 +206,15 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
if from_glib(f(element if from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -238,14 +231,15 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> { fn parent_finish(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.finish .finish
.map(|f| { .map(|f| {
try_from_glib(f(element try_from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -256,7 +250,6 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
fn parent_set_format( fn parent_set_format(
&self, &self,
element: &Self::Type,
state: &VideoCodecState<'static, Readable>, state: &VideoCodecState<'static, Readable>,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -267,7 +260,10 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
state.as_mut_ptr() state.as_mut_ptr()
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -280,7 +276,6 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
fn parent_handle_frame( fn parent_handle_frame(
&self, &self,
element: &Self::Type,
frame: VideoCodecFrame, frame: VideoCodecFrame,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
@ -290,7 +285,10 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.handle_frame .handle_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
frame.to_glib_none().0, frame.to_glib_none().0,
)) ))
}) })
@ -298,14 +296,15 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_flush(&self, element: &Self::Type) -> bool { fn parent_flush(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
(*parent_class) (*parent_class)
.flush .flush
.map(|f| { .map(|f| {
from_glib(f(element from_glib(f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -314,7 +313,7 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -322,7 +321,11 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.negotiate .negotiate
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f(element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0), f(self
.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
) )
@ -331,7 +334,7 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
} }
} }
fn parent_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_caps(&self, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -339,19 +342,22 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.getcaps .getcaps
.map(|f| { .map(|f| {
from_glib_full(f( from_glib_full(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
filter.to_glib_none().0, filter.to_glib_none().0,
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
element self.instance()
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.proxy_getcaps(None, filter) .proxy_getcaps(None, filter)
}) })
} }
} }
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -359,13 +365,16 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -373,13 +382,16 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
} }
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, event: gst::Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -387,13 +399,16 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
} }
} }
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoEncoderClass;
@ -401,7 +416,10 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
} }
@ -409,7 +427,6 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
fn parent_propose_allocation( fn parent_propose_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -420,7 +437,10 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -433,7 +453,6 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
fn parent_decide_allocation( fn parent_decide_allocation(
&self, &self,
element: &Self::Type,
query: &mut gst::query::Allocation, query: &mut gst::query::Allocation,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -444,7 +463,10 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoEncoder>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -484,13 +506,12 @@ unsafe extern "C" fn video_encoder_open<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -503,13 +524,12 @@ unsafe extern "C" fn video_encoder_close<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -522,13 +542,12 @@ unsafe extern "C" fn video_encoder_start<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -541,13 +560,12 @@ unsafe extern "C" fn video_encoder_stop<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(err); imp.post_error_message(err);
false false
} }
} }
@ -560,12 +578,8 @@ unsafe extern "C" fn video_encoder_finish<T: VideoEncoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.finish().into() }).into_glib()
imp.finish(wrap.unsafe_cast_ref()).into()
})
.into_glib()
} }
unsafe extern "C" fn video_encoder_set_format<T: VideoEncoderImpl>( unsafe extern "C" fn video_encoder_set_format<T: VideoEncoderImpl>(
@ -574,15 +588,14 @@ unsafe extern "C" fn video_encoder_set_format<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
ffi::gst_video_codec_state_ref(state); ffi::gst_video_codec_state_ref(state);
let wrap_state = VideoCodecState::<Readable>::new(state); let wrap_state = VideoCodecState::<Readable>::new(state);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_format(wrap.unsafe_cast_ref(), &wrap_state) { match imp.set_format(&wrap_state) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -596,11 +609,12 @@ unsafe extern "C" fn video_encoder_handle_frame<T: VideoEncoderImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr); let instance = imp.instance();
let wrap_frame = VideoCodecFrame::new(frame, &*wrap); let instance = instance.unsafe_cast_ref::<VideoEncoder>();
let wrap_frame = VideoCodecFrame::new(frame, instance);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.handle_frame(wrap.unsafe_cast_ref(), wrap_frame).into() imp.handle_frame(wrap_frame).into()
}) })
.into_glib() .into_glib()
} }
@ -610,12 +624,8 @@ unsafe extern "C" fn video_encoder_flush<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { VideoEncoderImpl::flush(imp) }).into_glib()
VideoEncoderImpl::flush(imp, wrap.unsafe_cast_ref())
})
.into_glib()
} }
unsafe extern "C" fn video_encoder_negotiate<T: VideoEncoderImpl>( unsafe extern "C" fn video_encoder_negotiate<T: VideoEncoderImpl>(
@ -623,13 +633,12 @@ unsafe extern "C" fn video_encoder_negotiate<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -643,12 +652,10 @@ unsafe extern "C" fn video_encoder_getcaps<T: VideoEncoderImpl>(
) -> *mut gst::ffi::GstCaps { ) -> *mut gst::ffi::GstCaps {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::Caps::new_empty(), { gst::panic_to_error!(imp, gst::Caps::new_empty(), {
VideoEncoderImpl::caps( VideoEncoderImpl::caps(
imp, imp,
wrap.unsafe_cast_ref(),
Option::<gst::Caps>::from_glib_borrow(filter) Option::<gst::Caps>::from_glib_borrow(filter)
.as_ref() .as_ref()
.as_ref(), .as_ref(),
@ -663,12 +670,8 @@ unsafe extern "C" fn video_encoder_sink_event<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.sink_event(from_glib_full(event)) }).into_glib()
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn video_encoder_sink_query<T: VideoEncoderImpl>( unsafe extern "C" fn video_encoder_sink_query<T: VideoEncoderImpl>(
@ -677,10 +680,9 @@ unsafe extern "C" fn video_encoder_sink_query<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -691,12 +693,8 @@ unsafe extern "C" fn video_encoder_src_event<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, { imp.src_event(from_glib_full(event)) }).into_glib()
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn video_encoder_src_query<T: VideoEncoderImpl>( unsafe extern "C" fn video_encoder_src_query<T: VideoEncoderImpl>(
@ -705,10 +703,9 @@ unsafe extern "C" fn video_encoder_src_query<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(gst::QueryRef::from_mut_ptr(query))
}) })
.into_glib() .into_glib()
} }
@ -719,17 +716,16 @@ unsafe extern "C" fn video_encoder_propose_allocation<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -743,17 +739,16 @@ unsafe extern "C" fn video_encoder_decide_allocation<T: VideoEncoderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoEncoder> = from_glib_borrow(ptr);
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
gst::QueryViewMut::Allocation(allocation) => allocation, gst::QueryViewMut::Allocation(allocation) => allocation,
_ => unreachable!(), _ => unreachable!(),
}; };
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -12,45 +12,40 @@ use crate::VideoInfo;
pub trait VideoFilterImpl: VideoFilterImplExt + BaseTransformImpl { pub trait VideoFilterImpl: VideoFilterImplExt + BaseTransformImpl {
fn set_info( fn set_info(
&self, &self,
element: &Self::Type,
incaps: &gst::Caps, incaps: &gst::Caps,
in_info: &VideoInfo, in_info: &VideoInfo,
outcaps: &gst::Caps, outcaps: &gst::Caps,
out_info: &VideoInfo, out_info: &VideoInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_set_info(element, incaps, in_info, outcaps, out_info) self.parent_set_info(incaps, in_info, outcaps, out_info)
} }
fn transform_frame( fn transform_frame(
&self, &self,
element: &Self::Type,
inframe: &VideoFrameRef<&gst::BufferRef>, inframe: &VideoFrameRef<&gst::BufferRef>,
outframe: &mut VideoFrameRef<&mut gst::BufferRef>, outframe: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_transform_frame(element, inframe, outframe) self.parent_transform_frame(inframe, outframe)
} }
fn transform_frame_ip( fn transform_frame_ip(
&self, &self,
element: &Self::Type,
frame: &mut VideoFrameRef<&mut gst::BufferRef>, frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_transform_frame_ip(element, frame) self.parent_transform_frame_ip(frame)
} }
fn transform_frame_ip_passthrough( fn transform_frame_ip_passthrough(
&self, &self,
element: &Self::Type,
frame: &VideoFrameRef<&gst::BufferRef>, frame: &VideoFrameRef<&gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_transform_frame_ip_passthrough(element, frame) self.parent_transform_frame_ip_passthrough(frame)
} }
} }
pub trait VideoFilterImplExt: ObjectSubclass { pub trait VideoFilterImplExt: ObjectSubclass {
fn parent_set_info( fn parent_set_info(
&self, &self,
element: &Self::Type,
incaps: &gst::Caps, incaps: &gst::Caps,
in_info: &VideoInfo, in_info: &VideoInfo,
outcaps: &gst::Caps, outcaps: &gst::Caps,
@ -59,20 +54,17 @@ pub trait VideoFilterImplExt: ObjectSubclass {
fn parent_transform_frame( fn parent_transform_frame(
&self, &self,
element: &Self::Type,
inframe: &VideoFrameRef<&gst::BufferRef>, inframe: &VideoFrameRef<&gst::BufferRef>,
outframe: &mut VideoFrameRef<&mut gst::BufferRef>, outframe: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_transform_frame_ip( fn parent_transform_frame_ip(
&self, &self,
element: &Self::Type,
frame: &mut VideoFrameRef<&mut gst::BufferRef>, frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
fn parent_transform_frame_ip_passthrough( fn parent_transform_frame_ip_passthrough(
&self, &self,
element: &Self::Type,
frame: &VideoFrameRef<&gst::BufferRef>, frame: &VideoFrameRef<&gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError>; ) -> Result<gst::FlowSuccess, gst::FlowError>;
} }
@ -80,7 +72,6 @@ pub trait VideoFilterImplExt: ObjectSubclass {
impl<T: VideoFilterImpl> VideoFilterImplExt for T { impl<T: VideoFilterImpl> VideoFilterImplExt for T {
fn parent_set_info( fn parent_set_info(
&self, &self,
element: &Self::Type,
incaps: &gst::Caps, incaps: &gst::Caps,
in_info: &VideoInfo, in_info: &VideoInfo,
outcaps: &gst::Caps, outcaps: &gst::Caps,
@ -94,7 +85,10 @@ impl<T: VideoFilterImpl> VideoFilterImplExt for T {
.map(|f| { .map(|f| {
gst::result_from_gboolean!( gst::result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<VideoFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoFilter>()
.to_glib_none()
.0,
incaps.to_glib_none().0, incaps.to_glib_none().0,
mut_override(in_info.to_glib_none().0), mut_override(in_info.to_glib_none().0),
outcaps.to_glib_none().0, outcaps.to_glib_none().0,
@ -110,7 +104,6 @@ impl<T: VideoFilterImpl> VideoFilterImplExt for T {
fn parent_transform_frame( fn parent_transform_frame(
&self, &self,
element: &Self::Type,
inframe: &VideoFrameRef<&gst::BufferRef>, inframe: &VideoFrameRef<&gst::BufferRef>,
outframe: &mut VideoFrameRef<&mut gst::BufferRef>, outframe: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
@ -121,21 +114,24 @@ impl<T: VideoFilterImpl> VideoFilterImplExt for T {
.transform_frame .transform_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoFilter>()
.to_glib_none()
.0,
mut_override(inframe.as_ptr()), mut_override(inframe.as_ptr()),
outframe.as_mut_ptr(), outframe.as_mut_ptr(),
)) ))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
if !element if !self
.instance()
.unsafe_cast_ref::<gst_base::BaseTransform>() .unsafe_cast_ref::<gst_base::BaseTransform>()
.is_in_place() .is_in_place()
{ {
Err(gst::FlowError::NotSupported) Err(gst::FlowError::NotSupported)
} else { } else {
unreachable!(concat!( unreachable!(concat!(
"parent `transform_frame` called ", "parent `transform_frame` called while transform operates in-place"
"while transform element operates in-place"
)); ));
} }
}) })
@ -144,31 +140,33 @@ impl<T: VideoFilterImpl> VideoFilterImplExt for T {
fn parent_transform_frame_ip( fn parent_transform_frame_ip(
&self, &self,
element: &Self::Type,
frame: &mut VideoFrameRef<&mut gst::BufferRef>, frame: &mut VideoFrameRef<&mut gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoFilterClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoFilterClass;
let f = (*parent_class).transform_frame_ip.unwrap_or_else(|| { let f = (*parent_class).transform_frame_ip.unwrap_or_else(|| {
if element if self
.instance()
.unsafe_cast_ref::<gst_base::BaseTransform>() .unsafe_cast_ref::<gst_base::BaseTransform>()
.is_in_place() .is_in_place()
{ {
panic!(concat!( panic!(concat!(
"Missing parent function `transform_frame_ip`. Required because ", "Missing parent function `transform_frame_ip`. Required because ",
"transform element operates in-place" "transform operates in-place"
)); ));
} else { } else {
unreachable!(concat!( unreachable!(concat!(
"parent `transform_frame` called ", "parent `transform_frame` called while transform doesn't operate in-place"
"while transform element doesn't operate in-place"
)); ));
} }
}); });
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoFilter>()
.to_glib_none()
.0,
frame.as_mut_ptr(), frame.as_mut_ptr(),
)) ))
} }
@ -176,31 +174,34 @@ impl<T: VideoFilterImpl> VideoFilterImplExt for T {
fn parent_transform_frame_ip_passthrough( fn parent_transform_frame_ip_passthrough(
&self, &self,
element: &Self::Type,
frame: &VideoFrameRef<&gst::BufferRef>, frame: &VideoFrameRef<&gst::BufferRef>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoFilterClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoFilterClass;
let f = (*parent_class).transform_frame_ip.unwrap_or_else(|| { let f = (*parent_class).transform_frame_ip.unwrap_or_else(|| {
if element if self
.instance()
.unsafe_cast_ref::<gst_base::BaseTransform>() .unsafe_cast_ref::<gst_base::BaseTransform>()
.is_in_place() .is_in_place()
{ {
panic!(concat!( panic!(concat!(
"Missing parent function `transform_frame_ip`. Required because ", "Missing parent function `transform_frame_ip`. Required because ",
"transform element operates in-place (passthrough mode)" "transform operates in-place (passthrough mode)"
)); ));
} else { } else {
unreachable!(concat!( unreachable!(concat!(
"parent `transform_frame_ip` called ", "parent `transform_frame_ip` called ",
"while transform element doesn't operate in-place (passthrough mode)" "while transform doesn't operate in-place (passthrough mode)"
)); ));
} }
}); });
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoFilter>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoFilter>()
.to_glib_none()
.0,
mut_override(frame.as_ptr()), mut_override(frame.as_ptr()),
)) ))
} }
@ -242,11 +243,9 @@ unsafe extern "C" fn video_filter_set_info<T: VideoFilterImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), false, { gst::panic_to_error!(imp, false, {
match imp.set_info( match imp.set_info(
wrap.unsafe_cast_ref(),
&from_glib_borrow(incaps), &from_glib_borrow(incaps),
&from_glib_none(in_info), &from_glib_none(in_info),
&from_glib_borrow(outcaps), &from_glib_borrow(outcaps),
@ -254,7 +253,7 @@ unsafe extern "C" fn video_filter_set_info<T: VideoFilterImpl>(
) { ) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -269,11 +268,9 @@ unsafe extern "C" fn video_filter_transform_frame<T: VideoFilterImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.transform_frame( imp.transform_frame(
wrap.unsafe_cast_ref(),
&VideoFrameRef::from_glib_borrow(inframe), &VideoFrameRef::from_glib_borrow(inframe),
&mut VideoFrameRef::from_glib_borrow_mut(outframe), &mut VideoFrameRef::from_glib_borrow_mut(outframe),
) )
@ -288,23 +285,16 @@ unsafe extern "C" fn video_filter_transform_frame_ip<T: VideoFilterImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoFilter> = from_glib_borrow(ptr);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
if from_glib(gst_base::ffi::gst_base_transform_is_passthrough( if from_glib(gst_base::ffi::gst_base_transform_is_passthrough(
ptr as *mut gst_base::ffi::GstBaseTransform, ptr as *mut gst_base::ffi::GstBaseTransform,
)) { )) {
imp.transform_frame_ip_passthrough( imp.transform_frame_ip_passthrough(&VideoFrameRef::from_glib_borrow(frame))
wrap.unsafe_cast_ref(), .into()
&VideoFrameRef::from_glib_borrow(frame),
)
.into()
} else { } else {
imp.transform_frame_ip( imp.transform_frame_ip(&mut VideoFrameRef::from_glib_borrow_mut(frame))
wrap.unsafe_cast_ref(), .into()
&mut VideoFrameRef::from_glib_borrow_mut(frame),
)
.into()
} }
}) })
.into_glib() .into_glib()

View file

@ -8,29 +8,17 @@ use gst_base::subclass::prelude::*;
use crate::VideoSink; use crate::VideoSink;
pub trait VideoSinkImpl: VideoSinkImplExt + BaseSinkImpl + ElementImpl { pub trait VideoSinkImpl: VideoSinkImplExt + BaseSinkImpl + ElementImpl {
fn show_frame( fn show_frame(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self, self.parent_show_frame(buffer)
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_show_frame(element, buffer)
} }
} }
pub trait VideoSinkImplExt: ObjectSubclass { pub trait VideoSinkImplExt: ObjectSubclass {
fn parent_show_frame( fn parent_show_frame(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
} }
impl<T: VideoSinkImpl> VideoSinkImplExt for T { impl<T: VideoSinkImpl> VideoSinkImplExt for T {
fn parent_show_frame( fn parent_show_frame(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
&self,
element: &Self::Type,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoSinkClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstVideoSinkClass;
@ -38,7 +26,10 @@ impl<T: VideoSinkImpl> VideoSinkImplExt for T {
.show_frame .show_frame
.map(|f| { .map(|f| {
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<VideoSink>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<VideoSink>()
.to_glib_none()
.0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
@ -61,11 +52,10 @@ unsafe extern "C" fn video_sink_show_frame<T: VideoSinkImpl>(
) -> gst::ffi::GstFlowReturn { ) -> gst::ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<VideoSink> = from_glib_borrow(ptr);
let buffer = from_glib_borrow(buffer); let buffer = from_glib_borrow(buffer);
gst::panic_to_error!(&wrap, imp.panicked(), gst::FlowReturn::Error, { gst::panic_to_error!(imp, gst::FlowReturn::Error, {
imp.show_frame(wrap.unsafe_cast_ref(), &buffer).into() imp.show_frame(&buffer).into()
}) })
.into_glib() .into_glib()
} }

View file

@ -491,7 +491,7 @@ macro_rules! log_with_level(
// Check the log level before using `format_args!` otherwise // Check the log level before using `format_args!` otherwise
// formatted arguments are evaluated even if we end up not logging. // formatted arguments are evaluated even if we end up not logging.
if $level <= $cat.threshold() { if $level <= $cat.threshold() {
$crate::DebugCategory::log_unfiltered($cat.clone(), Some($obj), $crate::DebugCategory::log_unfiltered($cat.clone(), Some(&*$obj),
$level, file!(), module_path!(), line!(), format_args!($($args)*)) $level, file!(), module_path!(), line!(), format_args!($($args)*))
} }
}}; }};

View file

@ -12,39 +12,35 @@ use crate::LoggableError;
use crate::Message; use crate::Message;
pub trait BinImpl: BinImplExt + ElementImpl { pub trait BinImpl: BinImplExt + ElementImpl {
fn add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> { fn add_element(&self, element: &Element) -> Result<(), LoggableError> {
self.parent_add_element(bin, element) self.parent_add_element(element)
} }
fn remove_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> { fn remove_element(&self, element: &Element) -> Result<(), LoggableError> {
self.parent_remove_element(bin, element) self.parent_remove_element(element)
} }
fn do_latency(&self, bin: &Self::Type) -> Result<(), LoggableError> { fn do_latency(&self) -> Result<(), LoggableError> {
self.parent_do_latency(bin) self.parent_do_latency()
} }
fn handle_message(&self, bin: &Self::Type, message: Message) { fn handle_message(&self, message: Message) {
self.parent_handle_message(bin, message) self.parent_handle_message(message)
} }
} }
pub trait BinImplExt: ObjectSubclass { pub trait BinImplExt: ObjectSubclass {
fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError>; fn parent_add_element(&self, element: &Element) -> Result<(), LoggableError>;
fn parent_remove_element( fn parent_remove_element(&self, element: &Element) -> Result<(), LoggableError>;
&self,
bin: &Self::Type,
element: &Element,
) -> Result<(), LoggableError>;
fn parent_do_latency(&self, bin: &Self::Type) -> Result<(), LoggableError>; fn parent_do_latency(&self) -> Result<(), LoggableError>;
fn parent_handle_message(&self, bin: &Self::Type, message: Message); fn parent_handle_message(&self, message: Message);
} }
impl<T: BinImpl> BinImplExt for T { impl<T: BinImpl> BinImplExt for T {
fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> { fn parent_add_element(&self, element: &Element) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass;
@ -56,7 +52,10 @@ impl<T: BinImpl> BinImplExt for T {
})?; })?;
result_from_gboolean!( result_from_gboolean!(
f( f(
bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<crate::Bin>()
.to_glib_none()
.0,
element.to_glib_none().0 element.to_glib_none().0
), ),
crate::CAT_RUST, crate::CAT_RUST,
@ -65,11 +64,7 @@ impl<T: BinImpl> BinImplExt for T {
} }
} }
fn parent_remove_element( fn parent_remove_element(&self, element: &Element) -> Result<(), LoggableError> {
&self,
bin: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass;
@ -81,7 +76,10 @@ impl<T: BinImpl> BinImplExt for T {
})?; })?;
result_from_gboolean!( result_from_gboolean!(
f( f(
bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<crate::Bin>()
.to_glib_none()
.0,
element.to_glib_none().0 element.to_glib_none().0
), ),
crate::CAT_RUST, crate::CAT_RUST,
@ -90,7 +88,7 @@ impl<T: BinImpl> BinImplExt for T {
} }
} }
fn parent_do_latency(&self, bin: &Self::Type) -> Result<(), LoggableError> { fn parent_do_latency(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass;
@ -101,20 +99,27 @@ impl<T: BinImpl> BinImplExt for T {
) )
})?; })?;
result_from_gboolean!( result_from_gboolean!(
f(bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0,), f(self
.instance()
.unsafe_cast_ref::<crate::Bin>()
.to_glib_none()
.0,),
crate::CAT_RUST, crate::CAT_RUST,
"Failed to update latency using the parent function" "Failed to update latency using the parent function"
) )
} }
} }
fn parent_handle_message(&self, bin: &Self::Type, message: Message) { fn parent_handle_message(&self, message: Message) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBinClass;
if let Some(ref f) = (*parent_class).handle_message { if let Some(ref f) = (*parent_class).handle_message {
f( f(
bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<crate::Bin>()
.to_glib_none()
.0,
message.into_glib_ptr(), message.into_glib_ptr(),
); );
} }
@ -139,13 +144,12 @@ unsafe extern "C" fn bin_add_element<T: BinImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, {
match imp.add_element(wrap.unsafe_cast_ref(), &from_glib_none(element)) { match imp.add_element(&from_glib_none(element)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -159,7 +163,6 @@ unsafe extern "C" fn bin_remove_element<T: BinImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
// If we get a floating reference passed simply return FALSE here. It can't be // If we get a floating reference passed simply return FALSE here. It can't be
// stored inside this bin, and if we continued to use it we would take ownership // stored inside this bin, and if we continued to use it we would take ownership
@ -170,11 +173,11 @@ unsafe extern "C" fn bin_remove_element<T: BinImpl>(
return glib::ffi::GFALSE; return glib::ffi::GFALSE;
} }
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, {
match imp.remove_element(wrap.unsafe_cast_ref(), &from_glib_none(element)) { match imp.remove_element(&from_glib_none(element)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -185,13 +188,12 @@ unsafe extern "C" fn bin_remove_element<T: BinImpl>(
unsafe extern "C" fn bin_do_latency<T: BinImpl>(ptr: *mut ffi::GstBin) -> glib::ffi::gboolean { unsafe extern "C" fn bin_do_latency<T: BinImpl>(ptr: *mut ffi::GstBin) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, {
match imp.do_latency(wrap.unsafe_cast_ref()) { match imp.do_latency() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -205,9 +207,6 @@ unsafe extern "C" fn bin_handle_message<T: BinImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), (), { panic_to_error!(imp, (), { imp.handle_message(from_glib_full(message)) });
imp.handle_message(wrap.unsafe_cast_ref(), from_glib_full(message))
});
} }

View file

@ -13,92 +13,86 @@ use crate::{BufferPool, BufferPoolAcquireParams, BufferPoolConfigRef};
pub trait BufferPoolImpl: BufferPoolImplExt + GstObjectImpl + Send + Sync { pub trait BufferPoolImpl: BufferPoolImplExt + GstObjectImpl + Send + Sync {
fn acquire_buffer( fn acquire_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError> { ) -> Result<crate::Buffer, crate::FlowError> {
self.parent_acquire_buffer(buffer_pool, params) self.parent_acquire_buffer(params)
} }
fn alloc_buffer( fn alloc_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError> { ) -> Result<crate::Buffer, crate::FlowError> {
self.parent_alloc_buffer(buffer_pool, params) self.parent_alloc_buffer(params)
} }
fn flush_start(&self, buffer_pool: &Self::Type) { fn flush_start(&self) {
self.parent_flush_start(buffer_pool) self.parent_flush_start()
} }
fn flush_stop(&self, buffer_pool: &Self::Type) { fn flush_stop(&self) {
self.parent_flush_stop(buffer_pool) self.parent_flush_stop()
} }
fn free_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer) { fn free_buffer(&self, buffer: crate::Buffer) {
self.parent_free_buffer(buffer_pool, buffer) self.parent_free_buffer(buffer)
} }
fn release_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer) { fn release_buffer(&self, buffer: crate::Buffer) {
self.parent_release_buffer(buffer_pool, buffer) self.parent_release_buffer(buffer)
} }
fn reset_buffer(&self, buffer_pool: &Self::Type, buffer: &mut crate::BufferRef) { fn reset_buffer(&self, buffer: &mut crate::BufferRef) {
self.parent_reset_buffer(buffer_pool, buffer) self.parent_reset_buffer(buffer)
} }
fn start(&self, buffer_pool: &Self::Type) -> bool { fn start(&self) -> bool {
self.parent_start(buffer_pool) self.parent_start()
} }
fn stop(&self, buffer_pool: &Self::Type) -> bool { fn stop(&self) -> bool {
self.parent_stop(buffer_pool) self.parent_stop()
} }
fn options() -> &'static [&'static str] { fn options() -> &'static [&'static str] {
&[] &[]
} }
fn set_config(&self, buffer_pool: &Self::Type, config: &mut BufferPoolConfigRef) -> bool { fn set_config(&self, config: &mut BufferPoolConfigRef) -> bool {
self.parent_set_config(buffer_pool, config) self.parent_set_config(config)
} }
} }
pub trait BufferPoolImplExt: ObjectSubclass { pub trait BufferPoolImplExt: ObjectSubclass {
fn parent_acquire_buffer( fn parent_acquire_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError>; ) -> Result<crate::Buffer, crate::FlowError>;
fn parent_alloc_buffer( fn parent_alloc_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError>; ) -> Result<crate::Buffer, crate::FlowError>;
fn parent_free_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer); fn parent_free_buffer(&self, buffer: crate::Buffer);
fn parent_release_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer); fn parent_release_buffer(&self, buffer: crate::Buffer);
fn parent_reset_buffer(&self, buffer_pool: &Self::Type, buffer: &mut crate::BufferRef); fn parent_reset_buffer(&self, buffer: &mut crate::BufferRef);
fn parent_start(&self, buffer_pool: &Self::Type) -> bool; fn parent_start(&self) -> bool;
fn parent_stop(&self, buffer_pool: &Self::Type) -> bool; fn parent_stop(&self) -> bool;
fn parent_set_config(&self, buffer_pool: &Self::Type, config: &mut BufferPoolConfigRef) fn parent_set_config(&self, config: &mut BufferPoolConfigRef) -> bool;
-> bool;
fn parent_flush_start(&self, _buffer_pool: &Self::Type); fn parent_flush_start(&self);
fn parent_flush_stop(&self, _buffer_pool: &Self::Type); fn parent_flush_stop(&self);
} }
impl<T: BufferPoolImpl> BufferPoolImplExt for T { impl<T: BufferPoolImpl> BufferPoolImplExt for T {
fn parent_acquire_buffer( fn parent_acquire_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError> { ) -> Result<crate::Buffer, crate::FlowError> {
unsafe { unsafe {
@ -109,7 +103,7 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
let mut buffer = std::ptr::null_mut(); let mut buffer = std::ptr::null_mut();
let result = f( let result = f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -126,7 +120,6 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
fn parent_alloc_buffer( fn parent_alloc_buffer(
&self, &self,
buffer_pool: &Self::Type,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<crate::Buffer, crate::FlowError> { ) -> Result<crate::Buffer, crate::FlowError> {
unsafe { unsafe {
@ -137,7 +130,7 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
let mut buffer = std::ptr::null_mut(); let mut buffer = std::ptr::null_mut();
let result = f( let result = f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -152,13 +145,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_free_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer) { fn parent_free_buffer(&self, buffer: crate::Buffer) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).free_buffer { if let Some(f) = (*parent_class).free_buffer {
f( f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -168,13 +161,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_release_buffer(&self, buffer_pool: &Self::Type, buffer: crate::Buffer) { fn parent_release_buffer(&self, buffer: crate::Buffer) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).release_buffer { if let Some(f) = (*parent_class).release_buffer {
f( f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -184,13 +177,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_reset_buffer(&self, buffer_pool: &Self::Type, buffer: &mut crate::BufferRef) { fn parent_reset_buffer(&self, buffer: &mut crate::BufferRef) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).reset_buffer { if let Some(f) = (*parent_class).reset_buffer {
f( f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -200,12 +193,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_start(&self, buffer_pool: &Self::Type) -> bool { fn parent_start(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).start { if let Some(f) = (*parent_class).start {
let result = f(buffer_pool let result = f(self
.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0); .0);
@ -217,12 +211,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_stop(&self, buffer_pool: &Self::Type) -> bool { fn parent_stop(&self) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).stop { if let Some(f) = (*parent_class).stop {
let result = f(buffer_pool let result = f(self
.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0); .0);
@ -234,17 +229,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_set_config( fn parent_set_config(&self, config: &mut BufferPoolConfigRef) -> bool {
&self,
buffer_pool: &Self::Type,
config: &mut BufferPoolConfigRef,
) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).set_config { if let Some(f) = (*parent_class).set_config {
let result = f( let result = f(
buffer_pool self.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0, .0,
@ -258,12 +249,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_flush_start(&self, buffer_pool: &Self::Type) { fn parent_flush_start(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).flush_start { if let Some(f) = (*parent_class).flush_start {
f(buffer_pool f(self
.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0) .0)
@ -271,12 +263,13 @@ impl<T: BufferPoolImpl> BufferPoolImplExt for T {
} }
} }
fn parent_flush_stop(&self, buffer_pool: &Self::Type) { fn parent_flush_stop(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBufferPoolClass;
if let Some(f) = (*parent_class).flush_stop { if let Some(f) = (*parent_class).flush_stop {
f(buffer_pool f(self
.instance()
.unsafe_cast_ref::<crate::BufferPool>() .unsafe_cast_ref::<crate::BufferPool>()
.to_glib_none() .to_glib_none()
.0) .0)
@ -331,10 +324,9 @@ unsafe extern "C" fn buffer_pool_acquire_buffer<T: BufferPoolImpl>(
) -> ffi::GstFlowReturn { ) -> ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr);
let params: Option<BufferPoolAcquireParams> = from_glib_none(params); let params: Option<BufferPoolAcquireParams> = from_glib_none(params);
match imp.acquire_buffer(wrap.unsafe_cast_ref(), params.as_ref()) { match imp.acquire_buffer(params.as_ref()) {
Ok(b) => { Ok(b) => {
*buffer = b.into_glib_ptr(); *buffer = b.into_glib_ptr();
ffi::GST_FLOW_OK ffi::GST_FLOW_OK
@ -350,10 +342,9 @@ unsafe extern "C" fn buffer_pool_alloc_buffer<T: BufferPoolImpl>(
) -> ffi::GstFlowReturn { ) -> ffi::GstFlowReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr);
let params: Option<BufferPoolAcquireParams> = from_glib_none(params); let params: Option<BufferPoolAcquireParams> = from_glib_none(params);
match imp.alloc_buffer(wrap.unsafe_cast_ref(), params.as_ref()) { match imp.alloc_buffer(params.as_ref()) {
Ok(b) => { Ok(b) => {
*buffer = b.into_glib_ptr(); *buffer = b.into_glib_ptr();
ffi::GST_FLOW_OK ffi::GST_FLOW_OK
@ -374,8 +365,7 @@ unsafe extern "C" fn buffer_pool_flush_start<T: BufferPoolImpl>(ptr: *mut ffi::G
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.flush_start();
imp.flush_start(wrap.unsafe_cast_ref());
} }
unsafe extern "C" fn buffer_pool_flush_stop<T: BufferPoolImpl>(ptr: *mut ffi::GstBufferPool) { unsafe extern "C" fn buffer_pool_flush_stop<T: BufferPoolImpl>(ptr: *mut ffi::GstBufferPool) {
@ -390,8 +380,7 @@ unsafe extern "C" fn buffer_pool_flush_stop<T: BufferPoolImpl>(ptr: *mut ffi::Gs
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.flush_stop();
imp.flush_stop(wrap.unsafe_cast_ref());
} }
unsafe extern "C" fn buffer_pool_free_buffer<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_free_buffer<T: BufferPoolImpl>(
@ -417,8 +406,7 @@ unsafe extern "C" fn buffer_pool_free_buffer<T: BufferPoolImpl>(
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.free_buffer(from_glib_full(buffer));
imp.free_buffer(wrap.unsafe_cast_ref(), from_glib_full(buffer));
} }
unsafe extern "C" fn buffer_pool_release_buffer<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_release_buffer<T: BufferPoolImpl>(
@ -427,8 +415,7 @@ unsafe extern "C" fn buffer_pool_release_buffer<T: BufferPoolImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.release_buffer(from_glib_full(buffer));
imp.release_buffer(wrap.unsafe_cast_ref(), from_glib_full(buffer));
} }
unsafe extern "C" fn buffer_pool_reset_buffer<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_reset_buffer<T: BufferPoolImpl>(
@ -437,11 +424,7 @@ unsafe extern "C" fn buffer_pool_reset_buffer<T: BufferPoolImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.reset_buffer(crate::BufferRef::from_mut_ptr(buffer));
imp.reset_buffer(
wrap.unsafe_cast_ref(),
crate::BufferRef::from_mut_ptr(buffer),
);
} }
unsafe extern "C" fn buffer_pool_start<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_start<T: BufferPoolImpl>(
@ -449,8 +432,7 @@ unsafe extern "C" fn buffer_pool_start<T: BufferPoolImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.start().into_glib()
imp.start(wrap.unsafe_cast_ref()).into_glib()
} }
unsafe extern "C" fn buffer_pool_stop<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_stop<T: BufferPoolImpl>(
@ -478,8 +460,7 @@ unsafe extern "C" fn buffer_pool_stop<T: BufferPoolImpl>(
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.stop().into_glib()
imp.stop(wrap.unsafe_cast_ref()).into_glib()
} }
unsafe extern "C" fn buffer_pool_get_options<T: BufferPoolImpl>( unsafe extern "C" fn buffer_pool_get_options<T: BufferPoolImpl>(
@ -498,12 +479,8 @@ unsafe extern "C" fn buffer_pool_set_config<T: BufferPoolImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<BufferPool> = from_glib_borrow(ptr); imp.set_config(BufferPoolConfigRef::from_glib_borrow_mut(config))
imp.set_config( .into_glib()
wrap.unsafe_cast_ref(),
BufferPoolConfigRef::from_glib_borrow_mut(config),
)
.into_glib()
} }
#[cfg(test)] #[cfg(test)]
@ -529,14 +506,10 @@ mod tests {
&["TEST_OPTION"] &["TEST_OPTION"]
} }
fn set_config( fn set_config(&self, config: &mut BufferPoolConfigRef) -> bool {
&self,
buffer_pool: &Self::Type,
config: &mut BufferPoolConfigRef,
) -> bool {
let (caps, size, min_buffers, max_buffers) = config.params().unwrap(); let (caps, size, min_buffers, max_buffers) = config.params().unwrap();
config.set_params(caps.as_ref(), size * 2, min_buffers, max_buffers); config.set_params(caps.as_ref(), size * 2, min_buffers, max_buffers);
self.parent_set_config(buffer_pool, config) self.parent_set_config(config)
} }
} }

View file

@ -8,33 +8,33 @@ use glib::translate::*;
use crate::ChildProxy; use crate::ChildProxy;
pub trait ChildProxyImpl: GstObjectImpl + Send + Sync { pub trait ChildProxyImpl: GstObjectImpl + Send + Sync {
fn child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> { fn child_by_name(&self, name: &str) -> Option<glib::Object> {
self.parent_child_by_name(object, name) self.parent_child_by_name(name)
} }
fn child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>; fn child_by_index(&self, index: u32) -> Option<glib::Object>;
fn children_count(&self, object: &Self::Type) -> u32; fn children_count(&self) -> u32;
fn child_added(&self, object: &Self::Type, child: &glib::Object, name: &str) { fn child_added(&self, child: &glib::Object, name: &str) {
self.parent_child_added(object, child, name); self.parent_child_added(child, name);
} }
fn child_removed(&self, object: &Self::Type, child: &glib::Object, name: &str) { fn child_removed(&self, child: &glib::Object, name: &str) {
self.parent_child_removed(object, child, name); self.parent_child_removed(child, name);
} }
} }
pub trait ChildProxyImplExt: ObjectSubclass { pub trait ChildProxyImplExt: ObjectSubclass {
fn parent_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object>; fn parent_child_by_name(&self, name: &str) -> Option<glib::Object>;
fn parent_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>; fn parent_child_by_index(&self, index: u32) -> Option<glib::Object>;
fn parent_children_count(&self, object: &Self::Type) -> u32; fn parent_children_count(&self) -> u32;
fn parent_child_added(&self, _object: &Self::Type, _child: &glib::Object, _name: &str); fn parent_child_added(&self, _child: &glib::Object, _name: &str);
fn parent_child_removed(&self, _object: &Self::Type, _child: &glib::Object, _name: &str); fn parent_child_removed(&self, _child: &glib::Object, _name: &str);
} }
impl<T: ChildProxyImpl> ChildProxyImplExt for T { impl<T: ChildProxyImpl> ChildProxyImplExt for T {
fn parent_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> { fn parent_child_by_name(&self, name: &str) -> Option<glib::Object> {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>() let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
@ -44,14 +44,17 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
.get_child_by_name .get_child_by_name
.expect("no parent \"child_by_name\" implementation"); .expect("no parent \"child_by_name\" implementation");
let ret = func( let ret = func(
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<ChildProxy>()
.to_glib_none()
.0,
name.to_glib_none().0, name.to_glib_none().0,
); );
from_glib_full(ret) from_glib_full(ret)
} }
} }
fn parent_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object> { fn parent_child_by_index(&self, index: u32) -> Option<glib::Object> {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>() let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
@ -61,14 +64,17 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
.get_child_by_index .get_child_by_index
.expect("no parent \"child_by_index\" implementation"); .expect("no parent \"child_by_index\" implementation");
let ret = func( let ret = func(
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<ChildProxy>()
.to_glib_none()
.0,
index, index,
); );
from_glib_full(ret) from_glib_full(ret)
} }
} }
fn parent_children_count(&self, object: &Self::Type) -> u32 { fn parent_children_count(&self) -> u32 {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>() let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
@ -77,11 +83,16 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
let func = (*parent_iface) let func = (*parent_iface)
.get_children_count .get_children_count
.expect("no parent \"children_count\" implementation"); .expect("no parent \"children_count\" implementation");
func(object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0) func(
self.instance()
.unsafe_cast_ref::<ChildProxy>()
.to_glib_none()
.0,
)
} }
} }
fn parent_child_added(&self, object: &Self::Type, child: &glib::Object, name: &str) { fn parent_child_added(&self, child: &glib::Object, name: &str) {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>() let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
@ -89,7 +100,10 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
if let Some(func) = (*parent_iface).child_added { if let Some(func) = (*parent_iface).child_added {
func( func(
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<ChildProxy>()
.to_glib_none()
.0,
child.to_glib_none().0, child.to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
); );
@ -97,7 +111,7 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
} }
} }
fn parent_child_removed(&self, object: &Self::Type, child: &glib::Object, name: &str) { fn parent_child_removed(&self, child: &glib::Object, name: &str) {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>() let parent_iface = type_data.as_ref().parent_interface::<ChildProxy>()
@ -105,7 +119,10 @@ impl<T: ChildProxyImpl> ChildProxyImplExt for T {
if let Some(func) = (*parent_iface).child_removed { if let Some(func) = (*parent_iface).child_removed {
func( func(
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<ChildProxy>()
.to_glib_none()
.0,
child.to_glib_none().0, child.to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
); );
@ -133,11 +150,8 @@ unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.child_by_name( imp.child_by_name(&glib::GString::from_glib_borrow(name))
from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(), .to_glib_full()
&glib::GString::from_glib_borrow(name),
)
.to_glib_full()
} }
unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
@ -147,11 +161,7 @@ unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.child_by_index( imp.child_by_index(index).to_glib_full()
from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
index,
)
.to_glib_full()
} }
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
@ -160,7 +170,7 @@ unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.children_count(from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref()) imp.children_count()
} }
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
@ -172,7 +182,6 @@ unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
let imp = instance.imp(); let imp = instance.imp();
imp.child_added( imp.child_added(
from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
&from_glib_borrow(child), &from_glib_borrow(child),
&glib::GString::from_glib_borrow(name), &glib::GString::from_glib_borrow(name),
) )
@ -187,7 +196,6 @@ unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
let imp = instance.imp(); let imp = instance.imp();
imp.child_removed( imp.child_removed(
from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
&from_glib_borrow(child), &from_glib_borrow(child),
&glib::GString::from_glib_borrow(name), &glib::GString::from_glib_borrow(name),
) )

View file

@ -14,65 +14,47 @@ use crate::ClockTime;
use crate::ClockTimeDiff; use crate::ClockTimeDiff;
pub trait ClockImpl: ClockImplExt + GstObjectImpl + Send + Sync { pub trait ClockImpl: ClockImplExt + GstObjectImpl + Send + Sync {
fn change_resolution( fn change_resolution(&self, old_resolution: ClockTime, new_resolution: ClockTime) -> ClockTime {
&self, self.parent_change_resolution(old_resolution, new_resolution)
clock: &Self::Type,
old_resolution: ClockTime,
new_resolution: ClockTime,
) -> ClockTime {
self.parent_change_resolution(clock, old_resolution, new_resolution)
} }
fn resolution(&self, clock: &Self::Type) -> ClockTime { fn resolution(&self) -> ClockTime {
self.parent_resolution(clock) self.parent_resolution()
} }
fn internal_time(&self, clock: &Self::Type) -> ClockTime { fn internal_time(&self) -> ClockTime {
self.parent_internal_time(clock) self.parent_internal_time()
} }
fn wait( fn wait(&self, id: &ClockId) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
&self, self.parent_wait(id)
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
self.parent_wait(clock, id)
} }
fn wait_async(&self, clock: &Self::Type, id: &ClockId) -> Result<ClockSuccess, ClockError> { fn wait_async(&self, id: &ClockId) -> Result<ClockSuccess, ClockError> {
self.parent_wait_async(clock, id) self.parent_wait_async(id)
} }
fn unschedule(&self, clock: &Self::Type, id: &ClockId) { fn unschedule(&self, id: &ClockId) {
self.parent_unschedule(clock, id) self.parent_unschedule(id)
} }
} }
pub trait ClockImplExt: ObjectSubclass { pub trait ClockImplExt: ObjectSubclass {
fn parent_change_resolution( fn parent_change_resolution(
&self, &self,
clock: &Self::Type,
old_resolution: ClockTime, old_resolution: ClockTime,
new_resolution: ClockTime, new_resolution: ClockTime,
) -> ClockTime; ) -> ClockTime;
fn parent_resolution(&self, clock: &Self::Type) -> ClockTime; fn parent_resolution(&self) -> ClockTime;
fn parent_internal_time(&self, clock: &Self::Type) -> ClockTime; fn parent_internal_time(&self) -> ClockTime;
fn parent_wait( fn parent_wait(&self, id: &ClockId) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff);
&self,
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff);
fn parent_wait_async( fn parent_wait_async(&self, id: &ClockId) -> Result<ClockSuccess, ClockError>;
&self,
clock: &Self::Type,
id: &ClockId,
) -> Result<ClockSuccess, ClockError>;
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId); fn parent_unschedule(&self, id: &ClockId);
fn wake_id(&self, id: &ClockId) fn wake_id(&self, id: &ClockId)
where where
@ -83,7 +65,6 @@ pub trait ClockImplExt: ObjectSubclass {
impl<T: ClockImpl> ClockImplExt for T { impl<T: ClockImpl> ClockImplExt for T {
fn parent_change_resolution( fn parent_change_resolution(
&self, &self,
clock: &Self::Type,
old_resolution: ClockTime, old_resolution: ClockTime,
new_resolution: ClockTime, new_resolution: ClockTime,
) -> ClockTime { ) -> ClockTime {
@ -93,18 +74,18 @@ impl<T: ClockImpl> ClockImplExt for T {
if let Some(func) = (*parent_class).change_resolution { if let Some(func) = (*parent_class).change_resolution {
try_from_glib(func( try_from_glib(func(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0,
old_resolution.into_glib(), old_resolution.into_glib(),
new_resolution.into_glib(), new_resolution.into_glib(),
)) ))
.expect("undefined resolution") .expect("undefined resolution")
} else { } else {
self.resolution(clock) self.resolution()
} }
} }
} }
fn parent_resolution(&self, clock: &Self::Type) -> ClockTime { fn parent_resolution(&self) -> ClockTime {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
@ -112,14 +93,14 @@ impl<T: ClockImpl> ClockImplExt for T {
try_from_glib( try_from_glib(
(*parent_class) (*parent_class)
.get_resolution .get_resolution
.map(|f| f(clock.unsafe_cast_ref::<Clock>().to_glib_none().0)) .map(|f| f(self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0))
.unwrap_or(1), .unwrap_or(1),
) )
.expect("undefined resolution") .expect("undefined resolution")
} }
} }
fn parent_internal_time(&self, clock: &Self::Type) -> ClockTime { fn parent_internal_time(&self) -> ClockTime {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
@ -127,18 +108,14 @@ impl<T: ClockImpl> ClockImplExt for T {
try_from_glib( try_from_glib(
(*parent_class) (*parent_class)
.get_internal_time .get_internal_time
.map(|f| f(clock.unsafe_cast_ref::<Clock>().to_glib_none().0)) .map(|f| f(self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0))
.unwrap_or(0), .unwrap_or(0),
) )
.expect("undefined internal_time") .expect("undefined internal_time")
} }
} }
fn parent_wait( fn parent_wait(&self, id: &ClockId) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
&self,
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
@ -150,7 +127,7 @@ impl<T: ClockImpl> ClockImplExt for T {
.wait .wait
.map(|f| { .map(|f| {
f( f(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0,
id.as_ptr() as *mut ffi::GstClockEntry, id.as_ptr() as *mut ffi::GstClockEntry,
&mut jitter, &mut jitter,
) )
@ -162,11 +139,7 @@ impl<T: ClockImpl> ClockImplExt for T {
} }
} }
fn parent_wait_async( fn parent_wait_async(&self, id: &ClockId) -> Result<ClockSuccess, ClockError> {
&self,
clock: &Self::Type,
id: &ClockId,
) -> Result<ClockSuccess, ClockError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
@ -175,7 +148,7 @@ impl<T: ClockImpl> ClockImplExt for T {
.wait_async .wait_async
.map(|f| { .map(|f| {
f( f(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0,
id.as_ptr() as *mut ffi::GstClockEntry, id.as_ptr() as *mut ffi::GstClockEntry,
) )
}) })
@ -184,13 +157,13 @@ impl<T: ClockImpl> ClockImplExt for T {
} }
} }
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId) { fn parent_unschedule(&self, id: &ClockId) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
if let Some(func) = (*parent_class).unschedule { if let Some(func) = (*parent_class).unschedule {
func( func(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, self.instance().unsafe_cast_ref::<Clock>().to_glib_none().0,
id.as_ptr() as *mut ffi::GstClockEntry, id.as_ptr() as *mut ffi::GstClockEntry,
); );
} }
@ -203,14 +176,15 @@ impl<T: ClockImpl> ClockImplExt for T {
<Self as ObjectSubclass>::Type: IsA<Clock>, <Self as ObjectSubclass>::Type: IsA<Clock>,
{ {
let clock = self.instance(); let clock = self.instance();
let clock = unsafe { clock.unsafe_cast_ref::<Clock>() };
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "v1_16")] { if #[cfg(feature = "v1_16")] {
assert!(id.uses_clock(&clock)); assert!(id.uses_clock(clock));
} else { } else {
unsafe { unsafe {
let ptr = id.as_ptr() as *mut ffi::GstClockEntry; let ptr = id.as_ptr() as *mut ffi::GstClockEntry;
assert_eq!((*ptr).clock, clock.as_ref().to_glib_none().0); assert_eq!((*ptr).clock, clock.to_glib_none().0);
} }
} }
} }
@ -219,7 +193,7 @@ impl<T: ClockImpl> ClockImplExt for T {
let ptr = id.as_ptr() as *mut ffi::GstClockEntry; let ptr = id.as_ptr() as *mut ffi::GstClockEntry;
if let Some(func) = (*ptr).func { if let Some(func) = (*ptr).func {
func( func(
clock.as_ref().to_glib_none().0, clock.to_glib_none().0,
(*ptr).time, (*ptr).time,
ptr as ffi::GstClockID, ptr as ffi::GstClockID,
(*ptr).user_data, (*ptr).user_data,
@ -252,7 +226,6 @@ unsafe extern "C" fn clock_change_resolution<T: ClockImpl>(
) -> ffi::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
let old_resolution = match from_glib(old_resolution) { let old_resolution = match from_glib(old_resolution) {
Some(old_resolution) => old_resolution, Some(old_resolution) => old_resolution,
@ -263,7 +236,7 @@ unsafe extern "C" fn clock_change_resolution<T: ClockImpl>(
None => return ffi::GST_CLOCK_TIME_NONE, None => return ffi::GST_CLOCK_TIME_NONE,
}; };
imp.change_resolution(wrap.unsafe_cast_ref(), old_resolution, new_resolution) imp.change_resolution(old_resolution, new_resolution)
.into_glib() .into_glib()
} }
@ -272,9 +245,8 @@ unsafe extern "C" fn clock_get_resolution<T: ClockImpl>(
) -> ffi::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.resolution(wrap.unsafe_cast_ref()).into_glib() imp.resolution().into_glib()
} }
unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>( unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
@ -282,9 +254,8 @@ unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
) -> ffi::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.internal_time(wrap.unsafe_cast_ref()).into_glib() imp.internal_time().into_glib()
} }
unsafe extern "C" fn clock_wait<T: ClockImpl>( unsafe extern "C" fn clock_wait<T: ClockImpl>(
@ -294,12 +265,8 @@ unsafe extern "C" fn clock_wait<T: ClockImpl>(
) -> ffi::GstClockReturn { ) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
let (res, j) = imp.wait( let (res, j) = imp.wait(&from_glib_borrow(id as ffi::GstClockID));
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as ffi::GstClockID),
);
if !jitter.is_null() { if !jitter.is_null() {
*jitter = j; *jitter = j;
} }
@ -313,13 +280,8 @@ unsafe extern "C" fn clock_wait_async<T: ClockImpl>(
) -> ffi::GstClockReturn { ) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
ClockReturn::from(imp.wait_async( ClockReturn::from(imp.wait_async(&from_glib_borrow(id as ffi::GstClockID))).into_glib()
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as ffi::GstClockID),
))
.into_glib()
} }
unsafe extern "C" fn clock_unschedule<T: ClockImpl>( unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
@ -328,10 +290,6 @@ unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.unschedule( imp.unschedule(&from_glib_borrow(id as ffi::GstClockID));
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as ffi::GstClockID),
);
} }

View file

@ -12,49 +12,29 @@ use crate::LoggableError;
use std::ptr; use std::ptr;
pub trait DeviceImpl: DeviceImplExt + GstObjectImpl + Send + Sync { pub trait DeviceImpl: DeviceImplExt + GstObjectImpl + Send + Sync {
fn create_element( fn create_element(&self, name: Option<&str>) -> Result<Element, LoggableError> {
&self, self.parent_create_element(name)
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError> {
self.parent_create_element(device, name)
} }
fn reconfigure_element( fn reconfigure_element(&self, element: &Element) -> Result<(), LoggableError> {
&self, self.parent_reconfigure_element(element)
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
self.parent_reconfigure_element(device, element)
} }
} }
pub trait DeviceImplExt: ObjectSubclass { pub trait DeviceImplExt: ObjectSubclass {
fn parent_create_element( fn parent_create_element(&self, name: Option<&str>) -> Result<Element, LoggableError>;
&self,
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError>;
fn parent_reconfigure_element( fn parent_reconfigure_element(&self, element: &Element) -> Result<(), LoggableError>;
&self,
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError>;
} }
impl<T: DeviceImpl> DeviceImplExt for T { impl<T: DeviceImpl> DeviceImplExt for T {
fn parent_create_element( fn parent_create_element(&self, name: Option<&str>) -> Result<Element, LoggableError> {
&self,
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceClass;
if let Some(f) = (*parent_class).create_element { if let Some(f) = (*parent_class).create_element {
let ptr = f( let ptr = f(
device.unsafe_cast_ref::<Device>().to_glib_none().0, self.instance().unsafe_cast_ref::<Device>().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
); );
@ -74,11 +54,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
} }
} }
fn parent_reconfigure_element( fn parent_reconfigure_element(&self, element: &Element) -> Result<(), LoggableError> {
&self,
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceClass;
@ -90,7 +66,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
})?; })?;
result_from_gboolean!( result_from_gboolean!(
f( f(
device.unsafe_cast_ref::<Device>().to_glib_none().0, self.instance().unsafe_cast_ref::<Device>().to_glib_none().0,
element.to_glib_none().0 element.to_glib_none().0
), ),
crate::CAT_RUST, crate::CAT_RUST,
@ -115,10 +91,8 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
) -> *mut ffi::GstElement { ) -> *mut ffi::GstElement {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Device> = from_glib_borrow(ptr);
match imp.create_element( match imp.create_element(
wrap.unsafe_cast_ref(),
Option::<glib::GString>::from_glib_borrow(name) Option::<glib::GString>::from_glib_borrow(name)
.as_ref() .as_ref()
.as_ref() .as_ref()
@ -136,7 +110,7 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
element_ptr element_ptr
} }
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
ptr::null_mut() ptr::null_mut()
} }
} }
@ -148,12 +122,11 @@ unsafe extern "C" fn device_reconfigure_element<T: DeviceImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Device> = from_glib_borrow(ptr);
match imp.reconfigure_element(wrap.unsafe_cast_ref(), &from_glib_borrow(element)) { match imp.reconfigure_element(&from_glib_borrow(element)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }

View file

@ -73,34 +73,35 @@ pub trait DeviceProviderImpl: DeviceProviderImplExt + GstObjectImpl + Send + Syn
None None
} }
fn probe(&self, device_provider: &Self::Type) -> Vec<Device> { fn probe(&self) -> Vec<Device> {
self.parent_probe(device_provider) self.parent_probe()
} }
fn start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> { fn start(&self) -> Result<(), LoggableError> {
self.parent_start(device_provider) self.parent_start()
} }
fn stop(&self, device_provider: &Self::Type) { fn stop(&self) {
self.parent_stop(device_provider) self.parent_stop()
} }
} }
pub trait DeviceProviderImplExt: ObjectSubclass { pub trait DeviceProviderImplExt: ObjectSubclass {
fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device>; fn parent_probe(&self) -> Vec<Device>;
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError>; fn parent_start(&self) -> Result<(), LoggableError>;
fn parent_stop(&self, device_provider: &Self::Type); fn parent_stop(&self);
} }
impl<T: DeviceProviderImpl> DeviceProviderImplExt for T { impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device> { fn parent_probe(&self) -> Vec<Device> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass;
if let Some(f) = (*parent_class).probe { if let Some(f) = (*parent_class).probe {
FromGlibPtrContainer::from_glib_full(f(device_provider FromGlibPtrContainer::from_glib_full(f(self
.instance()
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
.to_glib_none() .to_glib_none()
.0)) .0))
@ -110,7 +111,7 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
} }
} }
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> { fn parent_start(&self) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass;
@ -118,7 +119,8 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
loggable_error!(crate::CAT_RUST, "Parent function `start` is not defined") loggable_error!(crate::CAT_RUST, "Parent function `start` is not defined")
})?; })?;
result_from_gboolean!( result_from_gboolean!(
f(device_provider f(self
.instance()
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
.to_glib_none() .to_glib_none()
.0), .0),
@ -128,12 +130,13 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
} }
} }
fn parent_stop(&self, device_provider: &Self::Type) { fn parent_stop(&self) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstDeviceProviderClass;
if let Some(f) = (*parent_class).stop { if let Some(f) = (*parent_class).stop {
f(device_provider f(self
.instance()
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
.to_glib_none() .to_glib_none()
.0); .0);
@ -177,9 +180,8 @@ unsafe extern "C" fn device_provider_probe<T: DeviceProviderImpl>(
) -> *mut glib::ffi::GList { ) -> *mut glib::ffi::GList {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
imp.probe(wrap.unsafe_cast_ref()).to_glib_full() imp.probe().to_glib_full()
} }
unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>( unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
@ -187,12 +189,11 @@ unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
match imp.start(wrap.unsafe_cast_ref()) { match imp.start() {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_imp(imp);
false false
} }
} }
@ -202,7 +203,6 @@ unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(ptr: *mut ffi::GstDeviceProvider) { unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(ptr: *mut ffi::GstDeviceProvider) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
imp.stop(wrap.unsafe_cast_ref()); imp.stop();
} }

View file

@ -85,79 +85,75 @@ pub trait ElementImpl: ElementImplExt + GstObjectImpl + Send + Sync {
fn change_state( fn change_state(
&self, &self,
element: &Self::Type,
transition: StateChange, transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> { ) -> Result<StateChangeSuccess, StateChangeError> {
self.parent_change_state(element, transition) self.parent_change_state(transition)
} }
fn request_new_pad( fn request_new_pad(
&self, &self,
element: &Self::Type,
templ: &crate::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&crate::Caps>, caps: Option<&crate::Caps>,
) -> Option<crate::Pad> { ) -> Option<crate::Pad> {
self.parent_request_new_pad(element, templ, name, caps) self.parent_request_new_pad(templ, name, caps)
} }
fn release_pad(&self, element: &Self::Type, pad: &crate::Pad) { fn release_pad(&self, pad: &crate::Pad) {
self.parent_release_pad(element, pad) self.parent_release_pad(pad)
} }
fn send_event(&self, element: &Self::Type, event: Event) -> bool { fn send_event(&self, event: Event) -> bool {
self.parent_send_event(element, event) self.parent_send_event(event)
} }
fn query(&self, element: &Self::Type, query: &mut QueryRef) -> bool { fn query(&self, query: &mut QueryRef) -> bool {
self.parent_query(element, query) self.parent_query(query)
} }
fn set_context(&self, element: &Self::Type, context: &crate::Context) { fn set_context(&self, context: &crate::Context) {
self.parent_set_context(element, context) self.parent_set_context(context)
} }
fn set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool { fn set_clock(&self, clock: Option<&crate::Clock>) -> bool {
self.parent_set_clock(element, clock) self.parent_set_clock(clock)
} }
fn provide_clock(&self, element: &Self::Type) -> Option<crate::Clock> { fn provide_clock(&self) -> Option<crate::Clock> {
self.parent_provide_clock(element) self.parent_provide_clock()
} }
fn post_message(&self, element: &Self::Type, msg: crate::Message) -> bool { fn post_message(&self, msg: crate::Message) -> bool {
self.parent_post_message(element, msg) self.parent_post_message(msg)
} }
} }
pub trait ElementImplExt: ObjectSubclass { pub trait ElementImplExt: ObjectSubclass {
fn parent_change_state( fn parent_change_state(
&self, &self,
element: &Self::Type,
transition: StateChange, transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError>; ) -> Result<StateChangeSuccess, StateChangeError>;
fn parent_request_new_pad( fn parent_request_new_pad(
&self, &self,
element: &Self::Type,
templ: &crate::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&crate::Caps>, caps: Option<&crate::Caps>,
) -> Option<crate::Pad>; ) -> Option<crate::Pad>;
fn parent_release_pad(&self, element: &Self::Type, pad: &crate::Pad); fn parent_release_pad(&self, pad: &crate::Pad);
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool; fn parent_send_event(&self, event: Event) -> bool;
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool; fn parent_query(&self, query: &mut QueryRef) -> bool;
fn parent_set_context(&self, element: &Self::Type, context: &crate::Context); fn parent_set_context(&self, context: &crate::Context);
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool; fn parent_set_clock(&self, clock: Option<&crate::Clock>) -> bool;
fn parent_provide_clock(&self, element: &Self::Type) -> Option<crate::Clock>; fn parent_provide_clock(&self) -> Option<crate::Clock>;
fn parent_post_message(&self, element: &Self::Type, msg: crate::Message) -> bool; fn parent_post_message(&self, msg: crate::Message) -> bool;
fn panicked(&self) -> &atomic::AtomicBool; fn panicked(&self) -> &atomic::AtomicBool;
@ -168,7 +164,7 @@ pub trait ElementImplExt: ObjectSubclass {
f: F, f: F,
) -> R; ) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>( fn catch_panic_pad_function<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R>(
parent: Option<&crate::Object>, parent: Option<&crate::Object>,
fallback: G, fallback: G,
f: F, f: F,
@ -180,7 +176,6 @@ pub trait ElementImplExt: ObjectSubclass {
impl<T: ElementImpl> ElementImplExt for T { impl<T: ElementImpl> ElementImplExt for T {
fn parent_change_state( fn parent_change_state(
&self, &self,
element: &Self::Type,
transition: StateChange, transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> { ) -> Result<StateChangeSuccess, StateChangeError> {
unsafe { unsafe {
@ -191,7 +186,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.change_state .change_state
.expect("Missing parent function `change_state`"); .expect("Missing parent function `change_state`");
try_from_glib(f( try_from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
transition.into_glib(), transition.into_glib(),
)) ))
} }
@ -199,7 +197,6 @@ impl<T: ElementImpl> ElementImplExt for T {
fn parent_request_new_pad( fn parent_request_new_pad(
&self, &self,
element: &Self::Type,
templ: &crate::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&crate::Caps>, caps: Option<&crate::Caps>,
@ -212,7 +209,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.request_new_pad .request_new_pad
.map(|f| { .map(|f| {
from_glib_none(f( from_glib_none(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
templ.to_glib_none().0, templ.to_glib_none().0,
name.to_glib_full(), name.to_glib_full(),
caps.to_glib_none().0, caps.to_glib_none().0,
@ -222,7 +222,7 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_release_pad(&self, element: &Self::Type, pad: &crate::Pad) { fn parent_release_pad(&self, pad: &crate::Pad) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
@ -231,7 +231,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.release_pad .release_pad
.map(|f| { .map(|f| {
f( f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
pad.to_glib_none().0, pad.to_glib_none().0,
) )
}) })
@ -239,7 +242,7 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool { fn parent_send_event(&self, event: Event) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
@ -248,7 +251,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.send_event .send_event
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
event.into_glib_ptr(), event.into_glib_ptr(),
)) ))
}) })
@ -256,7 +262,7 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool { fn parent_query(&self, query: &mut QueryRef) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
@ -265,7 +271,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.query .query
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
}) })
@ -273,7 +282,7 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_set_context(&self, element: &Self::Type, context: &crate::Context) { fn parent_set_context(&self, context: &crate::Context) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
@ -282,7 +291,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.set_context .set_context
.map(|f| { .map(|f| {
f( f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
context.to_glib_none().0, context.to_glib_none().0,
) )
}) })
@ -290,7 +302,7 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool { fn parent_set_clock(&self, clock: Option<&crate::Clock>) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
@ -299,7 +311,10 @@ impl<T: ElementImpl> ElementImplExt for T {
.set_clock .set_clock
.map(|f| { .map(|f| {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
clock.to_glib_none().0, clock.to_glib_none().0,
)) ))
}) })
@ -307,26 +322,35 @@ impl<T: ElementImpl> ElementImplExt for T {
} }
} }
fn parent_provide_clock(&self, element: &Self::Type) -> Option<crate::Clock> { fn parent_provide_clock(&self) -> Option<crate::Clock> {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.provide_clock .provide_clock
.map(|f| from_glib_none(f(element.unsafe_cast_ref::<Element>().to_glib_none().0))) .map(|f| {
from_glib_none(f(self
.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0))
})
.unwrap_or(None) .unwrap_or(None)
} }
} }
fn parent_post_message(&self, element: &Self::Type, msg: crate::Message) -> bool { fn parent_post_message(&self, msg: crate::Message) -> bool {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstElementClass;
if let Some(f) = (*parent_class).post_message { if let Some(f) = (*parent_class).post_message {
from_glib(f( from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<Element>()
.to_glib_none()
.0,
msg.into_glib_ptr(), msg.into_glib_ptr(),
)) ))
} else { } else {
@ -352,11 +376,11 @@ impl<T: ElementImpl> ElementImplExt for T {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
panic_to_error!(element, imp.panicked(), fallback(), { f(imp) }) panic_to_error!(imp, fallback(), { f(imp) })
} }
} }
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>( fn catch_panic_pad_function<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R>(
parent: Option<&crate::Object>, parent: Option<&crate::Object>,
fallback: G, fallback: G,
f: F, f: F,
@ -368,9 +392,7 @@ impl<T: ElementImpl> ElementImplExt for T {
let instance = &*(ptr as *mut Self::Instance); let instance = &*(ptr as *mut Self::Instance);
let imp = instance.imp(); let imp = instance.imp();
panic_to_error!(wrap, imp.panicked(), fallback(), { panic_to_error!(imp, fallback(), { f(imp) })
f(imp, wrap.unsafe_cast_ref())
})
} }
} }
@ -435,7 +457,6 @@ unsafe extern "C" fn element_change_state<T: ElementImpl>(
) -> ffi::GstStateChangeReturn { ) -> ffi::GstStateChangeReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
// *Never* fail downwards state changes, this causes bugs in GStreamer // *Never* fail downwards state changes, this causes bugs in GStreamer
// and leads to crashes and deadlocks. // and leads to crashes and deadlocks.
@ -447,10 +468,7 @@ unsafe extern "C" fn element_change_state<T: ElementImpl>(
_ => StateChangeReturn::Failure, _ => StateChangeReturn::Failure,
}; };
panic_to_error!(&wrap, imp.panicked(), fallback, { panic_to_error!(imp, fallback, { imp.change_state(transition).into() }).into_glib()
imp.change_state(wrap.unsafe_cast_ref(), transition).into()
})
.into_glib()
} }
unsafe extern "C" fn element_request_new_pad<T: ElementImpl>( unsafe extern "C" fn element_request_new_pad<T: ElementImpl>(
@ -461,15 +479,13 @@ unsafe extern "C" fn element_request_new_pad<T: ElementImpl>(
) -> *mut ffi::GstPad { ) -> *mut ffi::GstPad {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
let caps = Option::<crate::Caps>::from_glib_borrow(caps); let caps = Option::<crate::Caps>::from_glib_borrow(caps);
// XXX: This is effectively unsafe but the best we can do // XXX: This is effectively unsafe but the best we can do
// See https://bugzilla.gnome.org/show_bug.cgi?id=791193 // See https://bugzilla.gnome.org/show_bug.cgi?id=791193
let pad = panic_to_error!(&wrap, imp.panicked(), None, { let pad = panic_to_error!(imp, None, {
imp.request_new_pad( imp.request_new_pad(
wrap.unsafe_cast_ref(),
&from_glib_borrow(templ), &from_glib_borrow(templ),
from_glib_none(name), from_glib_none(name),
caps.as_ref().as_ref(), caps.as_ref().as_ref(),
@ -495,7 +511,6 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
// If we get a floating reference passed simply return here. It can't be stored inside this // If we get a floating reference passed simply return here. It can't be stored inside this
// element, and if we continued to use it we would take ownership of this floating reference. // element, and if we continued to use it we would take ownership of this floating reference.
@ -505,9 +520,7 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
return; return;
} }
panic_to_error!(&wrap, imp.panicked(), (), { panic_to_error!(imp, (), { imp.release_pad(&from_glib_none(pad)) })
imp.release_pad(wrap.unsafe_cast_ref(), &from_glib_none(pad))
})
} }
unsafe extern "C" fn element_send_event<T: ElementImpl>( unsafe extern "C" fn element_send_event<T: ElementImpl>(
@ -516,12 +529,8 @@ unsafe extern "C" fn element_send_event<T: ElementImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, { imp.send_event(from_glib_full(event)) }).into_glib()
imp.send_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.into_glib()
} }
unsafe extern "C" fn element_query<T: ElementImpl>( unsafe extern "C" fn element_query<T: ElementImpl>(
@ -530,13 +539,9 @@ unsafe extern "C" fn element_query<T: ElementImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
let query = QueryRef::from_mut_ptr(query); let query = QueryRef::from_mut_ptr(query);
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, { imp.query(query) }).into_glib()
imp.query(wrap.unsafe_cast_ref(), query)
})
.into_glib()
} }
unsafe extern "C" fn element_set_context<T: ElementImpl>( unsafe extern "C" fn element_set_context<T: ElementImpl>(
@ -545,11 +550,8 @@ unsafe extern "C" fn element_set_context<T: ElementImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), (), { panic_to_error!(imp, (), { imp.set_context(&from_glib_borrow(context)) })
imp.set_context(wrap.unsafe_cast_ref(), &from_glib_borrow(context))
})
} }
unsafe extern "C" fn element_set_clock<T: ElementImpl>( unsafe extern "C" fn element_set_clock<T: ElementImpl>(
@ -558,14 +560,10 @@ unsafe extern "C" fn element_set_clock<T: ElementImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
let clock = Option::<crate::Clock>::from_glib_borrow(clock); let clock = Option::<crate::Clock>::from_glib_borrow(clock);
panic_to_error!(&wrap, imp.panicked(), false, { panic_to_error!(imp, false, { imp.set_clock(clock.as_ref().as_ref()) }).into_glib()
imp.set_clock(wrap.unsafe_cast_ref(), clock.as_ref().as_ref())
})
.into_glib()
} }
unsafe extern "C" fn element_provide_clock<T: ElementImpl>( unsafe extern "C" fn element_provide_clock<T: ElementImpl>(
@ -573,12 +571,8 @@ unsafe extern "C" fn element_provide_clock<T: ElementImpl>(
) -> *mut ffi::GstClock { ) -> *mut ffi::GstClock {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
panic_to_error!(&wrap, imp.panicked(), None, { panic_to_error!(imp, None, { imp.provide_clock() }).to_glib_full()
imp.provide_clock(wrap.unsafe_cast_ref())
})
.to_glib_full()
} }
unsafe extern "C" fn element_post_message<T: ElementImpl>( unsafe extern "C" fn element_post_message<T: ElementImpl>(
@ -587,12 +581,10 @@ unsafe extern "C" fn element_post_message<T: ElementImpl>(
) -> glib::ffi::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
// Can't catch panics here as posting the error message would cause // Can't catch panics here as posting the error message would cause
// this code to be called again recursively forever. // this code to be called again recursively forever.
imp.post_message(wrap.unsafe_cast_ref(), from_glib_full(msg)) imp.post_message(from_glib_full(msg)).into_glib()
.into_glib()
} }
#[cfg(test)] #[cfg(test)]
@ -616,46 +608,25 @@ mod tests {
fn sink_chain( fn sink_chain(
&self, &self,
_pad: &crate::Pad, _pad: &crate::Pad,
_element: &super::TestElement,
buffer: crate::Buffer, buffer: crate::Buffer,
) -> Result<crate::FlowSuccess, crate::FlowError> { ) -> Result<crate::FlowSuccess, crate::FlowError> {
self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst); self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst);
self.srcpad.push(buffer) self.srcpad.push(buffer)
} }
fn sink_event( fn sink_event(&self, _pad: &crate::Pad, event: crate::Event) -> bool {
&self,
_pad: &crate::Pad,
_element: &super::TestElement,
event: crate::Event,
) -> bool {
self.srcpad.push_event(event) self.srcpad.push_event(event)
} }
fn sink_query( fn sink_query(&self, _pad: &crate::Pad, query: &mut crate::QueryRef) -> bool {
&self,
_pad: &crate::Pad,
_element: &super::TestElement,
query: &mut crate::QueryRef,
) -> bool {
self.srcpad.peer_query(query) self.srcpad.peer_query(query)
} }
fn src_event( fn src_event(&self, _pad: &crate::Pad, event: crate::Event) -> bool {
&self,
_pad: &crate::Pad,
_element: &super::TestElement,
event: crate::Event,
) -> bool {
self.sinkpad.push_event(event) self.sinkpad.push_event(event)
} }
fn src_query( fn src_query(&self, _pad: &crate::Pad, query: &mut crate::QueryRef) -> bool {
&self,
_pad: &crate::Pad,
_element: &super::TestElement,
query: &mut crate::QueryRef,
) -> bool {
self.sinkpad.peer_query(query) self.sinkpad.peer_query(query)
} }
} }
@ -673,21 +644,21 @@ mod tests {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| Err(crate::FlowError::Error), || Err(crate::FlowError::Error),
|identity, element| identity.sink_chain(pad, element, buffer), |identity| identity.sink_chain(pad, buffer),
) )
}) })
.event_function(|pad, parent, event| { .event_function(|pad, parent, event| {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| false, || false,
|identity, element| identity.sink_event(pad, element, event), |identity| identity.sink_event(pad, event),
) )
}) })
.query_function(|pad, parent, query| { .query_function(|pad, parent, query| {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| false, || false,
|identity, element| identity.sink_query(pad, element, query), |identity| identity.sink_query(pad, query),
) )
}) })
.build(); .build();
@ -698,14 +669,14 @@ mod tests {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| false, || false,
|identity, element| identity.src_event(pad, element, event), |identity| identity.src_event(pad, event),
) )
}) })
.query_function(|pad, parent, query| { .query_function(|pad, parent, query| {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| false, || false,
|identity, element| identity.src_query(pad, element, query), |identity| identity.src_query(pad, query),
) )
}) })
.build(); .build();
@ -720,9 +691,10 @@ mod tests {
} }
impl ObjectImpl for TestElement { impl ObjectImpl for TestElement {
fn constructed(&self, element: &Self::Type) { fn constructed(&self) {
self.parent_constructed(element); self.parent_constructed();
let element = self.instance();
element.add_pad(&self.sinkpad).unwrap(); element.add_pad(&self.sinkpad).unwrap();
element.add_pad(&self.srcpad).unwrap(); element.add_pad(&self.srcpad).unwrap();
} }
@ -772,10 +744,9 @@ mod tests {
fn change_state( fn change_state(
&self, &self,
element: &Self::Type,
transition: crate::StateChange, transition: crate::StateChange,
) -> Result<crate::StateChangeSuccess, crate::StateChangeError> { ) -> Result<crate::StateChangeSuccess, crate::StateChangeError> {
let res = self.parent_change_state(element, transition)?; let res = self.parent_change_state(transition)?;
if transition == crate::StateChange::PausedToPlaying { if transition == crate::StateChange::PausedToPlaying {
self.reached_playing.store(true, atomic::Ordering::SeqCst); self.reached_playing.store(true, atomic::Ordering::SeqCst);

View file

@ -7,15 +7,14 @@ use crate::FlowReturn;
#[macro_export] #[macro_export]
macro_rules! panic_to_error( macro_rules! panic_to_error(
($element:expr, $panicked:expr, $ret:expr, $code:block) => {{ ($imp:expr, $ret:expr, $code:block) => {{
use std::panic::{self, AssertUnwindSafe}; use std::panic::{self, AssertUnwindSafe};
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use $crate::prelude::ElementExtManual;
#[allow(clippy::unused_unit)] #[allow(clippy::unused_unit)]
{ {
if $panicked.load(Ordering::Relaxed) { if $imp.panicked().load(Ordering::Relaxed) {
$element.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked"])); $imp.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked"]));
$ret $ret
} else { } else {
let result = panic::catch_unwind(AssertUnwindSafe(|| $code)); let result = panic::catch_unwind(AssertUnwindSafe(|| $code));
@ -23,13 +22,13 @@ macro_rules! panic_to_error(
match result { match result {
Ok(result) => result, Ok(result) => result,
Err(err) => { Err(err) => {
$panicked.store(true, Ordering::Relaxed); $imp.panicked().store(true, Ordering::Relaxed);
if let Some(cause) = err.downcast_ref::<&str>() { if let Some(cause) = err.downcast_ref::<&str>() {
$element.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); $imp.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause]));
} else if let Some(cause) = err.downcast_ref::<String>() { } else if let Some(cause) = err.downcast_ref::<String>() {
$element.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); $imp.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause]));
} else { } else {
$element.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked"])); $imp.post_error_message($crate::error_msg!($crate::LibraryError::Failed, ["Panicked"]));
} }
$ret $ret
} }

View file

@ -8,23 +8,23 @@ use glib::translate::*;
use crate::Pad; use crate::Pad;
pub trait PadImpl: PadImplExt + GstObjectImpl + Send + Sync { pub trait PadImpl: PadImplExt + GstObjectImpl + Send + Sync {
fn linked(&self, pad: &Self::Type, peer: &Pad) { fn linked(&self, peer: &Pad) {
self.parent_linked(pad, peer) self.parent_linked(peer)
} }
fn unlinked(&self, pad: &Self::Type, peer: &Pad) { fn unlinked(&self, peer: &Pad) {
self.parent_unlinked(pad, peer) self.parent_unlinked(peer)
} }
} }
pub trait PadImplExt: ObjectSubclass { pub trait PadImplExt: ObjectSubclass {
fn parent_linked(&self, pad: &Self::Type, peer: &Pad); fn parent_linked(&self, peer: &Pad);
fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad); fn parent_unlinked(&self, peer: &Pad);
} }
impl<T: PadImpl> PadImplExt for T { impl<T: PadImpl> PadImplExt for T {
fn parent_linked(&self, pad: &Self::Type, peer: &Pad) { fn parent_linked(&self, peer: &Pad) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstPadClass;
@ -33,7 +33,7 @@ impl<T: PadImpl> PadImplExt for T {
.linked .linked
.map(|f| { .map(|f| {
f( f(
pad.unsafe_cast_ref::<Pad>().to_glib_none().0, self.instance().unsafe_cast_ref::<Pad>().to_glib_none().0,
peer.to_glib_none().0, peer.to_glib_none().0,
) )
}) })
@ -41,7 +41,7 @@ impl<T: PadImpl> PadImplExt for T {
} }
} }
fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad) { fn parent_unlinked(&self, peer: &Pad) {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstPadClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstPadClass;
@ -50,7 +50,7 @@ impl<T: PadImpl> PadImplExt for T {
.unlinked .unlinked
.map(|f| { .map(|f| {
f( f(
pad.unsafe_cast_ref::<Pad>().to_glib_none().0, self.instance().unsafe_cast_ref::<Pad>().to_glib_none().0,
peer.to_glib_none().0, peer.to_glib_none().0,
) )
}) })
@ -71,17 +71,15 @@ unsafe impl<T: PadImpl> IsSubclassable<T> for Pad {
unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) { unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
imp.linked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer)) imp.linked(&from_glib_borrow(peer))
} }
unsafe extern "C" fn pad_unlinked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) { unsafe extern "C" fn pad_unlinked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
imp.unlinked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer)) imp.unlinked(&from_glib_borrow(peer))
} }
#[cfg(test)] #[cfg(test)]
@ -113,14 +111,14 @@ mod tests {
impl GstObjectImpl for TestPad {} impl GstObjectImpl for TestPad {}
impl PadImpl for TestPad { impl PadImpl for TestPad {
fn linked(&self, pad: &Self::Type, peer: &Pad) { fn linked(&self, peer: &Pad) {
self.linked.store(true, atomic::Ordering::SeqCst); self.linked.store(true, atomic::Ordering::SeqCst);
self.parent_linked(pad, peer) self.parent_linked(peer)
} }
fn unlinked(&self, pad: &Self::Type, peer: &Pad) { fn unlinked(&self, peer: &Pad) {
self.unlinked.store(true, atomic::Ordering::SeqCst); self.unlinked.store(true, atomic::Ordering::SeqCst);
self.parent_unlinked(pad, peer) self.parent_unlinked(peer)
} }
} }
} }

View file

@ -8,7 +8,6 @@ use std::ptr;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use glib::ffi::gpointer; use glib::ffi::gpointer;
use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
@ -25,7 +24,7 @@ pub trait TaskPoolImpl: GstObjectImpl + Send + Sync {
/// Prepare the task pool to accept tasks. /// Prepare the task pool to accept tasks.
/// ///
/// This defaults to doing nothing. /// This defaults to doing nothing.
fn prepare(&self, _task_pool: &Self::Type) -> Result<(), glib::Error> { fn prepare(&self) -> Result<(), glib::Error> {
Ok(()) Ok(())
} }
@ -34,7 +33,7 @@ pub trait TaskPoolImpl: GstObjectImpl + Send + Sync {
/// ///
/// This is mainly used internally to ensure proper cleanup of internal data structures in test /// This is mainly used internally to ensure proper cleanup of internal data structures in test
/// suites. /// suites.
fn cleanup(&self, _task_pool: &Self::Type) {} fn cleanup(&self) {}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Deliver a task to the pool. /// Deliver a task to the pool.
@ -42,11 +41,7 @@ pub trait TaskPoolImpl: GstObjectImpl + Send + Sync {
/// If returning `Ok`, you need to call the `func` eventually. /// If returning `Ok`, you need to call the `func` eventually.
/// ///
/// If returning `Err`, the `func` must be dropped without calling it. /// If returning `Err`, the `func` must be dropped without calling it.
fn push( fn push(&self, func: TaskPoolFunction) -> Result<Option<Self::Handle>, glib::Error>;
&self,
task_pool: &Self::Type,
func: TaskPoolFunction,
) -> Result<Option<Self::Handle>, glib::Error>;
} }
unsafe impl<T: TaskPoolImpl> IsSubclassable<T> for TaskPool { unsafe impl<T: TaskPoolImpl> IsSubclassable<T> for TaskPool {
@ -71,9 +66,8 @@ unsafe extern "C" fn task_pool_prepare<T: TaskPoolImpl>(
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
match imp.prepare(wrap.unsafe_cast_ref()) { match imp.prepare() {
Ok(()) => {} Ok(()) => {}
Err(err) => { Err(err) => {
if !error.is_null() { if !error.is_null() {
@ -86,9 +80,8 @@ unsafe extern "C" fn task_pool_prepare<T: TaskPoolImpl>(
unsafe extern "C" fn task_pool_cleanup<T: TaskPoolImpl>(ptr: *mut ffi::GstTaskPool) { unsafe extern "C" fn task_pool_cleanup<T: TaskPoolImpl>(ptr: *mut ffi::GstTaskPool) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
imp.cleanup(wrap.unsafe_cast_ref()); imp.cleanup();
} }
unsafe extern "C" fn task_pool_push<T: TaskPoolImpl>( unsafe extern "C" fn task_pool_push<T: TaskPoolImpl>(
@ -99,11 +92,10 @@ unsafe extern "C" fn task_pool_push<T: TaskPoolImpl>(
) -> gpointer { ) -> gpointer {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
let func = TaskPoolFunction::new(func.expect("Tried to push null func"), user_data); let func = TaskPoolFunction::new(func.expect("Tried to push null func"), user_data);
match imp.push(wrap.unsafe_cast_ref(), func.clone()) { match imp.push(func.clone()) {
Ok(None) => ptr::null_mut(), Ok(None) => ptr::null_mut(),
Ok(Some(handle)) => Box::into_raw(Box::new(handle)) as gpointer, Ok(Some(handle)) => Box::into_raw(Box::new(handle)) as gpointer,
Err(err) => { Err(err) => {
@ -117,9 +109,8 @@ unsafe extern "C" fn task_pool_push<T: TaskPoolImpl>(
} }
unsafe extern "C" fn task_pool_join<T: TaskPoolImpl>(ptr: *mut ffi::GstTaskPool, id: gpointer) { unsafe extern "C" fn task_pool_join<T: TaskPoolImpl>(ptr: *mut ffi::GstTaskPool, id: gpointer) {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
if id.is_null() { if id.is_null() {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to join null handle"); crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to join null handle");
return; return;
} }
@ -134,9 +125,8 @@ unsafe extern "C" fn task_pool_dispose_handle<T: TaskPoolImpl>(
ptr: *mut ffi::GstTaskPool, ptr: *mut ffi::GstTaskPool,
id: gpointer, id: gpointer,
) { ) {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
if id.is_null() { if id.is_null() {
let wrap: Borrowed<TaskPool> = from_glib_borrow(ptr);
crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to dispose null handle"); crate::warning!(crate::CAT_RUST, obj: wrap.as_ref(), "Tried to dispose null handle");
return; return;
} }
@ -270,20 +260,16 @@ mod tests {
impl TaskPoolImpl for TestPool { impl TaskPoolImpl for TestPool {
type Handle = TestHandle; type Handle = TestHandle;
fn prepare(&self, _task_pool: &Self::Type) -> Result<(), glib::Error> { fn prepare(&self) -> Result<(), glib::Error> {
self.prepared.store(true, atomic::Ordering::SeqCst); self.prepared.store(true, atomic::Ordering::SeqCst);
Ok(()) Ok(())
} }
fn cleanup(&self, _task_pool: &Self::Type) { fn cleanup(&self) {
self.cleaned_up.store(true, atomic::Ordering::SeqCst); self.cleaned_up.store(true, atomic::Ordering::SeqCst);
} }
fn push( fn push(&self, func: TaskPoolFunction) -> Result<Option<Self::Handle>, glib::Error> {
&self,
_task_pool: &Self::Type,
func: TaskPoolFunction,
) -> Result<Option<Self::Handle>, glib::Error> {
let handle = thread::spawn(move || func.call()); let handle = thread::spawn(move || func.call());
Ok(Some(TestHandle(handle))) Ok(Some(TestHandle(handle)))
} }

View file

@ -13,14 +13,14 @@ use std::ptr;
pub trait URIHandlerImpl: super::element::ElementImpl { pub trait URIHandlerImpl: super::element::ElementImpl {
const URI_TYPE: URIType; const URI_TYPE: URIType;
fn protocols() -> &'static [&'static str]; fn protocols() -> &'static [&'static str];
fn uri(&self, element: &Self::Type) -> Option<String>; fn uri(&self) -> Option<String>;
fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>; fn set_uri(&self, uri: &str) -> Result<(), glib::Error>;
} }
pub trait URIHandlerImplExt: ObjectSubclass { pub trait URIHandlerImplExt: ObjectSubclass {
fn parent_protocols() -> Vec<String>; fn parent_protocols() -> Vec<String>;
fn parent_uri(&self, element: &Self::Type) -> Option<String>; fn parent_uri(&self) -> Option<String>;
fn parent_set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>; fn parent_set_uri(&self, uri: &str) -> Result<(), glib::Error>;
} }
impl<T: URIHandlerImpl> URIHandlerImplExt for T { impl<T: URIHandlerImpl> URIHandlerImplExt for T {
@ -38,7 +38,7 @@ impl<T: URIHandlerImpl> URIHandlerImplExt for T {
} }
} }
fn parent_uri(&self, element: &Self::Type) -> Option<String> { fn parent_uri(&self) -> Option<String> {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<URIHandler>() let parent_iface = type_data.as_ref().parent_interface::<URIHandler>()
@ -47,12 +47,17 @@ impl<T: URIHandlerImpl> URIHandlerImplExt for T {
let func = (*parent_iface) let func = (*parent_iface)
.get_uri .get_uri
.expect("no parent \"uri\" implementation"); .expect("no parent \"uri\" implementation");
let ret = func(element.unsafe_cast_ref::<URIHandler>().to_glib_none().0); let ret = func(
self.instance()
.unsafe_cast_ref::<URIHandler>()
.to_glib_none()
.0,
);
from_glib_full(ret) from_glib_full(ret)
} }
} }
fn parent_set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error> { fn parent_set_uri(&self, uri: &str) -> Result<(), glib::Error> {
unsafe { unsafe {
let type_data = Self::type_data(); let type_data = Self::type_data();
let parent_iface = type_data.as_ref().parent_interface::<URIHandler>() let parent_iface = type_data.as_ref().parent_interface::<URIHandler>()
@ -64,7 +69,10 @@ impl<T: URIHandlerImpl> URIHandlerImplExt for T {
let mut err = ptr::null_mut(); let mut err = ptr::null_mut();
func( func(
element.unsafe_cast_ref::<URIHandler>().to_glib_none().0, self.instance()
.unsafe_cast_ref::<URIHandler>()
.to_glib_none()
.0,
uri.to_glib_none().0, uri.to_glib_none().0,
&mut err, &mut err,
); );
@ -126,8 +134,7 @@ unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(
let instance = &*(uri_handler as *mut T::Instance); let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
imp.uri(from_glib_borrow::<_, URIHandler>(uri_handler).unsafe_cast_ref()) imp.uri().to_glib_full()
.to_glib_full()
} }
unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>( unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
@ -138,10 +145,7 @@ unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
let instance = &*(uri_handler as *mut T::Instance); let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.imp(); let imp = instance.imp();
match imp.set_uri( match imp.set_uri(glib::GString::from_glib_borrow(uri).as_str()) {
from_glib_borrow::<_, URIHandler>(uri_handler).unsafe_cast_ref(),
glib::GString::from_glib_borrow(uri).as_str(),
) {
Ok(()) => true.into_glib(), Ok(()) => true.into_glib(),
Err(error) => { Err(error) => {
if !err.is_null() { if !err.is_null() {