1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::AudioInfo;
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// This base class is for audio encoders turning raw audio samples into
    /// encoded audio data.
    ///
    /// GstAudioEncoder and subclass should cooperate as follows.
    ///
    /// ## Configuration
    ///
    ///  * Initially, GstAudioEncoder calls `start` when the encoder element
    ///  is activated, which allows subclass to perform any global setup.
    ///
    ///  * GstAudioEncoder calls `set_format` to inform subclass of the format
    ///  of input audio data that it is about to receive. Subclass should
    ///  setup for encoding and configure various base class parameters
    ///  appropriately, notably those directing desired input data handling.
    ///  While unlikely, it might be called more than once, if changing input
    ///  parameters require reconfiguration.
    ///
    ///  * GstAudioEncoder calls `stop` at end of all processing.
    ///
    /// As of configuration stage, and throughout processing, GstAudioEncoder
    /// maintains various parameters that provide required context,
    /// e.g. describing the format of input audio data.
    /// Conversely, subclass can and should configure these context parameters
    /// to inform base class of its expectation w.r.t. buffer handling.
    ///
    /// ## Data processing
    ///
    ///  * Base class gathers input sample data (as directed by the context's
    ///  frame_samples and frame_max) and provides this to subclass' `handle_frame`.
    ///  * If codec processing results in encoded data, subclass should call
    ///  [`AudioEncoderExt::finish_frame()`][crate::prelude::AudioEncoderExt::finish_frame()] to have encoded data pushed
    ///  downstream. Alternatively, it might also call
    ///  [`AudioEncoderExt::finish_frame()`][crate::prelude::AudioEncoderExt::finish_frame()] (with a NULL buffer and some number of
    ///  dropped samples) to indicate dropped (non-encoded) samples.
    ///  * Just prior to actually pushing a buffer downstream,
    ///  it is passed to `pre_push`.
    ///  * During the parsing process GstAudioEncoderClass will handle both
    ///  srcpad and sinkpad events. Sink events will be passed to subclass
    ///  if `event` callback has been provided.
    ///
    /// ## Shutdown phase
    ///
    ///  * GstAudioEncoder class calls `stop` to inform the subclass that data
    ///  parsing will be stopped.
    ///
    /// Subclass is responsible for providing pad template caps for
    /// source and sink pads. The pads need to be named "sink" and "src". It also
    /// needs to set the fixed caps on srcpad, when the format is ensured. This
    /// is typically when base class calls subclass' `set_format` function, though
    /// it might be delayed until calling [`AudioEncoderExt::finish_frame()`][crate::prelude::AudioEncoderExt::finish_frame()].
    ///
    /// In summary, above process should have subclass concentrating on
    /// codec data processing while leaving other matters to base class,
    /// such as most notably timestamp handling. While it may exert more control
    /// in this area (see e.g. `pre_push`), it is very much not recommended.
    ///
    /// In particular, base class will either favor tracking upstream timestamps
    /// (at the possible expense of jitter) or aim to arrange for a perfect stream of
    /// output timestamps, depending on [`perfect-timestamp`][struct@crate::AudioEncoder#perfect-timestamp].
    /// However, in the latter case, the input may not be so perfect or ideal, which
    /// is handled as follows. An input timestamp is compared with the expected
    /// timestamp as dictated by input sample stream and if the deviation is less
    /// than [`tolerance`][struct@crate::AudioEncoder#tolerance], the deviation is discarded.
    /// Otherwise, it is considered a discontuinity and subsequent output timestamp
    /// is resynced to the new position after performing configured discontinuity
    /// processing. In the non-perfect-timestamp case, an upstream variation
    /// exceeding tolerance only leads to marking DISCONT on subsequent outgoing
    /// (while timestamps are adjusted to upstream regardless of variation).
    /// While DISCONT is also marked in the perfect-timestamp case, this one
    /// optionally (see [`hard-resync`][struct@crate::AudioEncoder#hard-resync])
    /// performs some additional steps, such as clipping of (early) input samples
    /// or draining all currently remaining input data, depending on the direction
    /// of the discontuinity.
    ///
    /// If perfect timestamps are arranged, it is also possible to request baseclass
    /// (usually set by subclass) to provide additional buffer metadata (in OFFSET
    /// and OFFSET_END) fields according to granule defined semantics currently
    /// needed by oggmux. Specifically, OFFSET is set to granulepos (= sample count
    /// including buffer) and OFFSET_END to corresponding timestamp (as determined
    /// by same sample count and sample rate).
    ///
    /// Things that subclass need to take care of:
    ///
    ///  * Provide pad templates
    ///  * Set source pad caps when appropriate
    ///  * Inform base class of buffer processing needs using context's
    ///  frame_samples and frame_bytes.
    ///  * Set user-configurable properties to sane defaults for format and
    ///  implementing codec at hand, e.g. those controlling timestamp behaviour
    ///  and discontinuity processing.
    ///  * Accept data in `handle_frame` and provide encoded results to
    ///  [`AudioEncoderExt::finish_frame()`][crate::prelude::AudioEncoderExt::finish_frame()].
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `hard-resync`
    ///  Readable | Writeable
    ///
    ///
    /// #### `mark-granule`
    ///  Readable
    ///
    ///
    /// #### `perfect-timestamp`
    ///  Readable | Writeable
    ///
    ///
    /// #### `tolerance`
    ///  Readable | Writeable
    /// <details><summary><h4>Object</h4></summary>
    ///
    ///
    /// #### `name`
    ///  Readable | Writeable | Construct
    ///
    ///
    /// #### `parent`
    ///  The parent of the object. Please note, that when changing the 'parent'
    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
    /// signals due to locking issues. In some cases one can use
    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
    /// achieve a similar effect.
    ///
    /// Readable | Writeable
    /// </details>
    ///
    /// # Implements
    ///
    /// [`AudioEncoderExt`][trait@crate::prelude::AudioEncoderExt], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::GstObjectExt`], [`trait@glib::ObjectExt`], [`AudioEncoderExtManual`][trait@crate::prelude::AudioEncoderExtManual]
    #[doc(alias = "GstAudioEncoder")]
    pub struct AudioEncoder(Object<ffi::GstAudioEncoder, ffi::GstAudioEncoderClass>) @extends gst::Element, gst::Object;

    match fn {
        type_ => || ffi::gst_audio_encoder_get_type(),
    }
}

