Update for glib::Object::new() API changes

This commit is contained in:
Sebastian Dröge 2022-10-07 20:39:11 +03:00
parent dcd53bd16e
commit 3cd902513d
13 changed files with 30 additions and 89 deletions

View file

@ -422,7 +422,7 @@ mod cairo_compositor {
impl CairoCompositor {
// Creates a new instance of our compositor with the given name.
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]).expect("Failed to create cairo compositor")
glib::Object::new(&[("name", &name)])
}
}

View file

@ -52,7 +52,7 @@ fn create_receiver_pipeline(
let pipeline = gst::Pipeline::new(None);
let src = gst::ElementFactory::make("appsrc", None).map_err(|_| MissingElement("appsrc"))?;
let filter = video_filter::FdMemoryFadeInVideoFilter::new()?.upcast::<gst::Element>();
let filter = video_filter::FdMemoryFadeInVideoFilter::default().upcast::<gst::Element>();
let convert = gst::ElementFactory::make("videoconvert", None)
.map_err(|_| MissingElement("videoconvert"))?;
let queue = gst::ElementFactory::make("queue", None).map_err(|_| MissingElement("queue"))?;
@ -376,15 +376,13 @@ fn main() {
// The purpose of this custom video filter is to demonstrate how
// the file descriptor of a FdMemory can be accessed.
mod video_filter {
use anyhow::Error;
glib::wrapper! {
pub struct FdMemoryFadeInVideoFilter(ObjectSubclass<imp::FdMemoryFadeInVideoFilter>) @extends gst_video::VideoFilter, gst_base::BaseTransform, gst::Element, gst::Object;
}
impl FdMemoryFadeInVideoFilter {
pub fn new() -> Result<Self, Error> {
Ok(glib::Object::builder().build()?)
impl Default for FdMemoryFadeInVideoFilter {
fn default() -> Self {
glib::Object::builder().build()
}
}
mod imp {

View file

@ -52,7 +52,7 @@ mod mirror {
impl GLMirrorFilter {
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]).expect("Failed to create GL Mirror Filter Object")
glib::Object::new(&[("name", &name)])
}
}

View file

@ -153,7 +153,7 @@ mod media_factory {
impl Default for Factory {
// Creates a new instance of our factory
fn default() -> Factory {
glib::Object::new(&[]).expect("Failed to create factory")
glib::Object::new(&[])
}
}
}
@ -265,7 +265,7 @@ mod server {
impl Default for Server {
// Creates a new instance of our factory
fn default() -> Server {
glib::Object::new(&[]).expect("Failed to create server")
glib::Object::new(&[])
}
}
}
@ -313,7 +313,7 @@ mod client {
impl Default for Client {
// Creates a new instance of our factory
fn default() -> Client {
glib::Object::new(&[]).expect("Failed to create client")
glib::Object::new(&[])
}
}
}
@ -361,7 +361,7 @@ mod mount_points {
impl Default for MountPoints {
// Creates a new instance of our factory
fn default() -> Self {
glib::Object::new(&[]).expect("Failed to create mount points")
glib::Object::new(&[])
}
}
}

View file

@ -223,7 +223,7 @@ mod fir_filter {
impl FirFilter {
// Creates a new instance of our filter with the given name
pub fn new(name: Option<&str>) -> FirFilter {
glib::Object::new(&[("name", &name)]).expect("Failed to create fir filter")
glib::Object::new(&[("name", &name)])
}
// Sets the coefficients by getting access to the private

View file

@ -15,32 +15,11 @@ pub trait ChildProxyExtManual: 'static {
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn child_property_value(&self, name: &str) -> glib::Value;
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
&self,
name: &str,
) -> Result<V, glib::BoolError>;
#[doc(alias = "get_child_property")]
#[doc(alias = "gst_child_proxy_get")]
fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError>;
#[doc(alias = "gst_child_proxy_set")]
fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V);
#[doc(alias = "gst_child_proxy_set_property")]
fn set_child_property_from_value(&self, name: &str, value: &glib::Value);
#[doc(alias = "gst_child_proxy_set")]
fn try_set_child_property<V: glib::ToValue>(
&self,
name: &str,
value: V,
) -> Result<(), glib::BoolError>;
#[doc(alias = "gst_child_proxy_set_property")]
fn try_set_child_property_from_value(
&self,
name: &str,
value: &glib::Value,
) -> Result<(), glib::BoolError>;
}
impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
@ -62,54 +41,27 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
}
}
#[track_caller]
fn child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(&self, name: &str) -> V {
let (child, pspec) = self.lookup(name).unwrap();
child.property(pspec.name())
}
#[track_caller]
fn child_property_value(&self, name: &str) -> glib::Value {
let (child, pspec) = self.lookup(name).unwrap();
child.property_value(pspec.name())
}
fn try_child_property<V: for<'b> glib::value::FromValue<'b> + 'static>(
&self,
name: &str,
) -> Result<V, glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_property(pspec.name())
}
fn try_child_property_value(&self, name: &str) -> Result<glib::Value, glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_property_value(pspec.name())
}
#[track_caller]
fn set_child_property<V: glib::ToValue>(&self, name: &str, value: V) {
let (child, pspec) = self.lookup(name).unwrap();
child.set_property(pspec.name(), value)
}
#[track_caller]
fn set_child_property_from_value(&self, name: &str, value: &glib::Value) {
let (child, pspec) = self.lookup(name).unwrap();
child.set_property_from_value(pspec.name(), value)
}
fn try_set_child_property<V: glib::ToValue>(
&self,
name: &str,
value: V,
) -> Result<(), glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_set_property(pspec.name(), value)
}
fn try_set_child_property_from_value(
&self,
name: &str,
value: &glib::Value,
) -> Result<(), glib::BoolError> {
let (child, pspec) = self.lookup(name)?;
child.try_set_property_from_value(pspec.name(), value)
}
}

