1use crate::{VideoCodecFrame, ffi};
7use glib::{
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GstVideoEncoder")]
16 pub struct VideoEncoder(Object<ffi::GstVideoEncoder, ffi::GstVideoEncoderClass>) @extends gst::Element, gst::Object;
17
18 match fn {
19 type_ => || ffi::gst_video_encoder_get_type(),
20 }
21}
22
23impl VideoEncoder {
24 pub const NONE: Option<&'static VideoEncoder> = None;
25}
26
27unsafe impl Send for VideoEncoder {}
28unsafe impl Sync for VideoEncoder {}
29
30pub trait VideoEncoderExt: IsA<VideoEncoder> + 'static {
31 #[doc(alias = "gst_video_encoder_allocate_output_buffer")]
32 fn allocate_output_buffer(&self, size: usize) -> gst::Buffer {
33 unsafe {
34 from_glib_full(ffi::gst_video_encoder_allocate_output_buffer(
35 self.as_ref().to_glib_none().0,
36 size,
37 ))
38 }
39 }
40
41 #[cfg(feature = "v1_26")]
42 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
43 #[doc(alias = "gst_video_encoder_drop_frame")]
44 fn drop_frame(&self, frame: VideoCodecFrame) {
45 unsafe {
46 ffi::gst_video_encoder_drop_frame(
47 self.as_ref().to_glib_none().0,
48 frame.into_glib_ptr(),
49 );
50 }
51 }
52
53 #[doc(alias = "gst_video_encoder_finish_frame")]
54 fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
55 unsafe {
56 try_from_glib(ffi::gst_video_encoder_finish_frame(
57 self.as_ref().to_glib_none().0,
58 frame.into_glib_ptr(),
59 ))
60 }
61 }
62
63 #[doc(alias = "gst_video_encoder_get_max_encode_time")]
64 #[doc(alias = "get_max_encode_time")]
65 fn max_encode_time(&self, frame: &VideoCodecFrame) -> gst::ClockTimeDiff {
66 unsafe {
67 ffi::gst_video_encoder_get_max_encode_time(
68 self.as_ref().to_glib_none().0,
69 frame.to_glib_none().0,
70 )
71 }
72 }
73
74 #[cfg(feature = "v1_18")]
75 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
76 #[doc(alias = "gst_video_encoder_get_min_force_key_unit_interval")]
77 #[doc(alias = "get_min_force_key_unit_interval")]
78 #[doc(alias = "min-force-key-unit-interval")]
79 fn min_force_key_unit_interval(&self) -> Option<gst::ClockTime> {
80 unsafe {
81 from_glib(ffi::gst_video_encoder_get_min_force_key_unit_interval(
82 self.as_ref().to_glib_none().0,
83 ))
84 }
85 }
86
87 #[doc(alias = "gst_video_encoder_is_qos_enabled")]
88 fn is_qos_enabled(&self) -> bool {
89 unsafe {
90 from_glib(ffi::gst_video_encoder_is_qos_enabled(
91 self.as_ref().to_glib_none().0,
92 ))
93 }
94 }
95
96 #[doc(alias = "gst_video_encoder_merge_tags")]
97 fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
98 unsafe {
99 ffi::gst_video_encoder_merge_tags(
100 self.as_ref().to_glib_none().0,
101 tags.to_glib_none().0,
102 mode.into_glib(),
103 );
104 }
105 }
106
107 #[doc(alias = "gst_video_encoder_proxy_getcaps")]
108 fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps {
109 unsafe {
110 from_glib_full(ffi::gst_video_encoder_proxy_getcaps(
111 self.as_ref().to_glib_none().0,
112 caps.to_glib_none().0,
113 filter.to_glib_none().0,
114 ))
115 }
116 }
117
118 #[cfg(feature = "v1_26")]
119 #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
120 #[doc(alias = "gst_video_encoder_release_frame")]
121 fn release_frame(&self, frame: VideoCodecFrame) {
122 unsafe {
123 ffi::gst_video_encoder_release_frame(
124 self.as_ref().to_glib_none().0,
125 frame.into_glib_ptr(),
126 );
127 }
128 }
129
130 #[cfg(feature = "v1_30")]
131 #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
132 #[doc(alias = "gst_video_encoder_set_allocator")]
133 fn set_allocator(
134 &self,
135 allocator: Option<impl IsA<gst::Allocator>>,
136 params: Option<&gst::AllocationParams>,
137 ) {
138 unsafe {
139 ffi::gst_video_encoder_set_allocator(
140 self.as_ref().to_glib_none().0,
141 allocator.map(|p| p.upcast()).into_glib_ptr(),
142 params.to_glib_none().0,
143 );
144 }
145 }
146
147 #[cfg(feature = "v1_18")]
148 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
149 #[doc(alias = "gst_video_encoder_set_min_force_key_unit_interval")]
150 #[doc(alias = "min-force-key-unit-interval")]
151 fn set_min_force_key_unit_interval(&self, interval: impl Into<Option<gst::ClockTime>>) {
152 unsafe {
153 ffi::gst_video_encoder_set_min_force_key_unit_interval(
154 self.as_ref().to_glib_none().0,
155 interval.into().into_glib(),
156 );
157 }
158 }
159
160 #[doc(alias = "gst_video_encoder_set_min_pts")]
161 fn set_min_pts(&self, min_pts: impl Into<Option<gst::ClockTime>>) {
162 unsafe {
163 ffi::gst_video_encoder_set_min_pts(
164 self.as_ref().to_glib_none().0,
165 min_pts.into().into_glib(),
166 );
167 }
168 }
169
170 #[doc(alias = "gst_video_encoder_set_qos_enabled")]
171 fn set_qos_enabled(&self, enabled: bool) {
172 unsafe {
173 ffi::gst_video_encoder_set_qos_enabled(
174 self.as_ref().to_glib_none().0,
175 enabled.into_glib(),
176 );
177 }
178 }
179
180 fn is_qos(&self) -> bool {
181 ObjectExt::property(self.as_ref(), "qos")
182 }
183
184 fn set_qos(&self, qos: bool) {
185 ObjectExt::set_property(self.as_ref(), "qos", qos)
186 }
187
188 #[cfg(feature = "v1_18")]
189 #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
190 #[doc(alias = "min-force-key-unit-interval")]
191 fn connect_min_force_key_unit_interval_notify<F: Fn(&Self) + Send + Sync + 'static>(
192 &self,
193 f: F,
194 ) -> SignalHandlerId {
195 unsafe extern "C" fn notify_min_force_key_unit_interval_trampoline<
196 P: IsA<VideoEncoder>,
197 F: Fn(&P) + Send + Sync + 'static,
198 >(
199 this: *mut ffi::GstVideoEncoder,
200 _param_spec: glib::ffi::gpointer,
201 f: glib::ffi::gpointer,
202 ) {
203 unsafe {
204 let f: &F = &*(f as *const F);
205 f(VideoEncoder::from_glib_borrow(this).unsafe_cast_ref())
206 }
207 }
208 unsafe {
209 let f: Box_<F> = Box_::new(f);
210 connect_raw(
211 self.as_ptr() as *mut _,
212 c"notify::min-force-key-unit-interval".as_ptr(),
213 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
214 notify_min_force_key_unit_interval_trampoline::<Self, F> as *const (),
215 )),
216 Box_::into_raw(f),
217 )
218 }
219 }
220
221 #[doc(alias = "qos")]
222 fn connect_qos_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
223 unsafe extern "C" fn notify_qos_trampoline<
224 P: IsA<VideoEncoder>,
225 F: Fn(&P) + Send + Sync + 'static,
226 >(
227 this: *mut ffi::GstVideoEncoder,
228 _param_spec: glib::ffi::gpointer,
229 f: glib::ffi::gpointer,
230 ) {
231 unsafe {
232 let f: &F = &*(f as *const F);
233 f(VideoEncoder::from_glib_borrow(this).unsafe_cast_ref())
234 }
235 }
236 unsafe {
237 let f: Box_<F> = Box_::new(f);
238 connect_raw(
239 self.as_ptr() as *mut _,
240 c"notify::qos".as_ptr(),
241 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242 notify_qos_trampoline::<Self, F> as *const (),
243 )),
244 Box_::into_raw(f),
245 )
246 }
247 }
248}
249
250impl<O: IsA<VideoEncoder>> VideoEncoderExt for O {}