diff options
author | Vivia Nikolaidou <vivia@ahiru.eu> | 2022-07-22 14:07:49 +0300 |
---|---|---|
committer | Vivia Nikolaidou <vivia@ahiru.eu> | 2022-08-09 22:01:10 +0300 |
commit | 247702b76d645c1ccdebe5727b31d461ec7bd598 (patch) | |
tree | 38efed0c404cc2d61d972e7b6a17f451ae56b16a /video | |
parent | fb7929dda68bcf091811750eebe26a8ff1c10c0d (diff) |
video: Use gst_video::VideoCapsBuilder in some plugins
Simplify caps creation codes
Diffstat (limited to 'video')
-rw-r--r-- | video/dav1d/src/dav1ddec/imp.rs | 20 | ||||
-rw-r--r-- | video/ffv1/src/ffv1dec/imp.rs | 22 | ||||
-rw-r--r-- | video/gif/src/gifenc/imp.rs | 23 | ||||
-rw-r--r-- | video/hsv/src/hsvdetector/imp.rs | 45 | ||||
-rw-r--r-- | video/hsv/src/hsvfilter/imp.rs | 39 | ||||
-rw-r--r-- | video/rav1e/src/rav1enc/imp.rs | 38 | ||||
-rw-r--r-- | video/rspng/src/pngenc/imp.rs | 26 | ||||
-rw-r--r-- | video/videofx/src/border/roundedcorners.rs | 29 | ||||
-rw-r--r-- | video/videofx/src/colordetect/imp.rs | 27 |
9 files changed, 72 insertions, 197 deletions
diff --git a/video/dav1d/src/dav1ddec/imp.rs b/video/dav1d/src/dav1ddec/imp.rs index d80e207d5..11309ed2a 100644 --- a/video/dav1d/src/dav1ddec/imp.rs +++ b/video/dav1d/src/dav1ddec/imp.rs @@ -446,8 +446,8 @@ impl Dav1dDec { } } -fn video_output_formats() -> Vec<glib::SendValue> { - let values = [ +fn video_output_formats() -> impl IntoIterator<Item = gst_video::VideoFormat> { + [ gst_video::VideoFormat::Gray8, #[cfg(target_endian = "little")] gst_video::VideoFormat::Gray16Le, @@ -482,8 +482,7 @@ fn video_output_formats() -> Vec<glib::SendValue> { gst_video::VideoFormat::I42212be, #[cfg(target_endian = "big")] gst_video::VideoFormat::Y44412be, - ]; - values.iter().map(|i| i.to_str().to_send_value()).collect() + ] } #[glib::object_subclass] @@ -586,17 +585,8 @@ impl ElementImpl for Dav1dDec { ) .unwrap(); - let src_caps = gst::Caps::builder("video/x-raw") - .field("format", gst::List::from(video_output_formats())) - .field("width", gst::IntRange::new(1, i32::MAX)) - .field("height", gst::IntRange::new(1, i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(0, 1), - gst::Fraction::new(i32::MAX, 1), - ), - ) + let src_caps = gst_video::VideoCapsBuilder::new() + .format_list(video_output_formats()) .build(); let src_pad_template = gst::PadTemplate::new( "src", diff --git a/video/ffv1/src/ffv1dec/imp.rs b/video/ffv1/src/ffv1dec/imp.rs index 9fdcbaaa6..6d6372fe0 100644 --- a/video/ffv1/src/ffv1dec/imp.rs +++ b/video/ffv1/src/ffv1dec/imp.rs @@ -13,7 +13,6 @@ use ffv1::decoder::{Decoder, Frame}; use ffv1::record::ConfigRecord; use gst::glib; -use gst::prelude::*; use gst::subclass::prelude::*; use gst_video::prelude::*; use gst_video::subclass::prelude::*; @@ -42,8 +41,8 @@ pub struct Ffv1Dec { state: Mutex<DecoderState>, } -fn get_all_video_formats() -> Vec<glib::SendValue> { - let values = [ +fn get_all_video_formats() -> impl IntoIterator<Item = gst_video::VideoFormat> { + [ VideoFormat::Gray8, VideoFormat::Gray16Le, VideoFormat::Gray16Be, @@ -81,9 +80,7 @@ fn get_all_video_formats() -> Vec<glib::SendValue> { VideoFormat::Gbra12be, VideoFormat::Y41b, VideoFormat::Yuv9, - ]; - - values.iter().map(|i| i.to_str().to_send_value()).collect() + ] } fn get_output_format(record: &ConfigRecord) -> Option<VideoFormat> { @@ -339,17 +336,8 @@ impl ElementImpl for Ffv1Dec { ) .unwrap(); - let src_caps = gst::Caps::builder("video/x-raw") - .field("format", gst::List::from(get_all_video_formats())) - .field("width", gst::IntRange::new(1, i32::MAX)) - .field("height", gst::IntRange::new(1, i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(0, 1), - gst::Fraction::new(i32::MAX, 1), - ), - ) + let src_caps = gst_video::VideoCapsBuilder::new() + .format_list(get_all_video_formats()) .build(); let src_pad_template = gst::PadTemplate::new( "src", diff --git a/video/gif/src/gifenc/imp.rs b/video/gif/src/gifenc/imp.rs index 80bcfa26c..8d84424a4 100644 --- a/video/gif/src/gifenc/imp.rs +++ b/video/gif/src/gifenc/imp.rs @@ -13,6 +13,7 @@ use gst::glib; use gst::subclass::prelude::*; use gst_video::prelude::*; use gst_video::subclass::prelude::*; +use gst_video::VideoFormat; use once_cell::sync::Lazy; use std::{ io, @@ -222,24 +223,10 @@ impl ElementImpl for GifEnc { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let sink_caps = gst::Caps::builder("video/x-raw") - .field( - "format", - gst::List::new([ - gst_video::VideoFormat::Rgb.to_str(), - gst_video::VideoFormat::Rgba.to_str(), - ]), - ) - .field("width", gst::IntRange::new(1, std::u16::MAX as i32)) - .field("height", gst::IntRange::new(1, std::u16::MAX as i32)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(1, 1), - // frame-delay timing in gif is a multiple of 10ms -> max 100fps - gst::Fraction::new(100, 1), - ), - ) + let sink_caps = gst_video::VideoCapsBuilder::new() + .format_list([VideoFormat::Rgb, VideoFormat::Rgba]) + // frame-delay timing in gif is a multiple of 10ms -> max 100fps + .framerate_range(gst::Fraction::new(1, 1)..gst::Fraction::new(100, 1)) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", diff --git a/video/hsv/src/hsvdetector/imp.rs b/video/hsv/src/hsvdetector/imp.rs index 03f3b17de..6ebb4f4e0 100644 --- a/video/hsv/src/hsvdetector/imp.rs +++ b/video/hsv/src/hsvdetector/imp.rs @@ -15,7 +15,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; @@ -75,26 +74,24 @@ impl ObjectSubclass for HsvDetector { type ParentType = gst_video::VideoFilter; } -fn video_input_formats() -> Vec<glib::SendValue> { - let values = [ +fn video_input_formats() -> impl IntoIterator<Item = gst_video::VideoFormat> { + [ gst_video::VideoFormat::Rgbx, gst_video::VideoFormat::Xrgb, gst_video::VideoFormat::Bgrx, gst_video::VideoFormat::Xbgr, gst_video::VideoFormat::Rgb, gst_video::VideoFormat::Bgr, - ]; - values.iter().map(|i| i.to_str().to_send_value()).collect() + ] } -fn video_output_formats() -> Vec<glib::SendValue> { - let values = [ +fn video_output_formats() -> impl IntoIterator<Item = gst_video::VideoFormat> { + [ gst_video::VideoFormat::Rgba, gst_video::VideoFormat::Argb, gst_video::VideoFormat::Bgra, gst_video::VideoFormat::Abgr, - ]; - values.iter().map(|i| i.to_str().to_send_value()).collect() + ] } impl HsvDetector { @@ -361,17 +358,8 @@ impl ElementImpl for HsvDetector { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let caps = gst::Caps::builder("video/x-raw") - .field("format", gst::List::from(video_output_formats())) - .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(video_output_formats()) .build(); let src_pad_template = gst::PadTemplate::new( @@ -383,17 +371,8 @@ impl ElementImpl for HsvDetector { .unwrap(); // sink pad capabilities - let caps = gst::Caps::builder("video/x-raw") - .field("format", gst::List::from(video_input_formats())) - .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(video_input_formats()) .build(); let sink_pad_template = gst::PadTemplate::new( @@ -427,11 +406,11 @@ impl BaseTransformImpl for HsvDetector { let mut other_caps = caps.clone(); if direction == gst::PadDirection::Src { for s in other_caps.make_mut().iter_mut() { - s.set("format", gst::List::from(video_input_formats())); + s.set("format", gst::List::new(video_input_formats())); } } else { for s in other_caps.make_mut().iter_mut() { - s.set("format", gst::List::from(video_output_formats())); + s.set("format", gst::List::new(video_output_formats())); } }; diff --git a/video/hsv/src/hsvfilter/imp.rs b/video/hsv/src/hsvfilter/imp.rs index c0a8228f6..416aca4cd 100644 --- a/video/hsv/src/hsvfilter/imp.rs +++ b/video/hsv/src/hsvfilter/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; @@ -295,31 +294,19 @@ impl ElementImpl for HsvFilter { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { // src pad capabilities - let caps = gst::Caps::builder("video/x-raw") - .field( - "format", - gst::List::new([ - gst_video::VideoFormat::Rgbx.to_str(), - gst_video::VideoFormat::Xrgb.to_str(), - gst_video::VideoFormat::Bgrx.to_str(), - gst_video::VideoFormat::Xbgr.to_str(), - gst_video::VideoFormat::Rgba.to_str(), - gst_video::VideoFormat::Argb.to_str(), - gst_video::VideoFormat::Bgra.to_str(), - gst_video::VideoFormat::Abgr.to_str(), - gst_video::VideoFormat::Rgb.to_str(), - gst_video::VideoFormat::Bgr.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::Rgbx, + gst_video::VideoFormat::Xrgb, + gst_video::VideoFormat::Bgrx, + gst_video::VideoFormat::Xbgr, + gst_video::VideoFormat::Rgba, + gst_video::VideoFormat::Argb, + gst_video::VideoFormat::Bgra, + gst_video::VideoFormat::Abgr, + gst_video::VideoFormat::Rgb, + gst_video::VideoFormat::Bgr, + ]) .build(); let src_pad_template = gst::PadTemplate::new( diff --git a/video/rav1e/src/rav1enc/imp.rs b/video/rav1e/src/rav1enc/imp.rs index 429e7e20e..d748b3446 100644 --- a/video/rav1e/src/rav1enc/imp.rs +++ b/video/rav1e/src/rav1enc/imp.rs @@ -553,31 +553,19 @@ impl ElementImpl for Rav1Enc { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let sink_caps = gst::Caps::builder("video/x-raw") - .field( - "format", - gst::List::new([ - gst_video::VideoFormat::I420.to_str(), - gst_video::VideoFormat::Y42b.to_str(), - gst_video::VideoFormat::Y444.to_str(), - gst_video::VideoFormat::I42010le.to_str(), - gst_video::VideoFormat::I42210le.to_str(), - gst_video::VideoFormat::Y44410le.to_str(), - gst_video::VideoFormat::I42012le.to_str(), - gst_video::VideoFormat::I42212le.to_str(), - gst_video::VideoFormat::Y44412le.to_str(), - gst_video::VideoFormat::Gray8.to_str(), - ]), - ) - .field("width", gst::IntRange::new(1, std::i32::MAX)) - .field("height", gst::IntRange::new(1, std::i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(0, 1), - gst::Fraction::new(std::i32::MAX, 1), - ), - ) + let sink_caps = gst_video::VideoCapsBuilder::new() + .format_list([ + gst_video::VideoFormat::I420, + gst_video::VideoFormat::Y42b, + gst_video::VideoFormat::Y444, + gst_video::VideoFormat::I42010le, + gst_video::VideoFormat::I42210le, + gst_video::VideoFormat::Y44410le, + gst_video::VideoFormat::I42012le, + gst_video::VideoFormat::I42212le, + gst_video::VideoFormat::Y44412le, + gst_video::VideoFormat::Gray8, + ]) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", diff --git a/video/rspng/src/pngenc/imp.rs b/video/rspng/src/pngenc/imp.rs index 8d00bcf3c..aa58929ef 100644 --- a/video/rspng/src/pngenc/imp.rs +++ b/video/rspng/src/pngenc/imp.rs @@ -253,25 +253,13 @@ impl ElementImpl for PngEncoder { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let sink_caps = gst::Caps::builder("video/x-raw") - .field( - "format", - gst::List::new([ - gst_video::VideoFormat::Gray8.to_str(), - gst_video::VideoFormat::Gray16Be.to_str(), - gst_video::VideoFormat::Rgb.to_str(), - gst_video::VideoFormat::Rgba.to_str(), - ]), - ) - .field("width", gst::IntRange::new(1, std::i32::MAX)) - .field("height", gst::IntRange::new(1, std::i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(1, 1), - gst::Fraction::new(std::i32::MAX, 1), - ), - ) + let sink_caps = gst_video::VideoCapsBuilder::new() + .format_list([ + gst_video::VideoFormat::Gray8, + gst_video::VideoFormat::Gray16Be, + gst_video::VideoFormat::Rgb, + gst_video::VideoFormat::Rgba, + ]) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", diff --git a/video/videofx/src/border/roundedcorners.rs b/video/videofx/src/border/roundedcorners.rs index 1051e73b6..c5b34a6be 100644 --- a/video/videofx/src/border/roundedcorners.rs +++ b/video/videofx/src/border/roundedcorners.rs @@ -349,17 +349,8 @@ impl ElementImpl for RoundedCorners { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let sink_caps = gst::Caps::builder("video/x-raw") - .field("format", VideoFormat::I420.to_str()) - .field("width", gst::IntRange::new(1, i32::MAX)) - .field("height", gst::IntRange::new(1, i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(0, 1), - gst::Fraction::new(i32::MAX, 1), - ), - ) + let sink_caps = gst_video::VideoCapsBuilder::new() + .format(VideoFormat::I420) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", @@ -369,20 +360,8 @@ impl ElementImpl for RoundedCorners { ) .unwrap(); - let src_caps = gst::Caps::builder("video/x-raw") - .field( - "format", - gst::List::new([VideoFormat::A420.to_str(), VideoFormat::I420.to_str()]), - ) - .field("width", gst::IntRange::new(1, i32::MAX)) - .field("height", gst::IntRange::new(1, i32::MAX)) - .field( - "framerate", - gst::FractionRange::new( - gst::Fraction::new(0, 1), - gst::Fraction::new(i32::MAX, 1), - ), - ) + let src_caps = gst_video::VideoCapsBuilder::new() + .format_list([VideoFormat::I420, VideoFormat::A420]) .build(); let src_pad_template = gst::PadTemplate::new( "src", diff --git a/video/videofx/src/colordetect/imp.rs b/video/videofx/src/colordetect/imp.rs index ebb87751b..6e48a0e4a 100644 --- a/video/videofx/src/colordetect/imp.rs +++ b/video/videofx/src/colordetect/imp.rs @@ -233,25 +233,14 @@ impl ElementImpl for ColorDetect { fn pad_templates() -> &'static [gst::PadTemplate] { static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| { - let formats = gst::List::new([ - VideoFormat::Rgb.to_str(), - VideoFormat::Rgba.to_str(), - VideoFormat::Argb.to_str(), - VideoFormat::Bgr.to_str(), - VideoFormat::Bgra.to_str(), - ]); - - let caps = gst::Caps::builder("video/x-raw") - .field("format", &formats) - .field("width", gst::IntRange::new(1, i32::MAX)) - .field("height", gst::IntRange::new(1, 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([ + VideoFormat::Rgb, + VideoFormat::Rgba, + VideoFormat::Argb, + VideoFormat::Bgr, + VideoFormat::Bgra, + ]) .build(); let sink_pad_template = gst::PadTemplate::new( "sink", |