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
// Take a look at the license at the top of the repository in the LICENSE file.

use std::fmt;

use glib::translate::*;
use gst::Caps;

use crate::{ffi, AudioInfo, AudioRingBufferFormatType};

/// The structure containing the format specification of the ringbuffer.
///
/// When `type` is GST_AUDIO_RING_BUFFER_FORMAT_TYPE_DSD, the `dsd_format`
/// is valid (otherwise it is unused). Also, when DSD is the sample type,
/// only the rate, channels, position, and bpf fields in `info` are populated.
#[repr(transparent)]
#[doc(alias = "GstAudioRingBufferSpec")]
pub struct AudioRingBufferSpec(pub(crate) ffi::GstAudioRingBufferSpec);

impl AudioRingBufferSpec {
    #[doc(alias = "get_type")]
    #[inline]
    pub fn type_(&self) -> AudioRingBufferFormatType {
        unsafe { AudioRingBufferFormatType::from_glib(self.0.type_) }
    }

    #[inline]
    pub fn set_type(&mut self, value: AudioRingBufferFormatType) {
        self.0.type_ = value.into_glib();
    }

    #[doc(alias = "get_caps")]
    #[inline]
    pub fn caps(&self) -> Caps {
        unsafe { Caps::from_glib_none(self.0.caps) }
    }

    #[doc(alias = "get_audio_info")]
    #[inline]
    pub fn audio_info(&self) -> AudioInfo {
        unsafe { AudioInfo::from_glib_none(&self.0.info as *const ffi::GstAudioInfo) }
    }

    #[doc(alias = "get_latency_time")]
    #[inline]
    pub fn latency_time(&self) -> u64 {
        self.0.latency_time
    }

    #[inline]
    pub fn set_latency_time(&mut self, value: u64) {
        self.0.latency_time = value;
    }

    #[doc(alias = "get_buffer_time")]
    #[inline]
    pub fn buffer_time(&self) -> u64 {
        self.0.buffer_time
    }

    #[inline]
    pub fn set_buffer_time(&mut self, value: u64) {
        self.0.buffer_time = value;
    }

    #[doc(alias = "get_segsize")]
    #[inline]
    pub fn segsize(&self) -> i32 {
        self.0.segsize
    }

    #[inline]
    pub fn set_segsize(&mut self, value: i32) {
        self.0.segsize = value;
    }

    #[doc(alias = "get_segtotal")]
    #[inline]
    pub fn segtotal(&self) -> i32 {
        self.0.segtotal
    }

    #[inline]
    pub fn set_segtotal(&mut self, value: i32) {
        self.0.segtotal = value;
    }

    #[doc(alias = "get_seglatency")]
    #[inline]
    pub fn seglatency(&self) -> i32 {
        self.0.seglatency
    }

    #[inline]
    pub fn set_seglatency(&mut self, value: i32) {
        self.0.seglatency = value;
    }
}

impl Clone for AudioRingBufferSpec {
    #[inline]
    fn clone(&self) -> Self {
        unsafe {
            let spec = self.0;
            gst::ffi::gst_mini_object_ref(spec.caps as *mut gst::ffi::GstMiniObject);

            Self(spec)
        }
    }
}

impl Drop for AudioRingBufferSpec {
    #[inline]
    fn drop(&mut self) {
        unsafe {
            gst::ffi::gst_mini_object_unref(self.0.caps as *mut gst::ffi::GstMiniObject);
        }
    }
}

unsafe impl Send for AudioRingBufferSpec {}
unsafe impl Sync for AudioRingBufferSpec {}

impl fmt::Debug for AudioRingBufferSpec {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("AudioRingBufferSpec")
            .field("type", &self.type_())
            .field("caps", &self.caps())
            .field("audio_info", &self.audio_info())
            .field("latency_time", &self.latency_time())
            .field("buffer_time", &self.buffer_time())
            .field("segsize", &self.segsize())
            .field("segtotal", &self.segtotal())
            .field("seglatency", &self.seglatency())
            .finish()
    }
}