| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 18 matching lines...) Expand all Loading... |
| 29 #include "webrtc/typedefs.h" | 29 #include "webrtc/typedefs.h" |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 namespace acm2 { | 33 namespace acm2 { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // TODO(turajs): the same functionality is used in NetEq. If both classes | 37 // TODO(turajs): the same functionality is used in NetEq. If both classes |
| 38 // need them, make it a static function in ACMCodecDB. | 38 // need them, make it a static function in ACMCodecDB. |
| 39 bool IsCodecRED(const CodecInst* codec) { | 39 bool IsCodecRED(const CodecInst& codec) { |
| 40 return (STR_CASE_CMP(codec->plname, "RED") == 0); | 40 return (STR_CASE_CMP(codec.plname, "RED") == 0); |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool IsCodecRED(int index) { | 43 bool IsCodecCN(const CodecInst& codec) { |
| 44 return (IsCodecRED(&ACMCodecDB::database_[index])); | 44 return (STR_CASE_CMP(codec.plname, "CN") == 0); |
| 45 } | |
| 46 | |
| 47 bool IsCodecCN(const CodecInst* codec) { | |
| 48 return (STR_CASE_CMP(codec->plname, "CN") == 0); | |
| 49 } | |
| 50 | |
| 51 bool IsCodecCN(int index) { | |
| 52 return (IsCodecCN(&ACMCodecDB::database_[index])); | |
| 53 } | 45 } |
| 54 | 46 |
| 55 // Stereo-to-mono can be used as in-place. | 47 // Stereo-to-mono can be used as in-place. |
| 56 int DownMix(const AudioFrame& frame, | 48 int DownMix(const AudioFrame& frame, |
| 57 size_t length_out_buff, | 49 size_t length_out_buff, |
| 58 int16_t* out_buff) { | 50 int16_t* out_buff) { |
| 59 if (length_out_buff < frame.samples_per_channel_) { | 51 if (length_out_buff < frame.samples_per_channel_) { |
| 60 return -1; | 52 return -1; |
| 61 } | 53 } |
| 62 for (size_t n = 0; n < frame.samples_per_channel_; ++n) | 54 for (size_t n = 0; n < frame.samples_per_channel_; ++n) |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (receiver_.RemoveAllCodecs() < 0) | 498 if (receiver_.RemoveAllCodecs() < 0) |
| 507 return -1; | 499 return -1; |
| 508 } | 500 } |
| 509 receiver_.set_id(id_); | 501 receiver_.set_id(id_); |
| 510 receiver_.ResetInitialDelay(); | 502 receiver_.ResetInitialDelay(); |
| 511 receiver_.SetMinimumDelay(0); | 503 receiver_.SetMinimumDelay(0); |
| 512 receiver_.SetMaximumDelay(0); | 504 receiver_.SetMaximumDelay(0); |
| 513 receiver_.FlushBuffers(); | 505 receiver_.FlushBuffers(); |
| 514 | 506 |
| 515 // Register RED and CN. | 507 // Register RED and CN. |
| 516 for (int i = 0; i < ACMCodecDB::kNumCodecs; i++) { | 508 auto db = RentACodec::Database(); |
| 517 if (IsCodecRED(i) || IsCodecCN(i)) { | 509 for (size_t i = 0; i < db.size(); i++) { |
| 518 uint8_t pl_type = static_cast<uint8_t>(ACMCodecDB::database_[i].pltype); | 510 if (IsCodecRED(db[i]) || IsCodecCN(db[i])) { |
| 519 int fs = ACMCodecDB::database_[i].plfreq; | 511 if (receiver_.AddCodec(static_cast<int>(i), |
| 520 if (receiver_.AddCodec(i, pl_type, 1, fs, NULL) < 0) { | 512 static_cast<uint8_t>(db[i].pltype), 1, |
| 513 db[i].plfreq, nullptr) < 0) { |
| 521 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, | 514 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, |
| 522 "Cannot register master codec."); | 515 "Cannot register master codec."); |
| 523 return -1; | 516 return -1; |
| 524 } | 517 } |
| 525 } | 518 } |
| 526 } | 519 } |
| 527 receiver_initialized_ = true; | 520 receiver_initialized_ = true; |
| 528 return 0; | 521 return 0; |
| 529 } | 522 } |
| 530 | 523 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 554 // Register possible receive codecs, can be called multiple times, | 547 // Register possible receive codecs, can be called multiple times, |
| 555 // for codecs, CNG (NB, WB and SWB), DTMF, RED. | 548 // for codecs, CNG (NB, WB and SWB), DTMF, RED. |
| 556 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { | 549 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { |
| 557 CriticalSectionScoped lock(acm_crit_sect_.get()); | 550 CriticalSectionScoped lock(acm_crit_sect_.get()); |
| 558 RTC_DCHECK(receiver_initialized_); | 551 RTC_DCHECK(receiver_initialized_); |
| 559 if (codec.channels > 2 || codec.channels < 0) { | 552 if (codec.channels > 2 || codec.channels < 0) { |
| 560 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; | 553 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; |
| 561 return -1; | 554 return -1; |
| 562 } | 555 } |
| 563 | 556 |
| 564 int codec_id = ACMCodecDB::ReceiverCodecNumber(codec); | 557 auto codec_id = |
| 565 if (codec_id < 0 || codec_id >= ACMCodecDB::kNumCodecs) { | 558 RentACodec::CodecIdByParams(codec.plname, codec.plfreq, codec.channels); |
| 559 if (!codec_id) { |
| 566 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec"; | 560 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec"; |
| 567 return -1; | 561 return -1; |
| 568 } | 562 } |
| 563 auto codec_index = RentACodec::CodecIndexFromId(*codec_id); |
| 564 RTC_CHECK(codec_index) << "Invalid codec ID: " << static_cast<int>(*codec_id); |
| 569 | 565 |
| 570 // Check if the payload-type is valid. | 566 // Check if the payload-type is valid. |
| 571 if (!ACMCodecDB::ValidPayloadType(codec.pltype)) { | 567 if (!ACMCodecDB::ValidPayloadType(codec.pltype)) { |
| 572 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " | 568 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " |
| 573 << codec.plname; | 569 << codec.plname; |
| 574 return -1; | 570 return -1; |
| 575 } | 571 } |
| 576 | 572 |
| 577 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does | 573 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does |
| 578 // not own its decoder. | 574 // not own its decoder. |
| 579 return receiver_.AddCodec(codec_id, codec.pltype, codec.channels, | 575 return receiver_.AddCodec(*codec_index, codec.pltype, codec.channels, |
| 580 codec.plfreq, | 576 codec.plfreq, |
| 581 codec_manager_.GetAudioDecoder(codec)); | 577 codec_manager_.GetAudioDecoder(codec)); |
| 582 } | 578 } |
| 583 | 579 |
| 584 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( | 580 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( |
| 585 int rtp_payload_type, | 581 int rtp_payload_type, |
| 586 AudioDecoder* external_decoder, | 582 AudioDecoder* external_decoder, |
| 587 int sample_rate_hz, | 583 int sample_rate_hz, |
| 588 int num_channels) { | 584 int num_channels) { |
| 589 CriticalSectionScoped lock(acm_crit_sect_.get()); | 585 CriticalSectionScoped lock(acm_crit_sect_.get()); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 return receiver_.LeastRequiredDelayMs(); | 793 return receiver_.LeastRequiredDelayMs(); |
| 798 } | 794 } |
| 799 | 795 |
| 800 void AudioCodingModuleImpl::GetDecodingCallStatistics( | 796 void AudioCodingModuleImpl::GetDecodingCallStatistics( |
| 801 AudioDecodingCallStats* call_stats) const { | 797 AudioDecodingCallStats* call_stats) const { |
| 802 receiver_.GetDecodingCallStatistics(call_stats); | 798 receiver_.GetDecodingCallStatistics(call_stats); |
| 803 } | 799 } |
| 804 | 800 |
| 805 } // namespace acm2 | 801 } // namespace acm2 |
| 806 } // namespace webrtc | 802 } // namespace webrtc |
| OLD | NEW |