diff options
author | Vivia Nikolaidou <vivia@ahiru.eu> | 2022-10-13 21:02:04 +0300 |
---|---|---|
committer | Vivia Nikolaidou <vivia@ahiru.eu> | 2022-10-13 22:24:57 +0300 |
commit | f11b0fa5eb0d294f09d4dda7a052cf647f254688 (patch) | |
tree | 6c3bd1726dc87c6a7d97f2804e1423f4c33acf72 | |
parent | 862c2af1d9e81743f659609552ad4d409fb9c1fb (diff) |
plugins, examples, tutorials: Use AudioCapsBuilder and VideoCapsBuilder
Simplify caps creation code
-rw-r--r-- | audio/audiofx/src/hrtfrender/imp.rs | 16 | ||||
-rw-r--r-- | audio/audiofx/tests/hrtfrender.rs | 90 | ||||
-rw-r--r-- | audio/claxon/tests/claxondec.rs | 9 | ||||
-rw-r--r-- | audio/csound/tests/csound_filter.rs | 63 | ||||
-rw-r--r-- | audio/lewton/src/lewtondec/imp.rs | 8 | ||||
-rw-r--r-- | audio/lewton/tests/lewtondec.rs | 9 | ||||
-rw-r--r-- | docs/plugins/gst_plugins_cache.json | 10 | ||||
-rw-r--r-- | generic/fmp4/examples/hls_live.rs | 10 | ||||
-rw-r--r-- | generic/fmp4/examples/hls_vod.rs | 14 | ||||
-rw-r--r-- | net/aws/Cargo.toml | 1 | ||||
-rw-r--r-- | net/aws/src/aws_transcriber/imp.rs | 8 | ||||
-rw-r--r-- | tutorial/src/rgb2gray/imp.rs | 33 | ||||
-rw-r--r-- | tutorial/src/sinesrc/imp.rs | 15 | ||||
-rw-r--r-- | tutorial/tutorial-1.md | 32 | ||||
-rw-r--r-- | tutorial/tutorial-2.md | 18 | ||||
-rw-r--r-- | utils/fallbackswitch/tests/fallbackswitch.rs | 20 | ||||
-rw-r--r-- | utils/togglerecord/tests/tests.rs | 19 | ||||
-rw-r--r-- | video/cdg/src/cdgdec/imp.rs | 10 | ||||
-rw-r--r-- | video/gtk4/examples/gtksink.rs | 6 | ||||
-rw-r--r-- | video/webp/src/dec/imp.rs | 4 |
20 files changed, 153 insertions, 242 deletions
diff --git a/audio/audiofx/src/hrtfrender/imp.rs b/audio/audiofx/src/hrtfrender/imp.rs index f79472174..c78878d38 100644 --- a/audio/audiofx/src/hrtfrender/imp.rs +++ b/audio/audiofx/src/hrtfrender/imp.rs @@ -547,11 +547,9 @@ impl ElementImpl for HrtfRender { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", gst::IntRange::new(1, i32::MAX)) - .field("channels", 2i32) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .channels(2) + .format(gst_audio::AUDIO_FORMAT_F32) .build(); let src_pad_template = gst::PadTemplate::new( @@ -562,11 +560,9 @@ impl ElementImpl for HrtfRender { ) .unwrap(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", gst::IntRange::new(1, i32::MAX)) - .field("channels", gst::IntRange::new(1i32, 64)) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .channels_range(1..=64) + .format(gst_audio::AUDIO_FORMAT_F32) .build(); let sink_pad_template = gst::PadTemplate::new( diff --git a/audio/audiofx/tests/hrtfrender.rs b/audio/audiofx/tests/hrtfrender.rs index a84e64be9..1b0abd666 100644 --- a/audio/audiofx/tests/hrtfrender.rs +++ b/audio/audiofx/tests/hrtfrender.rs @@ -40,19 +40,17 @@ fn build_harness(src_caps: gst::Caps, sink_caps: gst::Caps) -> (gst_check::Harne fn test_hrtfrender_samples_in_samples_out() { init(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 1i32) + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(1) .field("channel-mask", gst::Bitmask::new(0x1)) - .field("layout", "interleaved") .build(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(2) .build(); let (mut h, _) = build_harness(src_caps, sink_caps); @@ -97,19 +95,17 @@ fn test_hrtfrender_samples_in_samples_out() { fn test_hrtfrender_implicit_spatial_objects() { init(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 8i32) + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(8) .field("channel-mask", gst::Bitmask::new(0xc3f)) - .field("layout", "interleaved") .build(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(2) .build(); let (mut h, hrtf) = build_harness(src_caps, sink_caps); @@ -124,18 +120,16 @@ fn test_hrtfrender_implicit_spatial_objects() { fn test_hrtfrender_explicit_spatial_objects() { init(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 8i32) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(8) .build(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(2) .build(); let (mut h, hrtf) = build_harness(src_caps, sink_caps); @@ -166,18 +160,16 @@ fn test_hrtfrender_explicit_spatial_objects() { fn test_hrtfrender_caps_negotiation_fail() { init(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 6i32) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(6) .build(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(2) .build(); let (mut h, hrtf) = build_harness(src_caps, sink_caps); @@ -213,18 +205,16 @@ fn test_hrtfrender_caps_negotiation_fail() { fn test_hrtfrender_multiple_instances_sharing_thread_pool() { init(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 1i32) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(1) .build(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(2) .build(); let (_, hrtf) = build_harness(src_caps.clone(), sink_caps.clone()); diff --git a/audio/claxon/tests/claxondec.rs b/audio/claxon/tests/claxondec.rs index 2974b6405..c9cfe7435 100644 --- a/audio/claxon/tests/claxondec.rs +++ b/audio/claxon/tests/claxondec.rs @@ -50,11 +50,10 @@ fn test_stereo_s32() { assert_eq!( caps, - gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_S2432.to_str()) - .field("rate", 44_100i32) - .field("channels", 2i32) - .field("layout", "interleaved") + gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_S2432) + .rate(44100) + .channels(2) .field("channel-mask", gst::Bitmask::new(0x3)) .build() ); diff --git a/audio/csound/tests/csound_filter.rs b/audio/csound/tests/csound_filter.rs index ed8b15987..6d3ee8961 100644 --- a/audio/csound/tests/csound_filter.rs +++ b/audio/csound/tests/csound_filter.rs @@ -91,11 +91,10 @@ fn csound_filter_eos() { let num_channels = 1; let sr: i32 = 44_100; - let caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", sr) - .field("channels", num_channels) - .field("layout", "interleaved") + let caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(sr) + .channels(num_channels) .build(); let mut h = build_harness( @@ -201,11 +200,10 @@ fn csound_filter_underflow() { let num_channels = 1; let sr: i32 = 44_100; - let caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", sr) - .field("channels", num_channels) - .field("layout", "interleaved") + let caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(sr) + .channels(num_channels) .build(); let mut h = build_harness( @@ -280,20 +278,18 @@ fn csound_filter_caps_negotiation() { let ochannels = 1; let sr: i32 = 44_100; - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", sr) - .field("channels", ichannels) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(sr) + .channels(ichannels) .build(); // Define the output caps which would be fixated // at the end of the caps negotiation - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", gst::IntRange::new(1i32, 48000)) - .field("channels", gst::IntRange::new(1i32, 2)) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate_range(1..=48000) + .channels_range(1..=2) .build(); // build the harness setting its src and sink caps, @@ -329,11 +325,10 @@ fn csound_filter_caps_negotiation() { .expect("pad has no caps"); // our expected caps at the harness sinkpad - let expected_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", 44_100i32) - .field("channels", ochannels) - .field("layout", "interleaved") + let expected_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(44_100) + .channels(ochannels) .build(); assert_eq!(harness_sink_caps, expected_caps); @@ -350,20 +345,18 @@ fn csound_filter_caps_negotiation_fail() { let ichannels = 2; let ochannels = 1; - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", 44_100i32) - .field("channels", ichannels) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(44_100) + .channels(ichannels) .build(); // instead of having a range for channels/rate fields // we fixate them to 2 and 48_000 respectively, which would cause the negotiation error - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F64.to_str()) - .field("rate", 48_000i32) - .field("channels", ichannels) - .field("layout", "interleaved") + let sink_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F64) + .rate(48_000) + .channels(ichannels) .build(); let mut h = build_harness( diff --git a/audio/lewton/src/lewtondec/imp.rs b/audio/lewton/src/lewtondec/imp.rs index 0a58c3596..6c76ddd55 100644 --- a/audio/lewton/src/lewtondec/imp.rs +++ b/audio/lewton/src/lewtondec/imp.rs @@ -81,11 +81,9 @@ impl ElementImpl for LewtonDec { ) .unwrap(); - let src_caps = gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", gst::IntRange::new(1, std::i32::MAX)) - .field("channels", gst::IntRange::new(1i32, 255)) - .field("layout", "interleaved") + let src_caps = gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .channels_range(1..=255) .build(); let src_pad_template = gst::PadTemplate::new( "src", diff --git a/audio/lewton/tests/lewtondec.rs b/audio/lewton/tests/lewtondec.rs index 814c2b950..1e8584725 100644 --- a/audio/lewton/tests/lewtondec.rs +++ b/audio/lewton/tests/lewtondec.rs @@ -93,11 +93,10 @@ fn run_test(inline_headers: bool) { .expect("pad has no caps"); assert_eq!( caps, - gst::Caps::builder("audio/x-raw") - .field("format", gst_audio::AUDIO_FORMAT_F32.to_str()) - .field("rate", 44_100i32) - .field("channels", 1i32) - .field("layout", "interleaved") + gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_F32) + .rate(44_100) + .channels(1) .build() ); } diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index e98a5a530..fac159d22 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -596,7 +596,7 @@ "long-name": "Transcriber", "pad-templates": { "sink": { - "caps": "audio/x-raw:\n format: S16LE\n rate: [ 8000, 48000 ]\n channels: 1\n", + "caps": "audio/x-raw:\n rate: [ 8000, 48000 ]\n channels: 1\n layout: { (string)interleaved, (string)non-interleaved }\n format: S16LE\n", "direction": "sink", "presence": "always" }, @@ -2303,7 +2303,7 @@ "presence": "always" }, "src": { - "caps": "audio/x-raw:\n format: F32LE\n rate: [ 1, 2147483647 ]\n channels: [ 1, 255 ]\n layout: interleaved\n", + "caps": "audio/x-raw:\n rate: [ 1, 2147483647 ]\n channels: [ 1, 255 ]\n layout: interleaved\n format: F32LE\n", "direction": "src", "presence": "always" } @@ -3452,12 +3452,12 @@ "long-name": "Head-Related Transfer Function (HRTF) renderer", "pad-templates": { "sink": { - "caps": "audio/x-raw:\n format: F32LE\n rate: [ 1, 2147483647 ]\n channels: [ 1, 64 ]\n layout: interleaved\n", + "caps": "audio/x-raw:\n rate: [ 1, 2147483647 ]\n channels: [ 1, 64 ]\n layout: interleaved\n format: F32LE\n", "direction": "sink", "presence": "always" }, "src": { - "caps": "audio/x-raw:\n format: F32LE\n rate: [ 1, 2147483647 ]\n channels: 2\n layout: interleaved\n", + "caps": "audio/x-raw:\n rate: [ 1, 2147483647 ]\n channels: 2\n layout: interleaved\n format: F32LE\n", "direction": "src", "presence": "always" } @@ -5343,7 +5343,7 @@ "presence": "always" }, "src": { - "caps": "video/x-raw:\n format: RGBA\n", + "caps": "video/x-raw:\n format: RGBA\n width: [ 1, 2147483647 ]\n height: [ 1, 2147483647 ]\n framerate: [ 0/1, 2147483647/1 ]\n", "direction": "src", "presence": "always" } diff --git a/generic/fmp4/examples/hls_live.rs b/generic/fmp4/examples/hls_live.rs index 4c8a19111..275ac08f8 100644 --- a/generic/fmp4/examples/hls_live.rs +++ b/generic/fmp4/examples/hls_live.rs @@ -426,11 +426,11 @@ impl VideoStream { raw_capsfilter.set_property( "caps", - gst::Caps::builder("video/x-raw") - .field("format", "I420") - .field("width", self.width) - .field("height", self.height) - .field("framerate", gst::Fraction::new(30, 1)) + gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::I420) + .width(self.width as i32) + .height(self.height as i32) + .framerate(gst::Fraction::new(30, 1)) .build(), ); diff --git a/generic/fmp4/examples/hls_vod.rs b/generic/fmp4/examples/hls_vod.rs index d90bc5f54..0a7aa720a 100644 --- a/generic/fmp4/examples/hls_vod.rs +++ b/generic/fmp4/examples/hls_vod.rs @@ -321,11 +321,11 @@ impl VideoStream { raw_capsfilter.set_property( "caps", - gst::Caps::builder("video/x-raw") - .field("format", "I420") - .field("width", self.width) - .field("height", self.height) - .field("framerate", gst::Fraction::new(30, 1)) + gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::I420) + .width(self.width as i32) + .height(self.height as i32) + .framerate(gst::Fraction::new(30, 1)) .build(), ); @@ -375,9 +375,7 @@ impl AudioStream { src.set_property_from_str("wave", &self.wave); raw_capsfilter.set_property( "caps", - gst::Caps::builder("audio/x-raw") - .field("rate", 44100) - .build(), + gst_audio::AudioCapsBuilder::new().rate(44100).build(), ); mux.set_property("fragment-duration", gst::ClockTime::from_mseconds(2500)); diff --git a/net/aws/Cargo.toml b/net/aws/Cargo.toml index 192713119..a094a7a11 100644 --- a/net/aws/Cargo.toml +++ b/net/aws/Cargo.toml @@ -15,6 +15,7 @@ bytes = "1.0" futures = "0.3" gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } +gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_16"] } aws-config = "0.49.0" aws-sdk-s3 = "0.19.0" aws-sdk-transcribe = "0.19.0" diff --git a/net/aws/src/aws_transcriber/imp.rs b/net/aws/src/aws_transcriber/imp.rs index c38d90975..247f78126 100644 --- a/net/aws/src/aws_transcriber/imp.rs +++ b/net/aws/src/aws_transcriber/imp.rs @@ -1349,10 +1349,10 @@ impl ElementImpl for Transcriber { ) .unwrap(); - let sink_caps = gst::Caps::builder("audio/x-raw") - .field("format", "S16LE") - .field("rate", gst::IntRange::new(8000i32, 48000)) - .field("channels", 1) + let sink_caps = gst_audio::AudioCapsBuilder::new() + .format(gst_audio::AudioFormat::S16le) + .rate_range(8000..=48000) + .channels(1) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", 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 diff --git a/utils/fallbackswitch/tests/fallbackswitch.rs b/utils/fallbackswitch/tests/fallbackswitch.rs index 356c6c8b9..34d36995c 100644 --- a/utils/fallbackswitch/tests/fallbackswitch.rs +++ b/utils/fallbackswitch/tests/fallbackswitch.rs @@ -530,11 +530,11 @@ fn setup_pipeline( src.set_property("min-latency", LATENCY.nseconds() as i64); src.set_property( "caps", - gst::Caps::builder("video/x-raw") - .field("format", "ARGB") - .field("width", 320i32) - .field("height", 240i32) - .field("framerate", gst::Fraction::new(0, 1)) + gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::Argb) + .width(320) + .height(240) + .framerate(gst::Fraction::new(0, 1)) .build(), ); @@ -575,11 +575,11 @@ fn setup_pipeline( fallback_src.set_property("min-latency", LATENCY.nseconds() as i64); fallback_src.set_property( "caps", - gst::Caps::builder("video/x-raw") - .field("format", "ARGB") - .field("width", 160i32) - .field("height", 120i32) - .field("framerate", gst::Fraction::new(0, 1)) + gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::Argb) + .width(160) + .height(120) + .framerate(gst::Fraction::new(0, 1)) .build(), ); diff --git a/utils/togglerecord/tests/tests.rs b/utils/togglerecord/tests/tests.rs index a0a7e03fa..1c70c573d 100644 --- a/utils/togglerecord/tests/tests.rs +++ b/utils/togglerecord/tests/tests.rs @@ -101,18 +101,17 @@ fn setup_sender_receiver( if first { assert!(sinkpad.send_event(gst::event::StreamStart::new("test"))); let caps = if main_stream { - gst::Caps::builder("video/x-raw") - .field("format", "ARGB") - .field("width", 320i32) - .field("height", 240i32) - .field("framerate", gst::Fraction::new(50, 1)) + gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::Argb) + .width(320) + .height(240) + .framerate(gst::Fraction::new(50, 1)) .build() } else { - gst::Caps::builder("audio/x-raw") - .field("format", "U8") - .field("layout", "interleaved") - .field("rate", 8000i32) - .field("channels", 1i32) + gst_audio::AudioCapsBuilder::new_interleaved() + .format(gst_audio::AUDIO_FORMAT_U8) + .rate(800) + .channels(1) .build() }; assert!(sinkpad.send_event(gst::event::Caps::new(&caps))); diff --git a/video/cdg/src/cdgdec/imp.rs b/video/cdg/src/cdgdec/imp.rs index 469c09767..6656bc531 100644 --- a/video/cdg/src/cdgdec/imp.rs +++ b/video/cdg/src/cdgdec/imp.rs @@ -66,11 +66,11 @@ impl ElementImpl for CdgDec { ) .unwrap(); - let src_caps = gst::Caps::builder("video/x-raw") - .field("format", gst_video::VideoFormat::Rgba.to_str()) - .field("width", CDG_WIDTH as i32) - .field("height", CDG_HEIGHT as i32) - .field("framerate", gst::Fraction::new(0, 1)) + let src_caps = gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::Rgba) + .width(CDG_WIDTH as i32) + .height(CDG_HEIGHT as i32) + .framerate(gst::Fraction::new(0, 1)) .build(); let src_pad_template = gst::PadTemplate::new( "src", diff --git a/video/gtk4/examples/gtksink.rs b/video/gtk4/examples/gtksink.rs index eba0c94dc..530b18123 100644 --- a/video/gtk4/examples/gtksink.rs +++ b/video/gtk4/examples/gtksink.rs @@ -18,9 +18,9 @@ fn create_ui(app: >k::Application) { pipeline.add_many(&[&src, &overlay, &sink]).unwrap(); src.link_filtered( &overlay, - &gst::Caps::builder("video/x-raw") - .field("width", 640) - .field("height", 480) + &gst_video::VideoCapsBuilder::new() + .width(640) + .height(480) .build(), ) .unwrap(); diff --git a/video/webp/src/dec/imp.rs b/video/webp/src/dec/imp.rs index e9f327d8d..277f5692e 100644 --- a/video/webp/src/dec/imp.rs +++ b/video/webp/src/dec/imp.rs @@ -343,8 +343,8 @@ impl ElementImpl for WebPDec { ) .unwrap(); - let caps = gst::Caps::builder("video/x-raw") - .field("format", "RGBA") + let caps = gst_video::VideoCapsBuilder::new() + .format(gst_video::VideoFormat::Rgba) .build(); let src_pad_template = gst::PadTemplate::new( |