gstreamer_audio/
audio_ring_buffer_spec.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use glib::translate::*;
6use gst::Caps;
7
8use crate::{ffi, AudioInfo, AudioRingBufferFormatType};
9
10/// The structure containing the format specification of the ringbuffer.
11///
12/// When `type` is GST_AUDIO_RING_BUFFER_FORMAT_TYPE_DSD, the `dsd_format`
13/// is valid (otherwise it is unused). Also, when DSD is the sample type,
14/// only the rate, channels, position, and bpf fields in `info` are populated.
15#[repr(transparent)]
16#[doc(alias = "GstAudioRingBufferSpec")]
17pub struct AudioRingBufferSpec(pub(crate) ffi::GstAudioRingBufferSpec);
18
19impl AudioRingBufferSpec {
20    #[doc(alias = "get_type")]
21    #[inline]
22    pub fn type_(&self) -> AudioRingBufferFormatType {
23        unsafe { AudioRingBufferFormatType::from_glib(self.0.type_) }
24    }
25
26    #[inline]
27    pub fn set_type(&mut self, value: AudioRingBufferFormatType) {
28        self.0.type_ = value.into_glib();
29    }
30
31    #[doc(alias = "get_caps")]
32    #[inline]
33    pub fn caps(&self) -> Caps {
34        unsafe { Caps::from_glib_none(self.0.caps) }
35    }
36
37    #[doc(alias = "get_audio_info")]
38    #[inline]
39    pub fn audio_info(&self) -> AudioInfo {
40        unsafe { AudioInfo::from_glib_none(&self.0.info as *const ffi::GstAudioInfo) }
41    }
42
43    #[doc(alias = "get_latency_time")]
44    #[inline]
45    pub fn latency_time(&self) -> u64 {
46        self.0.latency_time
47    }
48
49    #[inline]
50    pub fn set_latency_time(&mut self, value: u64) {
51        self.0.latency_time = value;
52    }
53
54    #[doc(alias = "get_buffer_time")]
55    #[inline]
56    pub fn buffer_time(&self) -> u64 {
57        self.0.buffer_time
58    }
59
60    #[inline]
61    pub fn set_buffer_time(&mut self, value: u64) {
62        self.0.buffer_time = value;
63    }
64
65    #[doc(alias = "get_segsize")]
66    #[inline]
67    pub fn segsize(&self) -> i32 {
68        self.0.segsize
69    }
70
71    #[inline]
72    pub fn set_segsize(&mut self, value: i32) {
73        self.0.segsize = value;
74    }
75
76    #[doc(alias = "get_segtotal")]
77    #[inline]
78    pub fn segtotal(&self) -> i32 {
79        self.0.segtotal
80    }
81
82    #[inline]
83    pub fn set_segtotal(&mut self, value: i32) {
84        self.0.segtotal = value;
85    }
86
87    #[doc(alias = "get_seglatency")]
88    #[inline]
89    pub fn seglatency(&self) -> i32 {
90        self.0.seglatency
91    }
92
93    #[inline]
94    pub fn set_seglatency(&mut self, value: i32) {
95        self.0.seglatency = value;
96    }
97}
98
99impl Clone for AudioRingBufferSpec {
100    #[inline]
101    fn clone(&self) -> Self {
102        unsafe {
103            let spec = self.0;
104            gst::ffi::gst_mini_object_ref(spec.caps as *mut gst::ffi::GstMiniObject);
105
106            Self(spec)
107        }
108    }
109}
110
111impl Drop for AudioRingBufferSpec {
112    #[inline]
113    fn drop(&mut self) {
114        unsafe {
115            gst::ffi::gst_mini_object_unref(self.0.caps as *mut gst::ffi::GstMiniObject);
116        }
117    }
118}
119
120unsafe impl Send for AudioRingBufferSpec {}
121unsafe impl Sync for AudioRingBufferSpec {}
122
123impl fmt::Debug for AudioRingBufferSpec {
124    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125        f.debug_struct("AudioRingBufferSpec")
126            .field("type", &self.type_())
127            .field("caps", &self.caps())
128            .field("audio_info", &self.audio_info())
129            .field("latency_time", &self.latency_time())
130            .field("buffer_time", &self.buffer_time())
131            .field("segsize", &self.segsize())
132            .field("segtotal", &self.segtotal())
133            .field("seglatency", &self.seglatency())
134            .finish()
135    }
136}