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:
authorVivia Nikolaidou <vivia@ahiru.eu>2022-10-13 21:02:04 +0300
committerVivia Nikolaidou <vivia@ahiru.eu>2022-10-13 22:24:57 +0300
commitf11b0fa5eb0d294f09d4dda7a052cf647f254688 (patch)
tree6c3bd1726dc87c6a7d97f2804e1423f4c33acf72 /tutorial
parent862c2af1d9e81743f659609552ad4d409fb9c1fb (diff)
plugins, examples, tutorials: Use AudioCapsBuilder and VideoCapsBuilder
Simplify caps creation code
Diffstat (limited to 'tutorial')
-rw-r--r--tutorial/src/rgb2gray/imp.rs33
-rw-r--r--tutorial/src/sinesrc/imp.rs15
-rw-r--r--tutorial/tutorial-1.md32
-rw-r--r--tutorial/tutorial-2.md18
4 files changed, 18 insertions, 80 deletions
diff --git a/tutorial/src/rgb2gray/imp.rs b/tutorial/src/rgb2gray/imp.rs
index 5fef8ce51..70e936658 100644
--- a/tutorial/src/rgb2gray/imp.rs
+++ b/tutorial/src/rgb2gray/imp.rs
@@ -14,7 +14,6 @@ use gst::subclass::prelude::*;
use gst_base::subclass::prelude::*;
use gst_video::subclass::prelude::*;
-use std::i32;
use std::sync::Mutex;
use once_cell::sync::Lazy;
@@ -197,23 +196,8 @@ impl ElementImpl for Rgb2Gray {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
// On the src pad, we can produce BGRx and GRAY8 of any
// width/height and with any framerate
- let caps = gst::Caps::builder("video/x-raw")
- .field(
- "format",
- gst::List::new([
- gst_video::VideoFormat::Bgrx.to_str(),
- gst_video::VideoFormat::Gray8.to_str(),
- ]),
- )
- .field("width", gst::IntRange::new(0, i32::MAX))
- .field("height", gst::IntRange::new(0, i32::MAX))
- .field(
- "framerate",
- gst::FractionRange::new(
- gst::Fraction::new(0, 1),
- gst::Fraction::new(i32::MAX, 1),
- ),
- )
+ let caps = gst_video::VideoCapsBuilder::new()
+ .format_list([gst_video::VideoFormat::Bgrx, gst_video::VideoFormat::Gray8])
.build();
// The src pad template must be named "src" for basetransform
// and specific a pad that is always there
@@ -227,17 +211,8 @@ impl ElementImpl for Rgb2Gray {
// On the sink pad, we can accept BGRx of any
// width/height and with any framerate
- let caps = gst::Caps::builder("video/x-raw")
- .field("format", gst_video::VideoFormat::Bgrx.to_str())
- .field("width", gst::IntRange::new(0, i32::MAX))
- .field("height", gst::IntRange::new(0, i32::MAX))
- .field(
- "framerate",
- gst::FractionRange::new(
- gst::Fraction::new(0, 1),
- gst::Fraction::new(i32::MAX, 1),
- ),
- )
+ let caps = gst_video::VideoCapsBuilder::new()
+ .format(gst_video::VideoFormat::Bgrx)
.build();
// The sink pad template must be named "sink" for basetransform
// and specific a pad that is always there
diff --git a/tutorial/src/sinesrc/imp.rs b/tutorial/src/sinesrc/imp.rs
index d87025ce4..38811fc49 100644
--- a/tutorial/src/sinesrc/imp.rs
+++ b/tutorial/src/sinesrc/imp.rs
@@ -19,7 +19,7 @@ use byte_slice_cast::*;
use std::ops::Rem;
use std::sync::Mutex;
-use std::{i32, u32};
+use std::u32;
use num_traits::cast::NumCast;
use num_traits::float::Float;
@@ -352,17 +352,8 @@ impl ElementImpl for SineSrc {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
// On the src pad, we can produce F32/F64 with any sample rate
// and any number of channels
- let caps = gst::Caps::builder("audio/x-raw")
- .field(
- "format",
- gst::List::new([
- gst_audio::AUDIO_FORMAT_F32.to_str(),
- gst_audio::AUDIO_FORMAT_F64.to_str(),
- ]),
- )
- .field("layout", "interleaved")
- .field("rate", gst::IntRange::new(1, i32::MAX))
- .field("channels", gst::IntRange::new(1, i32::MAX))
+ let caps = gst_audio::AudioCapsBuilder::new_interleaved()
+ .format_list([gst_audio::AUDIO_FORMAT_F32, gst_audio::AUDIO_FORMAT_F64])
.build();
// The src pad template must be named "src" for basesrc
// and specific a pad that is always there
diff --git a/tutorial/tutorial-1.md b/tutorial/tutorial-1.md
index 8923ee31a..1ebc61f03 100644
--- a/tutorial/tutorial-1.md
+++ b/tutorial/tutorial-1.md
@@ -331,23 +331,10 @@ To be able to declare what kinds of pads an element can create (they are not nec
In our case we only have always pads, one sink pad called “sink”, on which we can only accept RGB (BGRx to be exact) data with any width/height/framerate and one source pad called “src”, on which we will produce either RGB (BGRx) data or GRAY8 (8-bit grayscale) data. We do this by adding the following code to the class_init function.
```rust
- let caps = gst::Caps::builder("video/x-raw")
- .field(
- "format",
- gst::List::new([
- gst_video::VideoFormat::Bgrx.to_str(),
+ let caps = gst_video::VideoCapsBuilder::new()
+ .format_list([gst_video::VideoFormat::Bgrx.to_str(),
gst_video::VideoFormat::Gray8.to_str(),
- ]),
- )
- .field("width", gst::IntRange::new(0, i32::MAX))
- .field("height", gst::IntRange::new(0, i32::MAX))
- .field(
- "framerate",
- gst::FractionRange::new(
- gst::Fraction::new(0, 1),
- gst::Fraction::new(i32::MAX, 1),
- ),
- )
+ ])
.build();
let src_pad_template = gst::PadTemplate::new(
"src",
@@ -359,17 +346,8 @@ In our case we only have always pads, one sink pad called “sink”, on which w
klass.add_pad_template(src_pad_template);
- let caps = gst::Caps::builder("video/x-raw")
- .field("format", gst_video::VideoFormat::Bgrx.to_str())
- .field("width", gst::IntRange::new(0, i32::MAX))
- .field("height", gst::IntRange:::new(0, i32::MAX))
- .field(
- "framerate",
- gst::FractionRange::new(
- gst::Fraction::new(0, 1),
- gst::Fraction::new(i32::MAX, 1),
- ),
- )
+ let caps = gst_video::VideoCapsBuilder::new()
+ .format(gst_video::VideoFormat::Bgrx)
.build();
let sink_pad_template = gst::PadTemplate::new(
"sink",
diff --git a/tutorial/tutorial-2.md b/tutorial/tutorial-2.md
index 75509ac50..7934a0c4d 100644
--- a/tutorial/tutorial-2.md
+++ b/tutorial/tutorial-2.md
@@ -137,18 +137,12 @@ impl ObjectSubclass for SineSrc {
// pads that could exist for this type.
// On the src pad, we can produce F32/F64 with any sample rate
- // and any number of channels
- let caps = gst::Caps::builder("audio/x-raw")
- .field(
- "format",
- gst::List::new([
- gst_audio::AUDIO_FORMAT_F32.to_str(),
- gst_audio::AUDIO_FORMAT_F64.to_str(),
- ]),
- )
- .field("layout", "interleaved")
- .field("rate", gst::IntRange::new(1, i32::MAX))
- .field("channels", gst::IntRange::new(1, i32::MAX))
+ // and any number of channels (default)
+ let caps = gst_audio::AudioCapsBuilder::new_interleaved()
+ .format_list([
+ gst_audio::AUDIO_FORMAT_F32,
+ gst_audio::AUDIO_FORMAT_F64,
+ ])
.build();
// The src pad template must be named "src" for basesrc
// and specific a pad that is always there