forked from mirrors/gstreamer-rs
Fix compilation with GLib subclassing changes
This commit is contained in:
parent
fec4e12410
commit
1d53b66858
5 changed files with 231 additions and 183 deletions
|
@ -98,6 +98,7 @@ mod media_factory {
|
|||
// up the class data
|
||||
impl ObjectSubclass for Factory {
|
||||
const NAME: &'static str = "RsRTSPMediaFactory";
|
||||
type Type = super::Factory;
|
||||
type ParentType = gst_rtsp_server::RTSPMediaFactory;
|
||||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -114,12 +115,8 @@ mod media_factory {
|
|||
|
||||
// Implementation of glib::Object virtual methods
|
||||
impl ObjectImpl for Factory {
|
||||
fn constructed(&self, obj: &glib::Object) {
|
||||
self.parent_constructed(obj);
|
||||
|
||||
let factory = obj
|
||||
.downcast_ref::<gst_rtsp_server::RTSPMediaFactory>()
|
||||
.unwrap();
|
||||
fn constructed(&self, factory: &Self::Type) {
|
||||
self.parent_constructed(factory);
|
||||
|
||||
// All media created by this factory are our custom media type. This would
|
||||
// not require a media factory subclass and can also be called on the normal
|
||||
|
@ -199,6 +196,7 @@ mod media {
|
|||
// up the class data
|
||||
impl ObjectSubclass for Media {
|
||||
const NAME: &'static str = "RsRTSPMedia";
|
||||
type Type = super::Media;
|
||||
type ParentType = gst_rtsp_server::RTSPMedia;
|
||||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -266,6 +264,7 @@ mod server {
|
|||
// up the class data
|
||||
impl ObjectSubclass for Server {
|
||||
const NAME: &'static str = "RsRTSPServer";
|
||||
type Type = super::Server;
|
||||
type ParentType = gst_rtsp_server::RTSPServer;
|
||||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -353,6 +352,7 @@ mod client {
|
|||
// up the class data
|
||||
impl ObjectSubclass for Client {
|
||||
const NAME: &'static str = "RsRTSPClient";
|
||||
type Type = super::Client;
|
||||
type ParentType = gst_rtsp_server::RTSPClient;
|
||||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
|
|
@ -62,6 +62,7 @@ mod fir_filter {
|
|||
// up the class data
|
||||
impl ObjectSubclass for FirFilter {
|
||||
const NAME: &'static str = "RsFirFilter";
|
||||
type Type = super::FirFilter;
|
||||
type ParentType = gst_base::BaseTransform;
|
||||
type Instance = gst::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -88,7 +89,7 @@ mod fir_filter {
|
|||
// will automatically instantiate pads for them.
|
||||
//
|
||||
// Our element here can only handle F32 mono audio.
|
||||
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
|
||||
fn class_init(klass: &mut Self::Class) {
|
||||
// Set the element specific metadata. This information is what
|
||||
// is visible from gst-inspect-1.0 and can also be programatically
|
||||
// retrieved from the gst::Registry after initial registration
|
||||
|
|
|
@ -81,7 +81,7 @@ pub trait ClockImplExt {
|
|||
fn wake_id(&self, id: &ClockId)
|
||||
where
|
||||
Self: ObjectSubclass,
|
||||
<Self as ObjectSubclass>::ParentType: IsA<Clock>;
|
||||
<Self as ObjectSubclass>::Type: IsA<Clock>;
|
||||
}
|
||||
|
||||
impl<T: ClockImpl> ClockImplExt for T {
|
||||
|
@ -199,7 +199,7 @@ impl<T: ClockImpl> ClockImplExt for T {
|
|||
fn wake_id(&self, id: &ClockId)
|
||||
where
|
||||
Self: ObjectSubclass,
|
||||
<Self as ObjectSubclass>::ParentType: IsA<Clock>,
|
||||
<Self as ObjectSubclass>::Type: IsA<Clock>,
|
||||
{
|
||||
let clock = self.get_instance();
|
||||
|
||||
|
|
|
@ -549,11 +549,14 @@ mod tests {
|
|||
use glib::subclass;
|
||||
use std::sync::atomic;
|
||||
|
||||
struct TestElement {
|
||||
srcpad: ::Pad,
|
||||
sinkpad: ::Pad,
|
||||
n_buffers: atomic::AtomicU32,
|
||||
reached_playing: atomic::AtomicBool,
|
||||
pub mod imp {
|
||||
use super::*;
|
||||
|
||||
pub struct TestElement {
|
||||
pub(super) srcpad: ::Pad,
|
||||
pub(super) sinkpad: ::Pad,
|
||||
pub(super) n_buffers: atomic::AtomicU32,
|
||||
pub(super) reached_playing: atomic::AtomicBool,
|
||||
}
|
||||
|
||||
impl TestElement {
|
||||
|
@ -571,7 +574,12 @@ mod tests {
|
|||
self.srcpad.push_event(event)
|
||||
}
|
||||
|
||||
fn sink_query(&self, _pad: &::Pad, _element: &::Element, query: &mut ::QueryRef) -> bool {
|
||||
fn sink_query(
|
||||
&self,
|
||||
_pad: &::Pad,
|
||||
_element: &::Element,
|
||||
query: &mut ::QueryRef,
|
||||
) -> bool {
|
||||
self.srcpad.peer_query(query)
|
||||
}
|
||||
|
||||
|
@ -579,13 +587,19 @@ mod tests {
|
|||
self.sinkpad.push_event(event)
|
||||
}
|
||||
|
||||
fn src_query(&self, _pad: &::Pad, _element: &::Element, query: &mut ::QueryRef) -> bool {
|
||||
fn src_query(
|
||||
&self,
|
||||
_pad: &::Pad,
|
||||
_element: &::Element,
|
||||
query: &mut ::QueryRef,
|
||||
) -> bool {
|
||||
self.sinkpad.peer_query(query)
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectSubclass for TestElement {
|
||||
const NAME: &'static str = "TestElement";
|
||||
type Type = super::TestElement;
|
||||
type ParentType = ::Element;
|
||||
type Instance = ::subclass::ElementInstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -666,10 +680,9 @@ mod tests {
|
|||
}
|
||||
|
||||
impl ObjectImpl for TestElement {
|
||||
fn constructed(&self, obj: &glib::Object) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self, element: &Self::Type) {
|
||||
self.parent_constructed(element);
|
||||
|
||||
let element = obj.downcast_ref::<::Element>().unwrap();
|
||||
element.add_pad(&self.sinkpad).unwrap();
|
||||
element.add_pad(&self.srcpad).unwrap();
|
||||
}
|
||||
|
@ -690,15 +703,29 @@ mod tests {
|
|||
Ok(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib_wrapper! {
|
||||
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends ::Element, ::Object;
|
||||
}
|
||||
|
||||
unsafe impl Send for TestElement {}
|
||||
unsafe impl Sync for TestElement {}
|
||||
|
||||
impl TestElement {
|
||||
pub fn new(name: Option<&str>) -> Self {
|
||||
glib::Object::new(TestElement::static_type(), &[("name", &name)])
|
||||
.unwrap()
|
||||
.downcast::<Self>()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_element_subclass() {
|
||||
::init().unwrap();
|
||||
|
||||
let element = glib::Object::new(TestElement::get_type(), &[("name", &"test")])
|
||||
.unwrap()
|
||||
.downcast::<::Element>()
|
||||
.unwrap();
|
||||
let element = TestElement::new(Some("test"));
|
||||
|
||||
assert_eq!(element.get_name(), "test");
|
||||
|
||||
|
@ -713,8 +740,10 @@ mod tests {
|
|||
|
||||
src.set_property("num-buffers", &100i32).unwrap();
|
||||
|
||||
pipeline.add_many(&[&src, &element, &sink]).unwrap();
|
||||
::Element::link_many(&[&src, &element, &sink]).unwrap();
|
||||
pipeline
|
||||
.add_many(&[&src, &element.upcast_ref(), &sink])
|
||||
.unwrap();
|
||||
::Element::link_many(&[&src, &element.upcast_ref(), &sink]).unwrap();
|
||||
|
||||
pipeline.set_state(::State::Playing).unwrap();
|
||||
let bus = pipeline.get_bus().unwrap();
|
||||
|
@ -724,7 +753,7 @@ mod tests {
|
|||
|
||||
pipeline.set_state(::State::Null).unwrap();
|
||||
|
||||
let imp = TestElement::from_instance(&element);
|
||||
let imp = imp::TestElement::from_instance(&element);
|
||||
assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100);
|
||||
assert_eq!(imp.reached_playing.load(atomic::Ordering::SeqCst), true);
|
||||
}
|
||||
|
|
|
@ -93,13 +93,17 @@ mod tests {
|
|||
use glib::subclass;
|
||||
use std::sync::atomic;
|
||||
|
||||
struct TestPad {
|
||||
linked: atomic::AtomicBool,
|
||||
unlinked: atomic::AtomicBool,
|
||||
pub mod imp {
|
||||
use super::*;
|
||||
|
||||
pub struct TestPad {
|
||||
pub(super) linked: atomic::AtomicBool,
|
||||
pub(super) unlinked: atomic::AtomicBool,
|
||||
}
|
||||
|
||||
impl ObjectSubclass for TestPad {
|
||||
const NAME: &'static str = "TestPad";
|
||||
type Type = super::TestPad;
|
||||
type ParentType = ::Pad;
|
||||
type Instance = subclass::simple::InstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
@ -127,18 +131,32 @@ mod tests {
|
|||
self.parent_unlinked(pad, peer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib_wrapper! {
|
||||
pub struct TestPad(ObjectSubclass<imp::TestPad>) @extends ::Pad, ::Object;
|
||||
}
|
||||
|
||||
unsafe impl Send for TestPad {}
|
||||
unsafe impl Sync for TestPad {}
|
||||
|
||||
impl TestPad {
|
||||
pub fn new(name: &str, direction: ::PadDirection) -> Self {
|
||||
glib::Object::new(
|
||||
TestPad::static_type(),
|
||||
&[("name", &name), ("direction", &direction)],
|
||||
)
|
||||
.unwrap()
|
||||
.downcast::<Self>()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pad_subclass() {
|
||||
::init().unwrap();
|
||||
|
||||
let pad = glib::Object::new(
|
||||
TestPad::get_type(),
|
||||
&[("name", &"test"), ("direction", &::PadDirection::Src)],
|
||||
)
|
||||
.unwrap()
|
||||
.downcast::<::Pad>()
|
||||
.unwrap();
|
||||
let pad = TestPad::new("test", ::PadDirection::Src);
|
||||
|
||||
assert_eq!(pad.get_name(), "test");
|
||||
|
||||
|
@ -146,7 +164,7 @@ mod tests {
|
|||
pad.link(&otherpad).unwrap();
|
||||
pad.unlink(&otherpad).unwrap();
|
||||
|
||||
let imp = TestPad::from_instance(&pad);
|
||||
let imp = imp::TestPad::from_instance(&pad);
|
||||
assert!(imp.linked.load(atomic::Ordering::SeqCst));
|
||||
assert!(imp.unlinked.load(atomic::Ordering::SeqCst));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue