Skip to main content

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::{StreamVolumeFormat, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
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            unsafe {
87                let f: &F = &*(f as *const F);
88                f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
89            }
90        }
91        unsafe {
92            let f: Box_<F> = Box_::new(f);
93            connect_raw(
94                self.as_ptr() as *mut _,
95                c"notify::mute".as_ptr(),
96                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
97                    notify_mute_trampoline::<Self, F> as *const (),
98                )),
99                Box_::into_raw(f),
100            )
101        }
102    }
103
104    #[doc(alias = "volume")]
105    fn connect_volume_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
106        unsafe extern "C" fn notify_volume_trampoline<
107            P: IsA<StreamVolume>,
108            F: Fn(&P) + Send + Sync + 'static,
109        >(
110            this: *mut ffi::GstStreamVolume,
111            _param_spec: glib::ffi::gpointer,
112            f: glib::ffi::gpointer,
113        ) {
114            unsafe {
115                let f: &F = &*(f as *const F);
116                f(StreamVolume::from_glib_borrow(this).unsafe_cast_ref())
117            }
118        }
119        unsafe {
120            let f: Box_<F> = Box_::new(f);
121            connect_raw(
122                self.as_ptr() as *mut _,
123                c"notify::volume".as_ptr(),
124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125                    notify_volume_trampoline::<Self, F> as *const (),
126                )),
127                Box_::into_raw(f),
128            )
129        }
130    }
131}
132
133impl<O: IsA<StreamVolume>> StreamVolumeExt for O {}