OLD | NEW |
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 : cng_nb_pltype_(255), | 157 : cng_nb_pltype_(255), |
158 cng_wb_pltype_(255), | 158 cng_wb_pltype_(255), |
159 cng_swb_pltype_(255), | 159 cng_swb_pltype_(255), |
160 cng_fb_pltype_(255), | 160 cng_fb_pltype_(255), |
161 red_nb_pltype_(255), | 161 red_nb_pltype_(255), |
162 stereo_send_(false), | 162 stereo_send_(false), |
163 dtx_enabled_(false), | 163 dtx_enabled_(false), |
164 vad_mode_(VADNormal), | 164 vad_mode_(VADNormal), |
165 send_codec_inst_(kEmptyCodecInst), | 165 send_codec_inst_(kEmptyCodecInst), |
166 red_enabled_(false), | 166 red_enabled_(false), |
167 codec_fec_enabled_(false) { | 167 codec_fec_enabled_(false), |
| 168 encoder_is_opus_(false) { |
168 // Register the default payload type for RED and for CNG at sampling rates of | 169 // Register the default payload type for RED and for CNG at sampling rates of |
169 // 8, 16, 32 and 48 kHz. | 170 // 8, 16, 32 and 48 kHz. |
170 for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { | 171 for (int i = (ACMCodecDB::kNumCodecs - 1); i >= 0; i--) { |
171 if (IsCodecRED(i) && ACMCodecDB::database_[i].plfreq == 8000) { | 172 if (IsCodecRED(i) && ACMCodecDB::database_[i].plfreq == 8000) { |
172 red_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 173 red_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
173 } else if (IsCodecCN(i)) { | 174 } else if (IsCodecCN(i)) { |
174 if (ACMCodecDB::database_[i].plfreq == 8000) { | 175 if (ACMCodecDB::database_[i].plfreq == 8000) { |
175 cng_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 176 cng_nb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
176 } else if (ACMCodecDB::database_[i].plfreq == 16000) { | 177 } else if (ACMCodecDB::database_[i].plfreq == 16000) { |
177 cng_wb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 178 cng_wb_pltype_ = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (codec_owner_.Encoder()) { | 269 if (codec_owner_.Encoder()) { |
269 int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_); | 270 int new_codec_id = ACMCodecDB::CodecNumber(send_codec_inst_); |
270 DCHECK_GE(new_codec_id, 0); | 271 DCHECK_GE(new_codec_id, 0); |
271 new_codec = new_codec_id != codec_id; | 272 new_codec = new_codec_id != codec_id; |
272 } | 273 } |
273 | 274 |
274 if (RedPayloadType(send_codec.plfreq) == -1) { | 275 if (RedPayloadType(send_codec.plfreq) == -1) { |
275 red_enabled_ = false; | 276 red_enabled_ = false; |
276 } | 277 } |
277 | 278 |
| 279 encoder_is_opus_ = IsOpus(send_codec); |
| 280 |
278 if (new_codec) { | 281 if (new_codec) { |
279 // This is a new codec. Register it and return. | 282 // This is a new codec. Register it and return. |
280 DCHECK(CodecSupported(send_codec)); | 283 DCHECK(CodecSupported(send_codec)); |
281 if (IsOpus(send_codec)) { | 284 if (IsOpus(send_codec)) { |
282 // VAD/DTX not supported. | 285 // VAD/DTX not supported. |
283 dtx_enabled_ = false; | 286 dtx_enabled_ = false; |
284 } | 287 } |
285 codec_owner_.SetEncoders( | 288 codec_owner_.SetEncoders( |
286 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 289 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
287 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); | 290 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
288 DCHECK(codec_owner_.Encoder()); | 291 DCHECK(codec_owner_.Encoder()); |
289 | 292 |
290 codec_fec_enabled_ = | 293 codec_fec_enabled_ = codec_fec_enabled_ && |
291 codec_fec_enabled_ && | 294 codec_owner_.Encoder()->SetFec(codec_fec_enabled_); |
292 codec_owner_.SpeechEncoder()->SetFec(codec_fec_enabled_); | |
293 | 295 |
294 send_codec_inst_ = send_codec; | 296 send_codec_inst_ = send_codec; |
295 return 0; | 297 return 0; |
296 } | 298 } |
297 | 299 |
298 // This is an existing codec; re-create it if any parameters have changed. | 300 // This is an existing codec; re-create it if any parameters have changed. |
299 if (send_codec_inst_.plfreq != send_codec.plfreq || | 301 if (send_codec_inst_.plfreq != send_codec.plfreq || |
300 send_codec_inst_.pacsize != send_codec.pacsize || | 302 send_codec_inst_.pacsize != send_codec.pacsize || |
301 send_codec_inst_.channels != send_codec.channels) { | 303 send_codec_inst_.channels != send_codec.channels) { |
302 codec_owner_.SetEncoders( | 304 codec_owner_.SetEncoders( |
303 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 305 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
304 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); | 306 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
305 DCHECK(codec_owner_.Encoder()); | 307 DCHECK(codec_owner_.Encoder()); |
306 } | 308 } |
307 send_codec_inst_.plfreq = send_codec.plfreq; | 309 send_codec_inst_.plfreq = send_codec.plfreq; |
308 send_codec_inst_.pacsize = send_codec.pacsize; | 310 send_codec_inst_.pacsize = send_codec.pacsize; |
309 send_codec_inst_.channels = send_codec.channels; | 311 send_codec_inst_.channels = send_codec.channels; |
310 send_codec_inst_.pltype = send_codec.pltype; | 312 send_codec_inst_.pltype = send_codec.pltype; |
311 | 313 |
312 // Check if a change in Rate is required. | 314 // Check if a change in Rate is required. |
313 if (send_codec.rate != send_codec_inst_.rate) { | 315 if (send_codec.rate != send_codec_inst_.rate) { |
314 codec_owner_.SpeechEncoder()->SetTargetBitrate(send_codec.rate); | 316 codec_owner_.Encoder()->SetTargetBitrate(send_codec.rate); |
315 send_codec_inst_.rate = send_codec.rate; | 317 send_codec_inst_.rate = send_codec.rate; |
316 } | 318 } |
317 | 319 |
318 codec_fec_enabled_ = codec_fec_enabled_ && | 320 codec_fec_enabled_ = |
319 codec_owner_.SpeechEncoder()->SetFec(codec_fec_enabled_); | 321 codec_fec_enabled_ && codec_owner_.Encoder()->SetFec(codec_fec_enabled_); |
320 | 322 |
321 return 0; | 323 return 0; |
322 } | 324 } |
323 | 325 |
324 void CodecManager::RegisterEncoder( | 326 void CodecManager::RegisterEncoder(AudioEncoder* external_speech_encoder) { |
325 AudioEncoderMutable* external_speech_encoder) { | |
326 // Make up a CodecInst. | 327 // Make up a CodecInst. |
327 send_codec_inst_.channels = external_speech_encoder->NumChannels(); | 328 send_codec_inst_.channels = external_speech_encoder->NumChannels(); |
328 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); | 329 send_codec_inst_.plfreq = external_speech_encoder->SampleRateHz(); |
329 send_codec_inst_.pacsize = rtc::CheckedDivExact( | 330 send_codec_inst_.pacsize = rtc::CheckedDivExact( |
330 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * | 331 static_cast<int>(external_speech_encoder->Max10MsFramesInAPacket() * |
331 send_codec_inst_.plfreq), | 332 send_codec_inst_.plfreq), |
332 100); | 333 100); |
333 send_codec_inst_.pltype = -1; // Not valid. | 334 send_codec_inst_.pltype = -1; // Not valid. |
334 send_codec_inst_.rate = -1; // Not valid. | 335 send_codec_inst_.rate = -1; // Not valid. |
335 static const char kName[] = "external"; | 336 static const char kName[] = "external"; |
336 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); | 337 memcpy(send_codec_inst_.plname, kName, sizeof(kName)); |
337 | 338 |
338 if (stereo_send_) | 339 if (stereo_send_) |
339 dtx_enabled_ = false; | 340 dtx_enabled_ = false; |
340 codec_fec_enabled_ = codec_fec_enabled_ && | 341 codec_fec_enabled_ = |
341 codec_owner_.SpeechEncoder()->SetFec(codec_fec_enabled_); | 342 codec_fec_enabled_ && codec_owner_.Encoder()->SetFec(codec_fec_enabled_); |
342 int cng_pt = dtx_enabled_ | 343 int cng_pt = dtx_enabled_ |
343 ? CngPayloadType(external_speech_encoder->SampleRateHz()) | 344 ? CngPayloadType(external_speech_encoder->SampleRateHz()) |
344 : -1; | 345 : -1; |
345 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; | 346 int red_pt = red_enabled_ ? RedPayloadType(send_codec_inst_.plfreq) : -1; |
346 codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt); | 347 codec_owner_.SetEncoders(external_speech_encoder, cng_pt, vad_mode_, red_pt); |
347 } | 348 } |
348 | 349 |
349 int CodecManager::GetCodecInst(CodecInst* current_codec) const { | 350 int CodecManager::GetCodecInst(CodecInst* current_codec) const { |
350 int dummy_id = 0; | 351 int dummy_id = 0; |
351 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, | 352 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, dummy_id, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 *mode = vad_mode_; | 424 *mode = vad_mode_; |
424 } | 425 } |
425 | 426 |
426 int CodecManager::SetCodecFEC(bool enable_codec_fec) { | 427 int CodecManager::SetCodecFEC(bool enable_codec_fec) { |
427 if (enable_codec_fec == true && red_enabled_ == true) { | 428 if (enable_codec_fec == true && red_enabled_ == true) { |
428 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, | 429 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, 0, |
429 "Codec internal FEC and RED cannot be co-enabled."); | 430 "Codec internal FEC and RED cannot be co-enabled."); |
430 return -1; | 431 return -1; |
431 } | 432 } |
432 | 433 |
433 CHECK(codec_owner_.SpeechEncoder()); | 434 CHECK(codec_owner_.Encoder()); |
434 codec_fec_enabled_ = codec_owner_.SpeechEncoder()->SetFec(enable_codec_fec) && | 435 codec_fec_enabled_ = |
435 enable_codec_fec; | 436 codec_owner_.Encoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
436 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; | 437 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; |
437 } | 438 } |
438 | 439 |
439 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 440 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
440 return IsIsac(codec) ? codec_owner_.GetIsacDecoder() : nullptr; | 441 return IsIsac(codec) ? codec_owner_.GetIsacDecoder() : nullptr; |
441 } | 442 } |
442 | 443 |
443 int CodecManager::CngPayloadType(int sample_rate_hz) const { | 444 int CodecManager::CngPayloadType(int sample_rate_hz) const { |
444 switch (sample_rate_hz) { | 445 switch (sample_rate_hz) { |
445 case 8000: | 446 case 8000: |
(...skipping 19 matching lines...) Expand all Loading... |
465 case 48000: | 466 case 48000: |
466 return -1; | 467 return -1; |
467 default: | 468 default: |
468 FATAL() << sample_rate_hz << " Hz is not supported"; | 469 FATAL() << sample_rate_hz << " Hz is not supported"; |
469 return -1; | 470 return -1; |
470 } | 471 } |
471 } | 472 } |
472 | 473 |
473 } // namespace acm2 | 474 } // namespace acm2 |
474 } // namespace webrtc | 475 } // namespace webrtc |
OLD | NEW |