mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-22 11:30:59 +00:00
Remove some boilerplate
This commit is contained in:
parent
f322395918
commit
b25e612458
5 changed files with 115 additions and 135 deletions
|
@ -115,59 +115,41 @@ unsafe impl BaseSinkClass<RsBaseSink> for gst_base_ffi::GstBaseSinkClass {}
|
|||
unsafe impl BaseSinkClass<RsBaseSink> for RsBaseSinkClass {}
|
||||
unsafe impl ElementClass<RsBaseSink> for gst_base_ffi::GstBaseSinkClass {}
|
||||
unsafe impl ElementClass<RsBaseSink> for RsBaseSinkClass {}
|
||||
unsafe impl ObjectClass for gst_base_ffi::GstBaseSinkClass {}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl BaseSinkImpl for Box<BaseSinkImpl> {
|
||||
fn start(&self, element: &gst_base::BaseSink) -> bool {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.start(element)
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! box_base_sink_impl(
|
||||
($name:ident) => {
|
||||
box_element_impl!($name);
|
||||
|
||||
fn stop(&self, element: &gst_base::BaseSink) -> bool {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.stop(element)
|
||||
}
|
||||
impl BaseSinkImpl for Box<$name> {
|
||||
fn start(&self, element: &gst_base::BaseSink) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.start(element)
|
||||
}
|
||||
|
||||
fn render(&self, element: &gst_base::BaseSink, buffer: &gst::BufferRef) -> gst::FlowReturn {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.render(element, buffer)
|
||||
}
|
||||
fn stop(&self, element: &gst_base::BaseSink) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.stop(element)
|
||||
}
|
||||
|
||||
fn query(&self, element: &gst_base::BaseSink, query: &mut gst::QueryRef) -> bool {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.query(element, query)
|
||||
}
|
||||
fn event(&self, element: &gst_base::BaseSink, event: &gst::Event) -> bool {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.event(element, event)
|
||||
}
|
||||
}
|
||||
fn render(&self, element: &gst_base::BaseSink, buffer: &gst::BufferRef) -> gst::FlowReturn {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.render(element, buffer)
|
||||
}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl ElementImpl for Box<BaseSinkImpl> {
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &gst::Element,
|
||||
transition: gst::StateChange,
|
||||
) -> gst::StateChangeReturn {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.change_state(element, transition)
|
||||
}
|
||||
}
|
||||
fn query(&self, element: &gst_base::BaseSink, query: &mut gst::QueryRef) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.query(element, query)
|
||||
}
|
||||
fn event(&self, element: &gst_base::BaseSink, event: &gst::Event) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.event(element, event)
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl ObjectImpl for Box<BaseSinkImpl> {
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.set_property(obj, id, value);
|
||||
}
|
||||
|
||||
fn get_property(&self, obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let imp: &BaseSinkImpl = self.as_ref();
|
||||
imp.get_property(obj, id)
|
||||
}
|
||||
}
|
||||
box_base_sink_impl!(BaseSinkImpl);
|
||||
|
||||
impl ObjectType for RsBaseSink {
|
||||
const NAME: &'static str = "RsBaseSink";
|
||||
|
|
|
@ -151,80 +151,61 @@ unsafe impl BaseSrcClass<RsBaseSrc> for gst_base_ffi::GstBaseSrcClass {}
|
|||
unsafe impl BaseSrcClass<RsBaseSrc> for RsBaseSrcClass {}
|
||||
unsafe impl ElementClass<RsBaseSrc> for gst_base_ffi::GstBaseSrcClass {}
|
||||
unsafe impl ElementClass<RsBaseSrc> for RsBaseSrcClass {}
|
||||
unsafe impl ObjectClass for gst_base_ffi::GstBaseSrcClass {}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl BaseSrcImpl for Box<BaseSrcImpl> {
|
||||
fn start(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.start(element)
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! box_base_src_impl(
|
||||
($name:ident) => {
|
||||
box_element_impl!($name);
|
||||
|
||||
fn stop(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.stop(element)
|
||||
}
|
||||
impl BaseSrcImpl for Box<$name> {
|
||||
fn start(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.start(element)
|
||||
}
|
||||
|
||||
fn is_seekable(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.is_seekable(element)
|
||||
}
|
||||
fn stop(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.stop(element)
|
||||
}
|
||||
|
||||
fn get_size(&self, element: &gst_base::BaseSrc) -> Option<u64> {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.get_size(element)
|
||||
}
|
||||
fn is_seekable(&self, element: &gst_base::BaseSrc) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.is_seekable(element)
|
||||
}
|
||||
|
||||
fn fill(
|
||||
&self,
|
||||
element: &gst_base::BaseSrc,
|
||||
offset: u64,
|
||||
length: u32,
|
||||
buffer: &mut gst::BufferRef,
|
||||
) -> gst::FlowReturn {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.fill(element, offset, length, buffer)
|
||||
}
|
||||
fn get_size(&self, element: &gst_base::BaseSrc) -> Option<u64> {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.get_size(element)
|
||||
}
|
||||
|
||||
fn do_seek(&self, element: &gst_base::BaseSrc, segment: &mut gst::Segment) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.do_seek(element, segment)
|
||||
}
|
||||
fn fill(
|
||||
&self,
|
||||
element: &gst_base::BaseSrc,
|
||||
offset: u64,
|
||||
length: u32,
|
||||
buffer: &mut gst::BufferRef,
|
||||
) -> gst::FlowReturn {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.fill(element, offset, length, buffer)
|
||||
}
|
||||
|
||||
fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.query(element, query)
|
||||
}
|
||||
fn event(&self, element: &gst_base::BaseSrc, event: &gst::Event) -> bool {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.event(element, event)
|
||||
}
|
||||
}
|
||||
fn do_seek(&self, element: &gst_base::BaseSrc, segment: &mut gst::Segment) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.do_seek(element, segment)
|
||||
}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl ElementImpl for Box<BaseSrcImpl> {
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &gst::Element,
|
||||
transition: gst::StateChange,
|
||||
) -> gst::StateChangeReturn {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.change_state(element, transition)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl ObjectImpl for Box<BaseSrcImpl> {
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.set_property(obj, id, value);
|
||||
}
|
||||
|
||||
fn get_property(&self, obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let imp: &BaseSrcImpl = self.as_ref();
|
||||
imp.get_property(obj, id)
|
||||
}
|
||||
}
|
||||
fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.query(element, query)
|
||||
}
|
||||
fn event(&self, element: &gst_base::BaseSrc, event: &gst::Event) -> bool {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.event(element, event)
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
box_base_src_impl!(BaseSrcImpl);
|
||||
|
||||
impl ObjectType for RsBaseSrc {
|
||||
const NAME: &'static str = "RsBaseSrc";
|
||||
|
|
|
@ -118,31 +118,26 @@ pub type RsElementClass = ClassStruct<RsElement>;
|
|||
// FIXME: Boilerplate
|
||||
unsafe impl ElementClass<RsElement> for RsElementClass {}
|
||||
unsafe impl ElementClass<RsElement> for gst_ffi::GstElementClass {}
|
||||
unsafe impl ObjectClass for gst_ffi::GstElementClass {}
|
||||
|
||||
// FIXME: Boilerplate
|
||||
impl ObjectImpl for Box<ElementImpl> {
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let imp: &ElementImpl = self.as_ref();
|
||||
imp.set_property(obj, id, value);
|
||||
}
|
||||
#[macro_export]
|
||||
macro_rules! box_element_impl(
|
||||
($name:ident) => {
|
||||
box_object_impl!($name);
|
||||
|
||||
fn get_property(&self, obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let imp: &ElementImpl = self.as_ref();
|
||||
imp.get_property(obj, id)
|
||||
}
|
||||
}
|
||||
impl ElementImpl for Box<$name> {
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &gst::Element,
|
||||
transition: gst::StateChange,
|
||||
) -> gst::StateChangeReturn {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.change_state(element, transition)
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
impl ElementImpl for Box<ElementImpl> {
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &gst::Element,
|
||||
transition: gst::StateChange,
|
||||
) -> gst::StateChangeReturn {
|
||||
let imp: &ElementImpl = self.as_ref();
|
||||
imp.change_state(element, transition)
|
||||
}
|
||||
}
|
||||
box_element_impl!(ElementImpl);
|
||||
|
||||
impl ObjectType for RsElement {
|
||||
const NAME: &'static str = "RsElement";
|
||||
|
|
|
@ -72,8 +72,13 @@ pub mod sink;
|
|||
pub mod demuxer;
|
||||
pub mod bytes;
|
||||
|
||||
#[macro_use]
|
||||
pub mod object;
|
||||
#[macro_use]
|
||||
pub mod element;
|
||||
#[macro_use]
|
||||
pub mod base_src;
|
||||
#[macro_use]
|
||||
pub mod base_sink;
|
||||
#[macro_use]
|
||||
pub mod uri_handler;
|
||||
|
|
|
@ -36,6 +36,23 @@ pub trait ObjectImpl: Send + Sync + 'static {
|
|||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! box_object_impl(
|
||||
($name:ident) => {
|
||||
impl ObjectImpl for Box<$name> {
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.set_property(obj, id, value);
|
||||
}
|
||||
|
||||
fn get_property(&self, obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let imp: &$name = self.as_ref();
|
||||
imp.get_property(obj, id)
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
pub trait ImplTypeStatic<T: ObjectType>: Send + Sync + 'static {
|
||||
fn get_name(&self) -> &str;
|
||||
fn new(&self, &T::RsType) -> T::ImplType;
|
||||
|
|
Loading…
Reference in a new issue