From bf982f422156f1424fc894efa77de964757fb7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Thu, 19 Jun 2025 12:57:06 +0200 Subject: [PATCH] gst: manual changes further to QueryType generation Part-of: --- gstreamer/src/query.rs | 48 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 341155f93..52b8f9f6b 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -15,12 +15,33 @@ use crate::{ ffi, format::{CompatibleFormattedValue, FormattedValue, GenericFormattedValue}, structure::*, + QueryType, }; mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || { ffi::gst_query_get_type() }); +impl QueryType { + #[doc(alias = "GST_QUERY_IS_UPSTREAM")] + #[inline] + pub fn is_upstream(self) -> bool { + (self.into_glib() as u32) & ffi::GST_QUERY_TYPE_UPSTREAM != 0 + } + + #[doc(alias = "GST_QUERY_IS_DOWNSTREAM")] + #[inline] + pub fn is_downstream(self) -> bool { + (self.into_glib() as u32) & ffi::GST_QUERY_TYPE_DOWNSTREAM != 0 + } + + #[doc(alias = "GST_QUERY_IS_SERIALIZED")] + #[inline] + pub fn is_serialized(self) -> bool { + (self.into_glib() as u32) & ffi::GST_QUERY_TYPE_SERIALIZED != 0 + } +} + impl QueryRef { #[doc(alias = "get_structure")] #[doc(alias = "gst_query_get_structure")] @@ -64,6 +85,13 @@ impl QueryRef { unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_SERIALIZED != 0 } } + #[doc(alias = "get_type")] + #[doc(alias = "GST_QUERY_TYPE")] + #[inline] + pub fn type_(&self) -> QueryType { + unsafe { from_glib((*self.as_ptr()).type_) } + } + pub fn view(&self) -> QueryView { unsafe { let type_ = (*self.as_ptr()).type_; @@ -2185,4 +2213,24 @@ mod tests { uri_q.set_uri::(None); */ } + + #[test] + fn query_type() { + crate::init().unwrap(); + + assert!(!QueryType::Allocation.is_upstream()); + assert!(QueryType::Allocation.is_downstream()); + assert!(QueryType::Allocation.is_serialized()); + + assert!(QueryType::Latency.is_upstream()); + assert!(QueryType::Latency.is_downstream()); + assert!(!QueryType::Latency.is_serialized()); + + assert!(QueryType::Scheduling.is_upstream()); + assert!(!QueryType::Scheduling.is_downstream()); + assert!(!QueryType::Scheduling.is_serialized()); + + let lat = Latency::new(); + assert_eq!(lat.type_(), QueryType::Latency); + } }