gstreamer_audio/
audio_stream_align.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::mem;
4
5use glib::translate::*;
6
7use crate::AudioStreamAlign;
8
9impl AudioStreamAlign {
10    /// Processes data with `timestamp` and `n_samples`, and returns the output
11    /// timestamp, duration and sample position together with a boolean to signal
12    /// whether a discontinuity was detected or not. All non-discontinuous data
13    /// will have perfect timestamps and durations.
14    ///
15    /// A discontinuity is detected once the difference between the actual
16    /// timestamp and the timestamp calculated from the sample count since the last
17    /// discontinuity differs by more than the alignment threshold for a duration
18    /// longer than discont wait.
19    ///
20    /// Note: In reverse playback, every buffer is considered discontinuous in the
21    /// context of buffer flags because the last sample of the previous buffer is
22    /// discontinuous with the first sample of the current one. However for this
23    /// function they are only considered discontinuous in reverse playback if the
24    /// first sample of the previous buffer is discontinuous with the last sample
25    /// of the current one.
26    /// ## `discont`
27    /// if this data is considered to be discontinuous
28    /// ## `timestamp`
29    /// a `GstClockTime` of the start of the data
30    /// ## `n_samples`
31    /// number of samples to process
32    ///
33    /// # Returns
34    ///
35    /// [`true`] if a discontinuity was detected, [`false`] otherwise.
36    ///
37    /// ## `out_timestamp`
38    /// output timestamp of the data
39    ///
40    /// ## `out_duration`
41    /// output duration of the data
42    ///
43    /// ## `out_sample_position`
44    /// output sample position of the start of the data
45    #[doc(alias = "gst_audio_stream_align_process")]
46    pub fn process(
47        &mut self,
48        discont: bool,
49        timestamp: gst::ClockTime,
50        n_samples: u32,
51    ) -> (bool, gst::ClockTime, gst::ClockTime, u64) {
52        unsafe {
53            let mut out_timestamp = mem::MaybeUninit::uninit();
54            let mut out_duration = mem::MaybeUninit::uninit();
55            let mut out_sample_position = mem::MaybeUninit::uninit();
56            let ret = from_glib(crate::ffi::gst_audio_stream_align_process(
57                self.to_glib_none_mut().0,
58                discont.into_glib(),
59                timestamp.into_glib(),
60                n_samples,
61                out_timestamp.as_mut_ptr(),
62                out_duration.as_mut_ptr(),
63                out_sample_position.as_mut_ptr(),
64            ));
65            (
66                ret,
67                try_from_glib(out_timestamp.assume_init()).expect("undefined out_timestamp"),
68                try_from_glib(out_duration.assume_init()).expect("undefined out_duration"),
69                out_sample_position.assume_init(),
70            )
71        }
72    }
73}