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