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