gstreamer_video/video_aggregator_pad.rs
1use glib::{object::IsA, translate::*};
2use gst::prelude::*;
3
4use crate::{ffi, subclass::AggregateFramesToken, VideoAggregatorPad};
5
6pub trait VideoAggregatorPadExtManual: IsA<VideoAggregatorPad> + 'static {
7 /// Checks if the pad currently has a buffer queued that is going to be used
8 /// for the current output frame.
9 ///
10 /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
11 /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
12 ///
13 /// # Returns
14 ///
15 /// [`true`] if the pad has currently a buffer queued
16 #[doc(alias = "gst_video_aggregator_pad_has_current_buffer")]
17 fn has_current_buffer(&self, _token: &AggregateFramesToken) -> bool {
18 unsafe {
19 from_glib(ffi::gst_video_aggregator_pad_has_current_buffer(
20 self.as_ref().to_glib_none().0,
21 ))
22 }
23 }
24
25 /// Returns the currently queued buffer that is going to be used
26 /// for the current output frame.
27 ///
28 /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
29 /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
30 ///
31 /// The return value is only valid until `GstVideoAggregatorClass::aggregate_frames` or `GstVideoAggregatorPadClass::prepare_frame`
32 /// returns.
33 ///
34 /// # Returns
35 ///
36 /// The currently queued buffer
37 #[doc(alias = "gst_video_aggregator_pad_get_current_buffer")]
38 fn current_buffer(&self, _token: &AggregateFramesToken) -> Option<gst::Buffer> {
39 unsafe {
40 from_glib_none(ffi::gst_video_aggregator_pad_get_current_buffer(
41 self.as_ref().to_glib_none().0,
42 ))
43 }
44 }
45
46 /// Returns the currently prepared video frame that has to be aggregated into
47 /// the current output frame.
48 ///
49 /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
50 /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
51 ///
52 /// The return value is only valid until `GstVideoAggregatorClass::aggregate_frames` or `GstVideoAggregatorPadClass::prepare_frame`
53 /// returns.
54 ///
55 /// # Returns
56 ///
57 /// The currently prepared video frame
58 #[doc(alias = "gst_video_aggregator_pad_get_prepared_frame")]
59 fn prepared_frame<'a>(
60 &self,
61 _token: &'a AggregateFramesToken,
62 ) -> Option<crate::VideoFrameRef<&'a gst::BufferRef>> {
63 unsafe {
64 let ptr =
65 ffi::gst_video_aggregator_pad_get_prepared_frame(self.as_ref().to_glib_none().0);
66
67 if ptr.is_null() {
68 None
69 } else {
70 Some(crate::VideoFrameRef::from_glib_borrow(ptr).into_inner())
71 }
72 }
73 }
74
75 fn video_info(&self) -> Option<crate::VideoInfo> {
76 unsafe {
77 let ptr = self.as_ptr() as *mut ffi::GstVideoAggregatorPad;
78 let _guard = self.as_ref().object_lock();
79
80 let info = &(*ptr).info;
81
82 if info.finfo.is_null() || info.width <= 0 || info.height <= 0 {
83 return None;
84 }
85
86 Some(from_glib_none(mut_override(
87 info as *const ffi::GstVideoInfo,
88 )))
89 }
90 }
91}
92
93impl<O: IsA<VideoAggregatorPad>> VideoAggregatorPadExtManual for O {}