View file

@ -4,18 +4,16 @@ use crate::value::GstValueExt;
use glib::prelude::*;
pub trait GObjectExtManualGst: 'static {
#[doc(alias = "gst_util_set_object_arg")]
fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError>;
#[doc(alias = "gst_util_set_object_arg")]
fn set_property_from_str(&self, name: &str, value: &str);
}
impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError> {
let pspec = self.find_property(name).ok_or_else(|| {
glib::bool_error!("property '{}' of type '{}' not found", name, self.type_())
})?;
#[track_caller]
fn set_property_from_str(&self, name: &str, value: &str) {
let pspec = self.find_property(name).unwrap_or_else(|| {
panic!("property '{}' of type '{}' not found", name, self.type_());
});
let value = {
if pspec.value_type() == crate::Structure::static_type() && value == "NULL" {
@ -23,20 +21,16 @@ impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
} else {
#[cfg(feature = "v1_20")]
{
glib::Value::deserialize_with_pspec(value, &pspec)?
glib::Value::deserialize_with_pspec(value, &pspec).unwrap()
}
#[cfg(not(feature = "v1_20"))]
{
glib::Value::deserialize(value, pspec.value_type())?
glib::Value::deserialize(value, pspec.value_type()).unwrap()
}
}
};
self.try_set_property_from_value(name, &value)
}
fn set_property_from_str(&self, name: &str, value: &str) {
self.try_set_property_from_str(name, value).unwrap()
self.set_property_from_value(name, &value)
}
}

View file

@ -1661,8 +1661,7 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
assert_initialized_main_thread!();
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)])
.expect("Failed to create pad");
let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)]);
// Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
@ -1713,7 +1712,6 @@ impl<T: IsA<Pad> + IsA<glib::Object> + glib::object::IsClass> PadBuilder<T> {
("template", templ),
],
)
.expect("Failed to create pad")
.downcast::<T>()
.unwrap();

View file

@ -554,7 +554,7 @@ mod tests {
impl Default for TestBufferPool {
fn default() -> Self {
glib::Object::new(&[]).unwrap()
glib::Object::new(&[])
}
}

View file

@ -782,7 +782,7 @@ mod tests {
impl TestElement {
pub fn new(name: Option<&str>) -> Self {
glib::Object::new(&[("name", &name)]).unwrap()
glib::Object::new(&[("name", &name)])
}
}

View file

@ -131,7 +131,7 @@ mod tests {
impl TestPad {
pub fn new(name: &str, direction: PadDirection) -> Self {
glib::Object::new(&[("name", &name), ("direction", &direction)]).unwrap()
glib::Object::new(&[("name", &name), ("direction", &direction)])
}
}

View file

@ -313,7 +313,7 @@ mod tests {
impl Default for TestPool {
fn default() -> Self {
glib::Object::new(&[]).unwrap()
glib::Object::new(&[])
}
}

View file

@ -56,7 +56,7 @@ fn send_seek_event(pipeline: &Element, rate: f64) -> bool {
};
// If we have not done so, obtain the sink through which we will send the seek events
if let Ok(Some(video_sink)) = pipeline.try_property::<Option<Element>>("video-sink") {
if let Some(video_sink) = pipeline.property::<Option<Element>>("video-sink") {
println!("Current rate: {}\r", rate);
// Send the event
video_sink.send_event(seek_event)
@ -171,8 +171,7 @@ USAGE: Choose one of the following options, then press enter:
}
}
Command::NextFrame => {
if let Ok(Some(video_sink)) = pipeline.try_property::<Option<Element>>("video-sink")
{
if let Some(video_sink) = pipeline.property::<Option<Element>>("video-sink") {
// Send the event
let step = Step::new(gst::format::Buffers(1), rate.abs(), true, false);
video_sink.send_event(step);