1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::mem;
4
5use glib::{prelude::*, translate::*};
6use gst::format::{FormattedValue, SpecificFormattedValueFullRange};
7
8use crate::{BaseParse, BaseParseFrame};
9
10mod sealed {
11 pub trait Sealed {}
12 impl<T: super::IsA<super::BaseParse>> Sealed for T {}
13}
14
15pub trait BaseParseExtManual: sealed::Sealed + IsA<BaseParse> + 'static {
16 #[doc(alias = "get_sink_pad")]
17 fn sink_pad(&self) -> &gst::Pad {
18 unsafe {
19 let elt = &*(self.as_ptr() as *const ffi::GstBaseParse);
20 &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
21 }
22 }
23
24 #[doc(alias = "get_src_pad")]
25 fn src_pad(&self) -> &gst::Pad {
26 unsafe {
27 let elt = &*(self.as_ptr() as *const ffi::GstBaseParse);
28 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
29 }
30 }
31
32 #[doc(alias = "gst_base_parse_set_duration")]
33 fn set_duration(&self, duration: impl FormattedValue, interval: u32) {
34 unsafe {
35 ffi::gst_base_parse_set_duration(
36 self.as_ref().to_glib_none().0,
37 duration.format().into_glib(),
38 duration.into_raw_value(),
39 interval as i32,
40 );
41 }
42 }
43
44 #[doc(alias = "gst_base_parse_set_frame_rate")]
45 fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32) {
46 let (fps_num, fps_den) = fps.into();
47 unsafe {
48 ffi::gst_base_parse_set_frame_rate(
49 self.as_ref().to_glib_none().0,
50 fps_num as u32,
51 fps_den as u32,
52 lead_in,
53 lead_out,
54 );
55 }
56 }
57
58 #[doc(alias = "gst_base_parse_convert_default")]
59 fn convert_default<U: SpecificFormattedValueFullRange>(
60 &self,
61 src_val: impl FormattedValue,
62 ) -> Option<U> {
63 unsafe {
64 let mut dest_val = mem::MaybeUninit::uninit();
65 let ret = from_glib(ffi::gst_base_parse_convert_default(
66 self.as_ref().to_glib_none().0,
67 src_val.format().into_glib(),
68 src_val.into_raw_value(),
69 U::default_format().into_glib(),
70 dest_val.as_mut_ptr(),
71 ));
72 if ret {
73 Some(U::from_raw(U::default_format(), dest_val.assume_init()))
74 } else {
75 None
76 }
77 }
78 }
79
80 fn convert_default_generic(
81 &self,
82 src_val: impl FormattedValue,
83 dest_format: gst::Format,
84 ) -> Option<gst::GenericFormattedValue> {
85 unsafe {
86 let mut dest_val = mem::MaybeUninit::uninit();
87 let ret = from_glib(ffi::gst_base_parse_convert_default(
88 self.as_ref().to_glib_none().0,
89 src_val.format().into_glib(),
90 src_val.into_raw_value(),
91 dest_format.into_glib(),
92 dest_val.as_mut_ptr(),
93 ));
94 if ret {
95 Some(gst::GenericFormattedValue::new(
96 dest_format,
97 dest_val.assume_init(),
98 ))
99 } else {
100 None
101 }
102 }
103 }
104
105 #[doc(alias = "gst_base_parse_finish_frame")]
106 fn finish_frame(
107 &self,
108 frame: BaseParseFrame,
109 size: u32,
110 ) -> Result<gst::FlowSuccess, gst::FlowError> {
111 unsafe {
112 try_from_glib(ffi::gst_base_parse_finish_frame(
113 self.as_ref().to_glib_none().0,
114 frame.to_glib_none().0,
115 i32::try_from(size).expect("size higher than i32::MAX"),
116 ))
117 }
118 }
119}
120
121impl<O: IsA<BaseParse>> BaseParseExtManual for O {}
122