From a16c3888e59abb13fabfb1407d5837f91ee1d3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 5 May 2022 13:24:46 +0300 Subject: [PATCH] Return base class pads by reference instead of strong reference Avoids unnecessary reference counting and the caller can get a strong reference easily by calling clone(). --- gstreamer-audio/src/audio_decoder.rs | 16 ++++++++-------- gstreamer-audio/src/audio_encoder.rs | 16 ++++++++-------- gstreamer-base/src/aggregator.rs | 9 ++++----- gstreamer-base/src/base_parse.rs | 16 ++++++++-------- gstreamer-base/src/base_sink.rs | 9 ++++----- gstreamer-base/src/base_src.rs | 9 ++++----- gstreamer-base/src/base_transform.rs | 16 ++++++++-------- gstreamer-rtp/src/rtp_base_depayload.rs | 16 ++++++++-------- gstreamer-rtp/src/rtp_base_payload.rs | 16 ++++++++-------- gstreamer-video/src/video_decoder.rs | 16 ++++++++-------- gstreamer-video/src/video_encoder.rs | 16 ++++++++-------- 11 files changed, 76 insertions(+), 79 deletions(-) diff --git a/gstreamer-audio/src/audio_decoder.rs b/gstreamer-audio/src/audio_decoder.rs index c50e5a46b..ae95c3dd3 100644 --- a/gstreamer-audio/src/audio_decoder.rs +++ b/gstreamer-audio/src/audio_decoder.rs @@ -58,9 +58,9 @@ pub trait AudioDecoderExtManual: 'static { line: u32, ) -> Result; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> AudioDecoderExtManual for O { @@ -178,17 +178,17 @@ impl> AudioDecoderExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstAudioDecoder); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstAudioDecoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstAudioDecoder); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-audio/src/audio_encoder.rs b/gstreamer-audio/src/audio_encoder.rs index 55496cbdd..8ea3814ca 100644 --- a/gstreamer-audio/src/audio_encoder.rs +++ b/gstreamer-audio/src/audio_encoder.rs @@ -24,9 +24,9 @@ pub trait AudioEncoderExtManual: 'static { #[doc(alias = "gst_audio_encoder_get_allocator")] fn allocator(&self) -> (Option, gst::AllocationParams); - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> AudioEncoderExtManual for O { @@ -84,17 +84,17 @@ impl> AudioEncoderExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstAudioEncoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstAudioEncoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstAudioEncoder); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-base/src/aggregator.rs b/gstreamer-base/src/aggregator.rs index cf919bdb7..cff94729e 100644 --- a/gstreamer-base/src/aggregator.rs +++ b/gstreamer-base/src/aggregator.rs @@ -85,7 +85,7 @@ pub trait AggregatorExtManual: 'static { f: F, ) -> SignalHandlerId; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> AggregatorExtManual for O { @@ -270,11 +270,10 @@ impl> AggregatorExtManual for O { } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let ptr: &ffi::GstAggregator = &*(self.as_ptr() as *const _); - - from_glib_none(ptr.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstAggregator); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-base/src/base_parse.rs b/gstreamer-base/src/base_parse.rs index 08545a3c2..0fcb78810 100644 --- a/gstreamer-base/src/base_parse.rs +++ b/gstreamer-base/src/base_parse.rs @@ -9,9 +9,9 @@ use std::mem; pub trait BaseParseExtManual: 'static { #[doc(alias = "get_sink_pad")] - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; #[doc(alias = "get_src_pad")] - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; #[doc(alias = "gst_base_parse_set_duration")] fn set_duration>(&self, duration: V, interval: u32); @@ -38,17 +38,17 @@ pub trait BaseParseExtManual: 'static { } impl> BaseParseExtManual for O { - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseParse); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseParse); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs index 4abd84ab8..433e34762 100644 --- a/gstreamer-base/src/base_sink.rs +++ b/gstreamer-base/src/base_sink.rs @@ -14,7 +14,7 @@ pub trait BaseSinkExtManual: 'static { &self, ) -> Result<(bool, bool, Option, Option), glib::BoolError>; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; } impl> BaseSinkExtManual for O { @@ -58,11 +58,10 @@ impl> BaseSinkExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let ptr: &ffi::GstBaseSink = &*(self.as_ptr() as *const _); - - from_glib_none(ptr.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseSink); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs index 00dbbc7e8..e62f3f500 100644 --- a/gstreamer-base/src/base_src.rs +++ b/gstreamer-base/src/base_src.rs @@ -25,7 +25,7 @@ pub trait BaseSrcExtManual: 'static { #[doc(alias = "gst_base_src_new_segment")] fn new_segment(&self, segment: &gst::Segment) -> Result<(), glib::BoolError>; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> BaseSrcExtManual for O { @@ -95,11 +95,10 @@ impl> BaseSrcExtManual for O { } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let ptr: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _); - - from_glib_none(ptr.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseSrc); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-base/src/base_transform.rs b/gstreamer-base/src/base_transform.rs index 389ec645a..a072a414f 100644 --- a/gstreamer-base/src/base_transform.rs +++ b/gstreamer-base/src/base_transform.rs @@ -14,9 +14,9 @@ pub trait BaseTransformExtManual: 'static { #[doc(alias = "get_segment")] fn segment(&self) -> gst::Segment; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> BaseTransformExtManual for O { @@ -41,17 +41,17 @@ impl> BaseTransformExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstBaseTransform = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstBaseTransform); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-rtp/src/rtp_base_depayload.rs b/gstreamer-rtp/src/rtp_base_depayload.rs index 26d8f99fa..b8d7c69b8 100644 --- a/gstreamer-rtp/src/rtp_base_depayload.rs +++ b/gstreamer-rtp/src/rtp_base_depayload.rs @@ -9,9 +9,9 @@ pub trait RTPBaseDepayloadExtManual: 'static { #[doc(alias = "gst_rtp_base_depayload_push_list")] fn push_list(&self, list: gst::BufferList) -> Result; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> RTPBaseDepayloadExtManual for O { @@ -33,17 +33,17 @@ impl> RTPBaseDepayloadExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstRTPBaseDepayload = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstRTPBaseDepayload); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstRTPBaseDepayload = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstRTPBaseDepayload); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-rtp/src/rtp_base_payload.rs b/gstreamer-rtp/src/rtp_base_payload.rs index 934120f07..a833b2cf0 100644 --- a/gstreamer-rtp/src/rtp_base_payload.rs +++ b/gstreamer-rtp/src/rtp_base_payload.rs @@ -16,9 +16,9 @@ pub trait RTPBasePayloadExtManual: 'static { #[doc(alias = "gst_rtp_base_payload_push_list")] fn push_list(&self, list: gst::BufferList) -> Result; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> RTPBasePayloadExtManual for O { @@ -56,17 +56,17 @@ impl> RTPBasePayloadExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstRTPBasePayload = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstRTPBasePayload = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstRTPBasePayload); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-video/src/video_decoder.rs b/gstreamer-video/src/video_decoder.rs index b03215109..9afd9283b 100644 --- a/gstreamer-video/src/video_decoder.rs +++ b/gstreamer-video/src/video_decoder.rs @@ -110,9 +110,9 @@ pub trait VideoDecoderExtManual: 'static { line: u32, ) -> Result; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> VideoDecoderExtManual for O { @@ -410,17 +410,17 @@ impl> VideoDecoderExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstVideoDecoder); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstVideoDecoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstVideoDecoder); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } } diff --git a/gstreamer-video/src/video_encoder.rs b/gstreamer-video/src/video_encoder.rs index 96a490616..cea854ee9 100644 --- a/gstreamer-video/src/video_encoder.rs +++ b/gstreamer-video/src/video_encoder.rs @@ -68,9 +68,9 @@ pub trait VideoEncoderExtManual: 'static { output_state: VideoCodecState<'a, InNegotiation<'a>>, ) -> Result<(), gst::FlowError>; - fn sink_pad(&self) -> gst::Pad; + fn sink_pad(&self) -> &gst::Pad; - fn src_pad(&self) -> gst::Pad; + fn src_pad(&self) -> &gst::Pad; } impl> VideoEncoderExtManual for O { @@ -253,17 +253,17 @@ impl> VideoEncoderExtManual for O { } } - fn sink_pad(&self) -> gst::Pad { + fn sink_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstVideoEncoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.sinkpad) + let elt = &*(self.as_ptr() as *const ffi::GstVideoEncoder); + &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } - fn src_pad(&self) -> gst::Pad { + fn src_pad(&self) -> &gst::Pad { unsafe { - let elt: &ffi::GstVideoEncoder = &*(self.as_ptr() as *const _); - from_glib_none(elt.srcpad) + let elt = &*(self.as_ptr() as *const ffi::GstVideoEncoder); + &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad) } } }