gstreamer/
query.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{
4    borrow::{Borrow, BorrowMut},
5    ffi::CStr,
6    fmt, mem,
7    ops::{Deref, DerefMut},
8    ptr,
9};
10
11use glib::{object::IsA, translate::*};
12
13use crate::{
14    ffi,
15    format::{CompatibleFormattedValue, FormattedValue, GenericFormattedValue},
16    structure::*,
17};
18
19mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, || {
20    ffi::gst_query_get_type()
21});
22
23impl QueryRef {
24    #[doc(alias = "get_structure")]
25    #[doc(alias = "gst_query_get_structure")]
26    #[inline]
27    pub fn structure(&self) -> Option<&StructureRef> {
28        unsafe {
29            let structure = ffi::gst_query_get_structure(self.as_mut_ptr());
30            if structure.is_null() {
31                None
32            } else {
33                Some(StructureRef::from_glib_borrow(structure))
34            }
35        }
36    }
37
38    #[doc(alias = "get_mut_structure")]
39    #[doc(alias = "gst_query_writable_structure")]
40    #[inline]
41    pub fn structure_mut(&mut self) -> &mut StructureRef {
42        unsafe {
43            let structure = ffi::gst_query_writable_structure(self.as_mut_ptr());
44            StructureRef::from_glib_borrow_mut(structure)
45        }
46    }
47
48    #[doc(alias = "GST_QUERY_IS_DOWNSTREAM")]
49    #[inline]
50    pub fn is_downstream(&self) -> bool {
51        unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_DOWNSTREAM != 0 }
52    }
53
54    #[doc(alias = "GST_QUERY_IS_UPSTREAM")]
55    #[inline]
56    pub fn is_upstream(&self) -> bool {
57        unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_UPSTREAM != 0 }
58    }
59
60    #[doc(alias = "GST_QUERY_IS_SERIALIZED")]
61    #[inline]
62    pub fn is_serialized(&self) -> bool {
63        unsafe { ((*self.as_ptr()).type_ as u32) & ffi::GST_QUERY_TYPE_SERIALIZED != 0 }
64    }
65
66    pub fn view(&self) -> QueryView {
67        unsafe {
68            let type_ = (*self.as_ptr()).type_;
69
70            match type_ {
71                ffi::GST_QUERY_POSITION => Position::view(self),
72                ffi::GST_QUERY_DURATION => Duration::view(self),
73                ffi::GST_QUERY_LATENCY => Latency::view(self),
74                ffi::GST_QUERY_SEEKING => Seeking::view(self),
75                ffi::GST_QUERY_SEGMENT => Segment::view(self),
76                ffi::GST_QUERY_CONVERT => Convert::view(self),
77                ffi::GST_QUERY_FORMATS => Formats::view(self),
78                ffi::GST_QUERY_BUFFERING => Buffering::view(self),
79                ffi::GST_QUERY_CUSTOM => Custom::view(self),
80                ffi::GST_QUERY_URI => Uri::view(self),
81                ffi::GST_QUERY_ALLOCATION => Allocation::view(self),
82                ffi::GST_QUERY_SCHEDULING => Scheduling::view(self),
83                ffi::GST_QUERY_ACCEPT_CAPS => AcceptCaps::view(self),
84                ffi::GST_QUERY_CAPS => Caps::view(self),
85                ffi::GST_QUERY_DRAIN => Drain::view(self),
86                ffi::GST_QUERY_CONTEXT => Context::view(self),
87                #[cfg(feature = "v1_16")]
88                ffi::GST_QUERY_BITRATE => Bitrate::view(self),
89                #[cfg(feature = "v1_22")]
90                ffi::GST_QUERY_SELECTABLE => Selectable::view(self),
91                _ => Other::view(self),
92            }
93        }
94    }
95
96    pub fn view_mut(&mut self) -> QueryViewMut {
97        unsafe {
98            let type_ = (*self.as_ptr()).type_;
99
100            match type_ {
101                ffi::GST_QUERY_POSITION => Position::view_mut(self),
102                ffi::GST_QUERY_DURATION => Duration::view_mut(self),
103                ffi::GST_QUERY_LATENCY => Latency::view_mut(self),
104                ffi::GST_QUERY_SEEKING => Seeking::view_mut(self),
105                ffi::GST_QUERY_SEGMENT => Segment::view_mut(self),
106                ffi::GST_QUERY_CONVERT => Convert::view_mut(self),
107                ffi::GST_QUERY_FORMATS => Formats::view_mut(self),
108                ffi::GST_QUERY_BUFFERING => Buffering::view_mut(self),
109                ffi::GST_QUERY_CUSTOM => Custom::view_mut(self),
110                ffi::GST_QUERY_URI => Uri::view_mut(self),
111                ffi::GST_QUERY_ALLOCATION => Allocation::view_mut(self),
112                ffi::GST_QUERY_SCHEDULING => Scheduling::view_mut(self),
113                ffi::GST_QUERY_ACCEPT_CAPS => AcceptCaps::view_mut(self),
114                ffi::GST_QUERY_CAPS => Caps::view_mut(self),
115                ffi::GST_QUERY_DRAIN => Drain::view_mut(self),
116                ffi::GST_QUERY_CONTEXT => Context::view_mut(self),
117                #[cfg(feature = "v1_16")]
118                ffi::GST_QUERY_BITRATE => Bitrate::view_mut(self),
119                #[cfg(feature = "v1_22")]
120                ffi::GST_QUERY_SELECTABLE => Selectable::view_mut(self),
121                _ => Other::view_mut(self),
122            }
123        }
124    }
125}
126
127impl fmt::Debug for Query {
128    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
129        QueryRef::fmt(self, f)
130    }
131}
132
133impl fmt::Debug for QueryRef {
134    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135        f.debug_struct("Query")
136            .field("ptr", &self.as_ptr())
137            .field("type", &unsafe {
138                let type_ = ffi::gst_query_type_get_name((*self.as_ptr()).type_);
139                CStr::from_ptr(type_).to_str().unwrap()
140            })
141            .field("structure", &self.structure())
142            .finish()
143    }
144}
145
146#[derive(Debug)]
147#[non_exhaustive]
148pub enum QueryView<'a> {
149    Position(&'a Position),
150    Duration(&'a Duration),
151    Latency(&'a Latency),
152    Seeking(&'a Seeking),
153    Segment(&'a Segment),
154    Convert(&'a Convert),
155    Formats(&'a Formats),
156    Buffering(&'a Buffering),
157    Custom(&'a Custom),
158    Uri(&'a Uri),
159    Allocation(&'a Allocation),
160    Scheduling(&'a Scheduling),
161    AcceptCaps(&'a AcceptCaps),
162    Caps(&'a Caps),
163    Drain(&'a Drain),
164    Context(&'a Context),
165    #[cfg(feature = "v1_16")]
166    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
167    Bitrate(&'a Bitrate),
168    #[cfg(feature = "v1_22")]
169    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
170    Selectable(&'a Selectable),
171    Other(&'a Other),
172}
173
174#[derive(Debug)]
175#[non_exhaustive]
176pub enum QueryViewMut<'a> {
177    Position(&'a mut Position),
178    Duration(&'a mut Duration),
179    Latency(&'a mut Latency),
180    Seeking(&'a mut Seeking),
181    Segment(&'a mut Segment),
182    Convert(&'a mut Convert),
183    Formats(&'a mut Formats),
184    Buffering(&'a mut Buffering),
185    Custom(&'a mut Custom),
186    Uri(&'a mut Uri),
187    Allocation(&'a mut Allocation),
188    Scheduling(&'a mut Scheduling),
189    AcceptCaps(&'a mut AcceptCaps),
190    Caps(&'a mut Caps),
191    Drain(&'a mut Drain),
192    Context(&'a mut Context),
193    #[cfg(feature = "v1_16")]
194    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
195    Bitrate(&'a mut Bitrate),
196    #[cfg(feature = "v1_22")]
197    #[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
198    Selectable(&'a mut Selectable),
199    Other(&'a mut Other),
200}
201
202macro_rules! declare_concrete_query(
203    ($name:ident, $param:ident) => {
204        #[repr(transparent)]
205        pub struct $name<$param = QueryRef>($param);
206
207        impl $name {
208            #[inline]
209            pub fn query(&self) -> &QueryRef {
210                unsafe { &*(self as *const Self as *const QueryRef) }
211            }
212
213            #[inline]
214            pub fn query_mut(&mut self) -> &mut QueryRef {
215                unsafe { &mut *(self as *mut Self as *mut QueryRef) }
216            }
217
218            #[inline]
219            unsafe fn view(query: &QueryRef) -> QueryView<'_> {
220                let query = &*(query as *const QueryRef as *const Self);
221                QueryView::$name(query)
222            }
223
224            #[inline]
225            unsafe fn view_mut(query: &mut QueryRef) -> QueryViewMut<'_> {
226                let query = &mut *(query as *mut QueryRef as *mut Self);
227                QueryViewMut::$name(query)
228            }
229        }
230
231        impl Deref for $name {
232            type Target = QueryRef;
233
234            #[inline]
235            fn deref(&self) -> &Self::Target {
236                self.query()
237            }
238        }
239
240        impl DerefMut for $name {
241            #[inline]
242            fn deref_mut(&mut self) -> &mut Self::Target {
243                self.query_mut()
244            }
245        }
246
247        impl ToOwned for $name {
248            type Owned = $name<Query>;
249
250            #[inline]
251            fn to_owned(&self) -> Self::Owned {
252                $name::<Query>(self.copy())
253            }
254        }
255
256        impl $name<Query> {
257            #[inline]
258            pub fn get_mut(&mut self) -> Option<&mut $name> {
259                self.0
260                    .get_mut()
261                    .map(|query| unsafe { &mut *(query as *mut QueryRef as *mut $name) })
262            }
263        }
264
265        impl Deref for $name<Query> {
266            type Target = $name;
267
268            #[inline]
269            fn deref(&self) -> &Self::Target {
270                unsafe { &*(self.0.as_ptr() as *const Self::Target) }
271            }
272        }
273
274        impl DerefMut for $name<Query> {
275            #[inline]
276            fn deref_mut(&mut self) -> &mut Self::Target {
277                debug_assert!(self.0.is_writable());
278                unsafe { &mut *(self.0.as_mut_ptr() as *mut Self::Target) }
279            }
280        }
281
282        impl Borrow<$name> for $name<Query> {
283            #[inline]
284            fn borrow(&self) -> &$name {
285                &*self
286            }
287        }
288
289        impl BorrowMut<$name> for $name<Query> {
290            #[inline]
291            fn borrow_mut(&mut self) -> &mut $name {
292                &mut *self
293            }
294        }
295
296        impl From<$name<Query>> for Query {
297            #[inline]
298            fn from(concrete: $name<Query>) -> Self {
299                skip_assert_initialized!();
300                concrete.0
301            }
302        }
303    }
304);
305
306declare_concrete_query!(Position, T);
307impl Position<Query> {
308    #[doc(alias = "gst_query_new_position")]
309    pub fn new(fmt: crate::Format) -> Self {
310        assert_initialized_main_thread!();
311        unsafe { Self(from_glib_full(ffi::gst_query_new_position(fmt.into_glib()))) }
312    }
313}
314
315impl Position {
316    #[doc(alias = "get_result")]
317    #[doc(alias = "gst_query_parse_position")]
318    pub fn result(&self) -> GenericFormattedValue {
319        unsafe {
320            let mut fmt = mem::MaybeUninit::uninit();
321            let mut pos = mem::MaybeUninit::uninit();
322
323            ffi::gst_query_parse_position(self.as_mut_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr());
324
325            GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init())
326        }
327    }
328
329    #[doc(alias = "get_format")]
330    #[doc(alias = "gst_query_parse_position")]
331    pub fn format(&self) -> crate::Format {
332        unsafe {
333            let mut fmt = mem::MaybeUninit::uninit();
334
335            ffi::gst_query_parse_position(self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut());
336
337            from_glib(fmt.assume_init())
338        }
339    }
340
341    #[doc(alias = "gst_query_set_position")]
342    pub fn set(&mut self, pos: impl FormattedValue) {
343        assert_eq!(pos.format(), self.format());
344        unsafe {
345            ffi::gst_query_set_position(
346                self.as_mut_ptr(),
347                pos.format().into_glib(),
348                pos.into_raw_value(),
349            );
350        }
351    }
352}
353
354impl std::fmt::Debug for Position {
355    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
356        f.debug_struct("Position")
357            .field("structure", &self.query().structure())
358            .field("result", &self.result())
359            .field("format", &self.format())
360            .finish()
361    }
362}
363
364impl std::fmt::Debug for Position<Query> {
365    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
366        Position::<QueryRef>::fmt(self, f)
367    }
368}
369
370declare_concrete_query!(Duration, T);
371impl Duration<Query> {
372    #[doc(alias = "gst_query_new_duration")]
373    pub fn new(fmt: crate::Format) -> Self {
374        assert_initialized_main_thread!();
375        unsafe { Self(from_glib_full(ffi::gst_query_new_duration(fmt.into_glib()))) }
376    }
377}
378
379impl Duration {
380    #[doc(alias = "get_result")]
381    #[doc(alias = "gst_query_parse_duration")]
382    pub fn result(&self) -> GenericFormattedValue {
383        unsafe {
384            let mut fmt = mem::MaybeUninit::uninit();
385            let mut pos = mem::MaybeUninit::uninit();
386
387            ffi::gst_query_parse_duration(self.as_mut_ptr(), fmt.as_mut_ptr(), pos.as_mut_ptr());
388
389            GenericFormattedValue::new(from_glib(fmt.assume_init()), pos.assume_init())
390        }
391    }
392
393    #[doc(alias = "get_format")]
394    #[doc(alias = "gst_query_parse_duration")]
395    pub fn format(&self) -> crate::Format {
396        unsafe {
397            let mut fmt = mem::MaybeUninit::uninit();
398
399            ffi::gst_query_parse_duration(self.as_mut_ptr(), fmt.as_mut_ptr(), ptr::null_mut());
400
401            from_glib(fmt.assume_init())
402        }
403    }
404
405    #[doc(alias = "gst_query_set_duration")]
406    pub fn set(&mut self, dur: impl FormattedValue) {
407        assert_eq!(dur.format(), self.format());
408        unsafe {
409            ffi::gst_query_set_duration(
410                self.as_mut_ptr(),
411                dur.format().into_glib(),
412                dur.into_raw_value(),
413            );
414        }
415    }
416}
417
418impl std::fmt::Debug for Duration {
419    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
420        f.debug_struct("Duration")
421            .field("structure", &self.query().structure())
422            .field("result", &self.result())
423            .field("format", &self.format())
424            .finish()
425    }
426}
427
428impl std::fmt::Debug for Duration<Query> {
429    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
430        Duration::<QueryRef>::fmt(self, f)
431    }
432}
433
434declare_concrete_query!(Latency, T);
435impl Latency<Query> {
436    #[doc(alias = "gst_query_new_latency")]
437    pub fn new() -> Self {
438        assert_initialized_main_thread!();
439        unsafe { Self(from_glib_full(ffi::gst_query_new_latency())) }
440    }
441}
442
443impl Default for Latency<Query> {
444    fn default() -> Self {
445        Self::new()
446    }
447}
448
449impl Latency {
450    #[doc(alias = "get_result")]
451    #[doc(alias = "gst_query_parse_latency")]
452    pub fn result(&self) -> (bool, crate::ClockTime, Option<crate::ClockTime>) {
453        unsafe {
454            let mut live = mem::MaybeUninit::uninit();
455            let mut min = mem::MaybeUninit::uninit();
456            let mut max = mem::MaybeUninit::uninit();
457
458            ffi::gst_query_parse_latency(
459                self.as_mut_ptr(),
460                live.as_mut_ptr(),
461                min.as_mut_ptr(),
462                max.as_mut_ptr(),
463            );
464
465            (
466                from_glib(live.assume_init()),
467                try_from_glib(min.assume_init()).expect("undefined min latency"),
468                from_glib(max.assume_init()),
469            )
470        }
471    }
472
473    #[doc(alias = "gst_query_set_latency")]
474    pub fn set(
475        &mut self,
476        live: bool,
477        min: crate::ClockTime,
478        max: impl Into<Option<crate::ClockTime>>,
479    ) {
480        unsafe {
481            ffi::gst_query_set_latency(
482                self.as_mut_ptr(),
483                live.into_glib(),
484                min.into_glib(),
485                max.into().into_glib(),
486            );
487        }
488    }
489}
490
491impl std::fmt::Debug for Latency {
492    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
493        f.debug_struct("Latency")
494            .field("structure", &self.query().structure())
495            .field("result", &self.result())
496            .finish()
497    }
498}
499
500impl std::fmt::Debug for Latency<Query> {
501    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
502        Latency::<QueryRef>::fmt(self, f)
503    }
504}
505
506declare_concrete_query!(Seeking, T);
507impl Seeking<Query> {
508    #[doc(alias = "gst_query_new_seeking")]
509    pub fn new(fmt: crate::Format) -> Self {
510        assert_initialized_main_thread!();
511        unsafe { Self(from_glib_full(ffi::gst_query_new_seeking(fmt.into_glib()))) }
512    }
513}
514
515impl Seeking {
516    #[doc(alias = "get_result")]
517    #[doc(alias = "gst_query_parse_seeking")]
518    pub fn result(&self) -> (bool, GenericFormattedValue, GenericFormattedValue) {
519        unsafe {
520            let mut fmt = mem::MaybeUninit::uninit();
521            let mut seekable = mem::MaybeUninit::uninit();
522            let mut start = mem::MaybeUninit::uninit();
523            let mut end = mem::MaybeUninit::uninit();
524            ffi::gst_query_parse_seeking(
525                self.as_mut_ptr(),
526                fmt.as_mut_ptr(),
527                seekable.as_mut_ptr(),
528                start.as_mut_ptr(),
529                end.as_mut_ptr(),
530            );
531
532            (
533                from_glib(seekable.assume_init()),
534                GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
535                GenericFormattedValue::new(from_glib(fmt.assume_init()), end.assume_init()),
536            )
537        }
538    }
539
540    #[doc(alias = "get_format")]
541    #[doc(alias = "gst_query_parse_seeking")]
542    pub fn format(&self) -> crate::Format {
543        unsafe {
544            let mut fmt = mem::MaybeUninit::uninit();
545            ffi::gst_query_parse_seeking(
546                self.as_mut_ptr(),
547                fmt.as_mut_ptr(),
548                ptr::null_mut(),
549                ptr::null_mut(),
550                ptr::null_mut(),
551            );
552
553            from_glib(fmt.assume_init())
554        }
555    }
556
557    #[doc(alias = "gst_query_set_seeking")]
558    pub fn set<V: FormattedValue>(
559        &mut self,
560        seekable: bool,
561        start: V,
562        end: impl CompatibleFormattedValue<V>,
563    ) {
564        assert_eq!(self.format(), start.format());
565        let end = end.try_into_checked(start).unwrap();
566
567        unsafe {
568            ffi::gst_query_set_seeking(
569                self.as_mut_ptr(),
570                start.format().into_glib(),
571                seekable.into_glib(),
572                start.into_raw_value(),
573                end.into_raw_value(),
574            );
575        }
576    }
577}
578
579impl std::fmt::Debug for Seeking {
580    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
581        f.debug_struct("Seeking")
582            .field("structure", &self.query().structure())
583            .field("result", &self.result())
584            .field("format", &self.format())
585            .finish()
586    }
587}
588
589impl std::fmt::Debug for Seeking<Query> {
590    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
591        Seeking::<QueryRef>::fmt(self, f)
592    }
593}
594
595declare_concrete_query!(Segment, T);
596impl Segment<Query> {
597    #[doc(alias = "gst_query_new_segment")]
598    pub fn new(fmt: crate::Format) -> Self {
599        assert_initialized_main_thread!();
600        unsafe { Self(from_glib_full(ffi::gst_query_new_segment(fmt.into_glib()))) }
601    }
602}
603
604impl Segment {
605    #[doc(alias = "get_result")]
606    #[doc(alias = "gst_query_parse_segment")]
607    pub fn result(&self) -> (f64, GenericFormattedValue, GenericFormattedValue) {
608        unsafe {
609            let mut rate = mem::MaybeUninit::uninit();
610            let mut fmt = mem::MaybeUninit::uninit();
611            let mut start = mem::MaybeUninit::uninit();
612            let mut stop = mem::MaybeUninit::uninit();
613
614            ffi::gst_query_parse_segment(
615                self.as_mut_ptr(),
616                rate.as_mut_ptr(),
617                fmt.as_mut_ptr(),
618                start.as_mut_ptr(),
619                stop.as_mut_ptr(),
620            );
621            (
622                rate.assume_init(),
623                GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
624                GenericFormattedValue::new(from_glib(fmt.assume_init()), stop.assume_init()),
625            )
626        }
627    }
628
629    #[doc(alias = "get_format")]
630    #[doc(alias = "gst_query_parse_segment")]
631    pub fn format(&self) -> crate::Format {
632        unsafe {
633            let mut fmt = mem::MaybeUninit::uninit();
634
635            ffi::gst_query_parse_segment(
636                self.as_mut_ptr(),
637                ptr::null_mut(),
638                fmt.as_mut_ptr(),
639                ptr::null_mut(),
640                ptr::null_mut(),
641            );
642            from_glib(fmt.assume_init())
643        }
644    }
645
646    #[doc(alias = "gst_query_set_segment")]
647    pub fn set<V: FormattedValue>(
648        &mut self,
649        rate: f64,
650        start: V,
651        stop: impl CompatibleFormattedValue<V>,
652    ) {
653        let stop = stop.try_into_checked(start).unwrap();
654
655        unsafe {
656            ffi::gst_query_set_segment(
657                self.as_mut_ptr(),
658                rate,
659                start.format().into_glib(),
660                start.into_raw_value(),
661                stop.into_raw_value(),
662            );
663        }
664    }
665}
666
667impl std::fmt::Debug for Segment {
668    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
669        f.debug_struct("Segment")
670            .field("structure", &self.query().structure())
671            .field("result", &self.result())
672            .field("format", &self.format())
673            .finish()
674    }
675}
676
677impl std::fmt::Debug for Segment<Query> {
678    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
679        Segment::<QueryRef>::fmt(self, f)
680    }
681}
682
683declare_concrete_query!(Convert, T);
684impl Convert<Query> {
685    #[doc(alias = "gst_query_new_convert")]
686    pub fn new(value: impl FormattedValue, dest_fmt: crate::Format) -> Self {
687        assert_initialized_main_thread!();
688        unsafe {
689            Self(from_glib_full(ffi::gst_query_new_convert(
690                value.format().into_glib(),
691                value.into_raw_value(),
692                dest_fmt.into_glib(),
693            )))
694        }
695    }
696}
697
698impl Convert {
699    #[doc(alias = "get_result")]
700    #[doc(alias = "gst_query_parse_convert")]
701    pub fn result(&self) -> (GenericFormattedValue, GenericFormattedValue) {
702        unsafe {
703            let mut src_fmt = mem::MaybeUninit::uninit();
704            let mut src = mem::MaybeUninit::uninit();
705            let mut dest_fmt = mem::MaybeUninit::uninit();
706            let mut dest = mem::MaybeUninit::uninit();
707
708            ffi::gst_query_parse_convert(
709                self.as_mut_ptr(),
710                src_fmt.as_mut_ptr(),
711                src.as_mut_ptr(),
712                dest_fmt.as_mut_ptr(),
713                dest.as_mut_ptr(),
714            );
715            (
716                GenericFormattedValue::new(from_glib(src_fmt.assume_init()), src.assume_init()),
717                GenericFormattedValue::new(from_glib(dest_fmt.assume_init()), dest.assume_init()),
718            )
719        }
720    }
721
722    #[doc(alias = "gst_query_parse_convert")]
723    pub fn get(&self) -> (GenericFormattedValue, crate::Format) {
724        unsafe {
725            let mut src_fmt = mem::MaybeUninit::uninit();
726            let mut src = mem::MaybeUninit::uninit();
727            let mut dest_fmt = mem::MaybeUninit::uninit();
728
729            ffi::gst_query_parse_convert(
730                self.as_mut_ptr(),
731                src_fmt.as_mut_ptr(),
732                src.as_mut_ptr(),
733                dest_fmt.as_mut_ptr(),
734                ptr::null_mut(),
735            );
736            (
737                GenericFormattedValue::new(from_glib(src_fmt.assume_init()), src.assume_init()),
738                from_glib(dest_fmt.assume_init()),
739            )
740        }
741    }
742
743    #[doc(alias = "gst_query_set_convert")]
744    pub fn set(&mut self, src: impl FormattedValue, dest: impl FormattedValue) {
745        unsafe {
746            ffi::gst_query_set_convert(
747                self.as_mut_ptr(),
748                src.format().into_glib(),
749                src.into_raw_value(),
750                dest.format().into_glib(),
751                dest.into_raw_value(),
752            );
753        }
754    }
755}
756
757impl std::fmt::Debug for Convert {
758    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
759        let (source, dest) = self.result();
760
761        f.debug_struct("Convert")
762            .field("structure", &self.query().structure())
763            .field("source", &source)
764            .field("dest", &dest)
765            .finish()
766    }
767}
768
769impl std::fmt::Debug for Convert<Query> {
770    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
771        Convert::<QueryRef>::fmt(self, f)
772    }
773}
774
775declare_concrete_query!(Formats, T);
776impl Formats<Query> {
777    #[doc(alias = "gst_query_new_formats")]
778    pub fn new() -> Self {
779        assert_initialized_main_thread!();
780        unsafe { Self(from_glib_full(ffi::gst_query_new_formats())) }
781    }
782}
783
784impl Default for Formats<Query> {
785    fn default() -> Self {
786        Self::new()
787    }
788}
789
790impl Formats {
791    #[doc(alias = "get_result")]
792    #[doc(alias = "gst_query_parse_n_formats")]
793    #[doc(alias = "gst_query_parse_nth_format")]
794    pub fn result(&self) -> Vec<crate::Format> {
795        unsafe {
796            let mut n = mem::MaybeUninit::uninit();
797            ffi::gst_query_parse_n_formats(self.as_mut_ptr(), n.as_mut_ptr());
798            let n = n.assume_init();
799            let mut res = Vec::with_capacity(n as usize);
800
801            for i in 0..n {
802                let mut fmt = mem::MaybeUninit::uninit();
803                ffi::gst_query_parse_nth_format(self.as_mut_ptr(), i, fmt.as_mut_ptr());
804                res.push(from_glib(fmt.assume_init()));
805            }
806
807            res
808        }
809    }
810
811    #[doc(alias = "gst_query_set_formats")]
812    #[doc(alias = "gst_query_set_formatsv")]
813    pub fn set(&mut self, formats: &[crate::Format]) {
814        unsafe {
815            let v: Vec<_> = formats.iter().map(|f| f.into_glib()).collect();
816            ffi::gst_query_set_formatsv(self.as_mut_ptr(), v.len() as i32, v.as_ptr() as *mut _);
817        }
818    }
819}
820
821impl std::fmt::Debug for Formats {
822    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
823        f.debug_struct("Formats")
824            .field("structure", &self.query().structure())
825            .field("result", &self.result())
826            .finish()
827    }
828}
829
830impl std::fmt::Debug for Formats<Query> {
831    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
832        Formats::<QueryRef>::fmt(self, f)
833    }
834}
835
836declare_concrete_query!(Buffering, T);
837impl Buffering<Query> {
838    #[doc(alias = "gst_query_new_buffering")]
839    pub fn new(fmt: crate::Format) -> Self {
840        assert_initialized_main_thread!();
841        unsafe {
842            Self(from_glib_full(ffi::gst_query_new_buffering(
843                fmt.into_glib(),
844            )))
845        }
846    }
847}
848
849impl Buffering {
850    #[doc(alias = "get_format")]
851    #[doc(alias = "gst_query_parse_buffering_range")]
852    pub fn format(&self) -> crate::Format {
853        unsafe {
854            let mut fmt = mem::MaybeUninit::uninit();
855
856            ffi::gst_query_parse_buffering_range(
857                self.as_mut_ptr(),
858                fmt.as_mut_ptr(),
859                ptr::null_mut(),
860                ptr::null_mut(),
861                ptr::null_mut(),
862            );
863
864            from_glib(fmt.assume_init())
865        }
866    }
867
868    #[doc(alias = "get_percent")]
869    #[doc(alias = "gst_query_parse_buffering_percent")]
870    pub fn percent(&self) -> (bool, i32) {
871        unsafe {
872            let mut busy = mem::MaybeUninit::uninit();
873            let mut percent = mem::MaybeUninit::uninit();
874
875            ffi::gst_query_parse_buffering_percent(
876                self.as_mut_ptr(),
877                busy.as_mut_ptr(),
878                percent.as_mut_ptr(),
879            );
880
881            (from_glib(busy.assume_init()), percent.assume_init())
882        }
883    }
884
885    #[doc(alias = "get_range")]
886    #[doc(alias = "gst_query_parse_buffering_range")]
887    pub fn range(&self) -> (GenericFormattedValue, GenericFormattedValue, i64) {
888        unsafe {
889            let mut fmt = mem::MaybeUninit::uninit();
890            let mut start = mem::MaybeUninit::uninit();
891            let mut stop = mem::MaybeUninit::uninit();
892            let mut estimated_total = mem::MaybeUninit::uninit();
893
894            ffi::gst_query_parse_buffering_range(
895                self.as_mut_ptr(),
896                fmt.as_mut_ptr(),
897                start.as_mut_ptr(),
898                stop.as_mut_ptr(),
899                estimated_total.as_mut_ptr(),
900            );
901            (
902                GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
903                GenericFormattedValue::new(from_glib(fmt.assume_init()), stop.assume_init()),
904                estimated_total.assume_init(),
905            )
906        }
907    }
908
909    #[doc(alias = "get_stats")]
910    #[doc(alias = "gst_query_parse_buffering_stats")]
911    pub fn stats(&self) -> (crate::BufferingMode, i32, i32, i64) {
912        unsafe {
913            let mut mode = mem::MaybeUninit::uninit();
914            let mut avg_in = mem::MaybeUninit::uninit();
915            let mut avg_out = mem::MaybeUninit::uninit();
916            let mut buffering_left = mem::MaybeUninit::uninit();
917
918            ffi::gst_query_parse_buffering_stats(
919                self.as_mut_ptr(),
920                mode.as_mut_ptr(),
921                avg_in.as_mut_ptr(),
922                avg_out.as_mut_ptr(),
923                buffering_left.as_mut_ptr(),
924            );
925
926            (
927                from_glib(mode.assume_init()),
928                avg_in.assume_init(),
929                avg_out.assume_init(),
930                buffering_left.assume_init(),
931            )
932        }
933    }
934
935    #[doc(alias = "get_ranges")]
936    #[doc(alias = "gst_query_get_n_buffering_ranges")]
937    #[doc(alias = "gst_query_parse_nth_buffering_range")]
938    pub fn ranges(&self) -> Vec<(GenericFormattedValue, GenericFormattedValue)> {
939        unsafe {
940            let mut fmt = mem::MaybeUninit::uninit();
941            ffi::gst_query_parse_buffering_range(
942                self.as_mut_ptr(),
943                fmt.as_mut_ptr(),
944                ptr::null_mut(),
945                ptr::null_mut(),
946                ptr::null_mut(),
947            );
948            let fmt = from_glib(fmt.assume_init());
949
950            let n = ffi::gst_query_get_n_buffering_ranges(self.as_mut_ptr());
951            let mut res = Vec::with_capacity(n as usize);
952            for i in 0..n {
953                let mut start = mem::MaybeUninit::uninit();
954                let mut stop = mem::MaybeUninit::uninit();
955                let s: bool = from_glib(ffi::gst_query_parse_nth_buffering_range(
956                    self.as_mut_ptr(),
957                    i,
958                    start.as_mut_ptr(),
959                    stop.as_mut_ptr(),
960                ));
961                if s {
962                    res.push((
963                        GenericFormattedValue::new(fmt, start.assume_init()),
964                        GenericFormattedValue::new(fmt, stop.assume_init()),
965                    ));
966                }
967            }
968
969            res
970        }
971    }
972
973    #[doc(alias = "gst_query_set_buffering_percent")]
974    pub fn set_percent(&mut self, busy: bool, percent: i32) {
975        unsafe {
976            ffi::gst_query_set_buffering_percent(self.as_mut_ptr(), busy.into_glib(), percent);
977        }
978    }
979
980    #[doc(alias = "gst_query_set_buffering_range")]
981    pub fn set_range<V: FormattedValue>(
982        &mut self,
983        start: V,
984        stop: impl CompatibleFormattedValue<V>,
985        estimated_total: i64,
986    ) {
987        assert_eq!(self.format(), start.format());
988        let stop = stop.try_into_checked(start).unwrap();
989
990        unsafe {
991            ffi::gst_query_set_buffering_range(
992                self.as_mut_ptr(),
993                start.format().into_glib(),
994                start.into_raw_value(),
995                stop.into_raw_value(),
996                estimated_total,
997            );
998        }
999    }
1000
1001    #[doc(alias = "gst_query_set_buffering_stats")]
1002    pub fn set_stats(
1003        &mut self,
1004        mode: crate::BufferingMode,
1005        avg_in: i32,
1006        avg_out: i32,
1007        buffering_left: i64,
1008    ) {
1009        skip_assert_initialized!();
1010        unsafe {
1011            ffi::gst_query_set_buffering_stats(
1012                self.as_mut_ptr(),
1013                mode.into_glib(),
1014                avg_in,
1015                avg_out,
1016                buffering_left,
1017            );
1018        }
1019    }
1020
1021    #[doc(alias = "gst_query_add_buffering_range")]
1022    pub fn add_buffering_ranges<V: FormattedValue, U: CompatibleFormattedValue<V> + Copy>(
1023        &mut self,
1024        ranges: &[(V, U)],
1025    ) {
1026        unsafe {
1027            let fmt = self.format();
1028
1029            for &(start, stop) in ranges {
1030                assert_eq!(start.format(), fmt);
1031                let stop = stop.try_into_checked(start).unwrap();
1032                ffi::gst_query_add_buffering_range(
1033                    self.as_mut_ptr(),
1034                    start.into_raw_value(),
1035                    stop.into_raw_value(),
1036                );
1037            }
1038        }
1039    }
1040}
1041
1042impl std::fmt::Debug for Buffering {
1043    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1044        f.debug_struct("Buffering")
1045            .field("structure", &self.query().structure())
1046            .field("format", &self.format())
1047            .field("percent", &self.percent())
1048            .field("range", &self.range())
1049            .finish()
1050    }
1051}
1052
1053impl std::fmt::Debug for Buffering<Query> {
1054    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1055        Buffering::<QueryRef>::fmt(self, f)
1056    }
1057}
1058
1059declare_concrete_query!(Custom, T);
1060impl Custom<Query> {
1061    #[doc(alias = "gst_query_new_custom")]
1062    pub fn new(structure: crate::Structure) -> Self {
1063        skip_assert_initialized!();
1064        unsafe {
1065            Self(from_glib_full(ffi::gst_query_new_custom(
1066                ffi::GST_QUERY_CUSTOM,
1067                structure.into_glib_ptr(),
1068            )))
1069        }
1070    }
1071}
1072
1073impl std::fmt::Debug for Custom {
1074    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1075        f.debug_struct("Custom")
1076            .field("structure", &self.query().structure())
1077            .finish()
1078    }
1079}
1080
1081impl std::fmt::Debug for Custom<Query> {
1082    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1083        Custom::<QueryRef>::fmt(self, f)
1084    }
1085}
1086
1087declare_concrete_query!(Uri, T);
1088impl Uri<Query> {
1089    #[doc(alias = "gst_query_new_uri")]
1090    pub fn new() -> Self {
1091        assert_initialized_main_thread!();
1092        unsafe { Self(from_glib_full(ffi::gst_query_new_uri())) }
1093    }
1094}
1095
1096impl Default for Uri<Query> {
1097    fn default() -> Self {
1098        Self::new()
1099    }
1100}
1101
1102impl Uri {
1103    #[doc(alias = "get_uri")]
1104    #[doc(alias = "gst_query_parse_uri")]
1105    pub fn uri(&self) -> Option<glib::GString> {
1106        unsafe {
1107            let mut uri = ptr::null_mut();
1108            ffi::gst_query_parse_uri(self.as_mut_ptr(), &mut uri);
1109            from_glib_full(uri)
1110        }
1111    }
1112
1113    #[doc(alias = "get_redirection")]
1114    #[doc(alias = "gst_query_parse_uri_redirection")]
1115    #[doc(alias = "gst_query_parse_uri_redirection_permanent")]
1116    pub fn redirection(&self) -> (Option<glib::GString>, bool) {
1117        unsafe {
1118            let mut uri = ptr::null_mut();
1119            ffi::gst_query_parse_uri_redirection(self.as_mut_ptr(), &mut uri);
1120            let mut permanent = mem::MaybeUninit::uninit();
1121            ffi::gst_query_parse_uri_redirection_permanent(
1122                self.as_mut_ptr(),
1123                permanent.as_mut_ptr(),
1124            );
1125
1126            (from_glib_full(uri), from_glib(permanent.assume_init()))
1127        }
1128    }
1129
1130    #[doc(alias = "gst_query_set_uri")]
1131    pub fn set_uri<'a, T>(&mut self, uri: impl Into<Option<&'a T>>)
1132    where
1133        T: 'a + AsRef<str> + ?Sized,
1134    {
1135        unsafe {
1136            ffi::gst_query_set_uri(
1137                self.as_mut_ptr(),
1138                uri.into().map(AsRef::as_ref).to_glib_none().0,
1139            );
1140        }
1141    }
1142
1143    #[doc(alias = "gst_query_set_uri_redirection")]
1144    #[doc(alias = "gst_query_set_uri_redirection_permanent")]
1145    pub fn set_redirection<'a, T>(&mut self, uri: impl Into<Option<&'a T>>, permanent: bool)
1146    where
1147        T: 'a + AsRef<str> + ?Sized,
1148    {
1149        unsafe {
1150            ffi::gst_query_set_uri_redirection(
1151                self.as_mut_ptr(),
1152                uri.into().map(AsRef::as_ref).to_glib_none().0,
1153            );
1154            ffi::gst_query_set_uri_redirection_permanent(
1155                self.0.as_mut_ptr(),
1156                permanent.into_glib(),
1157            );
1158        }
1159    }
1160}
1161
1162impl std::fmt::Debug for Uri {
1163    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1164        let (redirection, permanent) = self.redirection();
1165        f.debug_struct("Uri")
1166            .field("structure", &self.query().structure())
1167            .field("uri", &self.uri())
1168            .field("redirection", &redirection)
1169            .field("redirection-permanent", &permanent)
1170            .finish()
1171    }
1172}
1173
1174impl std::fmt::Debug for Uri<Query> {
1175    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1176        Uri::<QueryRef>::fmt(self, f)
1177    }
1178}
1179
1180declare_concrete_query!(Allocation, T);
1181impl Allocation<Query> {
1182    #[doc(alias = "gst_query_new_allocation")]
1183    pub fn new(caps: Option<&crate::Caps>, need_pool: bool) -> Self {
1184        skip_assert_initialized!();
1185        unsafe {
1186            Self(from_glib_full(ffi::gst_query_new_allocation(
1187                caps.map(|caps| caps.as_mut_ptr())
1188                    .unwrap_or(ptr::null_mut()),
1189                need_pool.into_glib(),
1190            )))
1191        }
1192    }
1193}
1194
1195impl Allocation {
1196    #[doc(alias = "gst_query_parse_allocation")]
1197    pub fn get(&self) -> (Option<&crate::CapsRef>, bool) {
1198        unsafe {
1199            let mut caps = ptr::null_mut();
1200            let mut need_pool = mem::MaybeUninit::uninit();
1201
1202            ffi::gst_query_parse_allocation(self.as_mut_ptr(), &mut caps, need_pool.as_mut_ptr());
1203            (
1204                if caps.is_null() {
1205                    None
1206                } else {
1207                    Some(crate::CapsRef::from_ptr(caps))
1208                },
1209                from_glib(need_pool.assume_init()),
1210            )
1211        }
1212    }
1213
1214    #[doc(alias = "gst_query_parse_allocation")]
1215    pub fn get_owned(&self) -> (Option<crate::Caps>, bool) {
1216        unsafe {
1217            let (caps, need_pool) = self.get();
1218            (caps.map(|caps| from_glib_none(caps.as_ptr())), need_pool)
1219        }
1220    }
1221
1222    #[doc(alias = "gst_allocation_params")]
1223    #[doc(alias = "gst_query_get_n_allocation_params")]
1224    #[doc(alias = "gst_query_parse_nth_allocation_param")]
1225    pub fn allocation_params(&self) -> Vec<(Option<crate::Allocator>, crate::AllocationParams)> {
1226        unsafe {
1227            let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr());
1228            let mut params = Vec::with_capacity(n as usize);
1229            for i in 0..n {
1230                let mut allocator = ptr::null_mut();
1231                let mut p = mem::MaybeUninit::uninit();
1232                ffi::gst_query_parse_nth_allocation_param(
1233                    self.as_mut_ptr(),
1234                    i,
1235                    &mut allocator,
1236                    p.as_mut_ptr(),
1237                );
1238                params.push((from_glib_full(allocator), from_glib(p.assume_init())));
1239            }
1240
1241            params
1242        }
1243    }
1244
1245    #[doc(alias = "get_allocation_pools")]
1246    #[doc(alias = "gst_query_get_n_allocation_pools")]
1247    #[doc(alias = "gst_query_parse_nth_allocation_pool")]
1248    pub fn allocation_pools(&self) -> Vec<(Option<crate::BufferPool>, u32, u32, u32)> {
1249        unsafe {
1250            let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr());
1251            let mut pools = Vec::with_capacity(n as usize);
1252            for i in 0..n {
1253                let mut pool = ptr::null_mut();
1254                let mut size = mem::MaybeUninit::uninit();
1255                let mut min_buffers = mem::MaybeUninit::uninit();
1256                let mut max_buffers = mem::MaybeUninit::uninit();
1257
1258                ffi::gst_query_parse_nth_allocation_pool(
1259                    self.0.as_mut_ptr(),
1260                    i,
1261                    &mut pool,
1262                    size.as_mut_ptr(),
1263                    min_buffers.as_mut_ptr(),
1264                    max_buffers.as_mut_ptr(),
1265                );
1266                pools.push((
1267                    from_glib_full(pool),
1268                    size.assume_init(),
1269                    min_buffers.assume_init(),
1270                    max_buffers.assume_init(),
1271                ));
1272            }
1273
1274            pools
1275        }
1276    }
1277
1278    #[doc(alias = "get_allocation_metas")]
1279    #[doc(alias = "gst_query_get_n_allocation_metas")]
1280    #[doc(alias = "gst_query_parse_nth_allocation_meta")]
1281    pub fn allocation_metas(&self) -> Vec<(glib::Type, Option<&crate::StructureRef>)> {
1282        unsafe {
1283            let n = ffi::gst_query_get_n_allocation_metas(self.0.as_mut_ptr());
1284            let mut metas = Vec::with_capacity(n as usize);
1285            for i in 0..n {
1286                let mut structure = ptr::null();
1287
1288                let api =
1289                    ffi::gst_query_parse_nth_allocation_meta(self.as_mut_ptr(), i, &mut structure);
1290                metas.push((
1291                    from_glib(api),
1292                    if structure.is_null() {
1293                        None
1294                    } else {
1295                        Some(crate::StructureRef::from_glib_borrow(structure))
1296                    },
1297                ));
1298            }
1299
1300            metas
1301        }
1302    }
1303
1304    #[doc(alias = "gst_query_find_allocation_meta")]
1305    pub fn find_allocation_meta<U: crate::MetaAPI>(&self) -> Option<u32> {
1306        unsafe {
1307            let mut idx = mem::MaybeUninit::uninit();
1308            if ffi::gst_query_find_allocation_meta(
1309                self.as_mut_ptr(),
1310                U::meta_api().into_glib(),
1311                idx.as_mut_ptr(),
1312            ) != glib::ffi::GFALSE
1313            {
1314                Some(idx.assume_init())
1315            } else {
1316                None
1317            }
1318        }
1319    }
1320
1321    #[doc(alias = "gst_query_add_allocation_pool")]
1322    pub fn add_allocation_pool(
1323        &mut self,
1324        pool: Option<&impl IsA<crate::BufferPool>>,
1325        size: u32,
1326        min_buffers: u32,
1327        max_buffers: u32,
1328    ) {
1329        unsafe {
1330            ffi::gst_query_add_allocation_pool(
1331                self.as_mut_ptr(),
1332                pool.to_glib_none().0 as *mut ffi::GstBufferPool,
1333                size,
1334                min_buffers,
1335                max_buffers,
1336            );
1337        }
1338    }
1339
1340    #[doc(alias = "gst_query_set_nth_allocation_pool")]
1341    pub fn set_nth_allocation_pool(
1342        &mut self,
1343        idx: u32,
1344        pool: Option<&impl IsA<crate::BufferPool>>,
1345        size: u32,
1346        min_buffers: u32,
1347        max_buffers: u32,
1348    ) {
1349        unsafe {
1350            let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr());
1351            assert!(idx < n);
1352            ffi::gst_query_set_nth_allocation_pool(
1353                self.as_mut_ptr(),
1354                idx,
1355                pool.to_glib_none().0 as *mut ffi::GstBufferPool,
1356                size,
1357                min_buffers,
1358                max_buffers,
1359            );
1360        }
1361    }
1362
1363    #[doc(alias = "gst_query_remove_nth_allocation_pool")]
1364    pub fn remove_nth_allocation_pool(&mut self, idx: u32) {
1365        unsafe {
1366            let n = ffi::gst_query_get_n_allocation_pools(self.as_mut_ptr());
1367            assert!(idx < n);
1368            ffi::gst_query_remove_nth_allocation_pool(self.as_mut_ptr(), idx);
1369        }
1370    }
1371
1372    #[doc(alias = "gst_query_add_allocation_param")]
1373    pub fn add_allocation_param(
1374        &mut self,
1375        allocator: Option<&impl IsA<crate::Allocator>>,
1376        params: crate::AllocationParams,
1377    ) {
1378        unsafe {
1379            ffi::gst_query_add_allocation_param(
1380                self.as_mut_ptr(),
1381                allocator.to_glib_none().0 as *mut ffi::GstAllocator,
1382                params.as_ptr(),
1383            );
1384        }
1385    }
1386
1387    #[doc(alias = "gst_query_set_nth_allocation_param")]
1388    pub fn set_nth_allocation_param(
1389        &mut self,
1390        idx: u32,
1391        allocator: Option<&impl IsA<crate::Allocator>>,
1392        params: crate::AllocationParams,
1393    ) {
1394        unsafe {
1395            let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr());
1396            assert!(idx < n);
1397            ffi::gst_query_set_nth_allocation_param(
1398                self.as_mut_ptr(),
1399                idx,
1400                allocator.to_glib_none().0 as *mut ffi::GstAllocator,
1401                params.as_ptr(),
1402            );
1403        }
1404    }
1405
1406    #[doc(alias = "gst_query_remove_nth_allocation_param")]
1407    pub fn remove_nth_allocation_param(&mut self, idx: u32) {
1408        unsafe {
1409            let n = ffi::gst_query_get_n_allocation_params(self.as_mut_ptr());
1410            assert!(idx < n);
1411            ffi::gst_query_remove_nth_allocation_param(self.as_mut_ptr(), idx);
1412        }
1413    }
1414
1415    #[doc(alias = "gst_query_add_allocation_meta")]
1416    pub fn add_allocation_meta<U: crate::MetaAPI>(
1417        &mut self,
1418        structure: Option<&crate::StructureRef>,
1419    ) {
1420        unsafe {
1421            ffi::gst_query_add_allocation_meta(
1422                self.as_mut_ptr(),
1423                U::meta_api().into_glib(),
1424                if let Some(structure) = structure {
1425                    structure.as_ptr()
1426                } else {
1427                    ptr::null()
1428                },
1429            );
1430        }
1431    }
1432
1433    #[doc(alias = "gst_query_remove_nth_allocation_meta")]
1434    pub fn remove_nth_allocation_meta(&mut self, idx: u32) {
1435        unsafe {
1436            let n = ffi::gst_query_get_n_allocation_metas(self.as_mut_ptr());
1437            assert!(idx < n);
1438            ffi::gst_query_remove_nth_allocation_meta(self.as_mut_ptr(), idx);
1439        }
1440    }
1441}
1442
1443impl std::fmt::Debug for Allocation {
1444    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1445        let (caps, need_pool) = self.get();
1446        f.debug_struct("Allocation")
1447            .field("structure", &self.query().structure())
1448            .field("caps", &caps)
1449            .field("need-pool", &need_pool)
1450            .field("allocation-params", &self.allocation_params())
1451            .field("allocation-pools", &self.allocation_pools())
1452            .field("allocation-metas", &self.allocation_metas())
1453            .finish()
1454    }
1455}
1456
1457impl std::fmt::Debug for Allocation<Query> {
1458    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1459        Allocation::<QueryRef>::fmt(self, f)
1460    }
1461}
1462
1463declare_concrete_query!(Scheduling, T);
1464impl Scheduling<Query> {
1465    #[doc(alias = "gst_query_new_scheduling")]
1466    pub fn new() -> Self {
1467        assert_initialized_main_thread!();
1468        unsafe { Self(from_glib_full(ffi::gst_query_new_scheduling())) }
1469    }
1470}
1471
1472impl Default for Scheduling<Query> {
1473    fn default() -> Self {
1474        Self::new()
1475    }
1476}
1477
1478impl Scheduling {
1479    #[doc(alias = "gst_query_has_scheduling_mode")]
1480    pub fn has_scheduling_mode(&self, mode: crate::PadMode) -> bool {
1481        unsafe {
1482            from_glib(ffi::gst_query_has_scheduling_mode(
1483                self.as_mut_ptr(),
1484                mode.into_glib(),
1485            ))
1486        }
1487    }
1488
1489    #[doc(alias = "gst_query_has_scheduling_mode_with_flags")]
1490    pub fn has_scheduling_mode_with_flags(
1491        &self,
1492        mode: crate::PadMode,
1493        flags: crate::SchedulingFlags,
1494    ) -> bool {
1495        skip_assert_initialized!();
1496        unsafe {
1497            from_glib(ffi::gst_query_has_scheduling_mode_with_flags(
1498                self.as_mut_ptr(),
1499                mode.into_glib(),
1500                flags.into_glib(),
1501            ))
1502        }
1503    }
1504
1505    #[doc(alias = "get_scheduling_modes")]
1506    #[doc(alias = "gst_query_get_n_scheduling_modes")]
1507    pub fn scheduling_modes(&self) -> Vec<crate::PadMode> {
1508        unsafe {
1509            let n = ffi::gst_query_get_n_scheduling_modes(self.as_mut_ptr());
1510            let mut res = Vec::with_capacity(n as usize);
1511            for i in 0..n {
1512                res.push(from_glib(ffi::gst_query_parse_nth_scheduling_mode(
1513                    self.as_mut_ptr(),
1514                    i,
1515                )));
1516            }
1517
1518            res
1519        }
1520    }
1521
1522    #[doc(alias = "get_result")]
1523    #[doc(alias = "gst_query_parse_scheduling")]
1524    pub fn result(&self) -> (crate::SchedulingFlags, i32, i32, i32) {
1525        unsafe {
1526            let mut flags = mem::MaybeUninit::uninit();
1527            let mut minsize = mem::MaybeUninit::uninit();
1528            let mut maxsize = mem::MaybeUninit::uninit();
1529            let mut align = mem::MaybeUninit::uninit();
1530
1531            ffi::gst_query_parse_scheduling(
1532                self.as_mut_ptr(),
1533                flags.as_mut_ptr(),
1534                minsize.as_mut_ptr(),
1535                maxsize.as_mut_ptr(),
1536                align.as_mut_ptr(),
1537            );
1538
1539            (
1540                from_glib(flags.assume_init()),
1541                minsize.assume_init(),
1542                maxsize.assume_init(),
1543                align.assume_init(),
1544            )
1545        }
1546    }
1547
1548    #[doc(alias = "gst_query_add_scheduling_mode")]
1549    pub fn add_scheduling_modes(&mut self, modes: &[crate::PadMode]) {
1550        unsafe {
1551            for mode in modes {
1552                ffi::gst_query_add_scheduling_mode(self.as_mut_ptr(), mode.into_glib());
1553            }
1554        }
1555    }
1556
1557    #[doc(alias = "gst_query_set_scheduling")]
1558    pub fn set(&mut self, flags: crate::SchedulingFlags, minsize: i32, maxsize: i32, align: i32) {
1559        unsafe {
1560            ffi::gst_query_set_scheduling(
1561                self.as_mut_ptr(),
1562                flags.into_glib(),
1563                minsize,
1564                maxsize,
1565                align,
1566            );
1567        }
1568    }
1569}
1570
1571impl std::fmt::Debug for Scheduling {
1572    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1573        f.debug_struct("Scheduling")
1574            .field("structure", &self.query().structure())
1575            .field("result", &self.result())
1576            .field("scheduling-modes", &self.scheduling_modes())
1577            .finish()
1578    }
1579}
1580
1581impl std::fmt::Debug for Scheduling<Query> {
1582    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1583        Scheduling::<QueryRef>::fmt(self, f)
1584    }
1585}
1586
1587declare_concrete_query!(AcceptCaps, T);
1588impl AcceptCaps<Query> {
1589    #[doc(alias = "gst_query_new_accept_caps")]
1590    pub fn new(caps: &crate::Caps) -> Self {
1591        skip_assert_initialized!();
1592        unsafe {
1593            Self(from_glib_full(ffi::gst_query_new_accept_caps(
1594                caps.as_mut_ptr(),
1595            )))
1596        }
1597    }
1598}
1599
1600impl AcceptCaps {
1601    #[doc(alias = "get_caps")]
1602    #[doc(alias = "gst_query_parse_accept_caps")]
1603    pub fn caps(&self) -> &crate::CapsRef {
1604        unsafe {
1605            let mut caps = ptr::null_mut();
1606            ffi::gst_query_parse_accept_caps(self.as_mut_ptr(), &mut caps);
1607            crate::CapsRef::from_ptr(caps)
1608        }
1609    }
1610
1611    #[doc(alias = "get_caps_owned")]
1612    #[doc(alias = "gst_query_parse_accept_caps")]
1613    pub fn caps_owned(&self) -> crate::Caps {
1614        unsafe { from_glib_none(self.caps().as_ptr()) }
1615    }
1616
1617    #[doc(alias = "get_result")]
1618    #[doc(alias = "gst_query_parse_accept_caps_result")]
1619    pub fn result(&self) -> bool {
1620        unsafe {
1621            let mut accepted = mem::MaybeUninit::uninit();
1622            ffi::gst_query_parse_accept_caps_result(self.as_mut_ptr(), accepted.as_mut_ptr());
1623            from_glib(accepted.assume_init())
1624        }
1625    }
1626
1627    #[doc(alias = "gst_query_set_accept_caps_result")]
1628    pub fn set_result(&mut self, accepted: bool) {
1629        unsafe {
1630            ffi::gst_query_set_accept_caps_result(self.as_mut_ptr(), accepted.into_glib());
1631        }
1632    }
1633}
1634
1635impl std::fmt::Debug for AcceptCaps {
1636    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1637        f.debug_struct("AcceptCaps")
1638            .field("structure", &self.query().structure())
1639            .field("result", &self.result())
1640            .field("caps", &self.caps())
1641            .finish()
1642    }
1643}
1644
1645impl std::fmt::Debug for AcceptCaps<Query> {
1646    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1647        AcceptCaps::<QueryRef>::fmt(self, f)
1648    }
1649}
1650
1651declare_concrete_query!(Caps, T);
1652impl Caps<Query> {
1653    #[doc(alias = "gst_query_new_caps")]
1654    pub fn new(filter: Option<&crate::Caps>) -> Self {
1655        skip_assert_initialized!();
1656        unsafe {
1657            Self(from_glib_full(ffi::gst_query_new_caps(
1658                filter.to_glib_none().0,
1659            )))
1660        }
1661    }
1662}
1663
1664impl Caps {
1665    #[doc(alias = "get_filter")]
1666    #[doc(alias = "gst_query_parse_caps")]
1667    pub fn filter(&self) -> Option<&crate::CapsRef> {
1668        unsafe {
1669            let mut caps = ptr::null_mut();
1670            ffi::gst_query_parse_caps(self.as_mut_ptr(), &mut caps);
1671            if caps.is_null() {
1672                None
1673            } else {
1674                Some(crate::CapsRef::from_ptr(caps))
1675            }
1676        }
1677    }
1678
1679    #[doc(alias = "get_filter_owned")]
1680    #[doc(alias = "gst_query_parse_caps")]
1681    pub fn filter_owned(&self) -> Option<crate::Caps> {
1682        unsafe { self.filter().map(|caps| from_glib_none(caps.as_ptr())) }
1683    }
1684
1685    #[doc(alias = "get_result")]
1686    #[doc(alias = "gst_query_parse_caps_result")]
1687    pub fn result(&self) -> Option<&crate::CapsRef> {
1688        unsafe {
1689            let mut caps = ptr::null_mut();
1690            ffi::gst_query_parse_caps_result(self.as_mut_ptr(), &mut caps);
1691            if caps.is_null() {
1692                None
1693            } else {
1694                Some(crate::CapsRef::from_ptr(caps))
1695            }
1696        }
1697    }
1698
1699    #[doc(alias = "get_result_owned")]
1700    #[doc(alias = "gst_query_parse_caps_result")]
1701    pub fn result_owned(&self) -> Option<crate::Caps> {
1702        unsafe { self.result().map(|caps| from_glib_none(caps.as_ptr())) }
1703    }
1704
1705    #[doc(alias = "gst_query_set_caps_result")]
1706    pub fn set_result<'a>(&mut self, caps: impl Into<Option<&'a crate::Caps>>) {
1707        unsafe {
1708            ffi::gst_query_set_caps_result(
1709                self.as_mut_ptr(),
1710                caps.into()
1711                    .map(|caps| caps.as_mut_ptr())
1712                    .unwrap_or(ptr::null_mut()),
1713            );
1714        }
1715    }
1716}
1717
1718impl std::fmt::Debug for Caps {
1719    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1720        f.debug_struct("Caps")
1721            .field("structure", &self.query().structure())
1722            .field("result", &self.result())
1723            .field("filter", &self.filter())
1724            .finish()
1725    }
1726}
1727
1728impl std::fmt::Debug for Caps<Query> {
1729    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1730        Caps::<QueryRef>::fmt(self, f)
1731    }
1732}
1733
1734declare_concrete_query!(Drain, T);
1735impl Drain<Query> {
1736    #[doc(alias = "gst_query_new_drain")]
1737    pub fn new() -> Self {
1738        assert_initialized_main_thread!();
1739        unsafe { Self(from_glib_full(ffi::gst_query_new_drain())) }
1740    }
1741}
1742
1743impl Default for Drain<Query> {
1744    fn default() -> Self {
1745        Self::new()
1746    }
1747}
1748
1749impl std::fmt::Debug for Drain {
1750    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1751        f.debug_struct("Drain")
1752            .field("structure", &self.query().structure())
1753            .finish()
1754    }
1755}
1756
1757impl std::fmt::Debug for Drain<Query> {
1758    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1759        Drain::<QueryRef>::fmt(self, f)
1760    }
1761}
1762
1763declare_concrete_query!(Context, T);
1764impl Context<Query> {
1765    #[doc(alias = "gst_query_new_context")]
1766    pub fn new(context_type: &str) -> Self {
1767        assert_initialized_main_thread!();
1768        unsafe {
1769            Self(from_glib_full(ffi::gst_query_new_context(
1770                context_type.to_glib_none().0,
1771            )))
1772        }
1773    }
1774}
1775
1776impl Context {
1777    #[doc(alias = "get_context")]
1778    #[doc(alias = "gst_query_parse_context")]
1779    pub fn context(&self) -> Option<&crate::ContextRef> {
1780        unsafe {
1781            let mut context = ptr::null_mut();
1782            ffi::gst_query_parse_context(self.as_mut_ptr(), &mut context);
1783            if context.is_null() {
1784                None
1785            } else {
1786                Some(crate::ContextRef::from_ptr(context))
1787            }
1788        }
1789    }
1790
1791    #[doc(alias = "get_context_owned")]
1792    #[doc(alias = "gst_query_parse_context")]
1793    pub fn context_owned(&self) -> Option<crate::Context> {
1794        unsafe {
1795            self.context()
1796                .map(|context| from_glib_none(context.as_ptr()))
1797        }
1798    }
1799
1800    #[doc(alias = "get_context_type")]
1801    #[doc(alias = "gst_query_parse_context_type")]
1802    pub fn context_type(&self) -> &str {
1803        unsafe {
1804            let mut context_type = ptr::null();
1805            ffi::gst_query_parse_context_type(self.as_mut_ptr(), &mut context_type);
1806            CStr::from_ptr(context_type).to_str().unwrap()
1807        }
1808    }
1809
1810    #[doc(alias = "gst_query_set_context")]
1811    pub fn set_context<'a>(&mut self, context: impl Into<Option<&'a crate::Context>>) {
1812        unsafe {
1813            ffi::gst_query_set_context(
1814                self.as_mut_ptr(),
1815                context
1816                    .into()
1817                    .map(|context| context.as_mut_ptr())
1818                    .unwrap_or(ptr::null_mut()),
1819            );
1820        }
1821    }
1822}
1823
1824impl std::fmt::Debug for Context {
1825    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1826        f.debug_struct("Context")
1827            .field("structure", &self.query().structure())
1828            .field("context", &self.context())
1829            .field("context-type", &self.context_type())
1830            .finish()
1831    }
1832}
1833
1834impl std::fmt::Debug for Context<Query> {
1835    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1836        Context::<QueryRef>::fmt(self, f)
1837    }
1838}
1839
1840#[cfg(feature = "v1_16")]
1841#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
1842declare_concrete_query!(Bitrate, T);
1843
1844#[cfg(feature = "v1_16")]
1845#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
1846impl Bitrate<Query> {
1847    #[doc(alias = "gst_query_new_bitrate")]
1848    pub fn new() -> Self {
1849        assert_initialized_main_thread!();
1850        unsafe { Self(from_glib_full(ffi::gst_query_new_bitrate())) }
1851    }
1852}
1853
1854#[cfg(feature = "v1_16")]
1855#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
1856impl Default for Bitrate<Query> {
1857    fn default() -> Self {
1858        Self::new()
1859    }
1860}
1861
1862#[cfg(feature = "v1_16")]
1863#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
1864impl Bitrate {
1865    #[doc(alias = "get_bitrate")]
1866    #[doc(alias = "gst_query_parse_bitrate")]
1867    pub fn bitrate(&self) -> u32 {
1868        unsafe {
1869            let mut bitrate = mem::MaybeUninit::uninit();
1870            ffi::gst_query_parse_bitrate(self.as_mut_ptr(), bitrate.as_mut_ptr());
1871            bitrate.assume_init()
1872        }
1873    }
1874
1875    #[doc(alias = "gst_query_set_bitrate")]
1876    pub fn set_bitrate(&mut self, bitrate: u32) {
1877        unsafe {
1878            ffi::gst_query_set_bitrate(self.as_mut_ptr(), bitrate);
1879        }
1880    }
1881}
1882
1883#[cfg(feature = "v1_16")]
1884impl std::fmt::Debug for Bitrate {
1885    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1886        f.debug_struct("Bitrate")
1887            .field("structure", &self.query().structure())
1888            .field("bitrate", &self.bitrate())
1889            .finish()
1890    }
1891}
1892
1893#[cfg(feature = "v1_16")]
1894impl std::fmt::Debug for Bitrate<Query> {
1895    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1896        Bitrate::<QueryRef>::fmt(self, f)
1897    }
1898}
1899
1900#[cfg(feature = "v1_22")]
1901#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
1902declare_concrete_query!(Selectable, T);
1903
1904#[cfg(feature = "v1_22")]
1905#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
1906impl Selectable<Query> {
1907    #[doc(alias = "gst_query_new_selectable")]
1908    pub fn new() -> Self {
1909        assert_initialized_main_thread!();
1910        unsafe { Self(from_glib_full(ffi::gst_query_new_selectable())) }
1911    }
1912}
1913
1914#[cfg(feature = "v1_22")]
1915#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
1916impl Default for Selectable<Query> {
1917    fn default() -> Self {
1918        Self::new()
1919    }
1920}
1921
1922#[cfg(feature = "v1_22")]
1923#[cfg_attr(docsrs, doc(cfg(feature = "v1_22")))]
1924impl Selectable {
1925    #[doc(alias = "get_selectable")]
1926    #[doc(alias = "gst_query_parse_selectable")]
1927    pub fn selectable(&self) -> bool {
1928        unsafe {
1929            let mut selectable = mem::MaybeUninit::uninit();
1930            ffi::gst_query_parse_selectable(self.as_mut_ptr(), selectable.as_mut_ptr());
1931            from_glib(selectable.assume_init())
1932        }
1933    }
1934
1935    #[doc(alias = "gst_query_set_selectable")]
1936    pub fn set_selectable(&mut self, selectable: bool) {
1937        unsafe {
1938            ffi::gst_query_set_selectable(self.as_mut_ptr(), selectable.into_glib());
1939        }
1940    }
1941}
1942
1943#[cfg(feature = "v1_22")]
1944impl std::fmt::Debug for Selectable {
1945    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1946        f.debug_struct("Selectable")
1947            .field("structure", &self.query().structure())
1948            .field("selectable", &self.selectable())
1949            .finish()
1950    }
1951}
1952
1953#[cfg(feature = "v1_22")]
1954impl std::fmt::Debug for Selectable<Query> {
1955    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1956        Selectable::<QueryRef>::fmt(self, f)
1957    }
1958}
1959
1960declare_concrete_query!(Other, T);
1961
1962impl std::fmt::Debug for Other {
1963    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1964        f.debug_struct("Other")
1965            .field("structure", &self.query().structure())
1966            .finish()
1967    }
1968}
1969
1970impl std::fmt::Debug for Other<Query> {
1971    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1972        Other::<QueryRef>::fmt(self, f)
1973    }
1974}
1975
1976#[cfg(test)]
1977mod tests {
1978    use super::*;
1979    use crate::ClockTime;
1980
1981    #[test]
1982    fn test_writability() {
1983        crate::init().unwrap();
1984
1985        fn check_mut(query: &mut QueryRef) {
1986            skip_assert_initialized!();
1987            match query.view_mut() {
1988                QueryViewMut::Position(p) => {
1989                    let pos = p.result();
1990                    assert_eq!(pos.try_into(), Ok(ClockTime::NONE));
1991                    p.set(Some(3 * ClockTime::SECOND));
1992                    let pos = p.result();
1993                    assert_eq!(pos.try_into(), Ok(Some(3 * ClockTime::SECOND)));
1994                }
1995                _ => panic!("Wrong concrete Query in Query"),
1996            }
1997        }
1998
1999        fn check_ref(query: &QueryRef) {
2000            skip_assert_initialized!();
2001            match query.view() {
2002                QueryView::Position(p) => {
2003                    let pos = p.result();
2004                    assert_eq!(pos.try_into(), Ok(Some(3 * ClockTime::SECOND)));
2005                    assert!(!p.as_mut_ptr().is_null());
2006                }
2007                _ => panic!("Wrong concrete Query in Query"),
2008            }
2009        }
2010
2011        let mut p = Position::new(crate::Format::Time);
2012        let pos = p.result();
2013        assert_eq!(pos.try_into(), Ok(ClockTime::NONE));
2014
2015        p.structure_mut().set("check_mut", true);
2016
2017        // deref
2018        assert!(!p.is_serialized());
2019
2020        {
2021            check_mut(&mut p);
2022
2023            let structure = p.structure();
2024            structure.unwrap().has_field("check_mut");
2025
2026            // Expected: cannot borrow `p` as mutable because it is also borrowed as immutable
2027            //check_mut(&mut p);
2028        }
2029
2030        check_ref(&p);
2031    }
2032
2033    #[test]
2034    fn test_into_query() {
2035        crate::init().unwrap();
2036        let d = Duration::new(crate::Format::Time);
2037
2038        let mut query: Query = d.into();
2039        assert!(query.is_writable());
2040
2041        let query = query.make_mut();
2042        if let QueryViewMut::Duration(d) = query.view_mut() {
2043            d.set(Some(2 * ClockTime::SECOND));
2044        }
2045
2046        if let QueryView::Duration(d) = query.view() {
2047            let duration = d.result();
2048            assert_eq!(duration.try_into(), Ok(Some(2 * ClockTime::SECOND)));
2049        }
2050    }
2051
2052    #[test]
2053    fn test_concrete_to_sys() {
2054        crate::init().unwrap();
2055
2056        let p = Position::new(crate::Format::Time);
2057        assert!(!p.as_mut_ptr().is_null());
2058    }
2059
2060    #[test]
2061    fn allocation_need_pool() {
2062        crate::init().unwrap();
2063
2064        let mut a = Allocation::new(Some(&crate::Caps::new_empty_simple("foo/bar")), true);
2065        let pool = crate::BufferPool::new();
2066        a.add_allocation_pool(Some(&pool), 1024, 1, 4);
2067    }
2068
2069    #[test]
2070    fn allocation_do_not_need_pool() {
2071        crate::init().unwrap();
2072
2073        let mut a = Allocation::new(Some(&crate::Caps::new_empty_simple("foo/bar")), false);
2074        a.add_allocation_pool(crate::BufferPool::NONE, 1024, 1, 4);
2075
2076        // cannot infer type of the type parameter `T` declared on the enum `Option`
2077        //a.add_allocation_pool(None, 1024, 1, 4);
2078
2079        // This would be possible if we moved the `crate::BufferPool`
2080        // as a generic argument instead of using current arg type:
2081        // - `pool: Option<&impl IsA<crate::BufferPool>>`
2082        //a.add_allocation_pool::<crate::BufferPool>(None, 1024, 1, 4);
2083    }
2084
2085    #[test]
2086    fn set_uri() {
2087        crate::init().unwrap();
2088
2089        let mut uri_q = Uri::new();
2090        uri_q.set_uri("https://test.org");
2091        uri_q.set_uri(&String::from("https://test.org"));
2092
2093        uri_q.set_uri(Some("https://test.org"));
2094        uri_q.set_uri(Some(&String::from("https://test.org")));
2095
2096        // FIXME: this is commented out for now due to an inconsistent
2097        //        assertion in `GStreamer` which results in critical logs.
2098        /*
2099        let none: Option<&str> = None;
2100        uri_q.set_uri(none);
2101
2102        let none: Option<String> = None;
2103        uri_q.set_uri(none.as_ref());
2104
2105        uri_q.set_uri::<str>(None);
2106        */
2107    }
2108}