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

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

Powered by Google App Engine
This is Rietveld 408576698