Skip to main content

gstreamer_video/auto/
video_encoder.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{VideoCodecFrame, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// = FPS).
16    /// The most specific match wins (highest pixel count, then highest fps
17    /// threshold). If no alternative matches, the base property value set by
18    /// `gst_preset_load_preset()` remains.
19    ///
20    /// The [`qos`][struct@crate::VideoEncoder#qos] property will enable the Quality-of-Service
21    /// features of the encoder which gather statistics about the real-time
22    /// performance of the downstream elements. If enabled, subclasses can
23    /// use [`VideoEncoderExt::max_encode_time()`][crate::prelude::VideoEncoderExt::max_encode_time()] to check if input frames
24    /// are already late and drop them right away to give a chance to the
25    /// pipeline to catch up.
26    ///
27    /// This is an Abstract Base Class, you cannot instantiate it.
28    ///
29    /// ## Properties
30    ///
31    ///
32    /// #### `min-force-key-unit-interval`
33    ///  Minimum interval between force-keyunit requests in nanoseconds. See
34    /// [`VideoEncoderExt::set_min_force_key_unit_interval()`][crate::prelude::VideoEncoderExt::set_min_force_key_unit_interval()] for more details.
35    ///
36    /// Readable | Writable
37    ///
38    ///
39    /// #### `qos`
40    ///  Readable | Writable
41    /// <details><summary><h4>Object</h4></summary>
42    ///
43    ///
44    /// #### `name`
45    ///  Readable | Writable | Construct
46    ///
47    ///
48    /// #### `parent`
49    ///  The parent of the object. Please note, that when changing the 'parent'
50    /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::gst::Object#deep-notify]
51    /// signals due to locking issues. In some cases one can use
52    /// `GstBin::element-added` or `GstBin::element-removed` signals on the parent to
53    /// achieve a similar effect.
54    ///
55    /// Readable | Writable
56    /// </details>
57    ///
58    /// # Implements
59    ///
60    /// [`VideoEncoderExt`][trait@crate::prelude::VideoEncoderExt], [`trait@gst::prelude::ElementExt`], [`trait@gst::prelude::ObjectExt`], [`trait@glib::ObjectExt`], [`VideoEncoderExtManual`][trait@crate::prelude::VideoEncoderExtManual]
61    #[doc(alias = "GstVideoEncoder")]
62    pub struct VideoEncoder(Object<ffi::GstVideoEncoder, ffi::GstVideoEncoderClass>) @extends gst::Element, gst::Object;
63
64    match fn {
65        type_ => || ffi::gst_video_encoder_get_type(),
66    }
67}
68
69impl VideoEncoder {
70    pub const NONE: Option<&'static VideoEncoder> = None;
71}
72
73unsafe impl Send for VideoEncoder {}
74unsafe impl Sync for VideoEncoder {}
75
76/// Trait containing all [`struct@VideoEncoder`] methods.
77///
78/// # Implementors
79///
80/// [`VideoEncoder`][struct@crate::VideoEncoder]
81pub trait VideoEncoderExt: IsA<VideoEncoder> + 'static {
82    /// Helper function that allocates a buffer to hold an encoded video frame
83    /// for `self`'s current [`VideoCodecState`][crate::VideoCodecState].
84    /// ## `size`
85    /// size of the buffer
86    ///
87    /// # Returns
88    ///
89    /// allocated buffer
90    #[doc(alias = "gst_video_encoder_allocate_output_buffer")]
91    fn allocate_output_buffer(&self, size: usize) -> gst::Buffer {
92        unsafe {
93            from_glib_full(ffi::gst_video_encoder_allocate_output_buffer(
94                self.as_ref().to_glib_none().0,
95                size,
96            ))
97        }
98    }
99
100    /// Removes `frame` from the list of pending frames, releases it
101    /// and posts a QoS message with the frame's details on the bus.
102    /// Similar to calling [`finish_frame()`][Self::finish_frame()] without a buffer
103    /// attached to `frame`, but this function additionally stores events
104    /// from `frame` as pending, to be pushed out alongside the next frame
105    /// submitted via [`finish_frame()`][Self::finish_frame()].
106    /// ## `frame`
107    /// a [`VideoCodecFrame`][crate::VideoCodecFrame]
108    #[cfg(feature = "v1_26")]
109    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
110    #[doc(alias = "gst_video_encoder_drop_frame")]
111    fn drop_frame(&self, frame: VideoCodecFrame) {
112        unsafe {
113            ffi::gst_video_encoder_drop_frame(
114                self.as_ref().to_glib_none().0,
115                frame.into_glib_ptr(),
116            );
117        }
118    }
119
120    /// `frame` must have a valid encoded data buffer, whose metadata fields
121    /// are then appropriately set according to frame data or no buffer at
122    /// all if the frame should be dropped.
123    /// It is subsequently pushed downstream or provided to `pre_push`.
124    /// In any case, the frame is considered finished and released.
125    ///
126    /// If `frame` does not have a buffer attached, it will be dropped, and
127    /// a QoS message will be posted on the bus. Events from `frame` will be
128    /// pushed out immediately.
129    ///
130    /// After calling this function the output buffer of the frame is to be
131    /// considered read-only. This function will also change the metadata
132    /// of the buffer.
133    /// ## `frame`
134    /// an encoded [`VideoCodecFrame`][crate::VideoCodecFrame]
135    ///
136    /// # Returns
137    ///
138    /// a [`gst::FlowReturn`][crate::gst::FlowReturn] resulting from sending data downstream
139    #[doc(alias = "gst_video_encoder_finish_frame")]
140    fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
141        unsafe {
142            try_from_glib(ffi::gst_video_encoder_finish_frame(
143                self.as_ref().to_glib_none().0,
144                frame.into_glib_ptr(),
145            ))
146        }
147    }
148
149    /// Determines maximum possible encoding time for `frame` that will
150    /// allow it to encode and arrive in time (as determined by QoS events).
151    /// In particular, a negative result means encoding in time is no longer possible
152    /// and should therefore occur as soon/skippy as possible.
153    ///
154    /// If no QoS events have been received from downstream, or if
155    /// [`qos`][struct@crate::VideoEncoder#qos] is disabled this function returns `G_MAXINT64`.
156    /// ## `frame`
157    /// a [`VideoCodecFrame`][crate::VideoCodecFrame]
158    ///
159    /// # Returns
160    ///
161    /// max decoding time.
162    #[doc(alias = "gst_video_encoder_get_max_encode_time")]
163    #[doc(alias = "get_max_encode_time")]
164    fn max_encode_time(&self, frame: &VideoCodecFrame) -> gst::ClockTimeDiff {
165        unsafe {
166            ffi::gst_video_encoder_get_max_encode_time(
167                self.as_ref().to_glib_none().0,
168                frame.to_glib_none().0,
169            )
170        }
171    }
172
173    /// Returns the minimum force-keyunit interval, see [`set_min_force_key_unit_interval()`][Self::set_min_force_key_unit_interval()]
174    /// for more details.
175    ///
176    /// # Returns
177    ///
178    /// the minimum force-keyunit interval
179    #[cfg(feature = "v1_18")]
180    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
181    #[doc(alias = "gst_video_encoder_get_min_force_key_unit_interval")]
182    #[doc(alias = "get_min_force_key_unit_interval")]
183    #[doc(alias = "min-force-key-unit-interval")]
184    fn min_force_key_unit_interval(&self) -> Option<gst::ClockTime> {
185        unsafe {
186            from_glib(ffi::gst_video_encoder_get_min_force_key_unit_interval(
187                self.as_ref().to_glib_none().0,
188            ))
189        }
190    }
191
192    /// Checks if `self` is currently configured to handle Quality-of-Service
193    /// events from downstream.
194    ///
195    /// # Returns
196    ///
197    /// [`true`] if the encoder is configured to perform Quality-of-Service.
198    #[doc(alias = "gst_video_encoder_is_qos_enabled")]
199    fn is_qos_enabled(&self) -> bool {
200        unsafe {
201            from_glib(ffi::gst_video_encoder_is_qos_enabled(
202                self.as_ref().to_glib_none().0,
203            ))
204        }
205    }
206
207    /// Sets the video encoder tags and how they should be merged with any
208    /// upstream stream tags. This will override any tags previously-set
209    /// with [`merge_tags()`][Self::merge_tags()].
210    ///
211    /// Note that this is provided for convenience, and the subclass is
212    /// not required to use this and can still do tag handling on its own.
213    ///
214    /// MT safe.
215    /// ## `tags`
216    /// a [`gst::TagList`][crate::gst::TagList] to merge, or NULL to unset
217    ///  previously-set tags
218    /// ## `mode`
219    /// the [`gst::TagMergeMode`][crate::gst::TagMergeMode] to use, usually [`gst::TagMergeMode::Replace`][crate::gst::TagMergeMode::Replace]
220    #[doc(alias = "gst_video_encoder_merge_tags")]
221    fn merge_tags(&self, tags: Option<&gst::TagList>, mode: gst::TagMergeMode) {
222        unsafe {
223            ffi::gst_video_encoder_merge_tags(
224                self.as_ref().to_glib_none().0,
225                tags.to_glib_none().0,
226                mode.into_glib(),
227            );
228        }
229    }
230
231    /// Returns caps that express `caps` (or sink template caps if `caps` == NULL)
232    /// restricted to resolution/format/... combinations supported by downstream
233    /// elements (e.g. muxers).
234    /// ## `caps`
235    /// initial caps
236    /// ## `filter`
237    /// filter caps
238    ///
239    /// # Returns
240    ///
241    /// a [`gst::Caps`][crate::gst::Caps] owned by caller
242    #[doc(alias = "gst_video_encoder_proxy_getcaps")]
243    fn proxy_getcaps(&self, caps: Option<&gst::Caps>, filter: Option<&gst::Caps>) -> gst::Caps {
244        unsafe {
245            from_glib_full(ffi::gst_video_encoder_proxy_getcaps(
246                self.as_ref().to_glib_none().0,
247                caps.to_glib_none().0,
248                filter.to_glib_none().0,
249            ))
250        }
251    }
252
253    /// Removes `frame` from list of pending frames and releases it, similar
254    /// to calling [`finish_frame()`][Self::finish_frame()] without a buffer attached
255    /// to the frame, but does not post a QoS message or do any additional
256    /// processing. Events from `frame` are moved to the pending events list.
257    /// ## `frame`
258    /// a [`VideoCodecFrame`][crate::VideoCodecFrame]
259    #[cfg(feature = "v1_26")]
260    #[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
261    #[doc(alias = "gst_video_encoder_release_frame")]
262    fn release_frame(&self, frame: VideoCodecFrame) {
263        unsafe {
264            ffi::gst_video_encoder_release_frame(
265                self.as_ref().to_glib_none().0,
266                frame.into_glib_ptr(),
267            );
268        }
269    }
270
271    /// Allows [`VideoEncoder`][crate::VideoEncoder] sub-classes to set the memory `allocator` and
272    /// its `params`.
273    /// ## `allocator`
274    /// the [`gst::Allocator`][crate::gst::Allocator]
275    /// ## `params`
276    /// the [`gst::AllocationParams`][crate::gst::AllocationParams] of `allocator`
277    #[cfg(feature = "v1_30")]
278    #[cfg_attr(docsrs, doc(cfg(feature = "v1_30")))]
279    #[doc(alias = "gst_video_encoder_set_allocator")]
280    fn set_allocator(
281        &self,
282        allocator: Option<impl IsA<gst::Allocator>>,
283        params: Option<&gst::AllocationParams>,
284    ) {
285        unsafe {
286            ffi::gst_video_encoder_set_allocator(
287                self.as_ref().to_glib_none().0,
288                allocator.map(|p| p.upcast()).into_glib_ptr(),
289                params.to_glib_none().0,
290            );
291        }
292    }
293
294    /// Sets the minimum interval for requesting keyframes based on force-keyunit
295    /// events. Setting this to 0 will allow to handle every event, setting this to
296    /// `GST_CLOCK_TIME_NONE` causes force-keyunit events to be ignored.
297    /// ## `interval`
298    /// minimum interval
299    #[cfg(feature = "v1_18")]
300    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
301    #[doc(alias = "gst_video_encoder_set_min_force_key_unit_interval")]
302    #[doc(alias = "min-force-key-unit-interval")]
303    fn set_min_force_key_unit_interval(&self, interval: impl Into<Option<gst::ClockTime>>) {
304        unsafe {
305            ffi::gst_video_encoder_set_min_force_key_unit_interval(
306                self.as_ref().to_glib_none().0,
307                interval.into().into_glib(),
308            );
309        }
310    }
311
312    /// Request minimal value for PTS passed to handle_frame.
313    ///
314    /// For streams with reordered frames this can be used to ensure that there
315    /// is enough time to accommodate first DTS, which may be less than first PTS
316    /// ## `min_pts`
317    /// minimal PTS that will be passed to handle_frame
318    #[doc(alias = "gst_video_encoder_set_min_pts")]
319    fn set_min_pts(&self, min_pts: impl Into<Option<gst::ClockTime>>) {
320        unsafe {
321            ffi::gst_video_encoder_set_min_pts(
322                self.as_ref().to_glib_none().0,
323                min_pts.into().into_glib(),
324            );
325        }
326    }
327
328    /// Configures `self` to handle Quality-of-Service events from downstream.
329    /// ## `enabled`
330    /// the new qos value.
331    #[doc(alias = "gst_video_encoder_set_qos_enabled")]
332    fn set_qos_enabled(&self, enabled: bool) {
333        unsafe {
334            ffi::gst_video_encoder_set_qos_enabled(
335                self.as_ref().to_glib_none().0,
336                enabled.into_glib(),
337            );
338        }
339    }
340
341    fn is_qos(&self) -> bool {
342        ObjectExt::property(self.as_ref(), "qos")
343    }
344
345    fn set_qos(&self, qos: bool) {
346        ObjectExt::set_property(self.as_ref(), "qos", qos)
347    }
348
349    #[cfg(feature = "v1_18")]
350    #[cfg_attr(docsrs, doc(cfg(feature = "v1_18")))]
351    #[doc(alias = "min-force-key-unit-interval")]
352    fn connect_min_force_key_unit_interval_notify<F: Fn(&Self) + Send + Sync + 'static>(
353        &self,
354        f: F,
355    ) -> SignalHandlerId {
356        unsafe extern "C" fn notify_min_force_key_unit_interval_trampoline<
357            P: IsA<VideoEncoder>,
358            F: Fn(&P) + Send + Sync + 'static,
359        >(
360            this: *mut ffi::GstVideoEncoder,
361            _param_spec: glib::ffi::gpointer,
362            f: glib::ffi::gpointer,
363        ) {
364            unsafe {
365                let f: &F = &*(f as *const F);
366                f(VideoEncoder::from_glib_borrow(this).unsafe_cast_ref())
367            }
368        }
369        unsafe {
370            let f: Box_<F> = Box_::new(f);
371            connect_raw(
372                self.as_ptr() as *mut _,
373                c"notify::min-force-key-unit-interval".as_ptr(),
374                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
375                    notify_min_force_key_unit_interval_trampoline::<Self, F> as *const (),
376                )),
377                Box_::into_raw(f),
378            )
379        }
380    }
381
382    #[doc(alias = "qos")]
383    fn connect_qos_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
384        unsafe extern "C" fn notify_qos_trampoline<
385            P: IsA<VideoEncoder>,
386            F: Fn(&P) + Send + Sync + 'static,
387        >(
388            this: *mut ffi::GstVideoEncoder,
389            _param_spec: glib::ffi::gpointer,
390            f: glib::ffi::gpointer,
391        ) {
392            unsafe {
393                let f: &F = &*(f as *const F);
394                f(VideoEncoder::from_glib_borrow(this).unsafe_cast_ref())
395            }
396        }
397        unsafe {
398            let f: Box_<F> = Box_::new(f);
399            connect_raw(
400                self.as_ptr() as *mut _,
401                c"notify::qos".as_ptr(),
402                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
403                    notify_qos_trampoline::<Self, F> as *const (),
404                )),
405                Box_::into_raw(f),
406            )
407        }
408    }
409}
410
411impl<O: IsA<VideoEncoder>> VideoEncoderExt for O {}