1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use glib::{object::IsA, translate::*};
use gst::prelude::*;

use crate::{ffi, subclass::AggregateFramesToken, VideoAggregatorPad};

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::VideoAggregatorPad>> Sealed for T {}
}

pub trait VideoAggregatorPadExtManual: sealed::Sealed + IsA<VideoAggregatorPad> + 'static {
    /// Checks if the pad currently has a buffer queued that is going to be used
    /// for the current output frame.
    ///
    /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
    /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
    ///
    /// # Returns
    ///
    /// [`true`] if the pad has currently a buffer queued
    #[doc(alias = "gst_video_aggregator_pad_has_current_buffer")]
    fn has_current_buffer(&self, _token: &AggregateFramesToken) -> bool {
        unsafe {
            from_glib(ffi::gst_video_aggregator_pad_has_current_buffer(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the currently queued buffer that is going to be used
    /// for the current output frame.
    ///
    /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
    /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
    ///
    /// The return value is only valid until `GstVideoAggregatorClass::aggregate_frames` or `GstVideoAggregatorPadClass::prepare_frame`
    /// returns.
    ///
    /// # Returns
    ///
    /// The currently queued buffer
    #[doc(alias = "gst_video_aggregator_pad_get_current_buffer")]
    fn current_buffer(&self, _token: &AggregateFramesToken) -> Option<gst::Buffer> {
        unsafe {
            from_glib_none(ffi::gst_video_aggregator_pad_get_current_buffer(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns the currently prepared video frame that has to be aggregated into
    /// the current output frame.
    ///
    /// This must only be called from the `GstVideoAggregatorClass::aggregate_frames` virtual method,
    /// or from the `GstVideoAggregatorPadClass::prepare_frame` virtual method of the aggregator pads.
    ///
    /// The return value is only valid until `GstVideoAggregatorClass::aggregate_frames` or `GstVideoAggregatorPadClass::prepare_frame`
    /// returns.
    ///
    /// # Returns
    ///
    /// The currently prepared video frame
    #[doc(alias = "gst_video_aggregator_pad_get_prepared_frame")]
    fn prepared_frame<'a>(
        &self,
        _token: &'a AggregateFramesToken,
    ) -> Option<crate::VideoFrameRef<&'a gst::BufferRef>> {
        unsafe {
            let ptr =
                ffi::gst_video_aggregator_pad_get_prepared_frame(self.as_ref().to_glib_none().0);

            if ptr.is_null() {
                None
            } else {
                Some(crate::VideoFrameRef::from_glib_borrow(ptr).into_inner())
            }
        }
    }

    fn video_info(&self) -> Option<crate::VideoInfo> {
        unsafe {
            let ptr = self.as_ptr() as *mut ffi::GstVideoAggregatorPad;
            let _guard = self.as_ref().object_lock();

            let info = &(*ptr).info;

            if info.finfo.is_null() || info.width <= 0 || info.height <= 0 {
                return None;
            }

            Some(from_glib_none(mut_override(
                info as *const ffi::GstVideoInfo,
            )))
        }
    }
}

impl<O: IsA<VideoAggregatorPad>> VideoAggregatorPadExtManual for O {}