audio: Add channel_mask() and default_channel_mask() to AudioCapsBuilder

Also use default_channel_mask() where applicable
This commit is contained in:
Vivia Nikolaidou 2022-10-14 16:26:30 +03:00
parent b230d8aab6
commit 6f51444c1f
2 changed files with 22 additions and 1 deletions

View file

@ -472,7 +472,7 @@ mod tests {
.format(crate::AudioFormat::S16le) .format(crate::AudioFormat::S16le)
.rate(48000) .rate(48000)
.channels(2) .channels(2)
.field("channel-mask", gst::Bitmask::new(0x3)) .fallback_channel_mask()
.build(); .build();
let info = AudioInfo::from_caps(&caps).unwrap(); let info = AudioInfo::from_caps(&caps).unwrap();
assert_eq!(info.format(), crate::AudioFormat::S16le); assert_eq!(info.format(), crate::AudioFormat::S16le);

View file

@ -113,6 +113,27 @@ impl<T> AudioCapsBuilder<T> {
} }
} }
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::<i32>("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<V: ToSendValue + Sync>(self, name: &str, value: V) -> Self { pub fn field<V: ToSendValue + Sync>(self, name: &str, value: V) -> Self {
Self { Self {
builder: self.builder.field(name, value), builder: self.builder.field(name, value),