audio: Use gst_audio::AudioCapsBuilder in some plugins

Simplify caps creation codes
This commit is contained in:
Vivia Nikolaidou 2022-08-09 14:18:12 +03:00
parent 247702b76d
commit 8ee8ae581a
9 changed files with 54 additions and 64 deletions

View file

@ -12,7 +12,7 @@ use gst::subclass::prelude::*;
use gst_base::subclass::prelude::*;
use std::sync::Mutex;
use std::{cmp, i32, u64};
use std::{cmp, u64};
use byte_slice_cast::*;
@ -209,17 +209,9 @@ impl ElementImpl for AudioEcho {
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
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("rate", gst::IntRange::new(0, i32::MAX))
.field("channels", gst::IntRange::new(0, i32::MAX))
.field("layout", "interleaved")
let caps = gst_audio::AudioCapsBuilder::new()
.format_list([gst_audio::AUDIO_FORMAT_F32, gst_audio::AUDIO_FORMAT_F64])
.layout(gst_audio::AudioLayout::Interleaved)
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -1880,11 +1880,10 @@ impl ElementImpl for AudioLoudNorm {
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
let caps = gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_F64.to_str())
.field("rate", 192_000i32)
.field("channels", gst::IntRange::new(1, std::i32::MAX))
.field("layout", "interleaved")
let caps = gst_audio::AudioCapsBuilder::new()
.format(gst_audio::AUDIO_FORMAT_F64)
.rate(192_000)
.layout(gst_audio::AudioLayout::Interleaved)
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -224,11 +224,10 @@ impl ElementImpl for AudioRNNoise {
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
let caps = gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_F32.to_str())
.field("rate", 48000)
.field("channels", gst::IntRange::new(1, std::i32::MAX))
.field("layout", "interleaved")
let caps = gst_audio::AudioCapsBuilder::new()
.format(gst_audio::AUDIO_FORMAT_F32)
.rate(48000)
.layout(gst_audio::AudioLayout::Interleaved)
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -250,21 +250,21 @@ impl ElementImpl for EbuR128Level {
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
let caps = gst::Caps::builder("audio/x-raw")
.field(
"format",
gst::List::new([
gst_audio::AUDIO_FORMAT_S16.to_str(),
gst_audio::AUDIO_FORMAT_S32.to_str(),
gst_audio::AUDIO_FORMAT_F32.to_str(),
gst_audio::AUDIO_FORMAT_F64.to_str(),
]),
)
.field("layout", gst::List::new(["interleaved", "non-interleaved"]))
let caps = gst_audio::AudioCapsBuilder::new()
.format_list([
gst_audio::AUDIO_FORMAT_S16,
gst_audio::AUDIO_FORMAT_S32,
gst_audio::AUDIO_FORMAT_F32,
gst_audio::AUDIO_FORMAT_F64,
])
// Limit from ebur128
.field("rate", gst::IntRange::new(1i32, 2_822_400))
.rate_range(1..2_822_400)
// Limit from ebur128
.field("channels", gst::IntRange::new(1i32, 64))
.channels_range(1..64)
.layout_list([
gst_audio::AudioLayout::Interleaved,
gst_audio::AudioLayout::NonInterleaved,
])
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -76,19 +76,16 @@ impl ElementImpl for ClaxonDec {
)
.unwrap();
let src_caps = gst::Caps::builder("audio/x-raw")
.field(
"format",
gst::List::new([
gst_audio::AudioFormat::S8.to_str(),
gst_audio::AUDIO_FORMAT_S16.to_str(),
gst_audio::AUDIO_FORMAT_S2432.to_str(),
gst_audio::AUDIO_FORMAT_S32.to_str(),
]),
)
.field("rate", gst::IntRange::new(1i32, 655_350))
.field("channels", gst::IntRange::new(1i32, 8))
.field("layout", "interleaved")
let src_caps = gst_audio::AudioCapsBuilder::new()
.format_list([
gst_audio::AudioFormat::S8,
gst_audio::AUDIO_FORMAT_S16,
gst_audio::AUDIO_FORMAT_S2432,
gst_audio::AUDIO_FORMAT_S32,
])
.rate_range(1..655_350)
.channels_range(1..8)
.layout(gst_audio::AudioLayout::Interleaved)
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -31,11 +31,11 @@ fn test_mono_s16() {
assert_eq!(
caps,
gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_S16.to_str())
.field("rate", 44_100i32)
.field("channels", 1i32)
.field("layout", "interleaved")
gst_audio::AudioCapsBuilder::new()
.layout(gst_audio::AudioLayout::Interleaved)
.format(gst_audio::AUDIO_FORMAT_S16)
.rate(44_100)
.channels(1)
.build()
);
}

View file

@ -453,11 +453,9 @@ impl ElementImpl for CsoundFilter {
fn pad_templates() -> &'static [gst::PadTemplate] {
static PAD_TEMPLATES: Lazy<Vec<gst::PadTemplate>> = Lazy::new(|| {
let caps = gst::Caps::builder("audio/x-raw")
.field("format", gst_audio::AUDIO_FORMAT_F64.to_str())
.field("rate", gst::IntRange::new(1, i32::MAX))
.field("channels", gst::IntRange::new(1, i32::MAX))
.field("layout", "interleaved")
let caps = gst_audio::AudioCapsBuilder::new()
.format(gst_audio::AUDIO_FORMAT_F64)
.layout(gst_audio::AudioLayout::Interleaved)
.build();
let src_pad_template = gst::PadTemplate::new(
"src",

View file

@ -11,6 +11,7 @@ description = "Rust FLV Plugin"
[dependencies]
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" }
num-rational = { version = "0.4", default-features = false, features = [] }
nom = "7"
flavors = { git = "https://github.com/rust-av/flavors" }

View file

@ -215,9 +215,9 @@ impl ElementImpl for FlvDemux {
.build(),
);
caps.append(
gst::Caps::builder("audio/x-raw")
.field("layout", "interleaved")
.field("format", gst::List::new(["U8", "S16LE"]))
gst_audio::AudioCapsBuilder::new()
.layout(gst_audio::AudioLayout::Interleaved)
.format_list([gst_audio::AudioFormat::U8, gst_audio::AudioFormat::S16le])
.build(),
);
caps.append(
@ -1280,9 +1280,13 @@ impl AudioFormat {
// Assume little-endian for "PCM_NE", it's probably more common and we have no
// way to know what the endianness of the system creating the stream was
Some(
gst::Caps::builder("audio/x-raw")
.field("layout", "interleaved")
.field("format", if self.width == 8 { "U8" } else { "S16LE" })
gst_audio::AudioCapsBuilder::new()
.layout(gst_audio::AudioLayout::Interleaved)
.format(if self.width == 8 {
gst_audio::AudioFormat::U8
} else {
gst_audio::AudioFormat::S16le
})
.build(),
)
} else {