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   return absl::EqualsIgnoreCase(format.name, "G722") &&
25                  format.clockrate_hz == 8000 &&
26                  (format.num_channels == 1 || format.num_channels == 2)
27              ? absl::optional<Config>(
28                    Config{rtc::dchecked_cast<int>(format.num_channels)})
29              : 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>)37 std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder(
38     Config config,
39     absl::optional<AudioCodecPairId> /*codec_pair_id*/) {
40   switch (config.num_channels) {
41     case 1:
42       return std::make_unique<AudioDecoderG722Impl>();
43     case 2:
44       return std::make_unique<AudioDecoderG722StereoImpl>();
45     default:
46       return nullptr;
47   }
48 }
49 
50 }  // namespace webrtc
51