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.
This commit is contained in:
lummax 2015-09-11 14:36:15 +02:00 committed by meh
parent 402657cbfb
commit c8a38a926f

View File

@ -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 {