1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::ptr; |
4 | |
5 | use glib::translate::*; |
6 | use gst_base::{prelude::*, subclass::prelude::*}; |
7 | |
8 | use crate::AudioAggregatorPad; |
9 | |
10 | pub trait AudioAggregatorPadImpl: AudioAggregatorPadImplExt + AggregatorPadImpl { |
11 | const HANDLE_CONVERSION: bool = false; |
12 | |
13 | fn update_conversion_info(&self) { |
14 | self.parent_update_conversion_info() |
15 | } |
16 | |
17 | fn convert_buffer( |
18 | &self, |
19 | in_info: &crate::AudioInfo, |
20 | out_info: &crate::AudioInfo, |
21 | buffer: &gst::Buffer, |
22 | ) -> Option<gst::Buffer> { |
23 | self.parent_convert_buffer(in_info, out_info, buffer) |
24 | } |
25 | } |
26 | |
27 | mod sealed { |
28 | pub trait Sealed {} |
29 | impl<T: super::AudioAggregatorPadImplExt> Sealed for T {} |
30 | } |
31 | |
32 | pub trait AudioAggregatorPadImplExt: sealed::Sealed + ObjectSubclass { |
33 | fn parent_update_conversion_info(&self) { |
34 | unsafe { |
35 | let data = Self::type_data(); |
36 | let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorPadClass; |
37 | if let Some(f) = (*parent_class).update_conversion_info { |
38 | f(self |
39 | .obj() |
40 | .unsafe_cast_ref::<AudioAggregatorPad>() |
41 | .to_glib_none() |
42 | .0); |
43 | } |
44 | } |
45 | } |
46 | |
47 | fn parent_convert_buffer( |
48 | &self, |
49 | in_info: &crate::AudioInfo, |
50 | out_info: &crate::AudioInfo, |
51 | buffer: &gst::Buffer, |
52 | ) -> Option<gst::Buffer> { |
53 | unsafe { |
54 | let data = Self::type_data(); |
55 | let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioAggregatorPadClass; |
56 | let f = (*parent_class) |
57 | .convert_buffer |
58 | .expect("Missing parent function `convert_buffer`" ); |
59 | from_glib_full(f( |
60 | self.obj() |
61 | .unsafe_cast_ref::<AudioAggregatorPad>() |
62 | .to_glib_none() |
63 | .0, |
64 | mut_override(in_info.to_glib_none().0), |
65 | mut_override(out_info.to_glib_none().0), |
66 | buffer.as_mut_ptr(), |
67 | )) |
68 | } |
69 | } |
70 | } |
71 | |
72 | impl<T: AudioAggregatorPadImpl> AudioAggregatorPadImplExt for T {} |
73 | |
74 | unsafe impl<T: AudioAggregatorPadImpl> IsSubclassable<T> for AudioAggregatorPad { |
75 | fn class_init(klass: &mut glib::Class<Self>) { |
76 | Self::parent_class_init::<T>(class:klass); |
77 | |
78 | let klass: &mut GstAudioAggregatorPadClass = klass.as_mut(); |
79 | if T::HANDLE_CONVERSION { |
80 | klass.update_conversion_info = Some(audio_aggregator_pad_update_conversion_info::<T>); |
81 | klass.convert_buffer = Some(audio_aggregator_pad_convert_buffer::<T>); |
82 | } |
83 | } |
84 | } |
85 | |
86 | unsafe extern "C" fn audio_aggregator_pad_update_conversion_info<T: AudioAggregatorPadImpl>( |
87 | ptr: *mut ffi::GstAudioAggregatorPad, |
88 | ) { |
89 | let instance: &::Instance = &*(ptr as *mut T::Instance); |
90 | let imp: &T = instance.imp(); |
91 | |
92 | imp.update_conversion_info(); |
93 | } |
94 | |
95 | unsafe extern "C" fn audio_aggregator_pad_convert_buffer<T: AudioAggregatorPadImpl>( |
96 | ptr: *mut ffi::GstAudioAggregatorPad, |
97 | in_info: *mut ffi::GstAudioInfo, |
98 | out_info: *mut ffi::GstAudioInfo, |
99 | buffer: *mut gst::ffi::GstBuffer, |
100 | ) -> *mut gst::ffi::GstBuffer { |
101 | let instance: &::Instance = &*(ptr as *mut T::Instance); |
102 | let imp: &T = instance.imp(); |
103 | |
104 | imp.convert_buffer( |
105 | &from_glib_none(in_info), |
106 | &from_glib_none(out_info), |
107 | &from_glib_borrow(buffer), |
108 | ) |
109 | .map(|buffer| buffer.into_glib_ptr()) |
110 | .unwrap_or(default:ptr::null_mut()) |
111 | } |
112 | |