1use crate::{ffi, AudioInfo};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstAudioEncoder")]
16 pub struct AudioEncoder(Object<ffi::GstAudioEncoder, ffi::GstAudioEncoderClass>) @extends gst::Element, gst::Object;
17
18 match fn {
19 type_ => || ffi::gst_audio_encoder_get_type(),
20 }
21}
22
23impl AudioEncoder {
24 pub const NONE: Option<&'static AudioEncoder> = None;
25}
26
27unsafe impl Send for AudioEncoder {}
28unsafe impl Sync for AudioEncoder {}
29
30pub trait AudioEncoderExt: IsA<AudioEncoder> + 'static {
31 #[doc(alias = "gst_audio_encoder_allocate_output_buffer")]
32 fn allocate_output_buffer(&self, size: usize) -> gst::Buffer {
33 unsafe {
34 from_glib_full(ffi::gst_audio_encoder_allocate_output_buffer(
35 self.as_ref().to_glib_none().0,
36 size,
37 ))
38 }
39 }
40
41 #[doc(alias = "gst_audio_encoder_finish_frame")]
42 fn finish_frame(
43 &self,
44 buffer: Option<gst::Buffer>,
45 samples: i32,
46 ) -> Result<gst::FlowSuccess, gst::FlowError> {
47 unsafe {
48 try_from_glib(ffi::gst_audio_encoder_finish_frame(
49 self.as_ref().to_glib_none().0,
50 buffer.into_glib_ptr(),
51 samples,
52 ))
53 }
54 }
55
56 #[doc(alias = "gst_audio_encoder_get_audio_info")]
57 #[doc(alias = "get_audio_info")]
58 fn audio_info(&self) -> AudioInfo {
59 unsafe {
60 from_glib_none(ffi::gst_audio_encoder_get_audio_info(
61 self.as_ref().to_glib_none().0,
62 ))
63 }
64 }
65
66 #[doc(alias = "gst_audio_encoder_get_drainable")]
67 #[doc(alias = "get_drainable")]
68 fn is_drainable(&self) -> bool {
69 unsafe {
70 from_glib(ffi::gst_audio_encoder_get_drainable(
71 self.as_ref().to_glib_none().0,
72 ))
73 }
74 }
75
76 #[doc(alias = "gst_audio_encoder_get_frame_max")]
77 #[doc(alias = "get_frame_max")]
78 fn frame_max(&self) -> i32 {
79 unsafe { ffi::gst_audio_encoder_get_frame_max(self.as_ref().to_glib_none().0) }
80 }
81
82 #[doc(alias = "gst_audio_encoder_get_frame_samples_max")]
83 #[doc(alias = "get_frame_samples_max")]
84 fn frame_samples_max(&self) -> i32 {
85 unsafe { ffi::gst_audio_encoder_get_frame_samples_max(self.as_ref().to_glib_none().0) }
86 }
87
88 #[doc(alias = "gst_audio_encoder_get_frame_samples_min")]
89 #[doc(alias = "get_frame_samples_min")]
90 fn frame_samples_min(&self) -> i32 {
91 unsafe { ffi::gst_audio_encoder_get_frame_samples_min(self.as_ref().to_glib_none().0) }
92 }
93
94 #[doc(alias = "gst_audio_encoder_get_hard_min")]
95 #[doc(alias = "get_hard_min")]
96 fn is_hard_min(&self) -> bool {
97 unsafe {
98 from_glib(ffi::gst_audio_encoder_get_hard_min(
99 self.as_ref().to_glib_none().0,
100 ))
101 }
102 }
103
104 #[doc(alias = "gst_audio_encoder_get_hard_resync")]
105 #[doc(alias = "get_hard_resync")]
106 #[doc(alias = "hard-resync")]
107 fn is_hard_resync(&self) -> bool {
108 unsafe {
109 from_glib(ffi::gst_audio_encoder_get_hard_resync(
110 self.as_ref().to_glib_none().0,
111 ))
112 }
113 }
114
115 #[doc(alias = "gst_audio_encoder_get_latency")]
116 #[doc(alias = "get_latency")]
117 fn latency(&self) -> (gst::ClockTime, Option<gst::ClockTime>) {
118 unsafe {
119 let mut min = std::mem::MaybeUninit::uninit();
120 let mut max = std::mem::MaybeUninit::uninit();
121 ffi::gst_audio_encoder_get_latency(
122 self.as_ref().to_glib_none().0,
123 min.as_mut_ptr(),
124 max.as_mut_ptr(),
125 );
126 (
127 try_from_glib(min.assume_init()).expect("mandatory glib value is None"),
128 from_glib(max.assume_init()),
129 )
130 }
131 }
132
133 #[doc(alias = "gst_audio_encoder_get_lookahead")]
134 #[doc(alias = "get_lookahead")]
135 fn lookahead(&self) -> i32 {
136 unsafe { ffi::gst_audio_encoder_get_lookahead(self.as_ref().to_glib_none().0) }
137 }
138
139 #[doc(alias = "gst_audio_encoder_get_mark_granule")]
140 #[doc(alias = "get_mark_granule")]
141 #[doc(alias = "mark-granule")]
142 fn is_mark_granule(&self) -> bool {
143 unsafe {
144 from_glib(ffi::gst_audio_encoder_get_mark_granule(
145 self.as_ref().to_glib_none().0,
146 ))
147 }
148 }
149
150 #[doc(alias = "gst_audio_encoder_get_perfect_timestamp")]
151 #[doc(alias = "get_perfect_timestamp")]
152 #[doc(alias = "perfect-timestamp")]
153 fn is_perfect_timestamp(&self) -> bool {
154 unsafe {
155 from_glib(ffi::gst_audio_encoder_get_perfect_timestamp(
156 self.as_ref().to_glib_none().0,
157 ))
158 }
159 }
160
161 #[doc(alias = "gst_audio_encoder_get_tolerance")]
162 #[doc(alias = "get_tolerance")]
163 fn tolerance(&self) -> gst::ClockTime {
164 unsafe {
165 try_from_glib(ffi::gst_audio_encoder_get_tolerance(
166 self.as_ref().to_glib_none().0,
167 ))
168 .expect("mandatory glib value is None")
169 }
170 }
171
172 #[doc(alias = "gst_audio_encoder_merge_tags")]
173 fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
174 unsafe {
175 ffi::gst_audio_encoder_merge_tags(
176 self.as_ref().to_glib_none().0,
177 tags.to_glib_none().0,
178 mode.into_glib(),
179 );
180 }
181 }
182
183 #[doc(alias = "gst_audio_encoder_proxy_getcaps")]
184 fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps {
185 unsafe {
186 from_glib_full(ffi::gst_audio_encoder_proxy_getcaps(
187 self.as_ref().to_glib_none().0,
188 caps.to_glib_none().0,
189 filter.to_glib_none().0,
190 ))
191 }
192 }
193
194 #[doc(alias = "gst_audio_encoder_set_allocation_caps")]
195 fn set_allocation_caps(&self, allocation_caps: Option<&gst::Caps>) {
196 unsafe {
197 ffi::gst_audio_encoder_set_allocation_caps(
198 self.as_ref().to_glib_none().0,
199 allocation_caps.to_glib_none().0,
200 );
201 }
202 }
203
204 #[doc(alias = "gst_audio_encoder_set_drainable")]
205 fn set_drainable(&self, enabled: bool) {
206 unsafe {
207 ffi::gst_audio_encoder_set_drainable(
208 self.as_ref().to_glib_none().0,
209 enabled.into_glib(),
210 );
211 }
212 }
213
214 #[doc(alias = "gst_audio_encoder_set_frame_max")]
215 fn set_frame_max(&self, num: i32) {
216 unsafe {
217 ffi::gst_audio_encoder_set_frame_max(self.as_ref().to_glib_none().0, num);
218 }
219 }
220
221 #[doc(alias = "gst_audio_encoder_set_frame_samples_max")]
222 fn set_frame_samples_max(&self, num: i32) {
223 unsafe {
224 ffi::gst_audio_encoder_set_frame_samples_max(self.as_ref().to_glib_none().0, num);
225 }
226 }
227
228 #[doc(alias = "gst_audio_encoder_set_frame_samples_min")]
229 fn set_frame_samples_min(&self, num: i32) {
230 unsafe {
231 ffi::gst_audio_encoder_set_frame_samples_min(self.as_ref().to_glib_none().0, num);
232 }
233 }
234
235 #[doc(alias = "gst_audio_encoder_set_hard_min")]
236 fn set_hard_min(&self, enabled: bool) {
237 unsafe {
238 ffi::gst_audio_encoder_set_hard_min(
239 self.as_ref().to_glib_none().0,
240 enabled.into_glib(),
241 );
242 }
243 }
244
245 #[doc(alias = "gst_audio_encoder_set_hard_resync")]
246 #[doc(alias = "hard-resync")]
247 fn set_hard_resync(&self, enabled: bool) {
248 unsafe {
249 ffi::gst_audio_encoder_set_hard_resync(
250 self.as_ref().to_glib_none().0,
251 enabled.into_glib(),
252 );
253 }
254 }
255
256 #[doc(alias = "gst_audio_encoder_set_latency")]
257 fn set_latency(&self, min: gst::ClockTime, max: impl Into<Option<gst::ClockTime>>) {
258 unsafe {
259 ffi::gst_audio_encoder_set_latency(
260 self.as_ref().to_glib_none().0,
261 min.into_glib(),
262 max.into().into_glib(),
263 );
264 }
265 }
266
267 #[doc(alias = "gst_audio_encoder_set_lookahead")]
268 fn set_lookahead(&self, num: i32) {
269 unsafe {
270 ffi::gst_audio_encoder_set_lookahead(self.as_ref().to_glib_none().0, num);
271 }
272 }
273
274 #[doc(alias = "gst_audio_encoder_set_mark_granule")]
275 fn set_mark_granule(&self, enabled: bool) {
276 unsafe {
277 ffi::gst_audio_encoder_set_mark_granule(
278 self.as_ref().to_glib_none().0,
279 enabled.into_glib(),
280 );
281 }
282 }
283
284 #[doc(alias = "gst_audio_encoder_set_perfect_timestamp")]
285 #[doc(alias = "perfect-timestamp")]
286 fn set_perfect_timestamp(&self, enabled: bool) {
287 unsafe {
288 ffi::gst_audio_encoder_set_perfect_timestamp(
289 self.as_ref().to_glib_none().0,
290 enabled.into_glib(),
291 );
292 }
293 }
294
295 #[doc(alias = "gst_audio_encoder_set_tolerance")]
296 #[doc(alias = "tolerance")]
297 fn set_tolerance(&self, tolerance: gst::ClockTime) {
298 unsafe {
299 ffi::gst_audio_encoder_set_tolerance(
300 self.as_ref().to_glib_none().0,
301 tolerance.into_glib(),
302 );
303 }
304 }
305
306 #[doc(alias = "hard-resync")]
307 fn connect_hard_resync_notify<F: Fn(&Self) + Send + Sync + 'static>(
308 &self,
309 f: F,
310 ) -> SignalHandlerId {
311 unsafe extern "C" fn notify_hard_resync_trampoline<
312 P: IsA<AudioEncoder>,
313 F: Fn(&P) + Send + Sync + 'static,
314 >(
315 this: *mut ffi::GstAudioEncoder,
316 _param_spec: glib::ffi::gpointer,
317 f: glib::ffi::gpointer,
318 ) {
319 let f: &F = &*(f as *const F);
320 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
321 }
322 unsafe {
323 let f: Box_<F> = Box_::new(f);
324 connect_raw(
325 self.as_ptr() as *mut _,
326 c"notify::hard-resync".as_ptr() as *const _,
327 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
328 notify_hard_resync_trampoline::<Self, F> as *const (),
329 )),
330 Box_::into_raw(f),
331 )
332 }
333 }
334
335 #[doc(alias = "mark-granule")]
336 fn connect_mark_granule_notify<F: Fn(&Self) + Send + Sync + 'static>(
337 &self,
338 f: F,
339 ) -> SignalHandlerId {
340 unsafe extern "C" fn notify_mark_granule_trampoline<
341 P: IsA<AudioEncoder>,
342 F: Fn(&P) + Send + Sync + 'static,
343 >(
344 this: *mut ffi::GstAudioEncoder,
345 _param_spec: glib::ffi::gpointer,
346 f: glib::ffi::gpointer,
347 ) {
348 let f: &F = &*(f as *const F);
349 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
350 }
351 unsafe {
352 let f: Box_<F> = Box_::new(f);
353 connect_raw(
354 self.as_ptr() as *mut _,
355 c"notify::mark-granule".as_ptr() as *const _,
356 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
357 notify_mark_granule_trampoline::<Self, F> as *const (),
358 )),
359 Box_::into_raw(f),
360 )
361 }
362 }
363
364 #[doc(alias = "perfect-timestamp")]
365 fn connect_perfect_timestamp_notify<F: Fn(&Self) + Send + Sync + 'static>(
366 &self,
367 f: F,
368 ) -> SignalHandlerId {
369 unsafe extern "C" fn notify_perfect_timestamp_trampoline<
370 P: IsA<AudioEncoder>,
371 F: Fn(&P) + Send + Sync + 'static,
372 >(
373 this: *mut ffi::GstAudioEncoder,
374 _param_spec: glib::ffi::gpointer,
375 f: glib::ffi::gpointer,
376 ) {
377 let f: &F = &*(f as *const F);
378 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
379 }
380 unsafe {
381 let f: Box_<F> = Box_::new(f);
382 connect_raw(
383 self.as_ptr() as *mut _,
384 c"notify::perfect-timestamp".as_ptr() as *const _,
385 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
386 notify_perfect_timestamp_trampoline::<Self, F> as *const (),
387 )),
388 Box_::into_raw(f),
389 )
390 }
391 }
392
393 #[doc(alias = "tolerance")]
394 fn connect_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>(
395 &self,
396 f: F,
397 ) -> SignalHandlerId {
398 unsafe extern "C" fn notify_tolerance_trampoline<
399 P: IsA<AudioEncoder>,
400 F: Fn(&P) + Send + Sync + 'static,
401 >(
402 this: *mut ffi::GstAudioEncoder,
403 _param_spec: glib::ffi::gpointer,
404 f: glib::ffi::gpointer,
405 ) {
406 let f: &F = &*(f as *const F);
407 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
408 }
409 unsafe {
410 let f: Box_<F> = Box_::new(f);
411 connect_raw(
412 self.as_ptr() as *mut _,
413 c"notify::tolerance".as_ptr() as *const _,
414 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
415 notify_tolerance_trampoline::<Self, F> as *const (),
416 )),
417 Box_::into_raw(f),
418 )
419 }
420 }
421}
422
423impl<O: IsA<AudioEncoder>> AudioEncoderExt for O {}