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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 encoder_is_opus_ = IsOpus(send_codec); | 258 encoder_is_opus_ = IsOpus(send_codec); |
259 | 259 |
260 if (new_codec) { | 260 if (new_codec) { |
261 // This is a new codec. Register it and return. | 261 // This is a new codec. Register it and return. |
262 RTC_DCHECK(CodecSupported(send_codec)); | 262 RTC_DCHECK(CodecSupported(send_codec)); |
263 if (IsOpus(send_codec)) { | 263 if (IsOpus(send_codec)) { |
264 // VAD/DTX not supported. | 264 // VAD/DTX not supported. |
265 dtx_enabled_ = false; | 265 dtx_enabled_ = false; |
266 } | 266 } |
267 if (!codec_owner_.SetEncoders( | 267 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
268 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 268 if (!enc) |
269 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1)) | |
270 return -1; | 269 return -1; |
| 270 codec_owner_.SetEncoders( |
| 271 enc, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
| 272 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
271 RTC_DCHECK(codec_owner_.Encoder()); | 273 RTC_DCHECK(codec_owner_.Encoder()); |
272 | 274 |
273 codec_fec_enabled_ = codec_fec_enabled_ && | 275 codec_fec_enabled_ = codec_fec_enabled_ && |
274 codec_owner_.Encoder()->SetFec(codec_fec_enabled_); | 276 enc->SetFec(codec_fec_enabled_); |
275 | 277 |
276 send_codec_inst_ = send_codec; | 278 send_codec_inst_ = send_codec; |
277 return 0; | 279 return 0; |
278 } | 280 } |
279 | 281 |
280 // This is an existing codec; re-create it if any parameters have changed. | 282 // This is an existing codec; re-create it if any parameters have changed. |
281 if (send_codec_inst_.plfreq != send_codec.plfreq || | 283 if (send_codec_inst_.plfreq != send_codec.plfreq || |
282 send_codec_inst_.pacsize != send_codec.pacsize || | 284 send_codec_inst_.pacsize != send_codec.pacsize || |
283 send_codec_inst_.channels != send_codec.channels) { | 285 send_codec_inst_.channels != send_codec.channels) { |
284 if (!codec_owner_.SetEncoders( | 286 AudioEncoder* enc = rent_a_codec_.RentEncoder(send_codec); |
285 send_codec, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, | 287 if (!enc) |
286 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1)) | |
287 return -1; | 288 return -1; |
| 289 codec_owner_.SetEncoders( |
| 290 enc, dtx_enabled_ ? CngPayloadType(send_codec.plfreq) : -1, |
| 291 vad_mode_, red_enabled_ ? RedPayloadType(send_codec.plfreq) : -1); |
288 RTC_DCHECK(codec_owner_.Encoder()); | 292 RTC_DCHECK(codec_owner_.Encoder()); |
289 } | 293 } |
290 send_codec_inst_.plfreq = send_codec.plfreq; | 294 send_codec_inst_.plfreq = send_codec.plfreq; |
291 send_codec_inst_.pacsize = send_codec.pacsize; | 295 send_codec_inst_.pacsize = send_codec.pacsize; |
292 send_codec_inst_.channels = send_codec.channels; | 296 send_codec_inst_.channels = send_codec.channels; |
293 send_codec_inst_.pltype = send_codec.pltype; | 297 send_codec_inst_.pltype = send_codec.pltype; |
294 | 298 |
295 // Check if a change in Rate is required. | 299 // Check if a change in Rate is required. |
296 if (send_codec.rate != send_codec_inst_.rate) { | 300 if (send_codec.rate != send_codec_inst_.rate) { |
297 codec_owner_.Encoder()->SetTargetBitrate(send_codec.rate); | 301 codec_owner_.Encoder()->SetTargetBitrate(send_codec.rate); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 return -1; | 415 return -1; |
412 } | 416 } |
413 | 417 |
414 RTC_CHECK(codec_owner_.Encoder()); | 418 RTC_CHECK(codec_owner_.Encoder()); |
415 codec_fec_enabled_ = | 419 codec_fec_enabled_ = |
416 codec_owner_.Encoder()->SetFec(enable_codec_fec) && enable_codec_fec; | 420 codec_owner_.Encoder()->SetFec(enable_codec_fec) && enable_codec_fec; |
417 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; | 421 return codec_fec_enabled_ == enable_codec_fec ? 0 : -1; |
418 } | 422 } |
419 | 423 |
420 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { | 424 AudioDecoder* CodecManager::GetAudioDecoder(const CodecInst& codec) { |
421 return IsIsac(codec) ? codec_owner_.GetIsacDecoder() : nullptr; | 425 return IsIsac(codec) ? rent_a_codec_.RentIsacDecoder() : nullptr; |
422 } | 426 } |
423 | 427 |
424 int CodecManager::CngPayloadType(int sample_rate_hz) const { | 428 int CodecManager::CngPayloadType(int sample_rate_hz) const { |
425 switch (sample_rate_hz) { | 429 switch (sample_rate_hz) { |
426 case 8000: | 430 case 8000: |
427 return cng_nb_pltype_; | 431 return cng_nb_pltype_; |
428 case 16000: | 432 case 16000: |
429 return cng_wb_pltype_; | 433 return cng_wb_pltype_; |
430 case 32000: | 434 case 32000: |
431 return cng_swb_pltype_; | 435 return cng_swb_pltype_; |
(...skipping 14 matching lines...) Expand all Loading... |
446 case 48000: | 450 case 48000: |
447 return -1; | 451 return -1; |
448 default: | 452 default: |
449 FATAL() << sample_rate_hz << " Hz is not supported"; | 453 FATAL() << sample_rate_hz << " Hz is not supported"; |
450 return -1; | 454 return -1; |
451 } | 455 } |
452 } | 456 } |
453 | 457 |
454 } // namespace acm2 | 458 } // namespace acm2 |
455 } // namespace webrtc | 459 } // namespace webrtc |
OLD | NEW |