impl AudioEncoder {
    pub const NONE: Option<&'static AudioEncoder> = None;
}

unsafe impl Send for AudioEncoder {}
unsafe impl Sync for AudioEncoder {}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::AudioEncoder>> Sealed for T {}
}

/// Trait containing all [`struct@AudioEncoder`] methods.
///
/// # Implementors
///
/// [`AudioEncoder`][struct@crate::AudioEncoder]
pub trait AudioEncoderExt: IsA<AudioEncoder> + sealed::Sealed + 'static {
    /// Helper function that allocates a buffer to hold an encoded audio frame
    /// for `self`'s current output format.
    /// ## `size`
    /// size of the buffer
    ///
    /// # Returns
    ///
    /// allocated buffer
    #[doc(alias = "gst_audio_encoder_allocate_output_buffer")]
    fn allocate_output_buffer(&self, size: usize) -> gst::Buffer {
        unsafe {
            from_glib_full(ffi::gst_audio_encoder_allocate_output_buffer(
                self.as_ref().to_glib_none().0,
                size,
            ))
        }
    }

    /// Collects encoded data and pushes encoded data downstream.
    /// Source pad caps must be set when this is called.
    ///
    /// If `samples` < 0, then best estimate is all samples provided to encoder
    /// (subclass) so far. `buf` may be NULL, in which case next number of `samples`
    /// are considered discarded, e.g. as a result of discontinuous transmission,
    /// and a discontinuity is marked.
    ///
    /// Note that samples received in `GstAudioEncoderClass.handle_frame()`
    /// may be invalidated by a call to this function.
    /// ## `buffer`
    /// encoded data
    /// ## `samples`
    /// number of samples (per channel) represented by encoded data
    ///
    /// # Returns
    ///
    /// a [`gst::FlowReturn`][crate::gst::FlowReturn] that should be escalated to caller (of caller)
    #[doc(alias = "gst_audio_encoder_finish_frame")]
    fn finish_frame(
        &self,
        buffer: Option<gst::Buffer>,
        samples: i32,
    ) -> Result<gst::FlowSuccess, gst::FlowError> {
        unsafe {
            try_from_glib(ffi::gst_audio_encoder_finish_frame(
                self.as_ref().to_glib_none().0,
                buffer.into_glib_ptr(),
                samples,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// a [`AudioInfo`][crate::AudioInfo] describing the input audio format
    #[doc(alias = "gst_audio_encoder_get_audio_info")]
    #[doc(alias = "get_audio_info")]
    fn audio_info(&self) -> AudioInfo {
        unsafe {
            from_glib_none(ffi::gst_audio_encoder_get_audio_info(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Queries encoder drain handling.
    ///
    /// # Returns
    ///
    /// TRUE if drainable handling is enabled.
    ///
    /// MT safe.
    #[doc(alias = "gst_audio_encoder_get_drainable")]
    #[doc(alias = "get_drainable")]
    fn is_drainable(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_audio_encoder_get_drainable(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    ///
    /// # Returns
    ///
    /// currently configured maximum handled frames
    #[doc(alias = "gst_audio_encoder_get_frame_max")]
    #[doc(alias = "get_frame_max")]
    fn frame_max(&self) -> i32 {
        unsafe { ffi::gst_audio_encoder_get_frame_max(self.as_ref().to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// currently maximum requested samples per frame
    #[doc(alias = "gst_audio_encoder_get_frame_samples_max")]
    #[doc(alias = "get_frame_samples_max")]
    fn frame_samples_max(&self) -> i32 {
        unsafe { ffi::gst_audio_encoder_get_frame_samples_max(self.as_ref().to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// currently minimum requested samples per frame
    #[doc(alias = "gst_audio_encoder_get_frame_samples_min")]
    #[doc(alias = "get_frame_samples_min")]
    fn frame_samples_min(&self) -> i32 {
        unsafe { ffi::gst_audio_encoder_get_frame_samples_min(self.as_ref().to_glib_none().0) }
    }

    /// Queries encoder hard minimum handling.
    ///
    /// # Returns
    ///
    /// TRUE if hard minimum handling is enabled.
    ///
    /// MT safe.
    #[doc(alias = "gst_audio_encoder_get_hard_min")]
    #[doc(alias = "get_hard_min")]
    fn is_hard_min(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_audio_encoder_get_hard_min(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gst_audio_encoder_get_hard_resync")]
    #[doc(alias = "get_hard_resync")]
    fn is_hard_resync(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_audio_encoder_get_hard_resync(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Sets the variables pointed to by `min` and `max` to the currently configured
    /// latency.
    ///
    /// # Returns
    ///
    ///
    /// ## `min`
    /// a pointer to storage to hold minimum latency
    ///
    /// ## `max`
    /// a pointer to storage to hold maximum latency
    #[doc(alias = "gst_audio_encoder_get_latency")]
    #[doc(alias = "get_latency")]
    fn latency(&self) -> (gst::ClockTime, Option<gst::ClockTime>) {
        unsafe {
            let mut min = std::mem::MaybeUninit::uninit();
            let mut max = std::mem::MaybeUninit::uninit();
            ffi::gst_audio_encoder_get_latency(
                self.as_ref().to_glib_none().0,
                min.as_mut_ptr(),
                max.as_mut_ptr(),
            );
            (
                try_from_glib(min.assume_init()).expect("mandatory glib value is None"),
                from_glib(max.assume_init()),
            )
        }
    }

    ///
    /// # Returns
    ///
    /// currently configured encoder lookahead
    #[doc(alias = "gst_audio_encoder_get_lookahead")]
    #[doc(alias = "get_lookahead")]
    fn lookahead(&self) -> i32 {
        unsafe { ffi::gst_audio_encoder_get_lookahead(self.as_ref().to_glib_none().0) }
    }

    /// Queries if the encoder will handle granule marking.
    ///
    /// # Returns
    ///
    /// TRUE if granule marking is enabled.
    ///
    /// MT safe.
    #[doc(alias = "gst_audio_encoder_get_mark_granule")]
    #[doc(alias = "get_mark_granule")]
    fn is_mark_granule(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_audio_encoder_get_mark_granule(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Queries encoder perfect timestamp behaviour.
    ///
    /// # Returns
    ///
    /// TRUE if perfect timestamp setting enabled.
    ///
    /// MT safe.
    #[doc(alias = "gst_audio_encoder_get_perfect_timestamp")]
    #[doc(alias = "get_perfect_timestamp")]
    fn is_perfect_timestamp(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_audio_encoder_get_perfect_timestamp(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Queries current audio jitter tolerance threshold.
    ///
    /// # Returns
    ///
    /// encoder audio jitter tolerance threshold.
    ///
    /// MT safe.
    #[doc(alias = "gst_audio_encoder_get_tolerance")]
    #[doc(alias = "get_tolerance")]
    fn tolerance(&self) -> gst::ClockTime {
        unsafe {
            try_from_glib(ffi::gst_audio_encoder_get_tolerance(
                self.as_ref().to_glib_none().0,
            ))
            .expect("mandatory glib value is None")
        }
    }

    /// Sets the audio encoder tags and how they should be merged with any
    /// upstream stream tags. This will override any tags previously-set
    /// with [`merge_tags()`][Self::merge_tags()].
    ///
    /// Note that this is provided for convenience, and the subclass is
    /// not required to use this and can still do tag handling on its own.
    ///
    /// MT safe.
    /// ## `tags`
    /// a [`gst::TagList`][crate::gst::TagList] to merge, or NULL to unset
    ///  previously-set tags
    /// ## `mode`
    /// the [`gst::TagMergeMode`][crate::gst::TagMergeMode] to use, usually [`gst::TagMergeMode::Replace`][crate::gst::TagMergeMode::Replace]
    #[doc(alias = "gst_audio_encoder_merge_tags")]
    fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
        unsafe {
            ffi::gst_audio_encoder_merge_tags(
                self.as_ref().to_glib_none().0,
                tags.to_glib_none().0,
                mode.into_glib(),
            );
        }
    }

    /// Returns caps that express `caps` (or sink template caps if `caps` == NULL)
    /// restricted to channel/rate combinations supported by downstream elements
    /// (e.g. muxers).
    /// ## `caps`
    /// initial caps
    /// ## `filter`
    /// filter caps
    ///
    /// # Returns
    ///
    /// a [`gst::Caps`][crate::gst::Caps] owned by caller
    #[doc(alias = "gst_audio_encoder_proxy_getcaps")]
    fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps {
        unsafe {
            from_glib_full(ffi::gst_audio_encoder_proxy_getcaps(
                self.as_ref().to_glib_none().0,
                caps.to_glib_none().0,
                filter.to_glib_none().0,
            ))
        }
    }

    /// Sets a caps in allocation query which are different from the set
    /// pad's caps. Use this function before calling
    /// [`AudioEncoderExtManual::negotiate()`][crate::prelude::AudioEncoderExtManual::negotiate()]. Setting to [`None`] the allocation
    /// query will use the caps from the pad.
    /// ## `allocation_caps`
    /// a [`gst::Caps`][crate::gst::Caps] or [`None`]
    #[doc(alias = "gst_audio_encoder_set_allocation_caps")]
    fn set_allocation_caps(&self, allocation_caps: Option<&gst::Caps>) {
        unsafe {
            ffi::gst_audio_encoder_set_allocation_caps(
                self.as_ref().to_glib_none().0,
                allocation_caps.to_glib_none().0,
            );
        }
    }

    /// Configures encoder drain handling. If drainable, subclass might
    /// be handed a NULL buffer to have it return any leftover encoded data.
    /// Otherwise, it is not considered so capable and will only ever be passed
    /// real data.
    ///
    /// MT safe.
    /// ## `enabled`
    /// new state
    #[doc(alias = "gst_audio_encoder_set_drainable")]
    fn set_drainable(&self, enabled: bool) {
        unsafe {
            ffi::gst_audio_encoder_set_drainable(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Sets max number of frames accepted at once (assumed minimally 1).
    /// Requires `frame_samples_min` and `frame_samples_max` to be the equal.
    ///
    /// Note: This value will be reset to 0 every time before
    /// `GstAudioEncoderClass.set_format()` is called.
    /// ## `num`
    /// number of frames
    #[doc(alias = "gst_audio_encoder_set_frame_max")]
    fn set_frame_max(&self, num: i32) {
        unsafe {
            ffi::gst_audio_encoder_set_frame_max(self.as_ref().to_glib_none().0, num);
        }
    }

    /// Sets number of samples (per channel) subclass needs to be handed,
    /// at most or will be handed all available if 0.
    ///
    /// If an exact number of samples is required, [`set_frame_samples_min()`][Self::set_frame_samples_min()]
    /// must be called with the same number.
    ///
    /// Note: This value will be reset to 0 every time before
    /// `GstAudioEncoderClass.set_format()` is called.
    /// ## `num`
    /// number of samples per frame
    #[doc(alias = "gst_audio_encoder_set_frame_samples_max")]
    fn set_frame_samples_max(&self, num: i32) {
        unsafe {
            ffi::gst_audio_encoder_set_frame_samples_max(self.as_ref().to_glib_none().0, num);
        }
    }

    /// Sets number of samples (per channel) subclass needs to be handed,
    /// at least or will be handed all available if 0.
    ///
    /// If an exact number of samples is required, [`set_frame_samples_max()`][Self::set_frame_samples_max()]
    /// must be called with the same number.
    ///
    /// Note: This value will be reset to 0 every time before
    /// `GstAudioEncoderClass.set_format()` is called.
    /// ## `num`
    /// number of samples per frame
    #[doc(alias = "gst_audio_encoder_set_frame_samples_min")]
    fn set_frame_samples_min(&self, num: i32) {
        unsafe {
            ffi::gst_audio_encoder_set_frame_samples_min(self.as_ref().to_glib_none().0, num);
        }
    }

    /// Configures encoder hard minimum handling. If enabled, subclass
    /// will never be handed less samples than it configured, which otherwise
    /// might occur near end-of-data handling. Instead, the leftover samples
    /// will simply be discarded.
    ///
    /// MT safe.
    /// ## `enabled`
    /// new state
    #[doc(alias = "gst_audio_encoder_set_hard_min")]
    fn set_hard_min(&self, enabled: bool) {
        unsafe {
            ffi::gst_audio_encoder_set_hard_min(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    #[doc(alias = "gst_audio_encoder_set_hard_resync")]
    fn set_hard_resync(&self, enabled: bool) {
        unsafe {
            ffi::gst_audio_encoder_set_hard_resync(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Sets encoder latency. If the provided values changed from
    /// previously provided ones, this will also post a LATENCY message on the bus
    /// so the pipeline can reconfigure its global latency.
    /// ## `min`
    /// minimum latency
    /// ## `max`
    /// maximum latency
    #[doc(alias = "gst_audio_encoder_set_latency")]
    fn set_latency(&self, min: gst::ClockTime, max: impl Into<Option<gst::ClockTime>>) {
        unsafe {
            ffi::gst_audio_encoder_set_latency(
                self.as_ref().to_glib_none().0,
                min.into_glib(),
                max.into().into_glib(),
            );
        }
    }

    /// Sets encoder lookahead (in units of input rate samples)
    ///
    /// Note: This value will be reset to 0 every time before
    /// `GstAudioEncoderClass.set_format()` is called.
    /// ## `num`
    /// lookahead
    #[doc(alias = "gst_audio_encoder_set_lookahead")]
    fn set_lookahead(&self, num: i32) {
        unsafe {
            ffi::gst_audio_encoder_set_lookahead(self.as_ref().to_glib_none().0, num);
        }
    }

    /// Enable or disable encoder granule handling.
    ///
    /// MT safe.
    /// ## `enabled`
    /// new state
    #[doc(alias = "gst_audio_encoder_set_mark_granule")]
    fn set_mark_granule(&self, enabled: bool) {
        unsafe {
            ffi::gst_audio_encoder_set_mark_granule(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Enable or disable encoder perfect output timestamp preference.
    ///
    /// MT safe.
    /// ## `enabled`
    /// new state
    #[doc(alias = "gst_audio_encoder_set_perfect_timestamp")]
    fn set_perfect_timestamp(&self, enabled: bool) {
        unsafe {
            ffi::gst_audio_encoder_set_perfect_timestamp(
                self.as_ref().to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    /// Configures encoder audio jitter tolerance threshold.
    ///
    /// MT safe.
    /// ## `tolerance`
    /// new tolerance
    #[doc(alias = "gst_audio_encoder_set_tolerance")]
    fn set_tolerance(&self, tolerance: gst::ClockTime) {
        unsafe {
            ffi::gst_audio_encoder_set_tolerance(
                self.as_ref().to_glib_none().0,
                tolerance.into_glib(),
            );
        }
    }

    #[doc(alias = "hard-resync")]
    fn connect_hard_resync_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_hard_resync_trampoline<
            P: IsA<AudioEncoder>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstAudioEncoder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::hard-resync\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_hard_resync_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "mark-granule")]
    fn connect_mark_granule_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_mark_granule_trampoline<
            P: IsA<AudioEncoder>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstAudioEncoder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::mark-granule\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_mark_granule_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "perfect-timestamp")]
    fn connect_perfect_timestamp_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_perfect_timestamp_trampoline<
            P: IsA<AudioEncoder>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstAudioEncoder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::perfect-timestamp\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_perfect_timestamp_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "tolerance")]
    fn connect_tolerance_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_tolerance_trampoline<
            P: IsA<AudioEncoder>,
            F: Fn(&P) + Send + Sync + 'static,
        >(
            this: *mut ffi::GstAudioEncoder,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(AudioEncoder::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::tolerance\0".as_ptr() as *const _,
                Some(std::mem::transmute::<_, unsafe extern "C" fn()>(
                    notify_tolerance_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<AudioEncoder>> AudioEncoderExt for O {}