gstreamer_audio/auto/
stream_volume.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use 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
36mod sealed {
37    pub trait Sealed {}
38    impl<T: super::IsA<super::StreamVolume>> Sealed for T {}
39}
40
41pub trait StreamVolumeExt: IsA<StreamVolume> + sealed::Sealed + 'static {
42    #[doc(alias = "gst_stream_volume_get_mute")]
43    #[doc(alias = "get_mute")]
44    #[doc(alias = "mute")]
45    fn is_muted(&self) -> bool {
46        unsafe {
47            from_glib(ffi::gst_stream_volume_get_mute(
48                self.as_ref().to_glib_none().0,
49            ))
50        }
51    }
52
53    #[doc(alias = "gst_stream_volume_get_volume")]
54    #[doc(alias = "get_volume")]
55    fn volume(&self, format: StreamVolumeFormat) -> f64 {
56        unsafe {
57            ffi::gst_stream_volume_get_volume(self.as_ref().to_glib_none().0, format.into_glib())
58        }
59    }
60
61    #[doc(alias = "gst_stream_volume_set_mute")]
62    #[doc(alias = "mute")]
63    fn set_mute(&self, mute: bool) {
64        unsafe {
65            ffi::gst_stream_volume_set_mute(self.as_ref().to_glib_none().0, mute.into_glib());
66        }
67    }
68
69    #[doc(alias = "gst_stream_volume_set_volume")]
70    #[doc(alias = "volume")]
71    fn set_volume(&self, format: StreamVolumeFormat, val: f64) {
72        unsafe {
73            ffi::gst_stream_volume_set_volume(
74                self.as_ref().to_glib_none().0,
75                format.into_glib(),
76                val,
77            );
78        }
79    }
80
81    #[doc(alias = "mute")]
82    fn connect_mute_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
83        unsafe extern "C" fn notify_mute_trampoline<
84            P: IsA<StreamVolume>,
85            F: Fn(&P) + Send + Sync + 'static,
86        >(
87            this: *mut ffi::GstStreamVolume,
88            _param_spec: glib::ffi::gpointer,
89            f: glib::ffi::gpointer,
90        ) {
91            let f: &F = &*(f as *const F);
92            f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
93        }
94        unsafe {
95            let f: Box_<F> = Box_::new(f);
96            connect_raw(
97                self.as_ptr() as *mut _,
98                b"notify::mute\0".as_ptr() as *const _,
99                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
100                    notify_mute_trampoline::<Self, F> as *const (),
101                )),
102                Box_::into_raw(f),
103            )
104        }
105    }
106
107    #[doc(alias = "volume")]
108    fn connect_volume_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
109        unsafe extern "C" fn notify_volume_trampoline<
110            P: IsA<StreamVolume>,
111            F: Fn(&P) + Send + Sync + 'static,
112        >(
113            this: *mut ffi::GstStreamVolume,
114            _param_spec: glib::ffi::gpointer,
115            f: glib::ffi::gpointer,
116        ) {
117            let f: &F = &*(f as *const F);
118            f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
119        }
120        unsafe {
121            let f: Box_<F> = Box_::new(f);
122            connect_raw(
123                self.as_ptr() as *mut _,
124                b"notify::volume\0".as_ptr() as *const _,
125                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
126                    notify_volume_trampoline::<Self, F> as *const (),
127                )),
128                Box_::into_raw(f),
129            )
130        }
131    }
132}
133
134impl<O: IsA<StreamVolume>> StreamVolumeExt for O {}