diff --git a/Gir_Gst.toml b/Gir_Gst.toml index f2a2bfb63..ed7dd29f7 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -58,6 +58,7 @@ generate = [ "Gst.ChildProxy", "Gst.Preset", "Gst.TagSetter", + "Gst.QOSType", ] manual = [ diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index ef40d19e5..fc8c61ce7 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -88,7 +88,7 @@ fn main() { }; match msg.view() { - MessageView::Eos => break, + MessageView::Eos(..) => break, MessageView::Error(err) => { println!( "Error from {}: {} ({:?})", diff --git a/examples/src/bin/launch.rs b/examples/src/bin/launch.rs index 3bb68fe7f..cb16ec06b 100644 --- a/examples/src/bin/launch.rs +++ b/examples/src/bin/launch.rs @@ -22,7 +22,7 @@ fn main() { }; match msg.view() { - MessageView::Eos => break, + MessageView::Eos(..) => break, MessageView::Error(err) => { println!( "Error from {}: {} ({:?})", diff --git a/examples/src/bin/launch_glib_main.rs b/examples/src/bin/launch_glib_main.rs index 6ce570abd..c8b8f1fb8 100644 --- a/examples/src/bin/launch_glib_main.rs +++ b/examples/src/bin/launch_glib_main.rs @@ -26,7 +26,7 @@ fn main() { bus.add_watch(move |_, msg| { let main_loop = &main_loop_clone; match msg.view() { - MessageView::Eos => main_loop.quit(), + MessageView::Eos(..) => main_loop.quit(), MessageView::Error(err) => { println!( "Error from {}: {} ({:?})", diff --git a/examples/src/bin/pad_probes.rs b/examples/src/bin/pad_probes.rs index f172f9529..cc59f0874 100644 --- a/examples/src/bin/pad_probes.rs +++ b/examples/src/bin/pad_probes.rs @@ -41,7 +41,7 @@ fn main() { }; match msg.view() { - MessageView::Eos => break, + MessageView::Eos(..) => break, MessageView::Error(err) => { println!( "Error from {}: {} ({:?})", diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index 7c98ad964..02ac197ae 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -59,7 +59,7 @@ fn main() { bus.add_watch(move |_, msg| { let main_loop = &main_loop_clone; match msg.view() { - MessageView::Eos => main_loop.quit(), + MessageView::Eos(..) => main_loop.quit(), MessageView::Error(err) => { println!( "Error from {}: {} ({:?})", diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index e1fa8f60e..0ecb32152 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -1205,6 +1205,66 @@ impl SetValue for ProgressType { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub enum QOSType { + Overflow, + Underflow, + Throttle, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl ToGlib for QOSType { + type GlibType = ffi::GstQOSType; + + fn to_glib(&self) -> ffi::GstQOSType { + match *self { + QOSType::Overflow => ffi::GST_QOS_TYPE_OVERFLOW, + QOSType::Underflow => ffi::GST_QOS_TYPE_UNDERFLOW, + QOSType::Throttle => ffi::GST_QOS_TYPE_THROTTLE, + QOSType::__Unknown(value) => unsafe{std::mem::transmute(value)} + } + } +} + +#[doc(hidden)] +impl FromGlib for QOSType { + fn from_glib(value: ffi::GstQOSType) -> Self { + skip_assert_initialized!(); + match value as i32 { + 0 => QOSType::Overflow, + 1 => QOSType::Underflow, + 2 => QOSType::Throttle, + value => QOSType::__Unknown(value), + } + } +} + +impl StaticType for QOSType { + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_qos_type_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for QOSType { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for QOSType { + unsafe fn from_value(value: &Value) -> Self { + from_glib(std::mem::transmute::(gobject_ffi::g_value_get_enum(value.to_glib_none().0))) + } +} + +impl SetValue for QOSType { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum ResourceError { Failed, diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 032cff466..990a21d80 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -115,6 +115,7 @@ pub use self::enums::PadProbeReturn; pub use self::enums::ParseError; pub use self::enums::PluginError; pub use self::enums::ProgressType; +pub use self::enums::QOSType; pub use self::enums::ResourceError; pub use self::enums::SeekType; pub use self::enums::State; diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs new file mode 100644 index 000000000..11053879a --- /dev/null +++ b/gstreamer/src/event.rs @@ -0,0 +1,1237 @@ +// Copyright (C) 2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ffi; +use Object; +use miniobject::*; +use structure::*; + +use std::ptr; +use std::mem; +use std::ffi::CStr; + +use glib; +use glib::translate::{from_glib, from_glib_none, from_glib_full, ToGlibPtr, ToGlib}; + +#[repr(C)] +pub struct EventRef(ffi::GstEvent); + +pub type Event = GstRc; + +unsafe impl MiniObject for EventRef { + type GstType = ffi::GstEvent; +} + +impl EventRef { + pub fn get_seqnum(&self) -> u32 { + unsafe { ffi::gst_event_get_seqnum(self.as_mut_ptr()) } + } + + pub fn get_running_time_offset(&self) -> i64 { + unsafe { ffi::gst_event_get_running_time_offset(self.as_mut_ptr()) } + } + + + pub fn get_structure(&self) -> &StructureRef { + unsafe { + let structure = ffi::gst_event_get_structure(self.as_mut_ptr()); + StructureRef::from_glib_borrow(structure) + } + } + + pub fn is_upstream(&self) -> bool { + unsafe { + ((*self.as_ptr()).type_ as u32) & (ffi::GST_EVENT_TYPE_UPSTREAM.bits()) != 0 + } + } + + pub fn is_downstream(&self) -> bool { + unsafe { + ((*self.as_ptr()).type_ as u32) & (ffi::GST_EVENT_TYPE_DOWNSTREAM.bits()) != 0 + } + } + + pub fn is_serialized(&self) -> bool { + unsafe { + ((*self.as_ptr()).type_ as u32) & (ffi::GST_EVENT_TYPE_SERIALIZED.bits()) != 0 + } + } + + pub fn is_sticky(&self) -> bool { + unsafe { + ((*self.as_ptr()).type_ as u32) & (ffi::GST_EVENT_TYPE_STICKY.bits()) != 0 + } + } + + pub fn is_sticky_multi(&self) -> bool { + unsafe { + ((*self.as_ptr()).type_ as u32) & (ffi::GST_EVENT_TYPE_STICKY_MULTI.bits()) != 0 + } + } + + pub fn view(&self) -> EventView { + let type_ = unsafe { (*self.as_ptr()).type_ }; + + if type_ == ffi::GST_EVENT_FLUSH_START { + EventView::FlushStart(FlushStart(self)) + } else if type_ == ffi::GST_EVENT_FLUSH_STOP { + EventView::FlushStop(FlushStop(self)) + } else if type_ == ffi::GST_EVENT_STREAM_START { + EventView::StreamStart(StreamStart(self)) + } else if type_ == ffi::GST_EVENT_CAPS { + EventView::Caps(Caps(self)) + } else if type_ == ffi::GST_EVENT_SEGMENT { + EventView::Segment(Segment(self)) + } else if type_ == ffi::GST_EVENT_STREAM_COLLECTION { + EventView::StreamCollection(StreamCollection(self)) + } else if type_ == ffi::GST_EVENT_TAG { + EventView::Tag(Tag(self)) + } else if type_ == ffi::GST_EVENT_BUFFERSIZE { + EventView::BufferSize(BufferSize(self)) + } else if type_ == ffi::GST_EVENT_SINK_MESSAGE { + EventView::SinkMessage(SinkMessage(self)) + } else if type_ == ffi::GST_EVENT_STREAM_GROUP_DONE { + EventView::StreamGroupDone(StreamGroupDone(self)) + } else if type_ == ffi::GST_EVENT_EOS { + EventView::Eos(Eos(self)) + } else if type_ == ffi::GST_EVENT_TOC { + EventView::Toc(Toc(self)) + } else if type_ == ffi::GST_EVENT_PROTECTION { + EventView::Protection(Protection(self)) + } else if type_ == ffi::GST_EVENT_SEGMENT_DONE { + EventView::SegmentDone(SegmentDone(self)) + } else if type_ == ffi::GST_EVENT_GAP { + EventView::Gap(Gap(self)) + } else if type_ == ffi::GST_EVENT_QOS { + EventView::Qos(Qos(self)) + } else if type_ == ffi::GST_EVENT_SEEK { + EventView::Seek(Seek(self)) + } else if type_ == ffi::GST_EVENT_NAVIGATION { + EventView::Navigation(Navigation(self)) + } else if type_ == ffi::GST_EVENT_LATENCY { + EventView::Latency(Latency(self)) + } else if type_ == ffi::GST_EVENT_STEP { + EventView::Step(Step(self)) + } else if type_ == ffi::GST_EVENT_RECONFIGURE { + EventView::Reconfigure(Reconfigure(self)) + } else if type_ == ffi::GST_EVENT_TOC_SELECT { + EventView::TocSelect(TocSelect(self)) + } else if type_ == ffi::GST_EVENT_SELECT_STREAMS { + EventView::SelectStreams(SelectStreams(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_UPSTREAM { + EventView::CustomUpstream(CustomUpstream(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_DOWNSTREAM { + EventView::CustomDownstream(CustomDownstream(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB { + EventView::CustomDownstreamOob(CustomDownstreamOob(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY { + EventView::CustomDownstreamSticky(CustomDownstreamSticky(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_BOTH { + EventView::CustomBoth(CustomBoth(self)) + } else if type_ == ffi::GST_EVENT_CUSTOM_BOTH_OOB { + EventView::CustomBothOob(CustomBothOob(self)) + } else { + EventView::Other + } + } + + pub fn new_flush_start() -> FlushStartBuilder { + FlushStartBuilder::new() + } + + pub fn new_flush_stop(reset_time: bool) -> FlushStopBuilder { + FlushStopBuilder::new(reset_time) + } + + pub fn new_stream_start(stream_id: &str) -> StreamStartBuilder { + StreamStartBuilder::new(stream_id) + } + + pub fn new_caps(caps: &::Caps) -> CapsBuilder { + CapsBuilder::new(caps) + } + + pub fn new_segment(segment: &::Segment) -> SegmentBuilder { + SegmentBuilder::new(segment) + } + + #[cfg(feature = "v1_10")] + pub fn new_stream_collection(stream_collection: &::StreamCollection) -> StreamCollectionBuilder { + StreamCollectionBuilder::new(stream_collection) + } + + pub fn new_tag(tags: ::TagList) -> TagBuilder { + TagBuilder::new(tags) + } + + pub fn new_buffer_size(format: ::Format, minsize: i64, maxsize: i64, async: bool) -> BufferSizeBuilder { + BufferSizeBuilder::new(format, minsize, maxsize, async) + } + + pub fn new_sink_message<'a>(name: &'a str, msg: &'a ::Message) -> SinkMessageBuilder<'a> { + SinkMessageBuilder::new(name, msg) + } + + #[cfg(feature = "v1_10")] + pub fn new_stream_group_done(group_id: u32) -> StreamGroupDoneBuilder { + StreamGroupDoneBuilder::new(group_id) + } + + pub fn new_eos() -> EosBuilder { + EosBuilder::new() + } + + pub fn new_toc(toc: (), updated: bool) -> TocBuilder { + TocBuilder::new(toc, updated) + } + + pub fn new_protection<'a>(system_id: &'a str, data: &'a ::Buffer, origin: &'a str) -> ProtectionBuilder<'a> { + ProtectionBuilder::new(system_id, data, origin) + } + + pub fn new_segment_done(format: ::Format, position: i64) -> SegmentDoneBuilder { + SegmentDoneBuilder::new(format, position) + } + + pub fn new_gap(timestamp: u64, duration: u64) -> GapBuilder { + GapBuilder::new(timestamp, duration) + } + + pub fn new_qos(type_: ::QOSType, proportion: f64, diff: i64, timestamp: u64) -> QosBuilder { + QosBuilder::new(type_, proportion, diff, timestamp) + } + + pub fn new_seek(rate: f64, format: ::Format, flags: ::SeekFlags, start_type: ::SeekType, start: i64, stop_type: ::SeekType, stop: i64) -> SeekBuilder { + SeekBuilder::new(rate, format, flags, start_type, start, stop_type, stop) + } + + pub fn new_navigation(structure: ::Structure) -> NavigationBuilder { + NavigationBuilder::new(structure) + } + + pub fn new_latency(latency: u64) -> LatencyBuilder { + LatencyBuilder::new(latency) + } + + pub fn new_step(format: ::Format, amount: u64, rate: f64, flush: bool, intermediate: bool) -> StepBuilder { + StepBuilder::new(format, amount, rate, flush, intermediate) + } + + pub fn new_reconfigure() -> ReconfigureBuilder { + ReconfigureBuilder::new() + } + + pub fn new_toc_select(uid: &str) -> TocSelectBuilder { + TocSelectBuilder::new(uid) + } + + #[cfg(feature = "v1_10")] + pub fn new_select_streams(streams: &[&'a str]) -> SelectStreamsBuilder { + SelectStreamsBuilder::new(streams) + } + + pub fn new_custom_upstream(structure: ::Structure) -> CustomUpstreamBuilder { + CustomUpstreamBuilder::new(structure) + } + + pub fn new_custom_downstream(structure: ::Structure) -> CustomDownstreamBuilder { + CustomDownstreamBuilder::new(structure) + } + + pub fn new_custom_downstream_oob(structure: ::Structure) -> CustomDownstreamOobBuilder { + CustomDownstreamOobBuilder::new(structure) + } + + pub fn new_custom_downstream_sticky(structure: ::Structure) -> CustomDownstreamStickyBuilder { + CustomDownstreamStickyBuilder::new(structure) + } + + pub fn new_custom_both(structure: ::Structure) -> CustomBothBuilder { + CustomBothBuilder::new(structure) + } + + pub fn new_custom_both_oob(structure: ::Structure) -> CustomBothOobBuilder { + CustomBothOobBuilder::new(structure) + } +} + +impl glib::types::StaticType for GstRc { + fn static_type() -> glib::types::Type { + unsafe { from_glib(ffi::gst_event_get_type()) } + } +} + +pub enum EventView<'a> { + FlushStart(FlushStart<'a>), + FlushStop(FlushStop<'a>), + StreamStart(StreamStart<'a>), + Caps(Caps<'a>), + Segment(Segment<'a>), + StreamCollection(StreamCollection<'a>), + Tag(Tag<'a>), + BufferSize(BufferSize<'a>), + SinkMessage(SinkMessage<'a>), + StreamGroupDone(StreamGroupDone<'a>), + Eos(Eos<'a>), + Toc(Toc<'a>), + Protection(Protection<'a>), + SegmentDone(SegmentDone<'a>), + Gap(Gap<'a>), + Qos(Qos<'a>), + Seek(Seek<'a>), + Navigation(Navigation<'a>), + Latency(Latency<'a>), + Step(Step<'a>), + Reconfigure(Reconfigure<'a>), + TocSelect(TocSelect<'a>), + SelectStreams(SelectStreams<'a>), + CustomUpstream(CustomUpstream<'a>), + CustomDownstream(CustomDownstream<'a>), + CustomDownstreamOob(CustomDownstreamOob<'a>), + CustomDownstreamSticky(CustomDownstreamSticky<'a>), + CustomBoth(CustomBoth<'a>), + CustomBothOob(CustomBothOob<'a>), + Other, + __NonExhaustive, +} + +pub struct FlushStart<'a>(&'a EventRef); + +pub struct FlushStop<'a>(&'a EventRef); +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); + + from_glib(reset_time) + } + } +} + +pub struct StreamStart<'a>(&'a EventRef); +impl<'a> StreamStart<'a> { + pub fn get_stream_id(&self) -> Option<&'a str> { + unsafe { + let mut stream_id = ptr::null(); + + ffi::gst_event_parse_stream_start(self.0.as_mut_ptr(), &mut stream_id); + if stream_id.is_null() { + None + } else { + Some((CStr::from_ptr(stream_id).to_str().unwrap())) + } + } + } + + pub fn get_stream_flags(&self) -> ::StreamFlags { + unsafe { + let mut stream_flags = mem::uninitialized(); + + ffi::gst_event_parse_stream_flags(self.0.as_mut_ptr(), &mut stream_flags); + + from_glib(stream_flags) + } + } + + pub fn get_group_id(&self) -> u32 { + unsafe { + let mut group_id = mem::uninitialized(); + + ffi::gst_event_parse_group_id(self.0.as_mut_ptr(), &mut group_id); + + group_id + } + } +} + +pub struct Caps<'a>(&'a EventRef); +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); + ::CapsRef::from_ptr(caps) + } + } +} + +pub struct Segment<'a>(&'a EventRef); +impl<'a> Segment<'a> { + pub fn get_segment(&self) -> ::Segment { + unsafe { + let mut segment = ptr::null(); + + ffi::gst_event_parse_segment(self.0.as_mut_ptr(), &mut segment); + from_glib_none(segment as *mut _) + } + } +} + +pub struct StreamCollection<'a>(&'a EventRef); +impl<'a> StreamCollection<'a> { + #[cfg(feature = "v1_10")] + pub fn get_stream_collection(&self) -> ::StreamCollection { + unsafe { + let mut stream_collection = ptr::null_mut(); + + ffi::gst_event_parse_segment(self.0.as_mut_ptr(), &mut stream_collection); + from_glib_full(stream_collection) + } + } +} + +pub struct Tag<'a>(&'a EventRef); +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); + ::TagListRef::from_ptr(tags) + } + } +} + +pub struct BufferSize<'a>(&'a EventRef); +impl<'a> BufferSize<'a> { + pub fn get(&self) -> (::Format, i64, i64, bool) { + unsafe { + let mut fmt = mem::uninitialized(); + let mut minsize = mem::uninitialized(); + let mut maxsize = mem::uninitialized(); + let mut async = mem::uninitialized(); + + ffi::gst_event_parse_buffer_size(self.0.as_mut_ptr(), &mut fmt, &mut minsize, &mut maxsize, &mut async); + (from_glib(fmt), minsize, maxsize, from_glib(async)) + } + } +} + +pub struct SinkMessage<'a>(&'a EventRef); +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); + from_glib_full(msg) + } + } +} + +pub struct StreamGroupDone<'a>(&'a EventRef); +impl<'a> StreamGroupDone<'a> { + #[cfg(feature = "v1_10")] + pub fn get_group_id(&self) -> u32 { + unsafe { + let mut group_id = mem::uninitialized(); + + ffi::gst_event_parse_stream_group_done(self.0.as_mut_ptr(), &mut group_id); + + group_id + } + } +} + +pub struct Eos<'a>(&'a EventRef); + +// TODO +pub struct Toc<'a>(&'a EventRef); + +pub struct Protection<'a>(&'a EventRef); +impl<'a> Protection<'a> { + pub fn get(&self) -> (&'a str, &'a ::BufferRef, &'a str) { + unsafe { + let mut system_id = ptr::null(); + let mut buffer = ptr::null_mut(); + let mut origin = ptr::null(); + + ffi::gst_event_parse_protection(self.0.as_mut_ptr(), &mut system_id, &mut buffer, &mut origin); + + (CStr::from_ptr(system_id).to_str().unwrap(), ::BufferRef::from_ptr(buffer), CStr::from_ptr(origin).to_str().unwrap()) + } + } +} + +pub struct SegmentDone<'a>(&'a EventRef); +impl<'a> SegmentDone<'a> { + pub fn get(&self) -> (::Format, i64) { + 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); + + (from_glib(fmt), position) + } + } +} + +pub struct Gap<'a>(&'a EventRef); +impl<'a> Gap<'a> { + pub fn get(&self) -> (u64, u64) { + 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); + + (timestamp, duration) + } + } +} + +pub struct Qos<'a>(&'a EventRef); +impl<'a> Qos<'a> { + pub fn get(&self) -> (::QOSType, f64, i64, u64) { + unsafe { + let mut type_ = mem::uninitialized(); + let mut proportion = mem::uninitialized(); + let mut diff = mem::uninitialized(); + let mut timestamp = mem::uninitialized(); + + ffi::gst_event_parse_qos(self.0.as_mut_ptr(), &mut type_, &mut proportion, &mut diff, &mut timestamp); + + (from_glib(type_), proportion, diff, timestamp) + } + } +} + + +pub struct Seek<'a>(&'a EventRef); +impl<'a> Seek<'a> { + pub fn get(&self) -> (f64, ::Format, ::SeekFlags, ::SeekType, i64, ::SeekType, i64) { + unsafe { + let mut rate = mem::uninitialized(); + let mut fmt = mem::uninitialized(); + let mut flags = mem::uninitialized(); + let mut start_type = mem::uninitialized(); + let mut start = mem::uninitialized(); + let mut stop_type = mem::uninitialized(); + let mut stop = mem::uninitialized(); + + ffi::gst_event_parse_seek(self.0.as_mut_ptr(), &mut rate, &mut fmt, &mut flags, &mut start_type, &mut start, &mut stop_type, &mut stop); + + (rate, from_glib(fmt), from_glib(flags), from_glib(start_type), start, from_glib(stop_type), stop) + } + } +} + +pub struct Navigation<'a>(&'a EventRef); + +pub struct Latency<'a>(&'a EventRef); +impl<'a> Latency<'a> { + pub fn get_latency(&self) -> u64 { + unsafe { + let mut latency = mem::uninitialized(); + + ffi::gst_event_parse_latency(self.0.as_mut_ptr(), &mut latency); + + latency + } + } +} + +pub struct Step<'a>(&'a EventRef); +impl<'a> Step<'a> { + pub fn get(&self) -> (::Format, u64, f64, bool, bool) { + unsafe { + let mut fmt = mem::uninitialized(); + let mut amount = mem::uninitialized(); + let mut rate = mem::uninitialized(); + let mut flush = mem::uninitialized(); + let mut intermediate = mem::uninitialized(); + + ffi::gst_event_parse_step(self.0.as_mut_ptr(), &mut fmt, &mut amount, &mut rate, &mut flush, &mut intermediate); + + (from_glib(fmt), amount, rate, from_glib(flush), from_glib(intermediate)) + } + } +} + +pub struct Reconfigure<'a>(&'a EventRef); + +pub struct TocSelect<'a>(&'a EventRef); +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); + + CStr::from_ptr(uid).to_str().unwrap() + } + } +} + +pub struct SelectStreams<'a>(&'a EventRef); +impl<'a> SelectStreams<'a> { + #[cfg(feature = "v1_10")] + 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); + + 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); + +macro_rules! event_builder_generic_impl { + ($new_fn:expr) => { + pub fn seqnum(self, seqnum: u32) -> Self { + Self { + seqnum: Some(seqnum), + .. self + } + } + + pub fn running_time_offset(self, running_time_offset: i64) -> Self { + Self { + running_time_offset: Some(running_time_offset), + .. self + } + } + + pub fn build(mut self) -> Event { + assert_initialized_main_thread!(); + unsafe { + let event = $new_fn(&mut self); + if let Some(seqnum) = self.seqnum { + ffi::gst_event_set_seqnum(event, seqnum); + } + + if let Some(running_time_offset) = self.running_time_offset { + ffi::gst_event_set_running_time_offset(event, running_time_offset); + } + + from_glib_full(event) + } + } + } +} + +pub struct FlushStartBuilder { + seqnum: Option, + running_time_offset: Option, +} +impl FlushStartBuilder { + pub fn new() -> Self { + Self { + seqnum: None, + running_time_offset: None, + } + } + + event_builder_generic_impl!(|_| ffi::gst_event_new_flush_start()); +} + +pub struct FlushStopBuilder { + seqnum: Option, + running_time_offset: Option, + reset_time: bool +} +impl FlushStopBuilder { + pub fn new(reset_time: bool) -> Self { + Self { + seqnum: None, + running_time_offset: None, + reset_time: reset_time, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_flush_stop(s.reset_time.to_glib())); +} + +pub struct StreamStartBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + stream_id: &'a str, + flags: Option<::StreamFlags>, + group_id: Option, +} +impl<'a> StreamStartBuilder<'a> { + pub fn new(stream_id: &'a str) -> Self { + Self { + seqnum: None, + running_time_offset: None, + stream_id: stream_id, + flags: None, + group_id: None, + } + } + + pub fn flags(self, flags: ::StreamFlags) -> Self { + Self { + flags: Some(flags), + .. self + } + } + + pub fn group_id(self, group_id: u32) -> Self { + Self { + group_id: Some(group_id), + .. self + } + } + + event_builder_generic_impl!(|s: &Self| { + let ev = ffi::gst_event_new_stream_start(s.stream_id.to_glib_none().0); + if let Some(flags) = s.flags { + ffi::gst_event_set_stream_flags(ev, flags.to_glib()); + } + if let Some(group_id) = s.group_id { + ffi::gst_event_set_group_id(ev, group_id); + } + ev + }); +} + +pub struct CapsBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + caps: &'a ::Caps, +} +impl<'a> CapsBuilder<'a> { + pub fn new(caps: &'a ::Caps) -> Self { + Self { + seqnum: None, + running_time_offset: None, + caps: caps, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_caps(s.caps.as_mut_ptr())); +} + +pub struct SegmentBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + segment: &'a ::Segment, +} +impl<'a> SegmentBuilder<'a> { + pub fn new(segment: &'a ::Segment) -> Self { + Self { + seqnum: None, + running_time_offset: None, + segment: segment, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_segment(s.segment.to_glib_none().0)); +} + +#[cfg(feature = "v1_10")] +pub struct StreamCollectionBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + stream_select: &'a ::StreamCollection, +} +#[cfg(feature = "v1_10")] +impl<'a> StreamCollectionBuilder<'a> { + pub fn new(stream_collection: &'a ::StreamCollection) -> Self { + Self { + seqnum: None, + running_time_offset: None, + stream_collection: stream_collection, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_stream_collection(s.stream_collection.to_glib_none().0)); +} + +pub struct TagBuilder { + seqnum: Option, + running_time_offset: Option, + tags: Option<::TagList>, +} +impl TagBuilder { + pub fn new(tags: ::TagList) -> Self { + Self { + seqnum: None, + running_time_offset: None, + tags: Some(tags), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let tags = s.tags.take().unwrap(); + ffi::gst_event_new_tag(tags.into_ptr()) + }); +} + +pub struct BufferSizeBuilder { + seqnum: Option, + running_time_offset: Option, + fmt: ::Format, + minsize: i64, + maxsize: i64, + async: bool, +} +impl BufferSizeBuilder { + pub fn new(fmt: ::Format, minsize: i64, maxsize: i64, async: bool) -> Self { + Self { + seqnum: None, + running_time_offset: None, + fmt: fmt, + minsize: minsize, + maxsize: maxsize, + async: async, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_buffer_size(s.fmt.to_glib(), s.minsize, s.maxsize, s.async.to_glib())); +} + +pub struct SinkMessageBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + name: &'a str, + msg: &'a ::Message, +} +impl<'a> SinkMessageBuilder<'a> { + pub fn new(name: &'a str, msg: &'a ::Message) -> Self { + Self { + seqnum: None, + running_time_offset: None, + name: name, + msg: msg, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_sink_message(s.name.to_glib_none().0, s.msg.as_mut_ptr())); +} + +#[cfg(feature = "v1_10")] +pub struct StreamGroupDoneBuilder { + seqnum: Option, + running_time_offset: Option, + uid: u32, +} +#[cfg(feature = "v1_10")] +impl StreamGroupDoneBuilder { + pub fn new(uid: u32) -> Self { + Self { + seqnum: None, + running_time_offset: None, + uid: uid, + } + } + + event_builder_generic_impl!(|s| ffi::gst_event_new_stream_group_done(s.uid)); +} + +pub struct EosBuilder { + seqnum: Option, + running_time_offset: Option, +} +impl EosBuilder { + pub fn new() -> Self { + Self { + seqnum: None, + running_time_offset: None, + } + } + + event_builder_generic_impl!(|_| ffi::gst_event_new_eos()); +} + +pub struct TocBuilder { + seqnum: Option, + running_time_offset: Option, + toc: (), + updated: bool, +} +impl TocBuilder { + pub fn new(toc: (), updated: bool) -> Self { + Self { + seqnum: None, + running_time_offset: None, + toc: toc, + updated: updated, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_toc(ptr::null_mut(), s.updated.to_glib())); +} + +pub struct ProtectionBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + system_id: &'a str, + data: &'a ::Buffer, + origin: &'a str, +} +impl<'a> ProtectionBuilder<'a> { + pub fn new(system_id: &'a str, data: &'a ::Buffer, origin: &'a str) -> Self { + Self { + seqnum: None, + running_time_offset: None, + system_id: system_id, + data: data, + origin: origin, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_protection(s.system_id.to_glib_none().0, s.data.as_mut_ptr(), s.origin.to_glib_none().0)); +} + +pub struct SegmentDoneBuilder { + seqnum: Option, + running_time_offset: Option, + fmt: ::Format, + position: i64, +} +impl SegmentDoneBuilder { + pub fn new(fmt: ::Format, position: i64) -> Self { + Self { + seqnum: None, + running_time_offset: None, + fmt: fmt, + position: position, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_segment_done(s.fmt.to_glib(), s.position)); +} + +pub struct GapBuilder { + seqnum: Option, + running_time_offset: Option, + timestamp: u64, + duration: u64, +} +impl GapBuilder { + pub fn new(timestamp: u64, duration: u64) -> Self { + Self { + seqnum: None, + running_time_offset: None, + timestamp: timestamp, + duration: duration, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_gap(s.timestamp, s.duration)); +} + +pub struct QosBuilder { + seqnum: Option, + running_time_offset: Option, + type_: ::QOSType, + proportion: f64, + diff: i64, + timestamp: u64, +} +impl QosBuilder { + pub fn new(type_: ::QOSType, proportion: f64, diff: i64, timestamp: u64) -> Self { + Self { + seqnum: None, + running_time_offset: None, + type_: type_, + proportion: proportion, + diff: diff, + timestamp: timestamp, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_qos(s.type_.to_glib(), s.proportion, s.diff, s.timestamp)); +} + +pub struct SeekBuilder { + seqnum: Option, + running_time_offset: Option, + rate: f64, + fmt: ::Format, + flags: ::SeekFlags, + start_type: ::SeekType, + start: i64, + stop_type: ::SeekType, + stop: i64, +} +impl SeekBuilder { + pub fn new(rate: f64, fmt: ::Format, flags: ::SeekFlags, start_type: ::SeekType, start: i64, stop_type: ::SeekType, stop: i64) -> Self { + Self { + seqnum: None, + running_time_offset: None, + rate: rate, + fmt: fmt, + flags: flags, + start_type, + start, + stop_type, + stop, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_seek(s.rate, s.fmt.to_glib(), s.flags.to_glib(), s.start_type.to_glib(), s.start, s.stop_type.to_glib(), s.stop)); +} + +pub struct NavigationBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl NavigationBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_navigation(structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct LatencyBuilder { + seqnum: Option, + running_time_offset: Option, + latency: u64, +} +impl LatencyBuilder { + pub fn new(latency: u64) -> Self { + Self { + seqnum: None, + running_time_offset: None, + latency: latency, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_latency(s.latency)); +} + +pub struct StepBuilder { + seqnum: Option, + running_time_offset: Option, + fmt: ::Format, + amount: u64, + rate: f64, + flush: bool, + intermediate: bool, +} +impl StepBuilder { + pub fn new(fmt: ::Format, amount: u64, rate: f64, flush: bool, intermediate: bool) -> Self { + Self { + seqnum: None, + running_time_offset: None, + fmt: fmt, + amount: amount, + rate: rate, + flush: flush, + intermediate: intermediate, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_step(s.fmt.to_glib(), s.amount, s.rate, s.flush.to_glib(), s.intermediate.to_glib())); +} + +pub struct ReconfigureBuilder { + seqnum: Option, + running_time_offset: Option, +} +impl ReconfigureBuilder { + pub fn new() -> Self { + Self { + seqnum: None, + running_time_offset: None, + } + } + + event_builder_generic_impl!(|_| ffi::gst_event_new_reconfigure()); +} + +pub struct TocSelectBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + uid: &'a str, +} +impl<'a> TocSelectBuilder<'a> { + pub fn new(uid: &'a str) -> Self { + Self { + seqnum: None, + running_time_offset: None, + uid: uid, + } + } + + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_toc_select(s.uid.to_glib_none().0)); +} + +#[cfg(feature = "v1_10")] +pub struct SelectStreamsBuilder<'a> { + seqnum: Option, + running_time_offset: Option, + streams: &'a [&'a str], +} +#[cfg(feature = "v1_10")] +impl<'a> SelectStreamsBuilder<'a> { + pub fn new(streams: &'a [&'a str]) -> Self { + Self { + seqnum: None, + running_time_offset: None, + streams: streams, + } + } + + event_builder_generic_impl!(|s| ffi::gst_event_new_select_streams(s.to_glib_full())); +} + +pub struct CustomUpstreamBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomUpstreamBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_UPSTREAM, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct CustomDownstreamBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomDownstreamBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_DOWNSTREAM, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct CustomDownstreamOobBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomDownstreamOobBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct CustomDownstreamStickyBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomDownstreamStickyBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct CustomBothBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomBothBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} + +pub struct CustomBothOobBuilder { + seqnum: Option, + running_time_offset: Option, + structure: Option, +} +impl CustomBothOobBuilder { + pub fn new(structure: Structure) -> Self { + Self { + seqnum: None, + running_time_offset: None, + structure: Some(structure), + } + } + + event_builder_generic_impl!(|s: &mut Self| { + let structure = s.structure.take(); + let ev = ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH_OOB, structure.to_glib_none().0); + mem::forget(structure); + + ev + }); +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index a0cb4fd65..33c248048 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -64,6 +64,8 @@ pub mod bufferlist; pub use bufferlist::{BufferList, BufferListRef}; pub mod query; pub use query::{Query, QueryRef, QueryView}; +pub mod event; +pub use event::{Event, EventRef, EventView}; mod element; mod bin; diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 9ed125f56..8287d4d01 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -8,7 +8,6 @@ use ffi; use Object; -use Element; use miniobject::*; use structure::*; use TagList; @@ -18,6 +17,8 @@ use std::mem; use std::ffi::CStr; use glib; +use glib::Cast; +use glib::IsA; use glib::translate::{from_glib, from_glib_none, from_glib_full, mut_override, ToGlibPtr, ToGlib}; #[repr(C)] @@ -49,7 +50,7 @@ impl MessageRef { let type_ = unsafe { (*self.as_ptr()).type_ }; if type_ == ffi::GST_MESSAGE_EOS { - MessageView::Eos + MessageView::Eos(Eos(self)) } else if type_ == ffi::GST_MESSAGE_ERROR { MessageView::Error(Error(self)) } else if type_ == ffi::GST_MESSAGE_WARNING { @@ -63,7 +64,7 @@ impl MessageRef { } else if type_ == ffi::GST_MESSAGE_STATE_CHANGED { MessageView::StateChanged(StateChanged(self)) } else if type_ == ffi::GST_MESSAGE_STATE_DIRTY { - MessageView::StateDirty + MessageView::StateDirty(StateDirty(self)) } else if type_ == ffi::GST_MESSAGE_STEP_DONE { MessageView::StepDone(StepDone(self)) } else if type_ == ffi::GST_MESSAGE_CLOCK_PROVIDE { @@ -77,19 +78,19 @@ impl MessageRef { } else if type_ == ffi::GST_MESSAGE_STREAM_STATUS { MessageView::StreamStatus(StreamStatus(self)) } else if type_ == ffi::GST_MESSAGE_APPLICATION { - MessageView::Application + MessageView::Application(Application(self)) } else if type_ == ffi::GST_MESSAGE_ELEMENT { - MessageView::Element + MessageView::Element(Element(self)) } else if type_ == ffi::GST_MESSAGE_SEGMENT_START { MessageView::SegmentStart(SegmentStart(self)) } else if type_ == ffi::GST_MESSAGE_SEGMENT_DONE { MessageView::SegmentDone(SegmentDone(self)) } else if type_ == ffi::GST_MESSAGE_DURATION_CHANGED { - MessageView::DurationChanged + MessageView::DurationChanged(DurationChanged(self)) } else if type_ == ffi::GST_MESSAGE_LATENCY { - MessageView::Latency + MessageView::Latency(Latency(self)) } else if type_ == ffi::GST_MESSAGE_ASYNC_START { - MessageView::AsyncStart + MessageView::AsyncStart(AsyncStart(self)) } else if type_ == ffi::GST_MESSAGE_ASYNC_DONE { MessageView::AsyncDone(AsyncDone(self)) } else if type_ == ffi::GST_MESSAGE_REQUEST_STATE { @@ -125,39 +126,39 @@ impl MessageRef { } } - pub fn new_eos<'a>() -> EosBuilder<'a> { + pub fn new_eos() -> EosBuilder { EosBuilder::new() } - pub fn new_error<'a>(error: &'a glib::Error) -> ErrorBuilder<'a> { + pub fn new_error(error: &glib::Error) -> ErrorBuilder { ErrorBuilder::new(error) } - pub fn new_warning<'a>(error: &'a glib::Error) -> WarningBuilder<'a> { + pub fn new_warning(error: &glib::Error) -> WarningBuilder { WarningBuilder::new(error) } - pub fn new_info<'a>(error: &'a glib::Error) -> InfoBuilder<'a> { + pub fn new_info(error: &glib::Error) -> InfoBuilder { InfoBuilder::new(error) } - pub fn new_tag<'a>(tags: &'a TagList) -> TagBuilder<'a> { + pub fn new_tag(tags: &TagList) -> TagBuilder { TagBuilder::new(tags) } - pub fn new_buffering<'a>(percent: i32) -> BufferingBuilder<'a> { + pub fn new_buffering(percent: i32) -> BufferingBuilder { BufferingBuilder::new(percent) } - pub fn new_state_changed<'a>(old: ::State, new: ::State, pending: ::State) -> StateChangedBuilder<'a> { + pub fn new_state_changed(old: ::State, new: ::State, pending: ::State) -> StateChangedBuilder { StateChangedBuilder::new(old, new, pending) } - pub fn new_state_dirty<'a>() -> StateDirtyBuilder<'a> { + pub fn new_state_dirty() -> StateDirtyBuilder { StateDirtyBuilder::new() } - pub fn new_step_done<'a>( + pub fn new_step_done( format: ::Format, amount: u64, rate: f64, @@ -165,106 +166,106 @@ impl MessageRef { intermediate: bool, duration: u64, eos: bool - ) -> StepDoneBuilder<'a> { + ) -> StepDoneBuilder { StepDoneBuilder::new(format, amount, rate, flush, intermediate, duration, eos) } - pub fn new_clock_provide<'a>(clock: &'a ::Clock, ready: bool) -> ClockProvideBuilder<'a> { + pub fn new_clock_provide(clock: &::Clock, ready: bool) -> ClockProvideBuilder { ClockProvideBuilder::new(clock, ready) } - pub fn new_clock_lost<'a>(clock: &'a ::Clock) -> ClockLostBuilder<'a> { + pub fn new_clock_lost(clock: &::Clock) -> ClockLostBuilder { ClockLostBuilder::new(clock) } - pub fn new_new_clock<'a>(clock: &'a ::Clock) -> NewClockBuilder<'a> { + pub fn new_new_clock(clock: &::Clock) -> NewClockBuilder { NewClockBuilder::new(clock) } - pub fn new_structure_change<'a>(type_: ::StructureChangeType, owner: &'a ::Element, busy: bool) -> StructureChangeBuilder<'a> { + pub fn new_structure_change(type_: ::StructureChangeType, owner: &::Element, busy: bool) -> StructureChangeBuilder { StructureChangeBuilder::new(type_, owner, busy) } - pub fn new_stream_status<'a>(type_: ::StreamStatusType, owner: &'a ::Element) -> StreamStatusBuilder<'a> { + pub fn new_stream_status(type_: ::StreamStatusType, owner: &::Element) -> StreamStatusBuilder { StreamStatusBuilder::new(type_, owner) } - pub fn new_application<'a>(structure: ::Structure) -> ApplicationBuilder<'a> { + pub fn new_application(structure: ::Structure) -> ApplicationBuilder { ApplicationBuilder::new(structure) } - pub fn new_element<'a>(structure: ::Structure) -> ElementBuilder<'a> { + pub fn new_element(structure: ::Structure) -> ElementBuilder { ElementBuilder::new(structure) } - pub fn new_segment_start<'a>(format: ::Format, position: i64) -> SegmentStartBuilder<'a> { + pub fn new_segment_start(format: ::Format, position: i64) -> SegmentStartBuilder { SegmentStartBuilder::new(format, position) } - pub fn new_segment_done<'a>(format: ::Format, position: i64) -> SegmentDoneBuilder<'a> { + pub fn new_segment_done(format: ::Format, position: i64) -> SegmentDoneBuilder { SegmentDoneBuilder::new(format, position) } - pub fn new_duration_changed<'a>() -> DurationChangedBuilder<'a> { + pub fn new_duration_changed() -> DurationChangedBuilder { DurationChangedBuilder::new() } - pub fn new_latency<'a>() -> LatencyBuilder<'a> { + pub fn new_latency() -> LatencyBuilder { LatencyBuilder::new() } - pub fn new_async_start<'a>() -> AsyncStartBuilder<'a> { + pub fn new_async_start() -> AsyncStartBuilder { AsyncStartBuilder::new() } - pub fn new_async_done<'a>(running_time: u64) -> AsyncDoneBuilder<'a> { + pub fn new_async_done(running_time: u64) -> AsyncDoneBuilder { AsyncDoneBuilder::new(running_time) } - pub fn new_step_start<'a>(active: bool, + pub fn new_step_start(active: bool, format: ::Format, amount: u64, rate: f64, flush: bool, intermediate: bool, - ) -> StepStartBuilder<'a> { + ) -> StepStartBuilder { StepStartBuilder::new(active, format, amount, rate, flush, intermediate) } - pub fn new_qos_builder<'a>(live: bool, + pub fn new_qos_builder(live: bool, running_time: u64, stream_time: u64, timestamp: u64, duration: u64, - ) -> QosBuilder<'a> { + ) -> QosBuilder { QosBuilder::new(live, running_time, stream_time, timestamp, duration) } - pub fn new_toc<'a>(toc: (), updated: bool) -> TocBuilder<'a> { + pub fn new_toc(toc: (), updated: bool) -> TocBuilder { TocBuilder::new(toc, updated) } - pub fn new_reset_time<'a>(running_time: u64) -> ResetTimeBuilder<'a> { + pub fn new_reset_time(running_time: u64) -> ResetTimeBuilder { ResetTimeBuilder::new(running_time) } - pub fn new_stream_start<'a>() -> StreamStartBuilder<'a> { + pub fn new_stream_start() -> StreamStartBuilder { StreamStartBuilder::new() } - pub fn new_need_context<'a>(context_type: &'a str) -> NeedContextBuilder<'a> { + pub fn new_need_context(context_type: &str) -> NeedContextBuilder { NeedContextBuilder::new(context_type) } - pub fn new_have_context<'a>(context: ()) -> HaveContextBuilder<'a> { + pub fn new_have_context(context: ()) -> HaveContextBuilder { HaveContextBuilder::new(context) } - pub fn new_device_added<'a>(device: &'a ::Device) -> DeviceAddedBuilder<'a> { + pub fn new_device_added(device: &::Device) -> DeviceAddedBuilder { DeviceAddedBuilder::new(device) } - pub fn new_device_removed<'a>(device: &'a ::Device) -> DeviceRemovedBuilder<'a> { + pub fn new_device_removed(device: &::Device) -> DeviceRemovedBuilder { DeviceRemovedBuilder::new(device) } @@ -274,12 +275,12 @@ impl MessageRef { } #[cfg(feature = "v1_10")] - pub fn new_stream_collection<'a>(collection: &'a ::StreamCollection) -> StreamCollectionBuilder<'a> { + pub fn new_stream_collection(collection: &::StreamCollection) -> StreamCollectionBuilder { StreamCollectionBuilder::new(collection) } #[cfg(feature = "v1_10")] - pub fn new_streams_selected<'a>(collection: &'a ::StreamCollection) -> StreamsSelectedBuilder<'a> { + pub fn new_streams_selected(collection: &::StreamCollection) -> StreamsSelectedBuilder { StreamsSelectedBuilder::new(collection) } @@ -299,27 +300,27 @@ impl glib::types::StaticType for GstRc { } pub enum MessageView<'a> { - Eos, + Eos(Eos<'a>), Error(Error<'a>), Warning(Warning<'a>), Info(Info<'a>), Tag(Tag<'a>), Buffering(Buffering<'a>), StateChanged(StateChanged<'a>), - StateDirty, + StateDirty(StateDirty<'a>), StepDone(StepDone<'a>), ClockProvide(ClockProvide<'a>), ClockLost(ClockLost<'a>), NewClock(NewClock<'a>), StructureChange(StructureChange<'a>), StreamStatus(StreamStatus<'a>), - Application, - Element, + Application(Application<'a>), + Element(Element<'a>), SegmentStart(SegmentStart<'a>), SegmentDone(SegmentDone<'a>), - DurationChanged, - Latency, - AsyncStart, + DurationChanged(DurationChanged<'a>), + Latency(Latency<'a>), + AsyncStart(AsyncStart<'a>), AsyncDone(AsyncDone<'a>), RequestState(RequestState<'a>), StepStart(StepStart<'a>), @@ -340,6 +341,8 @@ pub enum MessageView<'a> { __NonExhaustive, } +pub struct Eos<'a>(&'a MessageRef); + pub struct Error<'a>(&'a MessageRef); impl<'a> Error<'a> { pub fn get_error(&self) -> glib::Error { @@ -543,6 +546,8 @@ impl<'a> StateChanged<'a> { } } +pub struct StateDirty<'a>(&'a MessageRef); + pub struct StepDone<'a>(&'a MessageRef); impl<'a> StepDone<'a> { pub fn get(&self) -> (::Format, u64, f64, bool, bool, u64, bool) { @@ -631,7 +636,7 @@ impl<'a> NewClock<'a> { pub struct StructureChange<'a>(&'a MessageRef); impl<'a> StructureChange<'a> { - pub fn get(&self) -> (::StructureChangeType, Option, bool) { + pub fn get(&self) -> (::StructureChangeType, Option<::Element>, bool) { unsafe { let mut type_ = mem::uninitialized(); let mut owner = ptr::null_mut(); @@ -651,7 +656,7 @@ impl<'a> StructureChange<'a> { pub struct StreamStatus<'a>(&'a MessageRef); impl<'a> StreamStatus<'a> { - pub fn get(&self) -> (::StreamStatusType, Option) { + pub fn get(&self) -> (::StreamStatusType, Option<::Element>) { unsafe { let mut type_ = mem::uninitialized(); let mut owner = ptr::null_mut(); @@ -671,6 +676,10 @@ impl<'a> StreamStatus<'a> { } } +pub struct Application<'a>(&'a MessageRef); + +pub struct Element<'a>(&'a MessageRef); + pub struct SegmentStart<'a>(&'a MessageRef); impl<'a> SegmentStart<'a> { pub fn get(&self) -> (::Format, i64) { @@ -699,6 +708,12 @@ impl<'a> SegmentDone<'a> { } } +pub struct DurationChanged<'a>(&'a MessageRef); + +pub struct Latency<'a>(&'a MessageRef); + +pub struct AsyncStart<'a>(&'a MessageRef); + pub struct AsyncDone<'a>(&'a MessageRef); impl<'a> AsyncDone<'a> { pub fn get_running_time(&self) -> u64 { @@ -1043,9 +1058,12 @@ impl<'a> Redirect<'a> { macro_rules! message_builder_generic_impl { ($new_fn:expr) => { - pub fn src(self, src: Option<&'a Object>) -> Self { + pub fn src<'b, T: IsA + Cast + Clone>(self, src: Option<&'b T>) -> Self { Self { - src: src, + src: src.map(|o| { + let o = (*o).clone(); + o.upcast::() + }), .. self } } @@ -1072,11 +1090,11 @@ macro_rules! message_builder_generic_impl { } } -pub struct EosBuilder<'a> { - src: Option<&'a Object>, +pub struct EosBuilder { + src: Option, seqnum: Option, } -impl<'a> EosBuilder<'a> { +impl EosBuilder { pub fn new() -> Self { Self { src: None, @@ -1088,7 +1106,7 @@ impl<'a> EosBuilder<'a> { } pub struct ErrorBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, error: &'a glib::Error, debug: Option<&'a str>, @@ -1147,7 +1165,7 @@ impl<'a> ErrorBuilder<'a> { } pub struct WarningBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, error: &'a glib::Error, debug: Option<&'a str>, @@ -1206,7 +1224,7 @@ impl<'a> WarningBuilder<'a> { } pub struct InfoBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, error: &'a glib::Error, debug: Option<&'a str>, @@ -1265,7 +1283,7 @@ impl<'a> InfoBuilder<'a> { } pub struct TagBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, tags: &'a TagList, } @@ -1283,13 +1301,13 @@ impl<'a> TagBuilder<'a> { }); } -pub struct BufferingBuilder<'a> { - src: Option<&'a Object>, +pub struct BufferingBuilder { + src: Option, seqnum: Option, percent: i32, stats: Option<(::BufferingMode, i32, i32, i64)>, } -impl<'a> BufferingBuilder<'a> { +impl BufferingBuilder { pub fn new(percent: i32) -> Self { Self { src: None, @@ -1329,14 +1347,14 @@ impl<'a> BufferingBuilder<'a> { }); } -pub struct StateChangedBuilder<'a> { - src: Option<&'a Object>, +pub struct StateChangedBuilder { + src: Option, seqnum: Option, old: ::State, new: ::State, pending: ::State, } -impl<'a> StateChangedBuilder<'a> { +impl StateChangedBuilder { pub fn new(old: ::State, new: ::State, pending: ::State) -> Self { Self { src: None, @@ -1357,11 +1375,11 @@ impl<'a> StateChangedBuilder<'a> { }); } -pub struct StateDirtyBuilder<'a> { - src: Option<&'a Object>, +pub struct StateDirtyBuilder { + src: Option, seqnum: Option, } -impl<'a> StateDirtyBuilder<'a> { +impl StateDirtyBuilder { pub fn new() -> Self { Self { src: None, @@ -1372,8 +1390,8 @@ impl<'a> StateDirtyBuilder<'a> { message_builder_generic_impl!(|_, src| ffi::gst_message_new_state_dirty(src)); } -pub struct StepDoneBuilder<'a> { - src: Option<&'a Object>, +pub struct StepDoneBuilder { + src: Option, seqnum: Option, format: ::Format, amount: u64, @@ -1383,7 +1401,7 @@ pub struct StepDoneBuilder<'a> { duration: u64, eos: bool, } -impl<'a> StepDoneBuilder<'a> { +impl StepDoneBuilder { pub fn new( format: ::Format, amount: u64, @@ -1421,7 +1439,7 @@ impl<'a> StepDoneBuilder<'a> { } pub struct ClockProvideBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, clock: &'a ::Clock, ready: bool, @@ -1442,7 +1460,7 @@ impl<'a> ClockProvideBuilder<'a> { } pub struct ClockLostBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, clock: &'a ::Clock, } @@ -1461,7 +1479,7 @@ impl<'a> ClockLostBuilder<'a> { } pub struct NewClockBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, clock: &'a ::Clock, } @@ -1480,7 +1498,7 @@ impl<'a> NewClockBuilder<'a> { } pub struct StructureChangeBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, type_: ::StructureChangeType, owner: &'a ::Element, @@ -1508,7 +1526,7 @@ impl<'a> StructureChangeBuilder<'a> { } pub struct StreamStatusBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, type_: ::StreamStatusType, owner: &'a ::Element, @@ -1542,12 +1560,12 @@ impl<'a> StreamStatusBuilder<'a> { }); } -pub struct ApplicationBuilder<'a> { - src: Option<&'a Object>, +pub struct ApplicationBuilder { + src: Option, seqnum: Option, structure: Option<::Structure>, } -impl<'a> ApplicationBuilder<'a> { +impl ApplicationBuilder { pub fn new(structure: ::Structure) -> Self { Self { src: None, @@ -1561,12 +1579,12 @@ impl<'a> ApplicationBuilder<'a> { }); } -pub struct ElementBuilder<'a> { - src: Option<&'a Object>, +pub struct ElementBuilder { + src: Option, seqnum: Option, structure: Option<::Structure>, } -impl<'a> ElementBuilder<'a> { +impl ElementBuilder { pub fn new(structure: ::Structure) -> Self { Self { src: None, @@ -1580,13 +1598,13 @@ impl<'a> ElementBuilder<'a> { }); } -pub struct SegmentStartBuilder<'a> { - src: Option<&'a Object>, +pub struct SegmentStartBuilder { + src: Option, seqnum: Option, format: ::Format, position: i64, } -impl<'a> SegmentStartBuilder<'a> { +impl SegmentStartBuilder { pub fn new(format: ::Format, position: i64) -> Self { Self { src: None, @@ -1601,13 +1619,13 @@ impl<'a> SegmentStartBuilder<'a> { }); } -pub struct SegmentDoneBuilder<'a> { - src: Option<&'a Object>, +pub struct SegmentDoneBuilder { + src: Option, seqnum: Option, format: ::Format, position: i64, } -impl<'a> SegmentDoneBuilder<'a> { +impl SegmentDoneBuilder { pub fn new(format: ::Format, position: i64) -> Self { Self { src: None, @@ -1622,11 +1640,11 @@ impl<'a> SegmentDoneBuilder<'a> { }); } -pub struct DurationChangedBuilder<'a> { - src: Option<&'a Object>, +pub struct DurationChangedBuilder { + src: Option, seqnum: Option, } -impl<'a> DurationChangedBuilder<'a> { +impl DurationChangedBuilder { pub fn new() -> Self { Self { src: None, @@ -1637,11 +1655,11 @@ impl<'a> DurationChangedBuilder<'a> { message_builder_generic_impl!(|_, src| ffi::gst_message_new_duration_changed(src)); } -pub struct LatencyBuilder<'a> { - src: Option<&'a Object>, +pub struct LatencyBuilder { + src: Option, seqnum: Option, } -impl<'a> LatencyBuilder<'a> { +impl LatencyBuilder { pub fn new() -> Self { Self { src: None, @@ -1652,11 +1670,11 @@ impl<'a> LatencyBuilder<'a> { message_builder_generic_impl!(|_, src| ffi::gst_message_new_latency(src)); } -pub struct AsyncStartBuilder<'a> { - src: Option<&'a Object>, +pub struct AsyncStartBuilder { + src: Option, seqnum: Option, } -impl<'a> AsyncStartBuilder<'a> { +impl AsyncStartBuilder { pub fn new() -> Self { Self { src: None, @@ -1667,12 +1685,12 @@ impl<'a> AsyncStartBuilder<'a> { message_builder_generic_impl!(|_, src| ffi::gst_message_new_async_start(src)); } -pub struct AsyncDoneBuilder<'a> { - src: Option<&'a Object>, +pub struct AsyncDoneBuilder { + src: Option, seqnum: Option, running_time: u64, } -impl<'a> AsyncDoneBuilder<'a> { +impl AsyncDoneBuilder { pub fn new(running_time: u64) -> Self { Self { src: None, @@ -1686,12 +1704,12 @@ impl<'a> AsyncDoneBuilder<'a> { }); } -pub struct RequestStateBuilder<'a> { - src: Option<&'a Object>, +pub struct RequestStateBuilder { + src: Option, seqnum: Option, state: ::State, } -impl<'a> RequestStateBuilder<'a> { +impl RequestStateBuilder { pub fn new(state: ::State) -> Self { Self { src: None, @@ -1705,8 +1723,8 @@ impl<'a> RequestStateBuilder<'a> { }); } -pub struct StepStartBuilder<'a> { - src: Option<&'a Object>, +pub struct StepStartBuilder { + src: Option, seqnum: Option, active: bool, format: ::Format, @@ -1715,7 +1733,7 @@ pub struct StepStartBuilder<'a> { flush: bool, intermediate: bool, } -impl<'a> StepStartBuilder<'a> { +impl StepStartBuilder { pub fn new( active: bool, format: ::Format, @@ -1749,8 +1767,8 @@ impl<'a> StepStartBuilder<'a> { }); } -pub struct QosBuilder<'a> { - src: Option<&'a Object>, +pub struct QosBuilder { + src: Option, seqnum: Option, live: bool, running_time: u64, @@ -1760,7 +1778,7 @@ pub struct QosBuilder<'a> { values: Option<(i64, f64, i32)>, stats: Option<(::Format, u64, u64)>, } -impl<'a> QosBuilder<'a> { +impl QosBuilder { pub fn new( live: bool, running_time: u64, @@ -1815,7 +1833,7 @@ impl<'a> QosBuilder<'a> { } pub struct ProgressBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, type_: ::ProgressType, code: Option<&'a str>, @@ -1857,13 +1875,13 @@ impl<'a> ProgressBuilder<'a> { } // TODO Toc -pub struct TocBuilder<'a> { - src: Option<&'a Object>, +pub struct TocBuilder { + src: Option, seqnum: Option, toc: (), updated: bool, } -impl<'a> TocBuilder<'a> { +impl TocBuilder { pub fn new(toc: () /* &'a Toc */, updated: bool) -> Self { Self { src: None, @@ -1882,12 +1900,12 @@ impl<'a> TocBuilder<'a> { }); } -pub struct ResetTimeBuilder<'a> { - src: Option<&'a Object>, +pub struct ResetTimeBuilder { + src: Option, seqnum: Option, running_time: u64, } -impl<'a> ResetTimeBuilder<'a> { +impl ResetTimeBuilder { pub fn new(running_time: u64) -> Self { Self { src: None, @@ -1901,12 +1919,12 @@ impl<'a> ResetTimeBuilder<'a> { }); } -pub struct StreamStartBuilder<'a> { - src: Option<&'a Object>, +pub struct StreamStartBuilder { + src: Option, seqnum: Option, group_id: Option, } -impl<'a> StreamStartBuilder<'a> { +impl StreamStartBuilder { pub fn new() -> Self { Self { src: None, @@ -1932,7 +1950,7 @@ impl<'a> StreamStartBuilder<'a> { } pub struct NeedContextBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, context_type: &'a str, } @@ -1951,12 +1969,12 @@ impl<'a> NeedContextBuilder<'a> { } // TODO Context -pub struct HaveContextBuilder<'a> { - src: Option<&'a Object>, +pub struct HaveContextBuilder { + src: Option, seqnum: Option, context: (), } -impl<'a> HaveContextBuilder<'a> { +impl HaveContextBuilder { pub fn new(context: () /* ::Context */) -> Self { Self { src: None, @@ -1971,7 +1989,7 @@ impl<'a> HaveContextBuilder<'a> { } pub struct DeviceAddedBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, device: &'a ::Device, } @@ -1990,7 +2008,7 @@ impl<'a> DeviceAddedBuilder<'a> { } pub struct DeviceRemovedBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, device: &'a ::Device, } @@ -2009,7 +2027,7 @@ impl<'a> DeviceRemovedBuilder<'a> { } pub struct PropertyNotifyBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, property_name: &'a str, value: &'a glib::Value, @@ -2034,10 +2052,10 @@ impl<'a> PropertyNotifyBuilder<'a> { }); } +#[cfg(feature = "v1_10")] pub struct StreamCollectionBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, - #[cfg(feature = "v1_10")] collection: &'a ::StreamCollection, } #[cfg(feature = "v1_10")] @@ -2055,8 +2073,9 @@ impl<'a> StreamCollectionBuilder<'a> { }); } +#[cfg(feature = "v1_10")] pub struct StreamsSelectedBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, #[cfg(feature = "v1_10")] collection: &'a ::StreamCollection, @@ -2093,7 +2112,7 @@ impl<'a> StreamsSelectedBuilder<'a> { } pub struct RedirectBuilder<'a> { - src: Option<&'a Object>, + src: Option, seqnum: Option, location: &'a str, tag_list: Option<&'a TagList>,