1use crate::{AudioInfo, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 #[cfg(feature = "v1_30")]
205 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
206 #[doc(alias = "gst_audio_encoder_set_allocator")]
207 fn set_allocator(
208 &self,
209 allocator: Option<impl IsA<gst::Allocator>>,
210 params: Option<&gst::AllocationParams>,
211 ) {
212 unsafe {
213 ffi::gst_audio_encoder_set_allocator(
214 self.as_ref().to_glib_none().0,
215 allocator.map(|p| p.upcast()).into_glib_ptr(),
216 params.to_glib_none().0,
217 );
218 }
219 }
220
221 #[doc(alias = "gst_audio_encoder_set_drainable")]
222 fn set_drainable(&self, enabled: bool) {
223 unsafe {
224 ffi::gst_audio_encoder_set_drainable(
225 self.as_ref().to_glib_none().0,
226 enabled.into_glib(),
227 );
228 }
229 }
230
231 #[doc(alias = "gst_audio_encoder_set_frame_max")]
232 fn set_frame_max(&self, num: i32) {
233 unsafe {
234 ffi::gst_audio_encoder_set_frame_max(self.as_ref().to_glib_none().0, num);
235 }
236 }
237
238 #[doc(alias = "gst_audio_encoder_set_frame_samples_max")]
239 fn set_frame_samples_max(&self, num: i32) {
240 unsafe {
241 ffi::gst_audio_encoder_set_frame_samples_max(self.as_ref().to_glib_none().0, num);
242 }
243 }
244
245 #[doc(alias = "gst_audio_encoder_set_frame_samples_min")]
246 fn set_frame_samples_min(&self, num: i32) {
247 unsafe {
248 ffi::gst_audio_encoder_set_frame_samples_min(self.as_ref().to_glib_none().0, num);
249 }
250 }
251
252 #[doc(alias = "gst_audio_encoder_set_hard_min")]
253 fn set_hard_min(&self, enabled: bool) {
254 unsafe {
255 ffi::gst_audio_encoder_set_hard_min(
256 self.as_ref().to_glib_none().0,
257 enabled.into_glib(),
258 );
259 }
260 }
261
262 #[doc(alias = "gst_audio_encoder_set_hard_resync")]
263 #[doc(alias = "hard-resync")]
264 fn set_hard_resync(&self, enabled: bool) {
265 unsafe {
266 ffi::gst_audio_encoder_set_hard_resync(
267 self.as_ref().to_glib_none().0,
268 enabled.into_glib(),
269 );
270 }
271 }
272
273 #[doc(alias = "gst_audio_encoder_set_latency")]
274 fn set_latency(&self, min: gst::ClockTime, max: impl Into<Option<gst::ClockTime>>) {
275 unsafe {
276 ffi::gst_audio_encoder_set_latency(
277 self.as_ref().to_glib_none().0,
278 min.into_glib(),
279 max.into().into_glib(),
280 );
281 }
282 }
283
284 #[doc(alias = "gst_audio_encoder_set_lookahead")]
285 fn set_lookahead(&self, num: i32) {
286 unsafe {
287 ffi::gst_audio_encoder_set_lookahead(self.as_ref().to_glib_none().0, num);
288 }
289 }
290
291 #[doc(alias = "gst_audio_encoder_set_mark_granule")]
292 fn set_mark_granule(&self, enabled: bool) {
293 unsafe {
294 ffi::gst_audio_encoder_set_mark_granule(
295 self.as_ref().to_glib_none().0,
296 enabled.into_glib(),
297 );
298 }
299 }
300
301 #[doc(alias = "gst_audio_encoder_set_perfect_timestamp")]
302 #[doc(alias = "perfect-timestamp")]
303 fn set_perfect_timestamp(&self, enabled: bool) {
304 unsafe {
305 ffi::gst_audio_encoder_set_perfect_timestamp(
306 self.as_ref().to_glib_none().0,
307 enabled.into_glib(),
308 );
309 }
310 }
311
312 #[doc(alias = "gst_audio_encoder_set_tolerance")]
313 #[doc(alias = "tolerance")]
314 fn set_tolerance(&self, tolerance: gst::ClockTime) {
315 unsafe {
316 ffi::gst_audio_encoder_set_tolerance(
317 self.as_ref().to_glib_none().0,
318 tolerance.into_glib(),
319 );
320 }
321 }
322
323 #[doc(alias = "hard-resync")]
324 fn connect_hard_resync_notify<F: Fn(&Self) + Send + Sync + 'static>(
325 &self,
326 f: F,
327 ) -> SignalHandlerId {
328 unsafe extern "C" fn notify_hard_resync_trampoline<
329 P: IsA<AudioEncoder>,
330 F: Fn(&P) + Send + Sync + 'static,
331 >(
332 this: *mut ffi::GstAudioEncoder,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 unsafe {
337 let f: &F = &*(f as *const F);
338 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
339 }
340 }
341 unsafe {
342 let f: Box_<F> = Box_::new(f);
343 connect_raw(
344 self.as_ptr() as *mut _,
345 c"notify::hard-resync".as_ptr(),
346 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
347 notify_hard_resync_trampoline::<Self, F> as *const (),
348 )),
349 Box_::into_raw(f),
350 )
351 }
352 }
353
354 #[doc(alias = "mark-granule")]
355 fn connect_mark_granule_notify<F: Fn(&Self) + Send + Sync + 'static>(
356 &self,
357 f: F,
358 ) -> SignalHandlerId {
359 unsafe extern "C" fn notify_mark_granule_trampoline<
360 P: IsA<AudioEncoder>,
361 F: Fn(&P) + Send + Sync + 'static,
362 >(
363 this: *mut ffi::GstAudioEncoder,
364 _param_spec: glib::ffi::gpointer,
365 f: glib::ffi::gpointer,
366 ) {
367 unsafe {
368 let f: &F = &*(f as *const F);
369 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
370 }
371 }
372 unsafe {
373 let f: Box_<F> = Box_::new(f);
374 connect_raw(
375 self.as_ptr() as *mut _,
376 c"notify::mark-granule".as_ptr(),
377 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
378 notify_mark_granule_trampoline::<Self, F> as *const (),
379 )),
380 Box_::into_raw(f),
381 )
382 }
383 }
384
385 #[doc(alias = "perfect-timestamp")]
386 fn connect_perfect_timestamp_notify<F: Fn(&Self) + Send + Sync + 'static>(
387 &self,
388 f: F,
389 ) -> SignalHandlerId {
390 unsafe extern "C" fn notify_perfect_timestamp_trampoline<
391 P: IsA<AudioEncoder>,
392 F: Fn(&P) + Send + Sync + 'static,
393 >(
394 this: *mut ffi::GstAudioEncoder,
395 _param_spec: glib::ffi::gpointer,
396 f: glib::ffi::gpointer,
397 ) {
398 unsafe {
399 let f: &F = &*(f as *const F);
400 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
401 }
402 }
403 unsafe {
404 let f: Box_<F> = Box_::new(f);
405 connect_raw(
406 self.as_ptr() as *mut _,
407 c"notify::perfect-timestamp".as_ptr(),
408 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
409 notify_perfect_timestamp_trampoline::<Self, F> as *const (),
410 )),
411 Box_::into_raw(f),
412 )
413 }
414 }
415
416 #[doc(alias = "tolerance")]
417 fn connect_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>(
418 &self,
419 f: F,
420 ) -> SignalHandlerId {
421 unsafe extern "C" fn notify_tolerance_trampoline<
422 P: IsA<AudioEncoder>,
423 F: Fn(&P) + Send + Sync + 'static,
424 >(
425 this: *mut ffi::GstAudioEncoder,
426 _param_spec: glib::ffi::gpointer,
427 f: glib::ffi::gpointer,
428 ) {
429 unsafe {
430 let f: &F = &*(f as *const F);
431 f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
432 }
433 }
434 unsafe {
435 let f: Box_<F> = Box_::new(f);
436 connect_raw(
437 self.as_ptr() as *mut _,
438 c"notify::tolerance".as_ptr(),
439 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
440 notify_tolerance_trampoline::<Self, F> as *const (),
441 )),
442 Box_::into_raw(f),
443 )
444 }
445 }
446}
447
448impl<O: IsA<AudioEncoder>> AudioEncoderExt for O {}