| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
| 13 | 13 |
| 14 #include "webrtc/common_types.h" | 14 #include "webrtc/common_types.h" |
| 15 #include "webrtc/rtc_base/checks.h" | 15 #include "webrtc/rtc_base/checks.h" |
| 16 #include "webrtc/rtc_base/string_to_number.h" | |
| 17 | 16 |
| 18 namespace webrtc { | 17 namespace webrtc { |
| 19 namespace { // NOLINT (not a "regular" header file) | |
| 20 int GetIsacMaxBitrate(int clockrate_hz) { | |
| 21 return (clockrate_hz == 32000) ? 56000 : 32000; | |
| 22 } | |
| 23 } // namespace | |
| 24 | 18 |
| 25 template <typename T> | 19 template <typename T> |
| 26 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( | 20 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( |
| 27 const CodecInst& codec_inst, | 21 const CodecInst& codec_inst, |
| 28 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) { | 22 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) { |
| 29 typename AudioEncoderIsacT<T>::Config config; | 23 typename AudioEncoderIsacT<T>::Config config; |
| 30 config.bwinfo = bwinfo; | 24 config.bwinfo = bwinfo; |
| 31 config.payload_type = codec_inst.pltype; | 25 config.payload_type = codec_inst.pltype; |
| 32 config.sample_rate_hz = codec_inst.plfreq; | 26 config.sample_rate_hz = codec_inst.plfreq; |
| 33 config.frame_size_ms = | 27 config.frame_size_ms = |
| 34 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); | 28 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); |
| 35 config.adaptive_mode = (codec_inst.rate == -1); | 29 config.adaptive_mode = (codec_inst.rate == -1); |
| 36 if (codec_inst.rate != -1) | 30 if (codec_inst.rate != -1) |
| 37 config.bit_rate = codec_inst.rate; | 31 config.bit_rate = codec_inst.rate; |
| 38 return config; | 32 return config; |
| 39 } | 33 } |
| 40 | 34 |
| 41 template <typename T> | 35 template <typename T> |
| 42 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( | |
| 43 int payload_type, | |
| 44 const SdpAudioFormat& format) { | |
| 45 typename AudioEncoderIsacT<T>::Config config; | |
| 46 config.payload_type = payload_type; | |
| 47 config.sample_rate_hz = format.clockrate_hz; | |
| 48 | |
| 49 // We only support different frame sizes at 16000 Hz. | |
| 50 if (config.sample_rate_hz == 16000) { | |
| 51 auto ptime_iter = format.parameters.find("ptime"); | |
| 52 if (ptime_iter != format.parameters.end()) { | |
| 53 auto ptime = rtc::StringToNumber<int>(ptime_iter->second); | |
| 54 if (ptime && *ptime >= 60) { | |
| 55 config.frame_size_ms = 60; | |
| 56 } else { | |
| 57 config.frame_size_ms = 30; | |
| 58 } | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 // Set the default bitrate for ISAC to the maximum bitrate allowed at this | |
| 63 // clockrate. At this point, adaptive mode is not used by WebRTC. | |
| 64 config.bit_rate = GetIsacMaxBitrate(format.clockrate_hz); | |
| 65 return config; | |
| 66 } | |
| 67 | |
| 68 template <typename T> | |
| 69 bool AudioEncoderIsacT<T>::Config::IsOk() const { | 36 bool AudioEncoderIsacT<T>::Config::IsOk() const { |
| 70 if (max_bit_rate < 32000 && max_bit_rate != -1) | 37 if (max_bit_rate < 32000 && max_bit_rate != -1) |
| 71 return false; | 38 return false; |
| 72 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) | 39 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) |
| 73 return false; | 40 return false; |
| 74 if (adaptive_mode && !bwinfo) | 41 if (adaptive_mode && !bwinfo) |
| 75 return false; | 42 return false; |
| 76 switch (sample_rate_hz) { | 43 switch (sample_rate_hz) { |
| 77 case 16000: | 44 case 16000: |
| 78 if (max_bit_rate > 53400) | 45 if (max_bit_rate > 53400) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 99 RecreateEncoderInstance(config); | 66 RecreateEncoderInstance(config); |
| 100 } | 67 } |
| 101 | 68 |
| 102 template <typename T> | 69 template <typename T> |
| 103 AudioEncoderIsacT<T>::AudioEncoderIsacT( | 70 AudioEncoderIsacT<T>::AudioEncoderIsacT( |
| 104 const CodecInst& codec_inst, | 71 const CodecInst& codec_inst, |
| 105 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) | 72 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) |
| 106 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} | 73 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} |
| 107 | 74 |
| 108 template <typename T> | 75 template <typename T> |
| 109 AudioEncoderIsacT<T>::AudioEncoderIsacT(int payload_type, | |
| 110 const SdpAudioFormat& format) | |
| 111 : AudioEncoderIsacT(CreateIsacConfig<T>(payload_type, format)) {} | |
| 112 | |
| 113 template <typename T> | |
| 114 rtc::Optional<AudioCodecInfo> AudioEncoderIsacT<T>::QueryAudioEncoder( | |
| 115 const SdpAudioFormat& format) { | |
| 116 if (STR_CASE_CMP(format.name.c_str(), GetPayloadName()) == 0) { | |
| 117 Config config = CreateIsacConfig<T>(0, format); | |
| 118 if (config.IsOk()) { | |
| 119 return rtc::Optional<AudioCodecInfo>( | |
| 120 {config.sample_rate_hz, 1, config.bit_rate, 10000, | |
| 121 GetIsacMaxBitrate(format.clockrate_hz)}); | |
| 122 } | |
| 123 } | |
| 124 return rtc::Optional<AudioCodecInfo>(); | |
| 125 } | |
| 126 | |
| 127 template <typename T> | |
| 128 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { | 76 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { |
| 129 RTC_CHECK_EQ(0, T::Free(isac_state_)); | 77 RTC_CHECK_EQ(0, T::Free(isac_state_)); |
| 130 } | 78 } |
| 131 | 79 |
| 132 template <typename T> | 80 template <typename T> |
| 133 int AudioEncoderIsacT<T>::SampleRateHz() const { | 81 int AudioEncoderIsacT<T>::SampleRateHz() const { |
| 134 return T::EncSampRate(isac_state_); | 82 return T::EncSampRate(isac_state_); |
| 135 } | 83 } |
| 136 | 84 |
| 137 template <typename T> | 85 template <typename T> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // we get an encoding that isn't bit-for-bit identical with what a combined | 180 // we get an encoding that isn't bit-for-bit identical with what a combined |
| 233 // encoder+decoder object produces. | 181 // encoder+decoder object produces. |
| 234 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); | 182 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); |
| 235 | 183 |
| 236 config_ = config; | 184 config_ = config; |
| 237 } | 185 } |
| 238 | 186 |
| 239 } // namespace webrtc | 187 } // namespace webrtc |
| 240 | 188 |
| 241 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 189 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ |
| OLD | NEW |