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/isac/audio_encoder_isac_float.h" |
| 12 |
| 13 #include "webrtc/common_types.h" |
| 14 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa
c.h" |
| 15 #include "webrtc/rtc_base/ptr_util.h" |
| 16 #include "webrtc/rtc_base/string_to_number.h" |
| 17 |
| 18 namespace webrtc { |
| 19 |
| 20 rtc::Optional<AudioEncoderIsacFloat::Config> AudioEncoderIsacFloat::SdpToConfig( |
| 21 const SdpAudioFormat& format) { |
| 22 if (STR_CASE_CMP(format.name.c_str(), "ISAC") == 0 && |
| 23 (format.clockrate_hz == 16000 || format.clockrate_hz == 32000) && |
| 24 format.num_channels == 1) { |
| 25 Config config; |
| 26 config.sample_rate_hz = format.clockrate_hz; |
| 27 if (config.sample_rate_hz == 16000) { |
| 28 // For sample rate 16 kHz, optionally use 60 ms frames, instead of the |
| 29 // default 30 ms. |
| 30 const auto ptime_iter = format.parameters.find("ptime"); |
| 31 if (ptime_iter != format.parameters.end()) { |
| 32 const auto ptime = rtc::StringToNumber<int>(ptime_iter->second); |
| 33 if (ptime && *ptime >= 60) { |
| 34 config.frame_size_ms = 60; |
| 35 } |
| 36 } |
| 37 } |
| 38 return rtc::Optional<Config>(config); |
| 39 } else { |
| 40 return rtc::Optional<Config>(); |
| 41 } |
| 42 } |
| 43 |
| 44 void AudioEncoderIsacFloat::AppendSupportedEncoders( |
| 45 std::vector<AudioCodecSpec>* specs) { |
| 46 for (int sample_rate_hz : {16000, 32000}) { |
| 47 const SdpAudioFormat fmt = {"ISAC", sample_rate_hz, 1}; |
| 48 const AudioCodecInfo info = QueryAudioEncoder(*SdpToConfig(fmt)); |
| 49 specs->push_back({fmt, info}); |
| 50 } |
| 51 } |
| 52 |
| 53 AudioCodecInfo AudioEncoderIsacFloat::QueryAudioEncoder( |
| 54 const AudioEncoderIsacFloat::Config& config) { |
| 55 RTC_DCHECK(config.IsOk()); |
| 56 constexpr int min_bitrate = 10000; |
| 57 const int max_bitrate = config.sample_rate_hz == 16000 ? 32000 : 56000; |
| 58 const int default_bitrate = max_bitrate; |
| 59 return {config.sample_rate_hz, 1, default_bitrate, min_bitrate, max_bitrate}; |
| 60 } |
| 61 |
| 62 std::unique_ptr<AudioEncoder> AudioEncoderIsacFloat::MakeAudioEncoder( |
| 63 const AudioEncoderIsacFloat::Config& config, |
| 64 int payload_type) { |
| 65 RTC_DCHECK(config.IsOk()); |
| 66 AudioEncoderIsacFloatImpl::Config c; |
| 67 c.sample_rate_hz = config.sample_rate_hz; |
| 68 c.frame_size_ms = config.frame_size_ms; |
| 69 c.payload_type = payload_type; |
| 70 return rtc::MakeUnique<AudioEncoderIsacFloatImpl>(c); |
| 71 } |
| 72 |
| 73 } // namespace webrtc |
OLD | NEW |