| OLD | NEW |
| (Empty) | |
| 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 "webrtc/api/audio_codecs/g711/audio_decoder_g711.h" |
| 12 |
| 13 #include <memory> |
| 14 #include <vector> |
| 15 |
| 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/modules/audio_coding/codecs/g711/audio_decoder_pcm.h" |
| 18 #include "webrtc/rtc_base/ptr_util.h" |
| 19 #include "webrtc/rtc_base/safe_conversions.h" |
| 20 |
| 21 namespace webrtc { |
| 22 |
| 23 rtc::Optional<AudioDecoderG711::Config> AudioDecoderG711::SdpToConfig( |
| 24 const SdpAudioFormat& format) { |
| 25 const bool is_pcmu = STR_CASE_CMP(format.name.c_str(), "PCMU") == 0; |
| 26 const bool is_pcma = STR_CASE_CMP(format.name.c_str(), "PCMA") == 0; |
| 27 if (format.clockrate_hz == 8000 && format.num_channels >= 1 && |
| 28 (is_pcmu || is_pcma)) { |
| 29 Config config; |
| 30 config.type = is_pcmu ? Config::Type::kPcmU : Config::Type::kPcmA; |
| 31 config.num_channels = rtc::dchecked_cast<int>(format.num_channels); |
| 32 RTC_DCHECK(config.IsOk()); |
| 33 return rtc::Optional<Config>(config); |
| 34 } else { |
| 35 return rtc::Optional<Config>(); |
| 36 } |
| 37 } |
| 38 |
| 39 void AudioDecoderG711::AppendSupportedDecoders( |
| 40 std::vector<AudioCodecSpec>* specs) { |
| 41 for (const char* type : {"PCMU", "PCMA"}) { |
| 42 specs->push_back({{type, 8000, 1}, {8000, 1, 64000}}); |
| 43 } |
| 44 } |
| 45 |
| 46 std::unique_ptr<AudioDecoder> AudioDecoderG711::MakeAudioDecoder( |
| 47 const Config& config) { |
| 48 RTC_DCHECK(config.IsOk()); |
| 49 switch (config.type) { |
| 50 case Config::Type::kPcmU: |
| 51 return rtc::MakeUnique<AudioDecoderPcmU>(config.num_channels); |
| 52 case Config::Type::kPcmA: |
| 53 return rtc::MakeUnique<AudioDecoderPcmA>(config.num_channels); |
| 54 default: |
| 55 return nullptr; |
| 56 } |
| 57 } |
| 58 |
| 59 } // namespace webrtc |
| OLD | NEW |