2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2019-05-25 19:29:04 +00:00
|
|
|
|
2020-11-21 17:59:22 +00:00
|
|
|
use crate::BaseParse;
|
|
|
|
use crate::BaseParseFrame;
|
2021-04-26 12:15:53 +00:00
|
|
|
use glib::prelude::*;
|
2019-05-25 19:29:04 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
use gst::FormattedValue;
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
pub trait BaseParseExtManual: 'static {
|
2021-04-11 19:39:50 +00:00
|
|
|
fn sink_pad(&self) -> gst::Pad;
|
|
|
|
fn src_pad(&self) -> gst::Pad;
|
2019-05-25 19:29:04 +00:00
|
|
|
|
|
|
|
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 {
|
2021-04-11 19:39:50 +00:00
|
|
|
fn sink_pad(&self) -> gst::Pad {
|
2019-05-25 19:29:04 +00:00
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
|
2019-05-25 19:29:04 +00:00
|
|
|
from_glib_none(elt.sinkpad)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 19:39:50 +00:00
|
|
|
fn src_pad(&self) -> gst::Pad {
|
2019-05-25 19:29:04 +00:00
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
let elt: &ffi::GstBaseParse = &*(self.as_ptr() as *const _);
|
2019-05-25 19:29:04 +00:00
|
|
|
from_glib_none(elt.srcpad)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_duration<V: Into<gst::GenericFormattedValue>>(&self, duration: V, interval: u32) {
|
|
|
|
let duration = duration.into();
|
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
ffi::gst_base_parse_set_duration(
|
2019-05-25 19:29:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
duration.format().into_glib(),
|
2021-04-11 19:39:50 +00:00
|
|
|
duration.value(),
|
2019-05-25 19:29:04 +00:00
|
|
|
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 {
|
2020-11-21 17:59:22 +00:00
|
|
|
ffi::gst_base_parse_set_frame_rate(
|
2019-05-25 19:29:04 +00:00
|
|
|
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 {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 17:59:22 +00:00
|
|
|
let ret = from_glib(ffi::gst_base_parse_convert_default(
|
2019-05-25 19:29:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2019-05-25 19:29:04 +00:00
|
|
|
src_val.to_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
U::default_format().into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2019-05-25 19:29:04 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2021-04-20 10:24:17 +00:00
|
|
|
Some(U::from_raw(U::default_format(), dest_val.assume_init()))
|
2019-05-25 19:29:04 +00:00
|
|
|
} 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 {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut dest_val = mem::MaybeUninit::uninit();
|
2020-11-21 17:59:22 +00:00
|
|
|
let ret = from_glib(ffi::gst_base_parse_convert_default(
|
2019-05-25 19:29:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
src_val.format().into_glib(),
|
2019-05-25 19:29:04 +00:00
|
|
|
src_val.to_raw_value(),
|
2021-04-27 15:15:46 +00:00
|
|
|
dest_format.into_glib(),
|
2019-07-11 12:34:28 +00:00
|
|
|
dest_val.as_mut_ptr(),
|
2019-05-25 19:29:04 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(gst::GenericFormattedValue::new(
|
|
|
|
dest_format,
|
|
|
|
dest_val.assume_init(),
|
|
|
|
))
|
2019-05-25 19:29:04 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn finish_frame(
|
|
|
|
&self,
|
|
|
|
frame: BaseParseFrame,
|
|
|
|
size: u32,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-11-21 17:59:22 +00:00
|
|
|
gst::FlowReturn::from_glib(ffi::gst_base_parse_finish_frame(
|
2019-05-25 19:29:04 +00:00
|
|
|
self.as_ref().to_glib_none().0,
|
|
|
|
frame.to_glib_none().0,
|
|
|
|
i32::try_from(size).expect("size higher than i32::MAX"),
|
|
|
|
))
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|