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