gst: manual changes further to QueryType generation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1740>
This commit is contained in:
François Laignel 2025-06-19 12:57:06 +02:00
parent 98b5eb593e
commit bf982f4221

View file

@ -15,12 +15,33 @@ use crate::{
ffi, ffi,
format::{CompatibleFormattedValue, FormattedValue, GenericFormattedValue}, format::{CompatibleFormattedValue, FormattedValue, GenericFormattedValue},
structure::*, structure::*,
QueryType,
}; };
mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || { mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || {
ffi::gst_query_get_type() 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 { impl QueryRef {
#[doc(alias = "get_structure")] #[doc(alias = "get_structure")]
#[doc(alias = "gst_query_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 } 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 { pub fn view(&self) -> QueryView {
unsafe { unsafe {
let type_ = (*self.as_ptr()).type_; let type_ = (*self.as_ptr()).type_;
@ -2185,4 +2213,24 @@ mod tests {
uri_q.set_uri::<str>(None); uri_q.set_uri::<str>(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);
}
} }