From 6f51444c1f62eca912d5788e129a92d6c97378cd Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Fri, 14 Oct 2022 16:26:30 +0300 Subject: [PATCH] audio: Add channel_mask() and default_channel_mask() to AudioCapsBuilder Also use default_channel_mask() where applicable --- gstreamer-audio/src/audio_info.rs | 2 +- gstreamer-audio/src/caps.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index 2c407a88e..f29256d95 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -472,7 +472,7 @@ mod tests { .format(crate::AudioFormat::S16le) .rate(48000) .channels(2) - .field("channel-mask", gst::Bitmask::new(0x3)) + .fallback_channel_mask() .build(); let info = AudioInfo::from_caps(&caps).unwrap(); assert_eq!(info.format(), crate::AudioFormat::S16le); diff --git a/gstreamer-audio/src/caps.rs b/gstreamer-audio/src/caps.rs index 692d3015e..ea89603a1 100644 --- a/gstreamer-audio/src/caps.rs +++ b/gstreamer-audio/src/caps.rs @@ -113,6 +113,27 @@ impl AudioCapsBuilder { } } + pub fn channel_mask(self, channel_mask: u64) -> Self { + Self { + builder: self + .builder + .field("channel-mask", gst::Bitmask::new(channel_mask)), + } + } + + pub fn fallback_channel_mask(self) -> Self { + let channels = self.builder.structure().get::("channels"); + match channels { + Ok(channels) => Self { + builder: self.builder.field( + "channel-mask", + gst::Bitmask::new(crate::AudioChannelPosition::fallback_mask(channels as u32)), + ), + }, + Err(e) => panic!("{:?}", e), + } + } + pub fn field(self, name: &str, value: V) -> Self { Self { builder: self.builder.field(name, value),