gstreamer_audio/auto/
stream_volume.rs1use crate::{ffi, StreamVolumeFormat};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstStreamVolume")]
16 pub struct StreamVolume(Interface<ffi::GstStreamVolume, ffi::GstStreamVolumeInterface>);
17
18 match fn {
19 type_ => || ffi::gst_stream_volume_get_type(),
20 }
21}
22
23impl StreamVolume {
24 pub const NONE: Option<&'static StreamVolume> = None;
25
26 #[doc(alias = "gst_stream_volume_convert_volume")]
27 pub fn convert_volume(from: StreamVolumeFormat, to: StreamVolumeFormat, val: f64) -> f64 {
28 assert_initialized_main_thread!();
29 unsafe { ffi::gst_stream_volume_convert_volume(from.into_glib(), to.into_glib(), val) }
30 }
31}
32
33unsafe impl Send for StreamVolume {}
34unsafe impl Sync for StreamVolume {}
35
36pub trait StreamVolumeExt: IsA<StreamVolume> + 'static {
37 #[doc(alias = "gst_stream_volume_get_mute")]
38 #[doc(alias = "get_mute")]
39 #[doc(alias = "mute")]
40 fn is_muted(&self) -> bool {
41 unsafe {
42 from_glib(ffi::gst_stream_volume_get_mute(
43 self.as_ref().to_glib_none().0,
44 ))
45 }
46 }
47
48 #[doc(alias = "gst_stream_volume_get_volume")]
49 #[doc(alias = "get_volume")]
50 fn volume(&self, format: StreamVolumeFormat) -> f64 {
51 unsafe {
52 ffi::gst_stream_volume_get_volume(self.as_ref().to_glib_none().0, format.into_glib())
53 }
54 }
55
56 #[doc(alias = "gst_stream_volume_set_mute")]
57 #[doc(alias = "mute")]
58 fn set_mute(&self, mute: bool) {
59 unsafe {
60 ffi::gst_stream_volume_set_mute(self.as_ref().to_glib_none().0, mute.into_glib());
61 }
62 }
63
64 #[doc(alias = "gst_stream_volume_set_volume")]
65 #[doc(alias = "volume")]
66 fn set_volume(&self, format: StreamVolumeFormat, val: f64) {
67 unsafe {
68 ffi::gst_stream_volume_set_volume(
69 self.as_ref().to_glib_none().0,
70 format.into_glib(),
71 val,
72 );
73 }
74 }
75
76 #[doc(alias = "mute")]
77 fn connect_mute_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
78 unsafe extern "C" fn notify_mute_trampoline<
79 P: IsA<StreamVolume>,
80 F: Fn(&P) + Send + Sync + 'static,
81 >(
82 this: *mut ffi::GstStreamVolume,
83 _param_spec: glib::ffi::gpointer,
84 f: glib::ffi::gpointer,
85 ) {
86 let f: &F = &*(f as *const F);
87 f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
88 }
89 unsafe {
90 let f: Box_<F> = Box_::new(f);
91 connect_raw(
92 self.as_ptr() as *mut _,
93 c"notify::mute".as_ptr() as *const _,
94 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
95 notify_mute_trampoline::<Self, F> as *const (),
96 )),
97 Box_::into_raw(f),
98 )
99 }
100 }
101
102 #[doc(alias = "volume")]
103 fn connect_volume_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
104 unsafe extern "C" fn notify_volume_trampoline<
105 P: IsA<StreamVolume>,
106 F: Fn(&P) + Send + Sync + 'static,
107 >(
108 this: *mut ffi::GstStreamVolume,
109 _param_spec: glib::ffi::gpointer,
110 f: glib::ffi::gpointer,
111 ) {
112 let f: &F = &*(f as *const F);
113 f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
114 }
115 unsafe {
116 let f: Box_<F> = Box_::new(f);
117 connect_raw(
118 self.as_ptr() as *mut _,
119 c"notify::volume".as_ptr() as *const _,
120 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
121 notify_volume_trampoline::<Self, F> as *const (),
122 )),
123 Box_::into_raw(f),
124 )
125 }
126 }
127}
128
129impl<O: IsA<StreamVolume>> StreamVolumeExt for O {}