kwiberg | 7ea6e59 | 2017-08-16 06:12:57 -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 | |
| 11 | #include "webrtc/api/audio_codecs/L16/audio_encoder_L16.h" |
| 12 | |
| 13 | #include "webrtc/common_types.h" |
| 14 | #include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h" |
| 15 | #include "webrtc/modules/audio_coding/codecs/pcm16b/pcm16b_common.h" |
| 16 | #include "webrtc/rtc_base/ptr_util.h" |
oprypin | 0826fb2 | 2017-08-22 13:57:48 -0700 | [diff] [blame] | 17 | #include "webrtc/rtc_base/safe_conversions.h" |
kwiberg | 7ea6e59 | 2017-08-16 06:12:57 -0700 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | rtc::Optional<AudioEncoderL16::Config> AudioEncoderL16::SdpToConfig( |
| 22 | const SdpAudioFormat& format) { |
Karl Wiberg | eea063f | 2017-09-14 13:49:13 +0200 | [diff] [blame] | 23 | if (!rtc::IsValueInRangeForNumericType<int>(format.num_channels)) { |
| 24 | return rtc::Optional<Config>(); |
| 25 | } |
kwiberg | 7ea6e59 | 2017-08-16 06:12:57 -0700 | [diff] [blame] | 26 | Config config; |
| 27 | config.sample_rate_hz = format.clockrate_hz; |
Karl Wiberg | eea063f | 2017-09-14 13:49:13 +0200 | [diff] [blame] | 28 | config.num_channels = rtc::dchecked_cast<int>(format.num_channels); |
kwiberg | 7ea6e59 | 2017-08-16 06:12:57 -0700 | [diff] [blame] | 29 | return STR_CASE_CMP(format.name.c_str(), "L16") == 0 && config.IsOk() |
| 30 | ? rtc::Optional<Config>(config) |
| 31 | : rtc::Optional<Config>(); |
| 32 | } |
| 33 | |
| 34 | void AudioEncoderL16::AppendSupportedEncoders( |
| 35 | std::vector<AudioCodecSpec>* specs) { |
| 36 | Pcm16BAppendSupportedCodecSpecs(specs); |
| 37 | } |
| 38 | |
| 39 | AudioCodecInfo AudioEncoderL16::QueryAudioEncoder( |
| 40 | const AudioEncoderL16::Config& config) { |
| 41 | RTC_DCHECK(config.IsOk()); |
| 42 | return {config.sample_rate_hz, |
| 43 | rtc::dchecked_cast<size_t>(config.num_channels), |
| 44 | config.sample_rate_hz * config.num_channels * 16}; |
| 45 | } |
| 46 | |
| 47 | std::unique_ptr<AudioEncoder> AudioEncoderL16::MakeAudioEncoder( |
| 48 | const AudioEncoderL16::Config& config, |
| 49 | int payload_type) { |
| 50 | RTC_DCHECK(config.IsOk()); |
| 51 | AudioEncoderPcm16B::Config c; |
| 52 | c.sample_rate_hz = config.sample_rate_hz; |
| 53 | c.num_channels = config.num_channels; |
| 54 | c.frame_size_ms = config.frame_size_ms; |
| 55 | c.payload_type = payload_type; |
| 56 | return rtc::MakeUnique<AudioEncoderPcm16B>(c); |
| 57 | } |
| 58 | |
| 59 | } // namespace webrtc |