Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2017-09-22 00:23:40 +0300
committerSebastian Dröge <sebastian@centricular.com>2017-09-22 13:35:17 +0300
commitcda23d5c4126264934e96b235a3b3dcd49b579dd (patch)
treee402f51864c3685c11a6a2f9399cd6df9562774d /gst-plugin/src/base_src.rs
parent8d253fd46a2fe00e2395b8c3dde217a4f0f80061 (diff)
Implement generic object subclass creation in a more... generic... way
That actually works for subclasses of subclasses too without too much boilerplate, and also keeps the GObject boilerplate in a single file instead of having it for every single subclass.
Diffstat (limited to 'gst-plugin/src/base_src.rs')
-rw-r--r--gst-plugin/src/base_src.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/gst-plugin/src/base_src.rs b/gst-plugin/src/base_src.rs
new file mode 100644
index 000000000..1888964ae
--- /dev/null
+++ b/gst-plugin/src/base_src.rs
@@ -0,0 +1,89 @@
+// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::ptr;
+use std::mem;
+use mopa;
+
+use glib_ffi;
+use gobject_ffi;
+use gst_ffi;
+use gst_base_ffi;
+
+use glib;
+use glib::translate::*;
+use gst;
+use gst::prelude::*;
+use gst_base;
+use gst_base::prelude::*;
+
+use object::*;
+use element::*;
+
+pub trait BaseSrcImpl: mopa::Any + ElementImpl + Send + Sync + 'static {}
+
+mopafy!(BaseSrcImpl);
+
+pub unsafe trait BaseSrc: IsA<gst_base::BaseSrc> {}
+
+pub unsafe trait BaseSrcClass<T: ObjectType>
+where
+ T::RsType: IsA<gst_base::BaseSrc>,
+ T::ImplType: BaseSrcImpl,
+{
+}
+
+glib_wrapper! {
+ pub struct RsBaseSrc(Object<InstanceStruct<RsBaseSrc>>): [gst_base::BaseSrc => gst_base_ffi::GstBaseSrc,
+ gst::Element => gst_ffi::GstElement,
+ gst::Object => gst_ffi::GstObject];
+
+ match fn {
+ get_type => || get_type::<RsBaseSrc>(),
+ }
+}
+
+unsafe impl<T: IsA<gst_base::BaseSrc>> BaseSrc for T {}
+pub type RsBaseSrcClass = ClassStruct<RsBaseSrc>;
+
+// FIXME: Boilerplate
+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 {}
+
+// FIXME: Boilerplate
+impl BaseSrcImpl for Box<BaseSrcImpl> {}
+
+// 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)
+ }
+}
+
+impl ObjectType for RsBaseSrc {
+ const NAME: &'static str = "RsBaseSrc";
+ type GlibType = gst_base_ffi::GstBaseSrc;
+ type GlibClassType = gst_base_ffi::GstBaseSrcClass;
+ type RsType = RsBaseSrc;
+ type ImplType = Box<BaseSrcImpl>;
+
+ fn glib_type() -> glib::Type {
+ unsafe { from_glib(gst_base_ffi::gst_base_src_get_type()) }
+ }
+
+ fn class_init(klass: &mut Self::GlibClassType) {
+ ElementClass::override_vfuncs(klass);
+ }
+}