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

Side by Side Diff: webrtc/modules/audio_coding/main/acm2/rent_a_codec.cc

Issue 1443653004: Move CNG and RED management into the Rent-A-Codec (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Extract subroutine Created 5 years, 1 month 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h" 11 #include "webrtc/modules/audio_coding/main/acm2/rent_a_codec.h"
12 12
13 #include "webrtc/base/logging.h" 13 #include "webrtc/base/logging.h"
14 #include "webrtc/modules/audio_coding/codecs/cng/include/audio_encoder_cng.h"
14 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" 15 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h"
15 #ifdef WEBRTC_CODEC_G722 16 #ifdef WEBRTC_CODEC_G722
16 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h" 17 #include "webrtc/modules/audio_coding/codecs/g722/include/audio_encoder_g722.h"
17 #endif 18 #endif
18 #ifdef WEBRTC_CODEC_ILBC 19 #ifdef WEBRTC_CODEC_ILBC
19 #include "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h" 20 #include "webrtc/modules/audio_coding/codecs/ilbc/include/audio_encoder_ilbc.h"
20 #endif 21 #endif
21 #ifdef WEBRTC_CODEC_ISACFX 22 #ifdef WEBRTC_CODEC_ISACFX
22 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h" 23 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_decoder_isac fix.h"
23 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h" 24 #include "webrtc/modules/audio_coding/codecs/isac/fix/include/audio_encoder_isac fix.h"
24 #endif 25 #endif
25 #ifdef WEBRTC_CODEC_ISAC 26 #ifdef WEBRTC_CODEC_ISAC
26 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h" 27 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_decoder_isa c.h"
27 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h" 28 #include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isa c.h"
28 #endif 29 #endif
29 #ifdef WEBRTC_CODEC_OPUS 30 #ifdef WEBRTC_CODEC_OPUS
30 #include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h" 31 #include "webrtc/modules/audio_coding/codecs/opus/include/audio_encoder_opus.h"
31 #endif 32 #endif
32 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b .h" 33 #include "webrtc/modules/audio_coding/codecs/pcm16b/include/audio_encoder_pcm16b .h"
34 #ifdef WEBRTC_CODEC_RED
35 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h"
36 #endif
33 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h" 37 #include "webrtc/modules/audio_coding/main/acm2/acm_codec_database.h"
34 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h" 38 #include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
35 39
36 namespace webrtc { 40 namespace webrtc {
37 namespace acm2 { 41 namespace acm2 {
38 42
39 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams( 43 rtc::Optional<RentACodec::CodecId> RentACodec::CodecIdByParams(
40 const char* payload_name, 44 const char* payload_name,
41 int sampling_freq_hz, 45 int sampling_freq_hz,
42 int channels) { 46 int channels) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst)); 137 return rtc_make_scoped_ptr(new AudioEncoderIlbc(speech_inst));
134 #endif 138 #endif
135 #ifdef WEBRTC_CODEC_G722 139 #ifdef WEBRTC_CODEC_G722
136 if (STR_CASE_CMP(speech_inst.plname, "g722") == 0) 140 if (STR_CASE_CMP(speech_inst.plname, "g722") == 0)
137 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst)); 141 return rtc_make_scoped_ptr(new AudioEncoderG722(speech_inst));
138 #endif 142 #endif
139 LOG_F(LS_ERROR) << "Could not create encoder of type " << speech_inst.plname; 143 LOG_F(LS_ERROR) << "Could not create encoder of type " << speech_inst.plname;
140 return rtc::scoped_ptr<AudioEncoder>(); 144 return rtc::scoped_ptr<AudioEncoder>();
141 } 145 }
142 146
147 rtc::scoped_ptr<AudioEncoder> CreateRedEncoder(AudioEncoder* encoder,
148 int red_payload_type) {
149 #ifdef WEBRTC_CODEC_RED
150 AudioEncoderCopyRed::Config config;
151 config.payload_type = red_payload_type;
152 config.speech_encoder = encoder;
153 return rtc::scoped_ptr<AudioEncoder>(new AudioEncoderCopyRed(config));
154 #else
155 return rtc::scoped_ptr<AudioEncoder>();
156 #endif
157 }
158
159 rtc::scoped_ptr<AudioEncoder> CreateCngEncoder(
160 AudioEncoder* encoder,
161 RentACodec::CngConfig cng_config) {
162 AudioEncoderCng::Config config;
163 config.num_channels = encoder->NumChannels();
164 config.payload_type = cng_config.cng_payload_type;
165 config.speech_encoder = encoder;
166 switch (cng_config.vad_mode) {
167 case VADNormal:
168 config.vad_mode = Vad::kVadNormal;
169 break;
170 case VADLowBitrate:
171 config.vad_mode = Vad::kVadLowBitrate;
172 break;
173 case VADAggr:
174 config.vad_mode = Vad::kVadAggressive;
175 break;
176 case VADVeryAggr:
177 config.vad_mode = Vad::kVadVeryAggressive;
178 break;
179 default:
180 FATAL();
181 }
182 return rtc::scoped_ptr<AudioEncoder>(new AudioEncoderCng(config));
183 }
184
143 rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder( 185 rtc::scoped_ptr<AudioDecoder> CreateIsacDecoder(
144 LockedIsacBandwidthInfo* bwinfo) { 186 LockedIsacBandwidthInfo* bwinfo) {
145 #if defined(WEBRTC_CODEC_ISACFX) 187 #if defined(WEBRTC_CODEC_ISACFX)
146 return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo)); 188 return rtc_make_scoped_ptr(new AudioDecoderIsacFix(bwinfo));
147 #elif defined(WEBRTC_CODEC_ISAC) 189 #elif defined(WEBRTC_CODEC_ISAC)
148 return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo)); 190 return rtc_make_scoped_ptr(new AudioDecoderIsac(bwinfo));
149 #else 191 #else
150 FATAL() << "iSAC is not supported."; 192 FATAL() << "iSAC is not supported.";
151 return rtc::scoped_ptr<AudioDecoder>(); 193 return rtc::scoped_ptr<AudioDecoder>();
152 #endif 194 #endif
153 } 195 }
154 196
155 } // namespace 197 } // namespace
156 198
157 RentACodec::RentACodec() = default; 199 RentACodec::RentACodec() = default;
158 RentACodec::~RentACodec() = default; 200 RentACodec::~RentACodec() = default;
159 201
160 AudioEncoder* RentACodec::RentEncoder(const CodecInst& codec_inst) { 202 AudioEncoder* RentACodec::RentEncoder(const CodecInst& codec_inst) {
161 rtc::scoped_ptr<AudioEncoder> enc = 203 rtc::scoped_ptr<AudioEncoder> enc =
162 CreateEncoder(codec_inst, &isac_bandwidth_info_); 204 CreateEncoder(codec_inst, &isac_bandwidth_info_);
163 if (!enc) 205 if (!enc)
164 return nullptr; 206 return nullptr;
165 encoder_ = enc.Pass(); 207 speech_encoder_ = enc.Pass();
166 return encoder_.get(); 208 return speech_encoder_.get();
209 }
210
211 AudioEncoder* RentACodec::RentEncoderStack(
212 AudioEncoder* speech_encoder,
213 rtc::Optional<CngConfig> cng_config,
214 rtc::Optional<int> red_payload_type) {
215 RTC_DCHECK(speech_encoder);
216 if (cng_config || red_payload_type) {
217 // The RED and CNG encoders need to be in sync with the speech encoder, so
218 // reset the latter to ensure its buffer is empty.
219 speech_encoder->Reset();
220 }
221 encoder_stack_ = speech_encoder;
222 if (red_payload_type) {
223 red_encoder_ = CreateRedEncoder(encoder_stack_, *red_payload_type);
224 if (red_encoder_)
225 encoder_stack_ = red_encoder_.get();
226 } else {
227 red_encoder_.reset();
228 }
229 if (cng_config) {
230 cng_encoder_ = CreateCngEncoder(encoder_stack_, *cng_config);
231 encoder_stack_ = cng_encoder_.get();
232 } else {
233 cng_encoder_.reset();
234 }
235 return encoder_stack_;
167 } 236 }
168 237
169 AudioDecoder* RentACodec::RentIsacDecoder() { 238 AudioDecoder* RentACodec::RentIsacDecoder() {
170 if (!isac_decoder_) 239 if (!isac_decoder_)
171 isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_); 240 isac_decoder_ = CreateIsacDecoder(&isac_bandwidth_info_);
172 return isac_decoder_.get(); 241 return isac_decoder_.get();
173 } 242 }
174 243
175 } // namespace acm2 244 } // namespace acm2
176 } // namespace webrtc 245 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698