audio_decoder_g722.cc (1932B)
1 /* 2 * Copyright (c) 2017 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 #include "api/audio_codecs/g722/audio_decoder_g722.h" 12 13 #include <memory> 14 #include <optional> 15 #include <vector> 16 17 #include "absl/strings/match.h" 18 #include "api/audio_codecs/audio_codec_pair_id.h" 19 #include "api/audio_codecs/audio_decoder.h" 20 #include "api/audio_codecs/audio_format.h" 21 #include "api/field_trials_view.h" 22 #include "modules/audio_coding/codecs/g722/audio_decoder_g722.h" 23 #include "rtc_base/checks.h" 24 #include "rtc_base/numerics/safe_conversions.h" 25 26 namespace webrtc { 27 28 std::optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig( 29 const SdpAudioFormat& format) { 30 if (absl::EqualsIgnoreCase(format.name, "G722") && 31 format.clockrate_hz == 8000 && 32 (format.num_channels == 1 || format.num_channels == 2)) { 33 return Config{dchecked_cast<int>(format.num_channels)}; 34 } 35 return std::nullopt; 36 } 37 38 void AudioDecoderG722::AppendSupportedDecoders( 39 std::vector<AudioCodecSpec>* specs) { 40 specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}}); 41 } 42 43 std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder( 44 Config config, 45 std::optional<AudioCodecPairId> /*codec_pair_id*/, 46 const FieldTrialsView* /* field_trials */) { 47 if (!config.IsOk()) { 48 RTC_DCHECK_NOTREACHED(); 49 return nullptr; 50 } 51 switch (config.num_channels) { 52 case 1: 53 return std::make_unique<AudioDecoderG722Impl>(); 54 case 2: 55 return std::make_unique<AudioDecoderG722StereoImpl>(); 56 default: 57 RTC_DCHECK_NOTREACHED(); 58 return nullptr; 59 } 60 } 61 62 } // namespace webrtc