gstreamer-audio: Update manual code to 2018 edition

This commit is contained in:
Sebastian Dröge 2020-11-21 20:17:20 +02:00
parent 1e489ee1e2
commit 4a928136ed
17 changed files with 713 additions and 833 deletions

View file

@ -11,18 +11,15 @@ homepage = "https://gstreamer.freedesktop.org"
documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer_audio/" documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer_audio/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"] keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs" build = "build.rs"
edition = "2018"
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
bitflags = "1.0" bitflags = "1.0"
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" } ffi = { package = "gstreamer-audio-sys", path = "../gstreamer-audio/sys", features = ["v1_8"] }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer-sys = { path = "../gstreamer/sys", features = ["v1_8"] }
gstreamer-base-sys = { path = "../gstreamer-base/sys", features = ["v1_8"] }
gstreamer-audio-sys = { path = "../gstreamer-audio/sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/gtk-rs" } glib = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer = { path = "../gstreamer" } gst = { package = "gstreamer", path = "../gstreamer" }
gstreamer-base = { path = "../gstreamer-base" } gst-base = { package = "gstreamer-base", path = "../gstreamer-base" }
array-init = "1.0" array-init = "1.0"
once_cell = "1.0" once_cell = "1.0"
@ -34,14 +31,14 @@ itertools = "0.9"
[features] [features]
default = [] default = []
v1_10 = ["gstreamer/v1_10", "gstreamer-base/v1_10", "gstreamer-audio-sys/v1_10"] v1_10 = ["gst/v1_10", "gst-base/v1_10", "ffi/v1_10"]
v1_12 = ["gstreamer/v1_12", "gstreamer-base/v1_12", "gstreamer-audio-sys/v1_12", "v1_10"] v1_12 = ["gst/v1_12", "gst-base/v1_12", "ffi/v1_12", "v1_10"]
v1_14 = ["gstreamer/v1_14", "gstreamer-base/v1_14", "gstreamer-audio-sys/v1_14", "v1_12"] v1_14 = ["gst/v1_14", "gst-base/v1_14", "ffi/v1_14", "v1_12"]
v1_16 = ["gstreamer/v1_16", "gstreamer-base/v1_16", "gstreamer-audio-sys/v1_16", "v1_14"] v1_16 = ["gst/v1_16", "gst-base/v1_16", "ffi/v1_16", "v1_14"]
v1_18 = ["gstreamer/v1_18", "gstreamer-base/v1_18", "gstreamer-audio-sys/v1_18", "v1_16"] v1_18 = ["gst/v1_18", "gst-base/v1_18", "ffi/v1_18", "v1_16"]
embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"] embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"] purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
dox = ["v1_18", "gstreamer-audio-sys/dox", "glib/dox", "gstreamer/dox", "gstreamer-base/dox"] dox = ["v1_18", "ffi/dox", "glib/dox", "gst/dox", "gst-base/dox"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["dox", "embed-lgpl-docs"] features = ["dox", "embed-lgpl-docs"]

View file

@ -6,12 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_audio_sys;
use gst_sys;
use glib;
use glib::translate::{from_glib, Borrowed, FromGlibPtrNone, ToGlibPtr}; use glib::translate::{from_glib, Borrowed, FromGlibPtrNone, ToGlibPtr};
use gst;
use std::fmt; use std::fmt;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -25,9 +20,9 @@ pub enum Writable {}
pub struct AudioBuffer<T> { pub struct AudioBuffer<T> {
// Has to be boxed because it contains self-references // Has to be boxed because it contains self-references
audio_buffer: Box<gst_audio_sys::GstAudioBuffer>, audio_buffer: Box<ffi::GstAudioBuffer>,
buffer: Option<gst::Buffer>, buffer: Option<gst::Buffer>,
info: ::AudioInfo, info: crate::AudioInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -46,7 +41,7 @@ impl<T> fmt::Debug for AudioBuffer<T> {
} }
impl<T> AudioBuffer<T> { impl<T> AudioBuffer<T> {
pub fn info(&self) -> &::AudioInfo { pub fn info(&self) -> &crate::AudioInfo {
&self.info &self.info
} }
@ -54,11 +49,11 @@ impl<T> AudioBuffer<T> {
self.buffer.take().unwrap() self.buffer.take().unwrap()
} }
pub fn format(&self) -> ::AudioFormat { pub fn format(&self) -> crate::AudioFormat {
self.info().format() self.info().format()
} }
pub fn format_info(&self) -> ::AudioFormatInfo { pub fn format_info(&self) -> crate::AudioFormatInfo {
self.info().format_info() self.info().format_info()
} }
@ -70,7 +65,7 @@ impl<T> AudioBuffer<T> {
self.info().rate() self.info().rate()
} }
pub fn layout(&self) -> ::AudioLayout { pub fn layout(&self) -> crate::AudioLayout {
self.info().layout() self.info().layout()
} }
@ -113,7 +108,9 @@ impl<T> AudioBuffer<T> {
pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> { pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> {
if plane >= self.n_planes() { if plane >= self.n_planes() {
return Err(glib_bool_error!("Plane index higher than number of planes")); return Err(glib::glib_bool_error!(
"Plane index higher than number of planes"
));
} }
unsafe { unsafe {
@ -134,7 +131,7 @@ impl<T> AudioBuffer<T> {
} }
} }
pub fn as_ptr(&self) -> *const gst_audio_sys::GstAudioBuffer { pub fn as_ptr(&self) -> *const ffi::GstAudioBuffer {
&*self.audio_buffer &*self.audio_buffer
} }
} }
@ -142,7 +139,7 @@ impl<T> AudioBuffer<T> {
impl<T> Drop for AudioBuffer<T> { impl<T> Drop for AudioBuffer<T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
gst_audio_sys::gst_audio_buffer_unmap(&mut *self.audio_buffer); ffi::gst_audio_buffer_unmap(&mut *self.audio_buffer);
} }
} }
} }
@ -150,7 +147,7 @@ impl<T> Drop for AudioBuffer<T> {
impl AudioBuffer<Readable> { impl AudioBuffer<Readable> {
pub fn from_buffer_readable( pub fn from_buffer_readable(
buffer: gst::Buffer, buffer: gst::Buffer,
info: &::AudioInfo, info: &crate::AudioInfo,
) -> Result<AudioBuffer<Readable>, gst::Buffer> { ) -> Result<AudioBuffer<Readable>, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
@ -158,18 +155,18 @@ impl AudioBuffer<Readable> {
unsafe { unsafe {
let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init()); let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init());
let res: bool = from_glib(gst_audio_sys::gst_audio_buffer_map( let res: bool = from_glib(ffi::gst_audio_buffer_map(
&mut *audio_buffer, &mut *audio_buffer,
info.to_glib_none().0 as *mut _, info.to_glib_none().0 as *mut _,
buffer.to_glib_none().0, buffer.to_glib_none().0,
gst_sys::GST_MAP_READ, gst::ffi::GST_MAP_READ,
)); ));
if !res { if !res {
Err(buffer) Err(buffer)
} else { } else {
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut gst_audio_sys::GstAudioInfo, &audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
); );
Ok(AudioBuffer { Ok(AudioBuffer {
audio_buffer, audio_buffer,
@ -185,7 +182,7 @@ impl AudioBuffer<Readable> {
impl AudioBuffer<Writable> { impl AudioBuffer<Writable> {
pub fn from_buffer_writable( pub fn from_buffer_writable(
buffer: gst::Buffer, buffer: gst::Buffer,
info: &::AudioInfo, info: &crate::AudioInfo,
) -> Result<AudioBuffer<Writable>, gst::Buffer> { ) -> Result<AudioBuffer<Writable>, gst::Buffer> {
skip_assert_initialized!(); skip_assert_initialized!();
@ -193,18 +190,18 @@ impl AudioBuffer<Writable> {
unsafe { unsafe {
let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init()); let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init());
let res: bool = from_glib(gst_audio_sys::gst_audio_buffer_map( let res: bool = from_glib(ffi::gst_audio_buffer_map(
&mut *audio_buffer, &mut *audio_buffer,
info.to_glib_none().0 as *mut _, info.to_glib_none().0 as *mut _,
buffer.to_glib_none().0, buffer.to_glib_none().0,
gst_sys::GST_MAP_READ | gst_sys::GST_MAP_WRITE, gst::ffi::GST_MAP_READ | gst::ffi::GST_MAP_WRITE,
)); ));
if !res { if !res {
Err(buffer) Err(buffer)
} else { } else {
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut gst_audio_sys::GstAudioInfo, &audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
); );
Ok(AudioBuffer { Ok(AudioBuffer {
audio_buffer, audio_buffer,
@ -222,7 +219,9 @@ impl AudioBuffer<Writable> {
pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> { pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> {
if plane >= self.n_planes() { if plane >= self.n_planes() {
return Err(glib_bool_error!("Plane index higher than number of planes")); return Err(glib::glib_bool_error!(
"Plane index higher than number of planes"
));
} }
unsafe { unsafe {
@ -243,19 +242,19 @@ impl AudioBuffer<Writable> {
} }
} }
pub fn as_mut_ptr(&mut self) -> *mut gst_audio_sys::GstAudioBuffer { pub fn as_mut_ptr(&mut self) -> *mut ffi::GstAudioBuffer {
&mut *self.audio_buffer &mut *self.audio_buffer
} }
} }
#[derive(Debug)] #[derive(Debug)]
enum AudioBufferPtr { enum AudioBufferPtr {
Owned(Box<gst_audio_sys::GstAudioBuffer>), Owned(Box<ffi::GstAudioBuffer>),
Borrowed(ptr::NonNull<gst_audio_sys::GstAudioBuffer>), Borrowed(ptr::NonNull<ffi::GstAudioBuffer>),
} }
impl ops::Deref for AudioBufferPtr { impl ops::Deref for AudioBufferPtr {
type Target = gst_audio_sys::GstAudioBuffer; type Target = ffi::GstAudioBuffer;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
match self { match self {
@ -279,20 +278,20 @@ pub struct AudioBufferRef<T> {
// Has to be boxed because it contains self-references // Has to be boxed because it contains self-references
audio_buffer: AudioBufferPtr, audio_buffer: AudioBufferPtr,
buffer: Option<T>, buffer: Option<T>,
info: ::AudioInfo, info: crate::AudioInfo,
unmap: bool, unmap: bool,
} }
impl<T> AudioBufferRef<T> { impl<T> AudioBufferRef<T> {
pub fn info(&self) -> &::AudioInfo { pub fn info(&self) -> &crate::AudioInfo {
&self.info &self.info
} }
pub fn format(&self) -> ::AudioFormat { pub fn format(&self) -> crate::AudioFormat {
self.info().format() self.info().format()
} }
pub fn format_info(&self) -> ::AudioFormatInfo { pub fn format_info(&self) -> crate::AudioFormatInfo {
self.info().format_info() self.info().format_info()
} }
@ -304,7 +303,7 @@ impl<T> AudioBufferRef<T> {
self.info().rate() self.info().rate()
} }
pub fn layout(&self) -> ::AudioLayout { pub fn layout(&self) -> crate::AudioLayout {
self.info().layout() self.info().layout()
} }
@ -343,7 +342,9 @@ impl<T> AudioBufferRef<T> {
pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> { pub fn plane_data(&self, plane: u32) -> Result<&[u8], glib::BoolError> {
if plane >= self.n_planes() { if plane >= self.n_planes() {
return Err(glib_bool_error!("Plane index higher than number of planes")); return Err(glib::glib_bool_error!(
"Plane index higher than number of planes"
));
} }
unsafe { unsafe {
@ -354,19 +355,17 @@ impl<T> AudioBufferRef<T> {
} }
} }
pub fn as_ptr(&self) -> *const gst_audio_sys::GstAudioBuffer { pub fn as_ptr(&self) -> *const ffi::GstAudioBuffer {
&*self.audio_buffer &*self.audio_buffer
} }
} }
impl<'a> AudioBufferRef<&'a gst::BufferRef> { impl<'a> AudioBufferRef<&'a gst::BufferRef> {
pub unsafe fn from_glib_borrow( pub unsafe fn from_glib_borrow(audio_buffer: *const ffi::GstAudioBuffer) -> Borrowed<Self> {
audio_buffer: *const gst_audio_sys::GstAudioBuffer,
) -> Borrowed<Self> {
assert!(!audio_buffer.is_null()); assert!(!audio_buffer.is_null());
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&(*audio_buffer).info as *const _ as *mut gst_audio_sys::GstAudioInfo, &(*audio_buffer).info as *const _ as *mut ffi::GstAudioInfo,
); );
let buffer = gst::BufferRef::from_ptr((*audio_buffer).buffer); let buffer = gst::BufferRef::from_ptr((*audio_buffer).buffer);
Borrowed::new(AudioBufferRef { Borrowed::new(AudioBufferRef {
@ -381,7 +380,7 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
pub fn from_buffer_ref_readable<'b>( pub fn from_buffer_ref_readable<'b>(
buffer: &'a gst::BufferRef, buffer: &'a gst::BufferRef,
info: &'b ::AudioInfo, info: &'b crate::AudioInfo,
) -> Result<AudioBufferRef<&'a gst::BufferRef>, glib::BoolError> { ) -> Result<AudioBufferRef<&'a gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
@ -389,18 +388,18 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
unsafe { unsafe {
let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init()); let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init());
let res: bool = from_glib(gst_audio_sys::gst_audio_buffer_map( let res: bool = from_glib(ffi::gst_audio_buffer_map(
&mut *audio_buffer, &mut *audio_buffer,
info.to_glib_none().0 as *mut _, info.to_glib_none().0 as *mut _,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
gst_sys::GST_MAP_READ, gst::ffi::GST_MAP_READ,
)); ));
if !res { if !res {
Err(glib_bool_error!("Failed to map AudioBuffer")) Err(glib::glib_bool_error!("Failed to map AudioBuffer"))
} else { } else {
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut gst_audio_sys::GstAudioInfo, &audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
); );
Ok(AudioBufferRef { Ok(AudioBufferRef {
audio_buffer: AudioBufferPtr::Owned(audio_buffer), audio_buffer: AudioBufferPtr::Owned(audio_buffer),
@ -418,13 +417,11 @@ impl<'a> AudioBufferRef<&'a gst::BufferRef> {
} }
impl<'a> AudioBufferRef<&'a mut gst::BufferRef> { impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
pub unsafe fn from_glib_borrow_mut( pub unsafe fn from_glib_borrow_mut(audio_buffer: *mut ffi::GstAudioBuffer) -> Borrowed<Self> {
audio_buffer: *mut gst_audio_sys::GstAudioBuffer,
) -> Borrowed<Self> {
assert!(!audio_buffer.is_null()); assert!(!audio_buffer.is_null());
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&(*audio_buffer).info as *const _ as *mut gst_audio_sys::GstAudioInfo, &(*audio_buffer).info as *const _ as *mut ffi::GstAudioInfo,
); );
let buffer = gst::BufferRef::from_mut_ptr((*audio_buffer).buffer); let buffer = gst::BufferRef::from_mut_ptr((*audio_buffer).buffer);
Borrowed::new(AudioBufferRef { Borrowed::new(AudioBufferRef {
@ -437,7 +434,7 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
pub fn from_buffer_ref_writable<'b>( pub fn from_buffer_ref_writable<'b>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
info: &'b ::AudioInfo, info: &'b crate::AudioInfo,
) -> Result<AudioBufferRef<&'a mut gst::BufferRef>, glib::BoolError> { ) -> Result<AudioBufferRef<&'a mut gst::BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
@ -445,18 +442,18 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
unsafe { unsafe {
let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init()); let mut audio_buffer = Box::new(mem::MaybeUninit::zeroed().assume_init());
let res: bool = from_glib(gst_audio_sys::gst_audio_buffer_map( let res: bool = from_glib(ffi::gst_audio_buffer_map(
&mut *audio_buffer, &mut *audio_buffer,
info.to_glib_none().0 as *mut _, info.to_glib_none().0 as *mut _,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
gst_sys::GST_MAP_READ | gst_sys::GST_MAP_WRITE, gst::ffi::GST_MAP_READ | gst::ffi::GST_MAP_WRITE,
)); ));
if !res { if !res {
Err(glib_bool_error!("Failed to map AudioBuffer")) Err(glib::glib_bool_error!("Failed to map AudioBuffer"))
} else { } else {
let info = ::AudioInfo::from_glib_none( let info = crate::AudioInfo::from_glib_none(
&audio_buffer.info as *const _ as *mut gst_audio_sys::GstAudioInfo, &audio_buffer.info as *const _ as *mut ffi::GstAudioInfo,
); );
Ok(AudioBufferRef { Ok(AudioBufferRef {
audio_buffer: AudioBufferPtr::Owned(audio_buffer), audio_buffer: AudioBufferPtr::Owned(audio_buffer),
@ -474,7 +471,9 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> { pub fn plane_data_mut(&mut self, plane: u32) -> Result<&mut [u8], glib::BoolError> {
if plane >= self.n_planes() { if plane >= self.n_planes() {
return Err(glib_bool_error!("Plane index higher than number of planes")); return Err(glib::glib_bool_error!(
"Plane index higher than number of planes"
));
} }
unsafe { unsafe {
@ -485,7 +484,7 @@ impl<'a> AudioBufferRef<&'a mut gst::BufferRef> {
} }
} }
pub fn as_mut_ptr(&mut self) -> *mut gst_audio_sys::GstAudioBuffer { pub fn as_mut_ptr(&mut self) -> *mut ffi::GstAudioBuffer {
&mut *self.audio_buffer &mut *self.audio_buffer
} }
} }
@ -508,7 +507,7 @@ impl<T> Drop for AudioBufferRef<T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
if self.unmap { if self.unmap {
gst_audio_sys::gst_audio_buffer_unmap(&mut *self.audio_buffer); ffi::gst_audio_buffer_unmap(&mut *self.audio_buffer);
} }
} }
} }
@ -517,13 +516,12 @@ impl<T> Drop for AudioBufferRef<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use gst;
#[test] #[test]
fn test_map_read() { fn test_map_read() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.build() .build()
.unwrap(); .unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -553,15 +551,15 @@ mod tests {
fn test_map_read_planar() { fn test_map_read_planar() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved) .layout(crate::AudioLayout::NonInterleaved)
.build() .build()
.unwrap(); .unwrap();
let mut buffer = let mut buffer =
gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::AudioMeta::add(buffer, &info, 48000, &[]).unwrap(); crate::AudioMeta::add(buffer, &info, 48000, &[]).unwrap();
} }
let buffer = AudioBuffer::from_buffer_readable(buffer, &info).unwrap(); let buffer = AudioBuffer::from_buffer_readable(buffer, &info).unwrap();
@ -592,7 +590,7 @@ mod tests {
fn test_map_write() { fn test_map_write() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.build() .build()
.unwrap(); .unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -622,15 +620,15 @@ mod tests {
fn test_map_write_planar() { fn test_map_write_planar() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved) .layout(crate::AudioLayout::NonInterleaved)
.build() .build()
.unwrap(); .unwrap();
let mut buffer = let mut buffer =
gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::AudioMeta::add(buffer, &info, 48000, &[]).unwrap(); crate::AudioMeta::add(buffer, &info, 48000, &[]).unwrap();
} }
let mut buffer = AudioBuffer::from_buffer_writable(buffer, &info).unwrap(); let mut buffer = AudioBuffer::from_buffer_writable(buffer, &info).unwrap();
@ -661,7 +659,7 @@ mod tests {
fn test_map_ref_read() { fn test_map_ref_read() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.build() .build()
.unwrap(); .unwrap();
let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
@ -682,15 +680,15 @@ mod tests {
fn test_map_ref_read_planar() { fn test_map_ref_read_planar() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved) .layout(crate::AudioLayout::NonInterleaved)
.build() .build()
.unwrap(); .unwrap();
let mut buffer = let mut buffer =
gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::AudioMeta::add(buffer, &info, 48000, &[]).unwrap(); crate::AudioMeta::add(buffer, &info, 48000, &[]).unwrap();
} }
let buffer = AudioBufferRef::from_buffer_ref_readable(&buffer, &info).unwrap(); let buffer = AudioBufferRef::from_buffer_ref_readable(&buffer, &info).unwrap();
@ -711,7 +709,7 @@ mod tests {
fn test_map_ref_write() { fn test_map_ref_write() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.build() .build()
.unwrap(); .unwrap();
let mut buffer = let mut buffer =
@ -737,15 +735,15 @@ mod tests {
fn test_map_ref_write_planar() { fn test_map_ref_write_planar() {
gst::init().unwrap(); gst::init().unwrap();
let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) let info = crate::AudioInfo::builder(crate::AUDIO_FORMAT_S16, 48000, 2)
.layout(::AudioLayout::NonInterleaved) .layout(crate::AudioLayout::NonInterleaved)
.build() .build()
.unwrap(); .unwrap();
let mut buffer = let mut buffer =
gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::AudioMeta::add(buffer, &info, 48000, &[]).unwrap(); crate::AudioMeta::add(buffer, &info, 48000, &[]).unwrap();
} }
{ {

View file

@ -6,16 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_audio_sys; use crate::AudioChannelPosition;
use AudioChannelPosition;
use std::mem; use std::mem;
use glib;
use glib::translate::{from_glib, ToGlib}; use glib::translate::{from_glib, ToGlib};
use gst;
use array_init;
impl AudioChannelPosition { impl AudioChannelPosition {
pub fn to_mask(self) -> u64 { pub fn to_mask(self) -> u64 {
@ -35,13 +30,12 @@ impl AudioChannelPosition {
let len = positions.len(); let len = positions.len();
if len > 64 { if len > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let positions_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = let positions_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
array_init::array_init(|i| {
if i >= len as usize { if i >= len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
positions[i].to_glib() positions[i].to_glib()
} }
@ -49,7 +43,7 @@ impl AudioChannelPosition {
unsafe { unsafe {
let mut mask = mem::MaybeUninit::uninit(); let mut mask = mem::MaybeUninit::uninit();
let valid: bool = from_glib(gst_audio_sys::gst_audio_channel_positions_to_mask( let valid: bool = from_glib(ffi::gst_audio_channel_positions_to_mask(
positions_raw.as_ptr() as *mut _, positions_raw.as_ptr() as *mut _,
len as i32, len as i32,
force_order.to_glib(), force_order.to_glib(),
@ -58,7 +52,7 @@ impl AudioChannelPosition {
if valid { if valid {
Ok(mask.assume_init()) Ok(mask.assume_init())
} else { } else {
Err(glib_bool_error!( Err(glib::glib_bool_error!(
"Couldn't convert channel positions to mask" "Couldn't convert channel positions to mask"
)) ))
} }
@ -72,14 +66,14 @@ impl AudioChannelPosition {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
if positions.len() > 64 { if positions.len() > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let len = positions.len(); let len = positions.len();
let mut positions_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = let mut positions_raw: [ffi::GstAudioChannelPosition; 64] =
[gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID; 64]; [ffi::GST_AUDIO_CHANNEL_POSITION_INVALID; 64];
let valid: bool = unsafe { let valid: bool = unsafe {
from_glib(gst_audio_sys::gst_audio_channel_positions_from_mask( from_glib(ffi::gst_audio_channel_positions_from_mask(
len as i32, len as i32,
mask, mask,
positions_raw.as_mut_ptr(), positions_raw.as_mut_ptr(),
@ -92,7 +86,7 @@ impl AudioChannelPosition {
} }
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!( Err(glib::glib_bool_error!(
"Couldn't convert channel positions to mask", "Couldn't convert channel positions to mask",
)) ))
} }
@ -104,21 +98,20 @@ impl AudioChannelPosition {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
if positions.len() > 64 { if positions.len() > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let len = positions.len(); let len = positions.len();
let mut positions_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = let mut positions_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
array_init::array_init(|i| {
if i >= len as usize { if i >= len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
positions[i].to_glib() positions[i].to_glib()
} }
}); });
let valid: bool = unsafe { let valid: bool = unsafe {
from_glib(gst_audio_sys::gst_audio_channel_positions_to_valid_order( from_glib(ffi::gst_audio_channel_positions_to_valid_order(
positions_raw.as_mut_ptr(), positions_raw.as_mut_ptr(),
len as i32, len as i32,
)) ))
@ -130,7 +123,7 @@ impl AudioChannelPosition {
} }
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!( Err(glib::glib_bool_error!(
"Couldn't convert channel positions to mask", "Couldn't convert channel positions to mask",
)) ))
} }
@ -139,11 +132,11 @@ impl AudioChannelPosition {
pub fn get_fallback_mask(channels: u32) -> u64 { pub fn get_fallback_mask(channels: u32) -> u64 {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { gst_audio_sys::gst_audio_channel_get_fallback_mask(channels as i32) } unsafe { ffi::gst_audio_channel_get_fallback_mask(channels as i32) }
} }
pub fn check_valid_channel_positions( pub fn check_valid_channel_positions(
positions: &[::AudioChannelPosition], positions: &[crate::AudioChannelPosition],
force_order: bool, force_order: bool,
) -> bool { ) -> bool {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
@ -153,17 +146,16 @@ impl AudioChannelPosition {
} }
let len = positions.len(); let len = positions.len();
let positions_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = let positions_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
array_init::array_init(|i| {
if i >= len as usize { if i >= len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
positions[i].to_glib() positions[i].to_glib()
} }
}); });
unsafe { unsafe {
from_glib(gst_audio_sys::gst_audio_check_valid_channel_positions( from_glib(ffi::gst_audio_check_valid_channel_positions(
positions_raw.as_ptr() as *mut _, positions_raw.as_ptr() as *mut _,
len as i32, len as i32,
force_order.to_glib(), force_order.to_glib(),
@ -174,7 +166,7 @@ impl AudioChannelPosition {
pub fn buffer_reorder_channels( pub fn buffer_reorder_channels(
buffer: &mut gst::BufferRef, buffer: &mut gst::BufferRef,
format: ::AudioFormat, format: crate::AudioFormat,
channels: u32, channels: u32,
from: &[AudioChannelPosition], from: &[AudioChannelPosition],
to: &[AudioChannelPosition], to: &[AudioChannelPosition],
@ -182,30 +174,30 @@ pub fn buffer_reorder_channels(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
if from.len() != to.len() || from.len() > 64 { if from.len() != to.len() || from.len() > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let from_len = from.len(); let from_len = from.len();
let to_len = to.len(); let to_len = to.len();
let from_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let from_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= from_len as usize { if i >= from_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
from[i].to_glib() from[i].to_glib()
} }
}); });
let to_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let to_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= to_len as usize { if i >= to_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
to[i].to_glib() to[i].to_glib()
} }
}); });
let valid: bool = unsafe { let valid: bool = unsafe {
from_glib(gst_audio_sys::gst_audio_buffer_reorder_channels( from_glib(ffi::gst_audio_buffer_reorder_channels(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
format.to_glib(), format.to_glib(),
channels as i32, channels as i32,
@ -217,13 +209,13 @@ pub fn buffer_reorder_channels(
if valid { if valid {
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!("Failed to reorder channels")) Err(glib::glib_bool_error!("Failed to reorder channels"))
} }
} }
pub fn reorder_channels( pub fn reorder_channels(
data: &mut [u8], data: &mut [u8],
format: ::AudioFormat, format: crate::AudioFormat,
channels: u32, channels: u32,
from: &[AudioChannelPosition], from: &[AudioChannelPosition],
to: &[AudioChannelPosition], to: &[AudioChannelPosition],
@ -231,30 +223,30 @@ pub fn reorder_channels(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
if from.len() != to.len() || from.len() > 64 { if from.len() != to.len() || from.len() > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let from_len = from.len(); let from_len = from.len();
let to_len = to.len(); let to_len = to.len();
let from_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let from_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= from_len as usize { if i >= from_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
from[i].to_glib() from[i].to_glib()
} }
}); });
let to_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let to_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= to_len as usize { if i >= to_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
to[i].to_glib() to[i].to_glib()
} }
}); });
let valid: bool = unsafe { let valid: bool = unsafe {
from_glib(gst_audio_sys::gst_audio_reorder_channels( from_glib(ffi::gst_audio_reorder_channels(
data.as_mut_ptr() as *mut _, data.as_mut_ptr() as *mut _,
data.len(), data.len(),
format.to_glib(), format.to_glib(),
@ -267,7 +259,7 @@ pub fn reorder_channels(
if valid { if valid {
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!("Failed to reorder channels")) Err(glib::glib_bool_error!("Failed to reorder channels"))
} }
} }
@ -279,23 +271,23 @@ pub fn get_channel_reorder_map(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
if from.len() != to.len() || from.len() != reorder_map.len() || from.len() > 64 { if from.len() != to.len() || from.len() != reorder_map.len() || from.len() > 64 {
return Err(glib_bool_error!("Invalid number of channels")); return Err(glib::glib_bool_error!("Invalid number of channels"));
} }
let from_len = from.len(); let from_len = from.len();
let to_len = to.len(); let to_len = to.len();
let from_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let from_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= from_len as usize { if i >= from_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
from[i].to_glib() from[i].to_glib()
} }
}); });
let to_raw: [gst_audio_sys::GstAudioChannelPosition; 64] = array_init::array_init(|i| { let to_raw: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
if i >= to_len as usize { if i >= to_len as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
to[i].to_glib() to[i].to_glib()
} }
@ -303,7 +295,7 @@ pub fn get_channel_reorder_map(
let mut reorder_map_raw = [0i32, 64]; let mut reorder_map_raw = [0i32, 64];
let valid: bool = unsafe { let valid: bool = unsafe {
from_glib(gst_audio_sys::gst_audio_get_channel_reorder_map( from_glib(ffi::gst_audio_get_channel_reorder_map(
from_len as i32, from_len as i32,
from_raw.as_ptr() as *mut _, from_raw.as_ptr() as *mut _,
to_raw.as_ptr() as *mut _, to_raw.as_ptr() as *mut _,
@ -317,6 +309,6 @@ pub fn get_channel_reorder_map(
} }
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!("Failed to reorder channels")) Err(glib::glib_bool_error!("Failed to reorder channels"))
} }
} }

View file

@ -6,27 +6,25 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::AudioDecoder;
use crate::AudioInfo;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst;
use gst_audio_sys;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use AudioDecoder;
use AudioInfo;
extern "C" { extern "C" {
fn _gst_audio_decoder_error( fn _gst_audio_decoder_error(
dec: *mut gst_audio_sys::GstAudioDecoder, dec: *mut ffi::GstAudioDecoder,
weight: i32, weight: i32,
domain: glib_sys::GQuark, domain: glib::ffi::GQuark,
code: i32, code: i32,
txt: *mut libc::c_char, txt: *mut libc::c_char,
debug: *mut libc::c_char, debug: *mut libc::c_char,
file: *const libc::c_char, file: *const libc::c_char,
function: *const libc::c_char, function: *const libc::c_char,
line: i32, line: i32,
) -> gst_sys::GstFlowReturn; ) -> gst::ffi::GstFlowReturn;
} }
pub trait AudioDecoderExtManual: 'static { pub trait AudioDecoderExtManual: 'static {
@ -73,7 +71,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
frames: i32, frames: i32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { let ret: gst::FlowReturn = unsafe {
from_glib(gst_audio_sys::gst_audio_decoder_finish_frame( from_glib(ffi::gst_audio_decoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
frames, frames,
@ -89,7 +87,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
buffer: Option<gst::Buffer>, buffer: Option<gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { let ret: gst::FlowReturn = unsafe {
from_glib(gst_audio_sys::gst_audio_decoder_finish_subframe( from_glib(ffi::gst_audio_decoder_finish_subframe(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
)) ))
@ -99,7 +97,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
fn negotiate(&self) -> Result<(), gst::FlowError> { fn negotiate(&self) -> Result<(), gst::FlowError> {
unsafe { unsafe {
let ret = from_glib(gst_audio_sys::gst_audio_decoder_negotiate( let ret = from_glib(ffi::gst_audio_decoder_negotiate(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)); ));
if ret { if ret {
@ -114,7 +112,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
fn set_output_caps(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> { fn set_output_caps(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
unsafe { unsafe {
let ret = from_glib(gst_audio_sys::gst_audio_decoder_set_output_caps( let ret = from_glib(ffi::gst_audio_decoder_set_output_caps(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
caps.to_glib_none().0, caps.to_glib_none().0,
)); ));
@ -128,7 +126,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
fn set_output_format(&self, info: &AudioInfo) -> Result<(), gst::FlowError> { fn set_output_format(&self, info: &AudioInfo) -> Result<(), gst::FlowError> {
unsafe { unsafe {
let ret = from_glib(gst_audio_sys::gst_audio_decoder_set_output_format( let ret = from_glib(ffi::gst_audio_decoder_set_output_format(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
info.to_glib_none().0, info.to_glib_none().0,
)); ));
@ -144,7 +142,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
unsafe { unsafe {
let mut allocator = ptr::null_mut(); let mut allocator = ptr::null_mut();
let mut params = mem::zeroed(); let mut params = mem::zeroed();
gst_audio_sys::gst_audio_decoder_get_allocator( ffi::gst_audio_decoder_get_allocator(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
&mut allocator, &mut allocator,
&mut params, &mut params,

View file

@ -6,13 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::AudioEncoder;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst;
use gst_audio_sys;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use AudioEncoder;
pub trait AudioEncoderExtManual: 'static { pub trait AudioEncoderExtManual: 'static {
fn finish_frame( fn finish_frame(
@ -37,7 +35,7 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
frames: i32, frames: i32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { let ret: gst::FlowReturn = unsafe {
from_glib(gst_audio_sys::gst_audio_encoder_finish_frame( from_glib(ffi::gst_audio_encoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
frames, frames,
@ -48,7 +46,7 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
fn negotiate(&self) -> Result<(), gst::FlowError> { fn negotiate(&self) -> Result<(), gst::FlowError> {
unsafe { unsafe {
let ret = from_glib(gst_audio_sys::gst_audio_encoder_negotiate( let ret = from_glib(ffi::gst_audio_encoder_negotiate(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)); ));
if ret { if ret {
@ -61,7 +59,7 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> { fn set_output_format(&self, caps: &gst::Caps) -> Result<(), gst::FlowError> {
unsafe { unsafe {
let ret = from_glib(gst_audio_sys::gst_audio_encoder_set_output_format( let ret = from_glib(ffi::gst_audio_encoder_set_output_format(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
caps.to_glib_none().0, caps.to_glib_none().0,
)); ));
@ -77,7 +75,7 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
unsafe { unsafe {
let mut allocator = ptr::null_mut(); let mut allocator = ptr::null_mut();
let mut params = mem::zeroed(); let mut params = mem::zeroed();
gst_audio_sys::gst_audio_encoder_get_allocator( ffi::gst_audio_encoder_get_allocator(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
&mut allocator, &mut allocator,
&mut params, &mut params,
@ -90,7 +88,7 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
unsafe { unsafe {
let mut min = mem::MaybeUninit::uninit(); let mut min = mem::MaybeUninit::uninit();
let mut max = mem::MaybeUninit::uninit(); let mut max = mem::MaybeUninit::uninit();
gst_audio_sys::gst_audio_encoder_get_latency( ffi::gst_audio_encoder_get_latency(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
min.as_mut_ptr(), min.as_mut_ptr(),
max.as_mut_ptr(), max.as_mut_ptr(),

View file

@ -6,8 +6,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_audio_sys;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::str; use std::str;
@ -16,10 +14,10 @@ use glib::translate::{from_glib, FromGlib, ToGlib, ToGlibPtr};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[cfg(feature = "v1_18")] #[cfg(feature = "v1_18")]
pub static AUDIO_FORMATS_ALL: Lazy<Box<[::AudioFormat]>> = Lazy::new(|| unsafe { pub static AUDIO_FORMATS_ALL: Lazy<Box<[crate::AudioFormat]>> = Lazy::new(|| unsafe {
let mut len: u32 = 0; let mut len: u32 = 0;
let mut res = Vec::with_capacity(len as usize); let mut res = Vec::with_capacity(len as usize);
let formats = gst_audio_sys::gst_audio_formats_raw(&mut len); let formats = ffi::gst_audio_formats_raw(&mut len);
for i in 0..len { for i in 0..len {
let format = formats.offset(i as isize); let format = formats.offset(i as isize);
res.push(from_glib(*format)); res.push(from_glib(*format));
@ -28,40 +26,40 @@ pub static AUDIO_FORMATS_ALL: Lazy<Box<[::AudioFormat]>> = Lazy::new(|| unsafe {
}); });
#[cfg(not(feature = "v1_18"))] #[cfg(not(feature = "v1_18"))]
pub static AUDIO_FORMATS_ALL: Lazy<Box<[::AudioFormat]>> = Lazy::new(|| { pub static AUDIO_FORMATS_ALL: Lazy<Box<[crate::AudioFormat]>> = Lazy::new(|| {
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
{ {
Box::new([ Box::new([
::AudioFormat::F64le, crate::AudioFormat::F64le,
::AudioFormat::F64be, crate::AudioFormat::F64be,
::AudioFormat::F32le, crate::AudioFormat::F32le,
::AudioFormat::F32be, crate::AudioFormat::F32be,
::AudioFormat::S32le, crate::AudioFormat::S32le,
::AudioFormat::S32be, crate::AudioFormat::S32be,
::AudioFormat::U32le, crate::AudioFormat::U32le,
::AudioFormat::U32be, crate::AudioFormat::U32be,
::AudioFormat::S2432le, crate::AudioFormat::S2432le,
::AudioFormat::S2432be, crate::AudioFormat::S2432be,
::AudioFormat::U2432le, crate::AudioFormat::U2432le,
::AudioFormat::U2432be, crate::AudioFormat::U2432be,
::AudioFormat::S24le, crate::AudioFormat::S24le,
::AudioFormat::S24be, crate::AudioFormat::S24be,
::AudioFormat::U24le, crate::AudioFormat::U24le,
::AudioFormat::U24be, crate::AudioFormat::U24be,
::AudioFormat::S20le, crate::AudioFormat::S20le,
::AudioFormat::S20be, crate::AudioFormat::S20be,
::AudioFormat::U20le, crate::AudioFormat::U20le,
::AudioFormat::U20be, crate::AudioFormat::U20be,
::AudioFormat::S18le, crate::AudioFormat::S18le,
::AudioFormat::S18be, crate::AudioFormat::S18be,
::AudioFormat::U18le, crate::AudioFormat::U18le,
::AudioFormat::U18be, crate::AudioFormat::U18be,
::AudioFormat::S16le, crate::AudioFormat::S16le,
::AudioFormat::S16be, crate::AudioFormat::S16be,
::AudioFormat::U16le, crate::AudioFormat::U16le,
::AudioFormat::U16be, crate::AudioFormat::U16be,
::AudioFormat::S8, crate::AudioFormat::S8,
::AudioFormat::U8, crate::AudioFormat::U8,
]) ])
} }
#[cfg(target_endian = "big")] #[cfg(target_endian = "big")]
@ -101,17 +99,17 @@ pub static AUDIO_FORMATS_ALL: Lazy<Box<[::AudioFormat]>> = Lazy::new(|| {
} }
}); });
impl ::AudioFormat { impl crate::AudioFormat {
pub fn build_integer( pub fn build_integer(
sign: bool, sign: bool,
endianness: ::AudioEndianness, endianness: crate::AudioEndianness,
width: i32, width: i32,
depth: i32, depth: i32,
) -> ::AudioFormat { ) -> crate::AudioFormat {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(gst_audio_sys::gst_audio_format_build_integer( from_glib(ffi::gst_audio_format_build_integer(
sign.to_glib(), sign.to_glib(),
endianness.to_glib(), endianness.to_glib(),
width, width,
@ -121,12 +119,12 @@ impl ::AudioFormat {
} }
pub fn to_str<'a>(self) -> &'a str { pub fn to_str<'a>(self) -> &'a str {
if self == ::AudioFormat::Unknown { if self == crate::AudioFormat::Unknown {
return "UNKNOWN"; return "UNKNOWN";
} }
unsafe { unsafe {
CStr::from_ptr(gst_audio_sys::gst_audio_format_to_string(self.to_glib())) CStr::from_ptr(ffi::gst_audio_format_to_string(self.to_glib()))
.to_str() .to_str()
.unwrap() .unwrap()
} }
@ -137,18 +135,20 @@ impl ::AudioFormat {
} }
} }
impl str::FromStr for ::AudioFormat { impl str::FromStr for crate::AudioFormat {
type Err = glib::BoolError; type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, glib::BoolError> { fn from_str(s: &str) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let fmt = ::AudioFormat::from_glib(gst_audio_sys::gst_audio_format_from_string( let fmt = crate::AudioFormat::from_glib(ffi::gst_audio_format_from_string(
s.to_glib_none().0, s.to_glib_none().0,
)); ));
if fmt == ::AudioFormat::Unknown { if fmt == crate::AudioFormat::Unknown {
Err(glib_bool_error!("Failed to parse audio format from string")) Err(glib::glib_bool_error!(
"Failed to parse audio format from string"
))
} else { } else {
Ok(fmt) Ok(fmt)
} }
@ -156,28 +156,29 @@ impl str::FromStr for ::AudioFormat {
} }
} }
impl fmt::Display for ::AudioFormat { impl fmt::Display for crate::AudioFormat {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str((*self).to_str()) f.write_str((*self).to_str())
} }
} }
impl PartialOrd for ::AudioFormat { impl PartialOrd for crate::AudioFormat {
fn partial_cmp(&self, other: &::AudioFormat) -> Option<std::cmp::Ordering> { fn partial_cmp(&self, other: &crate::AudioFormat) -> Option<std::cmp::Ordering> {
::AudioFormatInfo::from_format(*self).partial_cmp(&::AudioFormatInfo::from_format(*other)) crate::AudioFormatInfo::from_format(*self)
.partial_cmp(&crate::AudioFormatInfo::from_format(*other))
} }
} }
impl Ord for ::AudioFormat { impl Ord for crate::AudioFormat {
fn cmp(&self, other: &::AudioFormat) -> std::cmp::Ordering { fn cmp(&self, other: &crate::AudioFormat) -> std::cmp::Ordering {
::AudioFormatInfo::from_format(*self).cmp(&::AudioFormatInfo::from_format(*other)) crate::AudioFormatInfo::from_format(*self).cmp(&crate::AudioFormatInfo::from_format(*other))
} }
} }
pub const AUDIO_FORMAT_UNKNOWN: ::AudioFormat = ::AudioFormat::Unknown; pub const AUDIO_FORMAT_UNKNOWN: crate::AudioFormat = crate::AudioFormat::Unknown;
pub const AUDIO_FORMAT_ENCODED: ::AudioFormat = ::AudioFormat::Encoded; pub const AUDIO_FORMAT_ENCODED: crate::AudioFormat = crate::AudioFormat::Encoded;
pub const AUDIO_FORMAT_S8: ::AudioFormat = ::AudioFormat::S8; pub const AUDIO_FORMAT_S8: crate::AudioFormat = crate::AudioFormat::S8;
pub const AUDIO_FORMAT_U8: ::AudioFormat = ::AudioFormat::U8; pub const AUDIO_FORMAT_U8: crate::AudioFormat = crate::AudioFormat::U8;
#[cfg(target_endian = "big")] #[cfg(target_endian = "big")]
pub const AUDIO_FORMAT_S16: ::AudioFormat = ::AudioFormat::S16be; pub const AUDIO_FORMAT_S16: ::AudioFormat = ::AudioFormat::S16be;
@ -209,33 +210,33 @@ pub const AUDIO_FORMAT_F32: ::AudioFormat = ::AudioFormat::F32be;
pub const AUDIO_FORMAT_F64: ::AudioFormat = ::AudioFormat::F64be; pub const AUDIO_FORMAT_F64: ::AudioFormat = ::AudioFormat::F64be;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S16: ::AudioFormat = ::AudioFormat::S16le; pub const AUDIO_FORMAT_S16: crate::AudioFormat = crate::AudioFormat::S16le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U16: ::AudioFormat = ::AudioFormat::U16le; pub const AUDIO_FORMAT_U16: crate::AudioFormat = crate::AudioFormat::U16le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S2432: ::AudioFormat = ::AudioFormat::S2432le; pub const AUDIO_FORMAT_S2432: crate::AudioFormat = crate::AudioFormat::S2432le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U2432: ::AudioFormat = ::AudioFormat::U2432le; pub const AUDIO_FORMAT_U2432: crate::AudioFormat = crate::AudioFormat::U2432le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S32: ::AudioFormat = ::AudioFormat::S32le; pub const AUDIO_FORMAT_S32: crate::AudioFormat = crate::AudioFormat::S32le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U32: ::AudioFormat = ::AudioFormat::U32le; pub const AUDIO_FORMAT_U32: crate::AudioFormat = crate::AudioFormat::U32le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S24: ::AudioFormat = ::AudioFormat::S24le; pub const AUDIO_FORMAT_S24: crate::AudioFormat = crate::AudioFormat::S24le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U24: ::AudioFormat = ::AudioFormat::U24le; pub const AUDIO_FORMAT_U24: crate::AudioFormat = crate::AudioFormat::U24le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S20: ::AudioFormat = ::AudioFormat::S20le; pub const AUDIO_FORMAT_S20: crate::AudioFormat = crate::AudioFormat::S20le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U20: ::AudioFormat = ::AudioFormat::U20le; pub const AUDIO_FORMAT_U20: crate::AudioFormat = crate::AudioFormat::U20le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_S18: ::AudioFormat = ::AudioFormat::S18le; pub const AUDIO_FORMAT_S18: crate::AudioFormat = crate::AudioFormat::S18le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_U18: ::AudioFormat = ::AudioFormat::U18le; pub const AUDIO_FORMAT_U18: crate::AudioFormat = crate::AudioFormat::U18le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_F32: ::AudioFormat = ::AudioFormat::F32le; pub const AUDIO_FORMAT_F32: crate::AudioFormat = crate::AudioFormat::F32le;
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
pub const AUDIO_FORMAT_F64: ::AudioFormat = ::AudioFormat::F64le; pub const AUDIO_FORMAT_F64: crate::AudioFormat = crate::AudioFormat::F64le;
pub struct AudioFormatIterator { pub struct AudioFormatIterator {
idx: usize, idx: usize,
@ -252,7 +253,7 @@ impl Default for AudioFormatIterator {
} }
impl Iterator for AudioFormatIterator { impl Iterator for AudioFormatIterator {
type Item = ::AudioFormat; type Item = crate::AudioFormat;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.idx >= self.len { if self.idx >= self.len {
@ -291,21 +292,21 @@ impl DoubleEndedIterator for AudioFormatIterator {
pub trait AudioFormatIteratorExt { pub trait AudioFormatIteratorExt {
fn into_audio_caps( fn into_audio_caps(
self, self,
layout: ::AudioLayout, layout: crate::AudioLayout,
) -> Option<gst::caps::Builder<gst::caps::NoFeature>>; ) -> Option<gst::caps::Builder<gst::caps::NoFeature>>;
} }
impl<T> AudioFormatIteratorExt for T impl<T> AudioFormatIteratorExt for T
where where
T: Iterator<Item = ::AudioFormat>, T: Iterator<Item = crate::AudioFormat>,
{ {
fn into_audio_caps( fn into_audio_caps(
self, self,
layout: ::AudioLayout, layout: crate::AudioLayout,
) -> Option<gst::caps::Builder<gst::caps::NoFeature>> { ) -> Option<gst::caps::Builder<gst::caps::NoFeature>> {
let formats: Vec<::AudioFormat> = self.collect(); let formats: Vec<crate::AudioFormat> = self.collect();
if !formats.is_empty() { if !formats.is_empty() {
Some(::functions::audio_make_raw_caps(&formats, layout)) Some(crate::functions::audio_make_raw_caps(&formats, layout))
} else { } else {
None None
} }
@ -315,21 +316,21 @@ where
pub trait AudioFormatIteratorExtRef { pub trait AudioFormatIteratorExtRef {
fn into_audio_caps( fn into_audio_caps(
self, self,
layout: ::AudioLayout, layout: crate::AudioLayout,
) -> Option<gst::caps::Builder<gst::caps::NoFeature>>; ) -> Option<gst::caps::Builder<gst::caps::NoFeature>>;
} }
impl<'a, T> AudioFormatIteratorExtRef for T impl<'a, T> AudioFormatIteratorExtRef for T
where where
T: Iterator<Item = &'a ::AudioFormat>, T: Iterator<Item = &'a crate::AudioFormat>,
{ {
fn into_audio_caps( fn into_audio_caps(
self, self,
layout: ::AudioLayout, layout: crate::AudioLayout,
) -> Option<gst::caps::Builder<gst::caps::NoFeature>> { ) -> Option<gst::caps::Builder<gst::caps::NoFeature>> {
let formats: Vec<::AudioFormat> = self.copied().collect(); let formats: Vec<crate::AudioFormat> = self.copied().collect();
if !formats.is_empty() { if !formats.is_empty() {
Some(::functions::audio_make_raw_caps(&formats, layout)) Some(crate::functions::audio_make_raw_caps(&formats, layout))
} else { } else {
None None
} }
@ -338,14 +339,13 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use gst;
use itertools::Itertools; use itertools::Itertools;
#[test] #[test]
fn test_display() { fn test_display() {
gst::init().unwrap(); gst::init().unwrap();
format!("{}", ::AudioFormat::S16be); format!("{}", crate::AudioFormat::S16be);
} }
#[test] #[test]
@ -353,13 +353,13 @@ mod tests {
use super::*; use super::*;
gst::init().unwrap(); gst::init().unwrap();
assert!(::AudioFormat::iter_raw().count() > 0); assert!(crate::AudioFormat::iter_raw().count() > 0);
assert_eq!( assert_eq!(
::AudioFormat::iter_raw().count(), crate::AudioFormat::iter_raw().count(),
::AudioFormat::iter_raw().len() crate::AudioFormat::iter_raw().len()
); );
let mut i = ::AudioFormat::iter_raw(); let mut i = crate::AudioFormat::iter_raw();
let mut count = 0; let mut count = 0;
loop { loop {
if i.next().is_none() { if i.next().is_none() {
@ -371,29 +371,29 @@ mod tests {
} }
count += 1; count += 1;
} }
assert_eq!(count, ::AudioFormat::iter_raw().len()); assert_eq!(count, crate::AudioFormat::iter_raw().len());
assert!(::AudioFormat::iter_raw().any(|f| f == ::AudioFormat::F64be)); assert!(crate::AudioFormat::iter_raw().any(|f| f == crate::AudioFormat::F64be));
assert!(::AudioFormat::iter_raw() assert!(crate::AudioFormat::iter_raw()
.find(|f| *f == ::AudioFormat::Encoded) .find(|f| *f == crate::AudioFormat::Encoded)
.is_none()); .is_none());
let caps = ::AudioFormat::iter_raw().into_audio_caps(::AudioLayout::Interleaved); let caps = crate::AudioFormat::iter_raw().into_audio_caps(crate::AudioLayout::Interleaved);
assert!(caps.is_some()); assert!(caps.is_some());
let caps = ::AudioFormat::iter_raw() let caps = crate::AudioFormat::iter_raw()
.filter(|f| ::AudioFormatInfo::from_format(*f).is_little_endian()) .filter(|f| crate::AudioFormatInfo::from_format(*f).is_little_endian())
.into_audio_caps(::AudioLayout::Interleaved); .into_audio_caps(crate::AudioLayout::Interleaved);
assert!(caps.is_some()); assert!(caps.is_some());
let caps = ::AudioFormat::iter_raw() let caps = crate::AudioFormat::iter_raw()
.skip(1000) .skip(1000)
.into_audio_caps(::AudioLayout::Interleaved); .into_audio_caps(crate::AudioLayout::Interleaved);
assert!(caps.is_none()); assert!(caps.is_none());
let caps = [::AudioFormat::S16le, ::AudioFormat::S16be] let caps = [crate::AudioFormat::S16le, crate::AudioFormat::S16be]
.iter() .iter()
.into_audio_caps(::AudioLayout::Interleaved) .into_audio_caps(crate::AudioLayout::Interleaved)
.unwrap() .unwrap()
.build(); .build();
assert_eq!(caps.to_string(), "audio/x-raw, format=(string){ S16LE, S16BE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], layout=(string)interleaved"); assert_eq!(caps.to_string(), "audio/x-raw, format=(string){ S16LE, S16BE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], layout=(string)interleaved");
@ -404,16 +404,17 @@ mod tests {
gst::init().unwrap(); gst::init().unwrap();
assert!( assert!(
::AudioFormatInfo::from_format(::AudioFormat::F64be) crate::AudioFormatInfo::from_format(crate::AudioFormat::F64be)
> ::AudioFormatInfo::from_format(::AudioFormat::U8) > crate::AudioFormatInfo::from_format(crate::AudioFormat::U8)
); );
assert!(::AudioFormat::S20be > ::AudioFormat::S18be); assert!(crate::AudioFormat::S20be > crate::AudioFormat::S18be);
let sorted: Vec<::AudioFormat> = ::AudioFormat::iter_raw().sorted().rev().collect(); let sorted: Vec<crate::AudioFormat> =
crate::AudioFormat::iter_raw().sorted().rev().collect();
// FIXME: use is_sorted_by() once API is in stable // FIXME: use is_sorted_by() once API is in stable
assert_eq!( assert_eq!(
sorted, sorted,
::AudioFormat::iter_raw().collect::<Vec<::AudioFormat>>() crate::AudioFormat::iter_raw().collect::<Vec<crate::AudioFormat>>()
); );
} }
} }

View file

@ -6,16 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gobject_sys;
use gst_audio_sys;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::str; use std::str;
use glib;
use glib::translate::{from_glib, FromGlib, FromGlibPtrNone, ToGlib, ToGlibPtr, ToGlibPtrMut}; use glib::translate::{from_glib, FromGlib, FromGlibPtrNone, ToGlib, ToGlibPtr, ToGlibPtrMut};
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)] #[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
@ -49,21 +44,21 @@ impl ToGlib for AudioEndianness {
} }
} }
pub struct AudioFormatInfo(&'static gst_audio_sys::GstAudioFormatInfo); pub struct AudioFormatInfo(&'static ffi::GstAudioFormatInfo);
impl AudioFormatInfo { impl AudioFormatInfo {
pub fn from_format(format: ::AudioFormat) -> AudioFormatInfo { pub fn from_format(format: crate::AudioFormat) -> AudioFormatInfo {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let info = gst_audio_sys::gst_audio_format_get_info(format.to_glib()); let info = ffi::gst_audio_format_get_info(format.to_glib());
assert!(!info.is_null()); assert!(!info.is_null());
AudioFormatInfo(&*info) AudioFormatInfo(&*info)
} }
} }
pub fn format(&self) -> ::AudioFormat { pub fn format(&self) -> crate::AudioFormat {
from_glib(self.0.format) from_glib(self.0.format)
} }
@ -75,7 +70,7 @@ impl AudioFormatInfo {
unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() } unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() }
} }
pub fn flags(&self) -> ::AudioFormatFlags { pub fn flags(&self) -> crate::AudioFormatFlags {
from_glib(self.0.flags) from_glib(self.0.flags)
} }
@ -91,7 +86,7 @@ impl AudioFormatInfo {
self.0.depth as u32 self.0.depth as u32
} }
pub fn unpack_format(&self) -> ::AudioFormat { pub fn unpack_format(&self) -> crate::AudioFormat {
from_glib(self.0.unpack_format) from_glib(self.0.unpack_format)
} }
@ -99,7 +94,7 @@ impl AudioFormatInfo {
&self.0.silence &self.0.silence
} }
pub fn unpack(&self, flags: ::AudioPackFlags, dest: &mut [u8], src: &[u8]) { pub fn unpack(&self, flags: crate::AudioPackFlags, dest: &mut [u8], src: &[u8]) {
let unpack_format = Self::from_format(self.unpack_format()); let unpack_format = Self::from_format(self.unpack_format());
let unpack_width = unpack_format.width() as usize; let unpack_width = unpack_format.width() as usize;
@ -133,7 +128,7 @@ impl AudioFormatInfo {
} }
} }
pub fn pack(&self, flags: ::AudioPackFlags, dest: &mut [u8], src: &[u8]) { pub fn pack(&self, flags: crate::AudioPackFlags, dest: &mut [u8], src: &[u8]) {
let unpack_format = Self::from_format(self.unpack_format()); let unpack_format = Self::from_format(self.unpack_format());
let unpack_width = unpack_format.width() as usize; let unpack_width = unpack_format.width() as usize;
@ -179,24 +174,20 @@ impl AudioFormatInfo {
} }
unsafe { unsafe {
gst_audio_sys::gst_audio_format_fill_silence( ffi::gst_audio_format_fill_silence(self.0, dest.as_mut_ptr() as *mut _, dest.len())
self.0,
dest.as_mut_ptr() as *mut _,
dest.len(),
)
} }
} }
pub fn is_float(&self) -> bool { pub fn is_float(&self) -> bool {
self.flags().contains(::AudioFormatFlags::FLOAT) self.flags().contains(crate::AudioFormatFlags::FLOAT)
} }
pub fn is_integer(&self) -> bool { pub fn is_integer(&self) -> bool {
self.flags().contains(::AudioFormatFlags::INTEGER) self.flags().contains(crate::AudioFormatFlags::INTEGER)
} }
pub fn is_signed(&self) -> bool { pub fn is_signed(&self) -> bool {
self.flags().contains(::AudioFormatFlags::SIGNED) self.flags().contains(crate::AudioFormatFlags::SIGNED)
} }
pub fn is_little_endian(&self) -> bool { pub fn is_little_endian(&self) -> bool {
@ -233,8 +224,8 @@ impl Ord for AudioFormatInfo {
.then_with(|| self.width().cmp(&other.width())) .then_with(|| self.width().cmp(&other.width()))
.then_with(|| { .then_with(|| {
match ( match (
self.flags().contains(::AudioFormatFlags::FLOAT), self.flags().contains(crate::AudioFormatFlags::FLOAT),
other.flags().contains(::AudioFormatFlags::FLOAT), other.flags().contains(crate::AudioFormatFlags::FLOAT),
) { ) {
(true, false) => Ordering::Greater, (true, false) => Ordering::Greater,
(false, true) => Ordering::Less, (false, true) => Ordering::Less,
@ -243,8 +234,8 @@ impl Ord for AudioFormatInfo {
}) })
.then_with(|| { .then_with(|| {
match ( match (
self.flags().contains(::AudioFormatFlags::SIGNED), self.flags().contains(crate::AudioFormatFlags::SIGNED),
other.flags().contains(::AudioFormatFlags::SIGNED), other.flags().contains(crate::AudioFormatFlags::SIGNED),
) { ) {
(true, false) => Ordering::Greater, (true, false) => Ordering::Greater,
(false, true) => Ordering::Less, (false, true) => Ordering::Less,
@ -252,7 +243,7 @@ impl Ord for AudioFormatInfo {
} }
}) })
.then_with(|| match (self.endianness(), other.endianness()) { .then_with(|| match (self.endianness(), other.endianness()) {
(::AudioEndianness::LittleEndian, ::AudioEndianness::BigEndian) => { (crate::AudioEndianness::LittleEndian, crate::AudioEndianness::BigEndian) => {
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
{ {
Ordering::Greater Ordering::Greater
@ -262,7 +253,7 @@ impl Ord for AudioFormatInfo {
Ordering::Less Ordering::Less
} }
} }
(::AudioEndianness::BigEndian, ::AudioEndianness::LittleEndian) => { (crate::AudioEndianness::BigEndian, crate::AudioEndianness::LittleEndian) => {
#[cfg(target_endian = "little")] #[cfg(target_endian = "little")]
{ {
Ordering::Less Ordering::Less
@ -298,7 +289,7 @@ impl fmt::Display for AudioFormatInfo {
} }
} }
impl str::FromStr for ::AudioFormatInfo { impl str::FromStr for crate::AudioFormatInfo {
type Err = glib::BoolError; type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, glib::BoolError> { fn from_str(s: &str) -> Result<Self, glib::BoolError> {
@ -308,8 +299,8 @@ impl str::FromStr for ::AudioFormatInfo {
} }
} }
impl From<::AudioFormat> for AudioFormatInfo { impl From<crate::AudioFormat> for AudioFormatInfo {
fn from(f: ::AudioFormat) -> Self { fn from(f: crate::AudioFormat) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
Self::from_format(f) Self::from_format(f)
} }
@ -317,29 +308,26 @@ impl From<::AudioFormat> for AudioFormatInfo {
impl glib::types::StaticType for AudioFormatInfo { impl glib::types::StaticType for AudioFormatInfo {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_audio_sys::gst_audio_format_info_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_audio_format_info_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for AudioFormatInfo { impl<'a> glib::value::FromValueOptional<'a> for AudioFormatInfo {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<AudioFormatInfo>::from_glib_none(gobject_sys::g_value_get_boxed( Option::<AudioFormatInfo>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
value.to_glib_none().0, value.to_glib_none().0,
) ) as *mut ffi::GstAudioFormatInfo)
as *mut gst_audio_sys::GstAudioFormatInfo)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValue for AudioFormatInfo { impl glib::value::SetValue for AudioFormatInfo {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_audio_sys::GstAudioFormatInfo>::to_glib_none( glib::translate::ToGlibPtr::<*const ffi::GstAudioFormatInfo>::to_glib_none(this).0
this, as glib::ffi::gpointer,
)
.0 as glib_sys::gpointer,
) )
} }
} }
@ -347,42 +335,36 @@ impl glib::value::SetValue for AudioFormatInfo {
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValueOptional for AudioFormatInfo { impl glib::value::SetValueOptional for AudioFormatInfo {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_audio_sys::GstAudioFormatInfo>::to_glib_none( glib::translate::ToGlibPtr::<*const ffi::GstAudioFormatInfo>::to_glib_none(&this).0
&this, as glib::ffi::gpointer,
)
.0 as glib_sys::gpointer,
) )
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::GlibPtrDefault for AudioFormatInfo { impl glib::translate::GlibPtrDefault for AudioFormatInfo {
type GlibType = *mut gst_audio_sys::GstAudioFormatInfo; type GlibType = *mut ffi::GstAudioFormatInfo;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const gst_audio_sys::GstAudioFormatInfo> impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for AudioFormatInfo {
for AudioFormatInfo
{
type Storage = &'a AudioFormatInfo; type Storage = &'a AudioFormatInfo;
fn to_glib_none( fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioFormatInfo, Self> {
&'a self,
) -> glib::translate::Stash<'a, *const gst_audio_sys::GstAudioFormatInfo, Self> {
glib::translate::Stash(self.0, self) glib::translate::Stash(self.0, self)
} }
fn to_glib_full(&self) -> *const gst_audio_sys::GstAudioFormatInfo { fn to_glib_full(&self) -> *const ffi::GstAudioFormatInfo {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_audio_sys::GstAudioFormatInfo> for AudioFormatInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioFormatInfo> for AudioFormatInfo {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_audio_sys::GstAudioFormatInfo) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstAudioFormatInfo) -> Self {
AudioFormatInfo(&*ptr) AudioFormatInfo(&*ptr)
} }
} }
@ -390,13 +372,12 @@ impl glib::translate::FromGlibPtrNone<*mut gst_audio_sys::GstAudioFormatInfo> fo
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use gst;
#[test] #[test]
fn test_get() { fn test_get() {
gst::init().unwrap(); gst::init().unwrap();
let info = AudioFormatInfo::from_format(::AudioFormat::S16le); let info = AudioFormatInfo::from_format(crate::AudioFormat::S16le);
assert_eq!(info.name(), "S16LE"); assert_eq!(info.name(), "S16LE");
let other_info = "S16LE".parse().unwrap(); let other_info = "S16LE".parse().unwrap();
@ -407,7 +388,7 @@ mod tests {
fn pack_unpack() { fn pack_unpack() {
gst::init().unwrap(); gst::init().unwrap();
let info = AudioFormatInfo::from_format(::AudioFormat::S16le); let info = AudioFormatInfo::from_format(crate::AudioFormat::S16le);
let unpack_info = AudioFormatInfo::from_format(info.unpack_format()); let unpack_info = AudioFormatInfo::from_format(info.unpack_format());
assert!(unpack_info.width() > 0); assert!(unpack_info.width() > 0);
@ -416,8 +397,8 @@ mod tests {
let mut unpacked = [0; 16]; let mut unpacked = [0; 16];
let mut output = [0; 8]; let mut output = [0; 8];
info.unpack(::AudioPackFlags::empty(), &mut unpacked, &input); info.unpack(crate::AudioPackFlags::empty(), &mut unpacked, &input);
info.pack(::AudioPackFlags::empty(), &mut output, &unpacked); info.pack(crate::AudioPackFlags::empty(), &mut output, &unpacked);
assert_eq!(input, output); assert_eq!(input, output);
} }

View file

@ -6,24 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gobject_sys;
use gst_audio_sys;
use glib;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlibPtrNone, ToGlib, ToGlibPtr, ToGlibPtrMut, from_glib, from_glib_full, from_glib_none, FromGlibPtrNone, ToGlib, ToGlibPtr, ToGlibPtrMut,
}; };
use gst;
use gst::prelude::*; use gst::prelude::*;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use array_init; pub struct AudioInfo(ffi::GstAudioInfo, [crate::AudioChannelPosition; 64]);
pub struct AudioInfo(gst_audio_sys::GstAudioInfo, [::AudioChannelPosition; 64]);
impl fmt::Debug for AudioInfo { impl fmt::Debug for AudioInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
@ -40,12 +32,12 @@ impl fmt::Debug for AudioInfo {
#[derive(Debug)] #[derive(Debug)]
pub struct AudioInfoBuilder<'a> { pub struct AudioInfoBuilder<'a> {
format: ::AudioFormat, format: crate::AudioFormat,
rate: u32, rate: u32,
channels: u32, channels: u32,
positions: Option<&'a [::AudioChannelPosition]>, positions: Option<&'a [crate::AudioChannelPosition]>,
flags: Option<::AudioFlags>, flags: Option<crate::AudioFlags>,
layout: Option<::AudioLayout>, layout: Option<crate::AudioLayout>,
} }
impl<'a> AudioInfoBuilder<'a> { impl<'a> AudioInfoBuilder<'a> {
@ -55,26 +47,24 @@ impl<'a> AudioInfoBuilder<'a> {
let positions = if let Some(p) = self.positions { let positions = if let Some(p) = self.positions {
if p.len() != self.channels as usize || p.len() > 64 { if p.len() != self.channels as usize || p.len() > 64 {
return Err(glib_bool_error!("Invalid positions length")); return Err(glib::glib_bool_error!("Invalid positions length"));
} }
let positions: [gst_audio_sys::GstAudioChannelPosition; 64] = let positions: [ffi::GstAudioChannelPosition; 64] = array_init::array_init(|i| {
array_init::array_init(|i| {
if i >= self.channels as usize { if i >= self.channels as usize {
gst_audio_sys::GST_AUDIO_CHANNEL_POSITION_INVALID ffi::GST_AUDIO_CHANNEL_POSITION_INVALID
} else { } else {
p[i].to_glib() p[i].to_glib()
} }
}); });
let valid: bool = let valid: bool = from_glib(ffi::gst_audio_check_valid_channel_positions(
from_glib(gst_audio_sys::gst_audio_check_valid_channel_positions(
positions.as_ptr() as *mut _, positions.as_ptr() as *mut _,
self.channels as i32, self.channels as i32,
true.to_glib(), true.to_glib(),
)); ));
if !valid { if !valid {
return Err(glib_bool_error!("channel positions are invalid")); return Err(glib::glib_bool_error!("channel positions are invalid"));
} }
Some(positions) Some(positions)
@ -87,7 +77,7 @@ impl<'a> AudioInfoBuilder<'a> {
.map(|p| p.as_ptr()) .map(|p| p.as_ptr())
.unwrap_or(ptr::null()); .unwrap_or(ptr::null());
gst_audio_sys::gst_audio_info_set_format( ffi::gst_audio_info_set_format(
info.as_mut_ptr(), info.as_mut_ptr(),
self.format.to_glib(), self.format.to_glib(),
self.rate as i32, self.rate as i32,
@ -98,7 +88,7 @@ impl<'a> AudioInfoBuilder<'a> {
let mut info = info.assume_init(); let mut info = info.assume_init();
if info.finfo.is_null() || info.rate <= 0 || info.channels <= 0 { if info.finfo.is_null() || info.rate <= 0 || info.channels <= 0 {
return Err(glib_bool_error!("Failed to build AudioInfo")); return Err(glib::glib_bool_error!("Failed to build AudioInfo"));
} }
if let Some(flags) = self.flags { if let Some(flags) = self.flags {
@ -114,21 +104,21 @@ impl<'a> AudioInfoBuilder<'a> {
} }
} }
pub fn positions(self, positions: &'a [::AudioChannelPosition]) -> AudioInfoBuilder<'a> { pub fn positions(self, positions: &'a [crate::AudioChannelPosition]) -> AudioInfoBuilder<'a> {
Self { Self {
positions: Some(positions), positions: Some(positions),
..self ..self
} }
} }
pub fn flags(self, flags: ::AudioFlags) -> Self { pub fn flags(self, flags: crate::AudioFlags) -> Self {
Self { Self {
flags: Some(flags), flags: Some(flags),
..self ..self
} }
} }
pub fn layout(self, layout: ::AudioLayout) -> Self { pub fn layout(self, layout: crate::AudioLayout) -> Self {
Self { Self {
layout: Some(layout), layout: Some(layout),
..self ..self
@ -137,7 +127,11 @@ impl<'a> AudioInfoBuilder<'a> {
} }
impl AudioInfo { impl AudioInfo {
pub fn builder<'a>(format: ::AudioFormat, rate: u32, channels: u32) -> AudioInfoBuilder<'a> { pub fn builder<'a>(
format: crate::AudioFormat,
rate: u32,
channels: u32,
) -> AudioInfoBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
AudioInfoBuilder { AudioInfoBuilder {
@ -159,7 +153,7 @@ impl AudioInfo {
unsafe { unsafe {
let mut info = mem::MaybeUninit::uninit(); let mut info = mem::MaybeUninit::uninit();
if from_glib(gst_audio_sys::gst_audio_info_from_caps( if from_glib(ffi::gst_audio_info_from_caps(
info.as_mut_ptr(), info.as_mut_ptr(),
caps.as_ptr(), caps.as_ptr(),
)) { )) {
@ -167,17 +161,21 @@ impl AudioInfo {
let positions = array_init::array_init(|i| from_glib(info.position[i])); let positions = array_init::array_init(|i| from_glib(info.position[i]));
Ok(AudioInfo(info, positions)) Ok(AudioInfo(info, positions))
} else { } else {
Err(glib_bool_error!("Failed to create AudioInfo from caps")) Err(glib::glib_bool_error!(
"Failed to create AudioInfo from caps"
))
} }
} }
} }
pub fn to_caps(&self) -> Result<gst::Caps, glib::error::BoolError> { pub fn to_caps(&self) -> Result<gst::Caps, glib::error::BoolError> {
unsafe { unsafe {
let result = from_glib_full(gst_audio_sys::gst_audio_info_to_caps(&self.0)); let result = from_glib_full(ffi::gst_audio_info_to_caps(&self.0));
match result { match result {
Some(c) => Ok(c), Some(c) => Ok(c),
None => Err(glib_bool_error!("Failed to create caps from AudioInfo")), None => Err(glib::glib_bool_error!(
"Failed to create caps from AudioInfo"
)),
} }
} }
} }
@ -191,7 +189,7 @@ impl AudioInfo {
let src_val = src_val.into(); let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(gst_audio_sys::gst_audio_info_convert( if from_glib(ffi::gst_audio_info_convert(
&self.0, &self.0,
src_val.get_format().to_glib(), src_val.get_format().to_glib(),
src_val.to_raw_value(), src_val.to_raw_value(),
@ -215,7 +213,7 @@ impl AudioInfo {
let src_val = src_val.into(); let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
if from_glib(gst_audio_sys::gst_audio_info_convert( if from_glib(ffi::gst_audio_info_convert(
&self.0, &self.0,
src_val.get_format().to_glib(), src_val.get_format().to_glib(),
src_val.to_raw_value(), src_val.to_raw_value(),
@ -232,23 +230,23 @@ impl AudioInfo {
} }
} }
pub fn format(&self) -> ::AudioFormat { pub fn format(&self) -> crate::AudioFormat {
if self.0.finfo.is_null() { if self.0.finfo.is_null() {
return ::AudioFormat::Unknown; return crate::AudioFormat::Unknown;
} }
unsafe { from_glib((*self.0.finfo).format) } unsafe { from_glib((*self.0.finfo).format) }
} }
pub fn format_info(&self) -> ::AudioFormatInfo { pub fn format_info(&self) -> crate::AudioFormatInfo {
::AudioFormatInfo::from_format(self.format()) crate::AudioFormatInfo::from_format(self.format())
} }
pub fn layout(&self) -> ::AudioLayout { pub fn layout(&self) -> crate::AudioLayout {
from_glib(self.0.layout) from_glib(self.0.layout)
} }
pub fn flags(&self) -> ::AudioFlags { pub fn flags(&self) -> crate::AudioFlags {
from_glib(self.0.flags) from_glib(self.0.flags)
} }
@ -276,7 +274,7 @@ impl AudioInfo {
self.format_info().width() self.format_info().width()
} }
pub fn endianness(&self) -> ::AudioEndianness { pub fn endianness(&self) -> crate::AudioEndianness {
self.format_info().endianness() self.format_info().endianness()
} }
@ -300,7 +298,7 @@ impl AudioInfo {
self.format_info().is_signed() self.format_info().is_signed()
} }
pub fn positions(&self) -> Option<&[::AudioChannelPosition]> { pub fn positions(&self) -> Option<&[crate::AudioChannelPosition]> {
if self.0.channels > 64 || self.is_unpositioned() { if self.0.channels > 64 || self.is_unpositioned() {
return None; return None;
} }
@ -309,7 +307,7 @@ impl AudioInfo {
} }
pub fn is_unpositioned(&self) -> bool { pub fn is_unpositioned(&self) -> bool {
self.flags().contains(::AudioFlags::UNPOSITIONED) self.flags().contains(crate::AudioFlags::UNPOSITIONED)
} }
} }
@ -321,7 +319,7 @@ impl Clone for AudioInfo {
impl PartialEq for AudioInfo { impl PartialEq for AudioInfo {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
unsafe { from_glib(gst_audio_sys::gst_audio_info_is_equal(&self.0, &other.0)) } unsafe { from_glib(ffi::gst_audio_info_is_equal(&self.0, &other.0)) }
} }
} }
@ -332,25 +330,26 @@ unsafe impl Sync for AudioInfo {}
impl glib::types::StaticType for AudioInfo { impl glib::types::StaticType for AudioInfo {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_audio_sys::gst_audio_info_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_audio_info_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for AudioInfo { impl<'a> glib::value::FromValueOptional<'a> for AudioInfo {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<AudioInfo>::from_glib_none(gobject_sys::g_value_get_boxed(value.to_glib_none().0) Option::<AudioInfo>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
as *mut gst_audio_sys::GstAudioInfo) value.to_glib_none().0,
) as *mut ffi::GstAudioInfo)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValue for AudioInfo { impl glib::value::SetValue for AudioInfo {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_audio_sys::GstAudioInfo>::to_glib_none(this).0 glib::translate::ToGlibPtr::<*const ffi::GstAudioInfo>::to_glib_none(this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -358,10 +357,10 @@ impl glib::value::SetValue for AudioInfo {
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValueOptional for AudioInfo { impl glib::value::SetValueOptional for AudioInfo {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_audio_sys::GstAudioInfo>::to_glib_none(&this).0 glib::translate::ToGlibPtr::<*const ffi::GstAudioInfo>::to_glib_none(&this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -375,28 +374,26 @@ impl glib::translate::Uninitialized for AudioInfo {
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::GlibPtrDefault for AudioInfo { impl glib::translate::GlibPtrDefault for AudioInfo {
type GlibType = *mut gst_audio_sys::GstAudioInfo; type GlibType = *mut ffi::GstAudioInfo;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const gst_audio_sys::GstAudioInfo> for AudioInfo { impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo {
type Storage = &'a AudioInfo; type Storage = &'a AudioInfo;
fn to_glib_none( fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioInfo, Self> {
&'a self,
) -> glib::translate::Stash<'a, *const gst_audio_sys::GstAudioInfo, Self> {
glib::translate::Stash(&self.0, self) glib::translate::Stash(&self.0, self)
} }
fn to_glib_full(&self) -> *const gst_audio_sys::GstAudioInfo { fn to_glib_full(&self) -> *const ffi::GstAudioInfo {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_audio_sys::GstAudioInfo> for AudioInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioInfo> for AudioInfo {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_audio_sys::GstAudioInfo) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstAudioInfo) -> Self {
AudioInfo( AudioInfo(
ptr::read(ptr), ptr::read(ptr),
array_init::array_init(|i| from_glib((*ptr).position[i])), array_init::array_init(|i| from_glib((*ptr).position[i])),
@ -405,11 +402,11 @@ impl glib::translate::FromGlibPtrNone<*mut gst_audio_sys::GstAudioInfo> for Audi
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_audio_sys::GstAudioInfo> for AudioInfo { impl glib::translate::FromGlibPtrFull<*mut ffi::GstAudioInfo> for AudioInfo {
#[inline] #[inline]
unsafe fn from_glib_full(ptr: *mut gst_audio_sys::GstAudioInfo) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstAudioInfo) -> Self {
let info = from_glib_none(ptr); let info = from_glib_none(ptr);
glib_sys::g_free(ptr as *mut _); glib::ffi::g_free(ptr as *mut _);
info info
} }
} }
@ -417,42 +414,41 @@ impl glib::translate::FromGlibPtrFull<*mut gst_audio_sys::GstAudioInfo> for Audi
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use gst;
#[test] #[test]
fn test_new() { fn test_new() {
gst::init().unwrap(); gst::init().unwrap();
let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2) let info = AudioInfo::builder(crate::AudioFormat::S16le, 48000, 2)
.build() .build()
.unwrap(); .unwrap();
assert_eq!(info.format(), ::AudioFormat::S16le); assert_eq!(info.format(), crate::AudioFormat::S16le);
assert_eq!(info.rate(), 48000); assert_eq!(info.rate(), 48000);
assert_eq!(info.channels(), 2); assert_eq!(info.channels(), 2);
assert_eq!( assert_eq!(
&info.positions().unwrap(), &info.positions().unwrap(),
&[ &[
::AudioChannelPosition::FrontLeft, crate::AudioChannelPosition::FrontLeft,
::AudioChannelPosition::FrontRight, crate::AudioChannelPosition::FrontRight,
] ]
); );
let positions = [ let positions = [
::AudioChannelPosition::RearLeft, crate::AudioChannelPosition::RearLeft,
::AudioChannelPosition::RearRight, crate::AudioChannelPosition::RearRight,
]; ];
let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2) let info = AudioInfo::builder(crate::AudioFormat::S16le, 48000, 2)
.positions(&positions) .positions(&positions)
.build() .build()
.unwrap(); .unwrap();
assert_eq!(info.format(), ::AudioFormat::S16le); assert_eq!(info.format(), crate::AudioFormat::S16le);
assert_eq!(info.rate(), 48000); assert_eq!(info.rate(), 48000);
assert_eq!(info.channels(), 2); assert_eq!(info.channels(), 2);
assert_eq!( assert_eq!(
&info.positions().unwrap(), &info.positions().unwrap(),
&[ &[
::AudioChannelPosition::RearLeft, crate::AudioChannelPosition::RearLeft,
::AudioChannelPosition::RearRight, crate::AudioChannelPosition::RearRight,
] ]
); );
} }
@ -472,14 +468,14 @@ mod tests {
], ],
); );
let info = AudioInfo::from_caps(&caps).unwrap(); let info = AudioInfo::from_caps(&caps).unwrap();
assert_eq!(info.format(), ::AudioFormat::S16le); assert_eq!(info.format(), crate::AudioFormat::S16le);
assert_eq!(info.rate(), 48000); assert_eq!(info.rate(), 48000);
assert_eq!(info.channels(), 2); assert_eq!(info.channels(), 2);
assert_eq!( assert_eq!(
&info.positions().unwrap(), &info.positions().unwrap(),
&[ &[
::AudioChannelPosition::FrontLeft, crate::AudioChannelPosition::FrontLeft,
::AudioChannelPosition::FrontRight, crate::AudioChannelPosition::FrontRight,
] ]
); );

View file

@ -15,17 +15,14 @@ use std::ptr;
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
use std::slice; use std::slice;
use glib;
use glib::translate::{from_glib, ToGlib}; use glib::translate::{from_glib, ToGlib};
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
use glib::translate::{from_glib_none, ToGlibPtr}; use glib::translate::{from_glib_none, ToGlibPtr};
use gst;
use gst::prelude::*; use gst::prelude::*;
use gst_audio_sys;
#[repr(transparent)] #[repr(transparent)]
pub struct AudioClippingMeta(gst_audio_sys::GstAudioClippingMeta); pub struct AudioClippingMeta(ffi::GstAudioClippingMeta);
unsafe impl Send for AudioClippingMeta {} unsafe impl Send for AudioClippingMeta {}
unsafe impl Sync for AudioClippingMeta {} unsafe impl Sync for AudioClippingMeta {}
@ -41,7 +38,7 @@ impl AudioClippingMeta {
let end = end.into(); let end = end.into();
assert_eq!(start.get_format(), end.get_format()); assert_eq!(start.get_format(), end.get_format());
unsafe { unsafe {
let meta = gst_audio_sys::gst_buffer_add_audio_clipping_meta( let meta = ffi::gst_buffer_add_audio_clipping_meta(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
start.get_format().to_glib(), start.get_format().to_glib(),
start.get_value() as u64, start.get_value() as u64,
@ -62,10 +59,10 @@ impl AudioClippingMeta {
} }
unsafe impl MetaAPI for AudioClippingMeta { unsafe impl MetaAPI for AudioClippingMeta {
type GstType = gst_audio_sys::GstAudioClippingMeta; type GstType = ffi::GstAudioClippingMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
unsafe { from_glib(gst_audio_sys::gst_audio_clipping_meta_api_get_type()) } unsafe { from_glib(ffi::gst_audio_clipping_meta_api_get_type()) }
} }
} }
@ -81,7 +78,7 @@ impl fmt::Debug for AudioClippingMeta {
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
#[repr(transparent)] #[repr(transparent)]
pub struct AudioMeta(gst_audio_sys::GstAudioMeta); pub struct AudioMeta(ffi::GstAudioMeta);
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
@ -95,39 +92,42 @@ unsafe impl Sync for AudioMeta {}
impl AudioMeta { impl AudioMeta {
pub fn add<'a>( pub fn add<'a>(
buffer: &'a mut gst::BufferRef, buffer: &'a mut gst::BufferRef,
info: &::AudioInfo, info: &crate::AudioInfo,
samples: usize, samples: usize,
offsets: &[usize], offsets: &[usize],
) -> Result<gst::MetaRefMut<'a, Self, gst::meta::Standalone>, glib::BoolError> { ) -> Result<gst::MetaRefMut<'a, Self, gst::meta::Standalone>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if !info.is_valid() { if !info.is_valid() {
return Err(glib_bool_error!("Invalid audio info")); return Err(glib::glib_bool_error!("Invalid audio info"));
} }
if info.rate() == 0 if info.rate() == 0
|| info.channels() == 0 || info.channels() == 0
|| info.format() == ::AudioFormat::Unknown || info.format() == crate::AudioFormat::Unknown
|| info.format() == ::AudioFormat::Encoded || info.format() == crate::AudioFormat::Encoded
{ {
return Err(glib_bool_error!("Unsupported audio format {:?}", info)); return Err(glib::glib_bool_error!(
"Unsupported audio format {:?}",
info
));
} }
if !offsets.is_empty() && info.layout() != ::AudioLayout::NonInterleaved { if !offsets.is_empty() && info.layout() != crate::AudioLayout::NonInterleaved {
return Err(glib_bool_error!( return Err(glib::glib_bool_error!(
"Channel offsets only supported for non-interleaved audio" "Channel offsets only supported for non-interleaved audio"
)); ));
} }
if !offsets.is_empty() && offsets.len() != info.channels() as usize { if !offsets.is_empty() && offsets.len() != info.channels() as usize {
return Err(glib_bool_error!( return Err(glib::glib_bool_error!(
"Number of channel offsets different than number of channels ({} != {})", "Number of channel offsets different than number of channels ({} != {})",
offsets.len(), offsets.len(),
info.channels() info.channels()
)); ));
} }
if info.layout() == ::AudioLayout::NonInterleaved { if info.layout() == crate::AudioLayout::NonInterleaved {
let plane_size = samples * (info.width() / 8) as usize; let plane_size = samples * (info.width() / 8) as usize;
let max_offset = if offsets.is_empty() { let max_offset = if offsets.is_empty() {
plane_size * (info.channels() - 1) as usize plane_size * (info.channels() - 1) as usize
@ -146,7 +146,7 @@ impl AudioMeta {
&& !(other_offset + plane_size <= offset && !(other_offset + plane_size <= offset
|| offset + plane_size <= other_offset) || offset + plane_size <= other_offset)
{ {
return Err(glib_bool_error!("Overlapping audio channel offsets: offset {} for channel {} and offset {} for channel {} with a plane size of {}", offset, i, other_offset, j, plane_size)); return Err(glib::glib_bool_error!("Overlapping audio channel offsets: offset {} for channel {} and offset {} for channel {} with a plane size of {}", offset, i, other_offset, j, plane_size));
} }
} }
} }
@ -155,12 +155,12 @@ impl AudioMeta {
}; };
if max_offset + plane_size > buffer.get_size() { if max_offset + plane_size > buffer.get_size() {
return Err(glib_bool_error!("Audio channel offsets out of bounds: max offset {} with plane size {} and buffer size {}", max_offset, plane_size, buffer.get_size())); return Err(glib::glib_bool_error!("Audio channel offsets out of bounds: max offset {} with plane size {} and buffer size {}", max_offset, plane_size, buffer.get_size()));
} }
} }
unsafe { unsafe {
let meta = gst_audio_sys::gst_buffer_add_audio_meta( let meta = ffi::gst_buffer_add_audio_meta(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
info.to_glib_none().0, info.to_glib_none().0,
samples, samples,
@ -172,15 +172,15 @@ impl AudioMeta {
); );
if meta.is_null() { if meta.is_null() {
return Err(glib_bool_error!("Failed to add audio meta")); return Err(glib::glib_bool_error!("Failed to add audio meta"));
} }
Ok(Self::from_mut_ptr(buffer, meta)) Ok(Self::from_mut_ptr(buffer, meta))
} }
} }
pub fn get_info(&self) -> ::AudioInfo { pub fn get_info(&self) -> crate::AudioInfo {
unsafe { from_glib_none(&self.0.info as *const _ as *mut gst_audio_sys::GstAudioInfo) } unsafe { from_glib_none(&self.0.info as *const _ as *mut ffi::GstAudioInfo) }
} }
pub fn get_samples(&self) -> usize { pub fn get_samples(&self) -> usize {
@ -199,10 +199,10 @@ impl AudioMeta {
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
unsafe impl MetaAPI for AudioMeta { unsafe impl MetaAPI for AudioMeta {
type GstType = gst_audio_sys::GstAudioMeta; type GstType = ffi::GstAudioMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
unsafe { from_glib(gst_audio_sys::gst_audio_meta_api_get_type()) } unsafe { from_glib(ffi::gst_audio_meta_api_get_type()) }
} }
} }

View file

@ -1,9 +1,9 @@
use crate::ffi::GstAudioRingBufferSpec;
use glib::translate::*; use glib::translate::*;
use gst::Caps; use gst::Caps;
use gst_audio_sys::GstAudioRingBufferSpec;
use AudioInfo; use crate::AudioInfo;
use AudioRingBufferFormatType; use crate::AudioRingBufferFormatType;
use std::fmt; use std::fmt;
@ -72,7 +72,7 @@ impl Clone for AudioRingBufferSpec {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { unsafe {
let spec = self.0; let spec = self.0;
gst_sys::gst_mini_object_ref(spec.caps as *mut gst_sys::GstMiniObject); gst::ffi::gst_mini_object_ref(spec.caps as *mut gst::ffi::GstMiniObject);
AudioRingBufferSpec(spec) AudioRingBufferSpec(spec)
} }
@ -82,7 +82,7 @@ impl Clone for AudioRingBufferSpec {
impl Drop for AudioRingBufferSpec { impl Drop for AudioRingBufferSpec {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
gst_sys::gst_mini_object_unref(self.0.caps as *mut gst_sys::GstMiniObject); gst::ffi::gst_mini_object_unref(self.0.caps as *mut gst::ffi::GstMiniObject);
} }
} }
} }

View file

@ -6,11 +6,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_audio_sys; use crate::AudioStreamAlign;
use AudioStreamAlign;
use glib::translate::*; use glib::translate::*;
use gst;
use std::mem; use std::mem;
impl AudioStreamAlign { impl AudioStreamAlign {
@ -26,7 +24,7 @@ impl AudioStreamAlign {
let mut out_timestamp = mem::MaybeUninit::uninit(); let mut out_timestamp = mem::MaybeUninit::uninit();
let mut out_duration = mem::MaybeUninit::uninit(); let mut out_duration = mem::MaybeUninit::uninit();
let mut out_sample_position = mem::MaybeUninit::uninit(); let mut out_sample_position = mem::MaybeUninit::uninit();
let ret = from_glib(gst_audio_sys::gst_audio_stream_align_process( let ret = from_glib(ffi::gst_audio_stream_align_process(
self.to_glib_none_mut().0, self.to_glib_none_mut().0,
discont.to_glib(), discont.to_glib(),
timestamp.to_glib(), timestamp.to_glib(),

View file

@ -7,10 +7,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::translate::{from_glib_full, ToGlibPtr}; use glib::translate::{from_glib_full, ToGlibPtr};
use glib::ToSendValue; use glib::ToSendValue;
use gst;
use std::i32; use std::i32;
@ -23,7 +21,7 @@ pub fn audio_buffer_clip(
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib_full(gst_audio_sys::gst_audio_buffer_clip( from_glib_full(ffi::gst_audio_buffer_clip(
buffer.into_ptr(), buffer.into_ptr(),
segment.to_glib_none().0, segment.to_glib_none().0,
rate as i32, rate as i32,
@ -43,7 +41,7 @@ pub fn audio_buffer_truncate(
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib_full(gst_audio_sys::gst_audio_buffer_truncate( from_glib_full(ffi::gst_audio_buffer_truncate(
buffer.into_ptr(), buffer.into_ptr(),
bpf as i32, bpf as i32,
trim, trim,
@ -53,16 +51,16 @@ pub fn audio_buffer_truncate(
} }
pub fn audio_make_raw_caps( pub fn audio_make_raw_caps(
formats: &[::AudioFormat], formats: &[crate::AudioFormat],
layout: ::AudioLayout, layout: crate::AudioLayout,
) -> gst::caps::Builder<gst::caps::NoFeature> { ) -> gst::caps::Builder<gst::caps::NoFeature> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let formats: Vec<glib::SendValue> = formats let formats: Vec<glib::SendValue> = formats
.iter() .iter()
.map(|f| match f { .map(|f| match f {
::AudioFormat::Encoded => panic!("Invalid encoded format"), crate::AudioFormat::Encoded => panic!("Invalid encoded format"),
::AudioFormat::Unknown => panic!("Invalid unknown format"), crate::AudioFormat::Unknown => panic!("Invalid unknown format"),
_ => f.to_string().to_send_value(), _ => f.to_string().to_send_value(),
}) })
.collect(); .collect();
@ -73,24 +71,23 @@ pub fn audio_make_raw_caps(
.field("channels", &gst::IntRange::<i32>::new(1, i32::MAX)); .field("channels", &gst::IntRange::<i32>::new(1, i32::MAX));
match layout { match layout {
::AudioLayout::Interleaved => builder.field("layout", &"interleaved"), crate::AudioLayout::Interleaved => builder.field("layout", &"interleaved"),
::AudioLayout::NonInterleaved => builder.field("layout", &"non-interleaved"), crate::AudioLayout::NonInterleaved => builder.field("layout", &"non-interleaved"),
::AudioLayout::__Unknown(_) => builder, crate::AudioLayout::__Unknown(_) => builder,
} }
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use gst;
#[test] #[test]
fn audio_caps() { fn audio_caps() {
gst::init().unwrap(); gst::init().unwrap();
let caps = audio_make_raw_caps( let caps = audio_make_raw_caps(
&[::AudioFormat::S16be, ::AudioFormat::S16le], &[crate::AudioFormat::S16be, crate::AudioFormat::S16le],
::AudioLayout::Interleaved, crate::AudioLayout::Interleaved,
) )
.build(); .build();
assert_eq!(caps.to_string(), "audio/x-raw, format=(string){ S16BE, S16LE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], layout=(string)interleaved"); assert_eq!(caps.to_string(), "audio/x-raw, format=(string){ S16BE, S16LE }, rate=(int)[ 1, 2147483647 ], channels=(int)[ 1, 2147483647 ], layout=(string)interleaved");
@ -101,15 +98,15 @@ mod tests {
/* audio_make_raw_caps() is a re-implementation so ensure it returns the same caps as the C API */ /* audio_make_raw_caps() is a re-implementation so ensure it returns the same caps as the C API */
let c_caps = unsafe { let c_caps = unsafe {
let formats: Vec<gst_audio_sys::GstAudioFormat> = let formats: Vec<ffi::GstAudioFormat> =
[::AudioFormat::S16be, ::AudioFormat::S16le] [crate::AudioFormat::S16be, crate::AudioFormat::S16le]
.iter() .iter()
.map(|f| f.to_glib()) .map(|f| f.to_glib())
.collect(); .collect();
let caps = gst_audio_sys::gst_audio_make_raw_caps( let caps = ffi::gst_audio_make_raw_caps(
formats.as_ptr(), formats.as_ptr(),
formats.len() as u32, formats.len() as u32,
gst_audio_sys::GST_AUDIO_LAYOUT_INTERLEAVED, ffi::GST_AUDIO_LAYOUT_INTERLEAVED,
); );
from_glib_full(caps) from_glib_full(caps)
}; };
@ -117,8 +114,8 @@ mod tests {
} }
let caps = audio_make_raw_caps( let caps = audio_make_raw_caps(
&[::AudioFormat::S16be, ::AudioFormat::S16le], &[crate::AudioFormat::S16be, crate::AudioFormat::S16le],
::AudioLayout::NonInterleaved, crate::AudioLayout::NonInterleaved,
) )
.field("rate", &16000) .field("rate", &16000)
.field("channels", &2) .field("channels", &2)
@ -133,13 +130,19 @@ mod tests {
#[should_panic(expected = "Invalid encoded format")] #[should_panic(expected = "Invalid encoded format")]
fn audio_caps_encoded() { fn audio_caps_encoded() {
gst::init().unwrap(); gst::init().unwrap();
audio_make_raw_caps(&[::AudioFormat::Encoded], ::AudioLayout::Interleaved); audio_make_raw_caps(
&[crate::AudioFormat::Encoded],
crate::AudioLayout::Interleaved,
);
} }
#[test] #[test]
#[should_panic(expected = "Invalid unknown format")] #[should_panic(expected = "Invalid unknown format")]
fn audio_caps_unknown() { fn audio_caps_unknown() {
gst::init().unwrap(); gst::init().unwrap();
audio_make_raw_caps(&[::AudioFormat::Unknown], ::AudioLayout::Interleaved); audio_make_raw_caps(
&[crate::AudioFormat::Unknown],
crate::AudioLayout::Interleaved,
);
} }
} }

View file

@ -8,28 +8,11 @@
#![cfg_attr(feature = "dox", feature(doc_cfg))] #![cfg_attr(feature = "dox", feature(doc_cfg))]
extern crate array_init; pub use ffi;
#[macro_use]
extern crate bitflags;
extern crate once_cell;
#[macro_use]
extern crate glib;
extern crate glib_sys;
extern crate gobject_sys;
#[macro_use]
extern crate gstreamer as gst;
extern crate gstreamer_audio_sys as gst_audio_sys;
extern crate gstreamer_base as gst_base;
extern crate gstreamer_base_sys as gst_base_sys;
extern crate gstreamer_sys as gst_sys;
#[cfg(test)]
extern crate itertools;
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => { () => {
if unsafe { ::gst_sys::gst_is_initialized() } != ::glib_sys::GTRUE { if unsafe { gst::ffi::gst_is_initialized() } != glib::ffi::GTRUE {
panic!("GStreamer has not been initialized. Call `gst::init` first."); panic!("GStreamer has not been initialized. Call `gst::init` first.");
} }
}; };
@ -44,25 +27,25 @@ macro_rules! skip_assert_initialized {
#[allow(clippy::match_same_arms)] #[allow(clippy::match_same_arms)]
#[allow(unused_imports)] #[allow(unused_imports)]
mod auto; mod auto;
pub use auto::*; pub use crate::auto::*;
mod audio_format; mod audio_format;
pub use audio_format::*; pub use crate::audio_format::*;
mod audio_format_info; mod audio_format_info;
pub use audio_format_info::*; pub use crate::audio_format_info::*;
mod audio_ring_buffer_spec; mod audio_ring_buffer_spec;
pub use audio_ring_buffer_spec::*; pub use crate::audio_ring_buffer_spec::*;
mod audio_info; mod audio_info;
pub use audio_info::*; pub use crate::audio_info::*;
mod audio_meta; mod audio_meta;
pub use audio_meta::*; pub use crate::audio_meta::*;
mod audio_channel_position; mod audio_channel_position;
pub use audio_channel_position::*; pub use crate::audio_channel_position::*;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
mod audio_stream_align; mod audio_stream_align;
mod functions; mod functions;
pub use functions::*; pub use crate::functions::*;
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub mod audio_buffer; pub mod audio_buffer;
@ -71,9 +54,9 @@ pub mod audio_buffer;
pub use audio_buffer::{AudioBuffer, AudioBufferRef}; pub use audio_buffer::{AudioBuffer, AudioBufferRef};
mod audio_decoder; mod audio_decoder;
pub use audio_decoder::AudioDecoderExtManual; pub use crate::audio_decoder::AudioDecoderExtManual;
mod audio_encoder; mod audio_encoder;
pub use audio_encoder::AudioEncoderExtManual; pub use crate::audio_encoder::AudioEncoderExtManual;
// Re-export all the traits in a prelude module, so that applications // Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts // can always "use gst::prelude::*" without getting conflicts
@ -83,8 +66,8 @@ pub mod prelude {
pub use super::audio_decoder::AudioDecoderExtManual; pub use super::audio_decoder::AudioDecoderExtManual;
pub use super::audio_encoder::AudioEncoderExtManual; pub use super::audio_encoder::AudioEncoderExtManual;
pub use audio_format::AudioFormatIteratorExt; pub use crate::audio_format::AudioFormatIteratorExt;
pub use auto::traits::*; pub use crate::auto::traits::*;
} }
pub mod subclass; pub mod subclass;

View file

@ -6,23 +6,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_audio_sys;
use gst_sys;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use gst;
use gst::subclass::prelude::*; use gst::subclass::prelude::*;
use gst_base;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use crate::prelude::*; use crate::prelude::*;
use AudioDecoder; use crate::AudioDecoder;
pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl { pub trait AudioDecoderImpl: AudioDecoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
@ -178,8 +172,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
@ -190,7 +183,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `open` failed"] ["Parent function `open` failed"]
)) ))
@ -203,8 +196,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
@ -215,7 +207,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `close` failed"] ["Parent function `close` failed"]
)) ))
@ -228,8 +220,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
@ -240,7 +231,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `start` failed"] ["Parent function `start` failed"]
)) ))
@ -253,8 +244,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
@ -265,7 +255,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `stop` failed"] ["Parent function `stop` failed"]
)) ))
@ -282,12 +272,11 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.set_format .set_format
.map(|f| { .map(|f| {
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0,
caps.to_glib_none().0 caps.to_glib_none().0
@ -307,8 +296,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<(u32, u32), gst::FlowError> { ) -> Result<(u32, u32), gst::FlowError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.parse .parse
.map(|f| { .map(|f| {
@ -343,15 +331,14 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowReturn::from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst_sys::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
)) ))
}) })
@ -367,8 +354,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<Option<gst::Buffer>, gst::FlowError> { ) -> Result<Option<gst::Buffer>, gst::FlowError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_ptr(); let mut buffer = buffer.into_ptr();
match gst::FlowReturn::from_glib(f( match gst::FlowReturn::from_glib(f(
@ -389,8 +375,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_flush(&self, element: &Self::Type, hard: bool) { fn parent_flush(&self, element: &Self::Type, hard: bool) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.flush .flush
.map(|f| { .map(|f| {
@ -406,12 +391,11 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.negotiate .negotiate
.map(|f| { .map(|f| {
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0), f(element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
@ -424,8 +408,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.getcaps .getcaps
.map(|f| { .map(|f| {
@ -445,8 +428,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
let f = (*parent_class) let f = (*parent_class)
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
@ -460,8 +442,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
let f = (*parent_class) let f = (*parent_class)
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
@ -475,8 +456,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
let f = (*parent_class) let f = (*parent_class)
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
@ -490,8 +470,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
let f = (*parent_class) let f = (*parent_class)
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
@ -509,8 +488,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<(), gst::ErrorMessage> { ) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.propose_allocation .propose_allocation
.map(|f| { .map(|f| {
@ -520,7 +498,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
)) { )) {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `propose_allocation` failed"] ["Parent function `propose_allocation` failed"]
)) ))
@ -537,8 +515,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
) -> Result<(), gst::ErrorMessage> { ) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioDecoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioDecoderClass;
(*parent_class) (*parent_class)
.decide_allocation .decide_allocation
.map(|f| { .map(|f| {
@ -548,7 +525,7 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
)) { )) {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `decide_allocation` failed"] ["Parent function `decide_allocation` failed"]
)) ))
@ -587,8 +564,8 @@ where
} }
unsafe extern "C" fn audio_decoder_open<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_open<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -596,7 +573,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -609,8 +586,8 @@ where
} }
unsafe extern "C" fn audio_decoder_close<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_close<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -618,7 +595,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -631,8 +608,8 @@ where
} }
unsafe extern "C" fn audio_decoder_start<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_start<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -640,7 +617,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -653,8 +630,8 @@ where
} }
unsafe extern "C" fn audio_decoder_stop<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_stop<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -662,7 +639,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -675,9 +652,9 @@ where
} }
unsafe extern "C" fn audio_decoder_set_format<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_set_format<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
caps: *mut gst_sys::GstCaps, caps: *mut gst::ffi::GstCaps,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -685,7 +662,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_borrow(caps)) { match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_borrow(caps)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -698,11 +675,11 @@ where
} }
unsafe extern "C" fn audio_decoder_parse<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_parse<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
adapter: *mut gst_base_sys::GstAdapter, adapter: *mut gst_base::ffi::GstAdapter,
offset: *mut i32, offset: *mut i32,
len: *mut i32, len: *mut i32,
) -> gst_sys::GstFlowReturn ) -> gst::ffi::GstFlowReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -710,7 +687,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
match imp.parse(wrap.unsafe_cast_ref(), &from_glib_borrow(adapter)) { match imp.parse(wrap.unsafe_cast_ref(), &from_glib_borrow(adapter)) {
Ok((new_offset, new_len)) => { Ok((new_offset, new_len)) => {
assert!(new_offset <= std::i32::MAX as u32); assert!(new_offset <= std::i32::MAX as u32);
@ -727,19 +704,19 @@ where
} }
unsafe extern "C" fn audio_decoder_handle_frame<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_handle_frame<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut gst::ffi::GstBuffer,
) -> gst_sys::GstFlowReturn ) -> gst::ffi::GstFlowReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
// FIXME: Misgenerated in gstreamer-audio-sys // FIXME: Misgenerated in gstreamer-audio-sys
let buffer = buffer as *mut gst_sys::GstBuffer; let buffer = buffer as *mut gst::ffi::GstBuffer;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.handle_frame( imp.handle_frame(
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
Option::<gst::Buffer>::from_glib_none(buffer).as_ref(), Option::<gst::Buffer>::from_glib_none(buffer).as_ref(),
@ -750,9 +727,9 @@ where
} }
unsafe extern "C" fn audio_decoder_pre_push<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_pre_push<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut gst::ffi::GstBuffer,
) -> gst_sys::GstFlowReturn ) -> gst::ffi::GstFlowReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -760,7 +737,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) { match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) {
Ok(Some(new_buffer)) => { Ok(Some(new_buffer)) => {
*buffer = new_buffer.into_ptr(); *buffer = new_buffer.into_ptr();
@ -778,8 +755,8 @@ where
} }
unsafe extern "C" fn audio_decoder_flush<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_flush<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
hard: glib_sys::gboolean, hard: glib::ffi::gboolean,
) where ) where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -787,14 +764,14 @@ unsafe extern "C" fn audio_decoder_flush<T: AudioDecoderImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), { gst::gst_panic_to_error!(&wrap, &instance.panicked(), (), {
AudioDecoderImpl::flush(imp, wrap.unsafe_cast_ref(), from_glib(hard)) AudioDecoderImpl::flush(imp, wrap.unsafe_cast_ref(), from_glib(hard))
}) })
} }
unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_negotiate<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -802,7 +779,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -815,9 +792,9 @@ where
} }
unsafe extern "C" fn audio_decoder_getcaps<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_getcaps<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
filter: *mut gst_sys::GstCaps, filter: *mut gst::ffi::GstCaps,
) -> *mut gst_sys::GstCaps ) -> *mut gst::ffi::GstCaps
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -825,7 +802,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), {
AudioDecoderImpl::get_caps( AudioDecoderImpl::get_caps(
imp, imp,
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
@ -838,9 +815,9 @@ where
} }
unsafe extern "C" fn audio_decoder_sink_event<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_sink_event<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
event: *mut gst_sys::GstEvent, event: *mut gst::ffi::GstEvent,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -848,16 +825,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event)) imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_sink_query<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -865,16 +842,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_decoder_src_event<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_src_event<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
event: *mut gst_sys::GstEvent, event: *mut gst::ffi::GstEvent,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -882,16 +859,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event)) imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_src_query<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -899,16 +876,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_decoder_propose_allocation<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_propose_allocation<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -917,7 +894,7 @@ where
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query); let query = gst::QueryRef::from_mut_ptr(query);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -930,9 +907,9 @@ where
} }
unsafe extern "C" fn audio_decoder_decide_allocation<T: AudioDecoderImpl>( unsafe extern "C" fn audio_decoder_decide_allocation<T: AudioDecoderImpl>(
ptr: *mut gst_audio_sys::GstAudioDecoder, ptr: *mut ffi::GstAudioDecoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -941,7 +918,7 @@ where
let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioDecoder> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query); let query = gst::QueryRef::from_mut_ptr(query);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {

View file

@ -6,22 +6,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_audio_sys;
use gst_sys;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use gst;
use gst::subclass::prelude::*; use gst::subclass::prelude::*;
use std::ptr; use std::ptr;
use crate::prelude::*; use crate::prelude::*;
use AudioEncoder; use crate::AudioEncoder;
use AudioInfo; use crate::AudioInfo;
pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl { pub trait AudioEncoderImpl: AudioEncoderImplExt + ElementImpl {
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
@ -163,8 +158,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.open .open
.map(|f| { .map(|f| {
@ -175,7 +169,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `open` failed"] ["Parent function `open` failed"]
)) ))
@ -188,8 +182,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.close .close
.map(|f| { .map(|f| {
@ -200,7 +193,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `close` failed"] ["Parent function `close` failed"]
)) ))
@ -213,8 +206,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.start .start
.map(|f| { .map(|f| {
@ -225,7 +217,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `start` failed"] ["Parent function `start` failed"]
)) ))
@ -238,8 +230,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> { fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.stop .stop
.map(|f| { .map(|f| {
@ -250,7 +241,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
{ {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `stop` failed"] ["Parent function `stop` failed"]
)) ))
@ -267,12 +258,11 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.set_format .set_format
.map(|f| { .map(|f| {
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f( f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0,
info.to_glib_none().0 as *mut _ info.to_glib_none().0 as *mut _
@ -292,15 +282,14 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowReturn::from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst_sys::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
)) ))
}) })
@ -316,8 +305,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
) -> Result<Option<gst::Buffer>, gst::FlowError> { ) -> Result<Option<gst::Buffer>, gst::FlowError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_ptr(); let mut buffer = buffer.into_ptr();
match gst::FlowReturn::from_glib(f( match gst::FlowReturn::from_glib(f(
@ -338,8 +326,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_flush(&self, element: &Self::Type) { fn parent_flush(&self, element: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.flush .flush
.map(|f| f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0)) .map(|f| f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0))
@ -350,12 +337,11 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> { fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.negotiate .negotiate
.map(|f| { .map(|f| {
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0), f(element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `negotiate` failed" "Parent function `negotiate` failed"
@ -368,8 +354,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps { fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.getcaps .getcaps
.map(|f| { .map(|f| {
@ -389,8 +374,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
let f = (*parent_class) let f = (*parent_class)
.sink_event .sink_event
.expect("Missing parent function `sink_event`"); .expect("Missing parent function `sink_event`");
@ -404,8 +388,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
let f = (*parent_class) let f = (*parent_class)
.sink_query .sink_query
.expect("Missing parent function `sink_query`"); .expect("Missing parent function `sink_query`");
@ -419,8 +402,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool { fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
let f = (*parent_class) let f = (*parent_class)
.src_event .src_event
.expect("Missing parent function `src_event`"); .expect("Missing parent function `src_event`");
@ -434,8 +416,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool { fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
let f = (*parent_class) let f = (*parent_class)
.src_query .src_query
.expect("Missing parent function `src_query`"); .expect("Missing parent function `src_query`");
@ -453,8 +434,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
) -> Result<(), gst::ErrorMessage> { ) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.propose_allocation .propose_allocation
.map(|f| { .map(|f| {
@ -464,7 +444,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
)) { )) {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `propose_allocation` failed"] ["Parent function `propose_allocation` failed"]
)) ))
@ -481,8 +461,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
) -> Result<(), gst::ErrorMessage> { ) -> Result<(), gst::ErrorMessage> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioEncoderClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioEncoderClass;
(*parent_class) (*parent_class)
.decide_allocation .decide_allocation
.map(|f| { .map(|f| {
@ -492,7 +471,7 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
)) { )) {
Ok(()) Ok(())
} else { } else {
Err(gst_error_msg!( Err(gst::gst_error_msg!(
gst::CoreError::StateChange, gst::CoreError::StateChange,
["Parent function `decide_allocation` failed"] ["Parent function `decide_allocation` failed"]
)) ))
@ -530,8 +509,8 @@ where
} }
unsafe extern "C" fn audio_encoder_open<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_open<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -539,7 +518,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -552,8 +531,8 @@ where
} }
unsafe extern "C" fn audio_encoder_close<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_close<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -561,7 +540,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -574,8 +553,8 @@ where
} }
unsafe extern "C" fn audio_encoder_start<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_start<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -583,7 +562,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.start(wrap.unsafe_cast_ref()) { match imp.start(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -596,8 +575,8 @@ where
} }
unsafe extern "C" fn audio_encoder_stop<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_stop<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -605,7 +584,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.stop(wrap.unsafe_cast_ref()) { match imp.stop(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -618,9 +597,9 @@ where
} }
unsafe extern "C" fn audio_encoder_set_format<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_set_format<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
info: *mut gst_audio_sys::GstAudioInfo, info: *mut ffi::GstAudioInfo,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -628,7 +607,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_none(info)) { match imp.set_format(wrap.unsafe_cast_ref(), &from_glib_none(info)) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -641,19 +620,19 @@ where
} }
unsafe extern "C" fn audio_encoder_handle_frame<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_handle_frame<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut gst::ffi::GstBuffer,
) -> gst_sys::GstFlowReturn ) -> gst::ffi::GstFlowReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
// FIXME: Misgenerated in gstreamer-audio-sys // FIXME: Misgenerated in gstreamer-audio-sys
let buffer = buffer as *mut gst_sys::GstBuffer; let buffer = buffer as *mut gst::ffi::GstBuffer;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.handle_frame( imp.handle_frame(
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
Option::<gst::Buffer>::from_glib_none(buffer).as_ref(), Option::<gst::Buffer>::from_glib_none(buffer).as_ref(),
@ -664,9 +643,9 @@ where
} }
unsafe extern "C" fn audio_encoder_pre_push<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_pre_push<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut gst::ffi::GstBuffer,
) -> gst_sys::GstFlowReturn ) -> gst::ffi::GstFlowReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -674,7 +653,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) { match imp.pre_push(wrap.unsafe_cast_ref(), from_glib_full(*buffer)) {
Ok(Some(new_buffer)) => { Ok(Some(new_buffer)) => {
*buffer = new_buffer.into_ptr(); *buffer = new_buffer.into_ptr();
@ -691,23 +670,7 @@ where
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_encoder_flush<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_flush<T: AudioEncoderImpl>(ptr: *mut ffi::GstAudioEncoder)
ptr: *mut gst_audio_sys::GstAudioEncoder,
) where
T::Instance: PanicPoison,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
AudioEncoderImpl::flush(imp, wrap.unsafe_cast_ref())
})
}
unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder,
) -> glib_sys::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -715,7 +678,22 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), (), {
AudioEncoderImpl::flush(imp, wrap.unsafe_cast_ref())
})
}
unsafe extern "C" fn audio_encoder_negotiate<T: AudioEncoderImpl>(
ptr: *mut ffi::GstAudioEncoder,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.negotiate(wrap.unsafe_cast_ref()) { match imp.negotiate(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -728,9 +706,9 @@ where
} }
unsafe extern "C" fn audio_encoder_getcaps<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_getcaps<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
filter: *mut gst_sys::GstCaps, filter: *mut gst::ffi::GstCaps,
) -> *mut gst_sys::GstCaps ) -> *mut gst::ffi::GstCaps
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -738,7 +716,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), { gst::gst_panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), {
AudioEncoderImpl::get_caps( AudioEncoderImpl::get_caps(
imp, imp,
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
@ -751,9 +729,9 @@ where
} }
unsafe extern "C" fn audio_encoder_sink_event<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_sink_event<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
event: *mut gst_sys::GstEvent, event: *mut gst::ffi::GstEvent,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -761,16 +739,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event)) imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_sink_query<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -778,16 +756,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_encoder_src_event<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_src_event<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
event: *mut gst_sys::GstEvent, event: *mut gst::ffi::GstEvent,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -795,16 +773,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event)) imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_src_query<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -812,16 +790,16 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query)) imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
}) })
.to_glib() .to_glib()
} }
unsafe extern "C" fn audio_encoder_propose_allocation<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_propose_allocation<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -830,7 +808,7 @@ where
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query); let query = gst::QueryRef::from_mut_ptr(query);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) { match imp.propose_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -843,9 +821,9 @@ where
} }
unsafe extern "C" fn audio_encoder_decide_allocation<T: AudioEncoderImpl>( unsafe extern "C" fn audio_encoder_decide_allocation<T: AudioEncoderImpl>(
ptr: *mut gst_audio_sys::GstAudioEncoder, ptr: *mut ffi::GstAudioEncoder,
query: *mut gst_sys::GstQuery, query: *mut gst::ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -854,7 +832,7 @@ where
let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr); let wrap: Borrowed<AudioEncoder> = from_glib_borrow(ptr);
let query = gst::QueryRef::from_mut_ptr(query); let query = gst::QueryRef::from_mut_ptr(query);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) { match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {

View file

@ -1,6 +1,3 @@
use glib_sys;
use gst_audio_sys;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
@ -9,8 +6,8 @@ use gst::subclass::prelude::*;
use gst::LoggableError; use gst::LoggableError;
use gst_base::subclass::prelude::*; use gst_base::subclass::prelude::*;
use AudioRingBufferSpec; use crate::AudioRingBufferSpec;
use AudioSink; use crate::AudioSink;
pub trait AudioSinkImpl: AudioSinkImplExt + BaseSinkImpl { pub trait AudioSinkImpl: AudioSinkImplExt + BaseSinkImpl {
fn close(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn close(&self, sink: &Self::Type) -> Result<(), LoggableError> {
@ -64,13 +61,12 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_close(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_close(&self, sink: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).close { let f = match (*parent_class).close {
None => return Ok(()), None => return Ok(()),
Some(f) => f, Some(f) => f,
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to close element using the parent function" "Failed to close element using the parent function"
@ -81,8 +77,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_delay(&self, sink: &Self::Type) -> u32 { fn parent_delay(&self, sink: &Self::Type) -> u32 {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).delay { let f = match (*parent_class).delay {
Some(f) => f, Some(f) => f,
None => return 0, None => return 0,
@ -94,13 +89,12 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_open(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_open(&self, sink: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).open { let f = match (*parent_class).open {
Some(f) => f, Some(f) => f,
None => return Ok(()), None => return Ok(()),
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to open element using the parent function" "Failed to open element using the parent function"
@ -115,13 +109,12 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).prepare { let f = match (*parent_class).prepare {
Some(f) => f, Some(f) => f,
None => return Ok(()), None => return Ok(()),
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f( f(
sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0, sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0,
&mut spec.0 &mut spec.0
@ -135,8 +128,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_unprepare(&self, sink: &Self::Type) -> Result<(), LoggableError> { fn parent_unprepare(&self, sink: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).unprepare { let f = match (*parent_class).unprepare {
Some(f) => f, Some(f) => f,
None => { None => {
@ -146,7 +138,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
)) ))
} }
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0), f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to unprepare element using the parent function" "Failed to unprepare element using the parent function"
@ -157,8 +149,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_write(&self, sink: &Self::Type, buffer: &[u8]) -> Result<i32, LoggableError> { fn parent_write(&self, sink: &Self::Type, buffer: &[u8]) -> Result<i32, LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
let f = match (*parent_class).write { let f = match (*parent_class).write {
Some(f) => f, Some(f) => f,
None => return Ok(-1), None => return Ok(-1),
@ -183,8 +174,7 @@ impl<T: AudioSinkImpl> AudioSinkImplExt for T {
fn parent_reset(&self, sink: &Self::Type) { fn parent_reset(&self, sink: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSinkClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSinkClass;
if let Some(f) = (*parent_class).reset { if let Some(f) = (*parent_class).reset {
f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0) f(sink.unsafe_cast_ref::<AudioSink>().to_glib_none().0)
} }
@ -210,8 +200,8 @@ where
} }
unsafe extern "C" fn audiosink_close<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_close<T: AudioSinkImpl>(
ptr: *mut gst_audio_sys::GstAudioSink, ptr: *mut ffi::GstAudioSink,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -219,7 +209,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -231,7 +221,7 @@ where
.to_glib() .to_glib()
} }
unsafe extern "C" fn audiosink_delay<T: AudioSinkImpl>(ptr: *mut gst_audio_sys::GstAudioSink) -> u32 unsafe extern "C" fn audiosink_delay<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink) -> u32
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -239,14 +229,14 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), 0, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), 0, {
imp.delay(wrap.unsafe_cast_ref()) imp.delay(wrap.unsafe_cast_ref())
}) })
} }
unsafe extern "C" fn audiosink_open<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_open<T: AudioSinkImpl>(
ptr: *mut gst_audio_sys::GstAudioSink, ptr: *mut ffi::GstAudioSink,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -254,7 +244,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -267,9 +257,9 @@ where
} }
unsafe extern "C" fn audiosink_prepare<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_prepare<T: AudioSinkImpl>(
ptr: *mut gst_audio_sys::GstAudioSink, ptr: *mut ffi::GstAudioSink,
spec: *mut gst_audio_sys::GstAudioRingBufferSpec, spec: *mut ffi::GstAudioRingBufferSpec,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -279,7 +269,7 @@ where
let spec = &mut *(spec as *mut AudioRingBufferSpec); let spec = &mut *(spec as *mut AudioRingBufferSpec);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match AudioSinkImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) { match AudioSinkImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -292,8 +282,8 @@ where
} }
unsafe extern "C" fn audiosink_unprepare<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_unprepare<T: AudioSinkImpl>(
ptr: *mut gst_audio_sys::GstAudioSink, ptr: *mut ffi::GstAudioSink,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -301,7 +291,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.unprepare(wrap.unsafe_cast_ref()) { match imp.unprepare(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -314,8 +304,8 @@ where
} }
unsafe extern "C" fn audiosink_write<T: AudioSinkImpl>( unsafe extern "C" fn audiosink_write<T: AudioSinkImpl>(
ptr: *mut gst_audio_sys::GstAudioSink, ptr: *mut ffi::GstAudioSink,
data: glib_sys::gpointer, data: glib::ffi::gpointer,
length: u32, length: u32,
) -> i32 ) -> i32
where where
@ -326,12 +316,12 @@ where
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
let data_slice = std::slice::from_raw_parts(data as *const u8, length as usize); let data_slice = std::slice::from_raw_parts(data as *const u8, length as usize);
gst_panic_to_error!(&wrap, &instance.panicked(), -1, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), -1, {
imp.write(wrap.unsafe_cast_ref(), data_slice).unwrap_or(-1) imp.write(wrap.unsafe_cast_ref(), data_slice).unwrap_or(-1)
}) })
} }
unsafe extern "C" fn audiosink_reset<T: AudioSinkImpl>(ptr: *mut gst_audio_sys::GstAudioSink) unsafe extern "C" fn audiosink_reset<T: AudioSinkImpl>(ptr: *mut ffi::GstAudioSink)
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -339,7 +329,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSink> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), { gst::gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.reset(wrap.unsafe_cast_ref()); imp.reset(wrap.unsafe_cast_ref());
}); });
} }

View file

@ -1,6 +1,3 @@
use glib_sys;
use gst_audio_sys;
use std::mem; use std::mem;
use glib::prelude::*; use glib::prelude::*;
@ -11,8 +8,8 @@ use gst::subclass::prelude::*;
use gst::LoggableError; use gst::LoggableError;
use gst_base::subclass::prelude::*; use gst_base::subclass::prelude::*;
use AudioRingBufferSpec; use crate::AudioRingBufferSpec;
use AudioSrc; use crate::AudioSrc;
pub trait AudioSrcImpl: AudioSrcImplExt + BaseSrcImpl { pub trait AudioSrcImpl: AudioSrcImplExt + BaseSrcImpl {
fn close(&self, src: &Self::Type) -> Result<(), LoggableError> { fn close(&self, src: &Self::Type) -> Result<(), LoggableError> {
@ -74,13 +71,12 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_close(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_close(&self, src: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).close { let f = match (*parent_class).close {
None => return Ok(()), None => return Ok(()),
Some(f) => f, Some(f) => f,
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to close element using the parent function" "Failed to close element using the parent function"
@ -91,8 +87,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_delay(&self, src: &Self::Type) -> u32 { fn parent_delay(&self, src: &Self::Type) -> u32 {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).delay { let f = match (*parent_class).delay {
Some(f) => f, Some(f) => f,
None => return 0, None => return 0,
@ -104,13 +99,12 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_open(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_open(&self, src: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).open { let f = match (*parent_class).open {
Some(f) => f, Some(f) => f,
None => return Ok(()), None => return Ok(()),
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to open element using the parent function" "Failed to open element using the parent function"
@ -125,13 +119,12 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).prepare { let f = match (*parent_class).prepare {
Some(f) => f, Some(f) => f,
None => return Ok(()), None => return Ok(()),
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f( f(
src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0, src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0,
&mut spec.0 &mut spec.0
@ -145,8 +138,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_unprepare(&self, src: &Self::Type) -> Result<(), LoggableError> { fn parent_unprepare(&self, src: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).unprepare { let f = match (*parent_class).unprepare {
Some(f) => f, Some(f) => f,
None => { None => {
@ -156,7 +148,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
)) ))
} }
}; };
gst_result_from_gboolean!( gst::gst_result_from_gboolean!(
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0), f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Failed to unprepare element using the parent function" "Failed to unprepare element using the parent function"
@ -171,8 +163,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
) -> Result<(u32, gst::ClockTime), LoggableError> { ) -> Result<(u32, gst::ClockTime), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
let f = match (*parent_class).read { let f = match (*parent_class).read {
Some(f) => f, Some(f) => f,
None => return Ok((0, gst::CLOCK_TIME_NONE)), None => return Ok((0, gst::CLOCK_TIME_NONE)),
@ -199,8 +190,7 @@ impl<T: AudioSrcImpl> AudioSrcImplExt for T {
fn parent_reset(&self, src: &Self::Type) { fn parent_reset(&self, src: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAudioSrcClass;
data.as_ref().get_parent_class() as *mut gst_audio_sys::GstAudioSrcClass;
if let Some(f) = (*parent_class).reset { if let Some(f) = (*parent_class).reset {
f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0) f(src.unsafe_cast_ref::<AudioSrc>().to_glib_none().0)
} }
@ -226,8 +216,8 @@ where
} }
unsafe extern "C" fn audiosrc_close<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_close<T: AudioSrcImpl>(
ptr: *mut gst_audio_sys::GstAudioSrc, ptr: *mut ffi::GstAudioSrc,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -235,7 +225,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.close(wrap.unsafe_cast_ref()) { match imp.close(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -247,7 +237,7 @@ where
.to_glib() .to_glib()
} }
unsafe extern "C" fn audiosrc_delay<T: AudioSrcImpl>(ptr: *mut gst_audio_sys::GstAudioSrc) -> u32 unsafe extern "C" fn audiosrc_delay<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc) -> u32
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -255,14 +245,14 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), 0, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), 0, {
imp.delay(wrap.unsafe_cast_ref()) imp.delay(wrap.unsafe_cast_ref())
}) })
} }
unsafe extern "C" fn audiosrc_open<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_open<T: AudioSrcImpl>(
ptr: *mut gst_audio_sys::GstAudioSrc, ptr: *mut ffi::GstAudioSrc,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -270,7 +260,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.open(wrap.unsafe_cast_ref()) { match imp.open(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -283,9 +273,9 @@ where
} }
unsafe extern "C" fn audiosrc_prepare<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_prepare<T: AudioSrcImpl>(
ptr: *mut gst_audio_sys::GstAudioSrc, ptr: *mut ffi::GstAudioSrc,
spec: *mut gst_audio_sys::GstAudioRingBufferSpec, spec: *mut ffi::GstAudioRingBufferSpec,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -295,7 +285,7 @@ where
let spec = &mut *(spec as *mut AudioRingBufferSpec); let spec = &mut *(spec as *mut AudioRingBufferSpec);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match AudioSrcImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) { match AudioSrcImpl::prepare(imp, wrap.unsafe_cast_ref(), spec) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -308,8 +298,8 @@ where
} }
unsafe extern "C" fn audiosrc_unprepare<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_unprepare<T: AudioSrcImpl>(
ptr: *mut gst_audio_sys::GstAudioSrc, ptr: *mut ffi::GstAudioSrc,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -317,7 +307,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.unprepare(wrap.unsafe_cast_ref()) { match imp.unprepare(wrap.unsafe_cast_ref()) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
@ -330,10 +320,10 @@ where
} }
unsafe extern "C" fn audiosrc_read<T: AudioSrcImpl>( unsafe extern "C" fn audiosrc_read<T: AudioSrcImpl>(
ptr: *mut gst_audio_sys::GstAudioSrc, ptr: *mut ffi::GstAudioSrc,
data: glib_sys::gpointer, data: glib::ffi::gpointer,
length: u32, length: u32,
timestamp: *mut gst_sys::GstClockTime, timestamp: *mut gst::ffi::GstClockTime,
) -> u32 ) -> u32
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
@ -343,7 +333,7 @@ where
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
let data_slice = std::slice::from_raw_parts_mut(data as *mut u8, length as usize); let data_slice = std::slice::from_raw_parts_mut(data as *mut u8, length as usize);
gst_panic_to_error!(&wrap, &instance.panicked(), 0, { gst::gst_panic_to_error!(&wrap, &instance.panicked(), 0, {
let (res, timestamp_res) = imp let (res, timestamp_res) = imp
.read(wrap.unsafe_cast_ref(), data_slice) .read(wrap.unsafe_cast_ref(), data_slice)
.unwrap_or((0, gst::CLOCK_TIME_NONE)); .unwrap_or((0, gst::CLOCK_TIME_NONE));
@ -353,7 +343,7 @@ where
}) })
} }
unsafe extern "C" fn audiosrc_reset<T: AudioSrcImpl>(ptr: *mut gst_audio_sys::GstAudioSrc) unsafe extern "C" fn audiosrc_reset<T: AudioSrcImpl>(ptr: *mut ffi::GstAudioSrc)
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -361,7 +351,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr); let wrap: Borrowed<AudioSrc> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), { gst::gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.reset(wrap.unsafe_cast_ref()); imp.reset(wrap.unsafe_cast_ref());
}); });
} }