text: Update for subclassing API changes

This commit is contained in:
Sebastian Dröge 2020-11-14 19:41:56 +02:00
parent d7404a7e1c
commit dbf108d9a4
2 changed files with 48 additions and 21 deletions

View file

@ -119,7 +119,7 @@ impl Default for State {
}
}
struct TextWrap {
pub struct TextWrap {
srcpad: gst::Pad,
sinkpad: gst::Pad,
settings: Mutex<Settings>,
@ -127,7 +127,7 @@ struct TextWrap {
}
impl TextWrap {
fn update_wrapper(&self, element: &gst::Element) {
fn update_wrapper(&self, element: &super::TextWrap) {
let settings = self.settings.lock().unwrap();
let mut state = self.state.lock().unwrap();
@ -173,7 +173,7 @@ impl TextWrap {
fn sink_chain(
&self,
_pad: &gst::Pad,
element: &gst::Element,
element: &super::TextWrap,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.update_wrapper(element);
@ -261,13 +261,14 @@ impl TextWrap {
impl ObjectSubclass for TextWrap {
const NAME: &'static str = "RsTextWrap";
type Type = super::TextWrap;
type ParentType = gst::Element;
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
fn with_class(klass: &subclass::simple::ClassStruct<Self>) -> Self {
fn with_class(klass: &Self::Class) -> Self {
let templ = klass.get_pad_template("sink").unwrap();
let sinkpad = gst::Pad::builder_with_template(&templ, Some("sink"))
.chain_function(|pad, parent, buffer| {
@ -296,7 +297,7 @@ impl ObjectSubclass for TextWrap {
}
}
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
fn class_init(klass: &mut Self::Class) {
klass.set_metadata(
"Text Wrapper",
"Text/Filter",
@ -330,15 +331,14 @@ impl ObjectSubclass for TextWrap {
}
impl ObjectImpl for TextWrap {
fn constructed(&self, obj: &glib::Object) {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
let element = obj.downcast_ref::<gst::Element>().unwrap();
element.add_pad(&self.sinkpad).unwrap();
element.add_pad(&self.srcpad).unwrap();
obj.add_pad(&self.sinkpad).unwrap();
obj.add_pad(&self.srcpad).unwrap();
}
fn set_property(&self, _obj: &glib::Object, id: usize, value: &glib::Value) {
fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value) {
let prop = &PROPERTIES[id];
match *prop {
@ -362,7 +362,7 @@ impl ObjectImpl for TextWrap {
}
}
fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> {
fn get_property(&self, _obj: &Self::Type, id: usize) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id];
match *prop {
@ -386,7 +386,7 @@ impl ObjectImpl for TextWrap {
impl ElementImpl for TextWrap {
fn change_state(
&self,
element: &gst::Element,
element: &Self::Type,
transition: gst::StateChange,
) -> Result<gst::StateChangeSuccess, gst::StateChangeError> {
gst_info!(CAT, obj: element, "Changing state {:?}", transition);
@ -404,12 +404,3 @@ impl ElementImpl for TextWrap {
Ok(success)
}
}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(
Some(plugin),
"textwrap",
gst::Rank::None,
TextWrap::get_type(),
)
}

View file

@ -0,0 +1,36 @@
// Copyright (C) 2020 Mathieu Duponchelle <mathieu@centricular.com>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the
// Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
// Boston, MA 02110-1335, USA.
use glib::prelude::*;
mod imp;
glib_wrapper! {
pub struct TextWrap(ObjectSubclass<imp::TextWrap>) @extends gst::Element, gst::Object;
}
unsafe impl Send for TextWrap {}
unsafe impl Sync for TextWrap {}
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(
Some(plugin),
"textwrap",
gst::Rank::None,
TextWrap::static_type(),
)
}