From f11b0fa5eb0d294f09d4dda7a052cf647f254688 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Thu, 13 Oct 2022 21:02:04 +0300 Subject: plugins, examples, tutorials: Use AudioCapsBuilder and VideoCapsBuilder Simplify caps creation code --- tutorial/src/rgb2gray/imp.rs | 33 ++++----------------------------- tutorial/src/sinesrc/imp.rs | 15 +++------------ 2 files changed, 7 insertions(+), 41 deletions(-) (limited to 'tutorial/src') 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> = 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> = 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 -- cgit v1.2.3