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
111impl PartialOrd for EventType {
112 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
113 if !self.is_serialized() || !other.is_serialized() {
114 return None;
115 }
116
117 let fixup_event_ordering = |v| match v {
119 ffi::GST_EVENT_INSTANT_RATE_CHANGE => ffi::GST_EVENT_SEGMENT as u32 + 1,
120 _ => v as u32,
121 };
122
123 let v1 = fixup_event_ordering(self.into_glib());
124 let v2 = fixup_event_ordering(other.into_glib());
125
126 let stream_start = ffi::GST_EVENT_STREAM_START as u32;
127 let segment = ffi::GST_EVENT_SEGMENT as u32;
128 let eos = ffi::GST_EVENT_EOS as u32;
129
130 if v1 >= stream_start && v1 <= segment || v2 >= stream_start && v2 <= segment {
133 Some(v1.cmp(&v2))
134 } else if v1 == eos || v2 == eos {
136 if v1 == v2 {
137 Some(cmp::Ordering::Equal)
138 } else if v1 == eos {
139 Some(cmp::Ordering::Greater)
140 } else {
141 Some(cmp::Ordering::Less)
142 }
143 } else {
144 None
145 }
146 }
147}
148
149mini_object_wrapper!(Event, EventRef, ffi::GstEvent, || {
150 ffi::gst_event_get_type()
151});
152
153impl EventRef {
154 #[doc(alias = "get_seqnum")]
155 #[doc(alias = "gst_event_get_seqnum")]
156 pub fn seqnum(&self) -> Seqnum {
157 unsafe {
158 let seqnum = ffi::gst_event_get_seqnum(self.as_mut_ptr());
159 debug_assert_ne!(seqnum, 0);
160 Seqnum(NonZeroU32::new_unchecked(seqnum))
161 }
162 }
163
164 #[doc(alias = "gst_event_set_seqnum")]
165 pub fn set_seqnum(&mut self, seqnum: Seqnum) {
166 unsafe {
167 ffi::gst_event_set_seqnum(self.as_mut_ptr(), seqnum.0.get());
168 }
169 }
170
171 #[doc(alias = "get_running_time_offset")]
172 #[doc(alias = "gst_event_get_running_time_offset")]
173 pub fn running_time_offset(&self) -> i64 {
174 unsafe { ffi::gst_event_get_running_time_offset(self.as_mut_ptr()) }
175 }
176
177 #[doc(alias = "gst_event_set_running_time_offset")]
178 pub fn set_running_time_offset(&mut self, offset: i64) {
179 unsafe { ffi::gst_event_set_running_time_offset(self.as_mut_ptr(), offset) }
180 }
181
182 #[doc(alias = "get_structure")]
183 #[doc(alias = "gst_event_get_structure")]
184 #[inline]
185 pub fn structure(&self) -> Option<&StructureRef> {
186 unsafe {
187 let structure = ffi::gst_event_get_structure(self.as_mut_ptr());
188 if structure.is_null() {
189 None
190 } else {
191 Some(StructureRef::from_glib_borrow(structure))
192 }
193 }
194 }
195
196 #[doc(alias = "gst_event_writable_structure")]
197 #[inline]
198 pub fn structure_mut(&mut self) -> &mut StructureRef {
199 unsafe {
200 StructureRef::from_glib_borrow_mut(ffi::gst_event_writable_structure(self.as_mut_ptr()))
201 }
202 }
203
204 #[doc(alias = "GST_EVENT_IS_UPSTREAM")]
205 #[inline]
206 pub fn is_upstream(&self) -> bool {
207 self.type_().is_upstream()
208 }
209
210 #[doc(alias = "GST_EVENT_IS_DOWNSTREAM")]
211 #[inline]
212 pub fn is_downstream(&self) -> bool {
213 self.type_().is_downstream()
214 }
215
216 #[doc(alias = "GST_EVENT_IS_SERIALIZED")]
217 #[inline]
218 pub fn is_serialized(&self) -> bool {
219 self.type_().is_serialized()
220 }
221
222 #[doc(alias = "GST_EVENT_IS_STICKY")]
223 #[inline]
224 pub fn is_sticky(&self) -> bool {
225 self.type_().is_sticky()
226 }
227
228 #[doc(alias = "GST_EVENT_IS_STICKY_MULTI")]
229 #[inline]
230 pub fn is_sticky_multi(&self) -> bool {
231 self.type_().is_sticky_multi()
232 }
233
234 #[doc(alias = "get_type")]
235 #[doc(alias = "GST_EVENT_TYPE")]
236 #[inline]
237 pub fn type_(&self) -> EventType {
238 unsafe { from_glib((*self.as_ptr()).type_) }
239 }
240
241 #[doc(alias = "gst_event_has_name")]
242 #[inline]
243 pub fn has_name(&self, name: &str) -> bool {
244 self.structure().is_some_and(|s| s.has_name(name))
245 }
246
247 pub fn view(&self) -> EventView<'_> {
248 unsafe {
249 let type_ = (*self.as_ptr()).type_;
250
251 match type_ {
252 ffi::GST_EVENT_FLUSH_START => FlushStart::view(self),
253 ffi::GST_EVENT_FLUSH_STOP => FlushStop::view(self),
254 ffi::GST_EVENT_STREAM_START => StreamStart::view(self),
255 ffi::GST_EVENT_CAPS => Caps::view(self),
256 ffi::GST_EVENT_SEGMENT => Segment::view(self),
257 ffi::GST_EVENT_STREAM_COLLECTION => StreamCollection::view(self),
258 ffi::GST_EVENT_TAG => Tag::view(self),
259 ffi::GST_EVENT_BUFFERSIZE => Buffersize::view(self),
260 ffi::GST_EVENT_SINK_MESSAGE => SinkMessage::view(self),
261 ffi::GST_EVENT_STREAM_GROUP_DONE => StreamGroupDone::view(self),
262 ffi::GST_EVENT_EOS => Eos::view(self),
263 ffi::GST_EVENT_TOC => Toc::view(self),
264 ffi::GST_EVENT_PROTECTION => Protection::view(self),
265 ffi::GST_EVENT_SEGMENT_DONE => SegmentDone::view(self),
266 ffi::GST_EVENT_GAP => Gap::view(self),
267 #[cfg(feature = "v1_18")]
268 ffi::GST_EVENT_INSTANT_RATE_CHANGE => InstantRateChange::view(self),
269 ffi::GST_EVENT_QOS => Qos::view(self),
270 ffi::GST_EVENT_SEEK => Seek::view(self),
271 ffi::GST_EVENT_NAVIGATION => Navigation::view(self),
272 ffi::GST_EVENT_LATENCY => Latency::view(self),
273 ffi::GST_EVENT_STEP => Step::view(self),
274 ffi::GST_EVENT_RECONFIGURE => Reconfigure::view(self),
275 ffi::GST_EVENT_TOC_SELECT => TocSelect::view(self),
276 ffi::GST_EVENT_SELECT_STREAMS => SelectStreams::view(self),
277 #[cfg(feature = "v1_18")]
278 ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => InstantRateSyncTime::view(self),
279 ffi::GST_EVENT_CUSTOM_UPSTREAM => CustomUpstream::view(self),
280 ffi::GST_EVENT_CUSTOM_DOWNSTREAM => CustomDownstream::view(self),
281 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => CustomDownstreamOob::view(self),
282 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => CustomDownstreamSticky::view(self),
283 ffi::GST_EVENT_CUSTOM_BOTH => CustomBoth::view(self),
284 ffi::GST_EVENT_CUSTOM_BOTH_OOB => CustomBothOob::view(self),
285 _ => Other::view(self),
286 }
287 }
288 }
289
290 pub fn view_mut(&mut self) -> EventViewMut<'_> {
291 unsafe {
292 let type_ = (*self.as_ptr()).type_;
293
294 match type_ {
295 ffi::GST_EVENT_FLUSH_START => FlushStart::view_mut(self),
296 ffi::GST_EVENT_FLUSH_STOP => FlushStop::view_mut(self),
297 ffi::GST_EVENT_STREAM_START => StreamStart::view_mut(self),
298 ffi::GST_EVENT_CAPS => Caps::view_mut(self),
299 ffi::GST_EVENT_SEGMENT => Segment::view_mut(self),
300 ffi::GST_EVENT_STREAM_COLLECTION => StreamCollection::view_mut(self),
301 ffi::GST_EVENT_TAG => Tag::view_mut(self),
302 ffi::GST_EVENT_BUFFERSIZE => Buffersize::view_mut(self),
303 ffi::GST_EVENT_SINK_MESSAGE => SinkMessage::view_mut(self),
304 ffi::GST_EVENT_STREAM_GROUP_DONE => StreamGroupDone::view_mut(self),
305 ffi::GST_EVENT_EOS => Eos::view_mut(self),
306 ffi::GST_EVENT_TOC => Toc::view_mut(self),
307 ffi::GST_EVENT_PROTECTION => Protection::view_mut(self),
308 ffi::GST_EVENT_SEGMENT_DONE => SegmentDone::view_mut(self),
309 ffi::GST_EVENT_GAP => Gap::view_mut(self),
310 #[cfg(feature = "v1_18")]
311 ffi::GST_EVENT_INSTANT_RATE_CHANGE => InstantRateChange::view_mut(self),
312 ffi::GST_EVENT_QOS => Qos::view_mut(self),
313 ffi::GST_EVENT_SEEK => Seek::view_mut(self),
314 ffi::GST_EVENT_NAVIGATION => Navigation::view_mut(self),
315 ffi::GST_EVENT_LATENCY => Latency::view_mut(self),
316 ffi::GST_EVENT_STEP => Step::view_mut(self),
317 ffi::GST_EVENT_RECONFIGURE => Reconfigure::view_mut(self),
318 ffi::GST_EVENT_TOC_SELECT => TocSelect::view_mut(self),
319 ffi::GST_EVENT_SELECT_STREAMS => SelectStreams::view_mut(self),
320 #[cfg(feature = "v1_18")]
321 ffi::GST_EVENT_INSTANT_RATE_SYNC_TIME => InstantRateSyncTime::view_mut(self),
322 ffi::GST_EVENT_CUSTOM_UPSTREAM => CustomUpstream::view_mut(self),
323 ffi::GST_EVENT_CUSTOM_DOWNSTREAM => CustomDownstream::view_mut(self),
324 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB => CustomDownstreamOob::view_mut(self),
325 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY => CustomDownstreamSticky::view_mut(self),
326 ffi::GST_EVENT_CUSTOM_BOTH => CustomBoth::view_mut(self),
327 ffi::GST_EVENT_CUSTOM_BOTH_OOB => CustomBothOob::view_mut(self),
328 _ => Other::view_mut(self),
329 }
330 }
331 }
332}
333
334impl fmt::Debug for Event {
335 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
336 EventRef::fmt(self, f)
337 }
338}
339
340impl fmt::Debug for EventRef {
341 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
342 f.debug_struct("Event")
343 .field("ptr", &self.as_ptr())
344 .field("type", &self.type_().name())
345 .field("seqnum", &self.seqnum())
346 .field("structure", &self.structure())
347 .finish()
348 }
349}
350
351pub trait StickyEventType: ToOwned {
352 const TYPE: EventType;
353
354 unsafe fn from_event(event: Event) -> Self::Owned;
355}
356
357#[derive(Debug)]
358#[non_exhaustive]
359pub enum EventView<'a> {
360 FlushStart(&'a FlushStart),
361 FlushStop(&'a FlushStop),
362 StreamStart(&'a StreamStart),
363 Caps(&'a Caps),
364 Segment(&'a Segment),
365 StreamCollection(&'a StreamCollection),
366 Tag(&'a Tag),
367 Buffersize(&'a Buffersize),
368 SinkMessage(&'a SinkMessage),
369 StreamGroupDone(&'a StreamGroupDone),
370 Eos(&'a Eos),
371 Toc(&'a Toc),
372 Protection(&'a Protection),
373 SegmentDone(&'a SegmentDone),
374 Gap(&'a Gap),
375 #[cfg(feature = "v1_18")]
376 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
377 InstantRateChange(&'a InstantRateChange),
378 Qos(&'a Qos),
379 Seek(&'a Seek),
380 Navigation(&'a Navigation),
381 Latency(&'a Latency),
382 Step(&'a Step),
383 Reconfigure(&'a Reconfigure),
384 TocSelect(&'a TocSelect),
385 SelectStreams(&'a SelectStreams),
386 #[cfg(feature = "v1_18")]
387 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
388 InstantRateSyncTime(&'a InstantRateSyncTime),
389 CustomUpstream(&'a CustomUpstream),
390 CustomDownstream(&'a CustomDownstream),
391 CustomDownstreamOob(&'a CustomDownstreamOob),
392 CustomDownstreamSticky(&'a CustomDownstreamSticky),
393 CustomBoth(&'a CustomBoth),
394 CustomBothOob(&'a CustomBothOob),
395 Other(&'a Other),
396}
397
398#[derive(Debug)]
399#[non_exhaustive]
400pub enum EventViewMut<'a> {
401 FlushStart(&'a mut FlushStart),
402 FlushStop(&'a mut FlushStop),
403 StreamStart(&'a mut StreamStart),
404 Caps(&'a mut Caps),
405 Segment(&'a mut Segment),
406 StreamCollection(&'a mut StreamCollection),
407 Tag(&'a mut Tag),
408 Buffersize(&'a mut Buffersize),
409 SinkMessage(&'a mut SinkMessage),
410 StreamGroupDone(&'a mut StreamGroupDone),
411 Eos(&'a mut Eos),
412 Toc(&'a mut Toc),
413 Protection(&'a mut Protection),
414 SegmentDone(&'a mut SegmentDone),
415 Gap(&'a mut Gap),
416 #[cfg(feature = "v1_18")]
417 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
418 InstantRateChange(&'a mut InstantRateChange),
419 Qos(&'a mut Qos),
420 Seek(&'a mut Seek),
421 Navigation(&'a mut Navigation),
422 Latency(&'a mut Latency),
423 Step(&'a mut Step),
424 Reconfigure(&'a mut Reconfigure),
425 TocSelect(&'a mut TocSelect),
426 SelectStreams(&'a mut SelectStreams),
427 #[cfg(feature = "v1_18")]
428 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
429 InstantRateSyncTime(&'a mut InstantRateSyncTime),
430 CustomUpstream(&'a mut CustomUpstream),
431 CustomDownstream(&'a mut CustomDownstream),
432 CustomDownstreamOob(&'a mut CustomDownstreamOob),
433 CustomDownstreamSticky(&'a mut CustomDownstreamSticky),
434 CustomBoth(&'a mut CustomBoth),
435 CustomBothOob(&'a mut CustomBothOob),
436 Other(&'a mut Other),
437}
438
439macro_rules! declare_concrete_event {
440 (@sticky $name:ident, $param:ident) => {
441 declare_concrete_event!($name, $param);
442
443 impl StickyEventType for $name {
444 const TYPE: EventType = EventType::$name;
445
446 #[inline]
447 unsafe fn from_event(event: Event) -> Self::Owned {
448 $name::<Event>(event)
449 }
450 }
451 };
452 ($name:ident, $param:ident) => {
453 #[repr(transparent)]
454 pub struct $name<$param = EventRef>($param);
455
456 impl $name {
457 #[inline]
458 pub fn event(&self) -> &EventRef {
459 unsafe { &*(self as *const Self as *const EventRef) }
460 }
461
462 #[inline]
463 pub fn event_mut(&mut self) -> &mut EventRef {
464 unsafe { &mut *(self as *mut Self as *mut EventRef) }
465 }
466
467 #[inline]
468 unsafe fn view(event: &EventRef) -> EventView<'_> {
469 unsafe {
470 let event = &*(event as *const EventRef as *const Self);
471 EventView::$name(event)
472 }
473 }
474
475 #[inline]
476 unsafe fn view_mut(event: &mut EventRef) -> EventViewMut<'_> {
477 unsafe {
478 let event = &mut *(event as *mut EventRef as *mut Self);
479 EventViewMut::$name(event)
480 }
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 #[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", ×tamp)
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", ×tamp)
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<'a>(streams: impl IntoIterator<Item = &'a str>) -> Event {
1846 skip_assert_initialized!();
1847 Self::builder(streams).build()
1848 }
1849
1850 pub fn builder<'a>(streams: impl IntoIterator<Item = &'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) -> glib::collections::List<glib::GStringPtr> {
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 glib::collections::List::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 struct StreamsDebug<'a>(&'a SelectStreams);
1873
1874 impl std::fmt::Debug for StreamsDebug<'_> {
1875 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1876 f.debug_list().entries(self.0.streams()).finish()
1877 }
1878 }
1879
1880 f.debug_struct("SelectStreams")
1881 .field("seqnum", &self.event().seqnum())
1882 .field("running-time-offset", &self.event().running_time_offset())
1883 .field("structure", &self.event().structure())
1884 .field("streams", &StreamsDebug(self))
1885 .finish()
1886 }
1887}
1888
1889impl std::fmt::Debug for SelectStreams<Event> {
1890 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1891 SelectStreams::<EventRef>::fmt(self, f)
1892 }
1893}
1894
1895#[cfg(feature = "v1_18")]
1896#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1897declare_concrete_event!(InstantRateSyncTime, T);
1898#[cfg(feature = "v1_18")]
1899#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1900impl InstantRateSyncTime<Event> {
1901 #[doc(alias = "gst_event_new_instant_rate_sync_time")]
1902 #[allow(clippy::new_ret_no_self)]
1903 pub fn new(
1904 rate_multiplier: f64,
1905 running_time: ClockTime,
1906 upstream_running_time: ClockTime,
1907 ) -> Event {
1908 skip_assert_initialized!();
1909 Self::builder(rate_multiplier, running_time, upstream_running_time).build()
1910 }
1911
1912 pub fn builder<'a>(
1913 rate_multiplier: f64,
1914 running_time: ClockTime,
1915 upstream_running_time: ClockTime,
1916 ) -> InstantRateSyncTimeBuilder<'a> {
1917 assert_initialized_main_thread!();
1918 InstantRateSyncTimeBuilder::new(rate_multiplier, running_time, upstream_running_time)
1919 }
1920}
1921
1922#[cfg(feature = "v1_18")]
1923#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
1924impl InstantRateSyncTime {
1925 #[doc(alias = "parse_instant_rate_sync_time")]
1926 #[doc(alias = "gst_event_parse_instant_rate_sync_time")]
1927 pub fn get(&self) -> (f64, ClockTime, ClockTime) {
1928 unsafe {
1929 let mut rate_multiplier = mem::MaybeUninit::uninit();
1930 let mut running_time = mem::MaybeUninit::uninit();
1931 let mut upstream_running_time = mem::MaybeUninit::uninit();
1932
1933 ffi::gst_event_parse_instant_rate_sync_time(
1934 self.as_mut_ptr(),
1935 rate_multiplier.as_mut_ptr(),
1936 running_time.as_mut_ptr(),
1937 upstream_running_time.as_mut_ptr(),
1938 );
1939
1940 (
1941 rate_multiplier.assume_init(),
1942 try_from_glib(running_time.assume_init()).expect("undefined timestamp"),
1943 try_from_glib(upstream_running_time.assume_init()).expect("undefined timestamp"),
1944 )
1945 }
1946 }
1947}
1948
1949#[cfg(feature = "v1_18")]
1950impl std::fmt::Debug for InstantRateSyncTime {
1951 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1952 let (rate_multiplier, running_time, upstream_running_time) = self.get();
1953 f.debug_struct("InstantRateSyncTime")
1954 .field("seqnum", &self.event().seqnum())
1955 .field("running-time-offset", &self.event().running_time_offset())
1956 .field("structure", &self.event().structure())
1957 .field("rate-multiplier", &rate_multiplier)
1958 .field("running-time", &running_time)
1959 .field("upstream-running-time", &upstream_running_time)
1960 .finish()
1961 }
1962}
1963
1964#[cfg(feature = "v1_18")]
1965impl std::fmt::Debug for InstantRateSyncTime<Event> {
1966 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1967 InstantRateSyncTime::<EventRef>::fmt(self, f)
1968 }
1969}
1970
1971declare_concrete_event!(CustomUpstream, T);
1972impl CustomUpstream<Event> {
1973 #[doc(alias = "gst_event_new_custom")]
1974 #[allow(clippy::new_ret_no_self)]
1975 pub fn new(structure: crate::Structure) -> Event {
1976 skip_assert_initialized!();
1977 Self::builder(structure).build()
1978 }
1979
1980 pub fn builder<'a>(structure: crate::Structure) -> CustomUpstreamBuilder<'a> {
1981 assert_initialized_main_thread!();
1982 CustomUpstreamBuilder::new(structure)
1983 }
1984}
1985
1986impl std::fmt::Debug for CustomUpstream {
1987 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1988 f.debug_struct("CustomUpstream")
1989 .field("seqnum", &self.event().seqnum())
1990 .field("running-time-offset", &self.event().running_time_offset())
1991 .field("structure", &self.event().structure())
1992 .finish()
1993 }
1994}
1995
1996impl std::fmt::Debug for CustomUpstream<Event> {
1997 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1998 CustomUpstream::<EventRef>::fmt(self, f)
1999 }
2000}
2001
2002declare_concrete_event!(CustomDownstream, T);
2003impl CustomDownstream<Event> {
2004 #[doc(alias = "gst_event_new_custom")]
2005 #[allow(clippy::new_ret_no_self)]
2006 pub fn new(structure: crate::Structure) -> Event {
2007 skip_assert_initialized!();
2008 Self::builder(structure).build()
2009 }
2010
2011 pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamBuilder<'a> {
2012 assert_initialized_main_thread!();
2013 CustomDownstreamBuilder::new(structure)
2014 }
2015}
2016
2017impl std::fmt::Debug for CustomDownstream {
2018 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2019 f.debug_struct("CustomDownstream")
2020 .field("seqnum", &self.event().seqnum())
2021 .field("running-time-offset", &self.event().running_time_offset())
2022 .field("structure", &self.event().structure())
2023 .finish()
2024 }
2025}
2026
2027impl std::fmt::Debug for CustomDownstream<Event> {
2028 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2029 CustomDownstream::<EventRef>::fmt(self, f)
2030 }
2031}
2032
2033declare_concrete_event!(CustomDownstreamOob, T);
2034impl CustomDownstreamOob<Event> {
2035 #[doc(alias = "gst_event_new_custom")]
2036 #[allow(clippy::new_ret_no_self)]
2037 pub fn new(structure: crate::Structure) -> Event {
2038 skip_assert_initialized!();
2039 Self::builder(structure).build()
2040 }
2041
2042 pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamOobBuilder<'a> {
2043 assert_initialized_main_thread!();
2044 CustomDownstreamOobBuilder::new(structure)
2045 }
2046}
2047
2048impl std::fmt::Debug for CustomDownstreamOob {
2049 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2050 f.debug_struct("CustomDownstreamOob")
2051 .field("seqnum", &self.event().seqnum())
2052 .field("running-time-offset", &self.event().running_time_offset())
2053 .field("structure", &self.event().structure())
2054 .finish()
2055 }
2056}
2057
2058impl std::fmt::Debug for CustomDownstreamOob<Event> {
2059 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2060 CustomDownstreamOob::<EventRef>::fmt(self, f)
2061 }
2062}
2063
2064declare_concrete_event!(@sticky CustomDownstreamSticky, T);
2065impl CustomDownstreamSticky<Event> {
2066 #[doc(alias = "gst_event_new_custom")]
2067 #[allow(clippy::new_ret_no_self)]
2068 pub fn new(structure: crate::Structure) -> Event {
2069 skip_assert_initialized!();
2070 Self::builder(structure).build()
2071 }
2072
2073 pub fn builder<'a>(structure: crate::Structure) -> CustomDownstreamStickyBuilder<'a> {
2074 assert_initialized_main_thread!();
2075 CustomDownstreamStickyBuilder::new(structure)
2076 }
2077}
2078
2079impl std::fmt::Debug for CustomDownstreamSticky {
2080 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2081 f.debug_struct("CustomDownstreamSticky")
2082 .field("seqnum", &self.event().seqnum())
2083 .field("running-time-offset", &self.event().running_time_offset())
2084 .field("structure", &self.event().structure())
2085 .finish()
2086 }
2087}
2088
2089impl std::fmt::Debug for CustomDownstreamSticky<Event> {
2090 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2091 CustomDownstreamSticky::<EventRef>::fmt(self, f)
2092 }
2093}
2094
2095declare_concrete_event!(CustomBoth, T);
2096impl CustomBoth<Event> {
2097 #[doc(alias = "gst_event_new_custom")]
2098 #[allow(clippy::new_ret_no_self)]
2099 pub fn new(structure: crate::Structure) -> Event {
2100 skip_assert_initialized!();
2101 Self::builder(structure).build()
2102 }
2103
2104 pub fn builder<'a>(structure: crate::Structure) -> CustomBothBuilder<'a> {
2105 assert_initialized_main_thread!();
2106 CustomBothBuilder::new(structure)
2107 }
2108}
2109
2110impl std::fmt::Debug for CustomBoth {
2111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2112 f.debug_struct("CustomBoth")
2113 .field("seqnum", &self.event().seqnum())
2114 .field("running-time-offset", &self.event().running_time_offset())
2115 .field("structure", &self.event().structure())
2116 .finish()
2117 }
2118}
2119
2120impl std::fmt::Debug for CustomBoth<Event> {
2121 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2122 CustomBoth::<EventRef>::fmt(self, f)
2123 }
2124}
2125
2126declare_concrete_event!(CustomBothOob, T);
2127impl CustomBothOob<Event> {
2128 #[doc(alias = "gst_event_new_custom")]
2129 #[allow(clippy::new_ret_no_self)]
2130 pub fn new(structure: crate::Structure) -> Event {
2131 skip_assert_initialized!();
2132 Self::builder(structure).build()
2133 }
2134
2135 pub fn builder<'a>(structure: crate::Structure) -> CustomBothOobBuilder<'a> {
2136 assert_initialized_main_thread!();
2137 CustomBothOobBuilder::new(structure)
2138 }
2139}
2140
2141impl std::fmt::Debug for CustomBothOob {
2142 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2143 f.debug_struct("CustomBothOob")
2144 .field("seqnum", &self.event().seqnum())
2145 .field("running-time-offset", &self.event().running_time_offset())
2146 .field("structure", &self.event().structure())
2147 .finish()
2148 }
2149}
2150
2151impl std::fmt::Debug for CustomBothOob<Event> {
2152 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2153 CustomBothOob::<EventRef>::fmt(self, f)
2154 }
2155}
2156
2157declare_concrete_event!(Other, T);
2158
2159impl std::fmt::Debug for Other {
2160 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2161 f.debug_struct("Other")
2162 .field("seqnum", &self.event().seqnum())
2163 .field("running-time-offset", &self.event().running_time_offset())
2164 .field("structure", &self.event().structure())
2165 .finish()
2166 }
2167}
2168
2169impl std::fmt::Debug for Other<Event> {
2170 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2171 Other::<EventRef>::fmt(self, f)
2172 }
2173}
2174
2175struct EventBuilder<'a> {
2176 seqnum: Option<Seqnum>,
2177 running_time_offset: Option<i64>,
2178 other_fields: Vec<(&'a str, glib::SendValue)>,
2179}
2180
2181impl<'a> EventBuilder<'a> {
2182 fn new() -> Self {
2183 Self {
2184 seqnum: None,
2185 running_time_offset: None,
2186 other_fields: Vec::new(),
2187 }
2188 }
2189
2190 fn seqnum(self, seqnum: Seqnum) -> Self {
2191 Self {
2192 seqnum: Some(seqnum),
2193 ..self
2194 }
2195 }
2196
2197 fn running_time_offset(self, running_time_offset: i64) -> Self {
2198 Self {
2199 running_time_offset: Some(running_time_offset),
2200 ..self
2201 }
2202 }
2203
2204 fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self {
2205 let mut other_fields = self.other_fields;
2206 other_fields.push((name, value.to_send_value()));
2207
2208 Self {
2209 other_fields,
2210 ..self
2211 }
2212 }
2213}
2214
2215macro_rules! event_builder_generic_impl {
2216 ($new_fn:expr) => {
2217 #[doc(alias = "gst_event_set_seqnum")]
2218 #[allow(clippy::needless_update)]
2219 pub fn seqnum(self, seqnum: Seqnum) -> Self {
2220 Self {
2221 builder: self.builder.seqnum(seqnum),
2222 ..self
2223 }
2224 }
2225
2226 #[doc(alias = "gst_event_set_seqnum")]
2227 #[allow(clippy::needless_update)]
2228 pub fn seqnum_if(self, seqnum: Seqnum, predicate: bool) -> Self {
2229 if predicate { self.seqnum(seqnum) } else { self }
2230 }
2231
2232 #[doc(alias = "gst_event_set_seqnum")]
2233 #[allow(clippy::needless_update)]
2234 pub fn seqnum_if_some(self, seqnum: Option<Seqnum>) -> Self {
2235 if let Some(seqnum) = seqnum {
2236 self.seqnum(seqnum)
2237 } else {
2238 self
2239 }
2240 }
2241
2242 #[doc(alias = "gst_event_set_running_time_offset")]
2243 #[allow(clippy::needless_update)]
2244 pub fn running_time_offset(self, running_time_offset: i64) -> Self {
2245 Self {
2246 builder: self.builder.running_time_offset(running_time_offset),
2247 ..self
2248 }
2249 }
2250
2251 #[doc(alias = "gst_event_set_running_time_offset")]
2252 #[allow(clippy::needless_update)]
2253 pub fn running_time_offset_if(self, running_time_offset: i64, predicate: bool) -> Self {
2254 if predicate {
2255 self.running_time_offset(running_time_offset)
2256 } else {
2257 self
2258 }
2259 }
2260
2261 #[doc(alias = "gst_event_set_running_time_offset")]
2262 #[allow(clippy::needless_update)]
2263 pub fn running_time_offset_if_some(self, running_time_offset: Option<i64>) -> Self {
2264 if let Some(running_time_offset) = running_time_offset {
2265 self.running_time_offset(running_time_offset)
2266 } else {
2267 self
2268 }
2269 }
2270
2271 #[allow(clippy::needless_update)]
2276 pub fn other_field(self, name: &'a str, value: impl ToSendValue) -> Self {
2277 Self {
2278 builder: self.builder.other_field(name, value),
2279 ..self
2280 }
2281 }
2282
2283 impl_builder_gvalue_extra_setters!(other_field);
2284
2285 #[must_use = "Building the event without using it has no effect"]
2286 #[allow(clippy::redundant_closure_call)]
2287 pub fn build(mut self) -> Event {
2288 unsafe {
2289 let event = $new_fn(&mut self);
2290 if let Some(seqnum) = self.builder.seqnum {
2291 ffi::gst_event_set_seqnum(event, seqnum.0.get());
2292 }
2293
2294 if let Some(running_time_offset) = self.builder.running_time_offset {
2295 ffi::gst_event_set_running_time_offset(event, running_time_offset);
2296 }
2297
2298 if !self.builder.other_fields.is_empty() {
2299 let s = StructureRef::from_glib_borrow_mut(ffi::gst_event_writable_structure(
2300 event,
2301 ));
2302
2303 for (k, v) in self.builder.other_fields {
2304 s.set_value(k, v);
2305 }
2306 }
2307
2308 from_glib_full(event)
2309 }
2310 }
2311 };
2312}
2313
2314#[must_use = "The builder must be built to be used"]
2315pub struct FlushStartBuilder<'a> {
2316 builder: EventBuilder<'a>,
2317}
2318
2319impl<'a> FlushStartBuilder<'a> {
2320 fn new() -> Self {
2321 skip_assert_initialized!();
2322 Self {
2323 builder: EventBuilder::new(),
2324 }
2325 }
2326
2327 event_builder_generic_impl!(|_| { ffi::gst_event_new_flush_start() });
2328}
2329
2330#[must_use = "The builder must be built to be used"]
2331pub struct FlushStopBuilder<'a> {
2332 builder: EventBuilder<'a>,
2333 reset_time: bool,
2334}
2335impl<'a> FlushStopBuilder<'a> {
2336 fn new(reset_time: bool) -> Self {
2337 skip_assert_initialized!();
2338 Self {
2339 builder: EventBuilder::new(),
2340 reset_time,
2341 }
2342 }
2343
2344 event_builder_generic_impl!(|s: &Self| {
2345 ffi::gst_event_new_flush_stop(s.reset_time.into_glib())
2346 });
2347}
2348
2349#[must_use = "The builder must be built to be used"]
2350pub struct StreamStartBuilder<'a> {
2351 builder: EventBuilder<'a>,
2352 stream_id: &'a str,
2353 flags: Option<crate::StreamFlags>,
2354 group_id: Option<GroupId>,
2355 stream: Option<crate::Stream>,
2356}
2357
2358impl<'a> StreamStartBuilder<'a> {
2359 fn new(stream_id: &'a str) -> Self {
2360 skip_assert_initialized!();
2361 Self {
2362 builder: EventBuilder::new(),
2363 stream_id,
2364 flags: None,
2365 group_id: None,
2366 stream: None,
2367 }
2368 }
2369
2370 pub fn flags(self, flags: crate::StreamFlags) -> Self {
2371 Self {
2372 flags: Some(flags),
2373 ..self
2374 }
2375 }
2376
2377 pub fn flags_if(self, flags: crate::StreamFlags, predicate: bool) -> Self {
2378 if predicate { self.flags(flags) } else { self }
2379 }
2380
2381 pub fn flags_if_some(self, flags: Option<crate::StreamFlags>) -> Self {
2382 if let Some(flags) = flags {
2383 self.flags(flags)
2384 } else {
2385 self
2386 }
2387 }
2388
2389 pub fn group_id(self, group_id: GroupId) -> Self {
2390 Self {
2391 group_id: Some(group_id),
2392 ..self
2393 }
2394 }
2395
2396 pub fn group_id_if(self, group_id: GroupId, predicate: bool) -> Self {
2397 if predicate {
2398 self.group_id(group_id)
2399 } else {
2400 self
2401 }
2402 }
2403
2404 pub fn group_id_if_some(self, group_id: Option<GroupId>) -> Self {
2405 if let Some(group_id) = group_id {
2406 self.group_id(group_id)
2407 } else {
2408 self
2409 }
2410 }
2411
2412 pub fn stream(self, stream: crate::Stream) -> Self {
2413 Self {
2414 stream: Some(stream),
2415 ..self
2416 }
2417 }
2418
2419 pub fn stream_if(self, stream: crate::Stream, predicate: bool) -> Self {
2420 if predicate { self.stream(stream) } else { self }
2421 }
2422
2423 pub fn stream_if_some(self, stream: Option<crate::Stream>) -> Self {
2424 if let Some(stream) = stream {
2425 self.stream(stream)
2426 } else {
2427 self
2428 }
2429 }
2430
2431 event_builder_generic_impl!(|s: &Self| {
2432 let ev = ffi::gst_event_new_stream_start(s.stream_id.to_glib_none().0);
2433 if let Some(flags) = s.flags {
2434 ffi::gst_event_set_stream_flags(ev, flags.into_glib());
2435 }
2436 if let Some(group_id) = s.group_id {
2437 ffi::gst_event_set_group_id(ev, group_id.0.get());
2438 }
2439
2440 if let Some(ref stream) = s.stream {
2441 ffi::gst_event_set_stream(ev, stream.to_glib_none().0);
2442 }
2443
2444 ev
2445 });
2446}
2447
2448#[must_use = "The builder must be built to be used"]
2449pub struct CapsBuilder<'a> {
2450 builder: EventBuilder<'a>,
2451 caps: &'a crate::Caps,
2452}
2453
2454impl<'a> CapsBuilder<'a> {
2455 fn new(caps: &'a crate::Caps) -> Self {
2456 skip_assert_initialized!();
2457 Self {
2458 builder: EventBuilder::new(),
2459 caps,
2460 }
2461 }
2462
2463 event_builder_generic_impl!(|s: &Self| { ffi::gst_event_new_caps(s.caps.as_mut_ptr()) });
2464}
2465
2466#[must_use = "The builder must be built to be used"]
2467pub struct SegmentBuilder<'a> {
2468 builder: EventBuilder<'a>,
2469 segment: &'a crate::Segment,
2470}
2471
2472impl<'a> SegmentBuilder<'a> {
2473 fn new(segment: &'a crate::Segment) -> Self {
2474 skip_assert_initialized!();
2475 Self {
2476 builder: EventBuilder::new(),
2477 segment,
2478 }
2479 }
2480
2481 event_builder_generic_impl!(|s: &Self| {
2482 ffi::gst_event_new_segment(s.segment.to_glib_none().0)
2483 });
2484}
2485
2486#[must_use = "The builder must be built to be used"]
2487pub struct StreamCollectionBuilder<'a> {
2488 builder: EventBuilder<'a>,
2489 stream_collection: &'a crate::StreamCollection,
2490}
2491
2492impl<'a> StreamCollectionBuilder<'a> {
2493 fn new(stream_collection: &'a crate::StreamCollection) -> Self {
2494 skip_assert_initialized!();
2495 Self {
2496 builder: EventBuilder::new(),
2497 stream_collection,
2498 }
2499 }
2500
2501 event_builder_generic_impl!(|s: &Self| {
2502 ffi::gst_event_new_stream_collection(s.stream_collection.to_glib_none().0)
2503 });
2504}
2505
2506#[cfg(feature = "v1_18")]
2507#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2508#[must_use = "The builder must be built to be used"]
2509pub struct InstantRateSyncTimeBuilder<'a> {
2510 builder: EventBuilder<'a>,
2511 rate_multiplier: f64,
2512 running_time: ClockTime,
2513 upstream_running_time: ClockTime,
2514}
2515
2516#[cfg(feature = "v1_18")]
2517#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2518impl<'a> InstantRateSyncTimeBuilder<'a> {
2519 fn new(
2520 rate_multiplier: f64,
2521 running_time: ClockTime,
2522 upstream_running_time: ClockTime,
2523 ) -> Self {
2524 skip_assert_initialized!();
2525 Self {
2526 builder: EventBuilder::new(),
2527 rate_multiplier,
2528 running_time,
2529 upstream_running_time,
2530 }
2531 }
2532
2533 event_builder_generic_impl!(|s: &Self| {
2534 ffi::gst_event_new_instant_rate_sync_time(
2535 s.rate_multiplier,
2536 s.running_time.into_glib(),
2537 s.upstream_running_time.into_glib(),
2538 )
2539 });
2540}
2541
2542#[must_use = "The builder must be built to be used"]
2543pub struct TagBuilder<'a> {
2544 builder: EventBuilder<'a>,
2545 tags: Option<crate::TagList>,
2546}
2547
2548impl<'a> TagBuilder<'a> {
2549 fn new(tags: crate::TagList) -> Self {
2550 skip_assert_initialized!();
2551 Self {
2552 builder: EventBuilder::new(),
2553 tags: Some(tags),
2554 }
2555 }
2556
2557 event_builder_generic_impl!(|s: &mut Self| {
2558 let tags = s.tags.take().unwrap();
2559 ffi::gst_event_new_tag(tags.into_glib_ptr())
2560 });
2561}
2562
2563#[must_use = "The builder must be built to be used"]
2564pub struct BuffersizeBuilder<'a> {
2565 builder: EventBuilder<'a>,
2566 minsize: GenericFormattedValue,
2567 maxsize: GenericFormattedValue,
2568 r#async: bool,
2569}
2570
2571impl<'a> BuffersizeBuilder<'a> {
2572 fn new(minsize: GenericFormattedValue, maxsize: GenericFormattedValue, r#async: bool) -> Self {
2573 skip_assert_initialized!();
2574 Self {
2575 builder: EventBuilder::new(),
2576 minsize,
2577 maxsize,
2578 r#async,
2579 }
2580 }
2581
2582 event_builder_generic_impl!(|s: &Self| {
2583 ffi::gst_event_new_buffer_size(
2584 s.minsize.format().into_glib(),
2585 s.minsize.value(),
2586 s.maxsize.value(),
2587 s.r#async.into_glib(),
2588 )
2589 });
2590}
2591
2592#[must_use = "The builder must be built to be used"]
2593pub struct SinkMessageBuilder<'a> {
2594 builder: EventBuilder<'a>,
2595 name: &'a str,
2596 msg: &'a crate::Message,
2597}
2598
2599impl<'a> SinkMessageBuilder<'a> {
2600 fn new(name: &'a str, msg: &'a crate::Message) -> Self {
2601 skip_assert_initialized!();
2602 Self {
2603 builder: EventBuilder::new(),
2604 name,
2605 msg,
2606 }
2607 }
2608
2609 event_builder_generic_impl!(|s: &Self| {
2610 ffi::gst_event_new_sink_message(s.name.to_glib_none().0, s.msg.as_mut_ptr())
2611 });
2612}
2613
2614#[must_use = "The builder must be built to be used"]
2615pub struct StreamGroupDoneBuilder<'a> {
2616 builder: EventBuilder<'a>,
2617 group_id: GroupId,
2618}
2619
2620impl<'a> StreamGroupDoneBuilder<'a> {
2621 fn new(group_id: GroupId) -> Self {
2622 skip_assert_initialized!();
2623 Self {
2624 builder: EventBuilder::new(),
2625 group_id,
2626 }
2627 }
2628
2629 event_builder_generic_impl!(|s: &Self| {
2630 ffi::gst_event_new_stream_group_done(s.group_id.0.get())
2631 });
2632}
2633
2634#[must_use = "The builder must be built to be used"]
2635pub struct EosBuilder<'a> {
2636 builder: EventBuilder<'a>,
2637}
2638
2639impl<'a> EosBuilder<'a> {
2640 fn new() -> Self {
2641 skip_assert_initialized!();
2642 Self {
2643 builder: EventBuilder::new(),
2644 }
2645 }
2646
2647 event_builder_generic_impl!(|_| ffi::gst_event_new_eos());
2648}
2649
2650#[must_use = "The builder must be built to be used"]
2651pub struct TocBuilder<'a> {
2652 builder: EventBuilder<'a>,
2653 toc: &'a crate::Toc,
2654 updated: bool,
2655}
2656
2657impl<'a> TocBuilder<'a> {
2658 fn new(toc: &'a crate::Toc, updated: bool) -> Self {
2659 skip_assert_initialized!();
2660 Self {
2661 builder: EventBuilder::new(),
2662 toc,
2663 updated,
2664 }
2665 }
2666
2667 event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_toc(
2668 s.toc.to_glib_none().0,
2669 s.updated.into_glib()
2670 ));
2671}
2672
2673#[must_use = "The builder must be built to be used"]
2674pub struct ProtectionBuilder<'a> {
2675 builder: EventBuilder<'a>,
2676 system_id: &'a str,
2677 data: &'a crate::Buffer,
2678 origin: Option<&'a str>,
2679}
2680
2681impl<'a> ProtectionBuilder<'a> {
2682 fn new(system_id: &'a str, data: &'a crate::Buffer) -> Self {
2683 skip_assert_initialized!();
2684 Self {
2685 builder: EventBuilder::new(),
2686 system_id,
2687 data,
2688 origin: None,
2689 }
2690 }
2691
2692 pub fn origin(self, origin: &'a str) -> Self {
2693 Self {
2694 origin: Some(origin),
2695 ..self
2696 }
2697 }
2698
2699 pub fn origin_if(self, origin: &'a str, predicate: bool) -> Self {
2700 if predicate { self.origin(origin) } else { self }
2701 }
2702
2703 pub fn origin_if_some(self, origin: Option<&'a str>) -> Self {
2704 if let Some(origin) = origin {
2705 self.origin(origin)
2706 } else {
2707 self
2708 }
2709 }
2710
2711 event_builder_generic_impl!(|s: &Self| {
2712 ffi::gst_event_new_protection(
2713 s.system_id.to_glib_none().0,
2714 s.data.as_mut_ptr(),
2715 s.origin.to_glib_none().0,
2716 )
2717 });
2718}
2719
2720#[must_use = "The builder must be built to be used"]
2721pub struct SegmentDoneBuilder<'a> {
2722 builder: EventBuilder<'a>,
2723 position: GenericFormattedValue,
2724}
2725
2726impl<'a> SegmentDoneBuilder<'a> {
2727 fn new(position: GenericFormattedValue) -> Self {
2728 skip_assert_initialized!();
2729 Self {
2730 builder: EventBuilder::new(),
2731 position,
2732 }
2733 }
2734
2735 event_builder_generic_impl!(|s: &Self| {
2736 ffi::gst_event_new_segment_done(s.position.format().into_glib(), s.position.value())
2737 });
2738}
2739
2740#[must_use = "The builder must be built to be used"]
2741pub struct GapBuilder<'a> {
2742 builder: EventBuilder<'a>,
2743 timestamp: ClockTime,
2744 duration: Option<ClockTime>,
2745 #[cfg(feature = "v1_20")]
2746 gap_flags: Option<crate::GapFlags>,
2747}
2748
2749impl<'a> GapBuilder<'a> {
2750 fn new(timestamp: ClockTime) -> Self {
2751 skip_assert_initialized!();
2752 Self {
2753 builder: EventBuilder::new(),
2754 timestamp,
2755 duration: None,
2756 #[cfg(feature = "v1_20")]
2757 gap_flags: None,
2758 }
2759 }
2760
2761 #[cfg(feature = "v1_20")]
2762 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2763 pub fn gap_flags(mut self, flags: crate::GapFlags) -> Self {
2764 self.gap_flags = Some(flags);
2765 self
2766 }
2767
2768 #[cfg(feature = "v1_20")]
2769 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2770 pub fn gap_flags_if(self, flags: crate::GapFlags, predicate: bool) -> Self {
2771 if predicate {
2772 self.gap_flags(flags)
2773 } else {
2774 self
2775 }
2776 }
2777
2778 #[cfg(feature = "v1_20")]
2779 #[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
2780 pub fn gap_flags_if_some(self, flags: Option<crate::GapFlags>) -> Self {
2781 if let Some(flags) = flags {
2782 self.gap_flags(flags)
2783 } else {
2784 self
2785 }
2786 }
2787
2788 pub fn duration(mut self, duration: impl Into<Option<ClockTime>>) -> Self {
2789 self.duration = duration.into();
2790 self
2791 }
2792
2793 pub fn duration_if(self, duration: ClockTime, predicate: bool) -> Self {
2794 if predicate {
2795 self.duration(duration)
2796 } else {
2797 self
2798 }
2799 }
2800
2801 pub fn duration_if_some(self, duration: Option<ClockTime>) -> Self {
2802 if let Some(duration) = duration {
2803 self.duration(duration)
2804 } else {
2805 self
2806 }
2807 }
2808
2809 event_builder_generic_impl!(|s: &Self| {
2810 #[allow(clippy::let_and_return)]
2811 let ev = ffi::gst_event_new_gap(s.timestamp.into_glib(), s.duration.into_glib());
2812
2813 #[cfg(feature = "v1_20")]
2814 if let Some(ref flags) = s.gap_flags {
2815 ffi::gst_event_set_gap_flags(ev, flags.into_glib());
2816 }
2817
2818 ev
2819 });
2820}
2821
2822#[cfg(feature = "v1_18")]
2823#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2824#[must_use = "The builder must be built to be used"]
2825pub struct InstantRateChangeBuilder<'a> {
2826 builder: EventBuilder<'a>,
2827 multiplier: f64,
2828 new_flags: crate::SegmentFlags,
2829}
2830
2831#[cfg(feature = "v1_18")]
2832#[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
2833impl<'a> InstantRateChangeBuilder<'a> {
2834 fn new(multiplier: f64, new_flags: crate::SegmentFlags) -> Self {
2835 skip_assert_initialized!();
2836 Self {
2837 builder: EventBuilder::new(),
2838 multiplier,
2839 new_flags,
2840 }
2841 }
2842
2843 event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_instant_rate_change(
2844 s.multiplier,
2845 s.new_flags.into_glib()
2846 ));
2847}
2848
2849#[must_use = "The builder must be built to be used"]
2850pub struct QosBuilder<'a> {
2851 builder: EventBuilder<'a>,
2852 type_: crate::QOSType,
2853 proportion: f64,
2854 diff: i64,
2855 timestamp: Option<ClockTime>,
2856}
2857
2858impl<'a> QosBuilder<'a> {
2859 fn new(type_: crate::QOSType, proportion: f64, diff: i64) -> Self {
2860 skip_assert_initialized!();
2861 Self {
2862 builder: EventBuilder::new(),
2863 type_,
2864 proportion,
2865 diff,
2866 timestamp: None,
2867 }
2868 }
2869
2870 pub fn timestamp(mut self, timestamp: impl Into<Option<ClockTime>>) -> Self {
2871 self.timestamp = timestamp.into();
2872 self
2873 }
2874
2875 pub fn timestamp_if(self, timestamp: ClockTime, predicate: bool) -> Self {
2876 if predicate {
2877 self.timestamp(timestamp)
2878 } else {
2879 self
2880 }
2881 }
2882
2883 pub fn timestamp_if_some(self, timestamp: Option<ClockTime>) -> Self {
2884 if let Some(timestamp) = timestamp {
2885 self.timestamp(timestamp)
2886 } else {
2887 self
2888 }
2889 }
2890
2891 event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_qos(
2892 s.type_.into_glib(),
2893 s.proportion,
2894 s.diff,
2895 s.timestamp.into_glib(),
2896 ));
2897}
2898
2899#[must_use = "The builder must be built to be used"]
2900pub struct SeekBuilder<'a> {
2901 builder: EventBuilder<'a>,
2902 rate: f64,
2903 flags: crate::SeekFlags,
2904 start_type: crate::SeekType,
2905 start: GenericFormattedValue,
2906 stop_type: crate::SeekType,
2907 stop: GenericFormattedValue,
2908 #[allow(unused)]
2909 trickmode_interval: Option<ClockTime>,
2910}
2911
2912impl<'a> SeekBuilder<'a> {
2913 fn new(
2914 rate: f64,
2915 flags: crate::SeekFlags,
2916 start_type: crate::SeekType,
2917 start: GenericFormattedValue,
2918 stop_type: crate::SeekType,
2919 stop: GenericFormattedValue,
2920 ) -> Self {
2921 skip_assert_initialized!();
2922 Self {
2923 builder: EventBuilder::new(),
2924 rate,
2925 flags,
2926 start_type,
2927 start,
2928 stop_type,
2929 stop,
2930 trickmode_interval: None,
2931 }
2932 }
2933
2934 pub fn trickmode_interval(mut self, trickmode_interval: impl Into<Option<ClockTime>>) -> Self {
2935 self.trickmode_interval = trickmode_interval.into();
2936 self
2937 }
2938
2939 event_builder_generic_impl!(|s: &Self| {
2940 #[allow(clippy::let_and_return)]
2941 {
2942 let ev = ffi::gst_event_new_seek(
2943 s.rate,
2944 s.start.format().into_glib(),
2945 s.flags.into_glib(),
2946 s.start_type.into_glib(),
2947 s.start.value(),
2948 s.stop_type.into_glib(),
2949 s.stop.value(),
2950 );
2951
2952 #[cfg(feature = "v1_16")]
2953 if let Some(trickmode_interval) = s.trickmode_interval {
2954 ffi::gst_event_set_seek_trickmode_interval(ev, trickmode_interval.into_glib());
2955 }
2956
2957 ev
2958 }
2959 });
2960}
2961
2962#[must_use = "The builder must be built to be used"]
2963pub struct NavigationBuilder<'a> {
2964 builder: EventBuilder<'a>,
2965 structure: Option<Structure>,
2966}
2967
2968impl<'a> NavigationBuilder<'a> {
2969 fn new(structure: Structure) -> Self {
2970 skip_assert_initialized!();
2971 Self {
2972 builder: EventBuilder::new(),
2973 structure: Some(structure),
2974 }
2975 }
2976
2977 event_builder_generic_impl!(|s: &mut Self| {
2978 let structure = s.structure.take().unwrap();
2979 ffi::gst_event_new_navigation(structure.into_glib_ptr())
2980 });
2981}
2982
2983#[must_use = "The builder must be built to be used"]
2984pub struct LatencyBuilder<'a> {
2985 builder: EventBuilder<'a>,
2986 latency: ClockTime,
2987}
2988
2989impl<'a> LatencyBuilder<'a> {
2990 fn new(latency: ClockTime) -> Self {
2991 skip_assert_initialized!();
2992 Self {
2993 builder: EventBuilder::new(),
2994 latency,
2995 }
2996 }
2997
2998 event_builder_generic_impl!(|s: &Self| { ffi::gst_event_new_latency(s.latency.into_glib()) });
2999}
3000
3001#[must_use = "The builder must be built to be used"]
3002pub struct StepBuilder<'a> {
3003 builder: EventBuilder<'a>,
3004 amount: GenericFormattedValue,
3005 rate: f64,
3006 flush: bool,
3007 intermediate: bool,
3008}
3009
3010impl<'a> StepBuilder<'a> {
3011 fn new(amount: GenericFormattedValue, rate: f64, flush: bool, intermediate: bool) -> Self {
3012 skip_assert_initialized!();
3013 Self {
3014 builder: EventBuilder::new(),
3015 amount,
3016 rate,
3017 flush,
3018 intermediate,
3019 }
3020 }
3021
3022 event_builder_generic_impl!(|s: &Self| {
3023 ffi::gst_event_new_step(
3024 s.amount.format().into_glib(),
3025 s.amount.value() as u64,
3026 s.rate,
3027 s.flush.into_glib(),
3028 s.intermediate.into_glib(),
3029 )
3030 });
3031}
3032
3033#[must_use = "The builder must be built to be used"]
3034pub struct ReconfigureBuilder<'a> {
3035 builder: EventBuilder<'a>,
3036}
3037
3038impl<'a> ReconfigureBuilder<'a> {
3039 fn new() -> Self {
3040 skip_assert_initialized!();
3041 Self {
3042 builder: EventBuilder::new(),
3043 }
3044 }
3045
3046 event_builder_generic_impl!(|_| { ffi::gst_event_new_reconfigure() });
3047}
3048
3049#[must_use = "The builder must be built to be used"]
3050pub struct TocSelectBuilder<'a> {
3051 builder: EventBuilder<'a>,
3052 uid: &'a str,
3053}
3054
3055impl<'a> TocSelectBuilder<'a> {
3056 fn new(uid: &'a str) -> Self {
3057 skip_assert_initialized!();
3058 Self {
3059 builder: EventBuilder::new(),
3060 uid,
3061 }
3062 }
3063
3064 event_builder_generic_impl!(|s: &Self| {
3065 ffi::gst_event_new_toc_select(s.uid.to_glib_none().0)
3066 });
3067}
3068
3069#[must_use = "The builder must be built to be used"]
3070pub struct SelectStreamsBuilder<'a> {
3071 builder: EventBuilder<'a>,
3072 streams: glib::collections::List<glib::GStringPtr>,
3073}
3074
3075impl<'a> SelectStreamsBuilder<'a> {
3076 fn new(streams: impl IntoIterator<Item = &'a str>) -> Self {
3077 skip_assert_initialized!();
3078 Self {
3079 builder: EventBuilder::new(),
3080 streams: streams.into_iter().map(glib::GStringPtr::from).collect(),
3081 }
3082 }
3083
3084 event_builder_generic_impl!(|s: &Self| {
3085 ffi::gst_event_new_select_streams(mut_override(s.streams.as_ptr()))
3086 });
3087}
3088
3089#[must_use = "The builder must be built to be used"]
3090pub struct CustomUpstreamBuilder<'a> {
3091 builder: EventBuilder<'a>,
3092 structure: Option<Structure>,
3093}
3094
3095impl<'a> CustomUpstreamBuilder<'a> {
3096 fn new(structure: Structure) -> Self {
3097 skip_assert_initialized!();
3098 Self {
3099 builder: EventBuilder::new(),
3100 structure: Some(structure),
3101 }
3102 }
3103
3104 event_builder_generic_impl!(|s: &mut Self| {
3105 let structure = s.structure.take().unwrap();
3106 ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_UPSTREAM, structure.into_glib_ptr())
3107 });
3108}
3109
3110#[must_use = "The builder must be built to be used"]
3111pub struct CustomDownstreamBuilder<'a> {
3112 builder: EventBuilder<'a>,
3113 structure: Option<Structure>,
3114}
3115
3116impl<'a> CustomDownstreamBuilder<'a> {
3117 fn new(structure: Structure) -> Self {
3118 skip_assert_initialized!();
3119 Self {
3120 builder: EventBuilder::new(),
3121 structure: Some(structure),
3122 }
3123 }
3124
3125 event_builder_generic_impl!(|s: &mut Self| {
3126 let structure = s.structure.take().unwrap();
3127 ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_DOWNSTREAM, structure.into_glib_ptr())
3128 });
3129}
3130
3131#[must_use = "The builder must be built to be used"]
3132pub struct CustomDownstreamOobBuilder<'a> {
3133 builder: EventBuilder<'a>,
3134 structure: Option<Structure>,
3135}
3136
3137impl<'a> CustomDownstreamOobBuilder<'a> {
3138 fn new(structure: Structure) -> Self {
3139 skip_assert_initialized!();
3140 Self {
3141 builder: EventBuilder::new(),
3142 structure: Some(structure),
3143 }
3144 }
3145
3146 event_builder_generic_impl!(|s: &mut Self| {
3147 let structure = s.structure.take().unwrap();
3148 ffi::gst_event_new_custom(
3149 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_OOB,
3150 structure.into_glib_ptr(),
3151 )
3152 });
3153}
3154
3155#[must_use = "The builder must be built to be used"]
3156pub struct CustomDownstreamStickyBuilder<'a> {
3157 builder: EventBuilder<'a>,
3158 structure: Option<Structure>,
3159}
3160
3161impl<'a> CustomDownstreamStickyBuilder<'a> {
3162 fn new(structure: Structure) -> Self {
3163 skip_assert_initialized!();
3164 Self {
3165 builder: EventBuilder::new(),
3166 structure: Some(structure),
3167 }
3168 }
3169
3170 event_builder_generic_impl!(|s: &mut Self| {
3171 let structure = s.structure.take().unwrap();
3172 ffi::gst_event_new_custom(
3173 ffi::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY,
3174 structure.into_glib_ptr(),
3175 )
3176 });
3177}
3178
3179#[must_use = "The builder must be built to be used"]
3180pub struct CustomBothBuilder<'a> {
3181 builder: EventBuilder<'a>,
3182 structure: Option<Structure>,
3183}
3184
3185impl<'a> CustomBothBuilder<'a> {
3186 fn new(structure: Structure) -> Self {
3187 skip_assert_initialized!();
3188 Self {
3189 builder: EventBuilder::new(),
3190 structure: Some(structure),
3191 }
3192 }
3193
3194 event_builder_generic_impl!(|s: &mut Self| {
3195 let structure = s.structure.take().unwrap();
3196 ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH, structure.into_glib_ptr())
3197 });
3198}
3199
3200#[must_use = "The builder must be built to be used"]
3201pub struct CustomBothOobBuilder<'a> {
3202 builder: EventBuilder<'a>,
3203 structure: Option<Structure>,
3204}
3205
3206impl<'a> CustomBothOobBuilder<'a> {
3207 fn new(structure: Structure) -> Self {
3208 skip_assert_initialized!();
3209 Self {
3210 builder: EventBuilder::new(),
3211 structure: Some(structure),
3212 }
3213 }
3214
3215 event_builder_generic_impl!(|s: &mut Self| {
3216 let structure = s.structure.take().unwrap();
3217 ffi::gst_event_new_custom(ffi::GST_EVENT_CUSTOM_BOTH_OOB, structure.into_glib_ptr())
3218 });
3219}
3220
3221#[cfg(test)]
3222mod tests {
3223 use super::*;
3224
3225 #[test]
3226 #[allow(deprecated)]
3227 fn test_simple() {
3228 crate::init().unwrap();
3229
3230 let flush_start_evt = FlushStart::new();
3232 match flush_start_evt.view() {
3233 EventView::FlushStart(flush_start_evt) => {
3234 assert!(!flush_start_evt.is_sticky());
3235 assert!(flush_start_evt.structure().is_none());
3236 }
3237 _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"),
3238 }
3239
3240 let flush_start_evt = FlushStart::builder()
3241 .other_field("extra-field", true)
3242 .build();
3243 match flush_start_evt.view() {
3244 EventView::FlushStart(flush_start_evt) => {
3245 assert!(flush_start_evt.structure().is_some());
3246 if let Some(other_fields) = flush_start_evt.structure() {
3247 assert!(other_fields.has_field("extra-field"));
3248 }
3249 }
3250 _ => panic!("flush_start_evt.view() is not an EventView::FlushStart(_)"),
3251 }
3252
3253 let flush_stop_evt = FlushStop::builder(true)
3255 .other_field("extra-field", true)
3256 .build();
3257 match flush_stop_evt.view() {
3258 EventView::FlushStop(flush_stop_evt) => {
3259 assert!(flush_stop_evt.resets_time());
3260 assert!(flush_stop_evt.structure().is_some());
3261 if let Some(other_fields) = flush_stop_evt.structure() {
3262 assert!(other_fields.has_field("extra-field"));
3263 }
3264 }
3265 _ => panic!("flush_stop_evt.view() is not an EventView::FlushStop(_)"),
3266 }
3267 }
3268
3269 #[test]
3270 fn test_get_structure_mut() {
3271 crate::init().unwrap();
3272
3273 let mut flush_start_evt = FlushStart::new();
3274
3275 {
3276 let flush_start_evt = flush_start_evt.get_mut().unwrap();
3277 let structure = flush_start_evt.structure_mut();
3278 structure.set("test", 42u32);
3279 }
3280
3281 let structure = flush_start_evt.structure().unwrap();
3282 assert_eq!(structure.get("test"), Ok(42u32));
3283 }
3284
3285 #[test]
3286 fn test_view_lifetimes() {
3287 crate::init().unwrap();
3288
3289 let caps = crate::Caps::builder("some/x-caps").build();
3290 let event = crate::event::Caps::new(&caps);
3291
3292 let caps2 = match event.view() {
3293 EventView::Caps(caps) => caps.caps(),
3294 _ => unreachable!(),
3295 };
3296
3297 assert_eq!(&*caps, caps2);
3298 }
3299
3300 #[test]
3301 fn test_select_streams() {
3302 crate::init().unwrap();
3303
3304 let s = ["foo", "bar"].to_vec();
3305 let event = crate::event::SelectStreams::new(s.iter().copied());
3306 let streams = match event.view() {
3307 EventView::SelectStreams(streams) => streams.streams(),
3308 _ => unreachable!(),
3309 };
3310 assert_eq!(streams.iter().collect::<Vec<_>>(), s);
3311 }
3312}