gstreamer_sdp/
sdp_bandwidth.rs
1use std::{ffi::CStr, fmt, mem};
4
5use crate::ffi;
6use glib::translate::*;
7
8#[repr(transparent)]
9#[doc(alias = "GstSDPBandwidth")]
10pub struct SDPBandwidth(pub(crate) ffi::GstSDPBandwidth);
11
12unsafe impl Send for SDPBandwidth {}
13unsafe impl Sync for SDPBandwidth {}
14
15impl SDPBandwidth {
16 pub fn new(bwtype: &str, bandwidth: u32) -> Self {
17 assert_initialized_main_thread!();
18 unsafe {
19 let mut bw = mem::MaybeUninit::uninit();
20 ffi::gst_sdp_bandwidth_set(bw.as_mut_ptr(), bwtype.to_glib_none().0, bandwidth);
21 SDPBandwidth(bw.assume_init())
22 }
23 }
24
25 pub fn bwtype(&self) -> Option<&str> {
26 unsafe {
27 if self.0.bwtype.is_null() {
28 None
29 } else {
30 Some(CStr::from_ptr(self.0.bwtype).to_str().unwrap())
31 }
32 }
33 }
34
35 pub fn value(&self) -> u32 {
36 self.0.bandwidth
37 }
38}
39
40impl Clone for SDPBandwidth {
41 fn clone(&self) -> Self {
42 skip_assert_initialized!();
43 unsafe {
44 let mut bw = mem::MaybeUninit::uninit();
45 ffi::gst_sdp_bandwidth_set(bw.as_mut_ptr(), self.0.bwtype, self.0.bandwidth);
46 SDPBandwidth(bw.assume_init())
47 }
48 }
49}
50
51impl Drop for SDPBandwidth {
52 fn drop(&mut self) {
53 unsafe {
54 ffi::gst_sdp_bandwidth_clear(&mut self.0);
55 }
56 }
57}
58
59impl fmt::Debug for SDPBandwidth {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 f.debug_struct("SDPBandwidth")
62 .field("bwtype", &self.bwtype())
63 .field("value", &self.value())
64 .finish()
65 }
66}