1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef API_AUDIO_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_CONFIG_H_ 12 #define API_AUDIO_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_CONFIG_H_ 13 14 #include <vector> 15 16 #include "api/audio_codecs/audio_decoder.h" 17 18 namespace webrtc { 19 struct AudioDecoderMultiChannelOpusConfig { 20 // The number of channels that the decoder will output. 21 int num_channels; 22 23 // Number of mono or stereo encoded Opus streams. 24 int num_streams; 25 26 // Number of channel pairs coupled together, see RFC 7845 section 27 // 5.1.1. Has to be less than the number of streams. 28 int coupled_streams; 29 30 // Channel mapping table, defines the mapping from encoded streams to output 31 // channels. See RFC 7845 section 5.1.1. 32 std::vector<unsigned char> channel_mapping; 33 IsOkAudioDecoderMultiChannelOpusConfig34 bool IsOk() const { 35 if (num_channels < 1 || num_channels > AudioDecoder::kMaxNumberOfChannels || 36 num_streams < 0 || coupled_streams < 0) { 37 return false; 38 } 39 if (num_streams < coupled_streams) { 40 return false; 41 } 42 if (channel_mapping.size() != static_cast<size_t>(num_channels)) { 43 return false; 44 } 45 46 // Every mono stream codes one channel, every coupled stream codes two. This 47 // is the total coded channel count: 48 const int max_coded_channel = num_streams + coupled_streams; 49 for (const auto& x : channel_mapping) { 50 // Coded channels >= max_coded_channel don't exist. Except for 255, which 51 // tells Opus to put silence in output channel x. 52 if (x >= max_coded_channel && x != 255) { 53 return false; 54 } 55 } 56 57 if (num_channels > 255 || max_coded_channel >= 255) { 58 return false; 59 } 60 return true; 61 } 62 }; 63 64 } // namespace webrtc 65 66 #endif // API_AUDIO_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_CONFIG_H_ 67