1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use glib::{prelude::*, translate::*}; |
4 | |
5 | glib::wrapper! { |
6 | #[derive (Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] |
7 | #[doc (alias = "GstFlowCombiner" )] |
8 | pub struct FlowCombiner(Shared<ffi::GstFlowCombiner>); |
9 | |
10 | match fn { |
11 | ref => |ptr| { |
12 | // cfg_if emits code in blocks (curly braces) and `ref` handling inserts a |
13 | // trailing semicolon to void an optionally returned value. The linter |
14 | // requests the resulting { ..ref() }; to be simplified making it unsuitable. |
15 | #[cfg (feature = "v1_12_1" )] |
16 | ffi::gst_flow_combiner_ref(ptr); |
17 | #[cfg (not(feature = "v1_12_1" ))] |
18 | glib::gobject_ffi::g_boxed_copy(ffi::gst_flow_combiner_get_type(), ptr as *mut _); |
19 | }, |
20 | unref => |ptr| { |
21 | cfg_if::cfg_if! { |
22 | if #[cfg(feature = "v1_12_1" )] { |
23 | ffi::gst_flow_combiner_unref(ptr); |
24 | } else { |
25 | glib::gobject_ffi::g_boxed_free(ffi::gst_flow_combiner_get_type(), ptr as *mut _); |
26 | } |
27 | } |
28 | }, |
29 | type_ => || ffi::gst_flow_combiner_get_type(), |
30 | } |
31 | } |
32 | |
33 | impl FlowCombiner { |
34 | #[doc (alias = "gst_flow_combiner_new" )] |
35 | pub fn new() -> Self { |
36 | assert_initialized_main_thread!(); |
37 | unsafe { from_glib_full(ffi::gst_flow_combiner_new()) } |
38 | } |
39 | |
40 | #[doc (alias = "gst_flow_combiner_add_pad" )] |
41 | pub fn add_pad<P: IsA<gst::Pad>>(&self, pad: &P) { |
42 | unsafe { |
43 | ffi::gst_flow_combiner_add_pad(self.to_glib_none().0, pad.as_ref().to_glib_none().0); |
44 | } |
45 | } |
46 | |
47 | #[doc (alias = "gst_flow_combiner_clear" )] |
48 | pub fn clear(&self) { |
49 | unsafe { |
50 | ffi::gst_flow_combiner_clear(self.to_glib_none().0); |
51 | } |
52 | } |
53 | |
54 | #[doc (alias = "gst_flow_combiner_remove_pad" )] |
55 | pub fn remove_pad<P: IsA<gst::Pad>>(&self, pad: &P) { |
56 | unsafe { |
57 | ffi::gst_flow_combiner_remove_pad(self.to_glib_none().0, pad.as_ref().to_glib_none().0); |
58 | } |
59 | } |
60 | |
61 | #[doc (alias = "gst_flow_combiner_reset" )] |
62 | pub fn reset(&self) { |
63 | unsafe { |
64 | ffi::gst_flow_combiner_reset(self.to_glib_none().0); |
65 | } |
66 | } |
67 | |
68 | #[doc (alias = "gst_flow_combiner_update_flow" )] |
69 | pub fn update_flow<FRet: Into<gst::FlowReturn>>( |
70 | &self, |
71 | fret: FRet, |
72 | ) -> Result<gst::FlowSuccess, gst::FlowError> { |
73 | let fret: gst::FlowReturn = fret.into(); |
74 | unsafe { |
75 | try_from_glib(ffi::gst_flow_combiner_update_flow( |
76 | self.to_glib_none().0, |
77 | fret.into_glib(), |
78 | )) |
79 | } |
80 | } |
81 | |
82 | #[doc (alias = "gst_flow_combiner_update_pad_flow" )] |
83 | pub fn update_pad_flow<P: IsA<gst::Pad>, FRet: Into<gst::FlowReturn>>( |
84 | &self, |
85 | pad: &P, |
86 | fret: FRet, |
87 | ) -> Result<gst::FlowSuccess, gst::FlowError> { |
88 | let fret: gst::FlowReturn = fret.into(); |
89 | unsafe { |
90 | try_from_glib(ffi::gst_flow_combiner_update_pad_flow( |
91 | self.to_glib_none().0, |
92 | pad.as_ref().to_glib_none().0, |
93 | fret.into_glib(), |
94 | )) |
95 | } |
96 | } |
97 | } |
98 | |
99 | impl Default for FlowCombiner { |
100 | fn default() -> Self { |
101 | Self::new() |
102 | } |
103 | } |
104 | |
105 | #[derive (Debug)] |
106 | pub struct UniqueFlowCombiner(FlowCombiner); |
107 | |
108 | unsafe impl Sync for UniqueFlowCombiner {} |
109 | unsafe impl Send for UniqueFlowCombiner {} |
110 | |
111 | impl UniqueFlowCombiner { |
112 | pub fn new() -> Self { |
113 | Self(FlowCombiner::new()) |
114 | } |
115 | |
116 | pub fn add_pad<P: IsA<gst::Pad>>(&mut self, pad: &P) { |
117 | self.0.add_pad(pad); |
118 | } |
119 | |
120 | pub fn clear(&mut self) { |
121 | self.0.clear(); |
122 | } |
123 | |
124 | pub fn remove_pad<P: IsA<gst::Pad>>(&mut self, pad: &P) { |
125 | self.0.remove_pad(pad); |
126 | } |
127 | |
128 | pub fn reset(&mut self) { |
129 | self.0.reset(); |
130 | } |
131 | |
132 | pub fn update_flow( |
133 | &mut self, |
134 | fret: Result<gst::FlowSuccess, gst::FlowError>, |
135 | ) -> Result<gst::FlowSuccess, gst::FlowError> { |
136 | self.0.update_flow(fret) |
137 | } |
138 | |
139 | pub fn update_pad_flow<P: IsA<gst::Pad>>( |
140 | &mut self, |
141 | pad: &P, |
142 | fret: Result<gst::FlowSuccess, gst::FlowError>, |
143 | ) -> Result<gst::FlowSuccess, gst::FlowError> { |
144 | self.0.update_pad_flow(pad, fret) |
145 | } |
146 | } |
147 | |
148 | impl Default for UniqueFlowCombiner { |
149 | fn default() -> Self { |
150 | Self::new() |
151 | } |
152 | } |
153 | |