gstreamer_video/
video_aggregator_pad.rs

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