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