From 5e2249d368ec5adceac1acd4efb48dc00947060d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 18 Jan 2022 11:57:22 +0200 Subject: [PATCH] message/query/event: Implement views in a more consistent way Co-authored-by: Jan Alexander Steffens (heftig) --- gstreamer-audio/src/subclass/audio_decoder.rs | 16 +- gstreamer-audio/src/subclass/audio_encoder.rs | 16 +- gstreamer-base/src/subclass/aggregator.rs | 22 +- gstreamer-base/src/subclass/base_sink.rs | 8 +- gstreamer-base/src/subclass/base_src.rs | 8 +- gstreamer-base/src/subclass/base_transform.rs | 22 +- gstreamer-gl/src/functions.rs | 2 +- gstreamer-video/src/subclass/video_decoder.rs | 16 +- gstreamer-video/src/subclass/video_encoder.rs | 16 +- gstreamer/src/event.rs | 417 ++++++------- gstreamer/src/lib.rs | 2 +- gstreamer/src/message.rs | 455 +++++++------- gstreamer/src/pad.rs | 30 +- gstreamer/src/query.rs | 568 ++++++++---------- 14 files changed, 762 insertions(+), 836 deletions(-) diff --git a/gstreamer-audio/src/subclass/audio_decoder.rs b/gstreamer-audio/src/subclass/audio_decoder.rs index 391a1da74..c8b834586 100644 --- a/gstreamer-audio/src/subclass/audio_decoder.rs +++ b/gstreamer-audio/src/subclass/audio_decoder.rs @@ -87,7 +87,7 @@ pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, query) } @@ -95,7 +95,7 @@ pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -151,13 +151,13 @@ pub trait AudioDecoderImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; } @@ -468,7 +468,7 @@ impl AudioDecoderImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -492,7 +492,7 @@ impl AudioDecoderImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -821,7 +821,7 @@ unsafe extern "C" fn audio_decoder_propose_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -845,7 +845,7 @@ unsafe extern "C" fn audio_decoder_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-audio/src/subclass/audio_encoder.rs b/gstreamer-audio/src/subclass/audio_encoder.rs index b2e5627be..810fa6679 100644 --- a/gstreamer-audio/src/subclass/audio_encoder.rs +++ b/gstreamer-audio/src/subclass/audio_encoder.rs @@ -79,7 +79,7 @@ pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, query) } @@ -87,7 +87,7 @@ pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -137,13 +137,13 @@ pub trait AudioEncoderImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; } @@ -418,7 +418,7 @@ impl AudioEncoderImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -442,7 +442,7 @@ impl AudioEncoderImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -741,7 +741,7 @@ unsafe extern "C" fn audio_encoder_propose_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -765,7 +765,7 @@ unsafe extern "C" fn audio_encoder_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index 148d8d3b7..d92e3a703 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -153,8 +153,8 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, pad, decide_query, query) } @@ -162,7 +162,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -289,14 +289,14 @@ pub trait AggregatorImplExt: ObjectSubclass { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; #[cfg(any(feature = "v1_18", feature = "dox"))] @@ -692,8 +692,8 @@ impl AggregatorImplExt for T { &self, element: &Self::Type, pad: &AggregatorPad, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -722,7 +722,7 @@ impl AggregatorImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -1178,7 +1178,7 @@ unsafe extern "C" fn aggregator_propose_allocation( } }; let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -1207,7 +1207,7 @@ unsafe extern "C" fn aggregator_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-base/src/subclass/base_sink.rs b/gstreamer-base/src/subclass/base_sink.rs index 9ea8fbf92..d96a5ec62 100644 --- a/gstreamer-base/src/subclass/base_sink.rs +++ b/gstreamer-base/src/subclass/base_sink.rs @@ -81,7 +81,7 @@ pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, query) } @@ -137,7 +137,7 @@ pub trait BaseSinkImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; } @@ -403,7 +403,7 @@ impl BaseSinkImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -671,7 +671,7 @@ unsafe extern "C" fn base_sink_propose_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index f58657539..c85f64dd8 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -111,7 +111,7 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -180,7 +180,7 @@ pub trait BaseSrcImplExt: ObjectSubclass { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; } @@ -587,7 +587,7 @@ impl BaseSrcImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -1020,7 +1020,7 @@ unsafe extern "C" fn base_src_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-base/src/subclass/base_transform.rs b/gstreamer-base/src/subclass/base_transform.rs index 7f2b93424..ba8d4b186 100644 --- a/gstreamer-base/src/subclass/base_transform.rs +++ b/gstreamer-base/src/subclass/base_transform.rs @@ -138,8 +138,8 @@ pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, decide_query, query) } @@ -147,7 +147,7 @@ pub trait BaseTransformImpl: BaseTransformImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -277,14 +277,14 @@ pub trait BaseTransformImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_copy_metadata( @@ -717,8 +717,8 @@ impl BaseTransformImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - decide_query: Option>, - query: gst::query::Allocation<&mut gst::QueryRef>, + decide_query: Option<&gst::query::Allocation>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -746,7 +746,7 @@ impl BaseTransformImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -1329,7 +1329,7 @@ unsafe extern "C" fn base_transform_propose_allocation( } }; let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -1353,7 +1353,7 @@ unsafe extern "C" fn base_transform_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-gl/src/functions.rs b/gstreamer-gl/src/functions.rs index 49ede0ea5..7c92ac1cf 100644 --- a/gstreamer-gl/src/functions.rs +++ b/gstreamer-gl/src/functions.rs @@ -7,7 +7,7 @@ use std::ptr; #[doc(alias = "gst_gl_handle_context_query")] pub fn gl_handle_context_query( element: &impl IsA, - query: gst::query::Context<&mut gst::QueryRef>, + query: &mut gst::query::Context, display: Option<&impl IsA>, context: Option<&impl IsA>, other_context: Option<&impl IsA>, diff --git a/gstreamer-video/src/subclass/video_decoder.rs b/gstreamer-video/src/subclass/video_decoder.rs index 11ccf0b47..58053bbf0 100644 --- a/gstreamer-video/src/subclass/video_decoder.rs +++ b/gstreamer-video/src/subclass/video_decoder.rs @@ -91,7 +91,7 @@ pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, query) } @@ -99,7 +99,7 @@ pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -166,13 +166,13 @@ pub trait VideoDecoderImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; #[cfg(any(feature = "v1_20", feature = "dox"))] @@ -494,7 +494,7 @@ impl VideoDecoderImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -518,7 +518,7 @@ impl VideoDecoderImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -869,7 +869,7 @@ unsafe extern "C" fn video_decoder_propose_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -893,7 +893,7 @@ unsafe extern "C" fn video_decoder_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer-video/src/subclass/video_encoder.rs b/gstreamer-video/src/subclass/video_encoder.rs index 307846277..bedce3a81 100644 --- a/gstreamer-video/src/subclass/video_encoder.rs +++ b/gstreamer-video/src/subclass/video_encoder.rs @@ -77,7 +77,7 @@ pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl { fn propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_propose_allocation(element, query) } @@ -85,7 +85,7 @@ pub trait VideoEncoderImpl: VideoEncoderImplExt + ElementImpl { fn decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { self.parent_decide_allocation(element, query) } @@ -131,13 +131,13 @@ pub trait VideoEncoderImplExt: ObjectSubclass { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError>; } @@ -410,7 +410,7 @@ impl VideoEncoderImplExt for T { fn parent_propose_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -434,7 +434,7 @@ impl VideoEncoderImplExt for T { fn parent_decide_allocation( &self, element: &Self::Type, - query: gst::query::Allocation<&mut gst::QueryRef>, + query: &mut gst::query::Allocation, ) -> Result<(), gst::LoggableError> { unsafe { let data = Self::type_data(); @@ -721,7 +721,7 @@ unsafe extern "C" fn video_encoder_propose_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; @@ -745,7 +745,7 @@ unsafe extern "C" fn video_encoder_decide_allocation( let imp = instance.imp(); let wrap: Borrowed = from_glib_borrow(ptr); let query = match gst::QueryRef::from_mut_ptr(query).view_mut() { - gst::QueryView::Allocation(allocation) => allocation, + gst::QueryViewMut::Allocation(allocation) => allocation, _ => unreachable!(), }; diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index 68c48c59b..80663dc10 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -4,6 +4,7 @@ use crate::structure::*; use crate::ClockTime; use crate::GenericFormattedValue; +use std::borrow::Borrow; use std::cmp; use std::ffi::CStr; use std::fmt; @@ -12,9 +13,7 @@ use std::num::NonZeroU32; use std::ops::Deref; use std::ptr; -use glib::translate::{ - from_glib, from_glib_full, from_glib_none, try_from_glib, IntoGlib, ToGlibPtr, -}; +use glib::translate::*; use glib::value::ToSendValue; #[cfg(any(feature = "v1_10", feature = "dox"))] @@ -221,55 +220,49 @@ impl EventRef { self.structure().map_or(false, |s| s.has_name(name)) } - pub fn view(&self) -> EventView<&EventRef> { - let type_ = unsafe { (*self.as_ptr()).type_ }; + pub fn view(&self) -> EventView { + unsafe { + let type_ = (*self.as_ptr()).type_; - match type_ { - ffi::GST_EVENT_FLUSH_START => EventView::FlushStart(FlushStart(self)), - ffi::GST_EVENT_FLUSH_STOP => EventView::FlushStop(FlushStop(self)), - ffi::GST_EVENT_STREAM_START => EventView::StreamStart(StreamStart(self)), - ffi::GST_EVENT_CAPS => EventView::Caps(Caps(self)), - ffi::GST_EVENT_SEGMENT => EventView::Segment(Segment(self)), - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_EVENT_STREAM_COLLECTION => EventView::StreamCollection(StreamCollection(self)), - ffi::GST_EVENT_TAG => EventView::Tag(Tag(self)), - ffi::GST_EVENT_BUFFERSIZE => EventView::Buffersize(Buffersize(self)), - ffi::GST_EVENT_SINK_MESSAGE => EventView::SinkMessage(SinkMessage(self)), - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_EVENT_STREAM_GROUP_DONE => EventView::StreamGroupDone(StreamGroupDone(self)), - ffi::GST_EVENT_EOS => EventView::Eos(Eos(self)), - ffi::GST_EVENT_TOC => EventView::Toc(Toc(self)), - ffi::GST_EVENT_PROTECTION => EventView::Protection(Protection(self)), - ffi::GST_EVENT_SEGMENT_DONE => EventView::SegmentDone(SegmentDone(self)), - ffi::GST_EVENT_GAP => EventView::Gap(Gap(self)), - #[cfg(any(feature = "v1_18", feature = "dox"))] - ffi::GST_EVENT_INSTANT_RATE_CHANGE => { - EventView::InstantRateChange(InstantRateChange(self)) + match type_ { + ffi::GST_EVENT_FLUSH_START => FlushStart::view(self), + ffi::GST_EVENT_FLUSH_STOP => FlushStop::view(self), + ffi::GST_EVENT_STREAM_START => StreamStart::view(self), + ffi::GST_EVENT_CAPS => Caps::view(self), + ffi::GST_EVENT_SEGMENT => Segment::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_EVENT_STREAM_COLLECTION => StreamCollection::view(self), + ffi::GST_EVENT_TAG => Tag::view(self), + ffi::GST_EVENT_BUFFERSIZE => Buffersize::view(self), + ffi::GST_EVENT_SINK_MESSAGE => SinkMessage::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_EVENT_STREAM_GROUP_DONE => StreamGroupDone::view(self), + ffi::GST_EVENT_EOS => Eos::view(self), + ffi::GST_EVENT_TOC => Toc::view(self), + ffi::GST_EVENT_PROTECTION => Protection::view(self), + ffi::GST_EVENT_SEGMENT_DONE => SegmentDone::view(self), + ffi::GST_EVENT_GAP => Gap::view(self), + #[cfg(any(feature = "v1_18", feature = "dox"))] + ffi::GST_EVENT_INSTANT_RATE_CHANGE => InstantRateChange::view(self), + ffi::GST_EVENT_QOS => Qos::view(self), + ffi::GST_EVENT_SEEK => Seek::view(self), + ffi::GST_EVENT_NAVIGATION => Navigation::view(self), + ffi::GST_EVENT_LATENCY => Latency::view(self), + ffi::GST_EVENT_STEP => Step::view(self), + ffi::GST_EVENT_RECONFIGURE => Reconfigure::view(self), + ffi::GST_EVENT_TOC_SELECT => TocSelect::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_EVENT_SELECT_STREAMS => SelectStreams::view(self), + #[cfg(any(feature = "v1_18", feature = "dox"))] + ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => InstantRateSyncTime::view(self), + ffi::GST_EVENT_CUSTOM_UPSTREAM => CustomUpstream::view(self), + ffi::GST_EVENT_CUSTOM_DOWNSTREAM => CustomDownstream::view(self), + ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => CustomDownstreamOob::view(self), + ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => CustomDownstreamSticky::view(self), + ffi::GST_EVENT_CUSTOM_BOTH => CustomBoth::view(self), + ffi::GST_EVENT_CUSTOM_BOTH_OOB => CustomBothOob::view(self), + _ => Other::view(self), } - ffi::GST_EVENT_QOS => EventView::Qos(Qos(self)), - ffi::GST_EVENT_SEEK => EventView::Seek(Seek(self)), - ffi::GST_EVENT_NAVIGATION => EventView::Navigation(Navigation(self)), - ffi::GST_EVENT_LATENCY => EventView::Latency(Latency(self)), - ffi::GST_EVENT_STEP => EventView::Step(Step(self)), - ffi::GST_EVENT_RECONFIGURE => EventView::Reconfigure(Reconfigure(self)), - ffi::GST_EVENT_TOC_SELECT => EventView::TocSelect(TocSelect(self)), - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_EVENT_SELECT_STREAMS => EventView::SelectStreams(SelectStreams(self)), - #[cfg(any(feature = "v1_18", feature = "dox"))] - ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => { - EventView::InstantRateSyncTime(InstantRateSyncTime(self)) - } - ffi::GST_EVENT_CUSTOM_UPSTREAM => EventView::CustomUpstream(CustomUpstream(self)), - ffi::GST_EVENT_CUSTOM_DOWNSTREAM => EventView::CustomDownstream(CustomDownstream(self)), - ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => { - EventView::CustomDownstreamOob(CustomDownstreamOob(self)) - } - ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => { - EventView::CustomDownstreamSticky(CustomDownstreamSticky(self)) - } - ffi::GST_EVENT_CUSTOM_BOTH => EventView::CustomBoth(CustomBoth(self)), - ffi::GST_EVENT_CUSTOM_BOTH_OOB => EventView::CustomBothOob(CustomBothOob(self)), - _ => EventView::Other(Other(self)), } } } @@ -291,116 +284,122 @@ impl fmt::Debug for EventRef { } } -pub unsafe trait AsPtr { - unsafe fn as_ptr(&self) -> *mut ffi::GstEvent; -} - -unsafe impl AsPtr for Event { - unsafe fn as_ptr(&self) -> *mut ffi::GstEvent { - EventRef::as_ptr(self) as *mut ffi::GstEvent - } -} - -unsafe impl<'a> AsPtr for &'a EventRef { - unsafe fn as_ptr(&self) -> *mut ffi::GstEvent { - EventRef::as_ptr(self) as *mut ffi::GstEvent - } -} - -pub trait StickyEventType { +pub trait StickyEventType: ToOwned { const TYPE: EventType; - unsafe fn from_event(event: Event) -> Self; + unsafe fn from_event(event: Event) -> Self::Owned; } #[derive(Debug)] #[non_exhaustive] -pub enum EventView { - FlushStart(FlushStart), - FlushStop(FlushStop), - StreamStart(StreamStart), - Caps(Caps), - Segment(Segment), +pub enum EventView<'a> { + FlushStart(&'a FlushStart), + FlushStop(&'a FlushStop), + StreamStart(&'a StreamStart), + Caps(&'a Caps), + Segment(&'a Segment), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - StreamCollection(StreamCollection), - Tag(Tag), - Buffersize(Buffersize), - SinkMessage(SinkMessage), + StreamCollection(&'a StreamCollection), + Tag(&'a Tag), + Buffersize(&'a Buffersize), + SinkMessage(&'a SinkMessage), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - StreamGroupDone(StreamGroupDone), - Eos(Eos), - Toc(Toc), - Protection(Protection), - SegmentDone(SegmentDone), - Gap(Gap), + StreamGroupDone(&'a StreamGroupDone), + Eos(&'a Eos), + Toc(&'a Toc), + Protection(&'a Protection), + SegmentDone(&'a SegmentDone), + Gap(&'a Gap), #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] - InstantRateChange(InstantRateChange), - Qos(Qos), - Seek(Seek), - Navigation(Navigation), - Latency(Latency), - Step(Step), - Reconfigure(Reconfigure), - TocSelect(TocSelect), + InstantRateChange(&'a InstantRateChange), + Qos(&'a Qos), + Seek(&'a Seek), + Navigation(&'a Navigation), + Latency(&'a Latency), + Step(&'a Step), + Reconfigure(&'a Reconfigure), + TocSelect(&'a TocSelect), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - SelectStreams(SelectStreams), + SelectStreams(&'a SelectStreams), #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] - InstantRateSyncTime(InstantRateSyncTime), - CustomUpstream(CustomUpstream), - CustomDownstream(CustomDownstream), - CustomDownstreamOob(CustomDownstreamOob), - CustomDownstreamSticky(CustomDownstreamSticky), - CustomBoth(CustomBoth), - CustomBothOob(CustomBothOob), - Other(Other), + InstantRateSyncTime(&'a InstantRateSyncTime), + CustomUpstream(&'a CustomUpstream), + CustomDownstream(&'a CustomDownstream), + CustomDownstreamOob(&'a CustomDownstreamOob), + CustomDownstreamSticky(&'a CustomDownstreamSticky), + CustomBoth(&'a CustomBoth), + CustomBothOob(&'a CustomBothOob), + Other(&'a Other), } macro_rules! declare_concrete_event { (@sticky $name:ident, $param:ident) => { declare_concrete_event!($name, $param); - impl StickyEventType for $name { + impl StickyEventType for $name { const TYPE: EventType = EventType::$name; - unsafe fn from_event(event: Event) -> Self { - Self(event) + unsafe fn from_event(event: Event) -> Self::Owned { + $name::(event) } } }; ($name:ident, $param:ident) => { #[derive(Debug)] - pub struct $name<$param>($param); + #[repr(transparent)] + pub struct $name<$param = EventRef>($param); - impl<'a> $name<&'a EventRef> { + impl $name { pub fn event(&self) -> &EventRef { - self.0 + unsafe { &*(self as *const Self as *const EventRef) } + } + + unsafe fn view(event: &EventRef) -> EventView<'_> { + let event = &*(event as *const EventRef as *const Self); + EventView::$name(event) } } - impl<'a> Deref for $name<&'a EventRef> { + impl Deref for $name { type Target = EventRef; fn deref(&self) -> &Self::Target { - self.0 + self.event() } } - impl Deref for $name { - type Target = EventRef; + impl ToOwned for $name { + type Owned = $name; - fn deref(&self) -> &Self::Target { - &self.0 + fn to_owned(&self) -> Self::Owned { + $name::(self.copy()) } } impl $name { - pub fn get_mut(&mut self) -> Option<&mut EventRef> { - self.0.get_mut() + pub fn get_mut(&mut self) -> Option<&mut $name> { + self.0 + .get_mut() + .map(|event| unsafe { &mut *(event as *mut EventRef as *mut $name) }) + } + } + + impl Deref for $name { + type Target = $name; + + fn deref(&self) -> &Self::Target { + unsafe { &*(self.0.as_ptr() as *const Self::Target) } + } + } + + impl Borrow<$name> for $name { + fn borrow(&self) -> &$name { + &*self } } @@ -443,14 +442,14 @@ impl FlushStop { } } -impl FlushStop { +impl FlushStop { #[doc(alias = "get_reset_time")] #[doc(alias = "gst_event_parse_flush_stop")] pub fn resets_time(&self) -> bool { unsafe { let mut reset_time = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_flush_stop(self.0.as_ptr(), reset_time.as_mut_ptr()); + ffi::gst_event_parse_flush_stop(self.as_mut_ptr(), reset_time.as_mut_ptr()); from_glib(reset_time.assume_init()) } @@ -470,40 +469,27 @@ impl StreamStart { assert_initialized_main_thread!(); StreamStartBuilder::new(stream_id) } +} +impl StreamStart { #[doc(alias = "get_stream_id")] #[doc(alias = "gst_event_parse_stream_start")] pub fn stream_id(&self) -> &str { unsafe { let mut stream_id = ptr::null(); - ffi::gst_event_parse_stream_start(AsPtr::as_ptr(&self.0), &mut stream_id); + ffi::gst_event_parse_stream_start(self.as_mut_ptr(), &mut stream_id); CStr::from_ptr(stream_id).to_str().unwrap() } } -} -impl<'a> StreamStart<&'a EventRef> { - #[doc(alias = "get_stream_id")] - #[doc(alias = "gst_event_parse_stream_start")] - pub fn stream_id(&self) -> &'a str { - unsafe { - let mut stream_id = ptr::null(); - - ffi::gst_event_parse_stream_start(AsPtr::as_ptr(&self.0), &mut stream_id); - CStr::from_ptr(stream_id).to_str().unwrap() - } - } -} - -impl StreamStart { #[doc(alias = "get_stream_flags")] #[doc(alias = "gst_event_parse_stream_flags")] pub fn stream_flags(&self) -> crate::StreamFlags { unsafe { let mut stream_flags = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_stream_flags(self.0.as_ptr(), stream_flags.as_mut_ptr()); + ffi::gst_event_parse_stream_flags(self.as_mut_ptr(), stream_flags.as_mut_ptr()); from_glib(stream_flags.assume_init()) } @@ -515,7 +501,7 @@ impl StreamStart { unsafe { let mut group_id = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_group_id(self.0.as_ptr(), group_id.as_mut_ptr()); + ffi::gst_event_parse_group_id(self.as_mut_ptr(), group_id.as_mut_ptr()); let group_id = group_id.assume_init(); if group_id == 0 { @@ -533,7 +519,7 @@ impl StreamStart { pub fn stream(&self) -> Option { unsafe { let mut stream = ptr::null_mut(); - ffi::gst_event_parse_stream(self.0.as_ptr(), &mut stream); + ffi::gst_event_parse_stream(self.as_mut_ptr(), &mut stream); from_glib_full(stream) } } @@ -552,33 +538,16 @@ impl Caps { assert_initialized_main_thread!(); CapsBuilder::new(caps) } +} +impl Caps { #[doc(alias = "get_caps")] #[doc(alias = "gst_event_parse_caps")] pub fn caps(&self) -> &crate::CapsRef { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_event_parse_caps(AsPtr::as_ptr(&self.0), &mut caps); - crate::CapsRef::from_ptr(caps) - } - } - - #[doc(alias = "get_caps_owned")] - #[doc(alias = "gst_event_parse_caps")] - pub fn caps_owned(&self) -> crate::Caps { - unsafe { from_glib_none(self.caps().as_ptr()) } - } -} - -impl<'a> Caps<&'a EventRef> { - #[doc(alias = "get_caps")] - #[doc(alias = "gst_event_parse_caps")] - pub fn caps(&self) -> &'a crate::CapsRef { - unsafe { - let mut caps = ptr::null_mut(); - - ffi::gst_event_parse_caps(AsPtr::as_ptr(&self.0), &mut caps); + ffi::gst_event_parse_caps(self.as_mut_ptr(), &mut caps); crate::CapsRef::from_ptr(caps) } } @@ -605,27 +574,16 @@ impl Segment { assert_initialized_main_thread!(); SegmentBuilder::new(segment.as_ref()) } +} +impl Segment { #[doc(alias = "get_segment")] #[doc(alias = "gst_event_parse_segment")] pub fn segment(&self) -> &crate::Segment { unsafe { let mut segment = ptr::null(); - ffi::gst_event_parse_segment(AsPtr::as_ptr(&self.0), &mut segment); - &*(segment as *mut ffi::GstSegment as *mut crate::Segment) - } - } -} - -impl<'a> Segment<&'a EventRef> { - #[doc(alias = "get_segment")] - #[doc(alias = "gst_event_parse_segment")] - pub fn segment(&self) -> &'a crate::Segment { - unsafe { - let mut segment = ptr::null(); - - ffi::gst_event_parse_segment(AsPtr::as_ptr(&self.0), &mut segment); + ffi::gst_event_parse_segment(self.as_mut_ptr(), &mut segment); &*(segment as *mut ffi::GstSegment as *mut crate::Segment) } } @@ -656,7 +614,7 @@ impl StreamCollection { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl StreamCollection { +impl StreamCollection { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[doc(alias = "get_stream_collection")] @@ -665,7 +623,7 @@ impl StreamCollection { unsafe { let mut stream_collection = ptr::null_mut(); - ffi::gst_event_parse_stream_collection(self.0.as_ptr(), &mut stream_collection); + ffi::gst_event_parse_stream_collection(self.as_mut_ptr(), &mut stream_collection); from_glib_full(stream_collection) } } @@ -684,33 +642,16 @@ impl Tag { assert_initialized_main_thread!(); TagBuilder::new(tags) } +} +impl Tag { #[doc(alias = "get_tag")] #[doc(alias = "gst_event_parse_tag")] pub fn tag(&self) -> &crate::TagListRef { unsafe { let mut tags = ptr::null_mut(); - ffi::gst_event_parse_tag(AsPtr::as_ptr(&self.0), &mut tags); - crate::TagListRef::from_ptr(tags) - } - } - - #[doc(alias = "get_tag_owned")] - #[doc(alias = "gst_event_parse_tag")] - pub fn tag_owned(&self) -> crate::TagList { - unsafe { from_glib_none(self.tag().as_ptr()) } - } -} - -impl<'a> Tag<&'a EventRef> { - #[doc(alias = "get_tag")] - #[doc(alias = "gst_event_parse_tag")] - pub fn tag(&self) -> &'a crate::TagListRef { - unsafe { - let mut tags = ptr::null_mut(); - - ffi::gst_event_parse_tag(AsPtr::as_ptr(&self.0), &mut tags); + ffi::gst_event_parse_tag(self.as_mut_ptr(), &mut tags); crate::TagListRef::from_ptr(tags) } } @@ -745,7 +686,7 @@ impl Buffersize { } } -impl Buffersize { +impl Buffersize { #[doc(alias = "gst_event_parse_buffer_size")] pub fn get(&self) -> (GenericFormattedValue, GenericFormattedValue, bool) { unsafe { @@ -755,7 +696,7 @@ impl Buffersize { let mut async_ = mem::MaybeUninit::uninit(); ffi::gst_event_parse_buffer_size( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), minsize.as_mut_ptr(), maxsize.as_mut_ptr(), @@ -785,14 +726,14 @@ impl SinkMessage { } } -impl SinkMessage { +impl SinkMessage { #[doc(alias = "get_message")] #[doc(alias = "gst_event_parse_sink_message")] pub fn message(&self) -> crate::Message { unsafe { let mut msg = ptr::null_mut(); - ffi::gst_event_parse_sink_message(self.0.as_ptr(), &mut msg); + ffi::gst_event_parse_sink_message(self.as_mut_ptr(), &mut msg); from_glib_full(msg) } } @@ -823,7 +764,7 @@ impl StreamGroupDone { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl StreamGroupDone { +impl StreamGroupDone { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[doc(alias = "get_group_id")] @@ -832,7 +773,7 @@ impl StreamGroupDone { unsafe { let mut group_id = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_stream_group_done(self.0.as_ptr(), group_id.as_mut_ptr()); + ffi::gst_event_parse_stream_group_done(self.as_mut_ptr(), group_id.as_mut_ptr()); let group_id = group_id.assume_init(); assert_ne!(group_id, 0); @@ -873,7 +814,7 @@ impl Toc { } } -impl Toc { +impl Toc { #[doc(alias = "get_toc")] #[doc(alias = "gst_event_parse_toc")] pub fn toc(&self) -> (&crate::TocRef, bool) { @@ -881,7 +822,7 @@ impl Toc { let mut toc = ptr::null_mut(); let mut updated = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_toc(self.0.as_ptr(), &mut toc, updated.as_mut_ptr()); + ffi::gst_event_parse_toc(self.as_mut_ptr(), &mut toc, updated.as_mut_ptr()); ( crate::TocRef::from_ptr(toc), from_glib(updated.assume_init()), @@ -914,7 +855,7 @@ impl Protection { } } -impl Protection { +impl Protection { #[doc(alias = "gst_event_parse_protection")] pub fn get(&self) -> (&str, &crate::BufferRef, Option<&str>) { unsafe { @@ -923,7 +864,7 @@ impl Protection { let mut origin = ptr::null(); ffi::gst_event_parse_protection( - self.0.as_ptr(), + self.as_mut_ptr(), &mut system_id, &mut buffer, &mut origin, @@ -966,7 +907,7 @@ impl SegmentDone { } } -impl SegmentDone { +impl SegmentDone { #[doc(alias = "gst_event_parse_segment_done")] pub fn get(&self) -> GenericFormattedValue { unsafe { @@ -974,7 +915,7 @@ impl SegmentDone { let mut position = mem::MaybeUninit::uninit(); ffi::gst_event_parse_segment_done( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), position.as_mut_ptr(), ); @@ -999,7 +940,7 @@ impl Gap { } } -impl Gap { +impl Gap { #[doc(alias = "gst_event_parse_gap")] pub fn get(&self) -> (ClockTime, Option) { unsafe { @@ -1007,7 +948,7 @@ impl Gap { let mut duration = mem::MaybeUninit::uninit(); ffi::gst_event_parse_gap( - self.0.as_ptr(), + self.as_mut_ptr(), timestamp.as_mut_ptr(), duration.as_mut_ptr(), ); @@ -1025,7 +966,7 @@ impl Gap { pub fn gap_flags(&self) -> crate::GapFlags { unsafe { let mut flags = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_gap_flags(self.0.as_ptr(), flags.as_mut_ptr()); + ffi::gst_event_parse_gap_flags(self.as_mut_ptr(), flags.as_mut_ptr()); from_glib(flags.assume_init()) } } @@ -1055,7 +996,7 @@ impl InstantRateChange { #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -impl InstantRateChange { +impl InstantRateChange { #[doc(alias = "gst_event_parse_instant_rate_change")] pub fn get(&self) -> (f64, crate::SegmentFlags) { unsafe { @@ -1063,7 +1004,7 @@ impl InstantRateChange { let mut new_flags = mem::MaybeUninit::uninit(); ffi::gst_event_parse_instant_rate_change( - self.0.as_ptr(), + self.as_mut_ptr(), multiplier.as_mut_ptr(), new_flags.as_mut_ptr(), ); @@ -1095,7 +1036,7 @@ impl Qos { } } -impl Qos { +impl Qos { #[doc(alias = "gst_event_parse_qos")] pub fn get(&self) -> (crate::QOSType, f64, i64, Option) { unsafe { @@ -1105,7 +1046,7 @@ impl Qos { let mut timestamp = mem::MaybeUninit::uninit(); ffi::gst_event_parse_qos( - self.0.as_ptr(), + self.as_mut_ptr(), type_.as_mut_ptr(), proportion.as_mut_ptr(), diff.as_mut_ptr(), @@ -1155,7 +1096,7 @@ impl Seek { } } -impl Seek { +impl Seek { #[doc(alias = "gst_event_parse_seek")] pub fn get( &self, @@ -1177,7 +1118,7 @@ impl Seek { let mut stop = mem::MaybeUninit::uninit(); ffi::gst_event_parse_seek( - self.0.as_ptr(), + self.as_mut_ptr(), rate.as_mut_ptr(), fmt.as_mut_ptr(), flags.as_mut_ptr(), @@ -1207,7 +1148,7 @@ impl Seek { let mut trickmode_interval = mem::MaybeUninit::uninit(); ffi::gst_event_parse_seek_trickmode_interval( - self.0.as_ptr(), + self.as_mut_ptr(), trickmode_interval.as_mut_ptr(), ); @@ -1246,14 +1187,14 @@ impl Latency { } } -impl Latency { +impl Latency { #[doc(alias = "get_latency")] #[doc(alias = "gst_event_parse_latency")] pub fn latency(&self) -> ClockTime { unsafe { let mut latency = mem::MaybeUninit::uninit(); - ffi::gst_event_parse_latency(self.0.as_ptr(), latency.as_mut_ptr()); + ffi::gst_event_parse_latency(self.as_mut_ptr(), latency.as_mut_ptr()); try_from_glib(latency.assume_init()).expect("undefined latency") } @@ -1285,7 +1226,7 @@ impl Step { } } -impl Step { +impl Step { #[doc(alias = "gst_event_parse_step")] pub fn get(&self) -> (GenericFormattedValue, f64, bool, bool) { unsafe { @@ -1296,7 +1237,7 @@ impl Step { let mut intermediate = mem::MaybeUninit::uninit(); ffi::gst_event_parse_step( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), amount.as_mut_ptr(), rate.as_mut_ptr(), @@ -1345,26 +1286,15 @@ impl TocSelect { assert_initialized_main_thread!(); TocSelectBuilder::new(uid) } +} +impl TocSelect { #[doc(alias = "get_uid")] pub fn uid(&self) -> &str { unsafe { let mut uid = ptr::null_mut(); - ffi::gst_event_parse_toc_select(AsPtr::as_ptr(&self.0), &mut uid); - - CStr::from_ptr(uid).to_str().unwrap() - } - } -} - -impl<'a> TocSelect<&'a EventRef> { - #[doc(alias = "get_uid")] - pub fn uid(&self) -> &'a str { - unsafe { - let mut uid = ptr::null_mut(); - - ffi::gst_event_parse_toc_select(AsPtr::as_ptr(&self.0), &mut uid); + ffi::gst_event_parse_toc_select(self.as_mut_ptr(), &mut uid); CStr::from_ptr(uid).to_str().unwrap() } @@ -1396,7 +1326,7 @@ impl SelectStreams { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl SelectStreams { +impl SelectStreams { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[doc(alias = "get_streams")] @@ -1405,7 +1335,7 @@ impl SelectStreams { unsafe { let mut streams = ptr::null_mut(); - ffi::gst_event_parse_select_streams(self.0.as_ptr(), &mut streams); + ffi::gst_event_parse_select_streams(self.as_mut_ptr(), &mut streams); FromGlibPtrContainer::from_glib_full(streams) } @@ -1445,7 +1375,7 @@ impl InstantRateSyncTime { #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -impl InstantRateSyncTime { +impl InstantRateSyncTime { #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[doc(alias = "parse_instant_rate_sync_time")] @@ -1457,7 +1387,7 @@ impl InstantRateSyncTime { let mut upstream_running_time = mem::MaybeUninit::uninit(); ffi::gst_event_parse_instant_rate_sync_time( - self.0.as_ptr(), + self.as_mut_ptr(), rate_multiplier.as_mut_ptr(), running_time.as_mut_ptr(), upstream_running_time.as_mut_ptr(), @@ -2547,4 +2477,19 @@ mod tests { let structure = flush_start_evt.structure().unwrap(); assert_eq!(structure.get("test"), Ok(42u32)); } + + #[test] + fn test_view_lifetimes() { + crate::init().unwrap(); + + let caps = crate::Caps::builder("some/x-caps").build(); + let event = crate::event::Caps::new(&caps); + + let caps2 = match event.view() { + EventView::Caps(caps) => caps.caps(), + _ => unreachable!(), + }; + + assert_eq!(&*caps, caps2); + } } diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index a92fd8b41..405aba3cd 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -115,7 +115,7 @@ pub use crate::bufferlist::{BufferList, BufferListRef}; mod bufferlist_serde; pub mod query; -pub use crate::query::{Query, QueryRef, QueryView}; +pub use crate::query::{Query, QueryRef, QueryView, QueryViewMut}; pub mod event; pub use crate::event::{Event, EventRef, EventView, GroupId, Seqnum}; pub mod context; diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 5c862133e..ab033d3de 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -9,6 +9,7 @@ use crate::Object; use crate::Seqnum; use crate::TagList; +use std::borrow::Borrow; use std::ffi::CStr; use std::fmt; use std::mem; @@ -16,9 +17,7 @@ use std::num::NonZeroU32; use std::ops::Deref; use std::ptr; -use glib::translate::{ - from_glib, from_glib_full, from_glib_none, mut_override, try_from_glib, IntoGlib, ToGlibPtr, -}; +use glib::translate::*; mini_object_wrapper!(Message, MessageRef, ffi::GstMessage, || { ffi::gst_message_get_type() @@ -74,63 +73,58 @@ impl MessageRef { } pub fn view(&self) -> MessageView { - let type_ = unsafe { (*self.as_ptr()).type_ }; + unsafe { + let type_ = (*self.as_ptr()).type_; - match type_ { - ffi::GST_MESSAGE_EOS => MessageView::Eos(Eos(self)), - ffi::GST_MESSAGE_ERROR => MessageView::Error(Error(self)), - ffi::GST_MESSAGE_WARNING => MessageView::Warning(Warning(self)), - ffi::GST_MESSAGE_INFO => MessageView::Info(Info(self)), - ffi::GST_MESSAGE_TAG => MessageView::Tag(Tag(self)), - ffi::GST_MESSAGE_BUFFERING => MessageView::Buffering(Buffering(self)), - ffi::GST_MESSAGE_STATE_CHANGED => MessageView::StateChanged(StateChanged(self)), - ffi::GST_MESSAGE_STATE_DIRTY => MessageView::StateDirty(StateDirty(self)), - ffi::GST_MESSAGE_STEP_DONE => MessageView::StepDone(StepDone(self)), - ffi::GST_MESSAGE_CLOCK_PROVIDE => MessageView::ClockProvide(ClockProvide(self)), - ffi::GST_MESSAGE_CLOCK_LOST => MessageView::ClockLost(ClockLost(self)), - ffi::GST_MESSAGE_NEW_CLOCK => MessageView::NewClock(NewClock(self)), - ffi::GST_MESSAGE_STRUCTURE_CHANGE => { - MessageView::StructureChange(StructureChange(self)) + match type_ { + ffi::GST_MESSAGE_EOS => Eos::view(self), + ffi::GST_MESSAGE_ERROR => Error::view(self), + ffi::GST_MESSAGE_WARNING => Warning::view(self), + ffi::GST_MESSAGE_INFO => Info::view(self), + ffi::GST_MESSAGE_TAG => Tag::view(self), + ffi::GST_MESSAGE_BUFFERING => Buffering::view(self), + ffi::GST_MESSAGE_STATE_CHANGED => StateChanged::view(self), + ffi::GST_MESSAGE_STATE_DIRTY => StateDirty::view(self), + ffi::GST_MESSAGE_STEP_DONE => StepDone::view(self), + ffi::GST_MESSAGE_CLOCK_PROVIDE => ClockProvide::view(self), + ffi::GST_MESSAGE_CLOCK_LOST => ClockLost::view(self), + ffi::GST_MESSAGE_NEW_CLOCK => NewClock::view(self), + ffi::GST_MESSAGE_STRUCTURE_CHANGE => StructureChange::view(self), + ffi::GST_MESSAGE_STREAM_STATUS => StreamStatus::view(self), + ffi::GST_MESSAGE_APPLICATION => Application::view(self), + ffi::GST_MESSAGE_ELEMENT => Element::view(self), + ffi::GST_MESSAGE_SEGMENT_START => SegmentStart::view(self), + ffi::GST_MESSAGE_SEGMENT_DONE => SegmentDone::view(self), + ffi::GST_MESSAGE_DURATION_CHANGED => DurationChanged::view(self), + ffi::GST_MESSAGE_LATENCY => Latency::view(self), + ffi::GST_MESSAGE_ASYNC_START => AsyncStart::view(self), + ffi::GST_MESSAGE_ASYNC_DONE => AsyncDone::view(self), + ffi::GST_MESSAGE_REQUEST_STATE => RequestState::view(self), + ffi::GST_MESSAGE_STEP_START => StepStart::view(self), + ffi::GST_MESSAGE_QOS => Qos::view(self), + ffi::GST_MESSAGE_PROGRESS => Progress::view(self), + ffi::GST_MESSAGE_TOC => Toc::view(self), + ffi::GST_MESSAGE_RESET_TIME => ResetTime::view(self), + ffi::GST_MESSAGE_STREAM_START => StreamStart::view(self), + ffi::GST_MESSAGE_NEED_CONTEXT => NeedContext::view(self), + ffi::GST_MESSAGE_HAVE_CONTEXT => HaveContext::view(self), + ffi::GST_MESSAGE_DEVICE_ADDED => DeviceAdded::view(self), + ffi::GST_MESSAGE_DEVICE_REMOVED => DeviceRemoved::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] + ffi::GST_MESSAGE_REDIRECT => Redirect::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_MESSAGE_PROPERTY_NOTIFY => PropertyNotify::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_MESSAGE_STREAM_COLLECTION => StreamCollection::view(self), + #[cfg(any(feature = "v1_10", feature = "dox"))] + ffi::GST_MESSAGE_STREAMS_SELECTED => StreamsSelected::view(self), + #[cfg(any(feature = "v1_16", feature = "dox"))] + ffi::GST_MESSAGE_DEVICE_CHANGED => DeviceChanged::view(self), + #[cfg(any(feature = "v1_18", feature = "dox"))] + ffi::GST_MESSAGE_INSTANT_RATE_REQUEST => InstantRateRequest::view(self), + _ => MessageView::Other, } - ffi::GST_MESSAGE_STREAM_STATUS => MessageView::StreamStatus(StreamStatus(self)), - ffi::GST_MESSAGE_APPLICATION => MessageView::Application(Application(self)), - ffi::GST_MESSAGE_ELEMENT => MessageView::Element(Element(self)), - ffi::GST_MESSAGE_SEGMENT_START => MessageView::SegmentStart(SegmentStart(self)), - ffi::GST_MESSAGE_SEGMENT_DONE => MessageView::SegmentDone(SegmentDone(self)), - ffi::GST_MESSAGE_DURATION_CHANGED => { - MessageView::DurationChanged(DurationChanged(self)) - } - ffi::GST_MESSAGE_LATENCY => MessageView::Latency(Latency(self)), - ffi::GST_MESSAGE_ASYNC_START => MessageView::AsyncStart(AsyncStart(self)), - ffi::GST_MESSAGE_ASYNC_DONE => MessageView::AsyncDone(AsyncDone(self)), - ffi::GST_MESSAGE_REQUEST_STATE => MessageView::RequestState(RequestState(self)), - ffi::GST_MESSAGE_STEP_START => MessageView::StepStart(StepStart(self)), - ffi::GST_MESSAGE_QOS => MessageView::Qos(Qos(self)), - ffi::GST_MESSAGE_PROGRESS => MessageView::Progress(Progress(self)), - ffi::GST_MESSAGE_TOC => MessageView::Toc(Toc(self)), - ffi::GST_MESSAGE_RESET_TIME => MessageView::ResetTime(ResetTime(self)), - ffi::GST_MESSAGE_STREAM_START => MessageView::StreamStart(StreamStart(self)), - ffi::GST_MESSAGE_NEED_CONTEXT => MessageView::NeedContext(NeedContext(self)), - ffi::GST_MESSAGE_HAVE_CONTEXT => MessageView::HaveContext(HaveContext(self)), - ffi::GST_MESSAGE_DEVICE_ADDED => MessageView::DeviceAdded(DeviceAdded(self)), - ffi::GST_MESSAGE_DEVICE_REMOVED => MessageView::DeviceRemoved(DeviceRemoved(self)), - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_MESSAGE_PROPERTY_NOTIFY => MessageView::PropertyNotify(PropertyNotify(self)), - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_MESSAGE_STREAM_COLLECTION => { - MessageView::StreamCollection(StreamCollection(self)) - } - #[cfg(any(feature = "v1_10", feature = "dox"))] - ffi::GST_MESSAGE_STREAMS_SELECTED => { - MessageView::StreamsSelected(StreamsSelected(self)) - } - #[cfg(any(feature = "v1_16", feature = "dox"))] - ffi::GST_MESSAGE_DEVICE_CHANGED => MessageView::DeviceChanged(DeviceChanged(self)), - #[cfg(any(feature = "v1_18", feature = "dox"))] - ffi::GST_MESSAGE_INSTANT_RATE_REQUEST => { - MessageView::InstantRateRequest(InstantRateRequest(self)) - } - _ => MessageView::Other, } } @@ -183,77 +177,128 @@ impl fmt::Debug for MessageRef { #[derive(Debug)] #[non_exhaustive] pub enum MessageView<'a> { - Eos(Eos<'a>), - Error(Error<'a>), - Warning(Warning<'a>), - Info(Info<'a>), - Tag(Tag<'a>), - Buffering(Buffering<'a>), - StateChanged(StateChanged<'a>), - StateDirty(StateDirty<'a>), - StepDone(StepDone<'a>), - ClockProvide(ClockProvide<'a>), - ClockLost(ClockLost<'a>), - NewClock(NewClock<'a>), - StructureChange(StructureChange<'a>), - StreamStatus(StreamStatus<'a>), - Application(Application<'a>), - Element(Element<'a>), - SegmentStart(SegmentStart<'a>), - SegmentDone(SegmentDone<'a>), - DurationChanged(DurationChanged<'a>), - Latency(Latency<'a>), - AsyncStart(AsyncStart<'a>), - AsyncDone(AsyncDone<'a>), - RequestState(RequestState<'a>), - StepStart(StepStart<'a>), - Qos(Qos<'a>), - Progress(Progress<'a>), - Toc(Toc<'a>), - ResetTime(ResetTime<'a>), - StreamStart(StreamStart<'a>), - NeedContext(NeedContext<'a>), - HaveContext(HaveContext<'a>), - DeviceAdded(DeviceAdded<'a>), - DeviceRemoved(DeviceRemoved<'a>), + Eos(&'a Eos), + Error(&'a Error), + Warning(&'a Warning), + Info(&'a Info), + Tag(&'a Tag), + Buffering(&'a Buffering), + StateChanged(&'a StateChanged), + StateDirty(&'a StateDirty), + StepDone(&'a StepDone), + ClockProvide(&'a ClockProvide), + ClockLost(&'a ClockLost), + NewClock(&'a NewClock), + StructureChange(&'a StructureChange), + StreamStatus(&'a StreamStatus), + Application(&'a Application), + Element(&'a Element), + SegmentStart(&'a SegmentStart), + SegmentDone(&'a SegmentDone), + DurationChanged(&'a DurationChanged), + Latency(&'a Latency), + AsyncStart(&'a AsyncStart), + AsyncDone(&'a AsyncDone), + RequestState(&'a RequestState), + StepStart(&'a StepStart), + Qos(&'a Qos), + Progress(&'a Progress), + Toc(&'a Toc), + ResetTime(&'a ResetTime), + StreamStart(&'a StreamStart), + NeedContext(&'a NeedContext), + HaveContext(&'a HaveContext), + DeviceAdded(&'a DeviceAdded), + DeviceRemoved(&'a DeviceRemoved), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - PropertyNotify(PropertyNotify<'a>), + PropertyNotify(&'a PropertyNotify), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - StreamCollection(StreamCollection<'a>), + StreamCollection(&'a StreamCollection), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - StreamsSelected(StreamsSelected<'a>), + StreamsSelected(&'a StreamsSelected), #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - Redirect(Redirect<'a>), + Redirect(&'a Redirect), #[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] - DeviceChanged(DeviceChanged<'a>), + DeviceChanged(&'a DeviceChanged), #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] - InstantRateRequest(InstantRateRequest<'a>), + InstantRateRequest(&'a InstantRateRequest), Other, } macro_rules! declare_concrete_message( - ($name:ident) => { + ($name:ident, $param:ident) => { #[derive(Debug)] - pub struct $name<'a>(&'a MessageRef); + #[repr(transparent)] + pub struct $name<$param = MessageRef>($param); - impl<'a> Deref for $name<'a> { + impl $name { + pub fn message(&self) -> &MessageRef { + unsafe { &*(self as *const Self as *const MessageRef) } + } + + unsafe fn view(message: &MessageRef) -> MessageView<'_> { + let message = &*(message as *const MessageRef as *const Self); + MessageView::$name(message) + } + } + + impl Deref for $name { type Target = MessageRef; fn deref(&self) -> &Self::Target { - self.0 + unsafe { + &*(self as *const Self as *const Self::Target) + } + } + } + + impl ToOwned for $name { + type Owned = $name; + + fn to_owned(&self) -> Self::Owned { + $name::(self.copy()) + } + } + + impl $name { + pub fn get_mut(&mut self) -> Option<&mut $name> { + self.0.get_mut().map(|message| unsafe { + &mut *(message as *mut MessageRef as *mut $name) + }) + } + } + + impl Deref for $name { + type Target = $name; + + fn deref(&self) -> &Self::Target { + unsafe { &*(self.0.as_ptr() as *const Self::Target) } + } + } + + impl Borrow<$name> for $name { + fn borrow(&self) -> &$name { + &*self + } + } + + impl From<$name> for Message { + fn from(concrete: $name) -> Self { + skip_assert_initialized!(); + concrete.0 } } } ); -declare_concrete_message!(Eos); -impl<'a> Eos<'a> { +declare_concrete_message!(Eos, T); +impl Eos { #[doc(alias = "gst_message_new_eos")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -261,14 +306,14 @@ impl<'a> Eos<'a> { Self::builder().build() } - pub fn builder() -> EosBuilder<'a> { + pub fn builder<'a>() -> EosBuilder<'a> { assert_initialized_main_thread!(); EosBuilder::new() } } -declare_concrete_message!(Error); -impl<'a> Error<'a> { +declare_concrete_message!(Error, T); +impl Error { #[doc(alias = "gst_message_new_error")] #[allow(clippy::new_ret_no_self)] pub fn new(error: T, message: &str) -> Message { @@ -324,8 +369,8 @@ impl<'a> Error<'a> { } } -declare_concrete_message!(Warning); -impl<'a> Warning<'a> { +declare_concrete_message!(Warning, T); +impl Warning { #[doc(alias = "gst_message_new_warning")] #[allow(clippy::new_ret_no_self)] pub fn new(error: T, message: &str) -> Message { @@ -381,8 +426,8 @@ impl<'a> Warning<'a> { } } -declare_concrete_message!(Info); -impl<'a> Info<'a> { +declare_concrete_message!(Info, T); +impl Info { #[doc(alias = "gst_message_new_info")] #[allow(clippy::new_ret_no_self)] pub fn new(error: T, message: &str) -> Message { @@ -438,8 +483,8 @@ impl<'a> Info<'a> { } } -declare_concrete_message!(Tag); -impl<'a> Tag<'a> { +declare_concrete_message!(Tag, T); +impl Tag { #[doc(alias = "gst_message_new_tag")] #[allow(clippy::new_ret_no_self)] pub fn new(tags: &TagList) -> Message { @@ -463,8 +508,8 @@ impl<'a> Tag<'a> { } } -declare_concrete_message!(Buffering); -impl<'a> Buffering<'a> { +declare_concrete_message!(Buffering, T); +impl Buffering { #[doc(alias = "gst_message_new_buffering")] #[allow(clippy::new_ret_no_self)] pub fn new(percent: i32) -> Message { @@ -472,7 +517,7 @@ impl<'a> Buffering<'a> { Self::builder(percent).build() } - pub fn builder(percent: i32) -> BufferingBuilder<'a> { + pub fn builder<'a>(percent: i32) -> BufferingBuilder<'a> { assert_initialized_main_thread!(); BufferingBuilder::new(percent) } @@ -514,8 +559,8 @@ impl<'a> Buffering<'a> { } } -declare_concrete_message!(StateChanged); -impl<'a> StateChanged<'a> { +declare_concrete_message!(StateChanged, T); +impl StateChanged { #[doc(alias = "gst_message_new_state_changed")] #[allow(clippy::new_ret_no_self)] pub fn new(old: crate::State, new: crate::State, pending: crate::State) -> Message { @@ -523,7 +568,7 @@ impl<'a> StateChanged<'a> { Self::builder(old, new, pending).build() } - pub fn builder( + pub fn builder<'a>( old: crate::State, new: crate::State, pending: crate::State, @@ -584,8 +629,8 @@ impl<'a> StateChanged<'a> { } } -declare_concrete_message!(StateDirty); -impl<'a> StateDirty<'a> { +declare_concrete_message!(StateDirty, T); +impl StateDirty { #[doc(alias = "gst_message_new_state_dirty")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -593,14 +638,14 @@ impl<'a> StateDirty<'a> { Self::builder().build() } - pub fn builder() -> StateDirtyBuilder<'a> { + pub fn builder<'a>() -> StateDirtyBuilder<'a> { assert_initialized_main_thread!(); StateDirtyBuilder::new() } } -declare_concrete_message!(StepDone); -impl<'a> StepDone<'a> { +declare_concrete_message!(StepDone, T); +impl StepDone { #[doc(alias = "gst_message_new_step_done")] #[allow(clippy::new_ret_no_self)] pub fn new>( @@ -623,7 +668,7 @@ impl<'a> StepDone<'a> { .build() } - pub fn builder>( + pub fn builder<'a, V: Into>( amount: V, rate: f64, flush: bool, @@ -691,8 +736,8 @@ impl<'a> StepDone<'a> { } } -declare_concrete_message!(ClockProvide); -impl<'a> ClockProvide<'a> { +declare_concrete_message!(ClockProvide, T); +impl ClockProvide { #[doc(alias = "gst_message_new_clock_provide")] #[allow(clippy::new_ret_no_self)] pub fn new(clock: &crate::Clock, ready: bool) -> Message { @@ -734,8 +779,8 @@ impl<'a> ClockProvide<'a> { } } -declare_concrete_message!(ClockLost); -impl<'a> ClockLost<'a> { +declare_concrete_message!(ClockLost, T); +impl ClockLost { #[doc(alias = "gst_message_new_clock_lost")] #[allow(clippy::new_ret_no_self)] pub fn new(clock: &crate::Clock) -> Message { @@ -761,8 +806,8 @@ impl<'a> ClockLost<'a> { } } -declare_concrete_message!(NewClock); -impl<'a> NewClock<'a> { +declare_concrete_message!(NewClock, T); +impl NewClock { #[doc(alias = "gst_message_new_new_clock")] #[allow(clippy::new_ret_no_self)] pub fn new(clock: &crate::Clock) -> Message { @@ -788,8 +833,8 @@ impl<'a> NewClock<'a> { } } -declare_concrete_message!(StructureChange); -impl<'a> StructureChange<'a> { +declare_concrete_message!(StructureChange, T); +impl StructureChange { #[doc(alias = "gst_message_new_structure_change")] #[allow(clippy::new_ret_no_self)] pub fn new(type_: crate::StructureChangeType, owner: &crate::Element, busy: bool) -> Message { @@ -829,8 +874,8 @@ impl<'a> StructureChange<'a> { } } -declare_concrete_message!(StreamStatus); -impl<'a> StreamStatus<'a> { +declare_concrete_message!(StreamStatus, T); +impl StreamStatus { #[doc(alias = "gst_message_new_stream_status")] #[allow(clippy::new_ret_no_self)] pub fn new(type_: crate::StreamStatusType, owner: &crate::Element) -> Message { @@ -866,8 +911,8 @@ impl<'a> StreamStatus<'a> { } } -declare_concrete_message!(Application); -impl<'a> Application<'a> { +declare_concrete_message!(Application, T); +impl Application { #[doc(alias = "gst_message_new_application")] #[allow(clippy::new_ret_no_self)] pub fn new(structure: crate::Structure) -> Message { @@ -875,14 +920,14 @@ impl<'a> Application<'a> { Self::builder(structure).build() } - pub fn builder(structure: crate::Structure) -> ApplicationBuilder<'a> { + pub fn builder<'a>(structure: crate::Structure) -> ApplicationBuilder<'a> { assert_initialized_main_thread!(); ApplicationBuilder::new(structure) } } -declare_concrete_message!(Element); -impl<'a> Element<'a> { +declare_concrete_message!(Element, T); +impl Element { #[doc(alias = "gst_message_new_element")] #[allow(clippy::new_ret_no_self)] pub fn new(structure: crate::Structure) -> Message { @@ -890,14 +935,14 @@ impl<'a> Element<'a> { Self::builder(structure).build() } - pub fn builder(structure: crate::Structure) -> ElementBuilder<'a> { + pub fn builder<'a>(structure: crate::Structure) -> ElementBuilder<'a> { assert_initialized_main_thread!(); ElementBuilder::new(structure) } } -declare_concrete_message!(SegmentStart); -impl<'a> SegmentStart<'a> { +declare_concrete_message!(SegmentStart, T); +impl SegmentStart { #[doc(alias = "gst_message_new_segment_start")] #[allow(clippy::new_ret_no_self)] pub fn new>(position: V) -> Message { @@ -905,7 +950,7 @@ impl<'a> SegmentStart<'a> { Self::builder(position).build() } - pub fn builder>(position: V) -> SegmentStartBuilder<'a> { + pub fn builder<'a, V: Into>(position: V) -> SegmentStartBuilder<'a> { assert_initialized_main_thread!(); let position = position.into(); SegmentStartBuilder::new(position) @@ -928,8 +973,8 @@ impl<'a> SegmentStart<'a> { } } -declare_concrete_message!(SegmentDone); -impl<'a> SegmentDone<'a> { +declare_concrete_message!(SegmentDone, T); +impl SegmentDone { #[doc(alias = "gst_message_new_segment_done")] #[allow(clippy::new_ret_no_self)] pub fn new>(position: V) -> Message { @@ -937,7 +982,7 @@ impl<'a> SegmentDone<'a> { Self::builder(position).build() } - pub fn builder>(position: V) -> SegmentDoneBuilder<'a> { + pub fn builder<'a, V: Into>(position: V) -> SegmentDoneBuilder<'a> { assert_initialized_main_thread!(); let position = position.into(); SegmentDoneBuilder::new(position) @@ -960,8 +1005,8 @@ impl<'a> SegmentDone<'a> { } } -declare_concrete_message!(DurationChanged); -impl<'a> DurationChanged<'a> { +declare_concrete_message!(DurationChanged, T); +impl DurationChanged { #[doc(alias = "gst_message_new_duration_changed")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -969,14 +1014,14 @@ impl<'a> DurationChanged<'a> { Self::builder().build() } - pub fn builder() -> DurationChangedBuilder<'a> { + pub fn builder<'a>() -> DurationChangedBuilder<'a> { assert_initialized_main_thread!(); DurationChangedBuilder::new() } } -declare_concrete_message!(Latency); -impl<'a> Latency<'a> { +declare_concrete_message!(Latency, T); +impl Latency { #[doc(alias = "gst_message_new_latency")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -984,14 +1029,14 @@ impl<'a> Latency<'a> { Self::builder().build() } - pub fn builder() -> LatencyBuilder<'a> { + pub fn builder<'a>() -> LatencyBuilder<'a> { assert_initialized_main_thread!(); LatencyBuilder::new() } } -declare_concrete_message!(AsyncStart); -impl<'a> AsyncStart<'a> { +declare_concrete_message!(AsyncStart, T); +impl AsyncStart { #[doc(alias = "gst_message_new_async_start")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -999,14 +1044,14 @@ impl<'a> AsyncStart<'a> { Self::builder().build() } - pub fn builder() -> AsyncStartBuilder<'a> { + pub fn builder<'a>() -> AsyncStartBuilder<'a> { assert_initialized_main_thread!(); AsyncStartBuilder::new() } } -declare_concrete_message!(AsyncDone); -impl<'a> AsyncDone<'a> { +declare_concrete_message!(AsyncDone, T); +impl AsyncDone { #[doc(alias = "gst_message_new_async_done")] #[allow(clippy::new_ret_no_self)] pub fn new(running_time: impl Into>) -> Message { @@ -1014,7 +1059,7 @@ impl<'a> AsyncDone<'a> { Self::builder().running_time(running_time).build() } - pub fn builder() -> AsyncDoneBuilder<'a> { + pub fn builder<'a>() -> AsyncDoneBuilder<'a> { assert_initialized_main_thread!(); AsyncDoneBuilder::new() } @@ -1032,8 +1077,8 @@ impl<'a> AsyncDone<'a> { } } -declare_concrete_message!(RequestState); -impl<'a> RequestState<'a> { +declare_concrete_message!(RequestState, T); +impl RequestState { #[doc(alias = "gst_message_new_request_state")] #[allow(clippy::new_ret_no_self)] pub fn new(state: crate::State) -> Message { @@ -1041,7 +1086,7 @@ impl<'a> RequestState<'a> { Self::builder(state).build() } - pub fn builder(state: crate::State) -> RequestStateBuilder<'a> { + pub fn builder<'a>(state: crate::State) -> RequestStateBuilder<'a> { assert_initialized_main_thread!(); RequestStateBuilder::new(state) } @@ -1059,8 +1104,8 @@ impl<'a> RequestState<'a> { } } -declare_concrete_message!(StepStart); -impl<'a> StepStart<'a> { +declare_concrete_message!(StepStart, T); +impl StepStart { #[doc(alias = "gst_message_new_step_start")] #[allow(clippy::new_ret_no_self)] pub fn new>( @@ -1074,7 +1119,7 @@ impl<'a> StepStart<'a> { Self::builder(active, amount.into(), rate, flush, intermediate).build() } - pub fn builder>( + pub fn builder<'a, V: Into>( active: bool, amount: V, rate: f64, @@ -1119,8 +1164,8 @@ impl<'a> StepStart<'a> { } } -declare_concrete_message!(Qos); -impl<'a> Qos<'a> { +declare_concrete_message!(Qos, T); +impl Qos { #[doc(alias = "gst_message_new_qos")] #[allow(clippy::new_ret_no_self)] pub fn new( @@ -1139,7 +1184,7 @@ impl<'a> Qos<'a> { .build() } - pub fn builder(live: bool) -> QosBuilder<'a> { + pub fn builder<'a>(live: bool) -> QosBuilder<'a> { assert_initialized_main_thread!(); QosBuilder::new(live) } @@ -1232,16 +1277,16 @@ impl<'a> Qos<'a> { } } -declare_concrete_message!(Progress); -impl<'a> Progress<'a> { +declare_concrete_message!(Progress, T); +impl Progress { #[doc(alias = "gst_message_new_progress")] #[allow(clippy::new_ret_no_self)] - pub fn new(type_: crate::ProgressType, code: &'a str, text: &'a str) -> Message { + pub fn new(type_: crate::ProgressType, code: &str, text: &str) -> Message { skip_assert_initialized!(); Self::builder(type_, code, text).build() } - pub fn builder( + pub fn builder<'a>( type_: crate::ProgressType, code: &'a str, text: &'a str, @@ -1251,7 +1296,7 @@ impl<'a> Progress<'a> { } #[doc(alias = "gst_message_parse_progress")] - pub fn get(&self) -> (crate::ProgressType, &'a str, &'a str) { + pub fn get(&self) -> (crate::ProgressType, &str, &str) { unsafe { let mut type_ = mem::MaybeUninit::uninit(); let mut code = ptr::null_mut(); @@ -1272,8 +1317,8 @@ impl<'a> Progress<'a> { } } -declare_concrete_message!(Toc); -impl<'a> Toc<'a> { +declare_concrete_message!(Toc, T); +impl Toc { // FIXME could use false for updated as default // Even better: use an enum for updated so that it is more explicit than true / false #[doc(alias = "gst_message_new_toc")] @@ -1300,8 +1345,8 @@ impl<'a> Toc<'a> { } } -declare_concrete_message!(ResetTime); -impl<'a> ResetTime<'a> { +declare_concrete_message!(ResetTime, T); +impl ResetTime { #[doc(alias = "gst_message_new_reset_time")] #[allow(clippy::new_ret_no_self)] pub fn new(running_time: crate::ClockTime) -> Message { @@ -1309,7 +1354,7 @@ impl<'a> ResetTime<'a> { Self::builder(running_time).build() } - pub fn builder(running_time: crate::ClockTime) -> ResetTimeBuilder<'a> { + pub fn builder<'a>(running_time: crate::ClockTime) -> ResetTimeBuilder<'a> { assert_initialized_main_thread!(); ResetTimeBuilder::new(running_time) } @@ -1327,8 +1372,8 @@ impl<'a> ResetTime<'a> { } } -declare_concrete_message!(StreamStart); -impl<'a> StreamStart<'a> { +declare_concrete_message!(StreamStart, T); +impl StreamStart { #[doc(alias = "gst_message_new_stream_start")] #[allow(clippy::new_ret_no_self)] pub fn new() -> Message { @@ -1336,7 +1381,7 @@ impl<'a> StreamStart<'a> { Self::builder().build() } - pub fn builder() -> StreamStartBuilder<'a> { + pub fn builder<'a>() -> StreamStartBuilder<'a> { assert_initialized_main_thread!(); StreamStartBuilder::new() } @@ -1364,8 +1409,8 @@ impl<'a> StreamStart<'a> { } } -declare_concrete_message!(NeedContext); -impl<'a> NeedContext<'a> { +declare_concrete_message!(NeedContext, T); +impl NeedContext { #[doc(alias = "gst_message_new_need_context")] #[allow(clippy::new_ret_no_self)] pub fn new(context_type: &str) -> Message { @@ -1391,8 +1436,8 @@ impl<'a> NeedContext<'a> { } } -declare_concrete_message!(HaveContext); -impl<'a> HaveContext<'a> { +declare_concrete_message!(HaveContext, T); +impl HaveContext { #[doc(alias = "gst_message_new_have_context")] #[allow(clippy::new_ret_no_self)] pub fn new(context: crate::Context) -> Message { @@ -1400,7 +1445,7 @@ impl<'a> HaveContext<'a> { Self::builder(context).build() } - pub fn builder(context: crate::Context) -> HaveContextBuilder<'a> { + pub fn builder<'a>(context: crate::Context) -> HaveContextBuilder<'a> { assert_initialized_main_thread!(); HaveContextBuilder::new(context) } @@ -1416,8 +1461,8 @@ impl<'a> HaveContext<'a> { } } -declare_concrete_message!(DeviceAdded); -impl<'a> DeviceAdded<'a> { +declare_concrete_message!(DeviceAdded, T); +impl DeviceAdded { #[doc(alias = "gst_message_new_device_added")] #[allow(clippy::new_ret_no_self)] pub fn new(device: &crate::Device) -> Message { @@ -1443,8 +1488,8 @@ impl<'a> DeviceAdded<'a> { } } -declare_concrete_message!(DeviceRemoved); -impl<'a> DeviceRemoved<'a> { +declare_concrete_message!(DeviceRemoved, T); +impl DeviceRemoved { #[doc(alias = "gst_message_new_device_removed")] #[allow(clippy::new_ret_no_self)] pub fn new(device: &crate::Device) -> Message { @@ -1472,10 +1517,10 @@ impl<'a> DeviceRemoved<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -declare_concrete_message!(PropertyNotify); +declare_concrete_message!(PropertyNotify, T); #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl<'a> PropertyNotify<'a> { +impl PropertyNotify { #[doc(alias = "gst_message_new_property_notify")] #[allow(clippy::new_ret_no_self)] pub fn new(property_name: &str) -> Message { @@ -1489,7 +1534,7 @@ impl<'a> PropertyNotify<'a> { } #[doc(alias = "gst_message_parse_property_notify")] - pub fn get(&self) -> (Object, &str, Option<&'a glib::Value>) { + pub fn get(&self) -> (Object, &str, Option<&glib::Value>) { unsafe { let mut object = ptr::null_mut(); let mut property_name = ptr::null(); @@ -1517,10 +1562,10 @@ impl<'a> PropertyNotify<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -declare_concrete_message!(StreamCollection); +declare_concrete_message!(StreamCollection, T); #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl<'a> StreamCollection<'a> { +impl StreamCollection { #[doc(alias = "gst_message_new_stream_collection")] #[allow(clippy::new_ret_no_self)] pub fn new(collection: &crate::StreamCollection) -> Message { @@ -1548,10 +1593,10 @@ impl<'a> StreamCollection<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -declare_concrete_message!(StreamsSelected); +declare_concrete_message!(StreamsSelected, T); #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl<'a> StreamsSelected<'a> { +impl StreamsSelected { #[doc(alias = "gst_message_new_streams_selected")] #[allow(clippy::new_ret_no_self)] pub fn new(collection: &crate::StreamCollection) -> Message { @@ -1597,10 +1642,10 @@ impl<'a> StreamsSelected<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -declare_concrete_message!(Redirect); +declare_concrete_message!(Redirect, T); #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] -impl<'a> Redirect<'a> { +impl Redirect { #[doc(alias = "gst_message_new_redirect")] #[allow(clippy::new_ret_no_self)] pub fn new(location: &str) -> Message { @@ -1653,18 +1698,18 @@ impl<'a> Redirect<'a> { #[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] -declare_concrete_message!(DeviceChanged); +declare_concrete_message!(DeviceChanged, T); #[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] -impl<'a> DeviceChanged<'a> { +impl DeviceChanged { #[doc(alias = "gst_message_new_device_changed")] #[allow(clippy::new_ret_no_self)] - pub fn new(device: &'a crate::Device, changed_device: &'a crate::Device) -> Message { + pub fn new(device: &crate::Device, changed_device: &crate::Device) -> Message { skip_assert_initialized!(); Self::builder(device, changed_device).build() } - pub fn builder( + pub fn builder<'a>( device: &'a crate::Device, changed_device: &'a crate::Device, ) -> DeviceChangedBuilder<'a> { @@ -1692,10 +1737,10 @@ impl<'a> DeviceChanged<'a> { #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -declare_concrete_message!(InstantRateRequest); +declare_concrete_message!(InstantRateRequest, T); #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] -impl<'a> InstantRateRequest<'a> { +impl InstantRateRequest { #[doc(alias = "gst_message_new_instant_rate_request")] #[allow(clippy::new_ret_no_self)] pub fn new(rate_multiplier: f64) -> Message { @@ -1703,7 +1748,7 @@ impl<'a> InstantRateRequest<'a> { Self::builder(rate_multiplier).build() } - pub fn builder(rate_multiplier: f64) -> InstantRateRequestBuilder<'a> { + pub fn builder<'a>(rate_multiplier: f64) -> InstantRateRequestBuilder<'a> { assert_initialized_main_thread!(); InstantRateRequestBuilder::new(rate_multiplier) } diff --git a/gstreamer/src/pad.rs b/gstreamer/src/pad.rs index f7c4dd00d..eef3c3796 100644 --- a/gstreamer/src/pad.rs +++ b/gstreamer/src/pad.rs @@ -324,7 +324,7 @@ pub trait PadExtManual: 'static { #[doc(alias = "gst_pad_get_sticky_event")] #[doc(alias = "get_sticky_event")] - fn sticky_event(&self, idx: u32) -> Option; + fn sticky_event(&self, idx: u32) -> Option; fn set_pad_flags(&self, flags: PadFlags); @@ -1059,7 +1059,7 @@ impl> PadExtManual for O { } } - fn sticky_event(&self, idx: u32) -> Option { + fn sticky_event(&self, idx: u32) -> Option { unsafe { let ptr = ffi::gst_pad_get_sticky_event( self.as_ref().to_glib_none().0, @@ -2169,6 +2169,32 @@ mod tests { ); } + #[test] + fn test_sticky_events() { + crate::init().unwrap(); + + let pad = crate::Pad::builder(Some("sink"), crate::PadDirection::Sink).build(); + pad.set_active(true).unwrap(); + + // Send some sticky events + assert!(pad.send_event(crate::event::StreamStart::new("test"))); + + let caps = crate::Caps::builder("some/x-caps").build(); + assert!(pad.send_event(crate::event::Caps::new(&caps))); + + let segment = crate::FormattedSegment::::new(); + assert!(pad.send_event(crate::event::Segment::new(segment.as_ref()))); + + let stream_start = pad.sticky_event::(0).unwrap(); + assert_eq!(stream_start.stream_id(), "test"); + + let caps2 = pad.sticky_event::(0).unwrap(); + assert_eq!(&*caps, caps2.caps()); + + let segment = pad.sticky_event::(0).unwrap(); + assert_eq!(segment.segment().format(), crate::Format::Time); + } + #[test] fn test_sticky_events_foreach() { crate::init().unwrap(); diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 097ca8926..ca648ef5c 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -3,6 +3,7 @@ use crate::structure::*; use crate::GenericFormattedValue; +use std::borrow::{Borrow, BorrowMut}; use std::ffi::CStr; use std::fmt; use std::mem; @@ -54,33 +55,58 @@ impl QueryRef { unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_SERIALIZED != 0 } } - pub fn view(&self) -> QueryView<&Self> { - let type_ = unsafe { (*self.as_ptr()).type_ }; + pub fn view(&self) -> QueryView { + unsafe { + let type_ = (*self.as_ptr()).type_; - match type_ { - ffi::GST_QUERY_POSITION => QueryView::Position(Position(self)), - ffi::GST_QUERY_DURATION => QueryView::Duration(Duration(self)), - ffi::GST_QUERY_LATENCY => QueryView::Latency(Latency(self)), - ffi::GST_QUERY_SEEKING => QueryView::Seeking(Seeking(self)), - ffi::GST_QUERY_SEGMENT => QueryView::Segment(Segment(self)), - ffi::GST_QUERY_CONVERT => QueryView::Convert(Convert(self)), - ffi::GST_QUERY_FORMATS => QueryView::Formats(Formats(self)), - ffi::GST_QUERY_BUFFERING => QueryView::Buffering(Buffering(self)), - ffi::GST_QUERY_CUSTOM => QueryView::Custom(Custom(self)), - ffi::GST_QUERY_URI => QueryView::Uri(Uri(self)), - ffi::GST_QUERY_ALLOCATION => QueryView::Allocation(Allocation(self)), - ffi::GST_QUERY_SCHEDULING => QueryView::Scheduling(Scheduling(self)), - ffi::GST_QUERY_ACCEPT_CAPS => QueryView::AcceptCaps(AcceptCaps(self)), - ffi::GST_QUERY_CAPS => QueryView::Caps(Caps(self)), - ffi::GST_QUERY_DRAIN => QueryView::Drain(Drain(self)), - ffi::GST_QUERY_CONTEXT => QueryView::Context(Context(self)), - ffi::GST_QUERY_BITRATE => QueryView::Bitrate(Bitrate(self)), - _ => QueryView::Other(Other(self)), + match type_ { + ffi::GST_QUERY_POSITION => Position::view(self), + ffi::GST_QUERY_DURATION => Duration::view(self), + ffi::GST_QUERY_LATENCY => Latency::view(self), + ffi::GST_QUERY_SEEKING => Seeking::view(self), + ffi::GST_QUERY_SEGMENT => Segment::view(self), + ffi::GST_QUERY_CONVERT => Convert::view(self), + ffi::GST_QUERY_FORMATS => Formats::view(self), + ffi::GST_QUERY_BUFFERING => Buffering::view(self), + ffi::GST_QUERY_CUSTOM => Custom::view(self), + ffi::GST_QUERY_URI => Uri::view(self), + ffi::GST_QUERY_ALLOCATION => Allocation::view(self), + ffi::GST_QUERY_SCHEDULING => Scheduling::view(self), + ffi::GST_QUERY_ACCEPT_CAPS => AcceptCaps::view(self), + ffi::GST_QUERY_CAPS => Caps::view(self), + ffi::GST_QUERY_DRAIN => Drain::view(self), + ffi::GST_QUERY_CONTEXT => Context::view(self), + ffi::GST_QUERY_BITRATE => Bitrate::view(self), + _ => Other::view(self), + } } } - pub fn view_mut(&mut self) -> QueryView<&mut Self> { - unsafe { mem::transmute(self.view()) } + pub fn view_mut(&mut self) -> QueryViewMut { + unsafe { + let type_ = (*self.as_ptr()).type_; + + match type_ { + ffi::GST_QUERY_POSITION => Position::view_mut(self), + ffi::GST_QUERY_DURATION => Duration::view_mut(self), + ffi::GST_QUERY_LATENCY => Latency::view_mut(self), + ffi::GST_QUERY_SEEKING => Seeking::view_mut(self), + ffi::GST_QUERY_SEGMENT => Segment::view_mut(self), + ffi::GST_QUERY_CONVERT => Convert::view_mut(self), + ffi::GST_QUERY_FORMATS => Formats::view_mut(self), + ffi::GST_QUERY_BUFFERING => Buffering::view_mut(self), + ffi::GST_QUERY_CUSTOM => Custom::view_mut(self), + ffi::GST_QUERY_URI => Uri::view_mut(self), + ffi::GST_QUERY_ALLOCATION => Allocation::view_mut(self), + ffi::GST_QUERY_SCHEDULING => Scheduling::view_mut(self), + ffi::GST_QUERY_ACCEPT_CAPS => AcceptCaps::view_mut(self), + ffi::GST_QUERY_CAPS => Caps::view_mut(self), + ffi::GST_QUERY_DRAIN => Drain::view_mut(self), + ffi::GST_QUERY_CONTEXT => Context::view_mut(self), + ffi::GST_QUERY_BITRATE => Bitrate::view_mut(self), + _ => Other::view_mut(self), + } + } } } @@ -103,113 +129,132 @@ impl fmt::Debug for QueryRef { } } -pub unsafe trait AsPtr { - unsafe fn as_ptr(&self) -> *mut ffi::GstQuery; -} - -pub unsafe trait AsMutPtr: AsPtr { - unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery; -} - -unsafe impl AsPtr for Query { - unsafe fn as_ptr(&self) -> *mut ffi::GstQuery { - QueryRef::as_ptr(self) as *mut ffi::GstQuery - } -} - -unsafe impl AsMutPtr for Query { - unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery { - QueryRef::as_ptr(self) as *mut ffi::GstQuery - } -} - -unsafe impl<'a> AsPtr for &'a QueryRef { - unsafe fn as_ptr(&self) -> *mut ffi::GstQuery { - QueryRef::as_ptr(self) as *mut ffi::GstQuery - } -} - -unsafe impl<'a> AsPtr for &'a mut QueryRef { - unsafe fn as_ptr(&self) -> *mut ffi::GstQuery { - QueryRef::as_ptr(self) as *mut ffi::GstQuery - } -} - -unsafe impl<'a> AsMutPtr for &'a mut QueryRef { - unsafe fn as_mut_ptr(&self) -> *mut ffi::GstQuery { - QueryRef::as_ptr(self) as *mut ffi::GstQuery - } +#[derive(Debug)] +#[non_exhaustive] +pub enum QueryView<'a> { + Position(&'a Position), + Duration(&'a Duration), + Latency(&'a Latency), + Seeking(&'a Seeking), + Segment(&'a Segment), + Convert(&'a Convert), + Formats(&'a Formats), + Buffering(&'a Buffering), + Custom(&'a Custom), + Uri(&'a Uri), + Allocation(&'a Allocation), + Scheduling(&'a Scheduling), + AcceptCaps(&'a AcceptCaps), + Caps(&'a Caps), + Drain(&'a Drain), + Context(&'a Context), + Bitrate(&'a Bitrate), + Other(&'a Other), } #[derive(Debug)] #[non_exhaustive] -pub enum QueryView { - Position(Position), - Duration(Duration), - Latency(Latency), - Seeking(Seeking), - Segment(Segment), - Convert(Convert), - Formats(Formats), - Buffering(Buffering), - Custom(Custom), - Uri(Uri), - Allocation(Allocation), - Scheduling(Scheduling), - AcceptCaps(AcceptCaps), - Caps(Caps), - Drain(Drain), - Context(Context), - Bitrate(Bitrate), - Other(Other), +pub enum QueryViewMut<'a> { + Position(&'a mut Position), + Duration(&'a mut Duration), + Latency(&'a mut Latency), + Seeking(&'a mut Seeking), + Segment(&'a mut Segment), + Convert(&'a mut Convert), + Formats(&'a mut Formats), + Buffering(&'a mut Buffering), + Custom(&'a mut Custom), + Uri(&'a mut Uri), + Allocation(&'a mut Allocation), + Scheduling(&'a mut Scheduling), + AcceptCaps(&'a mut AcceptCaps), + Caps(&'a mut Caps), + Drain(&'a mut Drain), + Context(&'a mut Context), + Bitrate(&'a mut Bitrate), + Other(&'a mut Other), } macro_rules! declare_concrete_query( ($name:ident, $param:ident) => { #[derive(Debug)] - pub struct $name<$param>($param); + #[repr(transparent)] + pub struct $name<$param = QueryRef>($param); - impl<'a> $name<&'a QueryRef> { + impl $name { pub fn query(&self) -> &QueryRef { - self.0 + unsafe { &*(self as *const Self as *const QueryRef) } + } + + pub fn query_mut(&mut self) -> &mut QueryRef { + unsafe { &mut *(self as *mut Self as *mut QueryRef) } + } + + unsafe fn view(query: &QueryRef) -> QueryView<'_> { + let query = &*(query as *const QueryRef as *const Self); + QueryView::$name(query) + } + + unsafe fn view_mut(query: &mut QueryRef) -> QueryViewMut<'_> { + let query = &mut *(query as *mut QueryRef as *mut Self); + QueryViewMut::$name(query) } } - impl<'a> Deref for $name<&'a QueryRef> { + impl Deref for $name { type Target = QueryRef; fn deref(&self) -> &Self::Target { - self.0 + self.query() } } - impl<'a> Deref for $name<&'a mut QueryRef> { - type Target = $name<&'a QueryRef>; - - fn deref(&self) -> &Self::Target { - unsafe { - &*(self as *const $name<&'a mut QueryRef> as *const $name<&'a QueryRef>) - } + impl DerefMut for $name { + fn deref_mut(&mut self) -> &mut Self::Target { + self.query_mut() } } - impl<'a> $name<&'a mut QueryRef> { - pub fn query_mut(&mut self) -> &mut QueryRef { + impl ToOwned for $name { + type Owned = $name; + + fn to_owned(&self) -> Self::Owned { + $name::(self.copy()) + } + } + + impl $name { + pub fn get_mut(&mut self) -> Option<&mut $name> { self.0 + .get_mut() + .map(|query| unsafe { &mut *(query as *mut QueryRef as *mut $name) }) } } impl Deref for $name { - type Target = QueryRef; + type Target = $name; fn deref(&self) -> &Self::Target { - &self.0 + unsafe { &*(self.0.as_ptr() as *const Self::Target) } } } impl DerefMut for $name { fn deref_mut(&mut self) -> &mut Self::Target { - self.0.get_mut().unwrap() + assert!(self.0.is_writable()); + unsafe { &mut *(self.0.as_mut_ptr() as *mut Self::Target) } + } + } + + impl Borrow<$name> for $name { + fn borrow(&self) -> &$name { + &*self + } + } + + impl BorrowMut<$name> for $name { + fn borrow_mut(&mut self) -> &mut $name { + &mut *self } } @@ -231,7 +276,7 @@ impl Position { } } -impl Position { +impl Position { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_position")] pub fn result(&self) -> GenericFormattedValue { @@ -239,7 +284,7 @@ impl Position { let mut fmt = mem::MaybeUninit::uninit(); let mut pos = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_position(self.0.as_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr()); + ffi::gst_query_parse_position(self.as_mut_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr()); GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init()) } @@ -251,20 +296,18 @@ impl Position { unsafe { let mut fmt = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_position(self.0.as_ptr(), fmt.as_mut_ptr(), ptr::null_mut()); + ffi::gst_query_parse_position(self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut()); from_glib(fmt.assume_init()) } } -} -impl Position { #[doc(alias = "gst_query_set_position")] pub fn set>(&mut self, pos: V) { let pos = pos.into(); assert_eq!(pos.format(), self.format()); unsafe { - ffi::gst_query_set_position(self.0.as_mut_ptr(), pos.format().into_glib(), pos.value()); + ffi::gst_query_set_position(self.as_mut_ptr(), pos.format().into_glib(), pos.value()); } } } @@ -278,7 +321,7 @@ impl Duration { } } -impl Duration { +impl Duration { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_duration")] pub fn result(&self) -> GenericFormattedValue { @@ -286,7 +329,7 @@ impl Duration { let mut fmt = mem::MaybeUninit::uninit(); let mut pos = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_duration(self.0.as_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr()); + ffi::gst_query_parse_duration(self.as_mut_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr()); GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init()) } @@ -298,20 +341,18 @@ impl Duration { unsafe { let mut fmt = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_duration(self.0.as_ptr(), fmt.as_mut_ptr(), ptr::null_mut()); + ffi::gst_query_parse_duration(self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut()); from_glib(fmt.assume_init()) } } -} -impl Duration { #[doc(alias = "gst_query_set_duration")] pub fn set>(&mut self, dur: V) { let dur = dur.into(); assert_eq!(dur.format(), self.format()); unsafe { - ffi::gst_query_set_duration(self.0.as_mut_ptr(), dur.format().into_glib(), dur.value()); + ffi::gst_query_set_duration(self.as_mut_ptr(), dur.format().into_glib(), dur.value()); } } } @@ -331,7 +372,7 @@ impl Default for Latency { } } -impl Latency { +impl Latency { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_latency")] pub fn result(&self) -> (bool, crate::ClockTime, Option) { @@ -341,7 +382,7 @@ impl Latency { let mut max = mem::MaybeUninit::uninit(); ffi::gst_query_parse_latency( - self.0.as_ptr(), + self.as_mut_ptr(), live.as_mut_ptr(), min.as_mut_ptr(), max.as_mut_ptr(), @@ -354,9 +395,7 @@ impl Latency { ) } } -} -impl Latency { #[doc(alias = "gst_query_set_latency")] pub fn set( &mut self, @@ -366,7 +405,7 @@ impl Latency { ) { unsafe { ffi::gst_query_set_latency( - self.0.as_mut_ptr(), + self.as_mut_ptr(), live.into_glib(), min.into_glib(), max.into().into_glib(), @@ -384,7 +423,7 @@ impl Seeking { } } -impl Seeking { +impl Seeking { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_seeking")] pub fn result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) { @@ -394,7 +433,7 @@ impl Seeking { let mut start = mem::MaybeUninit::uninit(); let mut end = mem::MaybeUninit::uninit(); ffi::gst_query_parse_seeking( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), seekable.as_mut_ptr(), start.as_mut_ptr(), @@ -415,7 +454,7 @@ impl Seeking { unsafe { let mut fmt = mem::MaybeUninit::uninit(); ffi::gst_query_parse_seeking( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), @@ -425,9 +464,7 @@ impl Seeking { from_glib(fmt.assume_init()) } } -} -impl Seeking { #[doc(alias = "gst_query_set_seeking")] pub fn set>(&mut self, seekable: bool, start: V, end: V) { let start = start.into(); @@ -438,7 +475,7 @@ impl Seeking { unsafe { ffi::gst_query_set_seeking( - self.0.as_mut_ptr(), + self.as_mut_ptr(), start.format().into_glib(), seekable.into_glib(), start.value(), @@ -457,7 +494,7 @@ impl Segment { } } -impl Segment { +impl Segment { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_segment")] pub fn result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) { @@ -468,7 +505,7 @@ impl Segment { let mut stop = mem::MaybeUninit::uninit(); ffi::gst_query_parse_segment( - self.0.as_ptr(), + self.as_mut_ptr(), rate.as_mut_ptr(), fmt.as_mut_ptr(), start.as_mut_ptr(), @@ -489,7 +526,7 @@ impl Segment { let mut fmt = mem::MaybeUninit::uninit(); ffi::gst_query_parse_segment( - self.0.as_ptr(), + self.as_mut_ptr(), ptr::null_mut(), fmt.as_mut_ptr(), ptr::null_mut(), @@ -498,9 +535,7 @@ impl Segment { from_glib(fmt.assume_init()) } } -} -impl Segment { #[doc(alias = "gst_query_set_segment")] pub fn set>(&mut self, rate: f64, start: V, stop: V) { let start = start.into(); @@ -510,7 +545,7 @@ impl Segment { unsafe { ffi::gst_query_set_segment( - self.0.as_mut_ptr(), + self.as_mut_ptr(), rate, start.format().into_glib(), start.value(), @@ -536,7 +571,7 @@ impl Convert { } } -impl Convert { +impl Convert { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_convert")] pub fn result(&self) -> (GenericFormattedValue, GenericFormattedValue) { @@ -547,7 +582,7 @@ impl Convert { let mut dest = mem::MaybeUninit::uninit(); ffi::gst_query_parse_convert( - self.0.as_ptr(), + self.as_mut_ptr(), src_fmt.as_mut_ptr(), src.as_mut_ptr(), dest_fmt.as_mut_ptr(), @@ -568,7 +603,7 @@ impl Convert { let mut dest_fmt = mem::MaybeUninit::uninit(); ffi::gst_query_parse_convert( - self.0.as_ptr(), + self.as_mut_ptr(), src_fmt.as_mut_ptr(), src.as_mut_ptr(), dest_fmt.as_mut_ptr(), @@ -580,9 +615,7 @@ impl Convert { ) } } -} -impl Convert { #[doc(alias = "gst_query_set_convert")] pub fn set>(&mut self, src: V, dest: V) { let src = src.into(); @@ -590,7 +623,7 @@ impl Convert { unsafe { ffi::gst_query_set_convert( - self.0.as_mut_ptr(), + self.as_mut_ptr(), src.format().into_glib(), src.value(), dest.format().into_glib(), @@ -615,35 +648,33 @@ impl Default for Formats { } } -impl Formats { +impl Formats { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_n_formats")] #[doc(alias = "gst_query_parse_nth_format")] pub fn result(&self) -> Vec { unsafe { let mut n = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_n_formats(self.0.as_ptr(), n.as_mut_ptr()); + ffi::gst_query_parse_n_formats(self.as_mut_ptr(), n.as_mut_ptr()); let n = n.assume_init(); let mut res = Vec::with_capacity(n as usize); for i in 0..n { let mut fmt = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_nth_format(self.0.as_ptr(), i, fmt.as_mut_ptr()); + ffi::gst_query_parse_nth_format(self.as_mut_ptr(), i, fmt.as_mut_ptr()); res.push(from_glib(fmt.assume_init())); } res } } -} -impl Formats { #[doc(alias = "gst_query_set_formats")] #[doc(alias = "gst_query_set_formatsv")] pub fn set(&mut self, formats: &[crate::Format]) { unsafe { let v: Vec<_> = formats.iter().map(|f| f.into_glib()).collect(); - ffi::gst_query_set_formatsv(self.0.as_mut_ptr(), v.len() as i32, v.as_ptr() as *mut _); + ffi::gst_query_set_formatsv(self.as_mut_ptr(), v.len() as i32, v.as_ptr() as *mut _); } } } @@ -661,7 +692,7 @@ impl Buffering { } } -impl Buffering { +impl Buffering { #[doc(alias = "get_format")] #[doc(alias = "gst_query_parse_buffering_range")] pub fn format(&self) -> crate::Format { @@ -669,7 +700,7 @@ impl Buffering { let mut fmt = mem::MaybeUninit::uninit(); ffi::gst_query_parse_buffering_range( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), @@ -688,7 +719,7 @@ impl Buffering { let mut percent = mem::MaybeUninit::uninit(); ffi::gst_query_parse_buffering_percent( - self.0.as_ptr(), + self.as_mut_ptr(), busy.as_mut_ptr(), percent.as_mut_ptr(), ); @@ -707,7 +738,7 @@ impl Buffering { let mut estimated_total = mem::MaybeUninit::uninit(); ffi::gst_query_parse_buffering_range( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), start.as_mut_ptr(), stop.as_mut_ptr(), @@ -731,7 +762,7 @@ impl Buffering { let mut buffering_left = mem::MaybeUninit::uninit(); ffi::gst_query_parse_buffering_stats( - self.0.as_ptr(), + self.as_mut_ptr(), mode.as_mut_ptr(), avg_in.as_mut_ptr(), avg_out.as_mut_ptr(), @@ -754,7 +785,7 @@ impl Buffering { unsafe { let mut fmt = mem::MaybeUninit::uninit(); ffi::gst_query_parse_buffering_range( - self.0.as_ptr(), + self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), @@ -762,13 +793,13 @@ impl Buffering { ); let fmt = from_glib(fmt.assume_init()); - let n = ffi::gst_query_get_n_buffering_ranges(self.0.as_ptr()); + let n = ffi::gst_query_get_n_buffering_ranges(self.as_mut_ptr()); let mut res = Vec::with_capacity(n as usize); for i in 0..n { let mut start = mem::MaybeUninit::uninit(); let mut stop = mem::MaybeUninit::uninit(); let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range( - self.0.as_ptr(), + self.as_mut_ptr(), i, start.as_mut_ptr(), stop.as_mut_ptr(), @@ -784,13 +815,11 @@ impl Buffering { res } } -} -impl Buffering { #[doc(alias = "gst_query_set_buffering_percent")] pub fn set_percent(&mut self, busy: bool, percent: i32) { unsafe { - ffi::gst_query_set_buffering_percent(self.0.as_mut_ptr(), busy.into_glib(), percent); + ffi::gst_query_set_buffering_percent(self.as_mut_ptr(), busy.into_glib(), percent); } } @@ -809,7 +838,7 @@ impl Buffering { unsafe { ffi::gst_query_set_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), start.format().into_glib(), start.value(), stop.value(), @@ -829,7 +858,7 @@ impl Buffering { skip_assert_initialized!(); unsafe { ffi::gst_query_set_buffering_stats( - self.0.as_mut_ptr(), + self.as_mut_ptr(), mode.into_glib(), avg_in, avg_out, @@ -851,11 +880,7 @@ impl Buffering { let stop = stop.into(); assert_eq!(start.format(), fmt); assert_eq!(stop.format(), fmt); - ffi::gst_query_add_buffering_range( - self.0.as_mut_ptr(), - start.value(), - stop.value(), - ); + ffi::gst_query_add_buffering_range(self.as_mut_ptr(), start.value(), stop.value()); } } } @@ -890,13 +915,13 @@ impl Default for Uri { } } -impl Uri { +impl Uri { #[doc(alias = "get_uri")] #[doc(alias = "gst_query_parse_uri")] pub fn uri(&self) -> Option { unsafe { let mut uri = ptr::null_mut(); - ffi::gst_query_parse_uri(self.0.as_ptr(), &mut uri); + ffi::gst_query_parse_uri(self.as_mut_ptr(), &mut uri); from_glib_full(uri) } } @@ -907,20 +932,21 @@ impl Uri { pub fn redirection(&self) -> (Option, bool) { unsafe { let mut uri = ptr::null_mut(); - ffi::gst_query_parse_uri_redirection(self.0.as_ptr(), &mut uri); + ffi::gst_query_parse_uri_redirection(self.as_mut_ptr(), &mut uri); let mut permanent = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_uri_redirection_permanent(self.0.as_ptr(), permanent.as_mut_ptr()); + ffi::gst_query_parse_uri_redirection_permanent( + self.as_mut_ptr(), + permanent.as_mut_ptr(), + ); (from_glib_full(uri), from_glib(permanent.assume_init())) } } -} -impl Uri { #[doc(alias = "gst_query_set_uri")] pub fn set_uri(&mut self, uri: &str) { unsafe { - ffi::gst_query_set_uri(self.0.as_mut_ptr(), uri.to_glib_none().0); + ffi::gst_query_set_uri(self.as_mut_ptr(), uri.to_glib_none().0); } } @@ -928,7 +954,7 @@ impl Uri { #[doc(alias = "gst_query_set_uri_redirection_permanent")] pub fn set_redirection(&mut self, uri: &str, permanent: bool) { unsafe { - ffi::gst_query_set_uri_redirection(self.0.as_mut_ptr(), uri.to_glib_none().0); + ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0); ffi::gst_query_set_uri_redirection_permanent( self.0.as_mut_ptr(), permanent.into_glib(), @@ -951,14 +977,14 @@ impl Allocation { } } -impl Allocation { +impl Allocation { #[doc(alias = "gst_query_parse_allocation")] pub fn get(&self) -> (&crate::CapsRef, bool) { unsafe { let mut caps = ptr::null_mut(); let mut need_pool = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_allocation(self.0.as_ptr(), &mut caps, need_pool.as_mut_ptr()); + ffi::gst_query_parse_allocation(self.as_mut_ptr(), &mut caps, need_pool.as_mut_ptr()); ( crate::CapsRef::from_ptr(caps), from_glib(need_pool.assume_init()), @@ -979,13 +1005,13 @@ impl Allocation { #[doc(alias = "gst_query_parse_nth_allocation_param")] pub fn allocation_params(&self) -> Vec<(Option, crate::AllocationParams)> { unsafe { - let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr()); let mut params = Vec::with_capacity(n as usize); for i in 0..n { let mut allocator = ptr::null_mut(); let mut p = mem::MaybeUninit::uninit(); ffi::gst_query_parse_nth_allocation_param( - self.0.as_ptr(), + self.as_mut_ptr(), i, &mut allocator, p.as_mut_ptr(), @@ -1002,7 +1028,7 @@ impl Allocation { #[doc(alias = "gst_query_parse_nth_allocation_pool")] pub fn allocation_pools(&self) -> Vec<(Option, u32, u32, u32)> { unsafe { - let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr()); let mut pools = Vec::with_capacity(n as usize); for i in 0..n { let mut pool = ptr::null_mut(); @@ -1011,7 +1037,7 @@ impl Allocation { let mut max_buffers = mem::MaybeUninit::uninit(); ffi::gst_query_parse_nth_allocation_pool( - self.0.as_ptr(), + self.0.as_mut_ptr(), i, &mut pool, size.as_mut_ptr(), @@ -1035,13 +1061,13 @@ impl Allocation { #[doc(alias = "gst_query_parse_nth_allocation_meta")] pub fn allocation_metas(&self) -> Vec<(glib::Type, Option<&crate::StructureRef>)> { unsafe { - let n = ffi::gst_query_get_n_allocation_metas(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_metas(self.0.as_mut_ptr()); let mut metas = Vec::with_capacity(n as usize); for i in 0..n { let mut structure = ptr::null(); let api = - ffi::gst_query_parse_nth_allocation_meta(self.0.as_ptr(), i, &mut structure); + ffi::gst_query_parse_nth_allocation_meta(self.as_mut_ptr(), i, &mut structure); metas.push(( from_glib(api), if structure.is_null() { @@ -1061,7 +1087,7 @@ impl Allocation { unsafe { let mut idx = mem::MaybeUninit::uninit(); if ffi::gst_query_find_allocation_meta( - self.0.as_ptr(), + self.as_mut_ptr(), U::meta_api().into_glib(), idx.as_mut_ptr(), ) != glib::ffi::GFALSE @@ -1072,9 +1098,7 @@ impl Allocation { } } } -} -impl Allocation { #[doc(alias = "gst_query_add_allocation_pool")] pub fn add_allocation_pool( &mut self, @@ -1085,7 +1109,7 @@ impl Allocation { ) { unsafe { ffi::gst_query_add_allocation_pool( - self.0.as_mut_ptr(), + self.as_mut_ptr(), pool.to_glib_none().0 as *mut ffi::GstBufferPool, size, min_buffers, @@ -1104,10 +1128,10 @@ impl Allocation { max_buffers: u32, ) { unsafe { - let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr()); assert!(idx < n); ffi::gst_query_set_nth_allocation_pool( - self.0.as_mut_ptr(), + self.as_mut_ptr(), idx, pool.to_glib_none().0 as *mut ffi::GstBufferPool, size, @@ -1120,9 +1144,9 @@ impl Allocation { #[doc(alias = "gst_query_remove_nth_allocation_pool")] pub fn remove_nth_allocation_pool(&mut self, idx: u32) { unsafe { - let n = ffi::gst_query_get_n_allocation_pools(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr()); assert!(idx < n); - ffi::gst_query_remove_nth_allocation_pool(self.0.as_mut_ptr(), idx); + ffi::gst_query_remove_nth_allocation_pool(self.as_mut_ptr(), idx); } } @@ -1134,7 +1158,7 @@ impl Allocation { ) { unsafe { ffi::gst_query_add_allocation_param( - self.0.as_mut_ptr(), + self.as_mut_ptr(), allocator.to_glib_none().0 as *mut ffi::GstAllocator, params.as_ptr(), ); @@ -1149,10 +1173,10 @@ impl Allocation { params: crate::AllocationParams, ) { unsafe { - let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr()); assert!(idx < n); ffi::gst_query_set_nth_allocation_param( - self.0.as_mut_ptr(), + self.as_mut_ptr(), idx, allocator.to_glib_none().0 as *mut ffi::GstAllocator, params.as_ptr(), @@ -1163,9 +1187,9 @@ impl Allocation { #[doc(alias = "gst_query_remove_nth_allocation_param")] pub fn remove_nth_allocation_param(&mut self, idx: u32) { unsafe { - let n = ffi::gst_query_get_n_allocation_params(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr()); assert!(idx < n); - ffi::gst_query_remove_nth_allocation_param(self.0.as_mut_ptr(), idx); + ffi::gst_query_remove_nth_allocation_param(self.as_mut_ptr(), idx); } } @@ -1176,7 +1200,7 @@ impl Allocation { ) { unsafe { ffi::gst_query_add_allocation_meta( - self.0.as_mut_ptr(), + self.as_mut_ptr(), U::meta_api().into_glib(), if let Some(structure) = structure { structure.as_ptr() @@ -1190,9 +1214,9 @@ impl Allocation { #[doc(alias = "gst_query_remove_nth_allocation_meta")] pub fn remove_nth_allocation_meta(&mut self, idx: u32) { unsafe { - let n = ffi::gst_query_get_n_allocation_metas(self.0.as_ptr()); + let n = ffi::gst_query_get_n_allocation_metas(self.as_mut_ptr()); assert!(idx < n); - ffi::gst_query_remove_nth_allocation_meta(self.0.as_mut_ptr(), idx); + ffi::gst_query_remove_nth_allocation_meta(self.as_mut_ptr(), idx); } } } @@ -1212,12 +1236,12 @@ impl Default for Scheduling { } } -impl Scheduling { +impl Scheduling { #[doc(alias = "gst_query_has_scheduling_mode")] pub fn has_scheduling_mode(&self, mode: crate::PadMode) -> bool { unsafe { from_glib(ffi::gst_query_has_scheduling_mode( - self.0.as_ptr(), + self.as_mut_ptr(), mode.into_glib(), )) } @@ -1232,7 +1256,7 @@ impl Scheduling { skip_assert_initialized!(); unsafe { from_glib(ffi::gst_query_has_scheduling_mode_with_flags( - self.0.as_ptr(), + self.as_mut_ptr(), mode.into_glib(), flags.into_glib(), )) @@ -1243,11 +1267,11 @@ impl Scheduling { #[doc(alias = "gst_query_get_n_scheduling_modes")] pub fn scheduling_modes(&self) -> Vec { unsafe { - let n = ffi::gst_query_get_n_scheduling_modes(self.0.as_ptr()); + let n = ffi::gst_query_get_n_scheduling_modes(self.as_mut_ptr()); let mut res = Vec::with_capacity(n as usize); for i in 0..n { res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode( - self.0.as_ptr(), + self.as_mut_ptr(), i, ))); } @@ -1266,7 +1290,7 @@ impl Scheduling { let mut align = mem::MaybeUninit::uninit(); ffi::gst_query_parse_scheduling( - self.0.as_ptr(), + self.as_mut_ptr(), flags.as_mut_ptr(), minsize.as_mut_ptr(), maxsize.as_mut_ptr(), @@ -1281,14 +1305,12 @@ impl Scheduling { ) } } -} -impl Scheduling { #[doc(alias = "gst_query_add_scheduling_mode")] pub fn add_scheduling_modes(&mut self, modes: &[crate::PadMode]) { unsafe { for mode in modes { - ffi::gst_query_add_scheduling_mode(self.0.as_mut_ptr(), mode.into_glib()); + ffi::gst_query_add_scheduling_mode(self.as_mut_ptr(), mode.into_glib()); } } } @@ -1297,7 +1319,7 @@ impl Scheduling { pub fn set(&mut self, flags: crate::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) { unsafe { ffi::gst_query_set_scheduling( - self.0.as_mut_ptr(), + self.as_mut_ptr(), flags.into_glib(), minsize, maxsize, @@ -1318,13 +1340,15 @@ impl AcceptCaps { ))) } } +} +impl AcceptCaps { #[doc(alias = "get_caps")] #[doc(alias = "gst_query_parse_accept_caps")] pub fn caps(&self) -> &crate::CapsRef { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps); + ffi::gst_query_parse_accept_caps(self.as_mut_ptr(), &mut caps); crate::CapsRef::from_ptr(caps) } } @@ -1334,61 +1358,21 @@ impl AcceptCaps { pub fn caps_owned(&self) -> crate::Caps { unsafe { from_glib_none(self.caps().as_ptr()) } } -} -impl<'a> AcceptCaps<&'a QueryRef> { - #[doc(alias = "get_caps")] - #[doc(alias = "gst_query_parse_accept_caps")] - pub fn caps(&self) -> &'a crate::CapsRef { - unsafe { - let mut caps = ptr::null_mut(); - ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps); - crate::CapsRef::from_ptr(caps) - } - } - - #[doc(alias = "get_caps_owned")] - #[doc(alias = "gst_query_parse_accept_caps")] - pub fn caps_owned(&self) -> crate::Caps { - unsafe { from_glib_none(self.caps().as_ptr()) } - } -} - -impl<'a> AcceptCaps<&'a mut QueryRef> { - #[doc(alias = "get_caps")] - #[doc(alias = "gst_query_parse_accept_caps")] - pub fn caps(&self) -> &'a crate::CapsRef { - unsafe { - let mut caps = ptr::null_mut(); - ffi::gst_query_parse_accept_caps(AsPtr::as_ptr(&self.0), &mut caps); - crate::CapsRef::from_ptr(caps) - } - } - - #[doc(alias = "get_caps_owned")] - #[doc(alias = "gst_query_parse_accept_caps")] - pub fn caps_owned(&self) -> crate::Caps { - unsafe { from_glib_none(self.caps().as_ptr()) } - } -} - -impl AcceptCaps { #[doc(alias = "get_result")] #[doc(alias = "gst_query_parse_accept_caps_result")] pub fn result(&self) -> bool { unsafe { let mut accepted = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_accept_caps_result(self.0.as_ptr(), accepted.as_mut_ptr()); + ffi::gst_query_parse_accept_caps_result(self.as_mut_ptr(), accepted.as_mut_ptr()); from_glib(accepted.assume_init()) } } -} -impl AcceptCaps { #[doc(alias = "gst_query_set_accept_caps_result")] pub fn set_result(&mut self, accepted: bool) { unsafe { - ffi::gst_query_set_accept_caps_result(self.0.as_mut_ptr(), accepted.into_glib()); + ffi::gst_query_set_accept_caps_result(self.as_mut_ptr(), accepted.into_glib()); } } } @@ -1406,13 +1390,13 @@ impl Caps { } } -impl Caps { +impl Caps { #[doc(alias = "get_filter")] #[doc(alias = "gst_query_parse_caps")] pub fn filter(&self) -> Option<&crate::CapsRef> { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_caps(self.0.as_ptr(), &mut caps); + ffi::gst_query_parse_caps(self.as_mut_ptr(), &mut caps); if caps.is_null() { None } else { @@ -1432,7 +1416,7 @@ impl Caps { pub fn result(&self) -> Option<&crate::CapsRef> { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_caps_result(self.0.as_ptr(), &mut caps); + ffi::gst_query_parse_caps_result(self.as_mut_ptr(), &mut caps); if caps.is_null() { None } else { @@ -1446,13 +1430,11 @@ impl Caps { pub fn result_owned(&self) -> Option { unsafe { self.result().map(|caps| from_glib_none(caps.as_ptr())) } } -} -impl Caps { #[doc(alias = "gst_query_set_caps_result")] pub fn set_result(&mut self, caps: &crate::Caps) { unsafe { - ffi::gst_query_set_caps_result(self.0.as_mut_ptr(), caps.as_mut_ptr()); + ffi::gst_query_set_caps_result(self.as_mut_ptr(), caps.as_mut_ptr()); } } } @@ -1483,13 +1465,15 @@ impl Context { ))) } } +} +impl Context { #[doc(alias = "get_context")] #[doc(alias = "gst_query_parse_context")] pub fn context(&self) -> Option<&crate::ContextRef> { unsafe { let mut context = ptr::null_mut(); - ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context); + ffi::gst_query_parse_context(self.as_mut_ptr(), &mut context); if context.is_null() { None } else { @@ -1512,87 +1496,15 @@ impl Context { pub fn context_type(&self) -> &str { unsafe { let mut context_type = ptr::null(); - ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type); + ffi::gst_query_parse_context_type(self.as_mut_ptr(), &mut context_type); CStr::from_ptr(context_type).to_str().unwrap() } } -} -impl<'a> Context<&'a QueryRef> { - #[doc(alias = "get_context")] - #[doc(alias = "gst_query_parse_context")] - pub fn context(&self) -> Option<&'a crate::ContextRef> { - unsafe { - let mut context = ptr::null_mut(); - ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context); - if context.is_null() { - None - } else { - Some(crate::ContextRef::from_ptr(context)) - } - } - } - - #[doc(alias = "get_context_owned")] - #[doc(alias = "gst_query_parse_context")] - pub fn context_owned(&self) -> Option { - unsafe { - self.context() - .map(|context| from_glib_none(context.as_ptr())) - } - } - - #[doc(alias = "get_context_type")] - #[doc(alias = "gst_query_parse_context_type")] - pub fn context_type(&self) -> &'a str { - unsafe { - let mut context_type = ptr::null(); - ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type); - CStr::from_ptr(context_type).to_str().unwrap() - } - } -} - -impl<'a> Context<&'a mut QueryRef> { - #[doc(alias = "get_context")] - #[doc(alias = "gst_query_parse_context")] - pub fn context(&self) -> Option<&'a crate::ContextRef> { - unsafe { - let mut context = ptr::null_mut(); - ffi::gst_query_parse_context(AsPtr::as_ptr(&self.0), &mut context); - if context.is_null() { - None - } else { - Some(crate::ContextRef::from_ptr(context)) - } - } - } - - #[doc(alias = "get_context_owned")] - #[doc(alias = "gst_query_parse_context")] - pub fn context_owned(&self) -> Option { - unsafe { - self.context() - .map(|context| from_glib_none(context.as_ptr())) - } - } - - #[doc(alias = "get_context_type")] - #[doc(alias = "gst_query_parse_context_type")] - pub fn context_type(&self) -> &'a str { - unsafe { - let mut context_type = ptr::null(); - ffi::gst_query_parse_context_type(AsPtr::as_ptr(&self.0), &mut context_type); - CStr::from_ptr(context_type).to_str().unwrap() - } - } -} - -impl Context { #[doc(alias = "gst_query_set_context")] pub fn set_context(&mut self, context: &crate::Context) { unsafe { - ffi::gst_query_set_context(self.0.as_mut_ptr(), context.as_mut_ptr()); + ffi::gst_query_set_context(self.as_mut_ptr(), context.as_mut_ptr()); } } } @@ -1617,7 +1529,7 @@ impl Default for Bitrate { } } -impl Bitrate { +impl Bitrate { #[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[doc(alias = "get_bitrate")] @@ -1625,19 +1537,17 @@ impl Bitrate { pub fn bitrate(&self) -> u32 { unsafe { let mut bitrate = mem::MaybeUninit::uninit(); - ffi::gst_query_parse_bitrate(self.0.as_ptr(), bitrate.as_mut_ptr()); + ffi::gst_query_parse_bitrate(self.as_mut_ptr(), bitrate.as_mut_ptr()); bitrate.assume_init() } } -} -impl Bitrate { #[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[doc(alias = "gst_query_set_bitrate")] pub fn set_bitrate(&mut self, bitrate: u32) { unsafe { - ffi::gst_query_set_bitrate(self.0.as_mut_ptr(), bitrate); + ffi::gst_query_set_bitrate(self.as_mut_ptr(), bitrate); } } } @@ -1656,7 +1566,7 @@ mod tests { fn check_mut(query: &mut QueryRef) { skip_assert_initialized!(); match query.view_mut() { - QueryView::Position(ref mut p) => { + QueryViewMut::Position(p) => { let pos = p.result(); assert_eq!(pos.try_into(), Ok(ClockTime::NONE)); p.set(Some(3 * ClockTime::SECOND)); @@ -1670,7 +1580,7 @@ mod tests { fn check_ref(query: &QueryRef) { skip_assert_initialized!(); match query.view() { - QueryView::Position(ref p) => { + QueryView::Position(p) => { let pos = p.result(); assert_eq!(pos.try_into(), Ok(Some(3 * ClockTime::SECOND))); unsafe { @@ -1712,11 +1622,11 @@ mod tests { assert!(query.is_writable()); let query = query.make_mut(); - if let QueryView::Duration(d) = &mut query.view_mut() { + if let QueryViewMut::Duration(d) = query.view_mut() { d.set(Some(2 * ClockTime::SECOND)); } - if let QueryView::Duration(d) = &query.view() { + if let QueryView::Duration(d) = query.view() { let duration = d.result(); assert_eq!(duration.try_into(), Ok(Some(2 * ClockTime::SECOND))); }