Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h

Issue 2695243005: Injectable audio encoders: BuiltinAudioEncoderFactory (Closed)
Patch Set: Wrote tests for BuiltinAudioEncoderFactory; addressed many comments. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 auto ptime_iter = format.parameters.find("ptime");
50 if (ptime_iter != format.parameters.end()) {
51 auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
52 if (ptime && *ptime > 0) {
53 config.frame_size_ms = *ptime;
54 }
55 }
56
57 // Set the default bitrate for ISAC to the maximum bitrate allowed at this
58 // clockrate. At this point, adaptive mode is not used by WebRTC.
59 config.bit_rate = GetIsacMaxBitrate(format.clockrate_hz);
60 return config;
61 }
62
63 template <typename T>
36 bool AudioEncoderIsacT<T>::Config::IsOk() const { 64 bool AudioEncoderIsacT<T>::Config::IsOk() const {
37 if (max_bit_rate < 32000 && max_bit_rate != -1) 65 if (max_bit_rate < 32000 && max_bit_rate != -1)
38 return false; 66 return false;
39 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) 67 if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1)
40 return false; 68 return false;
41 if (adaptive_mode && !bwinfo) 69 if (adaptive_mode && !bwinfo)
42 return false; 70 return false;
43 switch (sample_rate_hz) { 71 switch (sample_rate_hz) {
44 case 16000: 72 case 16000:
45 if (max_bit_rate > 53400) 73 if (max_bit_rate > 53400)
(...skipping 20 matching lines...) Expand all
66 RecreateEncoderInstance(config); 94 RecreateEncoderInstance(config);
67 } 95 }
68 96
69 template <typename T> 97 template <typename T>
70 AudioEncoderIsacT<T>::AudioEncoderIsacT( 98 AudioEncoderIsacT<T>::AudioEncoderIsacT(
71 const CodecInst& codec_inst, 99 const CodecInst& codec_inst,
72 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo) 100 const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo)
73 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {} 101 : AudioEncoderIsacT(CreateIsacConfig<T>(codec_inst, bwinfo)) {}
74 102
75 template <typename T> 103 template <typename T>
104 AudioEncoderIsacT<T>::AudioEncoderIsacT(int payload_type,
105 const SdpAudioFormat& format)
106 : AudioEncoderIsacT(CreateIsacConfig<T>(payload_type, format)) {}
107
108 template <typename T>
109 rtc::Optional<AudioCodecInfo> AudioEncoderIsacT<T>::QueryAudioEncoder(
110 const SdpAudioFormat& format) {
111 if (STR_CASE_CMP(format.name.c_str(), GetPayloadName()) == 0) {
112 Config config = CreateIsacConfig<T>(0, format);
113 if (config.IsOk()) {
114 return rtc::Optional<AudioCodecInfo>({
115 config.sample_rate_hz, 1, config.bit_rate, 10000,
116 GetIsacMaxBitrate(format.clockrate_hz)});
117 }
118 }
119 return rtc::Optional<AudioCodecInfo>();
120 }
121
122 template <typename T>
76 AudioEncoderIsacT<T>::~AudioEncoderIsacT() { 123 AudioEncoderIsacT<T>::~AudioEncoderIsacT() {
77 RTC_CHECK_EQ(0, T::Free(isac_state_)); 124 RTC_CHECK_EQ(0, T::Free(isac_state_));
78 } 125 }
79 126
80 template <typename T> 127 template <typename T>
81 int AudioEncoderIsacT<T>::SampleRateHz() const { 128 int AudioEncoderIsacT<T>::SampleRateHz() const {
82 return T::EncSampRate(isac_state_); 129 return T::EncSampRate(isac_state_);
83 } 130 }
84 131
85 template <typename T> 132 template <typename T>
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // we get an encoding that isn't bit-for-bit identical with what a combined 227 // we get an encoding that isn't bit-for-bit identical with what a combined
181 // encoder+decoder object produces. 228 // encoder+decoder object produces.
182 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); 229 RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz));
183 230
184 config_ = config; 231 config_ = config;
185 } 232 }
186 233
187 } // namespace webrtc 234 } // namespace webrtc
188 235
189 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ 236 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698