Event, Message & Query: allow dereferencing concrete types to access generic type methods

Implement `deref` for concrete derivatives of `Event`, `Message` and `Query`. This allows accessing generic methods such as `is_sticky` for events, `get_seqnum` for messages or `is_serialized` for queries and `get_structure` for all.
This commit is contained in:
fengalin 2018-01-29 11:31:12 +01:00 committed by Sebastian Dröge
parent 86812c1a53
commit 2d1218e6d6
3 changed files with 284 additions and 419 deletions

View file

@ -16,6 +16,7 @@ use std::mem;
use std::cmp; use std::cmp;
use std::fmt; use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use std::ops::Deref;
use glib; use glib;
use glib::value::ToSendValue; use glib::value::ToSendValue;
@ -494,28 +495,42 @@ pub enum EventView<'a> {
__NonExhaustive, __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> { impl<'a> FlushStop<'a> {
pub fn get_reset_time(&self) -> bool { pub fn get_reset_time(&self) -> bool {
unsafe { unsafe {
let mut reset_time = mem::uninitialized(); 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) from_glib(reset_time)
} }
} }
} }
pub struct StreamStart<'a>(&'a EventRef); declare_concrete_event!(StreamStart);
impl<'a> StreamStart<'a> { impl<'a> StreamStart<'a> {
pub fn get_stream_id(&self) -> &'a str { pub fn get_stream_id(&self) -> &'a str {
unsafe { unsafe {
let mut stream_id = ptr::null(); 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() CStr::from_ptr(stream_id).to_str().unwrap()
} }
} }
@ -524,7 +539,7 @@ impl<'a> StreamStart<'a> {
unsafe { unsafe {
let mut stream_flags = mem::uninitialized(); 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) from_glib(stream_flags)
} }
@ -534,63 +549,63 @@ impl<'a> StreamStart<'a> {
unsafe { unsafe {
let mut group_id = mem::uninitialized(); 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) from_glib(group_id)
} }
} }
} }
pub struct Caps<'a>(&'a EventRef); declare_concrete_event!(Caps);
impl<'a> Caps<'a> { impl<'a> Caps<'a> {
pub fn get_caps(&self) -> &'a ::CapsRef { pub fn get_caps(&self) -> &'a ::CapsRef {
unsafe { unsafe {
let mut caps = ptr::null_mut(); 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) ::CapsRef::from_ptr(caps)
} }
} }
} }
pub struct Segment<'a>(&'a EventRef); declare_concrete_event!(Segment);
impl<'a> Segment<'a> { impl<'a> Segment<'a> {
pub fn get_segment(&self) -> &'a ::Segment { pub fn get_segment(&self) -> &'a ::Segment {
unsafe { unsafe {
let mut segment = ptr::null(); 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) &*(segment as *mut ffi::GstSegment as *mut ::Segment)
} }
} }
} }
pub struct StreamCollection<'a>(&'a EventRef); declare_concrete_event!(StreamCollection);
impl<'a> StreamCollection<'a> { impl<'a> StreamCollection<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_stream_collection(&self) -> ::StreamCollection { pub fn get_stream_collection(&self) -> ::StreamCollection {
unsafe { unsafe {
let mut stream_collection = ptr::null_mut(); 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) from_glib_full(stream_collection)
} }
} }
} }
pub struct Tag<'a>(&'a EventRef); declare_concrete_event!(Tag);
impl<'a> Tag<'a> { impl<'a> Tag<'a> {
pub fn get_tag(&self) -> &'a ::TagListRef { pub fn get_tag(&self) -> &'a ::TagListRef {
unsafe { unsafe {
let mut tags = ptr::null_mut(); 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) ::TagListRef::from_ptr(tags)
} }
} }
} }
pub struct BufferSize<'a>(&'a EventRef); declare_concrete_event!(BufferSize);
impl<'a> BufferSize<'a> { impl<'a> BufferSize<'a> {
pub fn get(&self) -> (GenericFormattedValue, GenericFormattedValue, bool) { pub fn get(&self) -> (GenericFormattedValue, GenericFormattedValue, bool) {
unsafe { unsafe {
@ -600,7 +615,7 @@ impl<'a> BufferSize<'a> {
let mut async = mem::uninitialized(); let mut async = mem::uninitialized();
ffi::gst_event_parse_buffer_size( ffi::gst_event_parse_buffer_size(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
&mut minsize, &mut minsize,
&mut maxsize, &mut maxsize,
@ -615,48 +630,48 @@ impl<'a> BufferSize<'a> {
} }
} }
pub struct SinkMessage<'a>(&'a EventRef); declare_concrete_event!(SinkMessage);
impl<'a> SinkMessage<'a> { impl<'a> SinkMessage<'a> {
pub fn get_message(&self) -> ::Message { pub fn get_message(&self) -> ::Message {
unsafe { unsafe {
let mut msg = ptr::null_mut(); 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) from_glib_full(msg)
} }
} }
} }
pub struct StreamGroupDone<'a>(&'a EventRef); declare_concrete_event!(StreamGroupDone);
impl<'a> StreamGroupDone<'a> { impl<'a> StreamGroupDone<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_group_id(&self) -> GroupId { pub fn get_group_id(&self) -> GroupId {
unsafe { unsafe {
let mut group_id = mem::uninitialized(); 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) 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> { impl<'a> Toc<'a> {
pub fn get_toc(&self) -> (&'a ::TocRef, bool) { pub fn get_toc(&self) -> (&'a ::TocRef, bool) {
unsafe { unsafe {
let mut toc = ptr::null_mut(); let mut toc = ptr::null_mut();
let mut updated = mem::uninitialized(); 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)) (::TocRef::from_ptr(toc), from_glib(updated))
} }
} }
} }
pub struct Protection<'a>(&'a EventRef); declare_concrete_event!(Protection);
impl<'a> Protection<'a> { impl<'a> Protection<'a> {
pub fn get(&self) -> (&'a str, &'a ::BufferRef, Option<&'a str>) { pub fn get(&self) -> (&'a str, &'a ::BufferRef, Option<&'a str>) {
unsafe { unsafe {
@ -665,7 +680,7 @@ impl<'a> Protection<'a> {
let mut origin = ptr::null(); let mut origin = ptr::null();
ffi::gst_event_parse_protection( ffi::gst_event_parse_protection(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut system_id, &mut system_id,
&mut buffer, &mut buffer,
&mut origin, &mut origin,
@ -684,35 +699,35 @@ impl<'a> Protection<'a> {
} }
} }
pub struct SegmentDone<'a>(&'a EventRef); declare_concrete_event!(SegmentDone);
impl<'a> SegmentDone<'a> { impl<'a> SegmentDone<'a> {
pub fn get(&self) -> GenericFormattedValue { pub fn get(&self) -> GenericFormattedValue {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
let mut position = 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) GenericFormattedValue::new(from_glib(fmt), position)
} }
} }
} }
pub struct Gap<'a>(&'a EventRef); declare_concrete_event!(Gap);
impl<'a> Gap<'a> { impl<'a> Gap<'a> {
pub fn get(&self) -> (::ClockTime, ::ClockTime) { pub fn get(&self) -> (::ClockTime, ::ClockTime) {
unsafe { unsafe {
let mut timestamp = mem::uninitialized(); let mut timestamp = mem::uninitialized();
let mut duration = 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)) (from_glib(timestamp), from_glib(duration))
} }
} }
} }
pub struct Qos<'a>(&'a EventRef); declare_concrete_event!(Qos);
impl<'a> Qos<'a> { impl<'a> Qos<'a> {
pub fn get(&self) -> (::QOSType, f64, i64, ::ClockTime) { pub fn get(&self) -> (::QOSType, f64, i64, ::ClockTime) {
unsafe { unsafe {
@ -722,7 +737,7 @@ impl<'a> Qos<'a> {
let mut timestamp = mem::uninitialized(); let mut timestamp = mem::uninitialized();
ffi::gst_event_parse_qos( ffi::gst_event_parse_qos(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut type_, &mut type_,
&mut proportion, &mut proportion,
&mut diff, &mut diff,
@ -734,7 +749,7 @@ impl<'a> Qos<'a> {
} }
} }
pub struct Seek<'a>(&'a EventRef); declare_concrete_event!(Seek);
impl<'a> Seek<'a> { impl<'a> Seek<'a> {
pub fn get( pub fn get(
&self, &self,
@ -756,7 +771,7 @@ impl<'a> Seek<'a> {
let mut stop = mem::uninitialized(); let mut stop = mem::uninitialized();
ffi::gst_event_parse_seek( ffi::gst_event_parse_seek(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut rate, &mut rate,
&mut fmt, &mut fmt,
&mut flags, &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> { impl<'a> Latency<'a> {
pub fn get_latency(&self) -> ::ClockTime { pub fn get_latency(&self) -> ::ClockTime {
unsafe { unsafe {
let mut latency = mem::uninitialized(); 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) from_glib(latency)
} }
} }
} }
pub struct Step<'a>(&'a EventRef); declare_concrete_event!(Step);
impl<'a> Step<'a> { impl<'a> Step<'a> {
pub fn get(&self) -> (GenericFormattedValue, f64, bool, bool) { pub fn get(&self) -> (GenericFormattedValue, f64, bool, bool) {
unsafe { unsafe {
@ -804,7 +819,7 @@ impl<'a> Step<'a> {
let mut intermediate = mem::uninitialized(); let mut intermediate = mem::uninitialized();
ffi::gst_event_parse_step( ffi::gst_event_parse_step(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
&mut amount, &mut amount,
&mut rate, &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> { impl<'a> TocSelect<'a> {
pub fn get_uid(&self) -> &'a str { pub fn get_uid(&self) -> &'a str {
unsafe { unsafe {
let mut uid = ptr::null_mut(); 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() CStr::from_ptr(uid).to_str().unwrap()
} }
} }
} }
pub struct SelectStreams<'a>(&'a EventRef); declare_concrete_event!(SelectStreams);
impl<'a> SelectStreams<'a> { impl<'a> SelectStreams<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_streams(&self) -> Vec<String> { pub fn get_streams(&self) -> Vec<String> {
unsafe { unsafe {
let mut streams = ptr::null_mut(); 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) FromGlibPtrContainer::from_glib_full(streams)
} }
} }
} }
pub struct CustomUpstream<'a>(&'a EventRef); declare_concrete_event!(CustomUpstream);
pub struct CustomDownstream<'a>(&'a EventRef); declare_concrete_event!(CustomDownstream);
pub struct CustomDownstreamOob<'a>(&'a EventRef); declare_concrete_event!(CustomDownstreamOob);
pub struct CustomDownstreamSticky<'a>(&'a EventRef); declare_concrete_event!(CustomDownstreamSticky);
pub struct CustomBoth<'a>(&'a EventRef); declare_concrete_event!(CustomBoth);
pub struct CustomBothOob<'a>(&'a EventRef); declare_concrete_event!(CustomBothOob);
macro_rules! event_builder_generic_impl { macro_rules! event_builder_generic_impl {
($new_fn:expr) => { ($new_fn:expr) => {
@ -1679,7 +1694,8 @@ mod tests {
let flush_start_evt = Event::new_flush_start().build(); let flush_start_evt = Event::new_flush_start().build();
match flush_start_evt.view() { match flush_start_evt.view() {
EventView::FlushStart(flush_start_evt) => { 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(_)"), _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"),
} }
@ -1689,8 +1705,8 @@ mod tests {
.build(); .build();
match flush_start_evt.view() { match flush_start_evt.view() {
EventView::FlushStart(flush_start_evt) => { EventView::FlushStart(flush_start_evt) => {
assert!(flush_start_evt.0.get_structure().is_some()); assert!(flush_start_evt.get_structure().is_some());
if let Some(other_fields) = flush_start_evt.0.get_structure() { if let Some(other_fields) = flush_start_evt.get_structure() {
assert!(other_fields.has_field("extra-field")); assert!(other_fields.has_field("extra-field"));
} }
}, },
@ -1704,8 +1720,8 @@ mod tests {
match flush_stop_evt.view() { match flush_stop_evt.view() {
EventView::FlushStop(flush_stop_evt) => { EventView::FlushStop(flush_stop_evt) => {
assert_eq!(flush_stop_evt.get_reset_time(), true); assert_eq!(flush_stop_evt.get_reset_time(), true);
assert!(flush_stop_evt.0.get_structure().is_some()); assert!(flush_stop_evt.get_structure().is_some());
if let Some(other_fields) = flush_stop_evt.0.get_structure() { if let Some(other_fields) = flush_stop_evt.get_structure() {
assert!(other_fields.has_field("extra-field")); assert!(other_fields.has_field("extra-field"));
} }
} }

View file

@ -20,6 +20,7 @@ use std::ptr;
use std::mem; use std::mem;
use std::fmt; use std::fmt;
use std::ffi::CStr; use std::ffi::CStr;
use std::ops::Deref;
use glib; use glib;
use glib::Cast; use glib::Cast;
@ -420,15 +421,29 @@ pub enum MessageView<'a> {
__NonExhaustive, __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> { impl<'a> Error<'a> {
pub fn get_error(&self) -> glib::Error { pub fn get_error(&self) -> glib::Error {
unsafe { unsafe {
let mut error = ptr::null_mut(); 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) from_glib_full(error)
} }
@ -438,7 +453,7 @@ impl<'a> Error<'a> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); 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) from_glib_full(debug)
} }
@ -449,7 +464,7 @@ impl<'a> Error<'a> {
unsafe { unsafe {
let mut details = ptr::null(); 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() { if details.is_null() {
None None
@ -460,13 +475,13 @@ impl<'a> Error<'a> {
} }
} }
pub struct Warning<'a>(&'a MessageRef); declare_concrete_message!(Warning);
impl<'a> Warning<'a> { impl<'a> Warning<'a> {
pub fn get_error(&self) -> glib::Error { pub fn get_error(&self) -> glib::Error {
unsafe { unsafe {
let mut error = ptr::null_mut(); 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) from_glib_full(error)
} }
@ -476,7 +491,7 @@ impl<'a> Warning<'a> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); 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) from_glib_full(debug)
} }
@ -487,7 +502,7 @@ impl<'a> Warning<'a> {
unsafe { unsafe {
let mut details = ptr::null(); 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() { if details.is_null() {
None None
@ -498,13 +513,13 @@ impl<'a> Warning<'a> {
} }
} }
pub struct Info<'a>(&'a MessageRef); declare_concrete_message!(Info);
impl<'a> Info<'a> { impl<'a> Info<'a> {
pub fn get_error(&self) -> glib::Error { pub fn get_error(&self) -> glib::Error {
unsafe { unsafe {
let mut error = ptr::null_mut(); 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) from_glib_full(error)
} }
@ -514,7 +529,7 @@ impl<'a> Info<'a> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); 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) from_glib_full(debug)
} }
@ -525,7 +540,7 @@ impl<'a> Info<'a> {
unsafe { unsafe {
let mut details = ptr::null(); 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() { if details.is_null() {
None None
@ -536,23 +551,23 @@ impl<'a> Info<'a> {
} }
} }
pub struct Tag<'a>(&'a MessageRef); declare_concrete_message!(Tag);
impl<'a> Tag<'a> { impl<'a> Tag<'a> {
pub fn get_tags(&self) -> TagList { pub fn get_tags(&self) -> TagList {
unsafe { unsafe {
let mut tags = ptr::null_mut(); 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) from_glib_full(tags)
} }
} }
} }
pub struct Buffering<'a>(&'a MessageRef); declare_concrete_message!(Buffering);
impl<'a> Buffering<'a> { impl<'a> Buffering<'a> {
pub fn get_percent(&self) -> i32 { pub fn get_percent(&self) -> i32 {
unsafe { unsafe {
let mut p = mem::uninitialized(); 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 p
} }
} }
@ -565,7 +580,7 @@ impl<'a> Buffering<'a> {
let mut buffering_left = mem::uninitialized(); let mut buffering_left = mem::uninitialized();
ffi::gst_message_parse_buffering_stats( ffi::gst_message_parse_buffering_stats(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut mode, &mut mode,
&mut avg_in, &mut avg_in,
&mut avg_out, &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> { impl<'a> StateChanged<'a> {
pub fn get_old(&self) -> ::State { pub fn get_old(&self) -> ::State {
unsafe { unsafe {
let mut state = mem::uninitialized(); let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed( ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut state, &mut state,
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
@ -599,7 +614,7 @@ impl<'a> StateChanged<'a> {
let mut state = mem::uninitialized(); let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed( ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(), self.as_mut_ptr(),
ptr::null_mut(), ptr::null_mut(),
&mut state, &mut state,
ptr::null_mut(), ptr::null_mut(),
@ -614,7 +629,7 @@ impl<'a> StateChanged<'a> {
let mut state = mem::uninitialized(); let mut state = mem::uninitialized();
ffi::gst_message_parse_state_changed( ffi::gst_message_parse_state_changed(
self.0.as_mut_ptr(), self.as_mut_ptr(),
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
&mut state, &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> { impl<'a> StepDone<'a> {
pub fn get( pub fn get(
&self, &self,
@ -649,7 +664,7 @@ impl<'a> StepDone<'a> {
let mut eos = mem::uninitialized(); let mut eos = mem::uninitialized();
ffi::gst_message_parse_step_done( ffi::gst_message_parse_step_done(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut format, &mut format,
&mut amount, &mut amount,
&mut rate, &mut rate,
@ -671,13 +686,13 @@ impl<'a> StepDone<'a> {
} }
} }
pub struct ClockProvide<'a>(&'a MessageRef); declare_concrete_message!(ClockProvide);
impl<'a> ClockProvide<'a> { impl<'a> ClockProvide<'a> {
pub fn get_clock(&self) -> Option<::Clock> { pub fn get_clock(&self) -> Option<::Clock> {
let mut clock = ptr::null_mut(); let mut clock = ptr::null_mut();
unsafe { 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) from_glib_none(clock)
} }
@ -687,40 +702,40 @@ impl<'a> ClockProvide<'a> {
unsafe { unsafe {
let mut ready = mem::uninitialized(); 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) from_glib(ready)
} }
} }
} }
pub struct ClockLost<'a>(&'a MessageRef); declare_concrete_message!(ClockLost);
impl<'a> ClockLost<'a> { impl<'a> ClockLost<'a> {
pub fn get_clock(&self) -> Option<::Clock> { pub fn get_clock(&self) -> Option<::Clock> {
let mut clock = ptr::null_mut(); let mut clock = ptr::null_mut();
unsafe { 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) from_glib_none(clock)
} }
} }
} }
pub struct NewClock<'a>(&'a MessageRef); declare_concrete_message!(NewClock);
impl<'a> NewClock<'a> { impl<'a> NewClock<'a> {
pub fn get_clock(&self) -> Option<::Clock> { pub fn get_clock(&self) -> Option<::Clock> {
let mut clock = ptr::null_mut(); let mut clock = ptr::null_mut();
unsafe { 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) from_glib_none(clock)
} }
} }
} }
pub struct StructureChange<'a>(&'a MessageRef); declare_concrete_message!(StructureChange);
impl<'a> StructureChange<'a> { impl<'a> StructureChange<'a> {
pub fn get(&self) -> (::StructureChangeType, ::Element, bool) { pub fn get(&self) -> (::StructureChangeType, ::Element, bool) {
unsafe { unsafe {
@ -729,7 +744,7 @@ impl<'a> StructureChange<'a> {
let mut busy = mem::uninitialized(); let mut busy = mem::uninitialized();
ffi::gst_message_parse_structure_change( ffi::gst_message_parse_structure_change(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut type_, &mut type_,
&mut owner, &mut owner,
&mut busy, &mut busy,
@ -740,14 +755,14 @@ impl<'a> StructureChange<'a> {
} }
} }
pub struct StreamStatus<'a>(&'a MessageRef); declare_concrete_message!(StreamStatus);
impl<'a> StreamStatus<'a> { impl<'a> StreamStatus<'a> {
pub fn get(&self) -> (::StreamStatusType, ::Element) { pub fn get(&self) -> (::StreamStatusType, ::Element) {
unsafe { unsafe {
let mut type_ = mem::uninitialized(); let mut type_ = mem::uninitialized();
let mut owner = ptr::null_mut(); 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)) (from_glib(type_), from_glib_none(owner))
} }
@ -755,78 +770,76 @@ impl<'a> StreamStatus<'a> {
pub fn get_stream_status_object(&self) -> Option<glib::Value> { pub fn get_stream_status_object(&self) -> Option<glib::Value> {
unsafe { 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) 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> { impl<'a> SegmentStart<'a> {
pub fn get(&self) -> GenericFormattedValue { pub fn get(&self) -> GenericFormattedValue {
unsafe { unsafe {
let mut format = mem::uninitialized(); let mut format = mem::uninitialized();
let mut position = 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) GenericFormattedValue::new(from_glib(format), position)
} }
} }
} }
pub struct SegmentDone<'a>(&'a MessageRef); declare_concrete_message!(SegmentDone);
impl<'a> SegmentDone<'a> { impl<'a> SegmentDone<'a> {
pub fn get(&self) -> GenericFormattedValue { pub fn get(&self) -> GenericFormattedValue {
unsafe { unsafe {
let mut format = mem::uninitialized(); let mut format = mem::uninitialized();
let mut position = 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) 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); declare_concrete_message!(AsyncDone);
pub struct AsyncStart<'a>(&'a MessageRef);
pub struct AsyncDone<'a>(&'a MessageRef);
impl<'a> AsyncDone<'a> { impl<'a> AsyncDone<'a> {
pub fn get_running_time(&self) -> ::ClockTime { pub fn get_running_time(&self) -> ::ClockTime {
unsafe { unsafe {
let mut running_time = mem::uninitialized(); 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) from_glib(running_time)
} }
} }
} }
pub struct RequestState<'a>(&'a MessageRef); declare_concrete_message!(RequestState);
impl<'a> RequestState<'a> { impl<'a> RequestState<'a> {
pub fn get_requested_state(&self) -> ::State { pub fn get_requested_state(&self) -> ::State {
unsafe { unsafe {
let mut state = mem::uninitialized(); 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) from_glib(state)
} }
} }
} }
pub struct StepStart<'a>(&'a MessageRef); declare_concrete_message!(StepStart);
impl<'a> StepStart<'a> { impl<'a> StepStart<'a> {
pub fn get(&self) -> (bool, GenericFormattedValue, f64, bool, bool) { pub fn get(&self) -> (bool, GenericFormattedValue, f64, bool, bool) {
unsafe { unsafe {
@ -838,7 +851,7 @@ impl<'a> StepStart<'a> {
let mut intermediate = mem::uninitialized(); let mut intermediate = mem::uninitialized();
ffi::gst_message_parse_step_start( ffi::gst_message_parse_step_start(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut active, &mut active,
&mut format, &mut format,
&mut amount, &mut amount,
@ -858,7 +871,7 @@ impl<'a> StepStart<'a> {
} }
} }
pub struct Qos<'a>(&'a MessageRef); declare_concrete_message!(Qos);
impl<'a> Qos<'a> { impl<'a> Qos<'a> {
pub fn get(&self) -> (bool, ::ClockTime, ::ClockTime, ::ClockTime, ::ClockTime) { pub fn get(&self) -> (bool, ::ClockTime, ::ClockTime, ::ClockTime, ::ClockTime) {
unsafe { unsafe {
@ -869,7 +882,7 @@ impl<'a> Qos<'a> {
let mut duration = mem::uninitialized(); let mut duration = mem::uninitialized();
ffi::gst_message_parse_qos( ffi::gst_message_parse_qos(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut live, &mut live,
&mut running_time, &mut running_time,
&mut stream_time, &mut stream_time,
@ -894,7 +907,7 @@ impl<'a> Qos<'a> {
let mut quality = mem::uninitialized(); let mut quality = mem::uninitialized();
ffi::gst_message_parse_qos_values( ffi::gst_message_parse_qos_values(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut jitter, &mut jitter,
&mut proportion, &mut proportion,
&mut quality, &mut quality,
@ -911,7 +924,7 @@ impl<'a> Qos<'a> {
let mut dropped = mem::uninitialized(); let mut dropped = mem::uninitialized();
ffi::gst_message_parse_qos_stats( ffi::gst_message_parse_qos_stats(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut format, &mut format,
&mut processed, &mut processed,
&mut dropped, &mut dropped,
@ -925,7 +938,7 @@ impl<'a> Qos<'a> {
} }
} }
pub struct Progress<'a>(&'a MessageRef); declare_concrete_message!(Progress);
impl<'a> Progress<'a> { impl<'a> Progress<'a> {
pub fn get(&self) -> (::ProgressType, &'a str, &'a str) { pub fn get(&self) -> (::ProgressType, &'a str, &'a str) {
unsafe { unsafe {
@ -933,7 +946,7 @@ impl<'a> Progress<'a> {
let mut code = ptr::null_mut(); let mut code = ptr::null_mut();
let mut text = 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 code = CStr::from_ptr(code).to_str().unwrap();
let text = CStr::from_ptr(text).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> { impl<'a> Toc<'a> {
pub fn get_toc(&self) -> (::Toc, bool) { pub fn get_toc(&self) -> (::Toc, bool) {
unsafe { unsafe {
let mut toc = ptr::null_mut(); let mut toc = ptr::null_mut();
let mut updated = mem::uninitialized(); 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)) (from_glib_full(toc), from_glib(updated))
} }
} }
} }
pub struct ResetTime<'a>(&'a MessageRef); declare_concrete_message!(ResetTime);
impl<'a> ResetTime<'a> { impl<'a> ResetTime<'a> {
pub fn get_running_time(&self) -> ::ClockTime { pub fn get_running_time(&self) -> ::ClockTime {
unsafe { unsafe {
let mut running_time = mem::uninitialized(); 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) from_glib(running_time)
} }
} }
} }
pub struct StreamStart<'a>(&'a MessageRef); declare_concrete_message!(StreamStart);
impl<'a> StreamStart<'a> { impl<'a> StreamStart<'a> {
pub fn get_group_id(&self) -> Option<GroupId> { pub fn get_group_id(&self) -> Option<GroupId> {
unsafe { unsafe {
let mut group_id = mem::uninitialized(); let mut group_id = mem::uninitialized();
if from_glib(ffi::gst_message_parse_group_id( if from_glib(ffi::gst_message_parse_group_id(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut group_id, &mut group_id,
)) { )) {
Some(from_glib(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> { impl<'a> NeedContext<'a> {
pub fn get_context_type(&self) -> &str { pub fn get_context_type(&self) -> &str {
unsafe { unsafe {
let mut context_type = ptr::null(); 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() CStr::from_ptr(context_type).to_str().unwrap()
} }
} }
} }
pub struct HaveContext<'a>(&'a MessageRef); declare_concrete_message!(HaveContext);
impl<'a> HaveContext<'a> { impl<'a> HaveContext<'a> {
pub fn get_context(&self) -> ::Context { pub fn get_context(&self) -> ::Context {
unsafe { unsafe {
let mut context = ptr::null_mut(); 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) from_glib_full(context)
} }
} }
} }
pub struct DeviceAdded<'a>(&'a MessageRef); declare_concrete_message!(DeviceAdded);
impl<'a> DeviceAdded<'a> { impl<'a> DeviceAdded<'a> {
pub fn get_device(&self) -> ::Device { pub fn get_device(&self) -> ::Device {
unsafe { unsafe {
let mut device = ptr::null_mut(); 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) from_glib_none(device)
} }
} }
} }
pub struct DeviceRemoved<'a>(&'a MessageRef); declare_concrete_message!(DeviceRemoved);
impl<'a> DeviceRemoved<'a> { impl<'a> DeviceRemoved<'a> {
pub fn get_device(&self) -> ::Device { pub fn get_device(&self) -> ::Device {
unsafe { unsafe {
let mut device = ptr::null_mut(); 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) from_glib_none(device)
} }
} }
} }
pub struct PropertyNotify<'a>(&'a MessageRef); declare_concrete_message!(PropertyNotify);
impl<'a> PropertyNotify<'a> { impl<'a> PropertyNotify<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get(&self) -> (Object, &str, Option<&'a ::Value>) { pub fn get(&self) -> (Object, &str, Option<&'a ::Value>) {
@ -1046,7 +1059,7 @@ impl<'a> PropertyNotify<'a> {
let mut value = ptr::null(); let mut value = ptr::null();
ffi::gst_message_parse_property_notify( ffi::gst_message_parse_property_notify(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut object, &mut object,
&mut property_name, &mut property_name,
&mut value, &mut value,
@ -1065,27 +1078,28 @@ impl<'a> PropertyNotify<'a> {
} }
} }
pub struct StreamCollection<'a>(&'a MessageRef); declare_concrete_message!(StreamCollection);
impl<'a> StreamCollection<'a> { impl<'a> StreamCollection<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_stream_collection(&self) -> ::StreamCollection { pub fn get_stream_collection(&self) -> ::StreamCollection {
unsafe { unsafe {
let mut collection = ptr::null_mut(); 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) from_glib_full(collection)
} }
} }
} }
pub struct StreamsSelected<'a>(&'a MessageRef);
declare_concrete_message!(StreamsSelected);
impl<'a> StreamsSelected<'a> { impl<'a> StreamsSelected<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_stream_collection(&self) -> ::StreamCollection { pub fn get_stream_collection(&self) -> ::StreamCollection {
unsafe { unsafe {
let mut collection = ptr::null_mut(); 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) from_glib_full(collection)
} }
@ -1094,12 +1108,12 @@ impl<'a> StreamsSelected<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_streams(&self) -> Vec<::Stream> { pub fn get_streams(&self) -> Vec<::Stream> {
unsafe { 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) (0..n)
.map(|i| { .map(|i| {
from_glib_full(ffi::gst_message_streams_selected_get_stream( from_glib_full(ffi::gst_message_streams_selected_get_stream(
self.0.as_mut_ptr(), self.as_mut_ptr(),
i, i,
)) ))
}) })
@ -1108,12 +1122,12 @@ impl<'a> StreamsSelected<'a> {
} }
} }
pub struct Redirect<'a>(&'a MessageRef); declare_concrete_message!(Redirect);
impl<'a> Redirect<'a> { impl<'a> Redirect<'a> {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
pub fn get_entries(&self) -> Vec<(&str, Option<TagList>, Option<&StructureRef>)> { pub fn get_entries(&self) -> Vec<(&str, Option<TagList>, Option<&StructureRef>)> {
unsafe { 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) (0..n)
.map(|i| { .map(|i| {
@ -1122,7 +1136,7 @@ impl<'a> Redirect<'a> {
let mut structure = ptr::null(); let mut structure = ptr::null();
ffi::gst_message_parse_redirect_entry( ffi::gst_message_parse_redirect_entry(
self.0.as_mut_ptr(), self.as_mut_ptr(),
i, i,
&mut location, &mut location,
&mut tags, &mut tags,
@ -2459,10 +2473,13 @@ mod tests {
::init().unwrap(); ::init().unwrap();
// Message without arguments // Message without arguments
let eos_msg = Message::new_eos().build(); let eos_msg = Message::new_eos()
.seqnum(Seqnum(1))
.build();
match eos_msg.view() { match eos_msg.view() {
MessageView::Eos(eos_msg) => { 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(_)"), _ => panic!("eos_msg.view() is not a MessageView::Eos(_)"),
} }

View file

@ -242,14 +242,50 @@ pub enum QueryView<T> {
__NonExhaustive, __NonExhaustive,
} }
pub struct Position<T>(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> { impl<'a> Position<&'a QueryRef> {
pub fn get_result(&self) -> GenericFormattedValue { pub fn get_result(&self) -> GenericFormattedValue {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
let mut pos = 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) GenericFormattedValue::new(from_glib(fmt), pos)
} }
@ -259,15 +295,11 @@ impl<'a> Position<&'a QueryRef> {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); 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) from_glib(fmt)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Position<&'a mut QueryRef> { impl<'a> Position<&'a mut QueryRef> {
@ -276,26 +308,22 @@ impl<'a> Position<&'a mut QueryRef> {
assert_eq!(pos.get_format(), self.get_format()); assert_eq!(pos.get_format(), self.get_format());
unsafe { unsafe {
ffi::gst_query_set_position( ffi::gst_query_set_position(
self.0.as_mut_ptr(), self.as_mut_ptr(),
pos.get_format().to_glib(), pos.get_format().to_glib(),
pos.get_value(), pos.get_value(),
); );
} }
} }
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
} }
pub struct Duration<T>(T); declare_concrete_query!(Duration, T);
impl<'a> Duration<&'a QueryRef> { impl<'a> Duration<&'a QueryRef> {
pub fn get_result(&self) -> GenericFormattedValue { pub fn get_result(&self) -> GenericFormattedValue {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
let mut pos = 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) GenericFormattedValue::new(from_glib(fmt), pos)
} }
@ -305,15 +333,11 @@ impl<'a> Duration<&'a QueryRef> {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); 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) from_glib(fmt)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Duration<&'a mut QueryRef> { impl<'a> Duration<&'a mut QueryRef> {
@ -322,19 +346,15 @@ impl<'a> Duration<&'a mut QueryRef> {
assert_eq!(dur.get_format(), self.get_format()); assert_eq!(dur.get_format(), self.get_format());
unsafe { unsafe {
ffi::gst_query_set_duration( ffi::gst_query_set_duration(
self.0.as_mut_ptr(), self.as_mut_ptr(),
dur.get_format().to_glib(), dur.get_format().to_glib(),
dur.get_value(), dur.get_value(),
); );
} }
} }
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
} }
pub struct Latency<T>(T); declare_concrete_query!(Latency, T);
impl<'a> Latency<&'a QueryRef> { impl<'a> Latency<&'a QueryRef> {
pub fn get_result(&self) -> (bool, ::ClockTime, ::ClockTime) { pub fn get_result(&self) -> (bool, ::ClockTime, ::ClockTime) {
unsafe { unsafe {
@ -342,61 +362,30 @@ impl<'a> Latency<&'a QueryRef> {
let mut min = mem::uninitialized(); let mut min = mem::uninitialized();
let mut max = 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)) (from_glib(live), from_glib(min), from_glib(max))
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Latency<&'a mut QueryRef> { impl<'a> Latency<&'a mut QueryRef> {
pub fn set(&mut self, live: bool, min: ::ClockTime, max: ::ClockTime) { pub fn set(&mut self, live: bool, min: ::ClockTime, max: ::ClockTime) {
unsafe { unsafe {
ffi::gst_query_set_latency( ffi::gst_query_set_latency(
self.0.as_mut_ptr(), self.as_mut_ptr(),
live.to_glib(), live.to_glib(),
min.to_glib(), min.to_glib(),
max.to_glib(), max.to_glib(),
); );
} }
} }
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
} }
pub struct Jitter<T>(T); declare_concrete_query!(Jitter, T);
impl<'a> Jitter<&'a QueryRef> { declare_concrete_query!(Rate, T);
pub fn get_query(&self) -> &QueryRef {
self.0
}
}
impl<'a> Jitter<&'a mut QueryRef> { declare_concrete_query!(Seeking, T);
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
}
pub struct Rate<T>(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>(T);
impl<'a> Seeking<&'a QueryRef> { impl<'a> Seeking<&'a QueryRef> {
pub fn get_result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) { pub fn get_result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) {
unsafe { unsafe {
@ -405,7 +394,7 @@ impl<'a> Seeking<&'a QueryRef> {
let mut start = mem::uninitialized(); let mut start = mem::uninitialized();
let mut end = mem::uninitialized(); let mut end = mem::uninitialized();
ffi::gst_query_parse_seeking( ffi::gst_query_parse_seeking(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
&mut seekable, &mut seekable,
&mut start, &mut start,
@ -424,7 +413,7 @@ impl<'a> Seeking<&'a QueryRef> {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
ffi::gst_query_parse_seeking( ffi::gst_query_parse_seeking(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
@ -434,10 +423,6 @@ impl<'a> Seeking<&'a QueryRef> {
from_glib(fmt) from_glib(fmt)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Seeking<&'a mut QueryRef> { impl<'a> Seeking<&'a mut QueryRef> {
@ -450,7 +435,7 @@ impl<'a> Seeking<&'a mut QueryRef> {
unsafe { unsafe {
ffi::gst_query_set_seeking( ffi::gst_query_set_seeking(
self.0.as_mut_ptr(), self.as_mut_ptr(),
start.get_format().to_glib(), start.get_format().to_glib(),
seekable.to_glib(), seekable.to_glib(),
start.get_value(), 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>(T); declare_concrete_query!(Segment, T);
impl<'a> Segment<&'a QueryRef> { impl<'a> Segment<&'a QueryRef> {
pub fn get_result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) { pub fn get_result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) {
unsafe { unsafe {
@ -474,7 +455,7 @@ impl<'a> Segment<&'a QueryRef> {
let mut stop = mem::uninitialized(); let mut stop = mem::uninitialized();
ffi::gst_query_parse_segment( ffi::gst_query_parse_segment(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut rate, &mut rate,
&mut fmt, &mut fmt,
&mut start, &mut start,
@ -493,7 +474,7 @@ impl<'a> Segment<&'a QueryRef> {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
ffi::gst_query_parse_segment( ffi::gst_query_parse_segment(
self.0.as_mut_ptr(), self.as_mut_ptr(),
ptr::null_mut(), ptr::null_mut(),
&mut fmt, &mut fmt,
ptr::null_mut(), ptr::null_mut(),
@ -502,10 +483,6 @@ impl<'a> Segment<&'a QueryRef> {
from_glib(fmt) from_glib(fmt)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Segment<&'a mut QueryRef> { impl<'a> Segment<&'a mut QueryRef> {
@ -517,7 +494,7 @@ impl<'a> Segment<&'a mut QueryRef> {
unsafe { unsafe {
ffi::gst_query_set_segment( ffi::gst_query_set_segment(
self.0.as_mut_ptr(), self.as_mut_ptr(),
rate, rate,
start.get_format().to_glib(), start.get_format().to_glib(),
start.get_value(), 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>(T); declare_concrete_query!(Convert, T);
impl<'a> Convert<&'a QueryRef> { impl<'a> Convert<&'a QueryRef> {
pub fn get_result(&self) -> (GenericFormattedValue, GenericFormattedValue) { pub fn get_result(&self) -> (GenericFormattedValue, GenericFormattedValue) {
unsafe { unsafe {
@ -541,7 +514,7 @@ impl<'a> Convert<&'a QueryRef> {
let mut dest = mem::uninitialized(); let mut dest = mem::uninitialized();
ffi::gst_query_parse_convert( ffi::gst_query_parse_convert(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut src_fmt, &mut src_fmt,
&mut src, &mut src,
&mut dest_fmt, &mut dest_fmt,
@ -561,7 +534,7 @@ impl<'a> Convert<&'a QueryRef> {
let mut dest_fmt = mem::uninitialized(); let mut dest_fmt = mem::uninitialized();
ffi::gst_query_parse_convert( ffi::gst_query_parse_convert(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut src_fmt, &mut src_fmt,
&mut src, &mut src,
&mut dest_fmt, &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> { impl<'a> Convert<&'a mut QueryRef> {
@ -586,7 +555,7 @@ impl<'a> Convert<&'a mut QueryRef> {
unsafe { unsafe {
ffi::gst_query_set_convert( ffi::gst_query_set_convert(
self.0.as_mut_ptr(), self.as_mut_ptr(),
src.get_format().to_glib(), src.get_format().to_glib(),
src.get_value(), src.get_value(),
dest.get_format().to_glib(), 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>(T); declare_concrete_query!(Formats, T);
impl<'a> Formats<&'a QueryRef> { impl<'a> Formats<&'a QueryRef> {
pub fn get_result(&self) -> Vec<::Format> { pub fn get_result(&self) -> Vec<::Format> {
unsafe { unsafe {
let mut n = mem::uninitialized(); 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); let mut res = Vec::with_capacity(n as usize);
for i in 0..n { for i in 0..n {
let mut fmt = mem::uninitialized(); 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.push(from_glib(fmt));
} }
res res
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Formats<&'a mut QueryRef> { impl<'a> Formats<&'a mut QueryRef> {
pub fn set(&mut self, formats: &[::Format]) { pub fn set(&mut self, formats: &[::Format]) {
unsafe { unsafe {
let v: Vec<_> = formats.iter().map(|f| f.to_glib()).collect(); 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>(T); declare_concrete_query!(Buffering, T);
impl<'a> Buffering<&'a QueryRef> { impl<'a> Buffering<&'a QueryRef> {
pub fn get_format(&self) -> ::Format { pub fn get_format(&self) -> ::Format {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
ffi::gst_query_parse_buffering_range( ffi::gst_query_parse_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
@ -659,7 +616,7 @@ impl<'a> Buffering<&'a QueryRef> {
let mut busy = mem::uninitialized(); let mut busy = mem::uninitialized();
let mut percent = 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) (from_glib(busy), percent)
} }
@ -673,7 +630,7 @@ impl<'a> Buffering<&'a QueryRef> {
let mut estimated_total = mem::uninitialized(); let mut estimated_total = mem::uninitialized();
ffi::gst_query_parse_buffering_range( ffi::gst_query_parse_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
&mut start, &mut start,
&mut stop, &mut stop,
@ -695,7 +652,7 @@ impl<'a> Buffering<&'a QueryRef> {
let mut buffering_left = mem::uninitialized(); let mut buffering_left = mem::uninitialized();
ffi::gst_query_parse_buffering_stats( ffi::gst_query_parse_buffering_stats(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut mode, &mut mode,
&mut avg_in, &mut avg_in,
&mut avg_out, &mut avg_out,
@ -710,7 +667,7 @@ impl<'a> Buffering<&'a QueryRef> {
unsafe { unsafe {
let mut fmt = mem::uninitialized(); let mut fmt = mem::uninitialized();
ffi::gst_query_parse_buffering_range( ffi::gst_query_parse_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut fmt, &mut fmt,
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
@ -718,13 +675,13 @@ impl<'a> Buffering<&'a QueryRef> {
); );
let fmt = from_glib(fmt); 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); let mut res = Vec::with_capacity(n as usize);
for i in 0..n { for i in 0..n {
let mut start = mem::uninitialized(); let mut start = mem::uninitialized();
let mut stop = mem::uninitialized(); let mut stop = mem::uninitialized();
let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range( let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
i, i,
&mut start, &mut start,
&mut stop, &mut stop,
@ -740,16 +697,12 @@ impl<'a> Buffering<&'a QueryRef> {
res res
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Buffering<&'a mut QueryRef> { impl<'a> Buffering<&'a mut QueryRef> {
pub fn set_percent(&mut self, busy: bool, percent: i32) { pub fn set_percent(&mut self, busy: bool, percent: i32) {
unsafe { 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 { unsafe {
ffi::gst_query_set_buffering_range( ffi::gst_query_set_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
start.get_format().to_glib(), start.get_format().to_glib(),
start.get_value(), start.get_value(),
stop.get_value(), stop.get_value(),
@ -786,7 +739,7 @@ impl<'a> Buffering<&'a mut QueryRef> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
ffi::gst_query_set_buffering_stats( ffi::gst_query_set_buffering_stats(
self.0.as_mut_ptr(), self.as_mut_ptr(),
mode.to_glib(), mode.to_glib(),
avg_in, avg_in,
avg_out, avg_out,
@ -808,38 +761,23 @@ impl<'a> Buffering<&'a mut QueryRef> {
assert_eq!(start.get_format(), fmt); assert_eq!(start.get_format(), fmt);
assert_eq!(stop.get_format(), fmt); assert_eq!(stop.get_format(), fmt);
ffi::gst_query_add_buffering_range( ffi::gst_query_add_buffering_range(
self.0.as_mut_ptr(), self.as_mut_ptr(),
start.get_value(), start.get_value(),
stop.get_value(), stop.get_value(),
); );
} }
} }
} }
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
} }
pub struct Custom<T>(T); declare_concrete_query!(Custom, T);
impl<'a> Custom<&'a QueryRef> {
pub fn get_query(&self) -> &QueryRef {
self.0
}
}
impl<'a> Custom<&'a mut QueryRef> { declare_concrete_query!(Uri, T);
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
}
pub struct Uri<T>(T);
impl<'a> Uri<&'a QueryRef> { impl<'a> Uri<&'a QueryRef> {
pub fn get_uri(&self) -> Option<String> { pub fn get_uri(&self) -> Option<String> {
unsafe { unsafe {
let mut uri = ptr::null_mut(); 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) from_glib_full(uri)
} }
} }
@ -847,60 +785,41 @@ impl<'a> Uri<&'a QueryRef> {
pub fn get_redirection(&self) -> (Option<String>, bool) { pub fn get_redirection(&self) -> (Option<String>, bool) {
unsafe { unsafe {
let mut uri = ptr::null_mut(); 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(); 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)) (from_glib_full(uri), from_glib(permanent))
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Uri<&'a mut QueryRef> { impl<'a> Uri<&'a mut QueryRef> {
pub fn set_uri<'b, T: Into<&'b str>>(&mut self, uri: T) { pub fn set_uri<'b, T: Into<&'b str>>(&mut self, uri: T) {
let uri = uri.into(); let uri = uri.into();
unsafe { 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) { pub fn set_redirection<'b, T: Into<&'b str>>(&mut self, uri: T, permanent: bool) {
let uri = uri.into(); let uri = uri.into();
unsafe { unsafe {
ffi::gst_query_set_uri_redirection(self.0.as_mut_ptr(), uri.to_glib_none().0); ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0);
ffi::gst_query_set_uri_redirection_permanent(self.0.as_mut_ptr(), permanent.to_glib()); 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 // TODO
pub struct Allocation<T>(T); declare_concrete_query!(Allocation, T);
impl<'a> Allocation<&'a QueryRef> {
pub fn get_query(&self) -> &QueryRef {
self.0
}
}
impl<'a> Allocation<&'a mut QueryRef> { declare_concrete_query!(Scheduling, T);
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
}
pub struct Scheduling<T>(T);
impl<'a> Scheduling<&'a QueryRef> { impl<'a> Scheduling<&'a QueryRef> {
pub fn has_scheduling_mode(&self, mode: ::PadMode) -> bool { pub fn has_scheduling_mode(&self, mode: ::PadMode) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_query_has_scheduling_mode( from_glib(ffi::gst_query_has_scheduling_mode(
self.0.as_mut_ptr(), self.as_mut_ptr(),
mode.to_glib(), mode.to_glib(),
)) ))
} }
@ -914,7 +833,7 @@ impl<'a> Scheduling<&'a QueryRef> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib(ffi::gst_query_has_scheduling_mode_with_flags( from_glib(ffi::gst_query_has_scheduling_mode_with_flags(
self.0.as_mut_ptr(), self.as_mut_ptr(),
mode.to_glib(), mode.to_glib(),
flags.to_glib(), flags.to_glib(),
)) ))
@ -923,11 +842,11 @@ impl<'a> Scheduling<&'a QueryRef> {
pub fn get_scheduling_modes(&self) -> Vec<::PadMode> { pub fn get_scheduling_modes(&self) -> Vec<::PadMode> {
unsafe { 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); let mut res = Vec::with_capacity(n as usize);
for i in 0..n { for i in 0..n {
res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode( res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode(
self.0.as_mut_ptr(), self.as_mut_ptr(),
i, i,
))); )));
} }
@ -944,7 +863,7 @@ impl<'a> Scheduling<&'a QueryRef> {
let mut align = mem::uninitialized(); let mut align = mem::uninitialized();
ffi::gst_query_parse_scheduling( ffi::gst_query_parse_scheduling(
self.0.as_mut_ptr(), self.as_mut_ptr(),
&mut flags, &mut flags,
&mut minsize, &mut minsize,
&mut maxsize, &mut maxsize,
@ -954,17 +873,13 @@ impl<'a> Scheduling<&'a QueryRef> {
(from_glib(flags), minsize, maxsize, align) (from_glib(flags), minsize, maxsize, align)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Scheduling<&'a mut QueryRef> { impl<'a> Scheduling<&'a mut QueryRef> {
pub fn add_scheduling_modes(&mut self, modes: &[::PadMode]) { pub fn add_scheduling_modes(&mut self, modes: &[::PadMode]) {
unsafe { unsafe {
for mode in modes { 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) { pub fn set(&mut self, flags: ::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) {
unsafe { unsafe {
ffi::gst_query_set_scheduling( ffi::gst_query_set_scheduling(
self.0.as_mut_ptr(), self.as_mut_ptr(),
flags.to_glib(), flags.to_glib(),
minsize, minsize,
maxsize, 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>(T); declare_concrete_query!(AcceptCaps, T);
impl<'a> AcceptCaps<&'a QueryRef> { impl<'a> AcceptCaps<&'a QueryRef> {
pub fn get_caps(&self) -> &::CapsRef { pub fn get_caps(&self) -> &::CapsRef {
unsafe { unsafe {
let mut caps = ptr::null_mut(); 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) ::CapsRef::from_ptr(caps)
} }
} }
@ -999,34 +910,26 @@ impl<'a> AcceptCaps<&'a QueryRef> {
pub fn get_result(&self) -> bool { pub fn get_result(&self) -> bool {
unsafe { unsafe {
let mut accepted = mem::uninitialized(); 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) from_glib(accepted)
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> AcceptCaps<&'a mut QueryRef> { impl<'a> AcceptCaps<&'a mut QueryRef> {
pub fn set_result(&mut self, accepted: bool) { pub fn set_result(&mut self, accepted: bool) {
unsafe { 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>(T); declare_concrete_query!(Caps, T);
impl<'a> Caps<&'a QueryRef> { impl<'a> Caps<&'a QueryRef> {
pub fn get_filter(&self) -> Option<&::CapsRef> { pub fn get_filter(&self) -> Option<&::CapsRef> {
unsafe { unsafe {
let mut caps = ptr::null_mut(); 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() { if caps.is_null() {
None None
} else { } else {
@ -1038,7 +941,7 @@ impl<'a> Caps<&'a QueryRef> {
pub fn get_result(&self) -> Option<&::CapsRef> { pub fn get_result(&self) -> Option<&::CapsRef> {
unsafe { unsafe {
let mut caps = ptr::null_mut(); 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() { if caps.is_null() {
None None
} else { } else {
@ -1046,43 +949,24 @@ impl<'a> Caps<&'a QueryRef> {
} }
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Caps<&'a mut QueryRef> { impl<'a> Caps<&'a mut QueryRef> {
pub fn set_result(&mut self, caps: &::Caps) { pub fn set_result(&mut self, caps: &::Caps) {
unsafe { 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>(T); declare_concrete_query!(Drain, T);
impl<'a> Drain<&'a QueryRef> {
pub fn get_query(&self) -> &QueryRef {
self.0
}
}
impl<'a> Drain<&'a mut QueryRef> { declare_concrete_query!(Context, T);
pub fn get_mut_query(&mut self) -> &mut QueryRef {
self.0
}
}
pub struct Context<T>(T);
impl<'a> Context<&'a QueryRef> { impl<'a> Context<&'a QueryRef> {
pub fn get_context(&self) -> Option<&::ContextRef> { pub fn get_context(&self) -> Option<&::ContextRef> {
unsafe { unsafe {
let mut context = ptr::null_mut(); 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() { if context.is_null() {
None None
} else { } else {
@ -1094,74 +978,21 @@ impl<'a> Context<&'a QueryRef> {
pub fn get_context_type(&self) -> &str { pub fn get_context_type(&self) -> &str {
unsafe { unsafe {
let mut context_type = ptr::null(); 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() CStr::from_ptr(context_type).to_str().unwrap()
} }
} }
pub fn get_query(&self) -> &QueryRef {
self.0
}
} }
impl<'a> Context<&'a mut QueryRef> { impl<'a> Context<&'a mut QueryRef> {
pub fn set_context(&mut self, context: &::Context) { pub fn set_context(&mut self, context: &::Context) {
unsafe { 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>(T); declare_concrete_query!(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);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -1177,6 +1008,7 @@ mod tests {
QueryView::Position(ref p) => { QueryView::Position(ref p) => {
let fmt = p.get_format(); let fmt = p.get_format();
assert_eq!(fmt, ::Format::Time); assert_eq!(fmt, ::Format::Time);
assert!(!p.is_serialized());
} }
_ => (), _ => (),
} }