Chromium Code Reviews| 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/base/checks.h" | 14 #include "webrtc/base/checks.h" | 
| 15 #include "webrtc/base/string_to_number.h" | |
| 15 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" | 
| 16 | 17 | 
| 17 namespace webrtc { | 18 namespace webrtc { | 
| 19 namespace { | |
| 20 int GetIsacMaxBitrate(int clockrate_hz) { | |
| 21 return (clockrate_hz == 32000) ? 56000 : 32000; | |
| 22 } | |
| 23 } // namespace | |
| 18 | 24 | 
| 19 template <typename T> | 25 template <typename T> | 
| 20 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( | 26 typename AudioEncoderIsacT<T>::Config CreateIsacConfig( | 
| 21 const CodecInst& codec_inst, | 27 const CodecInst& codec_inst, | 
| 22 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) { | 28 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) { | 
| 23 typename AudioEncoderIsacT<T>::Config config; | 29 typename AudioEncoderIsacT<T>::Config config; | 
| 24 config.bwinfo = bwinfo; | 30 config.bwinfo = bwinfo; | 
| 25 config.payload_type = codec_inst.pltype; | 31 config.payload_type = codec_inst.pltype; | 
| 26 config.sample_rate_hz = codec_inst.plfreq; | 32 config.sample_rate_hz = codec_inst.plfreq; | 
| 27 config.frame_size_ms = | 33 config.frame_size_ms = | 
| 28 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); | 34 rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); | 
| 29 config.adaptive_mode = (codec_inst.rate == -1); | 35 config.adaptive_mode = (codec_inst.rate == -1); | 
| 30 if (codec_inst.rate != -1) | 36 if (codec_inst.rate != -1) | 
| 31 config.bit_rate = codec_inst.rate; | 37 config.bit_rate = codec_inst.rate; | 
| 32 return config; | 38 return config; | 
| 33 } | 39 } | 
| 34 | 40 | 
| 35 template <typename T> | 41 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 kHz. | |
| 
 
the sun
2017/03/20 20:53:40
That rate is *way* too high. :P
 
ossu
2017/03/21 16:15:31
:D
 
 | |
| 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) { | |
| 
 
ossu
2017/03/20 18:18:53
The ptime parsers are based on the values found in
 
the sun
2017/03/20 20:53:40
Acknowledged.
 
 | |
| 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> | |
| 36 bool AudioEncoderIsacT<T>::Config::IsOk() const { | 69 bool AudioEncoderIsacT<T>::Config::IsOk() const { | 
| 37 if (max_bit_rate < 32000 && max_bit_rate != -1) | 70 if (max_bit_rate < 32000 && max_bit_rate != -1) | 
| 38 return false; | 71 return false; | 
| 39 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) | 72 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) | 
| 40 return false; | 73 return false; | 
| 41 if (adaptive_mode && !bwinfo) | 74 if (adaptive_mode && !bwinfo) | 
| 42 return false; | 75 return false; | 
| 43 switch (sample_rate_hz) { | 76 switch (sample_rate_hz) { | 
| 44 case 16000: | 77 case 16000: | 
| 45 if (max_bit_rate > 53400) | 78 if (max_bit_rate > 53400) | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 66 RecreateEncoderInstance(config); | 99 RecreateEncoderInstance(config); | 
| 67 } | 100 } | 
| 68 | 101 | 
| 69 template <typename T> | 102 template <typename T> | 
| 70 AudioEncoderIsacT<T>::AudioEncoderIsacT( | 103 AudioEncoderIsacT<T>::AudioEncoderIsacT( | 
| 71 const CodecInst& codec_inst, | 104 const CodecInst& codec_inst, | 
| 72 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) | 105 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) | 
| 73 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} | 106 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} | 
| 74 | 107 | 
| 75 template <typename T> | 108 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> | |
| 76 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { | 128 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { | 
| 77 RTC_CHECK_EQ(0, T::Free(isac_state_)); | 129 RTC_CHECK_EQ(0, T::Free(isac_state_)); | 
| 78 } | 130 } | 
| 79 | 131 | 
| 80 template <typename T> | 132 template <typename T> | 
| 81 int AudioEncoderIsacT<T>::SampleRateHz() const { | 133 int AudioEncoderIsacT<T>::SampleRateHz() const { | 
| 82 return T::EncSampRate(isac_state_); | 134 return T::EncSampRate(isac_state_); | 
| 83 } | 135 } | 
| 84 | 136 | 
| 85 template <typename T> | 137 template <typename T> | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 // we get an encoding that isn't bit-for-bit identical with what a combined | 232 // we get an encoding that isn't bit-for-bit identical with what a combined | 
| 181 // encoder+decoder object produces. | 233 // encoder+decoder object produces. | 
| 182 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); | 234 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); | 
| 183 | 235 | 
| 184 config_ = config; | 236 config_ = config; | 
| 185 } | 237 } | 
| 186 | 238 | 
| 187 } // namespace webrtc | 239 } // namespace webrtc | 
| 188 | 240 | 
| 189 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 241 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ | 
| OLD | NEW |