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
// Copyright (C) 2018 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use gst_audio_sys;
use AudioStreamAlign;

use glib::translate::*;
use gst;
use std::mem;

impl AudioStreamAlign {
    /// Processes data with `timestamp` and `n_samples`, and returns the output
    /// timestamp, duration and sample position together with a boolean to signal
    /// whether a discontinuity was detected or not. All non-discontinuous data
    /// will have perfect timestamps and durations.
    ///
    /// A discontinuity is detected once the difference between the actual
    /// timestamp and the timestamp calculated from the sample count since the last
    /// discontinuity differs by more than the alignment threshold for a duration
    /// longer than discont wait.
    ///
    /// Note: In reverse playback, every buffer is considered discontinuous in the
    /// context of buffer flags because the last sample of the previous buffer is
    /// discontinuous with the first sample of the current one. However for this
    /// function they are only considered discontinuous in reverse playback if the
    /// first sample of the previous buffer is discontinuous with the last sample
    /// of the current one.
    ///
    /// Feature: `v1_14`
    ///
    /// ## `discont`
    /// if this data is considered to be discontinuous
    /// ## `timestamp`
    /// a `gst::ClockTime` of the start of the data
    /// ## `n_samples`
    /// number of samples to process
    /// ## `out_timestamp`
    /// output timestamp of the data
    /// ## `out_duration`
    /// output duration of the data
    /// ## `out_sample_position`
    /// output sample position of the start of the data
    ///
    /// # Returns
    ///
    /// `true` if a discontinuity was detected, `false` otherwise.
    #[cfg(any(feature = "v1_14", feature = "dox"))]
    pub fn process(
        &mut self,
        discont: bool,
        timestamp: gst::ClockTime,
        n_samples: u32,
    ) -> (bool, gst::ClockTime, gst::ClockTime, u64) {
        unsafe {
            let mut out_timestamp = mem::MaybeUninit::uninit();
            let mut out_duration = mem::MaybeUninit::uninit();
            let mut out_sample_position = mem::MaybeUninit::uninit();
            let ret = from_glib(gst_audio_sys::gst_audio_stream_align_process(
                self.to_glib_none_mut().0,
                discont.to_glib(),
                timestamp.to_glib(),
                n_samples,
                out_timestamp.as_mut_ptr(),
                out_duration.as_mut_ptr(),
                out_sample_position.as_mut_ptr(),
            ));
            (
                ret,
                from_glib(out_timestamp.assume_init()),
                from_glib(out_duration.assume_init()),
                out_sample_position.assume_init(),
            )
        }
    }
}