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),