1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{cmp, ops};
4
5use glib::{
6 translate::*,
7 value::{FromValue, ToValue, Value},
8 StaticType, Type,
9};
10use thiserror::Error;
11
12use crate::{ClockReturn, State, StateChange, StateChangeReturn};
13
14macro_rules! impl_return_result_traits {
15 ($ffi_type:ident, $ret_type:ident, $ok_type:ident, $err_type:ident) => {
16 impl From<$ok_type> for $ret_type {
17 #[inline]
18 fn from(value: $ok_type) -> Self {
19 skip_assert_initialized!();
20 $ret_type::from_ok(value)
21 }
22 }
23
24 impl IntoGlib for $ok_type {
25 type GlibType = <$ret_type as IntoGlib>::GlibType;
26
27 #[inline]
28 fn into_glib(self) -> Self::GlibType {
29 $ret_type::from_ok(self).into_glib()
30 }
31 }
32
33 impl From<$err_type> for $ret_type {
34 #[inline]
35 fn from(value: $err_type) -> Self {
36 skip_assert_initialized!();
37 $ret_type::from_error(value)
38 }
39 }
40
41 impl IntoGlib for $err_type {
42 type GlibType = <$ret_type as IntoGlib>::GlibType;
43
44 #[inline]
45 fn into_glib(self) -> Self::GlibType {
46 $ret_type::from_error(self).into_glib()
47 }
48 }
49
50 impl From<Result<$ok_type, $err_type>> for $ret_type {
51 #[inline]
52 fn from(res: Result<$ok_type, $err_type>) -> Self {
53 skip_assert_initialized!();
54 match res {
55 Ok(success) => $ret_type::from_ok(success),
56 Err(error) => $ret_type::from_error(error),
57 }
58 }
59 }
60
61 impl TryFromGlib<ffi::$ffi_type> for $ok_type {
62 type Error = $err_type;
63
64 #[inline]
65 unsafe fn try_from_glib(val: ffi::$ffi_type) -> Result<$ok_type, $err_type> {
66 skip_assert_initialized!();
67 $ret_type::from_glib(val).into_result()
68 }
69 }
70 };
71}
72
73impl StateChangeReturn {
74 #[inline]
75 pub fn into_result(self) -> Result<StateChangeSuccess, StateChangeError> {
76 match self {
77 StateChangeReturn::Failure => Err(StateChangeError),
78 _ => Ok(unsafe { std::mem::transmute(self) }),
79 }
80 }
81
82 #[inline]
83 pub fn from_error(_: StateChangeError) -> Self {
84 skip_assert_initialized!();
85 StateChangeReturn::Failure
86 }
87
88 #[inline]
89 pub fn from_ok(v: StateChangeSuccess) -> Self {
90 skip_assert_initialized!();
91 unsafe { std::mem::transmute(src:v) }
92 }
93}
94
95#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
96#[repr(i32)]
97pub enum StateChangeSuccess {
98 Success = ffi::GST_STATE_CHANGE_SUCCESS,
99 Async = ffi::GST_STATE_CHANGE_ASYNC,
100 NoPreroll = ffi::GST_STATE_CHANGE_NO_PREROLL,
101}
102
103#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
104#[must_use]
105#[error("Element failed to change its state")]
106pub struct StateChangeError;
107
108impl_return_result_traits!(
109 GstStateChangeReturn,
110 StateChangeReturn,
111 StateChangeSuccess,
112 StateChangeError
113);
114
115#[must_use]
116#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
117#[repr(i32)]
118#[doc(alias = "GstFlowReturn")]
119pub enum FlowReturn {
120 #[doc(alias = "GST_FLOW_CUSTOM_SUCCESS_2")]
121 CustomSuccess2 = ffi::GST_FLOW_CUSTOM_SUCCESS_2,
122 #[doc(alias = "GST_FLOW_CUSTOM_SUCCESS_1")]
123 CustomSuccess1 = ffi::GST_FLOW_CUSTOM_SUCCESS_1,
124 #[doc(alias = "GST_FLOW_CUSTOM_SUCCESS")]
125 CustomSuccess = ffi::GST_FLOW_CUSTOM_SUCCESS,
126 #[doc(alias = "GST_FLOW_OK")]
127 Ok = ffi::GST_FLOW_OK,
128 #[doc(alias = "GST_FLOW_NOT_LINKED")]
129 NotLinked = ffi::GST_FLOW_NOT_LINKED,
130 #[doc(alias = "GST_FLOW_FLUSHING")]
131 Flushing = ffi::GST_FLOW_FLUSHING,
132 #[doc(alias = "GST_FLOW_EOS")]
133 Eos = ffi::GST_FLOW_EOS,
134 #[doc(alias = "GST_FLOW_NOT_NEGOTIATED")]
135 NotNegotiated = ffi::GST_FLOW_NOT_NEGOTIATED,
136 #[doc(alias = "GST_FLOW_ERROR")]
137 Error = ffi::GST_FLOW_ERROR,
138 #[doc(alias = "GST_FLOW_NOT_SUPPORTED")]
139 NotSupported = ffi::GST_FLOW_NOT_SUPPORTED,
140 #[doc(alias = "GST_FLOW_CUSTOM_ERROR")]
141 CustomError = ffi::GST_FLOW_CUSTOM_ERROR,
142 #[doc(alias = "GST_FLOW_CUSTOM_ERROR_1")]
143 CustomError1 = ffi::GST_FLOW_CUSTOM_ERROR_1,
144 #[doc(alias = "GST_FLOW_CUSTOM_ERROR_2")]
145 CustomError2 = ffi::GST_FLOW_CUSTOM_ERROR_2,
146}
147
148#[doc(hidden)]
149impl IntoGlib for FlowReturn {
150 type GlibType = ffi::GstFlowReturn;
151
152 #[inline]
153 fn into_glib(self) -> ffi::GstFlowReturn {
154 self as ffi::GstFlowReturn
155 }
156}
157
158#[doc(hidden)]
159impl FromGlib<ffi::GstFlowReturn> for FlowReturn {
160 #[inline]
161 unsafe fn from_glib(value: ffi::GstFlowReturn) -> Self {
162 skip_assert_initialized!();
163
164 if value < ffi::GST_FLOW_NOT_SUPPORTED
165 && (value > ffi::GST_FLOW_CUSTOM_ERROR || value < ffi::GST_FLOW_CUSTOM_ERROR_2)
166 {
167 FlowReturn::Error
168 } else if value > 0
169 && (value < ffi::GST_FLOW_CUSTOM_SUCCESS || value > ffi::GST_FLOW_CUSTOM_SUCCESS_2)
170 {
171 FlowReturn::Ok
172 } else {
173 std::mem::transmute(src:value)
174 }
175 }
176}
177
178impl StaticType for FlowReturn {
179 #[inline]
180 fn static_type() -> Type {
181 unsafe { from_glib(val:ffi::gst_flow_return_get_type()) }
182 }
183}
184
185impl glib::value::ValueType for FlowReturn {
186 type Type = Self;
187}
188
189unsafe impl<'a> FromValue<'a> for FlowReturn {
190 type Checker = glib::value::GenericValueTypeChecker<Self>;
191
192 #[inline]
193 unsafe fn from_value(value: &'a glib::Value) -> Self {
194 skip_assert_initialized!();
195 from_glib(val:glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
196 }
197}
198
199impl ToValue for FlowReturn {
200 #[inline]
201 fn to_value(&self) -> glib::Value {
202 let mut value: Value = glib::Value::for_value_type::<Self>();
203 unsafe {
204 glib::gobject_ffi::g_value_set_enum(value:value.to_glib_none_mut().0, self.into_glib());
205 }
206 value
207 }
208
209 #[inline]
210 fn value_type(&self) -> glib::Type {
211 Self::static_type()
212 }
213}
214
215impl From<FlowReturn> for glib::Value {
216 #[inline]
217 fn from(v: FlowReturn) -> Self {
218 skip_assert_initialized!();
219 ToValue::to_value(&v)
220 }
221}
222
223impl FlowReturn {
224 #[inline]
225 pub fn into_result(self) -> Result<FlowSuccess, FlowError> {
226 if self.into_glib() >= 0 {
227 Ok(unsafe { std::mem::transmute(self) })
228 } else {
229 Err(unsafe { std::mem::transmute(self) })
230 }
231 }
232
233 #[inline]
234 pub fn from_error(v: FlowError) -> Self {
235 skip_assert_initialized!();
236 unsafe { std::mem::transmute(src:v) }
237 }
238
239 #[inline]
240 pub fn from_ok(v: FlowSuccess) -> Self {
241 skip_assert_initialized!();
242 unsafe { std::mem::transmute(src:v) }
243 }
244}
245
246#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
247#[repr(i32)]
248pub enum FlowSuccess {
249 CustomSuccess2 = ffi::GST_FLOW_CUSTOM_SUCCESS_2,
250 CustomSuccess1 = ffi::GST_FLOW_CUSTOM_SUCCESS_1,
251 CustomSuccess = ffi::GST_FLOW_CUSTOM_SUCCESS,
252 Ok = ffi::GST_FLOW_OK,
253}
254
255#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
256#[must_use]
257#[repr(i32)]
258pub enum FlowError {
259 #[error("Pad is not linked")]
260 NotLinked = ffi::GST_FLOW_NOT_LINKED,
261 #[error("Pad is flushing")]
262 Flushing = ffi::GST_FLOW_FLUSHING,
263 #[error("Pad is EOS")]
264 Eos = ffi::GST_FLOW_EOS,
265 #[error("Pad is not negotiated")]
266 NotNegotiated = ffi::GST_FLOW_NOT_NEGOTIATED,
267 #[error("Some (fatal) error occurred. Element generating this error should post an error message with more details")]
268 Error = ffi::GST_FLOW_ERROR,
269 #[error("This operation is not supported")]
270 NotSupported = ffi::GST_FLOW_NOT_SUPPORTED,
271 #[error("Elements can use values starting from this (and lower) to define custom error codes")]
272 CustomError = ffi::GST_FLOW_CUSTOM_ERROR,
273 #[error("Pre-defined custom error code")]
274 CustomError1 = ffi::GST_FLOW_CUSTOM_ERROR_1,
275 #[error("Pre-defined custom error code")]
276 CustomError2 = ffi::GST_FLOW_CUSTOM_ERROR_2,
277}
278
279impl_return_result_traits!(GstFlowReturn, FlowReturn, FlowSuccess, FlowError);
280
281#[must_use]
282#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
283#[repr(i32)]
284#[doc(alias = "GstPadLinkReturn")]
285pub enum PadLinkReturn {
286 #[doc(alias = "GST_PAD_LINK_OK")]
287 Ok = ffi::GST_PAD_LINK_OK,
288 #[doc(alias = "GST_PAD_LINK_WRONG_HIERARCHY")]
289 WrongHierarchy = ffi::GST_PAD_LINK_WRONG_HIERARCHY,
290 #[doc(alias = "GST_PAD_LINK_WAS_LINKED")]
291 WasLinked = ffi::GST_PAD_LINK_WAS_LINKED,
292 #[doc(alias = "GST_PAD_LINK_WRONG_DIRECTION")]
293 WrongDirection = ffi::GST_PAD_LINK_WRONG_DIRECTION,
294 #[doc(alias = "GST_PAD_LINK_NOFORMAT")]
295 Noformat = ffi::GST_PAD_LINK_NOFORMAT,
296 #[doc(alias = "GST_PAD_LINK_NOSCHED")]
297 Nosched = ffi::GST_PAD_LINK_NOSCHED,
298 #[doc(alias = "GST_PAD_LINK_REFUSED")]
299 Refused = ffi::GST_PAD_LINK_REFUSED,
300}
301
302#[doc(hidden)]
303impl IntoGlib for PadLinkReturn {
304 type GlibType = ffi::GstPadLinkReturn;
305
306 #[inline]
307 fn into_glib(self) -> ffi::GstPadLinkReturn {
308 self as ffi::GstPadLinkReturn
309 }
310}
311
312#[doc(hidden)]
313impl FromGlib<ffi::GstPadLinkReturn> for PadLinkReturn {
314 #[inline]
315 unsafe fn from_glib(value: ffi::GstPadLinkReturn) -> Self {
316 skip_assert_initialized!();
317
318 if value >= 0 {
319 PadLinkReturn::Ok
320 } else if value < ffi::GST_PAD_LINK_REFUSED {
321 PadLinkReturn::Refused
322 } else {
323 std::mem::transmute(src:value)
324 }
325 }
326}
327
328impl StaticType for PadLinkReturn {
329 #[inline]
330 fn static_type() -> Type {
331 unsafe { from_glib(val:ffi::gst_pad_link_return_get_type()) }
332 }
333}
334
335impl glib::value::ValueType for PadLinkReturn {
336 type Type = Self;
337}
338
339unsafe impl<'a> FromValue<'a> for PadLinkReturn {
340 type Checker = glib::value::GenericValueTypeChecker<Self>;
341
342 #[inline]
343 unsafe fn from_value(value: &'a glib::Value) -> Self {
344 skip_assert_initialized!();
345 from_glib(val:glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
346 }
347}
348
349impl ToValue for PadLinkReturn {
350 #[inline]
351 fn to_value(&self) -> glib::Value {
352 let mut value: Value = glib::Value::for_value_type::<Self>();
353 unsafe {
354 glib::gobject_ffi::g_value_set_enum(value:value.to_glib_none_mut().0, self.into_glib());
355 }
356 value
357 }
358
359 #[inline]
360 fn value_type(&self) -> glib::Type {
361 Self::static_type()
362 }
363}
364
365impl From<PadLinkReturn> for glib::Value {
366 #[inline]
367 fn from(v: PadLinkReturn) -> Self {
368 skip_assert_initialized!();
369 ToValue::to_value(&v)
370 }
371}
372
373impl PadLinkReturn {
374 #[inline]
375 pub fn into_result(self) -> Result<PadLinkSuccess, PadLinkError> {
376 if self == PadLinkReturn::Ok {
377 Ok(PadLinkSuccess)
378 } else {
379 Err(unsafe { std::mem::transmute(self) })
380 }
381 }
382
383 #[inline]
384 pub fn from_error(v: PadLinkError) -> Self {
385 skip_assert_initialized!();
386 unsafe { std::mem::transmute(src:v) }
387 }
388
389 #[inline]
390 pub fn from_ok(_: PadLinkSuccess) -> Self {
391 skip_assert_initialized!();
392 PadLinkReturn::Ok
393 }
394}
395
396#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
397pub struct PadLinkSuccess;
398
399#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
400#[must_use]
401#[repr(i32)]
402pub enum PadLinkError {
403 #[error("Pads have no common grandparent")]
404 WrongHierarchy = ffi::GST_PAD_LINK_WRONG_HIERARCHY,
405 #[error("Pad was already linked")]
406 WasLinked = ffi::GST_PAD_LINK_WAS_LINKED,
407 #[error("Pads have wrong direction")]
408 WrongDirection = ffi::GST_PAD_LINK_WRONG_DIRECTION,
409 #[error("Pads do not have common format")]
410 Noformat = ffi::GST_PAD_LINK_NOFORMAT,
411 #[error("Pads cannot cooperate in scheduling")]
412 Nosched = ffi::GST_PAD_LINK_NOSCHED,
413 #[error("Refused for some other reason")]
414 Refused = ffi::GST_PAD_LINK_REFUSED,
415}
416
417impl_return_result_traits!(
418 GstPadLinkReturn,
419 PadLinkReturn,
420 PadLinkSuccess,
421 PadLinkError
422);
423
424impl ClockReturn {
425 #[inline]
426 pub fn into_result(self) -> Result<ClockSuccess, ClockError> {
427 match self {
428 ClockReturn::Ok => Ok(ClockSuccess::Ok),
429 ClockReturn::Done => Ok(ClockSuccess::Done),
430 _ => Err(unsafe { std::mem::transmute(self) }),
431 }
432 }
433
434 #[inline]
435 pub fn from_error(v: ClockError) -> Self {
436 skip_assert_initialized!();
437 unsafe { std::mem::transmute(src:v) }
438 }
439
440 #[inline]
441 pub fn from_ok(v: ClockSuccess) -> Self {
442 skip_assert_initialized!();
443 unsafe { std::mem::transmute(src:v) }
444 }
445}
446
447#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
448#[repr(i32)]
449pub enum ClockSuccess {
450 Ok = ffi::GST_CLOCK_OK,
451 Done = ffi::GST_CLOCK_DONE,
452}
453
454#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
455#[must_use]
456#[repr(i32)]
457pub enum ClockError {
458 #[error("The operation was scheduled too late")]
459 Early = ffi::GST_CLOCK_EARLY,
460 #[error("The clockID was unscheduled")]
461 Unscheduled = ffi::GST_CLOCK_UNSCHEDULED,
462 #[error("The ClockID is busy")]
463 Busy = ffi::GST_CLOCK_BUSY,
464 #[error("A bad time was provided to a function")]
465 Badtime = ffi::GST_CLOCK_BADTIME,
466 #[error("An error occurred")]
467 Error = ffi::GST_CLOCK_ERROR,
468 #[error("Operation is not supported")]
469 Unsupported = ffi::GST_CLOCK_UNSUPPORTED,
470}
471
472impl_return_result_traits!(GstClockReturn, ClockReturn, ClockSuccess, ClockError);
473
474impl PartialEq for crate::TypeFindProbability {
475 #[inline]
476 fn eq(&self, other: &crate::TypeFindProbability) -> bool {
477 (self.into_glib() as u32).eq(&(other.into_glib() as u32))
478 }
479}
480
481impl Eq for crate::TypeFindProbability {}
482
483impl PartialOrd for crate::TypeFindProbability {
484 #[inline]
485 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
486 Some(self.cmp(other))
487 }
488}
489
490impl Ord for crate::TypeFindProbability {
491 #[inline]
492 fn cmp(&self, other: &Self) -> cmp::Ordering {
493 (self.into_glib() as u32).cmp(&(other.into_glib() as u32))
494 }
495}
496
497impl ops::Add<u32> for crate::TypeFindProbability {
498 type Output = crate::TypeFindProbability;
499
500 #[inline]
501 fn add(self, rhs: u32) -> crate::TypeFindProbability {
502 let res: u32 = (self.into_glib() as u32).saturating_add(rhs);
503 unsafe { from_glib(val:res as i32) }
504 }
505}
506
507impl ops::AddAssign<u32> for crate::TypeFindProbability {
508 #[inline]
509 fn add_assign(&mut self, rhs: u32) {
510 let res: u32 = (self.into_glib() as u32).saturating_add(rhs);
511 *self = unsafe { from_glib(val:res as i32) };
512 }
513}
514
515impl ops::Sub<u32> for crate::TypeFindProbability {
516 type Output = crate::TypeFindProbability;
517
518 #[inline]
519 fn sub(self, rhs: u32) -> crate::TypeFindProbability {
520 let res: u32 = (self.into_glib() as u32).saturating_sub(rhs);
521 unsafe { from_glib(val:res as i32) }
522 }
523}
524
525impl ops::SubAssign<u32> for crate::TypeFindProbability {
526 #[inline]
527 fn sub_assign(&mut self, rhs: u32) {
528 let res: u32 = (self.into_glib() as u32).saturating_sub(rhs);
529 *self = unsafe { from_glib(val:res as i32) };
530 }
531}
532
533impl PartialEq for crate::Rank {
534 #[inline]
535 fn eq(&self, other: &crate::Rank) -> bool {
536 (self.into_glib() as u32).eq(&(other.into_glib() as u32))
537 }
538}
539
540impl Eq for crate::Rank {}
541
542impl PartialOrd for crate::Rank {
543 #[inline]
544 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
545 Some(self.cmp(other))
546 }
547}
548
549impl Ord for crate::Rank {
550 #[inline]
551 fn cmp(&self, other: &Self) -> cmp::Ordering {
552 (self.into_glib() as u32).cmp(&(other.into_glib() as u32))
553 }
554}
555
556impl ops::Add<u32> for crate::Rank {
557 type Output = crate::Rank;
558
559 #[inline]
560 fn add(self, rhs: u32) -> crate::Rank {
561 let res: u32 = (self.into_glib() as u32).saturating_add(rhs);
562 unsafe { from_glib(val:res as i32) }
563 }
564}
565
566impl ops::AddAssign<u32> for crate::Rank {
567 #[inline]
568 fn add_assign(&mut self, rhs: u32) {
569 let res: u32 = (self.into_glib() as u32).saturating_add(rhs);
570 *self = unsafe { from_glib(val:res as i32) };
571 }
572}
573
574impl ops::Sub<u32> for crate::Rank {
575 type Output = crate::Rank;
576
577 #[inline]
578 fn sub(self, rhs: u32) -> crate::Rank {
579 let res: u32 = (self.into_glib() as u32).saturating_sub(rhs);
580 unsafe { from_glib(val:res as i32) }
581 }
582}
583
584impl ops::SubAssign<u32> for crate::Rank {
585 #[inline]
586 fn sub_assign(&mut self, rhs: u32) {
587 let res: u32 = (self.into_glib() as u32).saturating_sub(rhs);
588 *self = unsafe { from_glib(val:res as i32) };
589 }
590}
591
592#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
593#[must_use]
594pub enum TagError {
595 #[error("The value type doesn't match with the specified Tag")]
596 TypeMismatch,
597}
598
599// This cannot be done automatically because in GStreamer it's exposed as a bitflag but works as an
600// enum instead
601#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
602#[doc(alias = "GstMessageType")]
603#[non_exhaustive]
604pub enum MessageType {
605 #[doc(alias = "GST_MESSAGE_UNKNOWN")]
606 Unknown,
607 #[doc(alias = "GST_MESSAGE_EOS")]
608 Eos,
609 #[doc(alias = "GST_MESSAGE_ERROR")]
610 Error,
611 #[doc(alias = "GST_MESSAGE_WARNING")]
612 Warning,
613 #[doc(alias = "GST_MESSAGE_INFO")]
614 Info,
615 #[doc(alias = "GST_MESSAGE_TAG")]
616 Tag,
617 #[doc(alias = "GST_MESSAGE_BUFFERING")]
618 Buffering,
619 #[doc(alias = "GST_MESSAGE_STATE_CHANGED")]
620 StateChanged,
621 #[doc(alias = "GST_MESSAGE_STATE_DIRTY")]
622 StateDirty,
623 #[doc(alias = "GST_MESSAGE_STEP_DONE")]
624 StepDone,
625 #[doc(alias = "GST_MESSAGE_CLOCK_PROVIDE")]
626 ClockProvide,
627 #[doc(alias = "GST_MESSAGE_CLOCK_LOST")]
628 ClockLost,
629 #[doc(alias = "GST_MESSAGE_NEW_CLOCK")]
630 NewClock,
631 #[doc(alias = "GST_MESSAGE_STRUCTURE_CHANGE")]
632 StructureChange,
633 #[doc(alias = "GST_MESSAGE_STREAM_STATUS")]
634 StreamStatus,
635 #[doc(alias = "GST_MESSAGE_APPLICATION")]
636 Application,
637 #[doc(alias = "GST_MESSAGE_ELEMENT")]
638 Element,
639 #[doc(alias = "GST_MESSAGE_SEGMENT_START")]
640 SegmentStart,
641 #[doc(alias = "GST_MESSAGE_SEGMENT_DONE")]
642 SegmentDone,
643 #[doc(alias = "GST_MESSAGE_DURATION_CHANGED")]
644 DurationChanged,
645 #[doc(alias = "GST_MESSAGE_LATENCY")]
646 Latency,
647 #[doc(alias = "GST_MESSAGE_ASYNC_START")]
648 AsyncStart,
649 #[doc(alias = "GST_MESSAGE_ASYNC_DONE")]
650 AsyncDone,
651 #[doc(alias = "GST_MESSAGE_REQUEST_STATE")]
652 RequestState,
653 #[doc(alias = "GST_MESSAGE_STEP_START")]
654 StepStart,
655 #[doc(alias = "GST_MESSAGE_QOS")]
656 Qos,
657 #[doc(alias = "GST_MESSAGE_PROGRESS")]
658 Progress,
659 #[doc(alias = "GST_MESSAGE_TOC")]
660 Toc,
661 #[doc(alias = "GST_MESSAGE_RESET_TIME")]
662 ResetTime,
663 #[doc(alias = "GST_MESSAGE_STREAM_START")]
664 StreamStart,
665 #[doc(alias = "GST_MESSAGE_NEED_CONTEXT")]
666 NeedContext,
667 #[doc(alias = "GST_MESSAGE_HAVE_CONTEXT")]
668 HaveContext,
669 #[doc(alias = "GST_MESSAGE_EXTENDED")]
670 Extended,
671 #[doc(alias = "GST_MESSAGE_DEVICE_ADDED")]
672 DeviceAdded,
673 #[doc(alias = "GST_MESSAGE_DEVICE_REMOVED")]
674 DeviceRemoved,
675 #[doc(alias = "GST_MESSAGE_PROPERTY_NOTIFY")]
676 PropertyNotify,
677 #[doc(alias = "GST_MESSAGE_STREAM_COLLECTION")]
678 StreamCollection,
679 #[doc(alias = "GST_MESSAGE_STREAMS_SELECTED")]
680 StreamsSelected,
681 #[doc(alias = "GST_MESSAGE_REDIRECT")]
682 Redirect,
683 #[doc(hidden)]
684 __Unknown(i32),
685}
686
687#[doc(hidden)]
688impl IntoGlib for MessageType {
689 type GlibType = ffi::GstMessageType;
690
691 fn into_glib(self) -> ffi::GstMessageType {
692 match self {
693 MessageType::Unknown => ffi::GST_MESSAGE_UNKNOWN,
694 MessageType::Eos => ffi::GST_MESSAGE_EOS,
695 MessageType::Error => ffi::GST_MESSAGE_ERROR,
696 MessageType::Warning => ffi::GST_MESSAGE_WARNING,
697 MessageType::Info => ffi::GST_MESSAGE_INFO,
698 MessageType::Tag => ffi::GST_MESSAGE_TAG,
699 MessageType::Buffering => ffi::GST_MESSAGE_BUFFERING,
700 MessageType::StateChanged => ffi::GST_MESSAGE_STATE_CHANGED,
701 MessageType::StateDirty => ffi::GST_MESSAGE_STATE_DIRTY,
702 MessageType::StepDone => ffi::GST_MESSAGE_STEP_DONE,
703 MessageType::ClockProvide => ffi::GST_MESSAGE_CLOCK_PROVIDE,
704 MessageType::ClockLost => ffi::GST_MESSAGE_CLOCK_LOST,
705 MessageType::NewClock => ffi::GST_MESSAGE_NEW_CLOCK,
706 MessageType::StructureChange => ffi::GST_MESSAGE_STRUCTURE_CHANGE,
707 MessageType::StreamStatus => ffi::GST_MESSAGE_STREAM_STATUS,
708 MessageType::Application => ffi::GST_MESSAGE_APPLICATION,
709 MessageType::Element => ffi::GST_MESSAGE_ELEMENT,
710 MessageType::SegmentStart => ffi::GST_MESSAGE_SEGMENT_START,
711 MessageType::SegmentDone => ffi::GST_MESSAGE_SEGMENT_DONE,
712 MessageType::DurationChanged => ffi::GST_MESSAGE_DURATION_CHANGED,
713 MessageType::Latency => ffi::GST_MESSAGE_LATENCY,
714 MessageType::AsyncStart => ffi::GST_MESSAGE_ASYNC_START,
715 MessageType::AsyncDone => ffi::GST_MESSAGE_ASYNC_DONE,
716 MessageType::RequestState => ffi::GST_MESSAGE_REQUEST_STATE,
717 MessageType::StepStart => ffi::GST_MESSAGE_STEP_START,
718 MessageType::Qos => ffi::GST_MESSAGE_QOS,
719 MessageType::Progress => ffi::GST_MESSAGE_PROGRESS,
720 MessageType::Toc => ffi::GST_MESSAGE_TOC,
721 MessageType::ResetTime => ffi::GST_MESSAGE_RESET_TIME,
722 MessageType::StreamStart => ffi::GST_MESSAGE_STREAM_START,
723 MessageType::NeedContext => ffi::GST_MESSAGE_NEED_CONTEXT,
724 MessageType::HaveContext => ffi::GST_MESSAGE_HAVE_CONTEXT,
725 MessageType::Extended => ffi::GST_MESSAGE_EXTENDED,
726 MessageType::DeviceAdded => ffi::GST_MESSAGE_DEVICE_ADDED,
727 MessageType::DeviceRemoved => ffi::GST_MESSAGE_DEVICE_REMOVED,
728 MessageType::PropertyNotify => ffi::GST_MESSAGE_PROPERTY_NOTIFY,
729 MessageType::StreamCollection => ffi::GST_MESSAGE_STREAM_COLLECTION,
730 MessageType::StreamsSelected => ffi::GST_MESSAGE_STREAMS_SELECTED,
731 MessageType::Redirect => ffi::GST_MESSAGE_REDIRECT,
732 MessageType::__Unknown(value) => value as u32,
733 }
734 }
735}
736
737#[doc(hidden)]
738impl FromGlib<ffi::GstMessageType> for MessageType {
739 #[allow(clippy::unreadable_literal)]
740 unsafe fn from_glib(value: ffi::GstMessageType) -> Self {
741 skip_assert_initialized!();
742 match value {
743 ffi::GST_MESSAGE_UNKNOWN => MessageType::Unknown,
744 ffi::GST_MESSAGE_EOS => MessageType::Eos,
745 ffi::GST_MESSAGE_ERROR => MessageType::Error,
746 ffi::GST_MESSAGE_WARNING => MessageType::Warning,
747 ffi::GST_MESSAGE_INFO => MessageType::Info,
748 ffi::GST_MESSAGE_TAG => MessageType::Tag,
749 ffi::GST_MESSAGE_BUFFERING => MessageType::Buffering,
750 ffi::GST_MESSAGE_STATE_CHANGED => MessageType::StateChanged,
751 ffi::GST_MESSAGE_STATE_DIRTY => MessageType::StateDirty,
752 ffi::GST_MESSAGE_STEP_DONE => MessageType::StepDone,
753 ffi::GST_MESSAGE_CLOCK_PROVIDE => MessageType::ClockProvide,
754 ffi::GST_MESSAGE_CLOCK_LOST => MessageType::ClockLost,
755 ffi::GST_MESSAGE_NEW_CLOCK => MessageType::NewClock,
756 ffi::GST_MESSAGE_STRUCTURE_CHANGE => MessageType::StructureChange,
757 ffi::GST_MESSAGE_STREAM_STATUS => MessageType::StreamStatus,
758 ffi::GST_MESSAGE_APPLICATION => MessageType::Application,
759 ffi::GST_MESSAGE_ELEMENT => MessageType::Element,
760 ffi::GST_MESSAGE_SEGMENT_START => MessageType::SegmentStart,
761 ffi::GST_MESSAGE_SEGMENT_DONE => MessageType::SegmentDone,
762 ffi::GST_MESSAGE_DURATION_CHANGED => MessageType::DurationChanged,
763 ffi::GST_MESSAGE_LATENCY => MessageType::Latency,
764 ffi::GST_MESSAGE_ASYNC_START => MessageType::AsyncStart,
765 ffi::GST_MESSAGE_ASYNC_DONE => MessageType::AsyncDone,
766 ffi::GST_MESSAGE_REQUEST_STATE => MessageType::RequestState,
767 ffi::GST_MESSAGE_STEP_START => MessageType::StepStart,
768 ffi::GST_MESSAGE_QOS => MessageType::Qos,
769 ffi::GST_MESSAGE_PROGRESS => MessageType::Progress,
770 ffi::GST_MESSAGE_TOC => MessageType::Toc,
771 ffi::GST_MESSAGE_RESET_TIME => MessageType::ResetTime,
772 ffi::GST_MESSAGE_STREAM_START => MessageType::StreamStart,
773 ffi::GST_MESSAGE_NEED_CONTEXT => MessageType::NeedContext,
774 ffi::GST_MESSAGE_HAVE_CONTEXT => MessageType::HaveContext,
775 ffi::GST_MESSAGE_EXTENDED => MessageType::Extended,
776 ffi::GST_MESSAGE_DEVICE_ADDED => MessageType::DeviceAdded,
777 ffi::GST_MESSAGE_DEVICE_REMOVED => MessageType::DeviceRemoved,
778 ffi::GST_MESSAGE_PROPERTY_NOTIFY => MessageType::PropertyNotify,
779 ffi::GST_MESSAGE_STREAM_COLLECTION => MessageType::StreamCollection,
780 ffi::GST_MESSAGE_STREAMS_SELECTED => MessageType::StreamsSelected,
781 ffi::GST_MESSAGE_REDIRECT => MessageType::Redirect,
782 value => MessageType::__Unknown(value as i32),
783 }
784 }
785}
786
787impl StaticType for MessageType {
788 #[inline]
789 fn static_type() -> Type {
790 unsafe { from_glib(val:ffi::gst_message_type_get_type()) }
791 }
792}
793
794impl glib::value::ValueType for MessageType {
795 type Type = Self;
796}
797
798unsafe impl<'a> FromValue<'a> for MessageType {
799 type Checker = glib::value::GenericValueTypeChecker<Self>;
800
801 #[inline]
802 unsafe fn from_value(value: &glib::Value) -> Self {
803 skip_assert_initialized!();
804 from_glib(val:glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0) as ffi::GstMessageType)
805 }
806}
807
808impl ToValue for MessageType {
809 #[inline]
810 fn to_value(&self) -> Value {
811 let mut value: Value = glib::Value::for_value_type::<Self>();
812 unsafe {
813 glib::gobject_ffi::g_value_set_enum(value:value.to_glib_none_mut().0, self.into_glib() as i32)
814 }
815 value
816 }
817
818 #[inline]
819 fn value_type(&self) -> Type {
820 Self::static_type()
821 }
822}
823
824impl From<MessageType> for glib::Value {
825 #[inline]
826 fn from(v: MessageType) -> glib::Value {
827 skip_assert_initialized!();
828 ToValue::to_value(&v)
829 }
830}
831
832impl State {
833 #[must_use]
834 #[inline]
835 pub fn next(self, pending: Self) -> Self {
836 let current: i32 = self.into_glib();
837 let pending: i32 = pending.into_glib();
838
839 let sign: i32 = (pending - current).signum();
840
841 unsafe { from_glib(val:current + sign) }
842 }
843}
844
845impl StateChange {
846 #[inline]
847 pub fn new(current: State, next: State) -> Self {
848 skip_assert_initialized!();
849 let current: i32 = current.into_glib();
850 let next: i32 = next.into_glib();
851 unsafe { from_glib((current << 3) | next) }
852 }
853
854 #[inline]
855 pub fn current(self) -> State {
856 unsafe { from_glib(self.into_glib() >> 3) }
857 }
858
859 #[inline]
860 pub fn next(self) -> State {
861 unsafe { from_glib(self.into_glib() & 0x7) }
862 }
863}
864