Add GstStreamVolume interface

This commit is contained in:
Sebastian Dröge 2017-08-10 01:28:29 +03:00
parent fefa4819cd
commit a411ae4173
5 changed files with 114 additions and 3 deletions

View file

@ -21,6 +21,8 @@ generate = [
"GstAudio.AudioLayout",
"GstAudio.AudioPackFlags",
"GstAudio.AudioChannelPosition",
"GstAudio.StreamVolume",
"GstAudio.StreamVolumeFormat",
]
manual = [

View file

@ -1,4 +1,4 @@
// This file was generated by gir (3294959+) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;
@ -357,3 +357,39 @@ impl SetValue for AudioLayout {
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum StreamVolumeFormat {
Linear,
Cubic,
Db,
#[doc(hidden)]
__Unknown(i32),
}
#[doc(hidden)]
impl ToGlib for StreamVolumeFormat {
type GlibType = ffi::GstStreamVolumeFormat;
fn to_glib(&self) -> ffi::GstStreamVolumeFormat {
match *self {
StreamVolumeFormat::Linear => ffi::GST_STREAM_VOLUME_FORMAT_LINEAR,
StreamVolumeFormat::Cubic => ffi::GST_STREAM_VOLUME_FORMAT_CUBIC,
StreamVolumeFormat::Db => ffi::GST_STREAM_VOLUME_FORMAT_DB,
StreamVolumeFormat::__Unknown(value) => unsafe{std::mem::transmute(value)}
}
}
}
#[doc(hidden)]
impl FromGlib<ffi::GstStreamVolumeFormat> for StreamVolumeFormat {
fn from_glib(value: ffi::GstStreamVolumeFormat) -> Self {
skip_assert_initialized!();
match value as i32 {
0 => StreamVolumeFormat::Linear,
1 => StreamVolumeFormat::Cubic,
2 => StreamVolumeFormat::Db,
value => StreamVolumeFormat::__Unknown(value),
}
}
}

View file

@ -1,4 +1,4 @@
// This file was generated by gir (3294959+) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use ffi;

View file

@ -1,10 +1,15 @@
// This file was generated by gir (3294959+) from gir-files (???)
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
mod stream_volume;
pub use self::stream_volume::StreamVolume;
pub use self::stream_volume::StreamVolumeExt;
mod enums;
pub use self::enums::AudioChannelPosition;
pub use self::enums::AudioFormat;
pub use self::enums::AudioLayout;
pub use self::enums::StreamVolumeFormat;
mod flags;
pub use self::flags::AudioFlags;
@ -22,4 +27,5 @@ pub use self::flags::AUDIO_PACK_FLAG_TRUNCATE_RANGE;
#[doc(hidden)]
pub mod traits {
pub use super::StreamVolumeExt;
}

View file

@ -0,0 +1,67 @@
// This file was generated by gir (3294959) from gir-files (???)
// DO NOT EDIT
use StreamVolumeFormat;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;
glib_wrapper! {
pub struct StreamVolume(Object<ffi::GstStreamVolume>);
match fn {
get_type => || ffi::gst_stream_volume_get_type(),
}
}
impl StreamVolume {
pub fn convert_volume(from: StreamVolumeFormat, to: StreamVolumeFormat, val: f64) -> f64 {
assert_initialized_main_thread!();
unsafe {
ffi::gst_stream_volume_convert_volume(from.to_glib(), to.to_glib(), val)
}
}
}
unsafe impl Send for StreamVolume {}
unsafe impl Sync for StreamVolume {}
pub trait StreamVolumeExt {
fn get_mute(&self) -> bool;
fn get_volume(&self, format: StreamVolumeFormat) -> f64;
fn set_mute(&self, mute: bool);
fn set_volume(&self, format: StreamVolumeFormat, val: f64);
}
impl<O: IsA<StreamVolume>> StreamVolumeExt for O {
fn get_mute(&self) -> bool {
unsafe {
from_glib(ffi::gst_stream_volume_get_mute(self.to_glib_none().0))
}
}
fn get_volume(&self, format: StreamVolumeFormat) -> f64 {
unsafe {
ffi::gst_stream_volume_get_volume(self.to_glib_none().0, format.to_glib())
}
}
fn set_mute(&self, mute: bool) {
unsafe {
ffi::gst_stream_volume_set_mute(self.to_glib_none().0, mute.to_glib());
}
}
fn set_volume(&self, format: StreamVolumeFormat, val: f64) {
unsafe {
ffi::gst_stream_volume_set_volume(self.to_glib_none().0, format.to_glib(), val);
}
}
}