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

Side by Side Diff: webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc

Issue 1673213002: AudioCodingModule: Add methods for injecting external encoder stacks (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: more docs Created 4 years, 10 months 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) 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 void AudioCodingModuleImpl::RegisterExternalSendCodec( 216 void AudioCodingModuleImpl::RegisterExternalSendCodec(
217 AudioEncoder* external_speech_encoder) { 217 AudioEncoder* external_speech_encoder) {
218 rtc::CritScope lock(&acm_crit_sect_); 218 rtc::CritScope lock(&acm_crit_sect_);
219 auto* sp = encoder_factory_->codec_manager.GetStackParams(); 219 auto* sp = encoder_factory_->codec_manager.GetStackParams();
220 sp->speech_encoder = external_speech_encoder; 220 sp->speech_encoder = external_speech_encoder;
221 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp); 221 encoder_stack_ = encoder_factory_->rent_a_codec.RentEncoderStack(sp);
222 } 222 }
223 223
224 void AudioCodingModuleImpl::VisitEncoder(const EncoderVisitor& ev) {
hlundin-webrtc 2016/02/10 09:45:46 Rename function to ModifyEncoder, or something sim
225 rtc::CritScope lock(&acm_crit_sect_);
226
227 // Wipe the encoder factory, so that everything that relies on it will fail.
228 // We don't want the complexity of supporting swapping back and forth.
229 encoder_factory_.reset();
230
231 encoder_stack_ = ev(encoder_stack_);
232 }
233
224 // Get current send codec. 234 // Get current send codec.
225 rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const { 235 rtc::Optional<CodecInst> AudioCodingModuleImpl::SendCodec() const {
226 rtc::CritScope lock(&acm_crit_sect_); 236 rtc::CritScope lock(&acm_crit_sect_);
227 auto* ci = encoder_factory_->codec_manager.GetCodecInst(); 237 if (encoder_factory_) {
228 if (ci) { 238 auto* ci = encoder_factory_->codec_manager.GetCodecInst();
229 return rtc::Optional<CodecInst>(*ci); 239 if (ci) {
240 return rtc::Optional<CodecInst>(*ci);
241 }
230 } 242 }
231 auto* enc = encoder_factory_->codec_manager.GetStackParams()->speech_encoder; 243 if (encoder_stack_) {
232 if (enc) { 244 return rtc::Optional<CodecInst>(
233 return rtc::Optional<CodecInst>(CodecManager::ForgeCodecInst(enc)); 245 CodecManager::ForgeCodecInst(encoder_stack_));
234 } 246 }
235 return rtc::Optional<CodecInst>(); 247 return rtc::Optional<CodecInst>();
236 } 248 }
237 249
238 // Get current send frequency. 250 // Get current send frequency.
239 int AudioCodingModuleImpl::SendFrequency() const { 251 int AudioCodingModuleImpl::SendFrequency() const {
240 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 252 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
241 "SendFrequency()"); 253 "SendFrequency()");
242 rtc::CritScope lock(&acm_crit_sect_); 254 rtc::CritScope lock(&acm_crit_sect_);
243 255
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 : receiver_.last_output_sample_rate_hz(); 585 : receiver_.last_output_sample_rate_hz();
574 } 586 }
575 587
576 // Get current playout frequency. 588 // Get current playout frequency.
577 int AudioCodingModuleImpl::PlayoutFrequency() const { 589 int AudioCodingModuleImpl::PlayoutFrequency() const {
578 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 590 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
579 "PlayoutFrequency()"); 591 "PlayoutFrequency()");
580 return receiver_.last_output_sample_rate_hz(); 592 return receiver_.last_output_sample_rate_hz();
581 } 593 }
582 594
583 // Register possible receive codecs, can be called multiple times,
584 // for codecs, CNG (NB, WB and SWB), DTMF, RED.
585 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { 595 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) {
586 rtc::CritScope lock(&acm_crit_sect_); 596 rtc::CritScope lock(&acm_crit_sect_);
597 auto* ef = encoder_factory_.get();
598 return RegisterReceiveCodecUnlocked(
599 codec, [ef] { return ef->rent_a_codec.RentIsacDecoder(); });
600 }
601
602 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec,
603 const DecoderFactory& df) {
604 rtc::CritScope lock(&acm_crit_sect_);
605 return RegisterReceiveCodecUnlocked(codec, df);
606 }
607
608 int AudioCodingModuleImpl::RegisterReceiveCodecUnlocked(
609 const CodecInst& codec,
610 const DecoderFactory& df) {
587 RTC_DCHECK(receiver_initialized_); 611 RTC_DCHECK(receiver_initialized_);
588 if (codec.channels > 2) { 612 if (codec.channels > 2) {
589 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; 613 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels;
590 return -1; 614 return -1;
591 } 615 }
592 616
593 auto codec_id = 617 auto codec_id =
594 RentACodec::CodecIdByParams(codec.plname, codec.plfreq, codec.channels); 618 RentACodec::CodecIdByParams(codec.plname, codec.plfreq, codec.channels);
595 if (!codec_id) { 619 if (!codec_id) {
596 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec"; 620 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec";
597 return -1; 621 return -1;
598 } 622 }
599 auto codec_index = RentACodec::CodecIndexFromId(*codec_id); 623 auto codec_index = RentACodec::CodecIndexFromId(*codec_id);
600 RTC_CHECK(codec_index) << "Invalid codec ID: " << static_cast<int>(*codec_id); 624 RTC_CHECK(codec_index) << "Invalid codec ID: " << static_cast<int>(*codec_id);
601 625
602 // Check if the payload-type is valid. 626 // Check if the payload-type is valid.
603 if (!RentACodec::IsPayloadTypeValid(codec.pltype)) { 627 if (!RentACodec::IsPayloadTypeValid(codec.pltype)) {
604 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for " 628 LOG_F(LS_ERROR) << "Invalid payload type " << codec.pltype << " for "
605 << codec.plname; 629 << codec.plname;
606 return -1; 630 return -1;
607 } 631 }
608 632
609 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does 633 // Get |decoder| associated with |codec|. |decoder| is NULL if |codec| does
610 // not own its decoder. 634 // not own its decoder.
611 return receiver_.AddCodec( 635 return receiver_.AddCodec(
612 *codec_index, codec.pltype, codec.channels, codec.plfreq, 636 *codec_index, codec.pltype, codec.channels, codec.plfreq,
613 STR_CASE_CMP(codec.plname, "isac") == 0 637 STR_CASE_CMP(codec.plname, "isac") == 0 ? df() : nullptr, codec.plname);
614 ? encoder_factory_->rent_a_codec.RentIsacDecoder()
615 : nullptr,
616 codec.plname);
617 } 638 }
618 639
619 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( 640 int AudioCodingModuleImpl::RegisterExternalReceiveCodec(
620 int rtp_payload_type, 641 int rtp_payload_type,
621 AudioDecoder* external_decoder, 642 AudioDecoder* external_decoder,
622 int sample_rate_hz, 643 int sample_rate_hz,
623 int num_channels, 644 int num_channels,
624 const std::string& name) { 645 const std::string& name) {
625 rtc::CritScope lock(&acm_crit_sect_); 646 rtc::CritScope lock(&acm_crit_sect_);
626 RTC_DCHECK(receiver_initialized_); 647 RTC_DCHECK(receiver_initialized_);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 return receiver_.LeastRequiredDelayMs(); 837 return receiver_.LeastRequiredDelayMs();
817 } 838 }
818 839
819 void AudioCodingModuleImpl::GetDecodingCallStatistics( 840 void AudioCodingModuleImpl::GetDecodingCallStatistics(
820 AudioDecodingCallStats* call_stats) const { 841 AudioDecodingCallStats* call_stats) const {
821 receiver_.GetDecodingCallStatistics(call_stats); 842 receiver_.GetDecodingCallStatistics(call_stats);
822 } 843 }
823 844
824 } // namespace acm2 845 } // namespace acm2
825 } // namespace webrtc 846 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h ('k') | webrtc/modules/audio_coding/include/audio_coding_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698