kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "api/audio_codecs/g722/audio_decoder_g722.h" |
kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
| 14 | #include <vector> |
| 15 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 16 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/audio_coding/codecs/g722/audio_decoder_g722.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame^] | 18 | #include "rtc_base/numerics/safe_conversions.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "rtc_base/ptr_util.h" |
kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | rtc::Optional<AudioDecoderG722::Config> AudioDecoderG722::SdpToConfig( |
| 24 | const SdpAudioFormat& format) { |
kwiberg | e5eb724 | 2017-08-25 03:10:50 -0700 | [diff] [blame] | 25 | return STR_CASE_CMP(format.name.c_str(), "G722") == 0 && |
kwiberg | 1b97e26 | 2017-06-26 04:19:43 -0700 | [diff] [blame] | 26 | format.clockrate_hz == 8000 && |
| 27 | (format.num_channels == 1 || format.num_channels == 2) |
| 28 | ? rtc::Optional<Config>( |
| 29 | Config{rtc::dchecked_cast<int>(format.num_channels)}) |
Oskar Sundbom | 9065730 | 2017-11-16 10:52:34 +0100 | [diff] [blame] | 30 | : rtc::nullopt; |
kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void AudioDecoderG722::AppendSupportedDecoders( |
| 34 | std::vector<AudioCodecSpec>* specs) { |
kwiberg | e5eb724 | 2017-08-25 03:10:50 -0700 | [diff] [blame] | 35 | specs->push_back({{"G722", 8000, 1}, {16000, 1, 64000}}); |
kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | std::unique_ptr<AudioDecoder> AudioDecoderG722::MakeAudioDecoder( |
| 39 | Config config) { |
kwiberg | 1b97e26 | 2017-06-26 04:19:43 -0700 | [diff] [blame] | 40 | switch (config.num_channels) { |
| 41 | case 1: |
| 42 | return rtc::MakeUnique<AudioDecoderG722Impl>(); |
| 43 | case 2: |
| 44 | return rtc::MakeUnique<AudioDecoderG722StereoImpl>(); |
| 45 | default: |
| 46 | return nullptr; |
| 47 | } |
kwiberg | b1ed7f0 | 2017-06-17 17:30:09 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // namespace webrtc |