From c8a38a926f4111573615c868238538d00592b30f Mon Sep 17 00:00:00 2001 From: lummax Date: Fri, 11 Sep 2015 14:36:15 +0200 Subject: [PATCH] codec/audio: implement `ChannelLayoutIter.best()` Is some cases the decoder channel layout is not supported by the selected encoder. A selection from the channel layouts supported by the encoder is needed. For this the method `best()` is introduced. --- src/codec/audio.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/codec/audio.rs b/src/codec/audio.rs index a32aef1..6128396 100644 --- a/src/codec/audio.rs +++ b/src/codec/audio.rs @@ -121,6 +121,16 @@ impl ChannelLayoutIter { pub fn new(ptr: *const u64) -> Self { ChannelLayoutIter { ptr: ptr } } + + pub fn best(self, max: i32) -> ChannelLayout { + self.fold(::channel_layout::MONO, |acc, cur| + if cur.channels() > cur.channels() && cur.channels() <= max { + cur + } + else { + acc + }) + } } impl Iterator for ChannelLayoutIter {