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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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