Files
gstreamer
gstreamer_app
gstreamer_audio
gstreamer_base
gstreamer_check
gstreamer_controller
gstreamer_editing_services
gstreamer_gl
gstreamer_gl_egl
gstreamer_gl_wayland
gstreamer_gl_x11
gstreamer_net
gstreamer_pbutils
gstreamer_player
gstreamer_rtp
gstreamer_rtsp
gstreamer_rtsp_server
gstreamer_sdp
gstreamer_video
gstreamer_webrtc
  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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::BaseParse;
use crate::BaseParseFrame;
use glib::prelude::*;
use glib::translate::*;
use gst::FormattedValue;
use std::convert::TryFrom;
use std::mem;

pub trait BaseParseExtManual: 'static {
    #[doc(alias = "get_sink_pad")]
    fn sink_pad(&self) -> gst::Pad;
    #[doc(alias = "get_src_pad")]
    fn src_pad(&self) -> gst::Pad;

    fn set_duration<V: Into<gst::GenericFormattedValue>>(&self, duration: V, interval: u32);
    fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32);

    fn convert_default<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>(
        &self,
        src_val: V,
    ) -> Option<U>;
    fn convert_default_generic<V: Into<gst::GenericFormattedValue>>(
        &self,
        src_val: V,
        dest_format: gst::Format,
    ) -> Option<gst::GenericFormattedValue>;

    fn finish_frame(
        &self,
        frame: BaseParseFrame,
        size: u32,
    ) -> Result<gst::FlowSuccess, gst::FlowError>;
}

impl<O: IsA<BaseParse>> BaseParseExtManual for O {
    fn sink_pad(&self) -> gst::Pad {
        unsafe {
            let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
            from_glib_none(elt.sinkpad)
        }
    }

    fn src_pad(&self) -> gst::Pad {
        unsafe {
            let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
            from_glib_none(elt.srcpad)
        }
    }

    fn set_duration<V: Into<gst::GenericFormattedValue>>(&self, duration: V, interval: u32) {
        let duration = duration.into();
        unsafe {
            ffi::gst_base_parse_set_duration(
                self.as_ref().to_glib_none().0,
                duration.format().into_glib(),
                duration.value(),
                interval as i32,
            );
        }
    }

    fn set_frame_rate(&self, fps: gst::Fraction, lead_in: u32, lead_out: u32) {
        let (fps_num, fps_den) = fps.into();
        unsafe {
            ffi::gst_base_parse_set_frame_rate(
                self.as_ref().to_glib_none().0,
                fps_num as u32,
                fps_den as u32,
                lead_in,
                lead_out,
            );
        }
    }

    fn convert_default<V: Into<gst::GenericFormattedValue>, U: gst::SpecificFormattedValue>(
        &self,
        src_val: V,
    ) -> Option<U> {
        let src_val = src_val.into();
        unsafe {
            let mut dest_val = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gst_base_parse_convert_default(
                self.as_ref().to_glib_none().0,
                src_val.format().into_glib(),
                src_val.to_raw_value(),
                U::default_format().into_glib(),
                dest_val.as_mut_ptr(),
            ));
            if ret {
                Some(U::from_raw(U::default_format(), dest_val.assume_init()))
            } else {
                None
            }
        }
    }

    fn convert_default_generic<V: Into<gst::GenericFormattedValue>>(
        &self,
        src_val: V,
        dest_format: gst::Format,
    ) -> Option<gst::GenericFormattedValue> {
        let src_val = src_val.into();
        unsafe {
            let mut dest_val = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gst_base_parse_convert_default(
                self.as_ref().to_glib_none().0,
                src_val.format().into_glib(),
                src_val.to_raw_value(),
                dest_format.into_glib(),
                dest_val.as_mut_ptr(),
            ));
            if ret {
                Some(gst::GenericFormattedValue::new(
                    dest_format,
                    dest_val.assume_init(),
                ))
            } else {
                None
            }
        }
    }

    fn finish_frame(
        &self,
        frame: BaseParseFrame,
        size: u32,
    ) -> Result<gst::FlowSuccess, gst::FlowError> {
        unsafe {
            gst::FlowSuccess::try_from_glib(ffi::gst_base_parse_finish_frame(
                self.as_ref().to_glib_none().0,
                frame.to_glib_none().0,
                i32::try_from(size).expect("size higher than i32::MAX"),
            ))
        }
    }
}