mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
gst object: add a panicking variant of set_property_from_str
Similar to what was added to ObjectExt
This commit is contained in:
parent
213020165a
commit
e3a65a3a88
9 changed files with 21 additions and 16 deletions
|
@ -89,7 +89,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
||||||
|
|
||||||
// The videotestsrc supports multiple test patterns. In this example, we will use the
|
// The videotestsrc supports multiple test patterns. In this example, we will use the
|
||||||
// pattern with a white ball moving around the video's center point.
|
// pattern with a white ball moving around the video's center point.
|
||||||
src.set_property_from_str("pattern", "ball").unwrap();
|
src.set_property_from_str("pattern", "ball");
|
||||||
|
|
||||||
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
||||||
let fontmap = pangocairo::FontMap::new().unwrap();
|
let fontmap = pangocairo::FontMap::new().unwrap();
|
||||||
|
|
|
@ -87,7 +87,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
||||||
|
|
||||||
// The videotestsrc supports multiple test patterns. In this example, we will use the
|
// The videotestsrc supports multiple test patterns. In this example, we will use the
|
||||||
// pattern with a white ball moving around the video's center point.
|
// pattern with a white ball moving around the video's center point.
|
||||||
src.set_property_from_str("pattern", "ball").unwrap();
|
src.set_property_from_str("pattern", "ball");
|
||||||
|
|
||||||
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
// The PangoFontMap represents the set of fonts available for a particular rendering system.
|
||||||
let fontmap = pangocairo::FontMap::new().unwrap();
|
let fontmap = pangocairo::FontMap::new().unwrap();
|
||||||
|
|
|
@ -134,7 +134,7 @@ fn example_main() -> Result<(), Error> {
|
||||||
pipeline.add_many(&[&enc, &mux, &sink])?;
|
pipeline.add_many(&[&enc, &mux, &sink])?;
|
||||||
gst::Element::link_many(&[&filter, &enc, &mux, &sink])?;
|
gst::Element::link_many(&[&filter, &enc, &mux, &sink])?;
|
||||||
sink.set_property("location", "out.mkv");
|
sink.set_property("location", "out.mkv");
|
||||||
enc.set_property_from_str("tune", "zerolatency")?;
|
enc.set_property_from_str("tune", "zerolatency");
|
||||||
eprintln!("Recording to out.mkv");
|
eprintln!("Recording to out.mkv");
|
||||||
}
|
}
|
||||||
_ => return Err(Error::from(UsageError(args[0].clone()))),
|
_ => return Err(Error::from(UsageError(args[0].clone()))),
|
||||||
|
|
|
@ -151,14 +151,14 @@ fn example_main() -> Result<(), Error> {
|
||||||
|
|
||||||
let video_caps = gst::Caps::builder("video/x-raw").build();
|
let video_caps = gst::Caps::builder("video/x-raw").build();
|
||||||
|
|
||||||
src.set_property_from_str("pattern", "ball")?;
|
src.set_property_from_str("pattern", "ball");
|
||||||
sink.set_property("host", "127.0.0.1");
|
sink.set_property("host", "127.0.0.1");
|
||||||
sink.set_property("sync", true);
|
sink.set_property("sync", true);
|
||||||
enc.set_property("keyframe-max-dist", 30i32);
|
enc.set_property("keyframe-max-dist", 30i32);
|
||||||
enc.set_property("threads", 12i32);
|
enc.set_property("threads", 12i32);
|
||||||
enc.set_property("cpu-used", -16i32);
|
enc.set_property("cpu-used", -16i32);
|
||||||
enc.set_property("deadline", 1i64);
|
enc.set_property("deadline", 1i64);
|
||||||
enc.set_property_from_str("error-resilient", "default")?;
|
enc.set_property_from_str("error-resilient", "default");
|
||||||
src.set_property("expose-all-streams", false);
|
src.set_property("expose-all-streams", false);
|
||||||
src.set_property("caps", video_caps);
|
src.set_property("caps", video_caps);
|
||||||
src.set_property("uri", uri);
|
src.set_property("uri", uri);
|
||||||
|
|
|
@ -272,7 +272,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
||||||
filter.link(&conv)?;
|
filter.link(&conv)?;
|
||||||
conv.link(&sink)?;
|
conv.link(&sink)?;
|
||||||
|
|
||||||
src.set_property_from_str("wave", "white-noise").unwrap();
|
src.set_property_from_str("wave", "white-noise");
|
||||||
|
|
||||||
// Create a windowed sinc lowpass filter at 1/64 sample rate,
|
// Create a windowed sinc lowpass filter at 1/64 sample rate,
|
||||||
// i.e. 689Hz for 44.1kHz sample rate
|
// i.e. 689Hz for 44.1kHz sample rate
|
||||||
|
|
|
@ -5,11 +5,14 @@ use glib::prelude::*;
|
||||||
|
|
||||||
pub trait GObjectExtManualGst: 'static {
|
pub trait GObjectExtManualGst: 'static {
|
||||||
#[doc(alias = "gst_util_set_object_arg")]
|
#[doc(alias = "gst_util_set_object_arg")]
|
||||||
fn set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError>;
|
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 {
|
impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
|
||||||
fn set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError> {
|
fn try_set_property_from_str(&self, name: &str, value: &str) -> Result<(), glib::BoolError> {
|
||||||
let pspec = self.find_property(name).ok_or_else(|| {
|
let pspec = self.find_property(name).ok_or_else(|| {
|
||||||
glib::bool_error!("property '{}' of type '{}' not found", name, self.type_())
|
glib::bool_error!("property '{}' of type '{}' not found", name, self.type_())
|
||||||
})?;
|
})?;
|
||||||
|
@ -31,6 +34,10 @@ impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
|
||||||
|
|
||||||
self.try_set_property_from_value(name, &value)
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -42,9 +49,7 @@ mod tests {
|
||||||
crate::init().unwrap();
|
crate::init().unwrap();
|
||||||
|
|
||||||
let fakesink = crate::ElementFactory::make("fakesink", None).unwrap();
|
let fakesink = crate::ElementFactory::make("fakesink", None).unwrap();
|
||||||
fakesink
|
fakesink.set_property_from_str("state-error", "ready-to-paused");
|
||||||
.set_property_from_str("state-error", "ready-to-paused")
|
|
||||||
.unwrap();
|
|
||||||
let v = fakesink.property_value("state-error");
|
let v = fakesink.property_value("state-error");
|
||||||
let e = glib::EnumValue::from_value(&v).unwrap();
|
let e = glib::EnumValue::from_value(&v).unwrap();
|
||||||
assert_eq!(e.nick(), "ready-to-paused");
|
assert_eq!(e.nick(), "ready-to-paused");
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn tutorial_main() {
|
||||||
source.link(&sink).expect("Elements could not be linked.");
|
source.link(&sink).expect("Elements could not be linked.");
|
||||||
|
|
||||||
// Modify the source's properties
|
// Modify the source's properties
|
||||||
source.set_property_from_str("pattern", "smpte").unwrap();
|
source.set_property_from_str("pattern", "smpte");
|
||||||
|
|
||||||
// Start playing
|
// Start playing
|
||||||
pipeline
|
pipeline
|
||||||
|
|
|
@ -25,8 +25,8 @@ fn tutorial_main() {
|
||||||
let pipeline = gst::Pipeline::new(Some("test-pipeline"));
|
let pipeline = gst::Pipeline::new(Some("test-pipeline"));
|
||||||
|
|
||||||
audio_source.set_property("freq", 215.0);
|
audio_source.set_property("freq", 215.0);
|
||||||
visual.set_property_from_str("shader", "none").unwrap();
|
visual.set_property_from_str("shader", "none");
|
||||||
visual.set_property_from_str("style", "lines").unwrap();
|
visual.set_property_from_str("style", "lines");
|
||||||
|
|
||||||
pipeline
|
pipeline
|
||||||
.add_many(&[
|
.add_many(&[
|
||||||
|
|
|
@ -64,8 +64,8 @@ fn main() {
|
||||||
|
|
||||||
let pipeline = gst::Pipeline::new(Some("test-pipeline"));
|
let pipeline = gst::Pipeline::new(Some("test-pipeline"));
|
||||||
|
|
||||||
visual.set_property_from_str("shader", "none").unwrap();
|
visual.set_property_from_str("shader", "none");
|
||||||
visual.set_property_from_str("style", "lines").unwrap();
|
visual.set_property_from_str("style", "lines");
|
||||||
|
|
||||||
pipeline
|
pipeline
|
||||||
.add_many(&[
|
.add_many(&[
|
||||||
|
|
Loading…
Reference in a new issue