gstreamer/
event.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{
4    borrow::Borrow, cmp, ffi::CStr, fmt, mem, num::NonZeroU32, ops::Deref, ops::DerefMut, ptr,
5};
6
7use glib::{translate::*, value::ToSendValue};
8
9use crate::{
10    ffi,
11    format::{
12        CompatibleFormattedValue, FormattedValue, FormattedValueIntrinsic, GenericFormattedValue,
13    },
14    structure::*,
15    ClockTime, EventType,
16};
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct Seqnum(pub(crate) NonZeroU32);
20
21impl Seqnum {
22    #[doc(alias = "gst_util_seqnum_next")]
23    #[inline]
24    pub fn next() -> Self {
25        unsafe {
26            let v = ffi::gst_util_seqnum_next();
27            if v == 0 {
28                Seqnum::next()
29            } else {
30                Seqnum(NonZeroU32::new_unchecked(v))
31            }
32        }
33    }
34}
35
36impl IntoGlib for Seqnum {
37    type GlibType = u32;
38
39    #[inline]
40    fn into_glib(self) -> u32 {
41        self.0.get()
42    }
43}
44
45impl cmp::PartialOrd for Seqnum {
46    #[inline]
47    fn partial_cmp(&self, other: &Seqnum) -> Option<cmp::Ordering> {
48        Some(self.cmp(other))
49    }
50}
51
52impl cmp::Ord for Seqnum {
53    #[inline]
54    fn cmp(&self, other: &Seqnum) -> cmp::Ordering {
55        unsafe {
56            let ret = ffi::gst_util_seqnum_compare(self.0.get(), other.0.get());
57            ret.cmp(&0)
58        }
59    }
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63pub struct GroupId(pub(crate) NonZeroU32);
64
65impl GroupId {
66    #[doc(alias = "gst_util_group_id_next")]
67    #[inline]
68    pub fn next() -> Self {
69        unsafe {
70            let v = ffi::gst_util_group_id_next();
71            if v == 0 {
72                GroupId::next()
73            } else {
74                GroupId(NonZeroU32::new_unchecked(v))
75            }
76        }
77    }
78}
79
80impl EventType {
81    #[doc(alias = "GST_EVENT_IS_UPSTREAM")]
82    #[inline]
83    pub fn is_upstream(self) -> bool {
84        (self.into_glib() as u32) & ffi::GST_EVENT_TYPE_UPSTREAM != 0
85    }
86
87    #[doc(alias = "GST_EVENT_IS_DOWNSTREAM")]
88    #[inline]
89    pub fn is_downstream(self) -> bool {
90        (self.into_glib() as u32) & ffi::GST_EVENT_TYPE_DOWNSTREAM != 0
91    }
92
93    #[doc(alias = "GST_EVENT_IS_SERIALIZED")]
94    #[inline]
95    pub fn is_serialized(self) -> bool {
96        (self.into_glib() as u32) & ffi::GST_EVENT_TYPE_SERIALIZED != 0
97    }
98
99    #[doc(alias = "GST_EVENT_IS_STICKY")]
100    #[inline]
101    pub fn is_sticky(self) -> bool {
102        (self.into_glib() as u32) & ffi::GST_EVENT_TYPE_STICKY != 0
103    }
104
105    #[doc(alias = "GST_EVENT_IS_STICKY_MULTI")]
106    #[inline]
107    pub fn is_sticky_multi(self) -> bool {
108        (self.into_glib() as u32) & ffi::GST_EVENT_TYPE_STICKY_MULTI != 0
109    }
110}
111
112impl PartialOrd for EventType {
113    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
114        if !self.is_serialized() || !other.is_serialized() {
115            return None;
116        }
117
118        // See gst_event_type_to_sticky_ordering() from 1.22
119        let fixup_event_ordering = |v| match v {
120            ffi::GST_EVENT_INSTANT_RATE_CHANGE => ffi::GST_EVENT_SEGMENT as u32 + 1,
121            _ => v as u32,
122        };
123
124        let v1 = fixup_event_ordering(self.into_glib());
125        let v2 = fixup_event_ordering(other.into_glib());
126
127        let stream_start = ffi::GST_EVENT_STREAM_START as u32;
128        let segment = ffi::GST_EVENT_SEGMENT as u32;
129        let eos = ffi::GST_EVENT_EOS as u32;
130
131        // Strictly ordered range between stream_start and segment,
132        // and EOS is bigger than everything else
133        if v1 >= stream_start && v1 <= segment || v2 >= stream_start && v2 <= segment {
134            Some(v1.cmp(&v2))
135        // If one is EOS, the other is definitely less or equal
136        } else if v1 == eos || v2 == eos {
137            if v1 == v2 {
138                Some(cmp::Ordering::Equal)
139            } else if v1 == eos {
140                Some(cmp::Ordering::Greater)
141            } else {
142                Some(cmp::Ordering::Less)
143            }
144        } else {
145            None
146        }
147    }
148}
149
150mini_object_wrapper!(Event, EventRef, ffi::GstEvent, || {
151    ffi::gst_event_get_type()
152});
153
154impl EventRef {
155    #[doc(alias = "get_seqnum")]
156    #[doc(alias = "gst_event_get_seqnum")]
157    pub fn seqnum(&self) -> Seqnum {
158        unsafe {
159            let seqnum = ffi::gst_event_get_seqnum(self.as_mut_ptr());
160            debug_assert_ne!(seqnum, 0);
161            Seqnum(NonZeroU32::new_unchecked(seqnum))
162        }
163    }
164
165    #[doc(alias = "gst_event_set_seqnum")]
166    pub fn set_seqnum(&mut self, seqnum: Seqnum) {
167        unsafe {
168            ffi::gst_event_set_seqnum(self.as_mut_ptr(), seqnum.0.get());
169        }
170    }
171
172    #[doc(alias = "get_running_time_offset")]
173    #[doc(alias = "gst_event_get_running_time_offset")]
174    pub fn running_time_offset(&self) -> i64 {
175        unsafe { ffi::gst_event_get_running_time_offset(self.as_mut_ptr()) }
176    }
177
178    #[doc(alias = "gst_event_set_running_time_offset")]
179    pub fn set_running_time_offset(&mut self, offset: i64) {
180        unsafe { ffi::gst_event_set_running_time_offset(self.as_mut_ptr(), offset) }
181    }
182
183    #[doc(alias = "get_structure")]
184    #[doc(alias = "gst_event_get_structure")]
185    #[inline]
186    pub fn structure(&self) -> Option<&StructureRef> {
187        unsafe {
188            let structure = ffi::gst_event_get_structure(self.as_mut_ptr());
189            if structure.is_null() {
190                None
191            } else {
192                Some(StructureRef::from_glib_borrow(structure))
193            }
194        }
195    }
196
197    #[doc(alias = "gst_event_writable_structure")]
198    #[inline]
199    pub fn structure_mut(&mut self) -> &mut StructureRef {
200        unsafe {
201            StructureRef::from_glib_borrow_mut(ffi::gst_event_writable_structure(self.as_mut_ptr()))
202        }
203    }
204
205    #[doc(alias = "GST_EVENT_IS_UPSTREAM")]
206    #[inline]
207    pub fn is_upstream(&self) -> bool {
208        self.type_().is_upstream()
209    }
210
211    #[doc(alias = "GST_EVENT_IS_DOWNSTREAM")]
212    #[inline]
213    pub fn is_downstream(&self) -> bool {
214        self.type_().is_downstream()
215    }
216
217    #[doc(alias = "GST_EVENT_IS_SERIALIZED")]
218    #[inline]
219    pub fn is_serialized(&self) -> bool {
220        self.type_().is_serialized()
221    }
222
223    #[doc(alias = "GST_EVENT_IS_STICKY")]
224    #[inline]
225    pub fn is_sticky(&self) -> bool {
226        self.type_().is_sticky()
227    }
228
229    #[doc(alias = "GST_EVENT_IS_STICKY_MULTI")]
230    #[inline]
231    pub fn is_sticky_multi(&self) -> bool {
232        self.type_().is_sticky_multi()
233    }
234
235    #[doc(alias = "get_type")]
236    #[doc(alias = "GST_EVENT_TYPE")]
237    #[inline]
238    pub fn type_(&self) -> EventType {
239        unsafe { from_glib((*self.as_ptr()).type_) }
240    }
241
242    #[doc(alias = "gst_event_has_name")]
243    #[inline]
244    pub fn has_name(&self, name: &str) -> bool {
245        self.structure().is_some_and(|s| s.has_name(name))
246    }
247
248    pub fn view(&self) -> EventView {
249        unsafe {
250            let type_ = (*self.as_ptr()).type_;
251
252            match type_ {
253                ffi::GST_EVENT_FLUSH_START => FlushStart::view(self),
254                ffi::GST_EVENT_FLUSH_STOP => FlushStop::view(self),
255                ffi::GST_EVENT_STREAM_START => StreamStart::view(self),
256                ffi::GST_EVENT_CAPS => Caps::view(self),
257                ffi::GST_EVENT_SEGMENT => Segment::view(self),
258                ffi::GST_EVENT_STREAM_COLLECTION => StreamCollection::view(self),
259                ffi::GST_EVENT_TAG => Tag::view(self),
260                ffi::GST_EVENT_BUFFERSIZE => Buffersize::view(self),
261                ffi::GST_EVENT_SINK_MESSAGE => SinkMessage::view(self),
262                ffi::GST_EVENT_STREAM_GROUP_DONE => StreamGroupDone::view(self),
263                ffi::GST_EVENT_EOS => Eos::view(self),
264                ffi::GST_EVENT_TOC => Toc::view(self),
265                ffi::GST_EVENT_PROTECTION => Protection::view(self),
266                ffi::GST_EVENT_SEGMENT_DONE => SegmentDone::view(self),
267                ffi::GST_EVENT_GAP => Gap::view(self),
268                #[cfg(feature = "v1_18")]
269                ffi::GST_EVENT_INSTANT_RATE_CHANGE => InstantRateChange::view(self),
270                ffi::GST_EVENT_QOS => Qos::view(self),
271                ffi::GST_EVENT_SEEK => Seek::view(self),
272                ffi::GST_EVENT_NAVIGATION => Navigation::view(self),
273                ffi::GST_EVENT_LATENCY => Latency::view(self),
274                ffi::GST_EVENT_STEP => Step::view(self),
275                ffi::GST_EVENT_RECONFIGURE => Reconfigure::view(self),
276                ffi::GST_EVENT_TOC_SELECT => TocSelect::view(self),
277                ffi::GST_EVENT_SELECT_STREAMS => SelectStreams::view(self),
278                #[cfg(feature = "v1_18")]
279                ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => InstantRateSyncTime::view(self),
280                ffi::GST_EVENT_CUSTOM_UPSTREAM => CustomUpstream::view(self),
281                ffi::GST_EVENT_CUSTOM_DOWNSTREAM => CustomDownstream::view(self),
282                ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => CustomDownstreamOob::view(self),
283                ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => CustomDownstreamSticky::view(self),
284                ffi::GST_EVENT_CUSTOM_BOTH => CustomBoth::view(self),
285                ffi::GST_EVENT_CUSTOM_BOTH_OOB => CustomBothOob::view(self),
286                _ => Other::view(self),
287            }
288        }
289    }
290
291    pub fn view_mut(&mut self) -> EventViewMut {
292        unsafe {
293            let type_ = (*self.as_ptr()).type_;
294
295            match type_ {
296                ffi::GST_EVENT_FLUSH_START => FlushStart::view_mut(self),
297                ffi::GST_EVENT_FLUSH_STOP => FlushStop::view_mut(self),
298                ffi::GST_EVENT_STREAM_START => StreamStart::view_mut(self),
299                ffi::GST_EVENT_CAPS => Caps::view_mut(self),
300                ffi::GST_EVENT_SEGMENT => Segment::view_mut(self),
301                ffi::GST_EVENT_STREAM_COLLECTION => StreamCollection::view_mut(self),
302                ffi::GST_EVENT_TAG => Tag::view_mut(self),
303                ffi::GST_EVENT_BUFFERSIZE => Buffersize::view_mut(self),
304                ffi::GST_EVENT_SINK_MESSAGE => SinkMessage::view_mut(self),
305                ffi::GST_EVENT_STREAM_GROUP_DONE => StreamGroupDone::view_mut(self),
306                ffi::GST_EVENT_EOS => Eos::view_mut(self),
307                ffi::GST_EVENT_TOC => Toc::view_mut(self),
308                ffi::GST_EVENT_PROTECTION => Protection::view_mut(self),
309                ffi::GST_EVENT_SEGMENT_DONE => SegmentDone::view_mut(self),
310                ffi::GST_EVENT_GAP => Gap::view_mut(self),
311                #[cfg(feature = "v1_18")]
312                ffi::GST_EVENT_INSTANT_RATE_CHANGE => InstantRateChange::view_mut(self),
313                ffi::GST_EVENT_QOS => Qos::view_mut(self),
314                ffi::GST_EVENT_SEEK => Seek::view_mut(self),
315                ffi::GST_EVENT_NAVIGATION => Navigation::view_mut(self),
316                ffi::GST_EVENT_LATENCY => Latency::view_mut(self),
317                ffi::GST_EVENT_STEP => Step::view_mut(self),
318                ffi::GST_EVENT_RECONFIGURE => Reconfigure::view_mut(self),
319                ffi::GST_EVENT_TOC_SELECT => TocSelect::view_mut(self),
320                ffi::GST_EVENT_SELECT_STREAMS => SelectStreams::view_mut(self),
321                #[cfg(feature = "v1_18")]
322                ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => InstantRateSyncTime::view_mut(self),
323                ffi::GST_EVENT_CUSTOM_UPSTREAM => CustomUpstream::view_mut(self),
324                ffi::GST_EVENT_CUSTOM_DOWNSTREAM => CustomDownstream::view_mut(self),
325                ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => CustomDownstreamOob::view_mut(self),
326                ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => CustomDownstreamSticky::view_mut(self),
327                ffi::GST_EVENT_CUSTOM_BOTH => CustomBoth::view_mut(self),
328                ffi::GST_EVENT_CUSTOM_BOTH_OOB => CustomBothOob::view_mut(self),
329                _ => Other::view_mut(self),
330            }
331        }
332    }
333}
334
335impl fmt::Debug for Event {
336    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
337        EventRef::fmt(self, f)
338    }
339}
340
341impl fmt::Debug for EventRef {
342    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
343        f.debug_struct("Event")
344            .field("ptr", &self.as_ptr())
345            .field("type", &self.type_().name())
346            .field("seqnum", &self.seqnum())
347            .field("structure", &self.structure())
348            .finish()
349    }
350}
351
352pub trait StickyEventType: ToOwned {
353    const TYPE: EventType;
354
355    unsafe fn from_event(event: Event) -> Self::Owned;
356}
357
358#[derive(Debug)]
359#[non_exhaustive]
360pub enum EventView<'a> {
361    FlushStart(&'a FlushStart),
362    FlushStop(&'a FlushStop),
363    StreamStart(&'a StreamStart),
364    Caps(&'a Caps),
365    Segment(&'a Segment),
366    StreamCollection(&'a StreamCollection),
367    Tag(&'a Tag),
368    Buffersize(&'a Buffersize),
369    SinkMessage(&'a SinkMessage),
370    StreamGroupDone(&'a StreamGroupDone),
371    Eos(&'a Eos),
372    Toc(&'a Toc),
373    Protection(&'a Protection),
374    SegmentDone(&'a SegmentDone),
375    Gap(&'a Gap),
376    #[cfg(feature = "v1_18")]
377    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
378    InstantRateChange(&'a InstantRateChange),
379    Qos(&'a Qos),
380    Seek(&'a Seek),
381    Navigation(&'a Navigation),
382    Latency(&'a Latency),
383    Step(&'a Step),
384    Reconfigure(&'a Reconfigure),
385    TocSelect(&'a TocSelect),
386    SelectStreams(&'a SelectStreams),
387    #[cfg(feature = "v1_18")]
388    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
389    InstantRateSyncTime(&'a InstantRateSyncTime),
390    CustomUpstream(&'a CustomUpstream),
391    CustomDownstream(&'a CustomDownstream),
392    CustomDownstreamOob(&'a CustomDownstreamOob),
393    CustomDownstreamSticky(&'a CustomDownstreamSticky),
394    CustomBoth(&'a CustomBoth),
395    CustomBothOob(&'a CustomBothOob),
396    Other(&'a Other),
397}
398
399#[derive(Debug)]
400#[non_exhaustive]
401pub enum EventViewMut<'a> {
402    FlushStart(&'a mut FlushStart),
403    FlushStop(&'a mut FlushStop),
404    StreamStart(&'a mut StreamStart),
405    Caps(&'a mut Caps),
406    Segment(&'a mut Segment),
407    StreamCollection(&'a mut StreamCollection),
408    Tag(&'a mut Tag),
409    Buffersize(&'a mut Buffersize),
410    SinkMessage(&'a mut SinkMessage),
411    StreamGroupDone(&'a mut StreamGroupDone),
412    Eos(&'a mut Eos),
413    Toc(&'a mut Toc),
414    Protection(&'a mut Protection),
415    SegmentDone(&'a mut SegmentDone),
416    Gap(&'a mut Gap),
417    #[cfg(feature = "v1_18")]
418    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
419    InstantRateChange(&'a mut InstantRateChange),
420    Qos(&'a mut Qos),
421    Seek(&'a mut Seek),
422    Navigation(&'a mut Navigation),
423    Latency(&'a mut Latency),
424    Step(&'a mut Step),
425    Reconfigure(&'a mut Reconfigure),
426    TocSelect(&'a mut TocSelect),
427    SelectStreams(&'a mut SelectStreams),
428    #[cfg(feature = "v1_18")]
429    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
430    InstantRateSyncTime(&'a mut InstantRateSyncTime),
431    CustomUpstream(&'a mut CustomUpstream),
432    CustomDownstream(&'a mut CustomDownstream),
433    CustomDownstreamOob(&'a mut CustomDownstreamOob),
434    CustomDownstreamSticky(&'a mut CustomDownstreamSticky),
435    CustomBoth(&'a mut CustomBoth),
436    CustomBothOob(&'a mut CustomBothOob),
437    Other(&'a mut Other),
438}
439
440macro_rules! declare_concrete_event {
441    (@sticky $name:ident, $param:ident) => {
442        declare_concrete_event!($name, $param);
443
444        impl StickyEventType for $name {
445            const TYPE: EventType = EventType::$name;
446
447            #[inline]
448            unsafe fn from_event(event: Event) -> Self::Owned {
449                $name::<Event>(event)
450            }
451        }
452    };
453    ($name:ident, $param:ident) => {
454        #[repr(transparent)]
455        pub struct $name<$param = EventRef>($param);
456
457        impl $name {
458            #[inline]
459            pub fn event(&self) -> &EventRef {
460                unsafe { &*(self as *const Self as *const EventRef) }
461            }
462
463            #[inline]
464            pub fn event_mut(&mut self) -> &mut EventRef {
465                unsafe { &mut *(self as *mut Self as *mut EventRef) }
466            }
467
468            #[inline]
469            unsafe fn view(event: &EventRef) -> EventView<'_> {
470                let event = &*(event as *const EventRef as *const Self);
471                EventView::$name(event)
472            }
473
474            #[inline]
475            unsafe fn view_mut(event: &mut EventRef) -> EventViewMut<'_> {
476                let event = &mut *(event as *mut EventRef as *mut Self);
477                EventViewMut::$name(event)
478            }
479        }
480
481        impl Deref for $name {
482            type Target = EventRef;
483
484            #[inline]
485            fn deref(&self) -> &Self::Target {
486                self.event()
487            }
488        }
489
490        impl DerefMut for $name {
491            #[inline]
492            fn deref_mut(&mut self) -> &mut Self::Target {
493                self.event_mut()
494            }
495        }
496
497        impl ToOwned for $name {
498            type Owned = $name<Event>;
499
500            #[inline]
501            fn to_owned(&self) -> Self::Owned {
502                $name::<Event>(self.copy())
503            }
504        }
505
506        impl $name<Event> {
507            #[inline]
508            pub fn get_mut(&mut self) -> Option<&mut $name> {
509                self.0
510                    .get_mut()
511                    .map(|event| unsafe { &mut *(event as *mut EventRef as *mut $name) })
512            }
513        }
514
515        impl Deref for $name<Event> {
516            type Target = $name;
517
518            #[inline]
519            fn deref(&self) -> &Self::Target {
520                unsafe { &*(self.0.as_ptr() as *const Self::Target) }
521            }
522        }
523
524        impl DerefMut for $name<Event> {
525            #[inline]
526            fn deref_mut(&mut self) -> &mut Self::Target {
527                debug_assert!(self.0.is_writable());
528                unsafe { &mut *(self.0.as_mut_ptr() as *mut Self::Target) }
529            }
530        }
531
532        impl Borrow<$name> for $name<Event> {
533            #[inline]
534            fn borrow(&self) -> &$name {
535                &*self
536            }
537        }
538
539        impl From<$name<Event>> for Event {
540            #[inline]
541            fn from(concrete: $name<Event>) -> Self {
542                skip_assert_initialized!();
543                concrete.0
544            }
545        }
546    };
547}
548
549declare_concrete_event!(FlushStart, T);
550impl FlushStart<Event> {
551    #[doc(alias = "gst_event_new_flush_start")]
552    #[allow(clippy::new_ret_no_self)]
553    pub fn new() -> Event {
554        skip_assert_initialized!();
555        Self::builder().build()
556    }
557
558    pub fn builder<'a>() -> FlushStartBuilder<'a> {
559        assert_initialized_main_thread!();
560        FlushStartBuilder::new()
561    }
562}
563
564impl std::fmt::Debug for FlushStart {
565    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
566        f.debug_struct("FlushStart")
567            .field("seqnum", &self.event().seqnum())
568            .field("running-time-offset", &self.event().running_time_offset())
569            .field("structure", &self.event().structure())
570            .finish()
571    }
572}
573
574impl std::fmt::Debug for FlushStart<Event> {
575    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
576        FlushStart::<EventRef>::fmt(self, f)
577    }
578}
579
580declare_concrete_event!(FlushStop, T);
581impl FlushStop<Event> {
582    #[doc(alias = "gst_event_new_flush_stop")]
583    #[allow(clippy::new_ret_no_self)]
584    pub fn new(reset_time: bool) -> Event {
585        skip_assert_initialized!();
586        Self::builder(reset_time).build()
587    }
588
589    pub fn builder<'a>(reset_time: bool) -> FlushStopBuilder<'a> {
590        assert_initialized_main_thread!();
591        FlushStopBuilder::new(reset_time)
592    }
593}
594
595impl FlushStop {
596    #[doc(alias = "get_reset_time")]
597    #[doc(alias = "gst_event_parse_flush_stop")]
598    pub fn resets_time(&self) -> bool {
599        unsafe {
600            let mut reset_time = mem::MaybeUninit::uninit();
601
602            ffi::gst_event_parse_flush_stop(self.as_mut_ptr(), reset_time.as_mut_ptr());
603
604            from_glib(reset_time.assume_init())
605        }
606    }
607}
608
609impl std::fmt::Debug for FlushStop {
610    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
611        f.debug_struct("FlushStop")
612            .field("seqnum", &self.event().seqnum())
613            .field("running-time-offset", &self.event().running_time_offset())
614            .field("structure", &self.event().structure())
615            .field("resets-time", &self.resets_time())
616            .finish()
617    }
618}
619
620impl std::fmt::Debug for FlushStop<Event> {
621    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
622        FlushStop::<EventRef>::fmt(self, f)
623    }
624}
625
626declare_concrete_event!(@sticky StreamStart, T);
627impl StreamStart<Event> {
628    #[doc(alias = "gst_event_new_stream_start")]
629    #[allow(clippy::new_ret_no_self)]
630    pub fn new(stream_id: &str) -> Event {
631        skip_assert_initialized!();
632        Self::builder(stream_id).build()
633    }
634
635    pub fn builder(stream_id: &str) -> StreamStartBuilder {
636        assert_initialized_main_thread!();
637        StreamStartBuilder::new(stream_id)
638    }
639}
640
641impl StreamStart {
642    #[doc(alias = "get_stream_id")]
643    #[doc(alias = "gst_event_parse_stream_start")]
644    pub fn stream_id(&self) -> &str {
645        unsafe {
646            let mut stream_id = ptr::null();
647
648            ffi::gst_event_parse_stream_start(self.as_mut_ptr(), &mut stream_id);
649            CStr::from_ptr(stream_id).to_str().unwrap()
650        }
651    }
652
653    #[doc(alias = "get_stream_flags")]
654    #[doc(alias = "gst_event_parse_stream_flags")]
655    pub fn stream_flags(&self) -> crate::StreamFlags {
656        unsafe {
657            let mut stream_flags = mem::MaybeUninit::uninit();
658
659            ffi::gst_event_parse_stream_flags(self.as_mut_ptr(), stream_flags.as_mut_ptr());
660
661            from_glib(stream_flags.assume_init())
662        }
663    }
664
665    #[doc(alias = "get_group_id")]
666    #[doc(alias = "gst_event_parse_group_id")]
667    pub fn group_id(&self) -> Option<GroupId> {
668        unsafe {
669            let mut group_id = mem::MaybeUninit::uninit();
670
671            ffi::gst_event_parse_group_id(self.as_mut_ptr(), group_id.as_mut_ptr());
672
673            let group_id = group_id.assume_init();
674            if group_id == 0 {
675                None
676            } else {
677                Some(GroupId(NonZeroU32::new_unchecked(group_id)))
678            }
679        }
680    }
681
682    #[doc(alias = "gst_event_set_group_id")]
683    pub fn set_group_id(&mut self, group_id: GroupId) {
684        unsafe {
685            ffi::gst_event_set_group_id(self.as_mut_ptr(), group_id.0.get());
686        }
687    }
688
689    #[doc(alias = "get_stream")]
690    #[doc(alias = "gst_event_parse_stream")]
691    pub fn stream(&self) -> Option<crate::Stream> {
692        unsafe {
693            let mut stream = ptr::null_mut();
694            ffi::gst_event_parse_stream(self.as_mut_ptr(), &mut stream);
695            from_glib_full(stream)
696        }
697    }
698}
699
700impl std::fmt::Debug for StreamStart {
701    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
702        f.debug_struct("StreamStart")
703            .field("seqnum", &self.event().seqnum())
704            .field("running-time-offset", &self.event().running_time_offset())
705            .field("structure", &self.event().structure())
706            .field("stream-id", &self.stream_id())
707            .field("stream-flags", &self.stream_flags())
708            .field("group-id", &self.group_id())
709            .field("stream", &self.stream())
710            .finish()
711    }
712}
713
714impl std::fmt::Debug for StreamStart<Event> {
715    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
716        StreamStart::<EventRef>::fmt(self, f)
717    }
718}
719
720declare_concrete_event!(@sticky Caps, T);
721impl Caps<Event> {
722    #[doc(alias = "gst_event_new_caps")]
723    #[allow(clippy::new_ret_no_self)]
724    pub fn new(caps: &crate::Caps) -> Event {
725        skip_assert_initialized!();
726        Self::builder(caps).build()
727    }
728
729    pub fn builder(caps: &crate::Caps) -> CapsBuilder {
730        assert_initialized_main_thread!();
731        CapsBuilder::new(caps)
732    }
733}
734
735impl Caps {
736    #[doc(alias = "get_caps")]
737    #[doc(alias = "gst_event_parse_caps")]
738    pub fn caps(&self) -> &crate::CapsRef {
739        unsafe {
740            let mut caps = ptr::null_mut();
741
742            ffi::gst_event_parse_caps(self.as_mut_ptr(), &mut caps);
743            crate::CapsRef::from_ptr(caps)
744        }
745    }
746
747    #[doc(alias = "get_caps_owned")]
748    #[doc(alias = "gst_event_parse_caps")]
749    pub fn caps_owned(&self) -> crate::Caps {
750        unsafe { from_glib_none(self.caps().as_ptr()) }
751    }
752}
753
754impl std::fmt::Debug for Caps {
755    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
756        f.debug_struct("Caps")
757            .field("seqnum", &self.event().seqnum())
758            .field("running-time-offset", &self.event().running_time_offset())
759            .field("structure", &self.event().structure())
760            .field("caps", &self.caps())
761            .finish()
762    }
763}
764
765impl std::fmt::Debug for Caps<Event> {
766    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
767        Caps::<EventRef>::fmt(self, f)
768    }
769}
770
771declare_concrete_event!(@sticky Segment, T);
772impl Segment<Event> {
773    #[doc(alias = "gst_event_new_segment")]
774    #[allow(clippy::new_ret_no_self)]
775    pub fn new<F: FormattedValueIntrinsic>(segment: &crate::FormattedSegment<F>) -> Event {
776        skip_assert_initialized!();
777        Self::builder(segment).build()
778    }
779
780    pub fn builder<F: FormattedValueIntrinsic>(
781        segment: &crate::FormattedSegment<F>,
782    ) -> SegmentBuilder {
783        assert_initialized_main_thread!();
784        SegmentBuilder::new(segment.as_ref())
785    }
786}
787
788impl Segment {
789    #[doc(alias = "get_segment")]
790    #[doc(alias = "gst_event_parse_segment")]
791    pub fn segment(&self) -> &crate::Segment {
792        unsafe {
793            let mut segment = ptr::null();
794
795            ffi::gst_event_parse_segment(self.as_mut_ptr(), &mut segment);
796            &*(segment as *mut ffi::GstSegment as *mut crate::Segment)
797        }
798    }
799}
800
801impl std::fmt::Debug for Segment {
802    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
803        f.debug_struct("Segment")
804            .field("seqnum", &self.event().seqnum())
805            .field("running-time-offset", &self.event().running_time_offset())
806            .field("structure", &self.event().structure())
807            .field("segment", &self.segment())
808            .finish()
809    }
810}
811
812impl std::fmt::Debug for Segment<Event> {
813    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
814        Segment::<EventRef>::fmt(self, f)
815    }
816}
817
818declare_concrete_event!(@sticky StreamCollection, T);
819impl StreamCollection<Event> {
820    #[doc(alias = "gst_event_new_stream_collection")]
821    #[allow(clippy::new_ret_no_self)]
822    pub fn new(stream_collection: &crate::StreamCollection) -> Event {
823        skip_assert_initialized!();
824        Self::builder(stream_collection).build()
825    }
826
827    pub fn builder(stream_collection: &crate::StreamCollection) -> StreamCollectionBuilder {
828        assert_initialized_main_thread!();
829        StreamCollectionBuilder::new(stream_collection)
830    }
831}
832
833impl StreamCollection {
834    #[doc(alias = "get_stream_collection")]
835    #[doc(alias = "gst_event_parse_stream_collection")]
836    pub fn stream_collection(&self) -> crate::StreamCollection {
837        unsafe {
838            let mut stream_collection = ptr::null_mut();
839
840            ffi::gst_event_parse_stream_collection(self.as_mut_ptr(), &mut stream_collection);
841            from_glib_full(stream_collection)
842        }
843    }
844}
845
846impl std::fmt::Debug for StreamCollection {
847    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
848        f.debug_struct("StreamCollection")
849            .field("seqnum", &self.event().seqnum())
850            .field("running-time-offset", &self.event().running_time_offset())
851            .field("structure", &self.event().structure())
852            .field("stream-collection", &self.stream_collection())
853            .finish()
854    }
855}
856
857impl std::fmt::Debug for StreamCollection<Event> {
858    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
859        StreamCollection::<EventRef>::fmt(self, f)
860    }
861}
862
863declare_concrete_event!(@sticky Tag, T);
864impl Tag<Event> {
865    #[doc(alias = "gst_event_new_tag")]
866    #[allow(clippy::new_ret_no_self)]
867    pub fn new(tags: crate::TagList) -> Event {
868        skip_assert_initialized!();
869        Self::builder(tags).build()
870    }
871
872    pub fn builder<'a>(tags: crate::TagList) -> TagBuilder<'a> {
873        assert_initialized_main_thread!();
874        TagBuilder::new(tags)
875    }
876}
877
878impl Tag {
879    #[doc(alias = "get_tag")]
880    #[doc(alias = "gst_event_parse_tag")]
881    pub fn tag(&self) -> &crate::TagListRef {
882        unsafe {
883            let mut tags = ptr::null_mut();
884
885            ffi::gst_event_parse_tag(self.as_mut_ptr(), &mut tags);
886            crate::TagListRef::from_ptr(tags)
887        }
888    }
889
890    #[doc(alias = "get_tag_owned")]
891    #[doc(alias = "gst_event_parse_tag")]
892    pub fn tag_owned(&self) -> crate::TagList {
893        unsafe { from_glib_none(self.tag().as_ptr()) }
894    }
895}
896
897impl std::fmt::Debug for Tag {
898    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
899        f.debug_struct("Tag")
900            .field("seqnum", &self.event().seqnum())
901            .field("running-time-offset", &self.event().running_time_offset())
902            .field("structure", &self.event().structure())
903            .field("tag", &self.tag())
904            .finish()
905    }
906}
907
908impl std::fmt::Debug for Tag<Event> {
909    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
910        Tag::<EventRef>::fmt(self, f)
911    }
912}
913
914declare_concrete_event!(@sticky Buffersize, T);
915impl Buffersize<Event> {
916    #[doc(alias = "gst_event_new_buffer_size")]
917    #[allow(clippy::new_ret_no_self)]
918    pub fn new<V: FormattedValue>(
919        minsize: V,
920        maxsize: impl CompatibleFormattedValue<V>,
921        r#async: bool,
922    ) -> Event {
923        skip_assert_initialized!();
924        Self::builder(minsize, maxsize, r#async).build()
925    }
926
927    pub fn builder<'a, V: FormattedValue>(
928        minsize: V,
929        maxsize: impl CompatibleFormattedValue<V>,
930        r#async: bool,
931    ) -> BuffersizeBuilder<'a> {
932        assert_initialized_main_thread!();
933        let maxsize = maxsize.try_into_checked(minsize).unwrap();
934
935        BuffersizeBuilder::new(minsize.into(), maxsize.into(), r#async)
936    }
937}
938
939impl Buffersize {
940    #[doc(alias = "gst_event_parse_buffer_size")]
941    pub fn get(&self) -> (GenericFormattedValue, GenericFormattedValue, bool) {
942        unsafe {
943            let mut fmt = mem::MaybeUninit::uninit();
944            let mut minsize = mem::MaybeUninit::uninit();
945            let mut maxsize = mem::MaybeUninit::uninit();
946            let mut async_ = mem::MaybeUninit::uninit();
947
948            ffi::gst_event_parse_buffer_size(
949                self.as_mut_ptr(),
950                fmt.as_mut_ptr(),
951                minsize.as_mut_ptr(),
952                maxsize.as_mut_ptr(),
953                async_.as_mut_ptr(),
954            );
955            (
956                GenericFormattedValue::new(from_glib(fmt.assume_init()), minsize.assume_init()),
957                GenericFormattedValue::new(from_glib(fmt.assume_init()), maxsize.assume_init()),
958                from_glib(async_.assume_init()),
959            )
960        }
961    }
962}
963
964impl std::fmt::Debug for Buffersize {
965    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
966        let (minsize, maxsize, async_) = self.get();
967        f.debug_struct("Buffersize")
968            .field("seqnum", &self.event().seqnum())
969            .field("running-time-offset", &self.event().running_time_offset())
970            .field("structure", &self.event().structure())
971            .field("min-size", &minsize)
972            .field("max-size", &maxsize)
973            .field("async", &async_)
974            .finish()
975    }
976}
977
978impl std::fmt::Debug for Buffersize<Event> {
979    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
980        Buffersize::<EventRef>::fmt(self, f)
981    }
982}
983
984declare_concrete_event!(@sticky SinkMessage, T);
985impl SinkMessage<Event> {
986    #[doc(alias = "gst_event_new_sink_message")]
987    #[allow(clippy::new_ret_no_self)]
988    pub fn new(name: &str, msg: &crate::Message) -> Event {
989        skip_assert_initialized!();
990        Self::builder(name, msg).build()
991    }
992
993    pub fn builder<'a>(name: &'a str, msg: &'a crate::Message) -> SinkMessageBuilder<'a> {
994        assert_initialized_main_thread!();
995        SinkMessageBuilder::new(name, msg)
996    }
997}
998
999impl SinkMessage {
1000    #[doc(alias = "get_message")]
1001    #[doc(alias = "gst_event_parse_sink_message")]
1002    pub fn message(&self) -> crate::Message {
1003        unsafe {
1004            let mut msg = ptr::null_mut();
1005
1006            ffi::gst_event_parse_sink_message(self.as_mut_ptr(), &mut msg);
1007            from_glib_full(msg)
1008        }
1009    }
1010}
1011
1012impl std::fmt::Debug for SinkMessage {
1013    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1014        f.debug_struct("SinkMessage")
1015            .field("seqnum", &self.event().seqnum())
1016            .field("running-time-offset", &self.event().running_time_offset())
1017            .field("structure", &self.event().structure())
1018            .field("message", &self.message())
1019            .finish()
1020    }
1021}
1022
1023impl std::fmt::Debug for SinkMessage<Event> {
1024    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1025        SinkMessage::<EventRef>::fmt(self, f)
1026    }
1027}
1028
1029declare_concrete_event!(@sticky StreamGroupDone, T);
1030impl StreamGroupDone<Event> {
1031    #[doc(alias = "gst_event_new_stream_group_done")]
1032    #[allow(clippy::new_ret_no_self)]
1033    pub fn new(group_id: GroupId) -> Event {
1034        skip_assert_initialized!();
1035        Self::builder(group_id).build()
1036    }
1037
1038    pub fn builder<'a>(group_id: GroupId) -> StreamGroupDoneBuilder<'a> {
1039        assert_initialized_main_thread!();
1040        StreamGroupDoneBuilder::new(group_id)
1041    }
1042}
1043
1044impl StreamGroupDone {
1045    #[doc(alias = "get_group_id")]
1046    #[doc(alias = "gst_event_parse_stream_group_done")]
1047    pub fn group_id(&self) -> GroupId {
1048        unsafe {
1049            let mut group_id = mem::MaybeUninit::uninit();
1050
1051            ffi::gst_event_parse_stream_group_done(self.as_mut_ptr(), group_id.as_mut_ptr());
1052
1053            let group_id = group_id.assume_init();
1054            debug_assert_ne!(group_id, 0);
1055            GroupId(NonZeroU32::new_unchecked(group_id))
1056        }
1057    }
1058}
1059
1060impl std::fmt::Debug for StreamGroupDone {
1061    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1062        f.debug_struct("StreamGroupDone")
1063            .field("seqnum", &self.event().seqnum())
1064            .field("running-time-offset", &self.event().running_time_offset())
1065            .field("structure", &self.event().structure())
1066            .field("group-id", &self.group_id())
1067            .finish()
1068    }
1069}
1070
1071impl std::fmt::Debug for StreamGroupDone<Event> {
1072    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1073        StreamGroupDone::<EventRef>::fmt(self, f)
1074    }
1075}
1076
1077declare_concrete_event!(@sticky Eos, T);
1078impl Eos<Event> {
1079    #[doc(alias = "gst_event_new_eos")]
1080    #[allow(clippy::new_ret_no_self)]
1081    pub fn new() -> Event {
1082        skip_assert_initialized!();
1083        Self::builder().build()
1084    }
1085
1086    pub fn builder<'a>() -> EosBuilder<'a> {
1087        assert_initialized_main_thread!();
1088        EosBuilder::new()
1089    }
1090}
1091
1092impl std::fmt::Debug for Eos {
1093    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1094        f.debug_struct("Eos")
1095            .field("seqnum", &self.event().seqnum())
1096            .field("running-time-offset", &self.event().running_time_offset())
1097            .field("structure", &self.event().structure())
1098            .finish()
1099    }
1100}
1101
1102impl std::fmt::Debug for Eos<Event> {
1103    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1104        Eos::<EventRef>::fmt(self, f)
1105    }
1106}
1107
1108declare_concrete_event!(@sticky Toc, T);
1109impl Toc<Event> {
1110    // FIXME could use false for updated as default
1111    // Even better: use an enum for updated so that it is more explicit than true / false
1112    #[doc(alias = "gst_event_new_toc")]
1113    #[allow(clippy::new_ret_no_self)]
1114    pub fn new(toc: &crate::Toc, updated: bool) -> Event {
1115        skip_assert_initialized!();
1116        Self::builder(toc, updated).build()
1117    }
1118
1119    pub fn builder(toc: &crate::Toc, updated: bool) -> TocBuilder {
1120        assert_initialized_main_thread!();
1121        TocBuilder::new(toc, updated)
1122    }
1123}
1124
1125impl Toc {
1126    #[doc(alias = "get_toc")]
1127    #[doc(alias = "gst_event_parse_toc")]
1128    pub fn toc(&self) -> (&crate::TocRef, bool) {
1129        unsafe {
1130            let mut toc = ptr::null_mut();
1131            let mut updated = mem::MaybeUninit::uninit();
1132
1133            ffi::gst_event_parse_toc(self.as_mut_ptr(), &mut toc, updated.as_mut_ptr());
1134            (
1135                crate::TocRef::from_ptr(toc),
1136                from_glib(updated.assume_init()),
1137            )
1138        }
1139    }
1140
1141    #[doc(alias = "get_toc_owned")]
1142    #[doc(alias = "gst_event_parse_toc")]
1143    pub fn toc_owned(&self) -> (crate::Toc, bool) {
1144        unsafe {
1145            let (toc, updated) = self.toc();
1146            (from_glib_none(toc.as_ptr()), updated)
1147        }
1148    }
1149}
1150
1151impl std::fmt::Debug for Toc {
1152    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1153        f.debug_struct("Toc")
1154            .field("seqnum", &self.event().seqnum())
1155            .field("running-time-offset", &self.event().running_time_offset())
1156            .field("structure", &self.event().structure())
1157            .field("toc", &self.toc())
1158            .finish()
1159    }
1160}
1161
1162impl std::fmt::Debug for Toc<Event> {
1163    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1164        Toc::<EventRef>::fmt(self, f)
1165    }
1166}
1167
1168declare_concrete_event!(@sticky Protection, T);
1169impl Protection<Event> {
1170    #[doc(alias = "gst_event_new_protection")]
1171    #[allow(clippy::new_ret_no_self)]
1172    pub fn new(system_id: &str, data: &crate::Buffer) -> Event {
1173        skip_assert_initialized!();
1174        Self::builder(system_id, data).build()
1175    }
1176
1177    pub fn builder<'a>(system_id: &'a str, data: &'a crate::Buffer) -> ProtectionBuilder<'a> {
1178        assert_initialized_main_thread!();
1179        ProtectionBuilder::new(system_id, data)
1180    }
1181}
1182
1183impl Protection {
1184    #[doc(alias = "gst_event_parse_protection")]
1185    pub fn get(&self) -> (&str, &crate::BufferRef, Option<&str>) {
1186        unsafe {
1187            let mut system_id = ptr::null();
1188            let mut buffer = ptr::null_mut();
1189            let mut origin = ptr::null();
1190
1191            ffi::gst_event_parse_protection(
1192                self.as_mut_ptr(),
1193                &mut system_id,
1194                &mut buffer,
1195                &mut origin,
1196            );
1197
1198            (
1199                CStr::from_ptr(system_id).to_str().unwrap(),
1200                crate::BufferRef::from_ptr(buffer),
1201                if origin.is_null() {
1202                    None
1203                } else {
1204                    Some(CStr::from_ptr(origin).to_str().unwrap())
1205                },
1206            )
1207        }
1208    }
1209
1210    #[doc(alias = "gst_event_parse_protection")]
1211    pub fn get_owned(&self) -> (&str, crate::Buffer, Option<&str>) {
1212        unsafe {
1213            let (system_id, buffer, origin) = self.get();
1214            (system_id, from_glib_none(buffer.as_ptr()), origin)
1215        }
1216    }
1217}
1218
1219impl std::fmt::Debug for Protection {
1220    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1221        let (system_id, buffer, origin) = self.get();
1222        f.debug_struct("Protection")
1223            .field("seqnum", &self.event().seqnum())
1224            .field("running-time-offset", &self.event().running_time_offset())
1225            .field("structure", &self.event().structure())
1226            .field("system-id", &system_id)
1227            .field("buffer", &buffer)
1228            .field("origin", &origin)
1229            .finish()
1230    }
1231}
1232
1233impl std::fmt::Debug for Protection<Event> {
1234    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1235        Protection::<EventRef>::fmt(self, f)
1236    }
1237}
1238
1239declare_concrete_event!(SegmentDone, T);
1240impl SegmentDone<Event> {
1241    #[doc(alias = "gst_event_new_segment_done")]
1242    #[allow(clippy::new_ret_no_self)]
1243    pub fn new(position: impl FormattedValue) -> Event {
1244        skip_assert_initialized!();
1245        Self::builder(position).build()
1246    }
1247
1248    pub fn builder<'a>(position: impl FormattedValue) -> SegmentDoneBuilder<'a> {
1249        assert_initialized_main_thread!();
1250        SegmentDoneBuilder::new(position.into())
1251    }
1252}
1253
1254impl SegmentDone {
1255    #[doc(alias = "gst_event_parse_segment_done")]
1256    pub fn get(&self) -> GenericFormattedValue {
1257        unsafe {
1258            let mut fmt = mem::MaybeUninit::uninit();
1259            let mut position = mem::MaybeUninit::uninit();
1260
1261            ffi::gst_event_parse_segment_done(
1262                self.as_mut_ptr(),
1263                fmt.as_mut_ptr(),
1264                position.as_mut_ptr(),
1265            );
1266
1267            GenericFormattedValue::new(from_glib(fmt.assume_init()), position.assume_init())
1268        }
1269    }
1270}
1271
1272impl std::fmt::Debug for SegmentDone {
1273    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1274        f.debug_struct("SegmentDone")
1275            .field("seqnum", &self.event().seqnum())
1276            .field("running-time-offset", &self.event().running_time_offset())
1277            .field("structure", &self.event().structure())
1278            .field("segment", &self.get())
1279            .finish()
1280    }
1281}
1282
1283impl std::fmt::Debug for SegmentDone<Event> {
1284    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1285        SegmentDone::<EventRef>::fmt(self, f)
1286    }
1287}
1288
1289declare_concrete_event!(Gap, T);
1290impl Gap<Event> {
1291    #[doc(alias = "gst_event_new_gap")]
1292    #[allow(clippy::new_ret_no_self)]
1293    pub fn new(timestamp: ClockTime, duration: impl Into<Option<ClockTime>>) -> Event {
1294        skip_assert_initialized!();
1295        Self::builder(timestamp).duration(duration).build()
1296    }
1297
1298    pub fn builder<'a>(timestamp: ClockTime) -> GapBuilder<'a> {
1299        assert_initialized_main_thread!();
1300        GapBuilder::new(timestamp)
1301    }
1302}
1303
1304impl Gap {
1305    #[doc(alias = "gst_event_parse_gap")]
1306    pub fn get(&self) -> (ClockTime, Option<ClockTime>) {
1307        unsafe {
1308            let mut timestamp = mem::MaybeUninit::uninit();
1309            let mut duration = mem::MaybeUninit::uninit();
1310
1311            ffi::gst_event_parse_gap(
1312                self.as_mut_ptr(),
1313                timestamp.as_mut_ptr(),
1314                duration.as_mut_ptr(),
1315            );
1316
1317            (
1318                try_from_glib(timestamp.assume_init()).expect("undefined timestamp"),
1319                from_glib(duration.assume_init()),
1320            )
1321        }
1322    }
1323
1324    #[cfg(feature = "v1_20")]
1325    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
1326    #[doc(alias = "gst_event_parse_gap_flags")]
1327    pub fn gap_flags(&self) -> crate::GapFlags {
1328        unsafe {
1329            let mut flags = mem::MaybeUninit::uninit();
1330            ffi::gst_event_parse_gap_flags(self.as_mut_ptr(), flags.as_mut_ptr());
1331            from_glib(flags.assume_init())
1332        }
1333    }
1334}
1335
1336impl std::fmt::Debug for Gap {
1337    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1338        let (timestamp, duration) = self.get();
1339        let mut f = f.debug_struct("Gap");
1340        f.field("seqnum", &self.event().seqnum())
1341            .field("running-time-offset", &self.event().running_time_offset())
1342            .field("structure", &self.event().structure())
1343            .field("timestamp", &timestamp)
1344            .field("duration", &duration);
1345        #[cfg(feature = "v1_20")]
1346        f.field("flags", &self.gap_flags());
1347        f.finish()
1348    }
1349}
1350
1351impl std::fmt::Debug for Gap<Event> {
1352    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1353        Gap::<EventRef>::fmt(self, f)
1354    }
1355}
1356
1357#[cfg(feature = "v1_18")]
1358#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1359declare_concrete_event!(@sticky InstantRateChange, T);
1360#[cfg(feature = "v1_18")]
1361#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1362impl InstantRateChange<Event> {
1363    #[doc(alias = "gst_event_new_instant_rate_change")]
1364    #[allow(clippy::new_ret_no_self)]
1365    pub fn new(multiplier: f64, new_flags: crate::SegmentFlags) -> Event {
1366        skip_assert_initialized!();
1367        Self::builder(multiplier, new_flags).build()
1368    }
1369
1370    pub fn builder<'a>(
1371        multiplier: f64,
1372        new_flags: crate::SegmentFlags,
1373    ) -> InstantRateChangeBuilder<'a> {
1374        assert_initialized_main_thread!();
1375        InstantRateChangeBuilder::new(multiplier, new_flags)
1376    }
1377}
1378
1379#[cfg(feature = "v1_18")]
1380#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1381impl InstantRateChange {
1382    #[doc(alias = "gst_event_parse_instant_rate_change")]
1383    pub fn get(&self) -> (f64, crate::SegmentFlags) {
1384        unsafe {
1385            let mut multiplier = mem::MaybeUninit::uninit();
1386            let mut new_flags = mem::MaybeUninit::uninit();
1387
1388            ffi::gst_event_parse_instant_rate_change(
1389                self.as_mut_ptr(),
1390                multiplier.as_mut_ptr(),
1391                new_flags.as_mut_ptr(),
1392            );
1393
1394            (multiplier.assume_init(), from_glib(new_flags.assume_init()))
1395        }
1396    }
1397}
1398
1399#[cfg(feature = "v1_18")]
1400impl std::fmt::Debug for InstantRateChange {
1401    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1402        let (multiplier, new_flags) = self.get();
1403        f.debug_struct("InstantRateChange")
1404            .field("seqnum", &self.event().seqnum())
1405            .field("running-time-offset", &self.event().running_time_offset())
1406            .field("structure", &self.event().structure())
1407            .field("multiplier", &multiplier)
1408            .field("new-flags", &new_flags)
1409            .finish()
1410    }
1411}
1412
1413#[cfg(feature = "v1_18")]
1414impl std::fmt::Debug for InstantRateChange<Event> {
1415    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1416        InstantRateChange::<EventRef>::fmt(self, f)
1417    }
1418}
1419
1420declare_concrete_event!(Qos, T);
1421impl Qos<Event> {
1422    #[doc(alias = "gst_event_new_qos")]
1423    #[allow(clippy::new_ret_no_self)]
1424    pub fn new(
1425        type_: crate::QOSType,
1426        proportion: f64,
1427        diff: i64,
1428        timestamp: impl Into<Option<ClockTime>>,
1429    ) -> Event {
1430        skip_assert_initialized!();
1431        Self::builder(type_, proportion, diff)
1432            .timestamp(timestamp)
1433            .build()
1434    }
1435
1436    pub fn builder<'a>(type_: crate::QOSType, proportion: f64, diff: i64) -> QosBuilder<'a> {
1437        assert_initialized_main_thread!();
1438        QosBuilder::new(type_, proportion, diff)
1439    }
1440}
1441
1442impl Qos {
1443    #[doc(alias = "gst_event_parse_qos")]
1444    pub fn get(&self) -> (crate::QOSType, f64, i64, Option<ClockTime>) {
1445        unsafe {
1446            let mut type_ = mem::MaybeUninit::uninit();
1447            let mut proportion = mem::MaybeUninit::uninit();
1448            let mut diff = mem::MaybeUninit::uninit();
1449            let mut timestamp = mem::MaybeUninit::uninit();
1450
1451            ffi::gst_event_parse_qos(
1452                self.as_mut_ptr(),
1453                type_.as_mut_ptr(),
1454                proportion.as_mut_ptr(),
1455                diff.as_mut_ptr(),
1456                timestamp.as_mut_ptr(),
1457            );
1458
1459            (
1460                from_glib(type_.assume_init()),
1461                proportion.assume_init(),
1462                diff.assume_init(),
1463                from_glib(timestamp.assume_init()),
1464            )
1465        }
1466    }
1467}
1468
1469impl std::fmt::Debug for Qos {
1470    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1471        let (type_, proportion, diff, timestamp) = self.get();
1472        f.debug_struct("Qos")
1473            .field("seqnum", &self.event().seqnum())
1474            .field("running-time-offset", &self.event().running_time_offset())
1475            .field("structure", &self.event().structure())
1476            .field("type", &type_)
1477            .field("proportion", &proportion)
1478            .field("diff", &diff)
1479            .field("timestamp", &timestamp)
1480            .finish()
1481    }
1482}
1483
1484impl std::fmt::Debug for Qos<Event> {
1485    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1486        Qos::<EventRef>::fmt(self, f)
1487    }
1488}
1489
1490declare_concrete_event!(Seek, T);
1491impl Seek<Event> {
1492    #[doc(alias = "gst_event_new_seek")]
1493    #[allow(clippy::new_ret_no_self)]
1494    pub fn new<V: FormattedValue>(
1495        rate: f64,
1496        flags: crate::SeekFlags,
1497        start_type: crate::SeekType,
1498        start: V,
1499        stop_type: crate::SeekType,
1500        stop: impl CompatibleFormattedValue<V>,
1501    ) -> Event {
1502        skip_assert_initialized!();
1503        Self::builder(rate, flags, start_type, start, stop_type, stop).build()
1504    }
1505
1506    pub fn builder<'a, V: FormattedValue>(
1507        rate: f64,
1508        flags: crate::SeekFlags,
1509        start_type: crate::SeekType,
1510        start: V,
1511        stop_type: crate::SeekType,
1512        stop: impl CompatibleFormattedValue<V>,
1513    ) -> SeekBuilder<'a> {
1514        assert_initialized_main_thread!();
1515        let stop = stop.try_into_checked(start).unwrap();
1516
1517        SeekBuilder::new(
1518            rate,
1519            flags,
1520            start_type,
1521            start.into(),
1522            stop_type,
1523            stop.into(),
1524        )
1525    }
1526}
1527
1528impl Seek {
1529    #[doc(alias = "gst_event_parse_seek")]
1530    pub fn get(
1531        &self,
1532    ) -> (
1533        f64,
1534        crate::SeekFlags,
1535        crate::SeekType,
1536        GenericFormattedValue,
1537        crate::SeekType,
1538        GenericFormattedValue,
1539    ) {
1540        unsafe {
1541            let mut rate = mem::MaybeUninit::uninit();
1542            let mut fmt = mem::MaybeUninit::uninit();
1543            let mut flags = mem::MaybeUninit::uninit();
1544            let mut start_type = mem::MaybeUninit::uninit();
1545            let mut start = mem::MaybeUninit::uninit();
1546            let mut stop_type = mem::MaybeUninit::uninit();
1547            let mut stop = mem::MaybeUninit::uninit();
1548
1549            ffi::gst_event_parse_seek(
1550                self.as_mut_ptr(),
1551                rate.as_mut_ptr(),
1552                fmt.as_mut_ptr(),
1553                flags.as_mut_ptr(),
1554                start_type.as_mut_ptr(),
1555                start.as_mut_ptr(),
1556                stop_type.as_mut_ptr(),
1557                stop.as_mut_ptr(),
1558            );
1559
1560            (
1561                rate.assume_init(),
1562                from_glib(flags.assume_init()),
1563                from_glib(start_type.assume_init()),
1564                GenericFormattedValue::new(from_glib(fmt.assume_init()), start.assume_init()),
1565                from_glib(stop_type.assume_init()),
1566                GenericFormattedValue::new(from_glib(fmt.assume_init()), stop.assume_init()),
1567            )
1568        }
1569    }
1570
1571    #[cfg(feature = "v1_16")]
1572    #[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
1573    #[doc(alias = "get_trickmode_interval")]
1574    #[doc(alias = "gst_event_parse_seek_trickmode_interval")]
1575    pub fn trickmode_interval(&self) -> Option<ClockTime> {
1576        unsafe {
1577            let mut trickmode_interval = mem::MaybeUninit::uninit();
1578
1579            ffi::gst_event_parse_seek_trickmode_interval(
1580                self.as_mut_ptr(),
1581                trickmode_interval.as_mut_ptr(),
1582            );
1583
1584            from_glib(trickmode_interval.assume_init())
1585        }
1586    }
1587}
1588
1589impl std::fmt::Debug for Seek {
1590    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1591        let (rate, flags, start_type, start, stop_type, stop) = self.get();
1592        f.debug_struct("Seek")
1593            .field("seqnum", &self.event().seqnum())
1594            .field("running-time-offset", &self.event().running_time_offset())
1595            .field("structure", &self.event().structure())
1596            .field("rate", &rate)
1597            .field("flags", &flags)
1598            .field("start-type", &start_type)
1599            .field("start", &start)
1600            .field("stop-type", &stop_type)
1601            .field("stop", &stop)
1602            .finish()
1603    }
1604}
1605
1606impl std::fmt::Debug for Seek<Event> {
1607    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1608        Seek::<EventRef>::fmt(self, f)
1609    }
1610}
1611
1612declare_concrete_event!(Navigation, T);
1613impl Navigation<Event> {
1614    #[doc(alias = "gst_event_new_navigation")]
1615    #[allow(clippy::new_ret_no_self)]
1616    pub fn new(structure: crate::Structure) -> Event {
1617        skip_assert_initialized!();
1618        Self::builder(structure).build()
1619    }
1620
1621    pub fn builder<'a>(structure: crate::Structure) -> NavigationBuilder<'a> {
1622        assert_initialized_main_thread!();
1623        NavigationBuilder::new(structure)
1624    }
1625}
1626
1627impl std::fmt::Debug for Navigation {
1628    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1629        f.debug_struct("Navigation")
1630            .field("seqnum", &self.event().seqnum())
1631            .field("running-time-offset", &self.event().running_time_offset())
1632            .field("structure", &self.event().structure())
1633            .finish()
1634    }
1635}
1636
1637impl std::fmt::Debug for Navigation<Event> {
1638    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1639        Navigation::<EventRef>::fmt(self, f)
1640    }
1641}
1642
1643declare_concrete_event!(Latency, T);
1644impl Latency<Event> {
1645    #[doc(alias = "gst_event_new_latency")]
1646    #[allow(clippy::new_ret_no_self)]
1647    pub fn new(latency: ClockTime) -> Event {
1648        skip_assert_initialized!();
1649        Self::builder(latency).build()
1650    }
1651
1652    pub fn builder<'a>(latency: ClockTime) -> LatencyBuilder<'a> {
1653        assert_initialized_main_thread!();
1654        LatencyBuilder::new(latency)
1655    }
1656}
1657
1658impl Latency {
1659    #[doc(alias = "get_latency")]
1660    #[doc(alias = "gst_event_parse_latency")]
1661    pub fn latency(&self) -> ClockTime {
1662        unsafe {
1663            let mut latency = mem::MaybeUninit::uninit();
1664
1665            ffi::gst_event_parse_latency(self.as_mut_ptr(), latency.as_mut_ptr());
1666
1667            try_from_glib(latency.assume_init()).expect("undefined latency")
1668        }
1669    }
1670}
1671
1672impl std::fmt::Debug for Latency {
1673    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1674        f.debug_struct("Latency")
1675            .field("seqnum", &self.event().seqnum())
1676            .field("running-time-offset", &self.event().running_time_offset())
1677            .field("structure", &self.event().structure())
1678            .field("latency", &self.latency())
1679            .finish()
1680    }
1681}
1682
1683impl std::fmt::Debug for Latency<Event> {
1684    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1685        Latency::<EventRef>::fmt(self, f)
1686    }
1687}
1688
1689declare_concrete_event!(Step, T);
1690impl Step<Event> {
1691    #[doc(alias = "gst_event_new_step")]
1692    #[allow(clippy::new_ret_no_self)]
1693    pub fn new(amount: impl FormattedValue, rate: f64, flush: bool, intermediate: bool) -> Event {
1694        skip_assert_initialized!();
1695        Self::builder(amount, rate, flush, intermediate).build()
1696    }
1697
1698    pub fn builder<'a>(
1699        amount: impl FormattedValue,
1700        rate: f64,
1701        flush: bool,
1702        intermediate: bool,
1703    ) -> StepBuilder<'a> {
1704        assert_initialized_main_thread!();
1705        StepBuilder::new(amount.into(), rate, flush, intermediate)
1706    }
1707}
1708
1709impl Step {
1710    #[doc(alias = "gst_event_parse_step")]
1711    pub fn get(&self) -> (GenericFormattedValue, f64, bool, bool) {
1712        unsafe {
1713            let mut fmt = mem::MaybeUninit::uninit();
1714            let mut amount = mem::MaybeUninit::uninit();
1715            let mut rate = mem::MaybeUninit::uninit();
1716            let mut flush = mem::MaybeUninit::uninit();
1717            let mut intermediate = mem::MaybeUninit::uninit();
1718
1719            ffi::gst_event_parse_step(
1720                self.as_mut_ptr(),
1721                fmt.as_mut_ptr(),
1722                amount.as_mut_ptr(),
1723                rate.as_mut_ptr(),
1724                flush.as_mut_ptr(),
1725                intermediate.as_mut_ptr(),
1726            );
1727
1728            (
1729                GenericFormattedValue::new(
1730                    from_glib(fmt.assume_init()),
1731                    amount.assume_init() as i64,
1732                ),
1733                rate.assume_init(),
1734                from_glib(flush.assume_init()),
1735                from_glib(intermediate.assume_init()),
1736            )
1737        }
1738    }
1739}
1740
1741impl std::fmt::Debug for Step {
1742    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1743        let (amount, rate, flush, intermediate) = self.get();
1744        f.debug_struct("Step")
1745            .field("seqnum", &self.event().seqnum())
1746            .field("running-time-offset", &self.event().running_time_offset())
1747            .field("structure", &self.event().structure())
1748            .field("amount", &amount)
1749            .field("rate", &rate)
1750            .field("flush", &flush)
1751            .field("intermediate", &intermediate)
1752            .finish()
1753    }
1754}
1755
1756impl std::fmt::Debug for Step<Event> {
1757    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1758        Step::<EventRef>::fmt(self, f)
1759    }
1760}
1761
1762declare_concrete_event!(Reconfigure, T);
1763impl Reconfigure<Event> {
1764    #[doc(alias = "gst_event_new_reconfigure")]
1765    #[allow(clippy::new_ret_no_self)]
1766    pub fn new() -> Event {
1767        skip_assert_initialized!();
1768        Self::builder().build()
1769    }
1770
1771    pub fn builder<'a>() -> ReconfigureBuilder<'a> {
1772        assert_initialized_main_thread!();
1773        ReconfigureBuilder::new()
1774    }
1775}
1776
1777impl std::fmt::Debug for Reconfigure {
1778    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1779        f.debug_struct("Reconfigure")
1780            .field("seqnum", &self.event().seqnum())
1781            .field("running-time-offset", &self.event().running_time_offset())
1782            .field("structure", &self.event().structure())
1783            .finish()
1784    }
1785}
1786
1787impl std::fmt::Debug for Reconfigure<Event> {
1788    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1789        Reconfigure::<EventRef>::fmt(self, f)
1790    }
1791}
1792
1793declare_concrete_event!(TocSelect, T);
1794impl TocSelect<Event> {
1795    #[doc(alias = "gst_event_new_toc_select")]
1796    #[allow(clippy::new_ret_no_self)]
1797    pub fn new(uid: &str) -> Event {
1798        skip_assert_initialized!();
1799        Self::builder(uid).build()
1800    }
1801
1802    pub fn builder(uid: &str) -> TocSelectBuilder {
1803        assert_initialized_main_thread!();
1804        TocSelectBuilder::new(uid)
1805    }
1806}
1807
1808impl TocSelect {
1809    #[doc(alias = "get_uid")]
1810    pub fn uid(&self) -> &str {
1811        unsafe {
1812            let mut uid = ptr::null_mut();
1813
1814            ffi::gst_event_parse_toc_select(self.as_mut_ptr(), &mut uid);
1815
1816            CStr::from_ptr(uid).to_str().unwrap()
1817        }
1818    }
1819}
1820
1821impl std::fmt::Debug for TocSelect {
1822    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1823        f.debug_struct("TocSelect")
1824            .field("seqnum", &self.event().seqnum())
1825            .field("running-time-offset", &self.event().running_time_offset())
1826            .field("structure", &self.event().structure())
1827            .field("uid", &self.uid())
1828            .finish()
1829    }
1830}
1831
1832impl std::fmt::Debug for TocSelect<Event> {
1833    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1834        TocSelect::<EventRef>::fmt(self, f)
1835    }
1836}
1837
1838declare_concrete_event!(SelectStreams, T);
1839impl SelectStreams<Event> {
1840    #[doc(alias = "gst_event_new_select_streams")]
1841    #[allow(clippy::new_ret_no_self)]
1842    pub fn new<'a>(streams: impl IntoIterator<Item = &'a str>) -> Event {
1843        skip_assert_initialized!();
1844        Self::builder(streams).build()
1845    }
1846
1847    pub fn builder<'a>(streams: impl IntoIterator<Item = &'a str>) -> SelectStreamsBuilder<'a> {
1848        assert_initialized_main_thread!();
1849        SelectStreamsBuilder::new(streams)
1850    }
1851}
1852
1853impl SelectStreams {
1854    #[doc(alias = "get_streams")]
1855    #[doc(alias = "gst_event_parse_select_streams")]
1856    pub fn streams(&self) -> glib::collections::List<glib::GStringPtr> {
1857        unsafe {
1858            let mut streams = ptr::null_mut();
1859
1860            ffi::gst_event_parse_select_streams(self.as_mut_ptr(), &mut streams);
1861
1862            glib::collections::List::from_glib_full(streams)
1863        }
1864    }
1865}
1866
1867impl std::fmt::Debug for SelectStreams {
1868    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1869        struct StreamsDebug<'a>(&'a SelectStreams);
1870
1871        impl std::fmt::Debug for StreamsDebug<'_> {
1872            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1873                f.debug_list().entries(self.0.streams()).finish()
1874            }
1875        }
1876
1877        f.debug_struct("SelectStreams")
1878            .field("seqnum", &self.event().seqnum())
1879            .field("running-time-offset", &self.event().running_time_offset())
1880            .field("structure", &self.event().structure())
1881            .field("streams", &StreamsDebug(self))
1882            .finish()
1883    }
1884}
1885
1886impl std::fmt::Debug for SelectStreams<Event> {
1887    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1888        SelectStreams::<EventRef>::fmt(self, f)
1889    }
1890}
1891
1892#[cfg(feature = "v1_18")]
1893#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1894declare_concrete_event!(InstantRateSyncTime, T);
1895#[cfg(feature = "v1_18")]
1896#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1897impl InstantRateSyncTime<Event> {
1898    #[doc(alias = "gst_event_new_instant_rate_sync_time")]
1899    #[allow(clippy::new_ret_no_self)]
1900    pub fn new(
1901        rate_multiplier: f64,
1902        running_time: ClockTime,
1903        upstream_running_time: ClockTime,
1904    ) -> Event {
1905        skip_assert_initialized!();
1906        Self::builder(rate_multiplier, running_time, upstream_running_time).build()
1907    }
1908
1909    pub fn builder<'a>(
1910        rate_multiplier: f64,
1911        running_time: ClockTime,
1912        upstream_running_time: ClockTime,
1913    ) -> InstantRateSyncTimeBuilder<'a> {
1914        assert_initialized_main_thread!();
1915        InstantRateSyncTimeBuilder::new(rate_multiplier, running_time, upstream_running_time)
1916    }
1917}
1918
1919#[cfg(feature = "v1_18")]
1920#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1921impl InstantRateSyncTime {
1922    #[doc(alias = "parse_instant_rate_sync_time")]
1923    #[doc(alias = "gst_event_parse_instant_rate_sync_time")]
1924    pub fn get(&self) -> (f64, ClockTime, ClockTime) {
1925        unsafe {
1926            let mut rate_multiplier = mem::MaybeUninit::uninit();
1927            let mut running_time = mem::MaybeUninit::uninit();
1928            let mut upstream_running_time = mem::MaybeUninit::uninit();
1929
1930            ffi::gst_event_parse_instant_rate_sync_time(
1931                self.as_mut_ptr(),
1932                rate_multiplier.as_mut_ptr(),
1933                running_time.as_mut_ptr(),
1934                upstream_running_time.as_mut_ptr(),
1935            );
1936
1937            (
1938                rate_multiplier.assume_init(),
1939                try_from_glib(running_time.assume_init()).expect("undefined timestamp"),
1940                try_from_glib(upstream_running_time.assume_init()).expect("undefined timestamp"),
1941            )
1942        }
1943    }
1944}
1945
1946#[cfg(feature = "v1_18")]
1947impl std::fmt::Debug for InstantRateSyncTime {
1948    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1949        let (rate_multiplier, running_time, upstream_running_time) = self.get();
1950        f.debug_struct("InstantRateSyncTime")
1951            .field("seqnum", &self.event().seqnum())
1952            .field("running-time-offset", &self.event().running_time_offset())
1953            .field("structure", &self.event().structure())
1954            .field("rate-multiplier", &rate_multiplier)
1955            .field("running-time", &running_time)
1956            .field("upstream-running-time", &upstream_running_time)
1957            .finish()
1958    }
1959}
1960
1961#[cfg(feature = "v1_18")]
1962impl std::fmt::Debug for InstantRateSyncTime<Event> {
1963    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1964        InstantRateSyncTime::<EventRef>::fmt(self, f)
1965    }
1966}
1967
1968declare_concrete_event!(CustomUpstream, T);
1969impl CustomUpstream<Event> {
1970    #[doc(alias = "gst_event_new_custom")]
1971    #[allow(clippy::new_ret_no_self)]
1972    pub fn new(structure: crate::Structure) -> Event {
1973        skip_assert_initialized!();
1974        Self::builder(structure).build()
1975    }
1976
1977    pub fn builder<'a>(structure: crate::Structure) -> CustomUpstreamBuilder<'a> {
1978        assert_initialized_main_thread!();
1979        CustomUpstreamBuilder::new(structure)
1980    }
1981}
1982
1983impl std::fmt::Debug for CustomUpstream {
1984    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1985        f.debug_struct("CustomUpstream")
1986            .field("seqnum", &self.event().seqnum())
1987            .field("running-time-offset", &self.event().running_time_offset())
1988            .field("structure", &self.event().structure())
1989            .finish()
1990    }
1991}
1992
1993impl std::fmt::Debug for CustomUpstream<Event> {
1994    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1995        CustomUpstream::<EventRef>::fmt(self, f)
1996    }
1997}
1998
1999declare_concrete_event!(CustomDownstream, T);
2000impl CustomDownstream<Event> {
2001    #[doc(alias = "gst_event_new_custom")]
2002    #[allow(clippy::new_ret_no_self)]
2003    pub fn new(structure: crate::Structure) -> Event {
2004        skip_assert_initialized!();
2005        Self::builder(structure).build()
2006    }
2007
2008    pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamBuilder<'a> {
2009        assert_initialized_main_thread!();
2010        CustomDownstreamBuilder::new(structure)
2011    }
2012}
2013
2014impl std::fmt::Debug for CustomDownstream {
2015    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2016        f.debug_struct("CustomDownstream")
2017            .field("seqnum", &self.event().seqnum())
2018            .field("running-time-offset", &self.event().running_time_offset())
2019            .field("structure", &self.event().structure())
2020            .finish()
2021    }
2022}
2023
2024impl std::fmt::Debug for CustomDownstream<Event> {
2025    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2026        CustomDownstream::<EventRef>::fmt(self, f)
2027    }
2028}
2029
2030declare_concrete_event!(CustomDownstreamOob, T);
2031impl CustomDownstreamOob<Event> {
2032    #[doc(alias = "gst_event_new_custom")]
2033    #[allow(clippy::new_ret_no_self)]
2034    pub fn new(structure: crate::Structure) -> Event {
2035        skip_assert_initialized!();
2036        Self::builder(structure).build()
2037    }
2038
2039    pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamOobBuilder<'a> {
2040        assert_initialized_main_thread!();
2041        CustomDownstreamOobBuilder::new(structure)
2042    }
2043}
2044
2045impl std::fmt::Debug for CustomDownstreamOob {
2046    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2047        f.debug_struct("CustomDownstreamOob")
2048            .field("seqnum", &self.event().seqnum())
2049            .field("running-time-offset", &self.event().running_time_offset())
2050            .field("structure", &self.event().structure())
2051            .finish()
2052    }
2053}
2054
2055impl std::fmt::Debug for CustomDownstreamOob<Event> {
2056    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2057        CustomDownstreamOob::<EventRef>::fmt(self, f)
2058    }
2059}
2060
2061declare_concrete_event!(@sticky CustomDownstreamSticky, T);
2062impl CustomDownstreamSticky<Event> {
2063    #[doc(alias = "gst_event_new_custom")]
2064    #[allow(clippy::new_ret_no_self)]
2065    pub fn new(structure: crate::Structure) -> Event {
2066        skip_assert_initialized!();
2067        Self::builder(structure).build()
2068    }
2069
2070    pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamStickyBuilder<'a> {
2071        assert_initialized_main_thread!();
2072        CustomDownstreamStickyBuilder::new(structure)
2073    }
2074}
2075
2076impl std::fmt::Debug for CustomDownstreamSticky {
2077    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2078        f.debug_struct("CustomDownstreamSticky")
2079            .field("seqnum", &self.event().seqnum())
2080            .field("running-time-offset", &self.event().running_time_offset())
2081            .field("structure", &self.event().structure())
2082            .finish()
2083    }
2084}
2085
2086impl std::fmt::Debug for CustomDownstreamSticky<Event> {
2087    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2088        CustomDownstreamSticky::<EventRef>::fmt(self, f)
2089    }
2090}
2091
2092declare_concrete_event!(CustomBoth, T);
2093impl CustomBoth<Event> {
2094    #[doc(alias = "gst_event_new_custom")]
2095    #[allow(clippy::new_ret_no_self)]
2096    pub fn new(structure: crate::Structure) -> Event {
2097        skip_assert_initialized!();
2098        Self::builder(structure).build()
2099    }
2100
2101    pub fn builder<'a>(structure: crate::Structure) -> CustomBothBuilder<'a> {
2102        assert_initialized_main_thread!();
2103        CustomBothBuilder::new(structure)
2104    }
2105}
2106
2107impl std::fmt::Debug for CustomBoth {
2108    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2109        f.debug_struct("CustomBoth")
2110            .field("seqnum", &self.event().seqnum())
2111            .field("running-time-offset", &self.event().running_time_offset())
2112            .field("structure", &self.event().structure())
2113            .finish()
2114    }
2115}
2116
2117impl std::fmt::Debug for CustomBoth<Event> {
2118    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2119        CustomBoth::<EventRef>::fmt(self, f)
2120    }
2121}
2122
2123declare_concrete_event!(CustomBothOob, T);
2124impl CustomBothOob<Event> {
2125    #[doc(alias = "gst_event_new_custom")]
2126    #[allow(clippy::new_ret_no_self)]
2127    pub fn new(structure: crate::Structure) -> Event {
2128        skip_assert_initialized!();
2129        Self::builder(structure).build()
2130    }
2131
2132    pub fn builder<'a>(structure: crate::Structure) -> CustomBothOobBuilder<'a> {
2133        assert_initialized_main_thread!();
2134        CustomBothOobBuilder::new(structure)
2135    }
2136}
2137
2138impl std::fmt::Debug for CustomBothOob {
2139    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2140        f.debug_struct("CustomBothOob")
2141            .field("seqnum", &self.event().seqnum())
2142            .field("running-time-offset", &self.event().running_time_offset())
2143            .field("structure", &self.event().structure())
2144            .finish()
2145    }
2146}
2147
2148impl std::fmt::Debug for CustomBothOob<Event> {
2149    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2150        CustomBothOob::<EventRef>::fmt(self, f)
2151    }
2152}
2153
2154declare_concrete_event!(Other, T);
2155
2156impl std::fmt::Debug for Other {
2157    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2158        f.debug_struct("Other")
2159            .field("seqnum", &self.event().seqnum())
2160            .field("running-time-offset", &self.event().running_time_offset())
2161            .field("structure", &self.event().structure())
2162            .finish()
2163    }
2164}
2165
2166impl std::fmt::Debug for Other<Event> {
2167    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2168        Other::<EventRef>::fmt(self, f)
2169    }
2170}
2171
2172struct EventBuilder<'a> {
2173    seqnum: Option<Seqnum>,
2174    running_time_offset: Option<i64>,
2175    other_fields: Vec<(&'a str, glib::SendValue)>,
2176}
2177
2178impl<'a> EventBuilder<'a> {
2179    fn new() -> Self {
2180        Self {
2181            seqnum: None,
2182            running_time_offset: None,
2183            other_fields: Vec::new(),
2184        }
2185    }
2186
2187    fn seqnum(self, seqnum: Seqnum) -> Self {
2188        Self {
2189            seqnum: Some(seqnum),
2190            ..self
2191        }
2192    }
2193
2194    fn running_time_offset(self, running_time_offset: i64) -> Self {
2195        Self {
2196            running_time_offset: Some(running_time_offset),
2197            ..self
2198        }
2199    }
2200
2201    fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self {
2202        let mut other_fields = self.other_fields;
2203        other_fields.push((name, value.to_send_value()));
2204
2205        Self {
2206            other_fields,
2207            ..self
2208        }
2209    }
2210}
2211
2212macro_rules! event_builder_generic_impl {
2213    ($new_fn:expr) => {
2214        #[doc(alias = "gst_event_set_seqnum")]
2215        #[allow(clippy::needless_update)]
2216        pub fn seqnum(self, seqnum: Seqnum) -> Self {
2217            Self {
2218                builder: self.builder.seqnum(seqnum),
2219                ..self
2220            }
2221        }
2222
2223        #[doc(alias = "gst_event_set_seqnum")]
2224        #[allow(clippy::needless_update)]
2225        pub fn seqnum_if(self, seqnum: Seqnum, predicate: bool) -> Self {
2226            if predicate {
2227                self.seqnum(seqnum)
2228            } else {
2229                self
2230            }
2231        }
2232
2233        #[doc(alias = "gst_event_set_seqnum")]
2234        #[allow(clippy::needless_update)]
2235        pub fn seqnum_if_some(self, seqnum: Option<Seqnum>) -> Self {
2236            if let Some(seqnum) = seqnum {
2237                self.seqnum(seqnum)
2238            } else {
2239                self
2240            }
2241        }
2242
2243        #[doc(alias = "gst_event_set_running_time_offset")]
2244        #[allow(clippy::needless_update)]
2245        pub fn running_time_offset(self, running_time_offset: i64) -> Self {
2246            Self {
2247                builder: self.builder.running_time_offset(running_time_offset),
2248                ..self
2249            }
2250        }
2251
2252        #[doc(alias = "gst_event_set_running_time_offset")]
2253        #[allow(clippy::needless_update)]
2254        pub fn running_time_offset_if(self, running_time_offset: i64, predicate: bool) -> Self {
2255            if predicate {
2256                self.running_time_offset(running_time_offset)
2257            } else {
2258                self
2259            }
2260        }
2261
2262        #[doc(alias = "gst_event_set_running_time_offset")]
2263        #[allow(clippy::needless_update)]
2264        pub fn running_time_offset_if_some(self, running_time_offset: Option<i64>) -> Self {
2265            if let Some(running_time_offset) = running_time_offset {
2266                self.running_time_offset(running_time_offset)
2267            } else {
2268                self
2269            }
2270        }
2271
2272        // rustdoc-stripper-ignore-next
2273        /// Sets field `name` to the given value `value`.
2274        ///
2275        /// Overrides any default or previously defined value for `name`.
2276        #[allow(clippy::needless_update)]
2277        pub fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self {
2278            Self {
2279                builder: self.builder.other_field(name, value),
2280                ..self
2281            }
2282        }
2283
2284        impl_builder_gvalue_extra_setters!(other_field);
2285
2286        #[must_use = "Building the event without using it has no effect"]
2287        #[allow(clippy::redundant_closure_call)]
2288        pub fn build(mut self) -> Event {
2289            unsafe {
2290                let event = $new_fn(&mut self);
2291                if let Some(seqnum) = self.builder.seqnum {
2292                    ffi::gst_event_set_seqnum(event, seqnum.0.get());
2293                }
2294
2295                if let Some(running_time_offset) = self.builder.running_time_offset {
2296                    ffi::gst_event_set_running_time_offset(event, running_time_offset);
2297                }
2298
2299                if !self.builder.other_fields.is_empty() {
2300                    let s = StructureRef::from_glib_borrow_mut(ffi::gst_event_writable_structure(
2301                        event,
2302                    ));
2303
2304                    for (k, v) in self.builder.other_fields {
2305                        s.set_value(k, v);
2306                    }
2307                }
2308
2309                from_glib_full(event)
2310            }
2311        }
2312    };
2313}
2314
2315#[must_use = "The builder must be built to be used"]
2316pub struct FlushStartBuilder<'a> {
2317    builder: EventBuilder<'a>,
2318}
2319
2320impl<'a> FlushStartBuilder<'a> {
2321    fn new() -> Self {
2322        skip_assert_initialized!();
2323        Self {
2324            builder: EventBuilder::new(),
2325        }
2326    }
2327
2328    event_builder_generic_impl!(|_| { ffi::gst_event_new_flush_start() });
2329}
2330
2331#[must_use = "The builder must be built to be used"]
2332pub struct FlushStopBuilder<'a> {
2333    builder: EventBuilder<'a>,
2334    reset_time: bool,
2335}
2336impl<'a> FlushStopBuilder<'a> {
2337    fn new(reset_time: bool) -> Self {
2338        skip_assert_initialized!();
2339        Self {
2340            builder: EventBuilder::new(),
2341            reset_time,
2342        }
2343    }
2344
2345    event_builder_generic_impl!(|s: &Self| {
2346        ffi::gst_event_new_flush_stop(s.reset_time.into_glib())
2347    });
2348}
2349
2350#[must_use = "The builder must be built to be used"]
2351pub struct StreamStartBuilder<'a> {
2352    builder: EventBuilder<'a>,
2353    stream_id: &'a str,
2354    flags: Option<crate::StreamFlags>,
2355    group_id: Option<GroupId>,
2356    stream: Option<crate::Stream>,
2357}
2358
2359impl<'a> StreamStartBuilder<'a> {
2360    fn new(stream_id: &'a str) -> Self {
2361        skip_assert_initialized!();
2362        Self {
2363            builder: EventBuilder::new(),
2364            stream_id,
2365            flags: None,
2366            group_id: None,
2367            stream: None,
2368        }
2369    }
2370
2371    pub fn flags(self, flags: crate::StreamFlags) -> Self {
2372        Self {
2373            flags: Some(flags),
2374            ..self
2375        }
2376    }
2377
2378    pub fn flags_if(self, flags: crate::StreamFlags, predicate: bool) -> Self {
2379        if predicate {
2380            self.flags(flags)
2381        } else {
2382            self
2383        }
2384    }
2385
2386    pub fn flags_if_some(self, flags: Option<crate::StreamFlags>) -> Self {
2387        if let Some(flags) = flags {
2388            self.flags(flags)
2389        } else {
2390            self
2391        }
2392    }
2393
2394    pub fn group_id(self, group_id: GroupId) -> Self {
2395        Self {
2396            group_id: Some(group_id),
2397            ..self
2398        }
2399    }
2400
2401    pub fn group_id_if(self, group_id: GroupId, predicate: bool) -> Self {
2402        if predicate {
2403            self.group_id(group_id)
2404        } else {
2405            self
2406        }
2407    }
2408
2409    pub fn group_id_if_some(self, group_id: Option<GroupId>) -> Self {
2410        if let Some(group_id) = group_id {
2411            self.group_id(group_id)
2412        } else {
2413            self
2414        }
2415    }
2416
2417    pub fn stream(self, stream: crate::Stream) -> Self {
2418        Self {
2419            stream: Some(stream),
2420            ..self
2421        }
2422    }
2423
2424    pub fn stream_if(self, stream: crate::Stream, predicate: bool) -> Self {
2425        if predicate {
2426            self.stream(stream)
2427        } else {
2428            self
2429        }
2430    }
2431
2432    pub fn stream_if_some(self, stream: Option<crate::Stream>) -> Self {
2433        if let Some(stream) = stream {
2434            self.stream(stream)
2435        } else {
2436            self
2437        }
2438    }
2439
2440    event_builder_generic_impl!(|s: &Self| {
2441        let ev = ffi::gst_event_new_stream_start(s.stream_id.to_glib_none().0);
2442        if let Some(flags) = s.flags {
2443            ffi::gst_event_set_stream_flags(ev, flags.into_glib());
2444        }
2445        if let Some(group_id) = s.group_id {
2446            ffi::gst_event_set_group_id(ev, group_id.0.get());
2447        }
2448
2449        if let Some(ref stream) = s.stream {
2450            ffi::gst_event_set_stream(ev, stream.to_glib_none().0);
2451        }
2452
2453        ev
2454    });
2455}
2456
2457#[must_use = "The builder must be built to be used"]
2458pub struct CapsBuilder<'a> {
2459    builder: EventBuilder<'a>,
2460    caps: &'a crate::Caps,
2461}
2462
2463impl<'a> CapsBuilder<'a> {
2464    fn new(caps: &'a crate::Caps) -> Self {
2465        skip_assert_initialized!();
2466        Self {
2467            builder: EventBuilder::new(),
2468            caps,
2469        }
2470    }
2471
2472    event_builder_generic_impl!(|s: &Self| { ffi::gst_event_new_caps(s.caps.as_mut_ptr()) });
2473}
2474
2475#[must_use = "The builder must be built to be used"]
2476pub struct SegmentBuilder<'a> {
2477    builder: EventBuilder<'a>,
2478    segment: &'a crate::Segment,
2479}
2480
2481impl<'a> SegmentBuilder<'a> {
2482    fn new(segment: &'a crate::Segment) -> Self {
2483        skip_assert_initialized!();
2484        Self {
2485            builder: EventBuilder::new(),
2486            segment,
2487        }
2488    }
2489
2490    event_builder_generic_impl!(|s: &Self| {
2491        ffi::gst_event_new_segment(s.segment.to_glib_none().0)
2492    });
2493}
2494
2495#[must_use = "The builder must be built to be used"]
2496pub struct StreamCollectionBuilder<'a> {
2497    builder: EventBuilder<'a>,
2498    stream_collection: &'a crate::StreamCollection,
2499}
2500
2501impl<'a> StreamCollectionBuilder<'a> {
2502    fn new(stream_collection: &'a crate::StreamCollection) -> Self {
2503        skip_assert_initialized!();
2504        Self {
2505            builder: EventBuilder::new(),
2506            stream_collection,
2507        }
2508    }
2509
2510    event_builder_generic_impl!(|s: &Self| {
2511        ffi::gst_event_new_stream_collection(s.stream_collection.to_glib_none().0)
2512    });
2513}
2514
2515#[cfg(feature = "v1_18")]
2516#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2517#[must_use = "The builder must be built to be used"]
2518pub struct InstantRateSyncTimeBuilder<'a> {
2519    builder: EventBuilder<'a>,
2520    rate_multiplier: f64,
2521    running_time: ClockTime,
2522    upstream_running_time: ClockTime,
2523}
2524
2525#[cfg(feature = "v1_18")]
2526#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2527impl<'a> InstantRateSyncTimeBuilder<'a> {
2528    fn new(
2529        rate_multiplier: f64,
2530        running_time: ClockTime,
2531        upstream_running_time: ClockTime,
2532    ) -> Self {
2533        skip_assert_initialized!();
2534        Self {
2535            builder: EventBuilder::new(),
2536            rate_multiplier,
2537            running_time,
2538            upstream_running_time,
2539        }
2540    }
2541
2542    event_builder_generic_impl!(|s: &Self| {
2543        ffi::gst_event_new_instant_rate_sync_time(
2544            s.rate_multiplier,
2545            s.running_time.into_glib(),
2546            s.upstream_running_time.into_glib(),
2547        )
2548    });
2549}
2550
2551#[must_use = "The builder must be built to be used"]
2552pub struct TagBuilder<'a> {
2553    builder: EventBuilder<'a>,
2554    tags: Option<crate::TagList>,
2555}
2556
2557impl<'a> TagBuilder<'a> {
2558    fn new(tags: crate::TagList) -> Self {
2559        skip_assert_initialized!();
2560        Self {
2561            builder: EventBuilder::new(),
2562            tags: Some(tags),
2563        }
2564    }
2565
2566    event_builder_generic_impl!(|s: &mut Self| {
2567        let tags = s.tags.take().unwrap();
2568        ffi::gst_event_new_tag(tags.into_glib_ptr())
2569    });
2570}
2571
2572#[must_use = "The builder must be built to be used"]
2573pub struct BuffersizeBuilder<'a> {
2574    builder: EventBuilder<'a>,
2575    minsize: GenericFormattedValue,
2576    maxsize: GenericFormattedValue,
2577    r#async: bool,
2578}
2579
2580impl<'a> BuffersizeBuilder<'a> {
2581    fn new(minsize: GenericFormattedValue, maxsize: GenericFormattedValue, r#async: bool) -> Self {
2582        skip_assert_initialized!();
2583        Self {
2584            builder: EventBuilder::new(),
2585            minsize,
2586            maxsize,
2587            r#async,
2588        }
2589    }
2590
2591    event_builder_generic_impl!(|s: &Self| {
2592        ffi::gst_event_new_buffer_size(
2593            s.minsize.format().into_glib(),
2594            s.minsize.value(),
2595            s.maxsize.value(),
2596            s.r#async.into_glib(),
2597        )
2598    });
2599}
2600
2601#[must_use = "The builder must be built to be used"]
2602pub struct SinkMessageBuilder<'a> {
2603    builder: EventBuilder<'a>,
2604    name: &'a str,
2605    msg: &'a crate::Message,
2606}
2607
2608impl<'a> SinkMessageBuilder<'a> {
2609    fn new(name: &'a str, msg: &'a crate::Message) -> Self {
2610        skip_assert_initialized!();
2611        Self {
2612            builder: EventBuilder::new(),
2613            name,
2614            msg,
2615        }
2616    }
2617
2618    event_builder_generic_impl!(|s: &Self| {
2619        ffi::gst_event_new_sink_message(s.name.to_glib_none().0, s.msg.as_mut_ptr())
2620    });
2621}
2622
2623#[must_use = "The builder must be built to be used"]
2624pub struct StreamGroupDoneBuilder<'a> {
2625    builder: EventBuilder<'a>,
2626    group_id: GroupId,
2627}
2628
2629impl<'a> StreamGroupDoneBuilder<'a> {
2630    fn new(group_id: GroupId) -> Self {
2631        skip_assert_initialized!();
2632        Self {
2633            builder: EventBuilder::new(),
2634            group_id,
2635        }
2636    }
2637
2638    event_builder_generic_impl!(|s: &Self| {
2639        ffi::gst_event_new_stream_group_done(s.group_id.0.get())
2640    });
2641}
2642
2643#[must_use = "The builder must be built to be used"]
2644pub struct EosBuilder<'a> {
2645    builder: EventBuilder<'a>,
2646}
2647
2648impl<'a> EosBuilder<'a> {
2649    fn new() -> Self {
2650        skip_assert_initialized!();
2651        Self {
2652            builder: EventBuilder::new(),
2653        }
2654    }
2655
2656    event_builder_generic_impl!(|_| ffi::gst_event_new_eos());
2657}
2658
2659#[must_use = "The builder must be built to be used"]
2660pub struct TocBuilder<'a> {
2661    builder: EventBuilder<'a>,
2662    toc: &'a crate::Toc,
2663    updated: bool,
2664}
2665
2666impl<'a> TocBuilder<'a> {
2667    fn new(toc: &'a crate::Toc, updated: bool) -> Self {
2668        skip_assert_initialized!();
2669        Self {
2670            builder: EventBuilder::new(),
2671            toc,
2672            updated,
2673        }
2674    }
2675
2676    event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_toc(
2677        s.toc.to_glib_none().0,
2678        s.updated.into_glib()
2679    ));
2680}
2681
2682#[must_use = "The builder must be built to be used"]
2683pub struct ProtectionBuilder<'a> {
2684    builder: EventBuilder<'a>,
2685    system_id: &'a str,
2686    data: &'a crate::Buffer,
2687    origin: Option<&'a str>,
2688}
2689
2690impl<'a> ProtectionBuilder<'a> {
2691    fn new(system_id: &'a str, data: &'a crate::Buffer) -> Self {
2692        skip_assert_initialized!();
2693        Self {
2694            builder: EventBuilder::new(),
2695            system_id,
2696            data,
2697            origin: None,
2698        }
2699    }
2700
2701    pub fn origin(self, origin: &'a str) -> Self {
2702        Self {
2703            origin: Some(origin),
2704            ..self
2705        }
2706    }
2707
2708    pub fn origin_if(self, origin: &'a str, predicate: bool) -> Self {
2709        if predicate {
2710            self.origin(origin)
2711        } else {
2712            self
2713        }
2714    }
2715
2716    pub fn origin_if_some(self, origin: Option<&'a str>) -> Self {
2717        if let Some(origin) = origin {
2718            self.origin(origin)
2719        } else {
2720            self
2721        }
2722    }
2723
2724    event_builder_generic_impl!(|s: &Self| {
2725        ffi::gst_event_new_protection(
2726            s.system_id.to_glib_none().0,
2727            s.data.as_mut_ptr(),
2728            s.origin.to_glib_none().0,
2729        )
2730    });
2731}
2732
2733#[must_use = "The builder must be built to be used"]
2734pub struct SegmentDoneBuilder<'a> {
2735    builder: EventBuilder<'a>,
2736    position: GenericFormattedValue,
2737}
2738
2739impl<'a> SegmentDoneBuilder<'a> {
2740    fn new(position: GenericFormattedValue) -> Self {
2741        skip_assert_initialized!();
2742        Self {
2743            builder: EventBuilder::new(),
2744            position,
2745        }
2746    }
2747
2748    event_builder_generic_impl!(|s: &Self| {
2749        ffi::gst_event_new_segment_done(s.position.format().into_glib(), s.position.value())
2750    });
2751}
2752
2753#[must_use = "The builder must be built to be used"]
2754pub struct GapBuilder<'a> {
2755    builder: EventBuilder<'a>,
2756    timestamp: ClockTime,
2757    duration: Option<ClockTime>,
2758    #[cfg(feature = "v1_20")]
2759    gap_flags: Option<crate::GapFlags>,
2760}
2761
2762impl<'a> GapBuilder<'a> {
2763    fn new(timestamp: ClockTime) -> Self {
2764        skip_assert_initialized!();
2765        Self {
2766            builder: EventBuilder::new(),
2767            timestamp,
2768            duration: None,
2769            #[cfg(feature = "v1_20")]
2770            gap_flags: None,
2771        }
2772    }
2773
2774    #[cfg(feature = "v1_20")]
2775    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2776    pub fn gap_flags(mut self, flags: crate::GapFlags) -> Self {
2777        self.gap_flags = Some(flags);
2778        self
2779    }
2780
2781    #[cfg(feature = "v1_20")]
2782    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2783    pub fn gap_flags_if(self, flags: crate::GapFlags, predicate: bool) -> Self {
2784        if predicate {
2785            self.gap_flags(flags)
2786        } else {
2787            self
2788        }
2789    }
2790
2791    #[cfg(feature = "v1_20")]
2792    #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2793    pub fn gap_flags_if_some(self, flags: Option<crate::GapFlags>) -> Self {
2794        if let Some(flags) = flags {
2795            self.gap_flags(flags)
2796        } else {
2797            self
2798        }
2799    }
2800
2801    pub fn duration(mut self, duration: impl Into<Option<ClockTime>>) -> Self {
2802        self.duration = duration.into();
2803        self
2804    }
2805
2806    pub fn duration_if(self, duration: ClockTime, predicate: bool) -> Self {
2807        if predicate {
2808            self.duration(duration)
2809        } else {
2810            self
2811        }
2812    }
2813
2814    pub fn duration_if_some(self, duration: Option<ClockTime>) -> Self {
2815        if let Some(duration) = duration {
2816            self.duration(duration)
2817        } else {
2818            self
2819        }
2820    }
2821
2822    event_builder_generic_impl!(|s: &Self| {
2823        #[allow(clippy::let_and_return)]
2824        let ev = ffi::gst_event_new_gap(s.timestamp.into_glib(), s.duration.into_glib());
2825
2826        #[cfg(feature = "v1_20")]
2827        if let Some(ref flags) = s.gap_flags {
2828            ffi::gst_event_set_gap_flags(ev, flags.into_glib());
2829        }
2830
2831        ev
2832    });
2833}
2834
2835#[cfg(feature = "v1_18")]
2836#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2837#[must_use = "The builder must be built to be used"]
2838pub struct InstantRateChangeBuilder<'a> {
2839    builder: EventBuilder<'a>,
2840    multiplier: f64,
2841    new_flags: crate::SegmentFlags,
2842}
2843
2844#[cfg(feature = "v1_18")]
2845#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2846impl<'a> InstantRateChangeBuilder<'a> {
2847    fn new(multiplier: f64, new_flags: crate::SegmentFlags) -> Self {
2848        skip_assert_initialized!();
2849        Self {
2850            builder: EventBuilder::new(),
2851            multiplier,
2852            new_flags,
2853        }
2854    }
2855
2856    event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_instant_rate_change(
2857        s.multiplier,
2858        s.new_flags.into_glib()
2859    ));
2860}
2861
2862#[must_use = "The builder must be built to be used"]
2863pub struct QosBuilder<'a> {
2864    builder: EventBuilder<'a>,
2865    type_: crate::QOSType,
2866    proportion: f64,
2867    diff: i64,
2868    timestamp: Option<ClockTime>,
2869}
2870
2871impl<'a> QosBuilder<'a> {
2872    fn new(type_: crate::QOSType, proportion: f64, diff: i64) -> Self {
2873        skip_assert_initialized!();
2874        Self {
2875            builder: EventBuilder::new(),
2876            type_,
2877            proportion,
2878            diff,
2879            timestamp: None,
2880        }
2881    }
2882
2883    pub fn timestamp(mut self, timestamp: impl Into<Option<ClockTime>>) -> Self {
2884        self.timestamp = timestamp.into();
2885        self
2886    }
2887
2888    pub fn timestamp_if(self, timestamp: ClockTime, predicate: bool) -> Self {
2889        if predicate {
2890            self.timestamp(timestamp)
2891        } else {
2892            self
2893        }
2894    }
2895
2896    pub fn timestamp_if_some(self, timestamp: Option<ClockTime>) -> Self {
2897        if let Some(timestamp) = timestamp {
2898            self.timestamp(timestamp)
2899        } else {
2900            self
2901        }
2902    }
2903
2904    event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_qos(
2905        s.type_.into_glib(),
2906        s.proportion,
2907        s.diff,
2908        s.timestamp.into_glib(),
2909    ));
2910}
2911
2912#[must_use = "The builder must be built to be used"]
2913pub struct SeekBuilder<'a> {
2914    builder: EventBuilder<'a>,
2915    rate: f64,
2916    flags: crate::SeekFlags,
2917    start_type: crate::SeekType,
2918    start: GenericFormattedValue,
2919    stop_type: crate::SeekType,
2920    stop: GenericFormattedValue,
2921    #[allow(unused)]
2922    trickmode_interval: Option<ClockTime>,
2923}
2924
2925impl<'a> SeekBuilder<'a> {
2926    fn new(
2927        rate: f64,
2928        flags: crate::SeekFlags,
2929        start_type: crate::SeekType,
2930        start: GenericFormattedValue,
2931        stop_type: crate::SeekType,
2932        stop: GenericFormattedValue,
2933    ) -> Self {
2934        skip_assert_initialized!();
2935        Self {
2936            builder: EventBuilder::new(),
2937            rate,
2938            flags,
2939            start_type,
2940            start,
2941            stop_type,
2942            stop,
2943            trickmode_interval: None,
2944        }
2945    }
2946
2947    pub fn trickmode_interval(mut self, trickmode_interval: impl Into<Option<ClockTime>>) -> Self {
2948        self.trickmode_interval = trickmode_interval.into();
2949        self
2950    }
2951
2952    event_builder_generic_impl!(|s: &Self| {
2953        #[allow(clippy::let_and_return)]
2954        {
2955            let ev = ffi::gst_event_new_seek(
2956                s.rate,
2957                s.start.format().into_glib(),
2958                s.flags.into_glib(),
2959                s.start_type.into_glib(),
2960                s.start.value(),
2961                s.stop_type.into_glib(),
2962                s.stop.value(),
2963            );
2964
2965            #[cfg(feature = "v1_16")]
2966            if let Some(trickmode_interval) = s.trickmode_interval {
2967                ffi::gst_event_set_seek_trickmode_interval(ev, trickmode_interval.into_glib());
2968            }
2969
2970            ev
2971        }
2972    });
2973}
2974
2975#[must_use = "The builder must be built to be used"]
2976pub struct NavigationBuilder<'a> {
2977    builder: EventBuilder<'a>,
2978    structure: Option<Structure>,
2979}
2980
2981impl<'a> NavigationBuilder<'a> {
2982    fn new(structure: Structure) -> Self {
2983        skip_assert_initialized!();
2984        Self {
2985            builder: EventBuilder::new(),
2986            structure: Some(structure),
2987        }
2988    }
2989
2990    event_builder_generic_impl!(|s: &mut Self| {
2991        let structure = s.structure.take().unwrap();
2992        ffi::gst_event_new_navigation(structure.into_glib_ptr())
2993    });
2994}
2995
2996#[must_use = "The builder must be built to be used"]
2997pub struct LatencyBuilder<'a> {
2998    builder: EventBuilder<'a>,
2999    latency: ClockTime,
3000}
3001
3002impl<'a> LatencyBuilder<'a> {
3003    fn new(latency: ClockTime) -> Self {
3004        skip_assert_initialized!();
3005        Self {
3006            builder: EventBuilder::new(),
3007            latency,
3008        }
3009    }
3010
3011    event_builder_generic_impl!(|s: &Self| { ffi::gst_event_new_latency(s.latency.into_glib()) });
3012}
3013
3014#[must_use = "The builder must be built to be used"]
3015pub struct StepBuilder<'a> {
3016    builder: EventBuilder<'a>,
3017    amount: GenericFormattedValue,
3018    rate: f64,
3019    flush: bool,
3020    intermediate: bool,
3021}
3022
3023impl<'a> StepBuilder<'a> {
3024    fn new(amount: GenericFormattedValue, rate: f64, flush: bool, intermediate: bool) -> Self {
3025        skip_assert_initialized!();
3026        Self {
3027            builder: EventBuilder::new(),
3028            amount,
3029            rate,
3030            flush,
3031            intermediate,
3032        }
3033    }
3034
3035    event_builder_generic_impl!(|s: &Self| {
3036        ffi::gst_event_new_step(
3037            s.amount.format().into_glib(),
3038            s.amount.value() as u64,
3039            s.rate,
3040            s.flush.into_glib(),
3041            s.intermediate.into_glib(),
3042        )
3043    });
3044}
3045
3046#[must_use = "The builder must be built to be used"]
3047pub struct ReconfigureBuilder<'a> {
3048    builder: EventBuilder<'a>,
3049}
3050
3051impl<'a> ReconfigureBuilder<'a> {
3052    fn new() -> Self {
3053        skip_assert_initialized!();
3054        Self {
3055            builder: EventBuilder::new(),
3056        }
3057    }
3058
3059    event_builder_generic_impl!(|_| { ffi::gst_event_new_reconfigure() });
3060}
3061
3062#[must_use = "The builder must be built to be used"]
3063pub struct TocSelectBuilder<'a> {
3064    builder: EventBuilder<'a>,
3065    uid: &'a str,
3066}
3067
3068impl<'a> TocSelectBuilder<'a> {
3069    fn new(uid: &'a str) -> Self {
3070        skip_assert_initialized!();
3071        Self {
3072            builder: EventBuilder::new(),
3073            uid,
3074        }
3075    }
3076
3077    event_builder_generic_impl!(|s: &Self| {
3078        ffi::gst_event_new_toc_select(s.uid.to_glib_none().0)
3079    });
3080}
3081
3082#[must_use = "The builder must be built to be used"]
3083pub struct SelectStreamsBuilder<'a> {
3084    builder: EventBuilder<'a>,
3085    streams: glib::collections::List<glib::GStringPtr>,
3086}
3087
3088impl<'a> SelectStreamsBuilder<'a> {
3089    fn new(streams: impl IntoIterator<Item = &'a str>) -> Self {
3090        skip_assert_initialized!();
3091        Self {
3092            builder: EventBuilder::new(),
3093            streams: streams.into_iter().map(glib::GStringPtr::from).collect(),
3094        }
3095    }
3096
3097    event_builder_generic_impl!(|s: &Self| {
3098        ffi::gst_event_new_select_streams(mut_override(s.streams.as_ptr()))
3099    });
3100}
3101
3102#[must_use = "The builder must be built to be used"]
3103pub struct CustomUpstreamBuilder<'a> {
3104    builder: EventBuilder<'a>,
3105    structure: Option<Structure>,
3106}
3107
3108impl<'a> CustomUpstreamBuilder<'a> {
3109    fn new(structure: Structure) -> Self {
3110        skip_assert_initialized!();
3111        Self {
3112            builder: EventBuilder::new(),
3113            structure: Some(structure),
3114        }
3115    }
3116
3117    event_builder_generic_impl!(|s: &mut Self| {
3118        let structure = s.structure.take().unwrap();
3119        ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_UPSTREAM, structure.into_glib_ptr())
3120    });
3121}
3122
3123#[must_use = "The builder must be built to be used"]
3124pub struct CustomDownstreamBuilder<'a> {
3125    builder: EventBuilder<'a>,
3126    structure: Option<Structure>,
3127}
3128
3129impl<'a> CustomDownstreamBuilder<'a> {
3130    fn new(structure: Structure) -> Self {
3131        skip_assert_initialized!();
3132        Self {
3133            builder: EventBuilder::new(),
3134            structure: Some(structure),
3135        }
3136    }
3137
3138    event_builder_generic_impl!(|s: &mut Self| {
3139        let structure = s.structure.take().unwrap();
3140        ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_DOWNSTREAM, structure.into_glib_ptr())
3141    });
3142}
3143
3144#[must_use = "The builder must be built to be used"]
3145pub struct CustomDownstreamOobBuilder<'a> {
3146    builder: EventBuilder<'a>,
3147    structure: Option<Structure>,
3148}
3149
3150impl<'a> CustomDownstreamOobBuilder<'a> {
3151    fn new(structure: Structure) -> Self {
3152        skip_assert_initialized!();
3153        Self {
3154            builder: EventBuilder::new(),
3155            structure: Some(structure),
3156        }
3157    }
3158
3159    event_builder_generic_impl!(|s: &mut Self| {
3160        let structure = s.structure.take().unwrap();
3161        ffi::gst_event_new_custom(
3162            ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB,
3163            structure.into_glib_ptr(),
3164        )
3165    });
3166}
3167
3168#[must_use = "The builder must be built to be used"]
3169pub struct CustomDownstreamStickyBuilder<'a> {
3170    builder: EventBuilder<'a>,
3171    structure: Option<Structure>,
3172}
3173
3174impl<'a> CustomDownstreamStickyBuilder<'a> {
3175    fn new(structure: Structure) -> Self {
3176        skip_assert_initialized!();
3177        Self {
3178            builder: EventBuilder::new(),
3179            structure: Some(structure),
3180        }
3181    }
3182
3183    event_builder_generic_impl!(|s: &mut Self| {
3184        let structure = s.structure.take().unwrap();
3185        ffi::gst_event_new_custom(
3186            ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY,
3187            structure.into_glib_ptr(),
3188        )
3189    });
3190}
3191
3192#[must_use = "The builder must be built to be used"]
3193pub struct CustomBothBuilder<'a> {
3194    builder: EventBuilder<'a>,
3195    structure: Option<Structure>,
3196}
3197
3198impl<'a> CustomBothBuilder<'a> {
3199    fn new(structure: Structure) -> Self {
3200        skip_assert_initialized!();
3201        Self {
3202            builder: EventBuilder::new(),
3203            structure: Some(structure),
3204        }
3205    }
3206
3207    event_builder_generic_impl!(|s: &mut Self| {
3208        let structure = s.structure.take().unwrap();
3209        ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH, structure.into_glib_ptr())
3210    });
3211}
3212
3213#[must_use = "The builder must be built to be used"]
3214pub struct CustomBothOobBuilder<'a> {
3215    builder: EventBuilder<'a>,
3216    structure: Option<Structure>,
3217}
3218
3219impl<'a> CustomBothOobBuilder<'a> {
3220    fn new(structure: Structure) -> Self {
3221        skip_assert_initialized!();
3222        Self {
3223            builder: EventBuilder::new(),
3224            structure: Some(structure),
3225        }
3226    }
3227
3228    event_builder_generic_impl!(|s: &mut Self| {
3229        let structure = s.structure.take().unwrap();
3230        ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH_OOB, structure.into_glib_ptr())
3231    });
3232}
3233
3234#[cfg(test)]
3235mod tests {
3236    use super::*;
3237
3238    #[test]
3239    #[allow(deprecated)]
3240    fn test_simple() {
3241        crate::init().unwrap();
3242
3243        // Event without arguments
3244        let flush_start_evt = FlushStart::new();
3245        match flush_start_evt.view() {
3246            EventView::FlushStart(flush_start_evt) => {
3247                assert!(!flush_start_evt.is_sticky());
3248                assert!(flush_start_evt.structure().is_none());
3249            }
3250            _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"),
3251        }
3252
3253        let flush_start_evt = FlushStart::builder()
3254            .other_field("extra-field", true)
3255            .build();
3256        match flush_start_evt.view() {
3257            EventView::FlushStart(flush_start_evt) => {
3258                assert!(flush_start_evt.structure().is_some());
3259                if let Some(other_fields) = flush_start_evt.structure() {
3260                    assert!(other_fields.has_field("extra-field"));
3261                }
3262            }
3263            _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"),
3264        }
3265
3266        // Event with arguments
3267        let flush_stop_evt = FlushStop::builder(true)
3268            .other_field("extra-field", true)
3269            .build();
3270        match flush_stop_evt.view() {
3271            EventView::FlushStop(flush_stop_evt) => {
3272                assert!(flush_stop_evt.resets_time());
3273                assert!(flush_stop_evt.structure().is_some());
3274                if let Some(other_fields) = flush_stop_evt.structure() {
3275                    assert!(other_fields.has_field("extra-field"));
3276                }
3277            }
3278            _ => panic!("flush_stop_evt.view() is not an EventView::FlushStop(_)"),
3279        }
3280    }
3281
3282    #[test]
3283    fn test_get_structure_mut() {
3284        crate::init().unwrap();
3285
3286        let mut flush_start_evt = FlushStart::new();
3287
3288        {
3289            let flush_start_evt = flush_start_evt.get_mut().unwrap();
3290            let structure = flush_start_evt.structure_mut();
3291            structure.set("test", 42u32);
3292        }
3293
3294        let structure = flush_start_evt.structure().unwrap();
3295        assert_eq!(structure.get("test"), Ok(42u32));
3296    }
3297
3298    #[test]
3299    fn test_view_lifetimes() {
3300        crate::init().unwrap();
3301
3302        let caps = crate::Caps::builder("some/x-caps").build();
3303        let event = crate::event::Caps::new(&caps);
3304
3305        let caps2 = match event.view() {
3306            EventView::Caps(caps) => caps.caps(),
3307            _ => unreachable!(),
3308        };
3309
3310        assert_eq!(&*caps, caps2);
3311    }
3312
3313    #[test]
3314    fn test_select_streams() {
3315        crate::init().unwrap();
3316
3317        let s = ["foo", "bar"].to_vec();
3318        let event = crate::event::SelectStreams::new(s.iter().copied());
3319        let streams = match event.view() {
3320            EventView::SelectStreams(streams) => streams.streams(),
3321            _ => unreachable!(),
3322        };
3323        assert_eq!(streams.iter().collect::<Vec<_>>(), s);
3324    }
3325}