• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace webrtc {
17 struct AudioDecoderMultiChannelOpusConfig {
18   // The number of channels that the decoder will output.
19   int num_channels;
20 
21   // Number of mono or stereo encoded Opus streams.
22   int num_streams;
23 
24   // Number of channel pairs coupled together, see RFC 7845 section
25   // 5.1.1. Has to be less than the number of streams.
26   int coupled_streams;
27 
28   // Channel mapping table, defines the mapping from encoded streams to output
29   // channels. See RFC 7845 section 5.1.1.
30   std::vector<unsigned char> channel_mapping;
31 
IsOkAudioDecoderMultiChannelOpusConfig32   bool IsOk() const {
33     if (num_channels < 0 || num_streams < 0 || coupled_streams < 0) {
34       return false;
35     }
36     if (num_streams < coupled_streams) {
37       return false;
38     }
39     if (channel_mapping.size() != static_cast<size_t>(num_channels)) {
40       return false;
41     }
42 
43     // Every mono stream codes one channel, every coupled stream codes two. This
44     // is the total coded channel count:
45     const int max_coded_channel = num_streams + coupled_streams;
46     for (const auto& x : channel_mapping) {
47       // Coded channels >= max_coded_channel don't exist. Except for 255, which
48       // tells Opus to put silence in output channel x.
49       if (x >= max_coded_channel && x != 255) {
50         return false;
51       }
52     }
53 
54     if (num_channels > 255 || max_coded_channel >= 255) {
55       return false;
56     }
57     return true;
58   }
59 };
60 
61 }  // namespace webrtc
62 
63 #endif  //  API_AUDIO_CODECS_OPUS_AUDIO_DECODER_MULTI_CHANNEL_OPUS_CONFIG_H_
64