Set the maximum number of audio channels to 24 The number of audio channels can be configured in SDP, and can thus be set to arbitrary values. However, the audio code has limitations that prevent a high number of channels from working well in practice. Bug: chromium:1265806 Change-Id: I6f6c3f68a3791bb189a614eece6bd0ed7874f252 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237807 Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Ivo Creusen <ivoc@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35359}
diff --git a/api/audio_codecs/L16/audio_decoder_L16.h b/api/audio_codecs/L16/audio_decoder_L16.h index f0be036..581a5b8 100644 --- a/api/audio_codecs/L16/audio_decoder_L16.h +++ b/api/audio_codecs/L16/audio_decoder_L16.h
@@ -29,7 +29,8 @@ bool IsOk() const { return (sample_rate_hz == 8000 || sample_rate_hz == 16000 || sample_rate_hz == 32000 || sample_rate_hz == 48000) && - num_channels >= 1; + (num_channels >= 1 && + num_channels <= AudioDecoder::kMaxNumberOfChannels); } int sample_rate_hz = 8000; int num_channels = 1;
diff --git a/api/audio_codecs/L16/audio_encoder_L16.h b/api/audio_codecs/L16/audio_encoder_L16.h index b410286..25d2211 100644 --- a/api/audio_codecs/L16/audio_encoder_L16.h +++ b/api/audio_codecs/L16/audio_encoder_L16.h
@@ -29,7 +29,9 @@ bool IsOk() const { return (sample_rate_hz == 8000 || sample_rate_hz == 16000 || sample_rate_hz == 32000 || sample_rate_hz == 48000) && - num_channels >= 1 && frame_size_ms > 0 && frame_size_ms <= 120 && + num_channels >= 1 && + num_channels <= AudioEncoder::kMaxNumberOfChannels && + frame_size_ms > 0 && frame_size_ms <= 120 && frame_size_ms % 10 == 0; } int sample_rate_hz = 8000;
diff --git a/api/audio_codecs/audio_decoder.cc b/api/audio_codecs/audio_decoder.cc index d5c1cfe..28f5b8a 100644 --- a/api/audio_codecs/audio_decoder.cc +++ b/api/audio_codecs/audio_decoder.cc
@@ -166,4 +166,5 @@ } } +constexpr int AudioDecoder::kMaxNumberOfChannels; } // namespace webrtc
diff --git a/api/audio_codecs/audio_decoder.h b/api/audio_codecs/audio_decoder.h index 51d20c4..336e384 100644 --- a/api/audio_codecs/audio_decoder.h +++ b/api/audio_codecs/audio_decoder.h
@@ -170,6 +170,9 @@ // during the lifetime of the decoder. virtual size_t Channels() const = 0; + // The maximum number of audio channels supported by WebRTC decoders. + static constexpr int kMaxNumberOfChannels = 24; + protected: static SpeechType ConvertSpeechType(int16_t type);
diff --git a/api/audio_codecs/audio_encoder.cc b/api/audio_codecs/audio_encoder.cc index 81cfbe3..31bb873 100644 --- a/api/audio_codecs/audio_encoder.cc +++ b/api/audio_codecs/audio_encoder.cc
@@ -110,4 +110,5 @@ return ANAStats(); } +constexpr int AudioEncoder::kMaxNumberOfChannels; } // namespace webrtc
diff --git a/api/audio_codecs/audio_encoder.h b/api/audio_codecs/audio_encoder.h index 047d23c..7f5a342 100644 --- a/api/audio_codecs/audio_encoder.h +++ b/api/audio_codecs/audio_encoder.h
@@ -246,6 +246,9 @@ virtual absl::optional<std::pair<TimeDelta, TimeDelta>> GetFrameLengthRange() const = 0; + // The maximum number of audio channels supported by WebRTC encoders. + static constexpr int kMaxNumberOfChannels = 24; + protected: // Subclasses implement this to perform the actual encoding. Called by // Encode().
diff --git a/api/audio_codecs/g711/audio_decoder_g711.h b/api/audio_codecs/g711/audio_decoder_g711.h index ccd1ee0..18c15a8 100644 --- a/api/audio_codecs/g711/audio_decoder_g711.h +++ b/api/audio_codecs/g711/audio_decoder_g711.h
@@ -28,7 +28,9 @@ struct Config { enum class Type { kPcmU, kPcmA }; bool IsOk() const { - return (type == Type::kPcmU || type == Type::kPcmA) && num_channels >= 1; + return (type == Type::kPcmU || type == Type::kPcmA) && + num_channels >= 1 && + num_channels <= AudioDecoder::kMaxNumberOfChannels; } Type type; int num_channels;
diff --git a/api/audio_codecs/g711/audio_encoder_g711.h b/api/audio_codecs/g711/audio_encoder_g711.h index 23ae18b..29fe38f 100644 --- a/api/audio_codecs/g711/audio_encoder_g711.h +++ b/api/audio_codecs/g711/audio_encoder_g711.h
@@ -29,7 +29,9 @@ enum class Type { kPcmU, kPcmA }; bool IsOk() const { return (type == Type::kPcmU || type == Type::kPcmA) && - frame_size_ms > 0 && frame_size_ms % 10 == 0 && num_channels >= 1; + frame_size_ms > 0 && frame_size_ms % 10 == 0 && + num_channels >= 1 && + num_channels <= AudioEncoder::kMaxNumberOfChannels; } Type type = Type::kPcmU; int num_channels = 1;
diff --git a/api/audio_codecs/g722/audio_encoder_g722_config.h b/api/audio_codecs/g722/audio_encoder_g722_config.h index 2878985..f85eef0 100644 --- a/api/audio_codecs/g722/audio_encoder_g722_config.h +++ b/api/audio_codecs/g722/audio_encoder_g722_config.h
@@ -15,7 +15,8 @@ struct AudioEncoderG722Config { bool IsOk() const { - return frame_size_ms > 0 && frame_size_ms % 10 == 0 && num_channels >= 1; + return frame_size_ms > 0 && frame_size_ms % 10 == 0 && num_channels >= 1 && + num_channels <= AudioEncoder::kMaxNumberOfChannels; } int frame_size_ms = 20; int num_channels = 1;
diff --git a/api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h b/api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h index 30bc76e..7350045 100644 --- a/api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h +++ b/api/audio_codecs/opus/audio_decoder_multi_channel_opus_config.h
@@ -30,7 +30,8 @@ std::vector<unsigned char> channel_mapping; bool IsOk() const { - if (num_channels < 0 || num_streams < 0 || coupled_streams < 0) { + if (num_channels < 1 || num_channels > AudioDecoder::kMaxNumberOfChannels || + num_streams < 0 || coupled_streams < 0) { return false; } if (num_streams < coupled_streams) {