diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index c535be5b2..2e6525634 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -63,7 +63,7 @@ fn example_main() { // Create a new position query and send it to the pipeline. // This will traverse all elements in the pipeline, until one feels // capable of answering the query. - let mut q = gst::Query::new_position(gst::Format::Time); + let mut q = gst::query::Position::new(gst::Format::Time); if pipeline.query(&mut q) { Some(q.get_result()) } else { @@ -77,7 +77,7 @@ fn example_main() { // Create a new duration query and send it to the pipeline. // This will traverse all elements in the pipeline, until one feels // capable of answering the query. - let mut q = gst::Query::new_duration(gst::Format::Time); + let mut q = gst::query::Duration::new(gst::Format::Time); if pipeline.query(&mut q) { Some(q.get_result()) } else { diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 625e49822..e4ae5193e 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -26,6 +26,7 @@ gst_define_mini_object_wrapper!(Query, QueryRef, gst_sys::GstQuery, [Debug,], || }); impl Query { + #[deprecated(since = "0.16.0", note = "use `query::Position::new` instead")] pub fn new_position(fmt: ::Format) -> Position { assert_initialized_main_thread!(); unsafe { @@ -35,6 +36,7 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Duration::new` instead")] pub fn new_duration(fmt: ::Format) -> Duration { assert_initialized_main_thread!(); unsafe { @@ -44,11 +46,13 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Latency::new` instead")] pub fn new_latency() -> Latency { assert_initialized_main_thread!(); unsafe { Latency::(from_glib_full(gst_sys::gst_query_new_latency())) } } + #[deprecated(since = "0.16.0", note = "use `query::Seeking::new` instead")] pub fn new_seeking(fmt: ::Format) -> Seeking { assert_initialized_main_thread!(); unsafe { @@ -58,6 +62,7 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Segment::new` instead")] pub fn new_segment(fmt: ::Format) -> Segment { assert_initialized_main_thread!(); unsafe { @@ -67,6 +72,7 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Convert::new` instead")] pub fn new_convert>( value: V, dest_fmt: ::Format, @@ -82,11 +88,13 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Formats::new` instead")] pub fn new_formats() -> Formats { assert_initialized_main_thread!(); unsafe { Formats::(from_glib_full(gst_sys::gst_query_new_formats())) } } + #[deprecated(since = "0.16.0", note = "use `query::Buffering::new` instead")] pub fn new_buffering(fmt: ::Format) -> Buffering { assert_initialized_main_thread!(); unsafe { @@ -96,6 +104,7 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Custom::new` instead")] pub fn new_custom(structure: ::Structure) -> Custom { assert_initialized_main_thread!(); unsafe { @@ -106,11 +115,13 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Uri::new` instead")] pub fn new_uri() -> Uri { assert_initialized_main_thread!(); unsafe { Uri::(from_glib_full(gst_sys::gst_query_new_uri())) } } + #[deprecated(since = "0.16.0", note = "use `query::Allocation::new` instead")] pub fn new_allocation(caps: &::Caps, need_pool: bool) -> Allocation { assert_initialized_main_thread!(); unsafe { @@ -121,11 +132,13 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Scheduling::new` instead")] pub fn new_scheduling() -> Scheduling { assert_initialized_main_thread!(); unsafe { Scheduling::(from_glib_full(gst_sys::gst_query_new_scheduling())) } } + #[deprecated(since = "0.16.0", note = "use `query::AcceptCaps::new` instead")] pub fn new_accept_caps(caps: &::Caps) -> AcceptCaps { assert_initialized_main_thread!(); unsafe { @@ -135,6 +148,7 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Caps::new` instead")] pub fn new_caps(filter: Option<&::Caps>) -> Caps { assert_initialized_main_thread!(); unsafe { @@ -144,11 +158,13 @@ impl Query { } } + #[deprecated(since = "0.16.0", note = "use `query::Drain::new` instead")] pub fn new_drain() -> Drain { assert_initialized_main_thread!(); unsafe { Drain::(from_glib_full(gst_sys::gst_query_new_drain())) } } + #[deprecated(since = "0.16.0", note = "use `query::Context::new` instead")] pub fn new_context(context_type: &str) -> Context { assert_initialized_main_thread!(); unsafe { @@ -159,6 +175,7 @@ impl Query { } #[cfg(any(feature = "v1_16", feature = "dox"))] + #[deprecated(since = "0.16.0", note = "use `query::Bitrate::new` instead")] pub fn new_bitrate() -> Bitrate { assert_initialized_main_thread!(); unsafe { Bitrate::(from_glib_full(gst_sys::gst_query_new_bitrate())) } @@ -363,6 +380,17 @@ macro_rules! declare_concrete_query( ); declare_concrete_query!(Position, T); +impl Position { + pub fn new(fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_position( + fmt.to_glib(), + ))) + } + } +} + impl Position { pub fn get_result(&self) -> GenericFormattedValue { unsafe { @@ -401,6 +429,17 @@ impl Position { } declare_concrete_query!(Duration, T); +impl Duration { + pub fn new(fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_duration( + fmt.to_glib(), + ))) + } + } +} + impl Duration { pub fn get_result(&self) -> GenericFormattedValue { unsafe { @@ -439,6 +478,19 @@ impl Duration { } declare_concrete_query!(Latency, T); +impl Latency { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_latency())) } + } +} + +impl Default for Latency { + fn default() -> Self { + Self::new() + } +} + impl Latency { pub fn get_result(&self) -> (bool, ::ClockTime, ::ClockTime) { unsafe { @@ -476,9 +528,23 @@ impl Latency { } declare_concrete_query!(Jitter, T); +// FIXME no gst_sys::gst_query_new_jitter + declare_concrete_query!(Rate, T); +// FIXME no gst_sys::gst_query_new_rate declare_concrete_query!(Seeking, T); +impl Seeking { + pub fn new(fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_seeking( + fmt.to_glib(), + ))) + } + } +} + impl Seeking { pub fn get_result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -539,6 +605,17 @@ impl Seeking { } declare_concrete_query!(Segment, T); +impl Segment { + pub fn new(fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_segment( + fmt.to_glib(), + ))) + } + } +} + impl Segment { pub fn get_result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -598,6 +675,20 @@ impl Segment { } declare_concrete_query!(Convert, T); +impl Convert { + pub fn new>(value: V, dest_fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + let value = value.into(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_convert( + value.get_format().to_glib(), + value.get_value(), + dest_fmt.to_glib(), + ))) + } + } +} + impl Convert { pub fn get_result(&self) -> (GenericFormattedValue, GenericFormattedValue) { unsafe { @@ -659,6 +750,19 @@ impl Convert { } declare_concrete_query!(Formats, T); +impl Formats { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_formats())) } + } +} + +impl Default for Formats { + fn default() -> Self { + Self::new() + } +} + impl Formats { pub fn get_result(&self) -> Vec<::Format> { unsafe { @@ -692,6 +796,17 @@ impl Formats { } declare_concrete_query!(Buffering, T); +impl Buffering { + pub fn new(fmt: ::Format) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_buffering( + fmt.to_glib(), + ))) + } + } +} + impl Buffering { pub fn get_format(&self) -> ::Format { unsafe { @@ -878,8 +993,32 @@ impl Buffering { } declare_concrete_query!(Custom, T); +impl Custom { + pub fn new(structure: ::Structure) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_custom( + gst_sys::GST_QUERY_CUSTOM, + structure.into_ptr(), + ))) + } + } +} declare_concrete_query!(Uri, T); +impl Uri { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_uri())) } + } +} + +impl Default for Uri { + fn default() -> Self { + Self::new() + } +} + impl Uri { pub fn get_uri(&self) -> Option { unsafe { @@ -925,6 +1064,18 @@ impl Uri { } declare_concrete_query!(Allocation, T); +impl Allocation { + pub fn new(caps: &::Caps, need_pool: bool) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_allocation( + caps.as_mut_ptr(), + need_pool.to_glib(), + ))) + } + } +} + impl Allocation { pub fn get(&self) -> (&::CapsRef, bool) { unsafe { @@ -1086,6 +1237,19 @@ impl Allocation { } declare_concrete_query!(Scheduling, T); +impl Scheduling { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_scheduling())) } + } +} + +impl Default for Scheduling { + fn default() -> Self { + Self::new() + } +} + impl Scheduling { pub fn has_scheduling_mode(&self, mode: ::PadMode) -> bool { unsafe { @@ -1174,6 +1338,17 @@ impl Scheduling { } declare_concrete_query!(AcceptCaps, T); +impl AcceptCaps { + pub fn new(caps: &::Caps) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_accept_caps( + caps.as_mut_ptr(), + ))) + } + } +} + impl AcceptCaps { pub fn get_caps(&self) -> &::CapsRef { unsafe { @@ -1205,6 +1380,17 @@ impl AcceptCaps { } declare_concrete_query!(Caps, T); +impl Caps { + pub fn new(filter: Option<&::Caps>) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_caps( + filter.to_glib_none().0, + ))) + } + } +} + impl Caps { pub fn get_filter(&self) -> Option<&::CapsRef> { unsafe { @@ -1248,8 +1434,31 @@ impl Caps { } declare_concrete_query!(Drain, T); +impl Drain { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_drain())) } + } +} + +impl Default for Drain { + fn default() -> Self { + Self::new() + } +} declare_concrete_query!(Context, T); +impl Context { + pub fn new(context_type: &str) -> Self { + assert_initialized_main_thread!(); + unsafe { + Self(from_glib_full(gst_sys::gst_query_new_context( + context_type.to_glib_none().0, + ))) + } + } +} + impl Context { pub fn get_context(&self) -> Option<&::ContextRef> { unsafe { @@ -1288,6 +1497,22 @@ impl Context { } declare_concrete_query!(Bitrate, T); + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl Bitrate { + pub fn new() -> Self { + assert_initialized_main_thread!(); + unsafe { Self(from_glib_full(gst_sys::gst_query_new_bitrate())) } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl Default for Bitrate { + fn default() -> Self { + Self::new() + } +} + impl Bitrate { #[cfg(any(feature = "v1_16", feature = "dox"))] pub fn get_bitrate(&self) -> u32 { @@ -1347,7 +1572,7 @@ mod tests { } } - let mut p = Query::new_position(::Format::Time); + let mut p = Position::new(::Format::Time); let pos = p.get_result(); assert_eq!(pos.try_into(), Ok(::CLOCK_TIME_NONE)); @@ -1372,7 +1597,7 @@ mod tests { #[test] fn test_into_query() { ::init().unwrap(); - let d = Query::new_duration(::Format::Time); + let d = Duration::new(::Format::Time); let mut query: Query = d.into(); assert!(query.is_writable()); @@ -1398,7 +1623,7 @@ mod tests { fn test_concrete_to_sys() { ::init().unwrap(); - let p = Query::new_position(::Format::Time); + let p = Position::new(::Format::Time); unsafe { assert!(!p.as_mut_ptr().is_null()); } diff --git a/tutorials/src/bin/basic-tutorial-4.rs b/tutorials/src/bin/basic-tutorial-4.rs index 58a449f1b..e992cd523 100644 --- a/tutorials/src/bin/basic-tutorial-4.rs +++ b/tutorials/src/bin/basic-tutorial-4.rs @@ -134,7 +134,7 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::Message) { custom_data.playing = new_state == gst::State::Playing; if custom_data.playing { - let mut seeking = gst::Query::new_seeking(gst::Format::Time); + let mut seeking = gst::query::Seeking::new(gst::Format::Time); if custom_data.playbin.query(&mut seeking) { let (seekable, start, end) = seeking.get_result(); custom_data.seek_enabled = seekable;