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

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

Issue 1310213003: Get rid of the manual destructor in AudioCodingModuleImpl (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@remove-unused
Patch Set: error: [chromium-style] Complex class/struct needs an explicit out-of-line destructor. Created 5 years, 3 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 AudioCodingModuleImpl::AudioCodingModuleImpl( 135 AudioCodingModuleImpl::AudioCodingModuleImpl(
136 const AudioCodingModule::Config& config) 136 const AudioCodingModule::Config& config)
137 : acm_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 137 : acm_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
138 id_(config.id), 138 id_(config.id),
139 expected_codec_ts_(0xD87F3F9F), 139 expected_codec_ts_(0xD87F3F9F),
140 expected_in_ts_(0xD87F3F9F), 140 expected_in_ts_(0xD87F3F9F),
141 receiver_(config), 141 receiver_(config),
142 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), 142 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"),
143 previous_pltype_(255), 143 previous_pltype_(255),
144 aux_rtp_header_(NULL),
145 receiver_initialized_(false), 144 receiver_initialized_(false),
146 first_10ms_data_(false), 145 first_10ms_data_(false),
147 first_frame_(true), 146 first_frame_(true),
148 callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), 147 callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
149 packetization_callback_(NULL), 148 packetization_callback_(NULL),
150 vad_callback_(NULL) { 149 vad_callback_(NULL) {
151 if (InitializeReceiverSafe() < 0) { 150 if (InitializeReceiverSafe() < 0) {
152 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 151 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
153 "Cannot initialize receiver"); 152 "Cannot initialize receiver");
154 } 153 }
155 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); 154 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created");
156 } 155 }
157 156
158 AudioCodingModuleImpl::~AudioCodingModuleImpl() { 157 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default;
159 if (aux_rtp_header_ != NULL) {
160 delete aux_rtp_header_;
161 aux_rtp_header_ = NULL;
162 }
163
164 delete callback_crit_sect_;
165 callback_crit_sect_ = NULL;
166
167 delete acm_crit_sect_;
168 acm_crit_sect_ = NULL;
169 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_,
170 "Destroyed");
171 }
172 158
173 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { 159 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) {
174 uint8_t stream[2 * MAX_PAYLOAD_SIZE_BYTE]; // Make room for 1 RED payload. 160 uint8_t stream[2 * MAX_PAYLOAD_SIZE_BYTE]; // Make room for 1 RED payload.
175 AudioEncoder::EncodedInfo encoded_info; 161 AudioEncoder::EncodedInfo encoded_info;
176 uint8_t previous_pltype; 162 uint8_t previous_pltype;
177 163
178 // Check if there is an encoder before. 164 // Check if there is an encoder before.
179 if (!HaveValidEncoder("Process")) 165 if (!HaveValidEncoder("Process"))
180 return -1; 166 return -1;
181 167
(...skipping 26 matching lines...) Expand all
208 FrameType frame_type; 194 FrameType frame_type;
209 if (encoded_info.encoded_bytes == 0 && encoded_info.send_even_if_empty) { 195 if (encoded_info.encoded_bytes == 0 && encoded_info.send_even_if_empty) {
210 frame_type = kFrameEmpty; 196 frame_type = kFrameEmpty;
211 encoded_info.payload_type = previous_pltype; 197 encoded_info.payload_type = previous_pltype;
212 } else { 198 } else {
213 DCHECK_GT(encoded_info.encoded_bytes, 0u); 199 DCHECK_GT(encoded_info.encoded_bytes, 0u);
214 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN; 200 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN;
215 } 201 }
216 202
217 { 203 {
218 CriticalSectionScoped lock(callback_crit_sect_); 204 CriticalSectionScoped lock(callback_crit_sect_.get());
219 if (packetization_callback_) { 205 if (packetization_callback_) {
220 packetization_callback_->SendData( 206 packetization_callback_->SendData(
221 frame_type, encoded_info.payload_type, encoded_info.encoded_timestamp, 207 frame_type, encoded_info.payload_type, encoded_info.encoded_timestamp,
222 stream, encoded_info.encoded_bytes, 208 stream, encoded_info.encoded_bytes,
223 my_fragmentation.fragmentationVectorSize > 0 ? &my_fragmentation 209 my_fragmentation.fragmentationVectorSize > 0 ? &my_fragmentation
224 : nullptr); 210 : nullptr);
225 } 211 }
226 212
227 if (vad_callback_) { 213 if (vad_callback_) {
228 // Callback with VAD decision. 214 // Callback with VAD decision.
229 vad_callback_->InFrameType(frame_type); 215 vad_callback_->InFrameType(frame_type);
230 } 216 }
231 } 217 }
232 previous_pltype_ = encoded_info.payload_type; 218 previous_pltype_ = encoded_info.payload_type;
233 return static_cast<int32_t>(encoded_info.encoded_bytes); 219 return static_cast<int32_t>(encoded_info.encoded_bytes);
234 } 220 }
235 221
236 ///////////////////////////////////////// 222 /////////////////////////////////////////
237 // Sender 223 // Sender
238 // 224 //
239 225
240 // Can be called multiple times for Codec, CNG, RED. 226 // Can be called multiple times for Codec, CNG, RED.
241 int AudioCodingModuleImpl::RegisterSendCodec(const CodecInst& send_codec) { 227 int AudioCodingModuleImpl::RegisterSendCodec(const CodecInst& send_codec) {
242 CriticalSectionScoped lock(acm_crit_sect_); 228 CriticalSectionScoped lock(acm_crit_sect_.get());
243 return codec_manager_.RegisterEncoder(send_codec); 229 return codec_manager_.RegisterEncoder(send_codec);
244 } 230 }
245 231
246 void AudioCodingModuleImpl::RegisterExternalSendCodec( 232 void AudioCodingModuleImpl::RegisterExternalSendCodec(
247 AudioEncoderMutable* external_speech_encoder) { 233 AudioEncoderMutable* external_speech_encoder) {
248 CriticalSectionScoped lock(acm_crit_sect_); 234 CriticalSectionScoped lock(acm_crit_sect_.get());
249 codec_manager_.RegisterEncoder(external_speech_encoder); 235 codec_manager_.RegisterEncoder(external_speech_encoder);
250 } 236 }
251 237
252 // Get current send codec. 238 // Get current send codec.
253 int AudioCodingModuleImpl::SendCodec(CodecInst* current_codec) const { 239 int AudioCodingModuleImpl::SendCodec(CodecInst* current_codec) const {
254 CriticalSectionScoped lock(acm_crit_sect_); 240 CriticalSectionScoped lock(acm_crit_sect_.get());
255 return codec_manager_.GetCodecInst(current_codec); 241 return codec_manager_.GetCodecInst(current_codec);
256 } 242 }
257 243
258 // Get current send frequency. 244 // Get current send frequency.
259 int AudioCodingModuleImpl::SendFrequency() const { 245 int AudioCodingModuleImpl::SendFrequency() const {
260 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 246 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
261 "SendFrequency()"); 247 "SendFrequency()");
262 CriticalSectionScoped lock(acm_crit_sect_); 248 CriticalSectionScoped lock(acm_crit_sect_.get());
263 249
264 if (!codec_manager_.CurrentEncoder()) { 250 if (!codec_manager_.CurrentEncoder()) {
265 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 251 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
266 "SendFrequency Failed, no codec is registered"); 252 "SendFrequency Failed, no codec is registered");
267 return -1; 253 return -1;
268 } 254 }
269 255
270 return codec_manager_.CurrentEncoder()->SampleRateHz(); 256 return codec_manager_.CurrentEncoder()->SampleRateHz();
271 } 257 }
272 258
273 void AudioCodingModuleImpl::SetBitRate(int bitrate_bps) { 259 void AudioCodingModuleImpl::SetBitRate(int bitrate_bps) {
274 CriticalSectionScoped lock(acm_crit_sect_); 260 CriticalSectionScoped lock(acm_crit_sect_.get());
275 if (codec_manager_.CurrentEncoder()) { 261 if (codec_manager_.CurrentEncoder()) {
276 codec_manager_.CurrentEncoder()->SetTargetBitrate(bitrate_bps); 262 codec_manager_.CurrentEncoder()->SetTargetBitrate(bitrate_bps);
277 } 263 }
278 } 264 }
279 265
280 // Register a transport callback which will be called to deliver 266 // Register a transport callback which will be called to deliver
281 // the encoded buffers. 267 // the encoded buffers.
282 int AudioCodingModuleImpl::RegisterTransportCallback( 268 int AudioCodingModuleImpl::RegisterTransportCallback(
283 AudioPacketizationCallback* transport) { 269 AudioPacketizationCallback* transport) {
284 CriticalSectionScoped lock(callback_crit_sect_); 270 CriticalSectionScoped lock(callback_crit_sect_.get());
285 packetization_callback_ = transport; 271 packetization_callback_ = transport;
286 return 0; 272 return 0;
287 } 273 }
288 274
289 // Add 10MS of raw (PCM) audio data to the encoder. 275 // Add 10MS of raw (PCM) audio data to the encoder.
290 int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) { 276 int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) {
291 InputData input_data; 277 InputData input_data;
292 CriticalSectionScoped lock(acm_crit_sect_); 278 CriticalSectionScoped lock(acm_crit_sect_.get());
293 int r = Add10MsDataInternal(audio_frame, &input_data); 279 int r = Add10MsDataInternal(audio_frame, &input_data);
294 return r < 0 ? r : Encode(input_data); 280 return r < 0 ? r : Encode(input_data);
295 } 281 }
296 282
297 int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame, 283 int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame,
298 InputData* input_data) { 284 InputData* input_data) {
299 if (audio_frame.samples_per_channel_ == 0) { 285 if (audio_frame.samples_per_channel_ == 0) {
300 assert(false); 286 assert(false);
301 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 287 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
302 "Cannot Add 10 ms audio, payload length is zero"); 288 "Cannot Add 10 ms audio, payload length is zero");
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); 442 expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_);
457 443
458 return 0; 444 return 0;
459 } 445 }
460 446
461 ///////////////////////////////////////// 447 /////////////////////////////////////////
462 // (RED) Redundant Coding 448 // (RED) Redundant Coding
463 // 449 //
464 450
465 bool AudioCodingModuleImpl::REDStatus() const { 451 bool AudioCodingModuleImpl::REDStatus() const {
466 CriticalSectionScoped lock(acm_crit_sect_); 452 CriticalSectionScoped lock(acm_crit_sect_.get());
467 return codec_manager_.red_enabled(); 453 return codec_manager_.red_enabled();
468 } 454 }
469 455
470 // Configure RED status i.e on/off. 456 // Configure RED status i.e on/off.
471 int AudioCodingModuleImpl::SetREDStatus( 457 int AudioCodingModuleImpl::SetREDStatus(
472 #ifdef WEBRTC_CODEC_RED 458 #ifdef WEBRTC_CODEC_RED
473 bool enable_red) { 459 bool enable_red) {
474 CriticalSectionScoped lock(acm_crit_sect_); 460 CriticalSectionScoped lock(acm_crit_sect_.get());
475 return codec_manager_.SetCopyRed(enable_red) ? 0 : -1; 461 return codec_manager_.SetCopyRed(enable_red) ? 0 : -1;
476 #else 462 #else
477 bool /* enable_red */) { 463 bool /* enable_red */) {
478 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_, 464 WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, id_,
479 " WEBRTC_CODEC_RED is undefined"); 465 " WEBRTC_CODEC_RED is undefined");
480 return -1; 466 return -1;
481 #endif 467 #endif
482 } 468 }
483 469
484 ///////////////////////////////////////// 470 /////////////////////////////////////////
485 // (FEC) Forward Error Correction (codec internal) 471 // (FEC) Forward Error Correction (codec internal)
486 // 472 //
487 473
488 bool AudioCodingModuleImpl::CodecFEC() const { 474 bool AudioCodingModuleImpl::CodecFEC() const {
489 CriticalSectionScoped lock(acm_crit_sect_); 475 CriticalSectionScoped lock(acm_crit_sect_.get());
490 return codec_manager_.codec_fec_enabled(); 476 return codec_manager_.codec_fec_enabled();
491 } 477 }
492 478
493 int AudioCodingModuleImpl::SetCodecFEC(bool enable_codec_fec) { 479 int AudioCodingModuleImpl::SetCodecFEC(bool enable_codec_fec) {
494 CriticalSectionScoped lock(acm_crit_sect_); 480 CriticalSectionScoped lock(acm_crit_sect_.get());
495 return codec_manager_.SetCodecFEC(enable_codec_fec); 481 return codec_manager_.SetCodecFEC(enable_codec_fec);
496 } 482 }
497 483
498 int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) { 484 int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) {
499 CriticalSectionScoped lock(acm_crit_sect_); 485 CriticalSectionScoped lock(acm_crit_sect_.get());
500 if (HaveValidEncoder("SetPacketLossRate")) { 486 if (HaveValidEncoder("SetPacketLossRate")) {
501 codec_manager_.CurrentSpeechEncoder()->SetProjectedPacketLossRate( 487 codec_manager_.CurrentSpeechEncoder()->SetProjectedPacketLossRate(
502 loss_rate / 100.0); 488 loss_rate / 100.0);
503 } 489 }
504 return 0; 490 return 0;
505 } 491 }
506 492
507 ///////////////////////////////////////// 493 /////////////////////////////////////////
508 // (VAD) Voice Activity Detection 494 // (VAD) Voice Activity Detection
509 // 495 //
510 int AudioCodingModuleImpl::SetVAD(bool enable_dtx, 496 int AudioCodingModuleImpl::SetVAD(bool enable_dtx,
511 bool enable_vad, 497 bool enable_vad,
512 ACMVADMode mode) { 498 ACMVADMode mode) {
513 // Note: |enable_vad| is not used; VAD is enabled based on the DTX setting. 499 // Note: |enable_vad| is not used; VAD is enabled based on the DTX setting.
514 DCHECK_EQ(enable_dtx, enable_vad); 500 DCHECK_EQ(enable_dtx, enable_vad);
515 CriticalSectionScoped lock(acm_crit_sect_); 501 CriticalSectionScoped lock(acm_crit_sect_.get());
516 return codec_manager_.SetVAD(enable_dtx, mode); 502 return codec_manager_.SetVAD(enable_dtx, mode);
517 } 503 }
518 504
519 // Get VAD/DTX settings. 505 // Get VAD/DTX settings.
520 int AudioCodingModuleImpl::VAD(bool* dtx_enabled, bool* vad_enabled, 506 int AudioCodingModuleImpl::VAD(bool* dtx_enabled, bool* vad_enabled,
521 ACMVADMode* mode) const { 507 ACMVADMode* mode) const {
522 CriticalSectionScoped lock(acm_crit_sect_); 508 CriticalSectionScoped lock(acm_crit_sect_.get());
523 codec_manager_.VAD(dtx_enabled, vad_enabled, mode); 509 codec_manager_.VAD(dtx_enabled, vad_enabled, mode);
524 return 0; 510 return 0;
525 } 511 }
526 512
527 ///////////////////////////////////////// 513 /////////////////////////////////////////
528 // Receiver 514 // Receiver
529 // 515 //
530 516
531 int AudioCodingModuleImpl::InitializeReceiver() { 517 int AudioCodingModuleImpl::InitializeReceiver() {
532 CriticalSectionScoped lock(acm_crit_sect_); 518 CriticalSectionScoped lock(acm_crit_sect_.get());
533 return InitializeReceiverSafe(); 519 return InitializeReceiverSafe();
534 } 520 }
535 521
536 // Initialize receiver, resets codec database etc. 522 // Initialize receiver, resets codec database etc.
537 int AudioCodingModuleImpl::InitializeReceiverSafe() { 523 int AudioCodingModuleImpl::InitializeReceiverSafe() {
538 // If the receiver is already initialized then we want to destroy any 524 // If the receiver is already initialized then we want to destroy any
539 // existing decoders. After a call to this function, we should have a clean 525 // existing decoders. After a call to this function, we should have a clean
540 // start-up. 526 // start-up.
541 if (receiver_initialized_) { 527 if (receiver_initialized_) {
542 if (receiver_.RemoveAllCodecs() < 0) 528 if (receiver_.RemoveAllCodecs() < 0)
(...skipping 19 matching lines...) Expand all
562 } 548 }
563 receiver_initialized_ = true; 549 receiver_initialized_ = true;
564 return 0; 550 return 0;
565 } 551 }
566 552
567 // Get current receive frequency. 553 // Get current receive frequency.
568 int AudioCodingModuleImpl::ReceiveFrequency() const { 554 int AudioCodingModuleImpl::ReceiveFrequency() const {
569 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 555 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
570 "ReceiveFrequency()"); 556 "ReceiveFrequency()");
571 557
572 CriticalSectionScoped lock(acm_crit_sect_); 558 CriticalSectionScoped lock(acm_crit_sect_.get());
573 559
574 int codec_id = receiver_.last_audio_codec_id(); 560 int codec_id = receiver_.last_audio_codec_id();
575 561
576 return codec_id < 0 ? receiver_.current_sample_rate_hz() : 562 return codec_id < 0 ? receiver_.current_sample_rate_hz() :
577 ACMCodecDB::database_[codec_id].plfreq; 563 ACMCodecDB::database_[codec_id].plfreq;
578 } 564 }
579 565
580 // Get current playout frequency. 566 // Get current playout frequency.
581 int AudioCodingModuleImpl::PlayoutFrequency() const { 567 int AudioCodingModuleImpl::PlayoutFrequency() const {
582 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_, 568 WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
583 "PlayoutFrequency()"); 569 "PlayoutFrequency()");
584 570
585 CriticalSectionScoped lock(acm_crit_sect_); 571 CriticalSectionScoped lock(acm_crit_sect_.get());
586 572
587 return receiver_.current_sample_rate_hz(); 573 return receiver_.current_sample_rate_hz();
588 } 574 }
589 575
590 // Register possible receive codecs, can be called multiple times, 576 // Register possible receive codecs, can be called multiple times,
591 // for codecs, CNG (NB, WB and SWB), DTMF, RED. 577 // for codecs, CNG (NB, WB and SWB), DTMF, RED.
592 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) { 578 int AudioCodingModuleImpl::RegisterReceiveCodec(const CodecInst& codec) {
593 CriticalSectionScoped lock(acm_crit_sect_); 579 CriticalSectionScoped lock(acm_crit_sect_.get());
594 DCHECK(receiver_initialized_); 580 DCHECK(receiver_initialized_);
595 if (codec.channels > 2 || codec.channels < 0) { 581 if (codec.channels > 2 || codec.channels < 0) {
596 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels; 582 LOG_F(LS_ERROR) << "Unsupported number of channels: " << codec.channels;
597 return -1; 583 return -1;
598 } 584 }
599 585
600 int codec_id = ACMCodecDB::ReceiverCodecNumber(codec); 586 int codec_id = ACMCodecDB::ReceiverCodecNumber(codec);
601 if (codec_id < 0 || codec_id >= ACMCodecDB::kNumCodecs) { 587 if (codec_id < 0 || codec_id >= ACMCodecDB::kNumCodecs) {
602 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec"; 588 LOG_F(LS_ERROR) << "Wrong codec params to be registered as receive codec";
603 return -1; 589 return -1;
(...skipping 11 matching lines...) Expand all
615 return receiver_.AddCodec(codec_id, codec.pltype, codec.channels, 601 return receiver_.AddCodec(codec_id, codec.pltype, codec.channels,
616 codec.plfreq, 602 codec.plfreq,
617 codec_manager_.GetAudioDecoder(codec)); 603 codec_manager_.GetAudioDecoder(codec));
618 } 604 }
619 605
620 int AudioCodingModuleImpl::RegisterExternalReceiveCodec( 606 int AudioCodingModuleImpl::RegisterExternalReceiveCodec(
621 int rtp_payload_type, 607 int rtp_payload_type,
622 AudioDecoder* external_decoder, 608 AudioDecoder* external_decoder,
623 int sample_rate_hz, 609 int sample_rate_hz,
624 int num_channels) { 610 int num_channels) {
625 CriticalSectionScoped lock(acm_crit_sect_); 611 CriticalSectionScoped lock(acm_crit_sect_.get());
626 DCHECK(receiver_initialized_); 612 DCHECK(receiver_initialized_);
627 if (num_channels > 2 || num_channels < 0) { 613 if (num_channels > 2 || num_channels < 0) {
628 LOG_F(LS_ERROR) << "Unsupported number of channels: " << num_channels; 614 LOG_F(LS_ERROR) << "Unsupported number of channels: " << num_channels;
629 return -1; 615 return -1;
630 } 616 }
631 617
632 // Check if the payload-type is valid. 618 // Check if the payload-type is valid.
633 if (!ACMCodecDB::ValidPayloadType(rtp_payload_type)) { 619 if (!ACMCodecDB::ValidPayloadType(rtp_payload_type)) {
634 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type 620 LOG_F(LS_ERROR) << "Invalid payload-type " << rtp_payload_type
635 << " for external decoder."; 621 << " for external decoder.";
636 return -1; 622 return -1;
637 } 623 }
638 624
639 return receiver_.AddCodec(-1 /* external */, rtp_payload_type, num_channels, 625 return receiver_.AddCodec(-1 /* external */, rtp_payload_type, num_channels,
640 sample_rate_hz, external_decoder); 626 sample_rate_hz, external_decoder);
641 } 627 }
642 628
643 // Get current received codec. 629 // Get current received codec.
644 int AudioCodingModuleImpl::ReceiveCodec(CodecInst* current_codec) const { 630 int AudioCodingModuleImpl::ReceiveCodec(CodecInst* current_codec) const {
645 CriticalSectionScoped lock(acm_crit_sect_); 631 CriticalSectionScoped lock(acm_crit_sect_.get());
646 return receiver_.LastAudioCodec(current_codec); 632 return receiver_.LastAudioCodec(current_codec);
647 } 633 }
648 634
649 // Incoming packet from network parsed and ready for decode. 635 // Incoming packet from network parsed and ready for decode.
650 int AudioCodingModuleImpl::IncomingPacket(const uint8_t* incoming_payload, 636 int AudioCodingModuleImpl::IncomingPacket(const uint8_t* incoming_payload,
651 const size_t payload_length, 637 const size_t payload_length,
652 const WebRtcRTPHeader& rtp_header) { 638 const WebRtcRTPHeader& rtp_header) {
653 return receiver_.InsertPacket(rtp_header, incoming_payload, payload_length); 639 return receiver_.InsertPacket(rtp_header, incoming_payload, payload_length);
654 } 640 }
655 641
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // TODO(turajs) change the return value to void. Also change the corresponding 691 // TODO(turajs) change the return value to void. Also change the corresponding
706 // NetEq function. 692 // NetEq function.
707 int AudioCodingModuleImpl::GetNetworkStatistics(NetworkStatistics* statistics) { 693 int AudioCodingModuleImpl::GetNetworkStatistics(NetworkStatistics* statistics) {
708 receiver_.GetNetworkStatistics(statistics); 694 receiver_.GetNetworkStatistics(statistics);
709 return 0; 695 return 0;
710 } 696 }
711 697
712 int AudioCodingModuleImpl::RegisterVADCallback(ACMVADCallback* vad_callback) { 698 int AudioCodingModuleImpl::RegisterVADCallback(ACMVADCallback* vad_callback) {
713 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_, 699 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceAudioCoding, id_,
714 "RegisterVADCallback()"); 700 "RegisterVADCallback()");
715 CriticalSectionScoped lock(callback_crit_sect_); 701 CriticalSectionScoped lock(callback_crit_sect_.get());
716 vad_callback_ = vad_callback; 702 vad_callback_ = vad_callback;
717 return 0; 703 return 0;
718 } 704 }
719 705
720 // TODO(tlegrand): Modify this function to work for stereo, and add tests. 706 // TODO(kwiberg): Remove this method, and have callers call IncomingPacket
707 // instead. The translation logic and state belong with them, not with
708 // AudioCodingModuleImpl.
721 int AudioCodingModuleImpl::IncomingPayload(const uint8_t* incoming_payload, 709 int AudioCodingModuleImpl::IncomingPayload(const uint8_t* incoming_payload,
722 size_t payload_length, 710 size_t payload_length,
723 uint8_t payload_type, 711 uint8_t payload_type,
724 uint32_t timestamp) { 712 uint32_t timestamp) {
725 // We are not acquiring any lock when interacting with |aux_rtp_header_| no 713 // We are not acquiring any lock when interacting with |aux_rtp_header_| no
726 // other method uses this member variable. 714 // other method uses this member variable.
727 if (aux_rtp_header_ == NULL) { 715 if (!aux_rtp_header_) {
728 // This is the first time that we are using |dummy_rtp_header_| 716 // This is the first time that we are using |dummy_rtp_header_|
729 // so we have to create it. 717 // so we have to create it.
730 aux_rtp_header_ = new WebRtcRTPHeader; 718 aux_rtp_header_.reset(new WebRtcRTPHeader);
731 aux_rtp_header_->header.payloadType = payload_type; 719 aux_rtp_header_->header.payloadType = payload_type;
732 // Don't matter in this case. 720 // Don't matter in this case.
733 aux_rtp_header_->header.ssrc = 0; 721 aux_rtp_header_->header.ssrc = 0;
734 aux_rtp_header_->header.markerBit = false; 722 aux_rtp_header_->header.markerBit = false;
735 // Start with random numbers. 723 // Start with random numbers.
736 aux_rtp_header_->header.sequenceNumber = 0x1234; // Arbitrary. 724 aux_rtp_header_->header.sequenceNumber = 0x1234; // Arbitrary.
737 aux_rtp_header_->type.Audio.channel = 1; 725 aux_rtp_header_->type.Audio.channel = 1;
738 } 726 }
739 727
740 aux_rtp_header_->header.timestamp = timestamp; 728 aux_rtp_header_->header.timestamp = timestamp;
741 IncomingPacket(incoming_payload, payload_length, *aux_rtp_header_); 729 IncomingPacket(incoming_payload, payload_length, *aux_rtp_header_);
742 // Get ready for the next payload. 730 // Get ready for the next payload.
743 aux_rtp_header_->header.sequenceNumber++; 731 aux_rtp_header_->header.sequenceNumber++;
744 return 0; 732 return 0;
745 } 733 }
746 734
747 // TODO(henrik.lundin): Remove? Only used in tests. Deprecated in VoiceEngine. 735 // TODO(henrik.lundin): Remove? Only used in tests. Deprecated in VoiceEngine.
748 int AudioCodingModuleImpl::SetISACMaxRate(int max_bit_per_sec) { 736 int AudioCodingModuleImpl::SetISACMaxRate(int max_bit_per_sec) {
749 CriticalSectionScoped lock(acm_crit_sect_); 737 CriticalSectionScoped lock(acm_crit_sect_.get());
750 738
751 if (!HaveValidEncoder("SetISACMaxRate")) { 739 if (!HaveValidEncoder("SetISACMaxRate")) {
752 return -1; 740 return -1;
753 } 741 }
754 742
755 codec_manager_.CurrentSpeechEncoder()->SetMaxRate(max_bit_per_sec); 743 codec_manager_.CurrentSpeechEncoder()->SetMaxRate(max_bit_per_sec);
756 return 0; 744 return 0;
757 } 745 }
758 746
759 // TODO(henrik.lundin): Remove? Only used in tests. Deprecated in VoiceEngine. 747 // TODO(henrik.lundin): Remove? Only used in tests. Deprecated in VoiceEngine.
760 int AudioCodingModuleImpl::SetISACMaxPayloadSize(int max_size_bytes) { 748 int AudioCodingModuleImpl::SetISACMaxPayloadSize(int max_size_bytes) {
761 CriticalSectionScoped lock(acm_crit_sect_); 749 CriticalSectionScoped lock(acm_crit_sect_.get());
762 750
763 if (!HaveValidEncoder("SetISACMaxPayloadSize")) { 751 if (!HaveValidEncoder("SetISACMaxPayloadSize")) {
764 return -1; 752 return -1;
765 } 753 }
766 754
767 codec_manager_.CurrentSpeechEncoder()->SetMaxPayloadSize(max_size_bytes); 755 codec_manager_.CurrentSpeechEncoder()->SetMaxPayloadSize(max_size_bytes);
768 return 0; 756 return 0;
769 } 757 }
770 758
771 int AudioCodingModuleImpl::SetOpusApplication(OpusApplicationMode application) { 759 int AudioCodingModuleImpl::SetOpusApplication(OpusApplicationMode application) {
772 CriticalSectionScoped lock(acm_crit_sect_); 760 CriticalSectionScoped lock(acm_crit_sect_.get());
773 if (!HaveValidEncoder("SetOpusApplication")) { 761 if (!HaveValidEncoder("SetOpusApplication")) {
774 return -1; 762 return -1;
775 } 763 }
776 AudioEncoderMutable::Application app; 764 AudioEncoderMutable::Application app;
777 switch (application) { 765 switch (application) {
778 case kVoip: 766 case kVoip:
779 app = AudioEncoderMutable::kApplicationSpeech; 767 app = AudioEncoderMutable::kApplicationSpeech;
780 break; 768 break;
781 case kAudio: 769 case kAudio:
782 app = AudioEncoderMutable::kApplicationAudio; 770 app = AudioEncoderMutable::kApplicationAudio;
783 break; 771 break;
784 default: 772 default:
785 FATAL(); 773 FATAL();
786 return 0; 774 return 0;
787 } 775 }
788 return codec_manager_.CurrentSpeechEncoder()->SetApplication(app) ? 0 : -1; 776 return codec_manager_.CurrentSpeechEncoder()->SetApplication(app) ? 0 : -1;
789 } 777 }
790 778
791 // Informs Opus encoder of the maximum playback rate the receiver will render. 779 // Informs Opus encoder of the maximum playback rate the receiver will render.
792 int AudioCodingModuleImpl::SetOpusMaxPlaybackRate(int frequency_hz) { 780 int AudioCodingModuleImpl::SetOpusMaxPlaybackRate(int frequency_hz) {
793 CriticalSectionScoped lock(acm_crit_sect_); 781 CriticalSectionScoped lock(acm_crit_sect_.get());
794 if (!HaveValidEncoder("SetOpusMaxPlaybackRate")) { 782 if (!HaveValidEncoder("SetOpusMaxPlaybackRate")) {
795 return -1; 783 return -1;
796 } 784 }
797 return codec_manager_.CurrentSpeechEncoder()->SetMaxPlaybackRate(frequency_hz) 785 return codec_manager_.CurrentSpeechEncoder()->SetMaxPlaybackRate(frequency_hz)
798 ? 0 786 ? 0
799 : -1; 787 : -1;
800 } 788 }
801 789
802 int AudioCodingModuleImpl::EnableOpusDtx() { 790 int AudioCodingModuleImpl::EnableOpusDtx() {
803 CriticalSectionScoped lock(acm_crit_sect_); 791 CriticalSectionScoped lock(acm_crit_sect_.get());
804 if (!HaveValidEncoder("EnableOpusDtx")) { 792 if (!HaveValidEncoder("EnableOpusDtx")) {
805 return -1; 793 return -1;
806 } 794 }
807 return codec_manager_.CurrentSpeechEncoder()->SetDtx(true) ? 0 : -1; 795 return codec_manager_.CurrentSpeechEncoder()->SetDtx(true) ? 0 : -1;
808 } 796 }
809 797
810 int AudioCodingModuleImpl::DisableOpusDtx() { 798 int AudioCodingModuleImpl::DisableOpusDtx() {
811 CriticalSectionScoped lock(acm_crit_sect_); 799 CriticalSectionScoped lock(acm_crit_sect_.get());
812 if (!HaveValidEncoder("DisableOpusDtx")) { 800 if (!HaveValidEncoder("DisableOpusDtx")) {
813 return -1; 801 return -1;
814 } 802 }
815 return codec_manager_.CurrentSpeechEncoder()->SetDtx(false) ? 0 : -1; 803 return codec_manager_.CurrentSpeechEncoder()->SetDtx(false) ? 0 : -1;
816 } 804 }
817 805
818 int AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) { 806 int AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {
819 return receiver_.GetPlayoutTimestamp(timestamp) ? 0 : -1; 807 return receiver_.GetPlayoutTimestamp(timestamp) ? 0 : -1;
820 } 808 }
821 809
822 bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const { 810 bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const {
823 if (!codec_manager_.CurrentEncoder()) { 811 if (!codec_manager_.CurrentEncoder()) {
824 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 812 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
825 "%s failed: No send codec is registered.", caller_name); 813 "%s failed: No send codec is registered.", caller_name);
826 return false; 814 return false;
827 } 815 }
828 return true; 816 return true;
829 } 817 }
830 818
831 int AudioCodingModuleImpl::UnregisterReceiveCodec(uint8_t payload_type) { 819 int AudioCodingModuleImpl::UnregisterReceiveCodec(uint8_t payload_type) {
832 return receiver_.RemoveCodec(payload_type); 820 return receiver_.RemoveCodec(payload_type);
833 } 821 }
834 822
835 int AudioCodingModuleImpl::SetInitialPlayoutDelay(int delay_ms) { 823 int AudioCodingModuleImpl::SetInitialPlayoutDelay(int delay_ms) {
836 { 824 {
837 CriticalSectionScoped lock(acm_crit_sect_); 825 CriticalSectionScoped lock(acm_crit_sect_.get());
838 // Initialize receiver, if it is not initialized. Otherwise, initial delay 826 // Initialize receiver, if it is not initialized. Otherwise, initial delay
839 // is reset upon initialization of the receiver. 827 // is reset upon initialization of the receiver.
840 if (!receiver_initialized_) 828 if (!receiver_initialized_)
841 InitializeReceiverSafe(); 829 InitializeReceiverSafe();
842 } 830 }
843 return receiver_.SetInitialDelay(delay_ms); 831 return receiver_.SetInitialDelay(delay_ms);
844 } 832 }
845 833
846 int AudioCodingModuleImpl::SetDtmfPlayoutStatus(bool enable) { 834 int AudioCodingModuleImpl::SetDtmfPlayoutStatus(bool enable) {
847 return 0; 835 return 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 909
922 const CodecInst* AudioCodingImpl::GetSenderCodecInst() { 910 const CodecInst* AudioCodingImpl::GetSenderCodecInst() {
923 if (acm_old_->SendCodec(&current_send_codec_) != 0) { 911 if (acm_old_->SendCodec(&current_send_codec_) != 0) {
924 return NULL; 912 return NULL;
925 } 913 }
926 return &current_send_codec_; 914 return &current_send_codec_;
927 } 915 }
928 916
929 int AudioCodingImpl::Add10MsAudio(const AudioFrame& audio_frame) { 917 int AudioCodingImpl::Add10MsAudio(const AudioFrame& audio_frame) {
930 acm2::AudioCodingModuleImpl::InputData input_data; 918 acm2::AudioCodingModuleImpl::InputData input_data;
931 CriticalSectionScoped lock(acm_old_->acm_crit_sect_); 919 CriticalSectionScoped lock(acm_old_->acm_crit_sect_.get());
932 if (acm_old_->Add10MsDataInternal(audio_frame, &input_data) != 0) 920 if (acm_old_->Add10MsDataInternal(audio_frame, &input_data) != 0)
933 return -1; 921 return -1;
934 return acm_old_->Encode(input_data); 922 return acm_old_->Encode(input_data);
935 } 923 }
936 924
937 const ReceiverInfo* AudioCodingImpl::GetReceiverInfo() const { 925 const ReceiverInfo* AudioCodingImpl::GetReceiverInfo() const {
938 FATAL() << "Not implemented yet."; 926 FATAL() << "Not implemented yet.";
939 return reinterpret_cast<const ReceiverInfo*>(NULL); 927 return reinterpret_cast<const ReceiverInfo*>(NULL);
940 } 928 }
941 929
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 *channels = 1; 1149 *channels = 1;
1162 break; 1150 break;
1163 #endif 1151 #endif
1164 default: 1152 default:
1165 FATAL() << "Codec type " << codec_type << " not supported."; 1153 FATAL() << "Codec type " << codec_type << " not supported.";
1166 } 1154 }
1167 return true; 1155 return true;
1168 } 1156 }
1169 1157
1170 } // namespace webrtc 1158 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698