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