video: Use gst_video::VideoCapsBuilder in some plugins

Simplify caps creation codes
This commit is contained in:
Vivia Nikolaidou 2022-07-22 14:07:49 +03:00
parent fb7929dda6
commit 247702b76d
9 changed files with 72 additions and 197 deletions

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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()));
}
};

View file

@ -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(

View file

@ -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",

View file

@ -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",

View file

@ -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",

View file

@ -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",