diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index 973a1cafd..4eabc6dd6 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -16,6 +16,7 @@ use std::mem; use std::cmp; use std::fmt; use std::ffi::CStr; +use std::ops::Deref; use glib; use glib::value::ToSendValue; @@ -494,28 +495,42 @@ pub enum EventView<'a> { __NonExhaustive, } -pub struct FlushStart<'a>(&'a EventRef); +macro_rules! declare_concrete_event( + ($name:ident) => { + pub struct $name<'a>(&'a EventRef); -pub struct FlushStop<'a>(&'a EventRef); + impl<'a> Deref for $name<'a> { + type Target = EventRef; + + fn deref(&self) -> &Self::Target { + self.0 + } + } + } +); + +declare_concrete_event!(FlushStart); + +declare_concrete_event!(FlushStop); impl<'a> FlushStop<'a> { pub fn get_reset_time(&self) -> bool { unsafe { let mut reset_time = mem::uninitialized(); - ffi::gst_event_parse_flush_stop(self.0.as_mut_ptr(), &mut reset_time); + ffi::gst_event_parse_flush_stop(self.as_mut_ptr(), &mut reset_time); from_glib(reset_time) } } } -pub struct StreamStart<'a>(&'a EventRef); +declare_concrete_event!(StreamStart); impl<'a> StreamStart<'a> { pub fn get_stream_id(&self) -> &'a str { unsafe { let mut stream_id = ptr::null(); - ffi::gst_event_parse_stream_start(self.0.as_mut_ptr(), &mut stream_id); + ffi::gst_event_parse_stream_start(self.as_mut_ptr(), &mut stream_id); CStr::from_ptr(stream_id).to_str().unwrap() } } @@ -524,7 +539,7 @@ impl<'a> StreamStart<'a> { unsafe { let mut stream_flags = mem::uninitialized(); - ffi::gst_event_parse_stream_flags(self.0.as_mut_ptr(), &mut stream_flags); + ffi::gst_event_parse_stream_flags(self.as_mut_ptr(), &mut stream_flags); from_glib(stream_flags) } @@ -534,63 +549,63 @@ impl<'a> StreamStart<'a> { unsafe { let mut group_id = mem::uninitialized(); - ffi::gst_event_parse_group_id(self.0.as_mut_ptr(), &mut group_id); + ffi::gst_event_parse_group_id(self.as_mut_ptr(), &mut group_id); from_glib(group_id) } } } -pub struct Caps<'a>(&'a EventRef); +declare_concrete_event!(Caps); impl<'a> Caps<'a> { pub fn get_caps(&self) -> &'a ::CapsRef { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_event_parse_caps(self.0.as_mut_ptr(), &mut caps); + ffi::gst_event_parse_caps(self.as_mut_ptr(), &mut caps); ::CapsRef::from_ptr(caps) } } } -pub struct Segment<'a>(&'a EventRef); +declare_concrete_event!(Segment); impl<'a> Segment<'a> { pub fn get_segment(&self) -> &'a ::Segment { unsafe { let mut segment = ptr::null(); - ffi::gst_event_parse_segment(self.0.as_mut_ptr(), &mut segment); + ffi::gst_event_parse_segment(self.as_mut_ptr(), &mut segment); &*(segment as *mut ffi::GstSegment as *mut ::Segment) } } } -pub struct StreamCollection<'a>(&'a EventRef); +declare_concrete_event!(StreamCollection); impl<'a> StreamCollection<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_stream_collection(&self) -> ::StreamCollection { unsafe { let mut stream_collection = ptr::null_mut(); - ffi::gst_event_parse_stream_collection(self.0.as_mut_ptr(), &mut stream_collection); + ffi::gst_event_parse_stream_collection(self.as_mut_ptr(), &mut stream_collection); from_glib_full(stream_collection) } } } -pub struct Tag<'a>(&'a EventRef); +declare_concrete_event!(Tag); impl<'a> Tag<'a> { pub fn get_tag(&self) -> &'a ::TagListRef { unsafe { let mut tags = ptr::null_mut(); - ffi::gst_event_parse_tag(self.0.as_mut_ptr(), &mut tags); + ffi::gst_event_parse_tag(self.as_mut_ptr(), &mut tags); ::TagListRef::from_ptr(tags) } } } -pub struct BufferSize<'a>(&'a EventRef); +declare_concrete_event!(BufferSize); impl<'a> BufferSize<'a> { pub fn get(&self) -> (GenericFormattedValue, GenericFormattedValue, bool) { unsafe { @@ -600,7 +615,7 @@ impl<'a> BufferSize<'a> { let mut async = mem::uninitialized(); ffi::gst_event_parse_buffer_size( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, &mut minsize, &mut maxsize, @@ -615,48 +630,48 @@ impl<'a> BufferSize<'a> { } } -pub struct SinkMessage<'a>(&'a EventRef); +declare_concrete_event!(SinkMessage); impl<'a> SinkMessage<'a> { pub fn get_message(&self) -> ::Message { unsafe { let mut msg = ptr::null_mut(); - ffi::gst_event_parse_sink_message(self.0.as_mut_ptr(), &mut msg); + ffi::gst_event_parse_sink_message(self.as_mut_ptr(), &mut msg); from_glib_full(msg) } } } -pub struct StreamGroupDone<'a>(&'a EventRef); +declare_concrete_event!(StreamGroupDone); impl<'a> StreamGroupDone<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_group_id(&self) -> GroupId { unsafe { let mut group_id = mem::uninitialized(); - ffi::gst_event_parse_stream_group_done(self.0.as_mut_ptr(), &mut group_id); + ffi::gst_event_parse_stream_group_done(self.as_mut_ptr(), &mut group_id); from_glib(group_id) } } } -pub struct Eos<'a>(&'a EventRef); +declare_concrete_event!(Eos); -pub struct Toc<'a>(&'a EventRef); +declare_concrete_event!(Toc); impl<'a> Toc<'a> { pub fn get_toc(&self) -> (&'a ::TocRef, bool) { unsafe { let mut toc = ptr::null_mut(); let mut updated = mem::uninitialized(); - ffi::gst_event_parse_toc(self.0.as_mut_ptr(), &mut toc, &mut updated); + ffi::gst_event_parse_toc(self.as_mut_ptr(), &mut toc, &mut updated); (::TocRef::from_ptr(toc), from_glib(updated)) } } } -pub struct Protection<'a>(&'a EventRef); +declare_concrete_event!(Protection); impl<'a> Protection<'a> { pub fn get(&self) -> (&'a str, &'a ::BufferRef, Option<&'a str>) { unsafe { @@ -665,7 +680,7 @@ impl<'a> Protection<'a> { let mut origin = ptr::null(); ffi::gst_event_parse_protection( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut system_id, &mut buffer, &mut origin, @@ -684,35 +699,35 @@ impl<'a> Protection<'a> { } } -pub struct SegmentDone<'a>(&'a EventRef); +declare_concrete_event!(SegmentDone); impl<'a> SegmentDone<'a> { pub fn get(&self) -> GenericFormattedValue { unsafe { let mut fmt = mem::uninitialized(); let mut position = mem::uninitialized(); - ffi::gst_event_parse_segment_done(self.0.as_mut_ptr(), &mut fmt, &mut position); + ffi::gst_event_parse_segment_done(self.as_mut_ptr(), &mut fmt, &mut position); GenericFormattedValue::new(from_glib(fmt), position) } } } -pub struct Gap<'a>(&'a EventRef); +declare_concrete_event!(Gap); impl<'a> Gap<'a> { pub fn get(&self) -> (::ClockTime, ::ClockTime) { unsafe { let mut timestamp = mem::uninitialized(); let mut duration = mem::uninitialized(); - ffi::gst_event_parse_gap(self.0.as_mut_ptr(), &mut timestamp, &mut duration); + ffi::gst_event_parse_gap(self.as_mut_ptr(), &mut timestamp, &mut duration); (from_glib(timestamp), from_glib(duration)) } } } -pub struct Qos<'a>(&'a EventRef); +declare_concrete_event!(Qos); impl<'a> Qos<'a> { pub fn get(&self) -> (::QOSType, f64, i64, ::ClockTime) { unsafe { @@ -722,7 +737,7 @@ impl<'a> Qos<'a> { let mut timestamp = mem::uninitialized(); ffi::gst_event_parse_qos( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut type_, &mut proportion, &mut diff, @@ -734,7 +749,7 @@ impl<'a> Qos<'a> { } } -pub struct Seek<'a>(&'a EventRef); +declare_concrete_event!(Seek); impl<'a> Seek<'a> { pub fn get( &self, @@ -756,7 +771,7 @@ impl<'a> Seek<'a> { let mut stop = mem::uninitialized(); ffi::gst_event_parse_seek( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut rate, &mut fmt, &mut flags, @@ -778,22 +793,22 @@ impl<'a> Seek<'a> { } } -pub struct Navigation<'a>(&'a EventRef); +declare_concrete_event!(Navigation); -pub struct Latency<'a>(&'a EventRef); +declare_concrete_event!(Latency); impl<'a> Latency<'a> { pub fn get_latency(&self) -> ::ClockTime { unsafe { let mut latency = mem::uninitialized(); - ffi::gst_event_parse_latency(self.0.as_mut_ptr(), &mut latency); + ffi::gst_event_parse_latency(self.as_mut_ptr(), &mut latency); from_glib(latency) } } } -pub struct Step<'a>(&'a EventRef); +declare_concrete_event!(Step); impl<'a> Step<'a> { pub fn get(&self) -> (GenericFormattedValue, f64, bool, bool) { unsafe { @@ -804,7 +819,7 @@ impl<'a> Step<'a> { let mut intermediate = mem::uninitialized(); ffi::gst_event_parse_step( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, &mut amount, &mut rate, @@ -822,41 +837,41 @@ impl<'a> Step<'a> { } } -pub struct Reconfigure<'a>(&'a EventRef); +declare_concrete_event!(Reconfigure); -pub struct TocSelect<'a>(&'a EventRef); +declare_concrete_event!(TocSelect); impl<'a> TocSelect<'a> { pub fn get_uid(&self) -> &'a str { unsafe { let mut uid = ptr::null_mut(); - ffi::gst_event_parse_toc_select(self.0.as_mut_ptr(), &mut uid); + ffi::gst_event_parse_toc_select(self.as_mut_ptr(), &mut uid); CStr::from_ptr(uid).to_str().unwrap() } } } -pub struct SelectStreams<'a>(&'a EventRef); +declare_concrete_event!(SelectStreams); impl<'a> SelectStreams<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_streams(&self) -> Vec { unsafe { let mut streams = ptr::null_mut(); - ffi::gst_event_parse_select_streams(self.0.as_mut_ptr(), &mut streams); + ffi::gst_event_parse_select_streams(self.as_mut_ptr(), &mut streams); FromGlibPtrContainer::from_glib_full(streams) } } } -pub struct CustomUpstream<'a>(&'a EventRef); -pub struct CustomDownstream<'a>(&'a EventRef); -pub struct CustomDownstreamOob<'a>(&'a EventRef); -pub struct CustomDownstreamSticky<'a>(&'a EventRef); -pub struct CustomBoth<'a>(&'a EventRef); -pub struct CustomBothOob<'a>(&'a EventRef); +declare_concrete_event!(CustomUpstream); +declare_concrete_event!(CustomDownstream); +declare_concrete_event!(CustomDownstreamOob); +declare_concrete_event!(CustomDownstreamSticky); +declare_concrete_event!(CustomBoth); +declare_concrete_event!(CustomBothOob); macro_rules! event_builder_generic_impl { ($new_fn:expr) => { @@ -1679,7 +1694,8 @@ mod tests { let flush_start_evt = Event::new_flush_start().build(); match flush_start_evt.view() { EventView::FlushStart(flush_start_evt) => { - assert!(flush_start_evt.0.get_structure().is_none()); + assert!(!flush_start_evt.is_sticky()); + assert!(flush_start_evt.get_structure().is_none()); }, _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"), } @@ -1689,8 +1705,8 @@ mod tests { .build(); match flush_start_evt.view() { EventView::FlushStart(flush_start_evt) => { - assert!(flush_start_evt.0.get_structure().is_some()); - if let Some(other_fields) = flush_start_evt.0.get_structure() { + assert!(flush_start_evt.get_structure().is_some()); + if let Some(other_fields) = flush_start_evt.get_structure() { assert!(other_fields.has_field("extra-field")); } }, @@ -1704,8 +1720,8 @@ mod tests { match flush_stop_evt.view() { EventView::FlushStop(flush_stop_evt) => { assert_eq!(flush_stop_evt.get_reset_time(), true); - assert!(flush_stop_evt.0.get_structure().is_some()); - if let Some(other_fields) = flush_stop_evt.0.get_structure() { + assert!(flush_stop_evt.get_structure().is_some()); + if let Some(other_fields) = flush_stop_evt.get_structure() { assert!(other_fields.has_field("extra-field")); } } diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 7463c9f9a..18899be17 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -20,6 +20,7 @@ use std::ptr; use std::mem; use std::fmt; use std::ffi::CStr; +use std::ops::Deref; use glib; use glib::Cast; @@ -420,15 +421,29 @@ pub enum MessageView<'a> { __NonExhaustive, } -pub struct Eos<'a>(&'a MessageRef); +macro_rules! declare_concrete_message( + ($name:ident) => { + pub struct $name<'a>(&'a MessageRef); -pub struct Error<'a>(&'a MessageRef); + impl<'a> Deref for $name<'a> { + type Target = MessageRef; + + fn deref(&self) -> &Self::Target { + self.0 + } + } + } +); + +declare_concrete_message!(Eos); + +declare_concrete_message!(Error); impl<'a> Error<'a> { pub fn get_error(&self) -> glib::Error { unsafe { let mut error = ptr::null_mut(); - ffi::gst_message_parse_error(self.0.as_mut_ptr(), &mut error, ptr::null_mut()); + ffi::gst_message_parse_error(self.as_mut_ptr(), &mut error, ptr::null_mut()); from_glib_full(error) } @@ -438,7 +453,7 @@ impl<'a> Error<'a> { unsafe { let mut debug = ptr::null_mut(); - ffi::gst_message_parse_error(self.0.as_mut_ptr(), ptr::null_mut(), &mut debug); + ffi::gst_message_parse_error(self.as_mut_ptr(), ptr::null_mut(), &mut debug); from_glib_full(debug) } @@ -449,7 +464,7 @@ impl<'a> Error<'a> { unsafe { let mut details = ptr::null(); - ffi::gst_message_parse_error_details(self.0.as_mut_ptr(), &mut details); + ffi::gst_message_parse_error_details(self.as_mut_ptr(), &mut details); if details.is_null() { None @@ -460,13 +475,13 @@ impl<'a> Error<'a> { } } -pub struct Warning<'a>(&'a MessageRef); +declare_concrete_message!(Warning); impl<'a> Warning<'a> { pub fn get_error(&self) -> glib::Error { unsafe { let mut error = ptr::null_mut(); - ffi::gst_message_parse_warning(self.0.as_mut_ptr(), &mut error, ptr::null_mut()); + ffi::gst_message_parse_warning(self.as_mut_ptr(), &mut error, ptr::null_mut()); from_glib_full(error) } @@ -476,7 +491,7 @@ impl<'a> Warning<'a> { unsafe { let mut debug = ptr::null_mut(); - ffi::gst_message_parse_warning(self.0.as_mut_ptr(), ptr::null_mut(), &mut debug); + ffi::gst_message_parse_warning(self.as_mut_ptr(), ptr::null_mut(), &mut debug); from_glib_full(debug) } @@ -487,7 +502,7 @@ impl<'a> Warning<'a> { unsafe { let mut details = ptr::null(); - ffi::gst_message_parse_error_details(self.0.as_mut_ptr(), &mut details); + ffi::gst_message_parse_error_details(self.as_mut_ptr(), &mut details); if details.is_null() { None @@ -498,13 +513,13 @@ impl<'a> Warning<'a> { } } -pub struct Info<'a>(&'a MessageRef); +declare_concrete_message!(Info); impl<'a> Info<'a> { pub fn get_error(&self) -> glib::Error { unsafe { let mut error = ptr::null_mut(); - ffi::gst_message_parse_info(self.0.as_mut_ptr(), &mut error, ptr::null_mut()); + ffi::gst_message_parse_info(self.as_mut_ptr(), &mut error, ptr::null_mut()); from_glib_full(error) } @@ -514,7 +529,7 @@ impl<'a> Info<'a> { unsafe { let mut debug = ptr::null_mut(); - ffi::gst_message_parse_info(self.0.as_mut_ptr(), ptr::null_mut(), &mut debug); + ffi::gst_message_parse_info(self.as_mut_ptr(), ptr::null_mut(), &mut debug); from_glib_full(debug) } @@ -525,7 +540,7 @@ impl<'a> Info<'a> { unsafe { let mut details = ptr::null(); - ffi::gst_message_parse_error_details(self.0.as_mut_ptr(), &mut details); + ffi::gst_message_parse_error_details(self.as_mut_ptr(), &mut details); if details.is_null() { None @@ -536,23 +551,23 @@ impl<'a> Info<'a> { } } -pub struct Tag<'a>(&'a MessageRef); +declare_concrete_message!(Tag); impl<'a> Tag<'a> { pub fn get_tags(&self) -> TagList { unsafe { let mut tags = ptr::null_mut(); - ffi::gst_message_parse_tag(self.0.as_mut_ptr(), &mut tags); + ffi::gst_message_parse_tag(self.as_mut_ptr(), &mut tags); from_glib_full(tags) } } } -pub struct Buffering<'a>(&'a MessageRef); +declare_concrete_message!(Buffering); impl<'a> Buffering<'a> { pub fn get_percent(&self) -> i32 { unsafe { let mut p = mem::uninitialized(); - ffi::gst_message_parse_buffering(self.0.as_mut_ptr(), &mut p); + ffi::gst_message_parse_buffering(self.as_mut_ptr(), &mut p); p } } @@ -565,7 +580,7 @@ impl<'a> Buffering<'a> { let mut buffering_left = mem::uninitialized(); ffi::gst_message_parse_buffering_stats( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut mode, &mut avg_in, &mut avg_out, @@ -577,14 +592,14 @@ impl<'a> Buffering<'a> { } } -pub struct StateChanged<'a>(&'a MessageRef); +declare_concrete_message!(StateChanged); impl<'a> StateChanged<'a> { pub fn get_old(&self) -> ::State { unsafe { let mut state = mem::uninitialized(); ffi::gst_message_parse_state_changed( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut state, ptr::null_mut(), ptr::null_mut(), @@ -599,7 +614,7 @@ impl<'a> StateChanged<'a> { let mut state = mem::uninitialized(); ffi::gst_message_parse_state_changed( - self.0.as_mut_ptr(), + self.as_mut_ptr(), ptr::null_mut(), &mut state, ptr::null_mut(), @@ -614,7 +629,7 @@ impl<'a> StateChanged<'a> { let mut state = mem::uninitialized(); ffi::gst_message_parse_state_changed( - self.0.as_mut_ptr(), + self.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), &mut state, @@ -625,9 +640,9 @@ impl<'a> StateChanged<'a> { } } -pub struct StateDirty<'a>(&'a MessageRef); +declare_concrete_message!(StateDirty); -pub struct StepDone<'a>(&'a MessageRef); +declare_concrete_message!(StepDone); impl<'a> StepDone<'a> { pub fn get( &self, @@ -649,7 +664,7 @@ impl<'a> StepDone<'a> { let mut eos = mem::uninitialized(); ffi::gst_message_parse_step_done( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut format, &mut amount, &mut rate, @@ -671,13 +686,13 @@ impl<'a> StepDone<'a> { } } -pub struct ClockProvide<'a>(&'a MessageRef); +declare_concrete_message!(ClockProvide); impl<'a> ClockProvide<'a> { pub fn get_clock(&self) -> Option<::Clock> { let mut clock = ptr::null_mut(); unsafe { - ffi::gst_message_parse_clock_provide(self.0.as_mut_ptr(), &mut clock, ptr::null_mut()); + ffi::gst_message_parse_clock_provide(self.as_mut_ptr(), &mut clock, ptr::null_mut()); from_glib_none(clock) } @@ -687,40 +702,40 @@ impl<'a> ClockProvide<'a> { unsafe { let mut ready = mem::uninitialized(); - ffi::gst_message_parse_clock_provide(self.0.as_mut_ptr(), ptr::null_mut(), &mut ready); + ffi::gst_message_parse_clock_provide(self.as_mut_ptr(), ptr::null_mut(), &mut ready); from_glib(ready) } } } -pub struct ClockLost<'a>(&'a MessageRef); +declare_concrete_message!(ClockLost); impl<'a> ClockLost<'a> { pub fn get_clock(&self) -> Option<::Clock> { let mut clock = ptr::null_mut(); unsafe { - ffi::gst_message_parse_clock_lost(self.0.as_mut_ptr(), &mut clock); + ffi::gst_message_parse_clock_lost(self.as_mut_ptr(), &mut clock); from_glib_none(clock) } } } -pub struct NewClock<'a>(&'a MessageRef); +declare_concrete_message!(NewClock); impl<'a> NewClock<'a> { pub fn get_clock(&self) -> Option<::Clock> { let mut clock = ptr::null_mut(); unsafe { - ffi::gst_message_parse_new_clock(self.0.as_mut_ptr(), &mut clock); + ffi::gst_message_parse_new_clock(self.as_mut_ptr(), &mut clock); from_glib_none(clock) } } } -pub struct StructureChange<'a>(&'a MessageRef); +declare_concrete_message!(StructureChange); impl<'a> StructureChange<'a> { pub fn get(&self) -> (::StructureChangeType, ::Element, bool) { unsafe { @@ -729,7 +744,7 @@ impl<'a> StructureChange<'a> { let mut busy = mem::uninitialized(); ffi::gst_message_parse_structure_change( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut type_, &mut owner, &mut busy, @@ -740,14 +755,14 @@ impl<'a> StructureChange<'a> { } } -pub struct StreamStatus<'a>(&'a MessageRef); +declare_concrete_message!(StreamStatus); impl<'a> StreamStatus<'a> { pub fn get(&self) -> (::StreamStatusType, ::Element) { unsafe { let mut type_ = mem::uninitialized(); let mut owner = ptr::null_mut(); - ffi::gst_message_parse_stream_status(self.0.as_mut_ptr(), &mut type_, &mut owner); + ffi::gst_message_parse_stream_status(self.as_mut_ptr(), &mut type_, &mut owner); (from_glib(type_), from_glib_none(owner)) } @@ -755,78 +770,76 @@ impl<'a> StreamStatus<'a> { pub fn get_stream_status_object(&self) -> Option { unsafe { - let value = ffi::gst_message_get_stream_status_object(self.0.as_mut_ptr()); + let value = ffi::gst_message_get_stream_status_object(self.as_mut_ptr()); from_glib_none(value) } } } -pub struct Application<'a>(&'a MessageRef); +declare_concrete_message!(Application); -pub struct Element<'a>(&'a MessageRef); +declare_concrete_message!(Element); -pub struct SegmentStart<'a>(&'a MessageRef); +declare_concrete_message!(SegmentStart); impl<'a> SegmentStart<'a> { pub fn get(&self) -> GenericFormattedValue { unsafe { let mut format = mem::uninitialized(); let mut position = mem::uninitialized(); - ffi::gst_message_parse_segment_start(self.0.as_mut_ptr(), &mut format, &mut position); + ffi::gst_message_parse_segment_start(self.as_mut_ptr(), &mut format, &mut position); GenericFormattedValue::new(from_glib(format), position) } } } -pub struct SegmentDone<'a>(&'a MessageRef); +declare_concrete_message!(SegmentDone); impl<'a> SegmentDone<'a> { pub fn get(&self) -> GenericFormattedValue { unsafe { let mut format = mem::uninitialized(); let mut position = mem::uninitialized(); - ffi::gst_message_parse_segment_done(self.0.as_mut_ptr(), &mut format, &mut position); + ffi::gst_message_parse_segment_done(self.as_mut_ptr(), &mut format, &mut position); GenericFormattedValue::new(from_glib(format), position) } } } -pub struct DurationChanged<'a>(&'a MessageRef); +declare_concrete_message!(DurationChanged); +declare_concrete_message!(Latency); +declare_concrete_message!(AsyncStart); -pub struct Latency<'a>(&'a MessageRef); - -pub struct AsyncStart<'a>(&'a MessageRef); - -pub struct AsyncDone<'a>(&'a MessageRef); +declare_concrete_message!(AsyncDone); impl<'a> AsyncDone<'a> { pub fn get_running_time(&self) -> ::ClockTime { unsafe { let mut running_time = mem::uninitialized(); - ffi::gst_message_parse_async_done(self.0.as_mut_ptr(), &mut running_time); + ffi::gst_message_parse_async_done(self.as_mut_ptr(), &mut running_time); from_glib(running_time) } } } -pub struct RequestState<'a>(&'a MessageRef); +declare_concrete_message!(RequestState); impl<'a> RequestState<'a> { pub fn get_requested_state(&self) -> ::State { unsafe { let mut state = mem::uninitialized(); - ffi::gst_message_parse_request_state(self.0.as_mut_ptr(), &mut state); + ffi::gst_message_parse_request_state(self.as_mut_ptr(), &mut state); from_glib(state) } } } -pub struct StepStart<'a>(&'a MessageRef); +declare_concrete_message!(StepStart); impl<'a> StepStart<'a> { pub fn get(&self) -> (bool, GenericFormattedValue, f64, bool, bool) { unsafe { @@ -838,7 +851,7 @@ impl<'a> StepStart<'a> { let mut intermediate = mem::uninitialized(); ffi::gst_message_parse_step_start( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut active, &mut format, &mut amount, @@ -858,7 +871,7 @@ impl<'a> StepStart<'a> { } } -pub struct Qos<'a>(&'a MessageRef); +declare_concrete_message!(Qos); impl<'a> Qos<'a> { pub fn get(&self) -> (bool, ::ClockTime, ::ClockTime, ::ClockTime, ::ClockTime) { unsafe { @@ -869,7 +882,7 @@ impl<'a> Qos<'a> { let mut duration = mem::uninitialized(); ffi::gst_message_parse_qos( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut live, &mut running_time, &mut stream_time, @@ -894,7 +907,7 @@ impl<'a> Qos<'a> { let mut quality = mem::uninitialized(); ffi::gst_message_parse_qos_values( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut jitter, &mut proportion, &mut quality, @@ -911,7 +924,7 @@ impl<'a> Qos<'a> { let mut dropped = mem::uninitialized(); ffi::gst_message_parse_qos_stats( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut format, &mut processed, &mut dropped, @@ -925,7 +938,7 @@ impl<'a> Qos<'a> { } } -pub struct Progress<'a>(&'a MessageRef); +declare_concrete_message!(Progress); impl<'a> Progress<'a> { pub fn get(&self) -> (::ProgressType, &'a str, &'a str) { unsafe { @@ -933,7 +946,7 @@ impl<'a> Progress<'a> { let mut code = ptr::null_mut(); let mut text = ptr::null_mut(); - ffi::gst_message_parse_progress(self.0.as_mut_ptr(), &mut type_, &mut code, &mut text); + ffi::gst_message_parse_progress(self.as_mut_ptr(), &mut type_, &mut code, &mut text); let code = CStr::from_ptr(code).to_str().unwrap(); let text = CStr::from_ptr(text).to_str().unwrap(); @@ -943,39 +956,39 @@ impl<'a> Progress<'a> { } } -pub struct Toc<'a>(&'a MessageRef); +declare_concrete_message!(Toc); impl<'a> Toc<'a> { pub fn get_toc(&self) -> (::Toc, bool) { unsafe { let mut toc = ptr::null_mut(); let mut updated = mem::uninitialized(); - ffi::gst_message_parse_toc(self.0.as_mut_ptr(), &mut toc, &mut updated); + ffi::gst_message_parse_toc(self.as_mut_ptr(), &mut toc, &mut updated); (from_glib_full(toc), from_glib(updated)) } } } -pub struct ResetTime<'a>(&'a MessageRef); +declare_concrete_message!(ResetTime); impl<'a> ResetTime<'a> { pub fn get_running_time(&self) -> ::ClockTime { unsafe { let mut running_time = mem::uninitialized(); - ffi::gst_message_parse_reset_time(self.0.as_mut_ptr(), &mut running_time); + ffi::gst_message_parse_reset_time(self.as_mut_ptr(), &mut running_time); from_glib(running_time) } } } -pub struct StreamStart<'a>(&'a MessageRef); +declare_concrete_message!(StreamStart); impl<'a> StreamStart<'a> { pub fn get_group_id(&self) -> Option { unsafe { let mut group_id = mem::uninitialized(); if from_glib(ffi::gst_message_parse_group_id( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut group_id, )) { Some(from_glib(group_id)) @@ -986,57 +999,57 @@ impl<'a> StreamStart<'a> { } } -pub struct NeedContext<'a>(&'a MessageRef); +declare_concrete_message!(NeedContext); impl<'a> NeedContext<'a> { pub fn get_context_type(&self) -> &str { unsafe { let mut context_type = ptr::null(); - ffi::gst_message_parse_context_type(self.0.as_mut_ptr(), &mut context_type); + ffi::gst_message_parse_context_type(self.as_mut_ptr(), &mut context_type); CStr::from_ptr(context_type).to_str().unwrap() } } } -pub struct HaveContext<'a>(&'a MessageRef); +declare_concrete_message!(HaveContext); impl<'a> HaveContext<'a> { pub fn get_context(&self) -> ::Context { unsafe { let mut context = ptr::null_mut(); - ffi::gst_message_parse_have_context(self.0.as_mut_ptr(), &mut context); + ffi::gst_message_parse_have_context(self.as_mut_ptr(), &mut context); from_glib_full(context) } } } -pub struct DeviceAdded<'a>(&'a MessageRef); +declare_concrete_message!(DeviceAdded); impl<'a> DeviceAdded<'a> { pub fn get_device(&self) -> ::Device { unsafe { let mut device = ptr::null_mut(); - ffi::gst_message_parse_device_added(self.0.as_mut_ptr(), &mut device); + ffi::gst_message_parse_device_added(self.as_mut_ptr(), &mut device); from_glib_none(device) } } } -pub struct DeviceRemoved<'a>(&'a MessageRef); +declare_concrete_message!(DeviceRemoved); impl<'a> DeviceRemoved<'a> { pub fn get_device(&self) -> ::Device { unsafe { let mut device = ptr::null_mut(); - ffi::gst_message_parse_device_removed(self.0.as_mut_ptr(), &mut device); + ffi::gst_message_parse_device_removed(self.as_mut_ptr(), &mut device); from_glib_none(device) } } } -pub struct PropertyNotify<'a>(&'a MessageRef); +declare_concrete_message!(PropertyNotify); impl<'a> PropertyNotify<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get(&self) -> (Object, &str, Option<&'a ::Value>) { @@ -1046,7 +1059,7 @@ impl<'a> PropertyNotify<'a> { let mut value = ptr::null(); ffi::gst_message_parse_property_notify( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut object, &mut property_name, &mut value, @@ -1065,27 +1078,28 @@ impl<'a> PropertyNotify<'a> { } } -pub struct StreamCollection<'a>(&'a MessageRef); +declare_concrete_message!(StreamCollection); impl<'a> StreamCollection<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_stream_collection(&self) -> ::StreamCollection { unsafe { let mut collection = ptr::null_mut(); - ffi::gst_message_parse_stream_collection(self.0.as_mut_ptr(), &mut collection); + ffi::gst_message_parse_stream_collection(self.as_mut_ptr(), &mut collection); from_glib_full(collection) } } } -pub struct StreamsSelected<'a>(&'a MessageRef); + +declare_concrete_message!(StreamsSelected); impl<'a> StreamsSelected<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_stream_collection(&self) -> ::StreamCollection { unsafe { let mut collection = ptr::null_mut(); - ffi::gst_message_parse_streams_selected(self.0.as_mut_ptr(), &mut collection); + ffi::gst_message_parse_streams_selected(self.as_mut_ptr(), &mut collection); from_glib_full(collection) } @@ -1094,12 +1108,12 @@ impl<'a> StreamsSelected<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_streams(&self) -> Vec<::Stream> { unsafe { - let n = ffi::gst_message_streams_selected_get_size(self.0.as_mut_ptr()); + let n = ffi::gst_message_streams_selected_get_size(self.as_mut_ptr()); (0..n) .map(|i| { from_glib_full(ffi::gst_message_streams_selected_get_stream( - self.0.as_mut_ptr(), + self.as_mut_ptr(), i, )) }) @@ -1108,12 +1122,12 @@ impl<'a> StreamsSelected<'a> { } } -pub struct Redirect<'a>(&'a MessageRef); +declare_concrete_message!(Redirect); impl<'a> Redirect<'a> { #[cfg(any(feature = "v1_10", feature = "dox"))] pub fn get_entries(&self) -> Vec<(&str, Option, Option<&StructureRef>)> { unsafe { - let n = ffi::gst_message_get_num_redirect_entries(self.0.as_mut_ptr()); + let n = ffi::gst_message_get_num_redirect_entries(self.as_mut_ptr()); (0..n) .map(|i| { @@ -1122,7 +1136,7 @@ impl<'a> Redirect<'a> { let mut structure = ptr::null(); ffi::gst_message_parse_redirect_entry( - self.0.as_mut_ptr(), + self.as_mut_ptr(), i, &mut location, &mut tags, @@ -2459,10 +2473,13 @@ mod tests { ::init().unwrap(); // Message without arguments - let eos_msg = Message::new_eos().build(); + let eos_msg = Message::new_eos() + .seqnum(Seqnum(1)) + .build(); match eos_msg.view() { MessageView::Eos(eos_msg) => { - assert!(eos_msg.0.get_structure().is_none()); + assert_eq!(eos_msg.get_seqnum(), Seqnum(1)); + assert!(eos_msg.get_structure().is_none()); }, _ => panic!("eos_msg.view() is not a MessageView::Eos(_)"), } diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 31336f97e..84dea242e 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -242,14 +242,50 @@ pub enum QueryView { __NonExhaustive, } -pub struct Position(T); +macro_rules! declare_concrete_query( + ($name:ident, $param:ident) => { + pub struct $name<$param>($param); + + impl<'a> $name<&'a QueryRef> { + pub fn get_query(&self) -> &QueryRef { + self.0 + } + } + + impl<'a> Deref for $name<&'a QueryRef> { + type Target = QueryRef; + + fn deref(&self) -> &Self::Target { + self.0 + } + } + + impl<'a> $name<&'a mut QueryRef> { + pub fn get_mut_query(&mut self) -> &mut QueryRef { + self.0 + } + } + + impl<'a> Deref for $name<&'a mut QueryRef> { + type Target = $name<&'a QueryRef>; + + fn deref(&self) -> &Self::Target { + unsafe { + mem::transmute(self) + } + } + } + } +); + +declare_concrete_query!(Position, T); impl<'a> Position<&'a QueryRef> { pub fn get_result(&self) -> GenericFormattedValue { unsafe { let mut fmt = mem::uninitialized(); let mut pos = mem::uninitialized(); - ffi::gst_query_parse_position(self.0.as_mut_ptr(), &mut fmt, &mut pos); + ffi::gst_query_parse_position(self.as_mut_ptr(), &mut fmt, &mut pos); GenericFormattedValue::new(from_glib(fmt), pos) } @@ -259,15 +295,11 @@ impl<'a> Position<&'a QueryRef> { unsafe { let mut fmt = mem::uninitialized(); - ffi::gst_query_parse_position(self.0.as_mut_ptr(), &mut fmt, ptr::null_mut()); + ffi::gst_query_parse_position(self.as_mut_ptr(), &mut fmt, ptr::null_mut()); from_glib(fmt) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Position<&'a mut QueryRef> { @@ -276,26 +308,22 @@ impl<'a> Position<&'a mut QueryRef> { assert_eq!(pos.get_format(), self.get_format()); unsafe { ffi::gst_query_set_position( - self.0.as_mut_ptr(), + self.as_mut_ptr(), pos.get_format().to_glib(), pos.get_value(), ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Duration(T); +declare_concrete_query!(Duration, T); impl<'a> Duration<&'a QueryRef> { pub fn get_result(&self) -> GenericFormattedValue { unsafe { let mut fmt = mem::uninitialized(); let mut pos = mem::uninitialized(); - ffi::gst_query_parse_duration(self.0.as_mut_ptr(), &mut fmt, &mut pos); + ffi::gst_query_parse_duration(self.as_mut_ptr(), &mut fmt, &mut pos); GenericFormattedValue::new(from_glib(fmt), pos) } @@ -305,15 +333,11 @@ impl<'a> Duration<&'a QueryRef> { unsafe { let mut fmt = mem::uninitialized(); - ffi::gst_query_parse_duration(self.0.as_mut_ptr(), &mut fmt, ptr::null_mut()); + ffi::gst_query_parse_duration(self.as_mut_ptr(), &mut fmt, ptr::null_mut()); from_glib(fmt) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Duration<&'a mut QueryRef> { @@ -322,19 +346,15 @@ impl<'a> Duration<&'a mut QueryRef> { assert_eq!(dur.get_format(), self.get_format()); unsafe { ffi::gst_query_set_duration( - self.0.as_mut_ptr(), + self.as_mut_ptr(), dur.get_format().to_glib(), dur.get_value(), ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Latency(T); +declare_concrete_query!(Latency, T); impl<'a> Latency<&'a QueryRef> { pub fn get_result(&self) -> (bool, ::ClockTime, ::ClockTime) { unsafe { @@ -342,61 +362,30 @@ impl<'a> Latency<&'a QueryRef> { let mut min = mem::uninitialized(); let mut max = mem::uninitialized(); - ffi::gst_query_parse_latency(self.0.as_mut_ptr(), &mut live, &mut min, &mut max); + ffi::gst_query_parse_latency(self.as_mut_ptr(), &mut live, &mut min, &mut max); (from_glib(live), from_glib(min), from_glib(max)) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Latency<&'a mut QueryRef> { pub fn set(&mut self, live: bool, min: ::ClockTime, max: ::ClockTime) { unsafe { ffi::gst_query_set_latency( - self.0.as_mut_ptr(), + self.as_mut_ptr(), live.to_glib(), min.to_glib(), max.to_glib(), ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Jitter(T); -impl<'a> Jitter<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} +declare_concrete_query!(Jitter, T); +declare_concrete_query!(Rate, T); -impl<'a> Jitter<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -pub struct Rate(T); -impl<'a> Rate<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} - -impl<'a> Rate<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -pub struct Seeking(T); +declare_concrete_query!(Seeking, T); impl<'a> Seeking<&'a QueryRef> { pub fn get_result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -405,7 +394,7 @@ impl<'a> Seeking<&'a QueryRef> { let mut start = mem::uninitialized(); let mut end = mem::uninitialized(); ffi::gst_query_parse_seeking( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, &mut seekable, &mut start, @@ -424,7 +413,7 @@ impl<'a> Seeking<&'a QueryRef> { unsafe { let mut fmt = mem::uninitialized(); ffi::gst_query_parse_seeking( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, ptr::null_mut(), ptr::null_mut(), @@ -434,10 +423,6 @@ impl<'a> Seeking<&'a QueryRef> { from_glib(fmt) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Seeking<&'a mut QueryRef> { @@ -450,7 +435,7 @@ impl<'a> Seeking<&'a mut QueryRef> { unsafe { ffi::gst_query_set_seeking( - self.0.as_mut_ptr(), + self.as_mut_ptr(), start.get_format().to_glib(), seekable.to_glib(), start.get_value(), @@ -458,13 +443,9 @@ impl<'a> Seeking<&'a mut QueryRef> { ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Segment(T); +declare_concrete_query!(Segment, T); impl<'a> Segment<&'a QueryRef> { pub fn get_result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -474,7 +455,7 @@ impl<'a> Segment<&'a QueryRef> { let mut stop = mem::uninitialized(); ffi::gst_query_parse_segment( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut rate, &mut fmt, &mut start, @@ -493,7 +474,7 @@ impl<'a> Segment<&'a QueryRef> { let mut fmt = mem::uninitialized(); ffi::gst_query_parse_segment( - self.0.as_mut_ptr(), + self.as_mut_ptr(), ptr::null_mut(), &mut fmt, ptr::null_mut(), @@ -502,10 +483,6 @@ impl<'a> Segment<&'a QueryRef> { from_glib(fmt) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Segment<&'a mut QueryRef> { @@ -517,7 +494,7 @@ impl<'a> Segment<&'a mut QueryRef> { unsafe { ffi::gst_query_set_segment( - self.0.as_mut_ptr(), + self.as_mut_ptr(), rate, start.get_format().to_glib(), start.get_value(), @@ -525,13 +502,9 @@ impl<'a> Segment<&'a mut QueryRef> { ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Convert(T); +declare_concrete_query!(Convert, T); impl<'a> Convert<&'a QueryRef> { pub fn get_result(&self) -> (GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -541,7 +514,7 @@ impl<'a> Convert<&'a QueryRef> { let mut dest = mem::uninitialized(); ffi::gst_query_parse_convert( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut src_fmt, &mut src, &mut dest_fmt, @@ -561,7 +534,7 @@ impl<'a> Convert<&'a QueryRef> { let mut dest_fmt = mem::uninitialized(); ffi::gst_query_parse_convert( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut src_fmt, &mut src, &mut dest_fmt, @@ -573,10 +546,6 @@ impl<'a> Convert<&'a QueryRef> { ) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Convert<&'a mut QueryRef> { @@ -586,7 +555,7 @@ impl<'a> Convert<&'a mut QueryRef> { unsafe { ffi::gst_query_set_convert( - self.0.as_mut_ptr(), + self.as_mut_ptr(), src.get_format().to_glib(), src.get_value(), dest.get_format().to_glib(), @@ -594,56 +563,44 @@ impl<'a> Convert<&'a mut QueryRef> { ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Formats(T); +declare_concrete_query!(Formats, T); impl<'a> Formats<&'a QueryRef> { pub fn get_result(&self) -> Vec<::Format> { unsafe { let mut n = mem::uninitialized(); - ffi::gst_query_parse_n_formats(self.0.as_mut_ptr(), &mut n); + ffi::gst_query_parse_n_formats(self.as_mut_ptr(), &mut n); let mut res = Vec::with_capacity(n as usize); for i in 0..n { let mut fmt = mem::uninitialized(); - ffi::gst_query_parse_nth_format(self.0.as_mut_ptr(), i, &mut fmt); + ffi::gst_query_parse_nth_format(self.as_mut_ptr(), i, &mut fmt); res.push(from_glib(fmt)); } res } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Formats<&'a mut QueryRef> { pub fn set(&mut self, formats: &[::Format]) { unsafe { let v: Vec<_> = formats.iter().map(|f| f.to_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 _); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Buffering(T); +declare_concrete_query!(Buffering, T); impl<'a> Buffering<&'a QueryRef> { pub fn get_format(&self) -> ::Format { unsafe { let mut fmt = mem::uninitialized(); ffi::gst_query_parse_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, ptr::null_mut(), ptr::null_mut(), @@ -659,7 +616,7 @@ impl<'a> Buffering<&'a QueryRef> { let mut busy = mem::uninitialized(); let mut percent = mem::uninitialized(); - ffi::gst_query_parse_buffering_percent(self.0.as_mut_ptr(), &mut busy, &mut percent); + ffi::gst_query_parse_buffering_percent(self.as_mut_ptr(), &mut busy, &mut percent); (from_glib(busy), percent) } @@ -673,7 +630,7 @@ impl<'a> Buffering<&'a QueryRef> { let mut estimated_total = mem::uninitialized(); ffi::gst_query_parse_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, &mut start, &mut stop, @@ -695,7 +652,7 @@ impl<'a> Buffering<&'a QueryRef> { let mut buffering_left = mem::uninitialized(); ffi::gst_query_parse_buffering_stats( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut mode, &mut avg_in, &mut avg_out, @@ -710,7 +667,7 @@ impl<'a> Buffering<&'a QueryRef> { unsafe { let mut fmt = mem::uninitialized(); ffi::gst_query_parse_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut fmt, ptr::null_mut(), ptr::null_mut(), @@ -718,13 +675,13 @@ impl<'a> Buffering<&'a QueryRef> { ); let fmt = from_glib(fmt); - let n = ffi::gst_query_get_n_buffering_ranges(self.0.as_mut_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::uninitialized(); let mut stop = mem::uninitialized(); let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), i, &mut start, &mut stop, @@ -740,16 +697,12 @@ impl<'a> Buffering<&'a QueryRef> { res } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Buffering<&'a mut QueryRef> { pub fn set_percent(&mut self, busy: bool, percent: i32) { unsafe { - ffi::gst_query_set_buffering_percent(self.0.as_mut_ptr(), busy.to_glib(), percent); + ffi::gst_query_set_buffering_percent(self.as_mut_ptr(), busy.to_glib(), percent); } } @@ -767,7 +720,7 @@ impl<'a> Buffering<&'a mut QueryRef> { unsafe { ffi::gst_query_set_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), start.get_format().to_glib(), start.get_value(), stop.get_value(), @@ -786,7 +739,7 @@ impl<'a> Buffering<&'a mut QueryRef> { skip_assert_initialized!(); unsafe { ffi::gst_query_set_buffering_stats( - self.0.as_mut_ptr(), + self.as_mut_ptr(), mode.to_glib(), avg_in, avg_out, @@ -808,38 +761,23 @@ impl<'a> Buffering<&'a mut QueryRef> { assert_eq!(start.get_format(), fmt); assert_eq!(stop.get_format(), fmt); ffi::gst_query_add_buffering_range( - self.0.as_mut_ptr(), + self.as_mut_ptr(), start.get_value(), stop.get_value(), ); } } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Custom(T); -impl<'a> Custom<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} +declare_concrete_query!(Custom, T); -impl<'a> Custom<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -pub struct Uri(T); +declare_concrete_query!(Uri, T); impl<'a> Uri<&'a QueryRef> { pub fn get_uri(&self) -> Option { unsafe { let mut uri = ptr::null_mut(); - ffi::gst_query_parse_uri(self.0.as_mut_ptr(), &mut uri); + ffi::gst_query_parse_uri(self.as_mut_ptr(), &mut uri); from_glib_full(uri) } } @@ -847,60 +785,41 @@ impl<'a> Uri<&'a QueryRef> { pub fn get_redirection(&self) -> (Option, bool) { unsafe { let mut uri = ptr::null_mut(); - ffi::gst_query_parse_uri_redirection(self.0.as_mut_ptr(), &mut uri); + ffi::gst_query_parse_uri_redirection(self.as_mut_ptr(), &mut uri); let mut permanent = mem::uninitialized(); - ffi::gst_query_parse_uri_redirection_permanent(self.0.as_mut_ptr(), &mut permanent); + ffi::gst_query_parse_uri_redirection_permanent(self.as_mut_ptr(), &mut permanent); (from_glib_full(uri), from_glib(permanent)) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Uri<&'a mut QueryRef> { pub fn set_uri<'b, T: Into<&'b str>>(&mut self, uri: T) { let uri = uri.into(); 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); } } pub fn set_redirection<'b, T: Into<&'b str>>(&mut self, uri: T, permanent: bool) { let uri = uri.into(); unsafe { - ffi::gst_query_set_uri_redirection(self.0.as_mut_ptr(), uri.to_glib_none().0); - ffi::gst_query_set_uri_redirection_permanent(self.0.as_mut_ptr(), permanent.to_glib()); + ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0); + ffi::gst_query_set_uri_redirection_permanent(self.as_mut_ptr(), permanent.to_glib()); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } // TODO -pub struct Allocation(T); -impl<'a> Allocation<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} +declare_concrete_query!(Allocation, T); -impl<'a> Allocation<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -pub struct Scheduling(T); +declare_concrete_query!(Scheduling, T); impl<'a> Scheduling<&'a QueryRef> { pub fn has_scheduling_mode(&self, mode: ::PadMode) -> bool { unsafe { from_glib(ffi::gst_query_has_scheduling_mode( - self.0.as_mut_ptr(), + self.as_mut_ptr(), mode.to_glib(), )) } @@ -914,7 +833,7 @@ impl<'a> Scheduling<&'a QueryRef> { skip_assert_initialized!(); unsafe { from_glib(ffi::gst_query_has_scheduling_mode_with_flags( - self.0.as_mut_ptr(), + self.as_mut_ptr(), mode.to_glib(), flags.to_glib(), )) @@ -923,11 +842,11 @@ impl<'a> Scheduling<&'a QueryRef> { pub fn get_scheduling_modes(&self) -> Vec<::PadMode> { unsafe { - let n = ffi::gst_query_get_n_scheduling_modes(self.0.as_mut_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_mut_ptr(), + self.as_mut_ptr(), i, ))); } @@ -944,7 +863,7 @@ impl<'a> Scheduling<&'a QueryRef> { let mut align = mem::uninitialized(); ffi::gst_query_parse_scheduling( - self.0.as_mut_ptr(), + self.as_mut_ptr(), &mut flags, &mut minsize, &mut maxsize, @@ -954,17 +873,13 @@ impl<'a> Scheduling<&'a QueryRef> { (from_glib(flags), minsize, maxsize, align) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Scheduling<&'a mut QueryRef> { pub fn add_scheduling_modes(&mut self, modes: &[::PadMode]) { unsafe { for mode in modes { - ffi::gst_query_add_scheduling_mode(self.0.as_mut_ptr(), mode.to_glib()); + ffi::gst_query_add_scheduling_mode(self.as_mut_ptr(), mode.to_glib()); } } } @@ -972,7 +887,7 @@ impl<'a> Scheduling<&'a mut QueryRef> { pub fn set(&mut self, flags: ::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) { unsafe { ffi::gst_query_set_scheduling( - self.0.as_mut_ptr(), + self.as_mut_ptr(), flags.to_glib(), minsize, maxsize, @@ -980,18 +895,14 @@ impl<'a> Scheduling<&'a mut QueryRef> { ); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct AcceptCaps(T); +declare_concrete_query!(AcceptCaps, T); impl<'a> AcceptCaps<&'a QueryRef> { pub fn get_caps(&self) -> &::CapsRef { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_accept_caps(self.0.as_mut_ptr(), &mut caps); + ffi::gst_query_parse_accept_caps(self.as_mut_ptr(), &mut caps); ::CapsRef::from_ptr(caps) } } @@ -999,34 +910,26 @@ impl<'a> AcceptCaps<&'a QueryRef> { pub fn get_result(&self) -> bool { unsafe { let mut accepted = mem::uninitialized(); - ffi::gst_query_parse_accept_caps_result(self.0.as_mut_ptr(), &mut accepted); + ffi::gst_query_parse_accept_caps_result(self.as_mut_ptr(), &mut accepted); from_glib(accepted) } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> AcceptCaps<&'a mut QueryRef> { pub fn set_result(&mut self, accepted: bool) { unsafe { - ffi::gst_query_set_accept_caps_result(self.0.as_mut_ptr(), accepted.to_glib()); + ffi::gst_query_set_accept_caps_result(self.as_mut_ptr(), accepted.to_glib()); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Caps(T); +declare_concrete_query!(Caps, T); impl<'a> Caps<&'a QueryRef> { pub fn get_filter(&self) -> Option<&::CapsRef> { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_caps(self.0.as_mut_ptr(), &mut caps); + ffi::gst_query_parse_caps(self.as_mut_ptr(), &mut caps); if caps.is_null() { None } else { @@ -1038,7 +941,7 @@ impl<'a> Caps<&'a QueryRef> { pub fn get_result(&self) -> Option<&::CapsRef> { unsafe { let mut caps = ptr::null_mut(); - ffi::gst_query_parse_caps_result(self.0.as_mut_ptr(), &mut caps); + ffi::gst_query_parse_caps_result(self.as_mut_ptr(), &mut caps); if caps.is_null() { None } else { @@ -1046,43 +949,24 @@ impl<'a> Caps<&'a QueryRef> { } } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Caps<&'a mut QueryRef> { pub fn set_result(&mut self, caps: &::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()); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Drain(T); -impl<'a> Drain<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} +declare_concrete_query!(Drain, T); -impl<'a> Drain<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -pub struct Context(T); +declare_concrete_query!(Context, T); impl<'a> Context<&'a QueryRef> { pub fn get_context(&self) -> Option<&::ContextRef> { unsafe { let mut context = ptr::null_mut(); - ffi::gst_query_parse_context(self.0.as_mut_ptr(), &mut context); + ffi::gst_query_parse_context(self.as_mut_ptr(), &mut context); if context.is_null() { None } else { @@ -1094,74 +978,21 @@ impl<'a> Context<&'a QueryRef> { pub fn get_context_type(&self) -> &str { unsafe { let mut context_type = ptr::null(); - ffi::gst_query_parse_context_type(self.0.as_mut_ptr(), &mut context_type); + ffi::gst_query_parse_context_type(self.as_mut_ptr(), &mut context_type); CStr::from_ptr(context_type).to_str().unwrap() } } - - pub fn get_query(&self) -> &QueryRef { - self.0 - } } impl<'a> Context<&'a mut QueryRef> { pub fn set_context(&mut self, context: &::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()); } } - - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } } -pub struct Other(T); -impl<'a> Other<&'a QueryRef> { - pub fn get_query(&self) -> &QueryRef { - self.0 - } -} - -impl<'a> Other<&'a mut QueryRef> { - pub fn get_mut_query(&mut self) -> &mut QueryRef { - self.0 - } -} - -macro_rules! impl_deref_view( - ($name:ident) => { - impl<'a> Deref for $name<&'a mut QueryRef> { - type Target = $name<&'a QueryRef>; - - fn deref(&self) -> &Self::Target { - unsafe { - mem::transmute(self) - } - } - } - }; -); - -impl_deref_view!(Position); -impl_deref_view!(Duration); -impl_deref_view!(Latency); -impl_deref_view!(Jitter); -impl_deref_view!(Rate); -impl_deref_view!(Seeking); -impl_deref_view!(Segment); -impl_deref_view!(Convert); -impl_deref_view!(Formats); -impl_deref_view!(Buffering); -impl_deref_view!(Custom); -impl_deref_view!(Uri); -impl_deref_view!(Allocation); -impl_deref_view!(Scheduling); -impl_deref_view!(AcceptCaps); -impl_deref_view!(Caps); -impl_deref_view!(Drain); -impl_deref_view!(Context); -impl_deref_view!(Other); +declare_concrete_query!(Other, T); #[cfg(test)] mod tests { @@ -1177,6 +1008,7 @@ mod tests { QueryView::Position(ref p) => { let fmt = p.get_format(); assert_eq!(fmt, ::Format::Time); + assert!(!p.is_serialized()); } _ => (), }