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

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

Issue 1423803007: CodecManager: Eliminate the stereo_send_ member (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@rac2
Patch Set: 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
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/codec_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 const CodecInst kEmptyCodecInst = {-1, "noCodecRegistered", 0, 0, 0, 0}; 131 const CodecInst kEmptyCodecInst = {-1, "noCodecRegistered", 0, 0, 0, 0};
132 } // namespace 132 } // namespace
133 133
134 CodecManager::CodecManager() 134 CodecManager::CodecManager()
135 : cng_nb_pltype_(255), 135 : cng_nb_pltype_(255),
136 cng_wb_pltype_(255), 136 cng_wb_pltype_(255),
137 cng_swb_pltype_(255), 137 cng_swb_pltype_(255),
138 cng_fb_pltype_(255), 138 cng_fb_pltype_(255),
139 red_nb_pltype_(255), 139 red_nb_pltype_(255),
140 stereo_send_(false),
141 dtx_enabled_(false), 140 dtx_enabled_(false),
142 vad_mode_(VADNormal), 141 vad_mode_(VADNormal),
143 send_codec_inst_(kEmptyCodecInst), 142 send_codec_inst_(kEmptyCodecInst),
144 red_enabled_(false), 143 red_enabled_(false),
145 codec_fec_enabled_(false), 144 codec_fec_enabled_(false),
146 encoder_is_opus_(false) { 145 encoder_is_opus_(false) {
147 // Register the default payload type for RED and for CNG at sampling rates of 146 // Register the default payload type for RED and for CNG at sampling rates of
148 // 8, 16, 32 and 48 kHz. 147 // 8, 16, 32 and 48 kHz.
149 for (const CodecInst& ci : RentACodec::Database()) { 148 for (const CodecInst& ci : RentACodec::Database()) {
150 if (IsCodecRED(ci) && ci.plfreq == 8000) { 149 if (IsCodecRED(ci) && ci.plfreq == 8000) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 default: { 223 default: {
225 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id, 224 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, dummy_id,
226 "RegisterSendCodec() failed, invalid frequency for CNG " 225 "RegisterSendCodec() failed, invalid frequency for CNG "
227 "registration"); 226 "registration");
228 return -1; 227 return -1;
229 } 228 }
230 } 229 }
231 } 230 }
232 231
233 // Set Stereo, and make sure VAD and DTX is turned off. 232 // Set Stereo, and make sure VAD and DTX is turned off.
234 if (send_codec.channels == 2) { 233 if (send_codec.channels != 1) {
235 stereo_send_ = true;
236 if (dtx_enabled_) { 234 if (dtx_enabled_) {
237 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, dummy_id, 235 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, dummy_id,
238 "VAD/DTX is turned off, not supported when sending stereo."); 236 "VAD/DTX is turned off, not supported when sending stereo.");
239 } 237 }
240 dtx_enabled_ = false; 238 dtx_enabled_ = false;
241 } else {
242 stereo_send_ = false;
243 } 239 }
244 240
245 // Check if the codec is already registered as send codec. 241 // Check if the codec is already registered as send codec.
246 bool new_codec = true; 242 bool new_codec = true;
247 if (codec_owner_.Encoder()) { 243 if (codec_owner_.Encoder()) {
248 auto new_codec_id = RentACodec::CodecIdByInst(send_codec_inst_); 244 auto new_codec_id = RentACodec::CodecIdByInst(send_codec_inst_);
249 RTC_DCHECK(new_codec_id); 245 RTC_DCHECK(new_codec_id);
250 auto old_codec_id = RentACodec::CodecIdFromIndex(codec_id); 246 auto old_codec_id = RentACodec::CodecIdFromIndex(codec_id);
251 new_codec = !old_codec_id || *new_codec_id != *old_codec_id; 247 new_codec = !old_codec_id || *new_codec_id != *old_codec_id;
252 } 248 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); 310 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz();
315 send_codec_inst_.pacsize = rtc::CheckedDivExact( 311 send_codec_inst_.pacsize = rtc::CheckedDivExact(
316 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * 312 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() *
317 send_codec_inst_.plfreq), 313 send_codec_inst_.plfreq),
318 100); 314 100);
319 send_codec_inst_.pltype = -1; // Not valid. 315 send_codec_inst_.pltype = -1; // Not valid.
320 send_codec_inst_.rate = -1; // Not valid. 316 send_codec_inst_.rate = -1; // Not valid.
321 static const char kName[] = "external"; 317 static const char kName[] = "external";
322 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); 318 memcpy(send_codec_inst_.plname, kName, sizeof(kName));
323 319
324 if (stereo_send_) 320 if (send_codec_inst_.channels != 1)
325 dtx_enabled_ = false; 321 dtx_enabled_ = false;
326 codec_fec_enabled_ = 322 codec_fec_enabled_ =
327 codec_fec_enabled_ && codec_owner_.Encoder()->SetFec(codec_fec_enabled_); 323 codec_fec_enabled_ && codec_owner_.Encoder()->SetFec(codec_fec_enabled_);
328 int cng_pt = dtx_enabled_ 324 int cng_pt = dtx_enabled_
329 ? CngPayloadType(external_speech_encoder->SampleRateHz()) 325 ? CngPayloadType(external_speech_encoder->SampleRateHz())
330 : -1; 326 : -1;
331 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; 327 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1;
332 codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt); 328 codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt);
333 } 329 }
334 330
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 return true; 363 return true;
368 } 364 }
369 365
370 int CodecManager::SetVAD(bool enable, ACMVADMode mode) { 366 int CodecManager::SetVAD(bool enable, ACMVADMode mode) {
371 // Sanity check of the mode. 367 // Sanity check of the mode.
372 RTC_DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr || 368 RTC_DCHECK(mode == VADNormal || mode == VADLowBitrate || mode == VADAggr ||
373 mode == VADVeryAggr); 369 mode == VADVeryAggr);
374 370
375 // Check that the send codec is mono. We don't support VAD/DTX for stereo 371 // Check that the send codec is mono. We don't support VAD/DTX for stereo
376 // sending. 372 // sending.
377 if (enable && stereo_send_) { 373 const auto* enc = codec_owner_.Encoder();
374 const bool stereo_send = enc ? (enc->NumChannels() != 1) : false;
375 if (enable && stereo_send) {
378 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0, 376 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, 0,
379 "VAD/DTX not supported for stereo sending"); 377 "VAD/DTX not supported for stereo sending");
380 dtx_enabled_ = false; 378 dtx_enabled_ = false;
381 return -1; 379 return -1;
382 } 380 }
383 381
384 // If a send codec is registered, set VAD/DTX for the codec. 382 // If a send codec is registered, set VAD/DTX for the codec.
385 if (IsOpus(send_codec_inst_)) { 383 if (IsOpus(send_codec_inst_)) {
386 // VAD/DTX not supported. 384 // VAD/DTX not supported.
387 dtx_enabled_ = false; 385 dtx_enabled_ = false;
388 return 0; 386 return 0;
389 } 387 }
390 388
391 if (dtx_enabled_ != enable || vad_mode_ != mode) { 389 if (dtx_enabled_ != enable || vad_mode_ != mode) {
392 dtx_enabled_ = enable; 390 dtx_enabled_ = enable;
393 vad_mode_ = mode; 391 vad_mode_ = mode;
394 if (codec_owner_.Encoder()) { 392 if (enc) {
395 int cng_pt = dtx_enabled_ ? CngPayloadType(send_codec_inst_.plfreq) : -1; 393 int cng_pt = dtx_enabled_ ? CngPayloadType(send_codec_inst_.plfreq) : -1;
396 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; 394 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1;
397 codec_owner_.ChangeCngAndRed(cng_pt, vad_mode_, red_pt); 395 codec_owner_.ChangeCngAndRed(cng_pt, vad_mode_, red_pt);
398 } 396 }
399 } 397 }
400 return 0; 398 return 0;
401 } 399 }
402 400
403 void CodecManager::VAD(bool* dtx_enabled, 401 void CodecManager::VAD(bool* dtx_enabled,
404 bool* vad_enabled, 402 bool* vad_enabled,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 case 48000: 448 case 48000:
451 return -1; 449 return -1;
452 default: 450 default:
453 FATAL() << sample_rate_hz << " Hz is not supported"; 451 FATAL() << sample_rate_hz << " Hz is not supported";
454 return -1; 452 return -1;
455 } 453 }
456 } 454 }
457 455
458 } // namespace acm2 456 } // namespace acm2
459 } // namespace webrtc 457 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/main/acm2/codec_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698