Chromium Code Reviews| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) | 216 #if defined(WEBRTC_ANDROID) || defined(WEBRTC_IOS) |
| 217 transient_suppressor_enabled_(false), | 217 transient_suppressor_enabled_(false), |
| 218 #else | 218 #else |
| 219 transient_suppressor_enabled_(config.Get<ExperimentalNs>().enabled), | 219 transient_suppressor_enabled_(config.Get<ExperimentalNs>().enabled), |
| 220 #endif | 220 #endif |
| 221 beamformer_enabled_(config.Get<Beamforming>().enabled), | 221 beamformer_enabled_(config.Get<Beamforming>().enabled), |
| 222 beamformer_(beamformer), | 222 beamformer_(beamformer), |
| 223 array_geometry_(config.Get<Beamforming>().array_geometry), | 223 array_geometry_(config.Get<Beamforming>().array_geometry), |
| 224 target_direction_(config.Get<Beamforming>().target_direction), | 224 target_direction_(config.Get<Beamforming>().target_direction), |
| 225 intelligibility_enabled_(config.Get<Intelligibility>().enabled) { | 225 intelligibility_enabled_(config.Get<Intelligibility>().enabled) { |
| 226 echo_cancellation_ = new EchoCancellationImpl(this, crit_); | 226 render_thread_checker_.DetachFromThread(); |
| 227 signal_thread_checker_.DetachFromThread(); | |
| 228 capture_thread_checker_.DetachFromThread(); | |
| 229 | |
| 230 echo_cancellation_ = | |
| 231 new EchoCancellationImpl(this, crit_, &render_thread_checker_); | |
| 227 component_list_.push_back(echo_cancellation_); | 232 component_list_.push_back(echo_cancellation_); |
| 228 | 233 |
| 229 echo_control_mobile_ = new EchoControlMobileImpl(this, crit_); | 234 echo_control_mobile_ = |
| 235 new EchoControlMobileImpl(this, crit_, &render_thread_checker_); | |
| 230 component_list_.push_back(echo_control_mobile_); | 236 component_list_.push_back(echo_control_mobile_); |
| 231 | 237 |
| 232 gain_control_ = new GainControlImpl(this, crit_); | 238 gain_control_ = new GainControlImpl(this, crit_, &render_thread_checker_, |
| 239 &capture_thread_checker_); | |
| 233 component_list_.push_back(gain_control_); | 240 component_list_.push_back(gain_control_); |
| 234 | 241 |
| 235 high_pass_filter_ = new HighPassFilterImpl(this, crit_); | 242 high_pass_filter_ = new HighPassFilterImpl(this, crit_); |
| 236 component_list_.push_back(high_pass_filter_); | 243 component_list_.push_back(high_pass_filter_); |
| 237 | 244 |
| 238 level_estimator_ = new LevelEstimatorImpl(this, crit_); | 245 level_estimator_ = new LevelEstimatorImpl(this, crit_); |
| 239 component_list_.push_back(level_estimator_); | 246 component_list_.push_back(level_estimator_); |
| 240 | 247 |
| 241 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); | 248 noise_suppression_ = new NoiseSuppressionImpl(this, crit_); |
| 242 component_list_.push_back(noise_suppression_); | 249 component_list_.push_back(noise_suppression_); |
| 243 | 250 |
| 244 voice_detection_ = new VoiceDetectionImpl(this, crit_); | 251 voice_detection_ = new VoiceDetectionImpl(this, crit_); |
| 245 component_list_.push_back(voice_detection_); | 252 component_list_.push_back(voice_detection_); |
| 246 | 253 |
| 247 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); | 254 gain_control_for_new_agc_.reset(new GainControlForNewAgc(gain_control_)); |
| 248 | 255 |
| 249 SetExtraOptions(config); | 256 SetExtraOptions(config); |
| 250 } | 257 } |
| 251 | 258 |
| 252 AudioProcessingImpl::~AudioProcessingImpl() { | 259 AudioProcessingImpl::~AudioProcessingImpl() { |
| 253 { | 260 { |
| 254 CriticalSectionScoped crit_scoped(crit_); | 261 CriticalSectionScoped crit_scoped(crit_); |
|
the sun
2015/11/23 12:46:21
RTC_DCHECK(signal_thread_checker_.CalledOnValidThr
peah-webrtc
2015/11/23 13:49:40
Done.
| |
| 255 // Depends on gain_control_ and gain_control_for_new_agc_. | 262 // Depends on gain_control_ and gain_control_for_new_agc_. |
| 256 agc_manager_.reset(); | 263 agc_manager_.reset(); |
| 257 // Depends on gain_control_. | 264 // Depends on gain_control_. |
| 258 gain_control_for_new_agc_.reset(); | 265 gain_control_for_new_agc_.reset(); |
| 259 while (!component_list_.empty()) { | 266 while (!component_list_.empty()) { |
| 260 ProcessingComponent* component = component_list_.front(); | 267 ProcessingComponent* component = component_list_.front(); |
| 261 component->Destroy(); | 268 component->Destroy(); |
| 262 delete component; | 269 delete component; |
| 263 component_list_.pop_front(); | 270 component_list_.pop_front(); |
| 264 } | 271 } |
| 265 | 272 |
| 266 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 273 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 267 if (debug_file_->Open()) { | 274 if (debug_file_->Open()) { |
| 268 debug_file_->CloseFile(); | 275 debug_file_->CloseFile(); |
| 269 } | 276 } |
| 270 #endif | 277 #endif |
| 271 } | 278 } |
| 272 delete crit_; | 279 delete crit_; |
| 273 crit_ = NULL; | 280 crit_ = NULL; |
| 274 } | 281 } |
| 275 | 282 |
| 276 int AudioProcessingImpl::Initialize() { | 283 int AudioProcessingImpl::Initialize() { |
| 284 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | |
| 277 CriticalSectionScoped crit_scoped(crit_); | 285 CriticalSectionScoped crit_scoped(crit_); |
| 278 return InitializeLocked(); | 286 return InitializeLocked(); |
| 279 } | 287 } |
| 280 | 288 |
| 281 int AudioProcessingImpl::Initialize(int input_sample_rate_hz, | 289 int AudioProcessingImpl::Initialize(int input_sample_rate_hz, |
| 282 int output_sample_rate_hz, | 290 int output_sample_rate_hz, |
| 283 int reverse_sample_rate_hz, | 291 int reverse_sample_rate_hz, |
| 284 ChannelLayout input_layout, | 292 ChannelLayout input_layout, |
| 285 ChannelLayout output_layout, | 293 ChannelLayout output_layout, |
| 286 ChannelLayout reverse_layout) { | 294 ChannelLayout reverse_layout) { |
| 295 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | |
| 287 const ProcessingConfig processing_config = { | 296 const ProcessingConfig processing_config = { |
| 288 {{input_sample_rate_hz, | 297 {{input_sample_rate_hz, |
| 289 ChannelsFromLayout(input_layout), | 298 ChannelsFromLayout(input_layout), |
| 290 LayoutHasKeyboard(input_layout)}, | 299 LayoutHasKeyboard(input_layout)}, |
| 291 {output_sample_rate_hz, | 300 {output_sample_rate_hz, |
| 292 ChannelsFromLayout(output_layout), | 301 ChannelsFromLayout(output_layout), |
| 293 LayoutHasKeyboard(output_layout)}, | 302 LayoutHasKeyboard(output_layout)}, |
| 294 {reverse_sample_rate_hz, | 303 {reverse_sample_rate_hz, |
| 295 ChannelsFromLayout(reverse_layout), | 304 ChannelsFromLayout(reverse_layout), |
| 296 LayoutHasKeyboard(reverse_layout)}, | 305 LayoutHasKeyboard(reverse_layout)}, |
| 297 {reverse_sample_rate_hz, | 306 {reverse_sample_rate_hz, |
| 298 ChannelsFromLayout(reverse_layout), | 307 ChannelsFromLayout(reverse_layout), |
| 299 LayoutHasKeyboard(reverse_layout)}}}; | 308 LayoutHasKeyboard(reverse_layout)}}}; |
| 300 | 309 |
| 301 return Initialize(processing_config); | 310 return Initialize(processing_config); |
| 302 } | 311 } |
| 303 | 312 |
| 304 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { | 313 int AudioProcessingImpl::Initialize(const ProcessingConfig& processing_config) { |
| 314 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | |
| 305 CriticalSectionScoped crit_scoped(crit_); | 315 CriticalSectionScoped crit_scoped(crit_); |
| 306 return InitializeLocked(processing_config); | 316 return InitializeLocked(processing_config); |
| 307 } | 317 } |
| 308 | 318 |
| 309 // Calls InitializeLocked() if any of the audio parameters have changed from | 319 // Calls InitializeLocked() if any of the audio parameters have changed from |
| 310 // their current values. | 320 // their current values. |
| 311 int AudioProcessingImpl::MaybeInitializeLocked( | 321 int AudioProcessingImpl::MaybeInitializeLocked( |
| 312 const ProcessingConfig& processing_config) { | 322 const ProcessingConfig& processing_config) { |
| 323 // Called from both threads. Thread check is therefore not possible. | |
|
the sun
2015/11/23 12:46:21
Uhm, yes it is possible:
RTC_DCHECK(render_thread_
peah-webrtc
2015/11/23 13:49:40
Of course! Great! Added that!
Done.
| |
| 313 if (processing_config == shared_state_.api_format_) { | 324 if (processing_config == shared_state_.api_format_) { |
| 314 return kNoError; | 325 return kNoError; |
| 315 } | 326 } |
| 316 return InitializeLocked(processing_config); | 327 return InitializeLocked(processing_config); |
| 317 } | 328 } |
| 318 | 329 |
| 319 int AudioProcessingImpl::InitializeLocked() { | 330 int AudioProcessingImpl::InitializeLocked() { |
| 320 const int fwd_audio_buffer_channels = | 331 const int fwd_audio_buffer_channels = |
| 321 beamformer_enabled_ | 332 beamformer_enabled_ |
| 322 ? shared_state_.api_format_.input_stream().num_channels() | 333 ? shared_state_.api_format_.input_stream().num_channels() |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 if (err != kNoError) { | 383 if (err != kNoError) { |
| 373 return err; | 384 return err; |
| 374 } | 385 } |
| 375 } | 386 } |
| 376 #endif | 387 #endif |
| 377 | 388 |
| 378 return kNoError; | 389 return kNoError; |
| 379 } | 390 } |
| 380 | 391 |
| 381 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { | 392 int AudioProcessingImpl::InitializeLocked(const ProcessingConfig& config) { |
| 393 // Called from both render and capture threads, thread checks is therefore not | |
| 394 // possible. | |
| 382 for (const auto& stream : config.streams) { | 395 for (const auto& stream : config.streams) { |
| 383 if (stream.num_channels() < 0) { | 396 if (stream.num_channels() < 0) { |
| 384 return kBadNumberChannelsError; | 397 return kBadNumberChannelsError; |
| 385 } | 398 } |
| 386 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { | 399 if (stream.num_channels() > 0 && stream.sample_rate_hz() <= 0) { |
| 387 return kBadSampleRateError; | 400 return kBadSampleRateError; |
| 388 } | 401 } |
| 389 } | 402 } |
| 390 | 403 |
| 391 const int num_in_channels = config.input_stream().num_channels(); | 404 const int num_in_channels = config.input_stream().num_channels(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || | 459 if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || |
| 447 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { | 460 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { |
| 448 split_rate_ = kSampleRate16kHz; | 461 split_rate_ = kSampleRate16kHz; |
| 449 } else { | 462 } else { |
| 450 split_rate_ = fwd_proc_format_.sample_rate_hz(); | 463 split_rate_ = fwd_proc_format_.sample_rate_hz(); |
| 451 } | 464 } |
| 452 | 465 |
| 453 return InitializeLocked(); | 466 return InitializeLocked(); |
| 454 } | 467 } |
| 455 | 468 |
| 456 | |
| 457 void AudioProcessingImpl::SetExtraOptions(const Config& config) { | 469 void AudioProcessingImpl::SetExtraOptions(const Config& config) { |
| 458 CriticalSectionScoped crit_scoped(crit_); | 470 CriticalSectionScoped crit_scoped(crit_); |
| 471 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | |
| 459 for (auto item : component_list_) { | 472 for (auto item : component_list_) { |
| 460 item->SetExtraOptions(config); | 473 item->SetExtraOptions(config); |
| 461 } | 474 } |
| 462 | 475 |
| 463 if (transient_suppressor_enabled_ != config.Get<ExperimentalNs>().enabled) { | 476 if (transient_suppressor_enabled_ != config.Get<ExperimentalNs>().enabled) { |
| 464 transient_suppressor_enabled_ = config.Get<ExperimentalNs>().enabled; | 477 transient_suppressor_enabled_ = config.Get<ExperimentalNs>().enabled; |
| 465 InitializeTransient(); | 478 InitializeTransient(); |
| 466 } | 479 } |
| 467 } | 480 } |
| 468 | 481 |
| 469 | 482 |
| 470 int AudioProcessingImpl::proc_sample_rate_hz() const { | 483 int AudioProcessingImpl::proc_sample_rate_hz() const { |
| 484 // TODO(peah): Add threadchecker when possible. | |
| 471 return fwd_proc_format_.sample_rate_hz(); | 485 return fwd_proc_format_.sample_rate_hz(); |
| 472 } | 486 } |
| 473 | 487 |
| 474 int AudioProcessingImpl::proc_split_sample_rate_hz() const { | 488 int AudioProcessingImpl::proc_split_sample_rate_hz() const { |
| 489 // TODO(peah): Add threadchecker when possible. | |
| 475 return split_rate_; | 490 return split_rate_; |
| 476 } | 491 } |
| 477 | 492 |
| 478 int AudioProcessingImpl::num_reverse_channels() const { | 493 int AudioProcessingImpl::num_reverse_channels() const { |
| 494 // TODO(peah): Add threadchecker when possible. | |
| 479 return rev_proc_format_.num_channels(); | 495 return rev_proc_format_.num_channels(); |
| 480 } | 496 } |
| 481 | 497 |
| 482 int AudioProcessingImpl::num_input_channels() const { | 498 int AudioProcessingImpl::num_input_channels() const { |
| 499 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 483 return shared_state_.api_format_.input_stream().num_channels(); | 500 return shared_state_.api_format_.input_stream().num_channels(); |
| 484 } | 501 } |
| 485 | 502 |
| 486 int AudioProcessingImpl::num_output_channels() const { | 503 int AudioProcessingImpl::num_output_channels() const { |
| 504 // TODO(peah): Add appropriate thread checker when possible. | |
| 487 return shared_state_.api_format_.output_stream().num_channels(); | 505 return shared_state_.api_format_.output_stream().num_channels(); |
| 488 } | 506 } |
| 489 | 507 |
| 490 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { | 508 void AudioProcessingImpl::set_output_will_be_muted(bool muted) { |
| 491 CriticalSectionScoped lock(crit_); | 509 CriticalSectionScoped lock(crit_); |
| 510 RTC_DCHECK(signal_thread_checker_.CalledOnValidThread()); | |
| 492 output_will_be_muted_ = muted; | 511 output_will_be_muted_ = muted; |
| 493 if (agc_manager_.get()) { | 512 if (agc_manager_.get()) { |
| 494 agc_manager_->SetCaptureMuted(output_will_be_muted_); | 513 agc_manager_->SetCaptureMuted(output_will_be_muted_); |
| 495 } | 514 } |
| 496 } | 515 } |
| 497 | 516 |
| 498 | 517 |
| 499 int AudioProcessingImpl::ProcessStream(const float* const* src, | 518 int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 500 size_t samples_per_channel, | 519 size_t samples_per_channel, |
| 501 int input_sample_rate_hz, | 520 int input_sample_rate_hz, |
| 502 ChannelLayout input_layout, | 521 ChannelLayout input_layout, |
| 503 int output_sample_rate_hz, | 522 int output_sample_rate_hz, |
| 504 ChannelLayout output_layout, | 523 ChannelLayout output_layout, |
| 505 float* const* dest) { | 524 float* const* dest) { |
| 506 CriticalSectionScoped crit_scoped(crit_); | 525 CriticalSectionScoped crit_scoped(crit_); |
| 526 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 507 StreamConfig input_stream = shared_state_.api_format_.input_stream(); | 527 StreamConfig input_stream = shared_state_.api_format_.input_stream(); |
| 508 input_stream.set_sample_rate_hz(input_sample_rate_hz); | 528 input_stream.set_sample_rate_hz(input_sample_rate_hz); |
| 509 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); | 529 input_stream.set_num_channels(ChannelsFromLayout(input_layout)); |
| 510 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); | 530 input_stream.set_has_keyboard(LayoutHasKeyboard(input_layout)); |
| 511 | 531 |
| 512 StreamConfig output_stream = shared_state_.api_format_.output_stream(); | 532 StreamConfig output_stream = shared_state_.api_format_.output_stream(); |
| 513 output_stream.set_sample_rate_hz(output_sample_rate_hz); | 533 output_stream.set_sample_rate_hz(output_sample_rate_hz); |
| 514 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); | 534 output_stream.set_num_channels(ChannelsFromLayout(output_layout)); |
| 515 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); | 535 output_stream.set_has_keyboard(LayoutHasKeyboard(output_layout)); |
| 516 | 536 |
| 517 if (samples_per_channel != input_stream.num_frames()) { | 537 if (samples_per_channel != input_stream.num_frames()) { |
| 518 return kBadDataLengthError; | 538 return kBadDataLengthError; |
| 519 } | 539 } |
| 520 return ProcessStream(src, input_stream, output_stream, dest); | 540 return ProcessStream(src, input_stream, output_stream, dest); |
| 521 } | 541 } |
| 522 | 542 |
| 523 int AudioProcessingImpl::ProcessStream(const float* const* src, | 543 int AudioProcessingImpl::ProcessStream(const float* const* src, |
| 524 const StreamConfig& input_config, | 544 const StreamConfig& input_config, |
| 525 const StreamConfig& output_config, | 545 const StreamConfig& output_config, |
| 526 float* const* dest) { | 546 float* const* dest) { |
| 527 CriticalSectionScoped crit_scoped(crit_); | 547 CriticalSectionScoped crit_scoped(crit_); |
| 548 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 528 if (!src || !dest) { | 549 if (!src || !dest) { |
| 529 return kNullPointerError; | 550 return kNullPointerError; |
| 530 } | 551 } |
| 531 | 552 |
| 532 echo_cancellation_->ReadQueuedRenderData(); | 553 echo_cancellation_->ReadQueuedRenderData(); |
| 533 echo_control_mobile_->ReadQueuedRenderData(); | 554 echo_control_mobile_->ReadQueuedRenderData(); |
| 534 gain_control_->ReadQueuedRenderData(); | 555 gain_control_->ReadQueuedRenderData(); |
| 535 | 556 |
| 536 ProcessingConfig processing_config = shared_state_.api_format_; | 557 ProcessingConfig processing_config = shared_state_.api_format_; |
| 537 processing_config.input_stream() = input_config; | 558 processing_config.input_stream() = input_config; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 msg->add_output_channel(dest[i], channel_size); | 590 msg->add_output_channel(dest[i], channel_size); |
| 570 RETURN_ON_ERR(WriteMessageToDebugFile()); | 591 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 571 } | 592 } |
| 572 #endif | 593 #endif |
| 573 | 594 |
| 574 return kNoError; | 595 return kNoError; |
| 575 } | 596 } |
| 576 | 597 |
| 577 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { | 598 int AudioProcessingImpl::ProcessStream(AudioFrame* frame) { |
| 578 CriticalSectionScoped crit_scoped(crit_); | 599 CriticalSectionScoped crit_scoped(crit_); |
| 600 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 579 echo_cancellation_->ReadQueuedRenderData(); | 601 echo_cancellation_->ReadQueuedRenderData(); |
| 580 echo_control_mobile_->ReadQueuedRenderData(); | 602 echo_control_mobile_->ReadQueuedRenderData(); |
| 581 gain_control_->ReadQueuedRenderData(); | 603 gain_control_->ReadQueuedRenderData(); |
| 582 | 604 |
| 583 if (!frame) { | 605 if (!frame) { |
| 584 return kNullPointerError; | 606 return kNullPointerError; |
| 585 } | 607 } |
| 586 // Must be a native rate. | 608 // Must be a native rate. |
| 587 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 609 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 588 frame->sample_rate_hz_ != kSampleRate16kHz && | 610 frame->sample_rate_hz_ != kSampleRate16kHz && |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 654 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 633 msg->set_output_data(frame->data_, data_size); | 655 msg->set_output_data(frame->data_, data_size); |
| 634 RETURN_ON_ERR(WriteMessageToDebugFile()); | 656 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 635 } | 657 } |
| 636 #endif | 658 #endif |
| 637 | 659 |
| 638 return kNoError; | 660 return kNoError; |
| 639 } | 661 } |
| 640 | 662 |
| 641 int AudioProcessingImpl::ProcessStreamLocked() { | 663 int AudioProcessingImpl::ProcessStreamLocked() { |
| 664 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 642 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 665 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 643 if (debug_file_->Open()) { | 666 if (debug_file_->Open()) { |
| 644 audioproc::Stream* msg = event_msg_->mutable_stream(); | 667 audioproc::Stream* msg = event_msg_->mutable_stream(); |
| 645 msg->set_delay(stream_delay_ms_); | 668 msg->set_delay(stream_delay_ms_); |
| 646 msg->set_drift(echo_cancellation_->stream_drift_samples()); | 669 msg->set_drift(echo_cancellation_->stream_drift_samples()); |
| 647 msg->set_level(gain_control()->stream_analog_level()); | 670 msg->set_level(gain_control()->stream_analog_level()); |
| 648 msg->set_keypress(key_pressed_); | 671 msg->set_keypress(key_pressed_); |
| 649 } | 672 } |
| 650 #endif | 673 #endif |
| 651 | 674 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 RETURN_ON_ERR(level_estimator_->ProcessStream(ca)); | 736 RETURN_ON_ERR(level_estimator_->ProcessStream(ca)); |
| 714 | 737 |
| 715 was_stream_delay_set_ = false; | 738 was_stream_delay_set_ = false; |
| 716 return kNoError; | 739 return kNoError; |
| 717 } | 740 } |
| 718 | 741 |
| 719 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, | 742 int AudioProcessingImpl::AnalyzeReverseStream(const float* const* data, |
| 720 size_t samples_per_channel, | 743 size_t samples_per_channel, |
| 721 int rev_sample_rate_hz, | 744 int rev_sample_rate_hz, |
| 722 ChannelLayout layout) { | 745 ChannelLayout layout) { |
| 746 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 723 const StreamConfig reverse_config = { | 747 const StreamConfig reverse_config = { |
| 724 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), | 748 rev_sample_rate_hz, ChannelsFromLayout(layout), LayoutHasKeyboard(layout), |
| 725 }; | 749 }; |
| 726 if (samples_per_channel != reverse_config.num_frames()) { | 750 if (samples_per_channel != reverse_config.num_frames()) { |
| 727 return kBadDataLengthError; | 751 return kBadDataLengthError; |
| 728 } | 752 } |
| 729 return AnalyzeReverseStream(data, reverse_config, reverse_config); | 753 return AnalyzeReverseStream(data, reverse_config, reverse_config); |
| 730 } | 754 } |
| 731 | 755 |
| 732 int AudioProcessingImpl::ProcessReverseStream( | 756 int AudioProcessingImpl::ProcessReverseStream( |
| 733 const float* const* src, | 757 const float* const* src, |
| 734 const StreamConfig& reverse_input_config, | 758 const StreamConfig& reverse_input_config, |
| 735 const StreamConfig& reverse_output_config, | 759 const StreamConfig& reverse_output_config, |
| 736 float* const* dest) { | 760 float* const* dest) { |
| 761 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 737 RETURN_ON_ERR( | 762 RETURN_ON_ERR( |
| 738 AnalyzeReverseStream(src, reverse_input_config, reverse_output_config)); | 763 AnalyzeReverseStream(src, reverse_input_config, reverse_output_config)); |
| 739 if (is_rev_processed()) { | 764 if (is_rev_processed()) { |
| 740 render_audio_->CopyTo(shared_state_.api_format_.reverse_output_stream(), | 765 render_audio_->CopyTo(shared_state_.api_format_.reverse_output_stream(), |
| 741 dest); | 766 dest); |
| 742 } else if (rev_conversion_needed()) { | 767 } else if (rev_conversion_needed()) { |
| 743 render_converter_->Convert(src, reverse_input_config.num_samples(), dest, | 768 render_converter_->Convert(src, reverse_input_config.num_samples(), dest, |
| 744 reverse_output_config.num_samples()); | 769 reverse_output_config.num_samples()); |
| 745 } else { | 770 } else { |
| 746 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), | 771 CopyAudioIfNeeded(src, reverse_input_config.num_frames(), |
| 747 reverse_input_config.num_channels(), dest); | 772 reverse_input_config.num_channels(), dest); |
| 748 } | 773 } |
| 749 | 774 |
| 750 return kNoError; | 775 return kNoError; |
| 751 } | 776 } |
| 752 | 777 |
| 753 int AudioProcessingImpl::AnalyzeReverseStream( | 778 int AudioProcessingImpl::AnalyzeReverseStream( |
| 754 const float* const* src, | 779 const float* const* src, |
| 755 const StreamConfig& reverse_input_config, | 780 const StreamConfig& reverse_input_config, |
| 756 const StreamConfig& reverse_output_config) { | 781 const StreamConfig& reverse_output_config) { |
| 757 CriticalSectionScoped crit_scoped(crit_); | 782 CriticalSectionScoped crit_scoped(crit_); |
| 783 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 758 if (src == NULL) { | 784 if (src == NULL) { |
| 759 return kNullPointerError; | 785 return kNullPointerError; |
| 760 } | 786 } |
| 761 | 787 |
| 762 if (reverse_input_config.num_channels() <= 0) { | 788 if (reverse_input_config.num_channels() <= 0) { |
| 763 return kBadNumberChannelsError; | 789 return kBadNumberChannelsError; |
| 764 } | 790 } |
| 765 | 791 |
| 766 ProcessingConfig processing_config = shared_state_.api_format_; | 792 ProcessingConfig processing_config = shared_state_.api_format_; |
| 767 processing_config.reverse_input_stream() = reverse_input_config; | 793 processing_config.reverse_input_stream() = reverse_input_config; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 785 RETURN_ON_ERR(WriteMessageToDebugFile()); | 811 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 786 } | 812 } |
| 787 #endif | 813 #endif |
| 788 | 814 |
| 789 render_audio_->CopyFrom(src, | 815 render_audio_->CopyFrom(src, |
| 790 shared_state_.api_format_.reverse_input_stream()); | 816 shared_state_.api_format_.reverse_input_stream()); |
| 791 return ProcessReverseStreamLocked(); | 817 return ProcessReverseStreamLocked(); |
| 792 } | 818 } |
| 793 | 819 |
| 794 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { | 820 int AudioProcessingImpl::ProcessReverseStream(AudioFrame* frame) { |
| 821 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 795 RETURN_ON_ERR(AnalyzeReverseStream(frame)); | 822 RETURN_ON_ERR(AnalyzeReverseStream(frame)); |
| 796 if (is_rev_processed()) { | 823 if (is_rev_processed()) { |
| 797 render_audio_->InterleaveTo(frame, true); | 824 render_audio_->InterleaveTo(frame, true); |
| 798 } | 825 } |
| 799 | 826 |
| 800 return kNoError; | 827 return kNoError; |
| 801 } | 828 } |
| 802 | 829 |
| 803 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { | 830 int AudioProcessingImpl::AnalyzeReverseStream(AudioFrame* frame) { |
| 831 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 804 CriticalSectionScoped crit_scoped(crit_); | 832 CriticalSectionScoped crit_scoped(crit_); |
| 805 if (frame == NULL) { | 833 if (frame == NULL) { |
| 806 return kNullPointerError; | 834 return kNullPointerError; |
| 807 } | 835 } |
| 808 // Must be a native rate. | 836 // Must be a native rate. |
| 809 if (frame->sample_rate_hz_ != kSampleRate8kHz && | 837 if (frame->sample_rate_hz_ != kSampleRate8kHz && |
| 810 frame->sample_rate_hz_ != kSampleRate16kHz && | 838 frame->sample_rate_hz_ != kSampleRate16kHz && |
| 811 frame->sample_rate_hz_ != kSampleRate32kHz && | 839 frame->sample_rate_hz_ != kSampleRate32kHz && |
| 812 frame->sample_rate_hz_ != kSampleRate48kHz) { | 840 frame->sample_rate_hz_ != kSampleRate48kHz) { |
| 813 return kBadSampleRateError; | 841 return kBadSampleRateError; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; | 874 sizeof(int16_t) * frame->samples_per_channel_ * frame->num_channels_; |
| 847 msg->set_data(frame->data_, data_size); | 875 msg->set_data(frame->data_, data_size); |
| 848 RETURN_ON_ERR(WriteMessageToDebugFile()); | 876 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 849 } | 877 } |
| 850 #endif | 878 #endif |
| 851 render_audio_->DeinterleaveFrom(frame); | 879 render_audio_->DeinterleaveFrom(frame); |
| 852 return ProcessReverseStreamLocked(); | 880 return ProcessReverseStreamLocked(); |
| 853 } | 881 } |
| 854 | 882 |
| 855 int AudioProcessingImpl::ProcessReverseStreamLocked() { | 883 int AudioProcessingImpl::ProcessReverseStreamLocked() { |
| 884 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 856 AudioBuffer* ra = render_audio_.get(); // For brevity. | 885 AudioBuffer* ra = render_audio_.get(); // For brevity. |
| 857 if (rev_proc_format_.sample_rate_hz() == kSampleRate32kHz) { | 886 if (rev_proc_format_.sample_rate_hz() == kSampleRate32kHz) { |
| 858 ra->SplitIntoFrequencyBands(); | 887 ra->SplitIntoFrequencyBands(); |
| 859 } | 888 } |
| 860 | 889 |
| 861 if (intelligibility_enabled_) { | 890 if (intelligibility_enabled_) { |
| 862 intelligibility_enhancer_->ProcessRenderAudio( | 891 intelligibility_enhancer_->ProcessRenderAudio( |
| 863 ra->split_channels_f(kBand0To8kHz), split_rate_, ra->num_channels()); | 892 ra->split_channels_f(kBand0To8kHz), split_rate_, ra->num_channels()); |
| 864 } | 893 } |
| 865 | 894 |
| 866 RETURN_ON_ERR(echo_cancellation_->ProcessRenderAudio(ra)); | 895 RETURN_ON_ERR(echo_cancellation_->ProcessRenderAudio(ra)); |
| 867 RETURN_ON_ERR(echo_control_mobile_->ProcessRenderAudio(ra)); | 896 RETURN_ON_ERR(echo_control_mobile_->ProcessRenderAudio(ra)); |
| 868 if (!use_new_agc_) { | 897 if (!use_new_agc_) { |
| 869 RETURN_ON_ERR(gain_control_->ProcessRenderAudio(ra)); | 898 RETURN_ON_ERR(gain_control_->ProcessRenderAudio(ra)); |
| 870 } | 899 } |
| 871 | 900 |
| 872 if (rev_proc_format_.sample_rate_hz() == kSampleRate32kHz && | 901 if (rev_proc_format_.sample_rate_hz() == kSampleRate32kHz && |
| 873 is_rev_processed()) { | 902 is_rev_processed()) { |
| 874 ra->MergeFrequencyBands(); | 903 ra->MergeFrequencyBands(); |
| 875 } | 904 } |
| 876 | 905 |
| 877 return kNoError; | 906 return kNoError; |
| 878 } | 907 } |
| 879 | 908 |
| 880 int AudioProcessingImpl::set_stream_delay_ms(int delay) { | 909 int AudioProcessingImpl::set_stream_delay_ms(int delay) { |
| 910 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 881 Error retval = kNoError; | 911 Error retval = kNoError; |
| 882 was_stream_delay_set_ = true; | 912 was_stream_delay_set_ = true; |
| 883 delay += delay_offset_ms_; | 913 delay += delay_offset_ms_; |
| 884 | 914 |
| 885 if (delay < 0) { | 915 if (delay < 0) { |
| 886 delay = 0; | 916 delay = 0; |
| 887 retval = kBadStreamParameterWarning; | 917 retval = kBadStreamParameterWarning; |
| 888 } | 918 } |
| 889 | 919 |
| 890 // TODO(ajm): the max is rather arbitrarily chosen; investigate. | 920 // TODO(ajm): the max is rather arbitrarily chosen; investigate. |
| 891 if (delay > 500) { | 921 if (delay > 500) { |
| 892 delay = 500; | 922 delay = 500; |
| 893 retval = kBadStreamParameterWarning; | 923 retval = kBadStreamParameterWarning; |
| 894 } | 924 } |
| 895 | 925 |
| 896 stream_delay_ms_ = delay; | 926 stream_delay_ms_ = delay; |
| 897 return retval; | 927 return retval; |
| 898 } | 928 } |
| 899 | 929 |
| 900 int AudioProcessingImpl::stream_delay_ms() const { | 930 int AudioProcessingImpl::stream_delay_ms() const { |
| 931 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 901 return stream_delay_ms_; | 932 return stream_delay_ms_; |
| 902 } | 933 } |
| 903 | 934 |
| 904 bool AudioProcessingImpl::was_stream_delay_set() const { | 935 bool AudioProcessingImpl::was_stream_delay_set() const { |
| 936 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 905 return was_stream_delay_set_; | 937 return was_stream_delay_set_; |
| 906 } | 938 } |
| 907 | 939 |
| 908 void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { | 940 void AudioProcessingImpl::set_stream_key_pressed(bool key_pressed) { |
| 941 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 909 key_pressed_ = key_pressed; | 942 key_pressed_ = key_pressed; |
| 910 } | 943 } |
| 911 | 944 |
| 912 void AudioProcessingImpl::set_delay_offset_ms(int offset) { | 945 void AudioProcessingImpl::set_delay_offset_ms(int offset) { |
| 946 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 913 CriticalSectionScoped crit_scoped(crit_); | 947 CriticalSectionScoped crit_scoped(crit_); |
| 914 delay_offset_ms_ = offset; | 948 delay_offset_ms_ = offset; |
| 915 } | 949 } |
| 916 | 950 |
| 917 int AudioProcessingImpl::delay_offset_ms() const { | 951 int AudioProcessingImpl::delay_offset_ms() const { |
| 952 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 918 return delay_offset_ms_; | 953 return delay_offset_ms_; |
| 919 } | 954 } |
| 920 | 955 |
| 921 int AudioProcessingImpl::StartDebugRecording( | 956 int AudioProcessingImpl::StartDebugRecording( |
| 922 const char filename[AudioProcessing::kMaxFilenameSize]) { | 957 const char filename[AudioProcessing::kMaxFilenameSize]) { |
| 923 CriticalSectionScoped crit_scoped(crit_); | 958 CriticalSectionScoped crit_scoped(crit_); |
| 959 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 924 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); | 960 static_assert(kMaxFilenameSize == FileWrapper::kMaxFileNameSize, ""); |
| 925 | 961 |
| 926 if (filename == NULL) { | 962 if (filename == NULL) { |
| 927 return kNullPointerError; | 963 return kNullPointerError; |
| 928 } | 964 } |
| 929 | 965 |
| 930 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 966 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 931 // Stop any ongoing recording. | 967 // Stop any ongoing recording. |
| 932 if (debug_file_->Open()) { | 968 if (debug_file_->Open()) { |
| 933 if (debug_file_->CloseFile() == -1) { | 969 if (debug_file_->CloseFile() == -1) { |
| 934 return kFileError; | 970 return kFileError; |
| 935 } | 971 } |
| 936 } | 972 } |
| 937 | 973 |
| 938 if (debug_file_->OpenFile(filename, false) == -1) { | 974 if (debug_file_->OpenFile(filename, false) == -1) { |
| 939 debug_file_->CloseFile(); | 975 debug_file_->CloseFile(); |
| 940 return kFileError; | 976 return kFileError; |
| 941 } | 977 } |
| 942 | 978 |
| 943 RETURN_ON_ERR(WriteConfigMessage(true)); | 979 RETURN_ON_ERR(WriteConfigMessage(true)); |
| 944 RETURN_ON_ERR(WriteInitMessage()); | 980 RETURN_ON_ERR(WriteInitMessage()); |
| 945 return kNoError; | 981 return kNoError; |
| 946 #else | 982 #else |
| 947 return kUnsupportedFunctionError; | 983 return kUnsupportedFunctionError; |
| 948 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 984 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 949 } | 985 } |
| 950 | 986 |
| 951 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { | 987 int AudioProcessingImpl::StartDebugRecording(FILE* handle) { |
| 952 CriticalSectionScoped crit_scoped(crit_); | 988 CriticalSectionScoped crit_scoped(crit_); |
| 989 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 953 | 990 |
| 954 if (handle == NULL) { | 991 if (handle == NULL) { |
| 955 return kNullPointerError; | 992 return kNullPointerError; |
| 956 } | 993 } |
| 957 | 994 |
| 958 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 995 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 959 // Stop any ongoing recording. | 996 // Stop any ongoing recording. |
| 960 if (debug_file_->Open()) { | 997 if (debug_file_->Open()) { |
| 961 if (debug_file_->CloseFile() == -1) { | 998 if (debug_file_->CloseFile() == -1) { |
| 962 return kFileError; | 999 return kFileError; |
| 963 } | 1000 } |
| 964 } | 1001 } |
| 965 | 1002 |
| 966 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { | 1003 if (debug_file_->OpenFromFileHandle(handle, true, false) == -1) { |
| 967 return kFileError; | 1004 return kFileError; |
| 968 } | 1005 } |
| 969 | 1006 |
| 970 RETURN_ON_ERR(WriteConfigMessage(true)); | 1007 RETURN_ON_ERR(WriteConfigMessage(true)); |
| 971 RETURN_ON_ERR(WriteInitMessage()); | 1008 RETURN_ON_ERR(WriteInitMessage()); |
| 972 return kNoError; | 1009 return kNoError; |
| 973 #else | 1010 #else |
| 974 return kUnsupportedFunctionError; | 1011 return kUnsupportedFunctionError; |
| 975 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1012 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 976 } | 1013 } |
| 977 | 1014 |
| 978 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( | 1015 int AudioProcessingImpl::StartDebugRecordingForPlatformFile( |
| 979 rtc::PlatformFile handle) { | 1016 rtc::PlatformFile handle) { |
| 1017 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 980 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); | 1018 FILE* stream = rtc::FdopenPlatformFileForWriting(handle); |
| 981 return StartDebugRecording(stream); | 1019 return StartDebugRecording(stream); |
| 982 } | 1020 } |
| 983 | 1021 |
| 984 int AudioProcessingImpl::StopDebugRecording() { | 1022 int AudioProcessingImpl::StopDebugRecording() { |
| 985 CriticalSectionScoped crit_scoped(crit_); | 1023 CriticalSectionScoped crit_scoped(crit_); |
| 1024 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 986 | 1025 |
| 987 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1026 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 988 // We just return if recording hasn't started. | 1027 // We just return if recording hasn't started. |
| 989 if (debug_file_->Open()) { | 1028 if (debug_file_->Open()) { |
| 990 if (debug_file_->CloseFile() == -1) { | 1029 if (debug_file_->CloseFile() == -1) { |
| 991 return kFileError; | 1030 return kFileError; |
| 992 } | 1031 } |
| 993 } | 1032 } |
| 994 return kNoError; | 1033 return kNoError; |
| 995 #else | 1034 #else |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1022 | 1061 |
| 1023 NoiseSuppression* AudioProcessingImpl::noise_suppression() const { | 1062 NoiseSuppression* AudioProcessingImpl::noise_suppression() const { |
| 1024 return noise_suppression_; | 1063 return noise_suppression_; |
| 1025 } | 1064 } |
| 1026 | 1065 |
| 1027 VoiceDetection* AudioProcessingImpl::voice_detection() const { | 1066 VoiceDetection* AudioProcessingImpl::voice_detection() const { |
| 1028 return voice_detection_; | 1067 return voice_detection_; |
| 1029 } | 1068 } |
| 1030 | 1069 |
| 1031 bool AudioProcessingImpl::is_data_processed() const { | 1070 bool AudioProcessingImpl::is_data_processed() const { |
| 1071 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1032 if (beamformer_enabled_) { | 1072 if (beamformer_enabled_) { |
| 1033 return true; | 1073 return true; |
| 1034 } | 1074 } |
| 1035 | 1075 |
| 1036 int enabled_count = 0; | 1076 int enabled_count = 0; |
| 1037 for (auto item : component_list_) { | 1077 for (auto item : component_list_) { |
| 1038 if (item->is_component_enabled()) { | 1078 if (item->is_component_enabled()) { |
| 1039 enabled_count++; | 1079 enabled_count++; |
| 1040 } | 1080 } |
| 1041 } | 1081 } |
| 1042 | 1082 |
| 1043 // Data is unchanged if no components are enabled, or if only level_estimator_ | 1083 // Data is unchanged if no components are enabled, or if only level_estimator_ |
| 1044 // or voice_detection_ is enabled. | 1084 // or voice_detection_ is enabled. |
| 1045 if (enabled_count == 0) { | 1085 if (enabled_count == 0) { |
| 1046 return false; | 1086 return false; |
| 1047 } else if (enabled_count == 1) { | 1087 } else if (enabled_count == 1) { |
| 1048 if (level_estimator_->is_enabled() || voice_detection_->is_enabled()) { | 1088 if (level_estimator_->is_enabled() || voice_detection_->is_enabled()) { |
| 1049 return false; | 1089 return false; |
| 1050 } | 1090 } |
| 1051 } else if (enabled_count == 2) { | 1091 } else if (enabled_count == 2) { |
| 1052 if (level_estimator_->is_enabled() && voice_detection_->is_enabled()) { | 1092 if (level_estimator_->is_enabled() && voice_detection_->is_enabled()) { |
| 1053 return false; | 1093 return false; |
| 1054 } | 1094 } |
| 1055 } | 1095 } |
| 1056 return true; | 1096 return true; |
| 1057 } | 1097 } |
| 1058 | 1098 |
| 1059 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { | 1099 bool AudioProcessingImpl::output_copy_needed(bool is_data_processed) const { |
| 1100 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1060 // Check if we've upmixed or downmixed the audio. | 1101 // Check if we've upmixed or downmixed the audio. |
| 1061 return ((shared_state_.api_format_.output_stream().num_channels() != | 1102 return ((shared_state_.api_format_.output_stream().num_channels() != |
| 1062 shared_state_.api_format_.input_stream().num_channels()) || | 1103 shared_state_.api_format_.input_stream().num_channels()) || |
| 1063 is_data_processed || transient_suppressor_enabled_); | 1104 is_data_processed || transient_suppressor_enabled_); |
| 1064 } | 1105 } |
| 1065 | 1106 |
| 1066 bool AudioProcessingImpl::synthesis_needed(bool is_data_processed) const { | 1107 bool AudioProcessingImpl::synthesis_needed(bool is_data_processed) const { |
| 1108 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1067 return (is_data_processed && | 1109 return (is_data_processed && |
| 1068 (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || | 1110 (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || |
| 1069 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz)); | 1111 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz)); |
| 1070 } | 1112 } |
| 1071 | 1113 |
| 1072 bool AudioProcessingImpl::analysis_needed(bool is_data_processed) const { | 1114 bool AudioProcessingImpl::analysis_needed(bool is_data_processed) const { |
| 1115 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1073 if (!is_data_processed && !voice_detection_->is_enabled() && | 1116 if (!is_data_processed && !voice_detection_->is_enabled() && |
| 1074 !transient_suppressor_enabled_) { | 1117 !transient_suppressor_enabled_) { |
| 1075 // Only level_estimator_ is enabled. | 1118 // Only level_estimator_ is enabled. |
| 1076 return false; | 1119 return false; |
| 1077 } else if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || | 1120 } else if (fwd_proc_format_.sample_rate_hz() == kSampleRate32kHz || |
| 1078 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { | 1121 fwd_proc_format_.sample_rate_hz() == kSampleRate48kHz) { |
| 1079 // Something besides level_estimator_ is enabled, and we have super-wb. | 1122 // Something besides level_estimator_ is enabled, and we have super-wb. |
| 1080 return true; | 1123 return true; |
| 1081 } | 1124 } |
| 1082 return false; | 1125 return false; |
| 1083 } | 1126 } |
| 1084 | 1127 |
| 1085 bool AudioProcessingImpl::is_rev_processed() const { | 1128 bool AudioProcessingImpl::is_rev_processed() const { |
| 1129 RTC_DCHECK(render_thread_checker_.CalledOnValidThread()); | |
| 1086 return intelligibility_enabled_ && intelligibility_enhancer_->active(); | 1130 return intelligibility_enabled_ && intelligibility_enhancer_->active(); |
| 1087 } | 1131 } |
| 1088 | 1132 |
| 1089 bool AudioProcessingImpl::rev_conversion_needed() const { | 1133 bool AudioProcessingImpl::rev_conversion_needed() const { |
| 1134 // Called from several threads, thread check not possible. | |
| 1090 return (shared_state_.api_format_.reverse_input_stream() != | 1135 return (shared_state_.api_format_.reverse_input_stream() != |
| 1091 shared_state_.api_format_.reverse_output_stream()); | 1136 shared_state_.api_format_.reverse_output_stream()); |
| 1092 } | 1137 } |
| 1093 | 1138 |
| 1094 void AudioProcessingImpl::InitializeExperimentalAgc() { | 1139 void AudioProcessingImpl::InitializeExperimentalAgc() { |
| 1140 // Called from several threads, thread check not possible. | |
| 1095 if (use_new_agc_) { | 1141 if (use_new_agc_) { |
| 1096 if (!agc_manager_.get()) { | 1142 if (!agc_manager_.get()) { |
| 1097 agc_manager_.reset(new AgcManagerDirect(gain_control_, | 1143 agc_manager_.reset(new AgcManagerDirect(gain_control_, |
| 1098 gain_control_for_new_agc_.get(), | 1144 gain_control_for_new_agc_.get(), |
| 1099 agc_startup_min_volume_)); | 1145 agc_startup_min_volume_)); |
| 1100 } | 1146 } |
| 1101 agc_manager_->Initialize(); | 1147 agc_manager_->Initialize(); |
| 1102 agc_manager_->SetCaptureMuted(output_will_be_muted_); | 1148 agc_manager_->SetCaptureMuted(output_will_be_muted_); |
| 1103 } | 1149 } |
| 1104 } | 1150 } |
| 1105 | 1151 |
| 1106 void AudioProcessingImpl::InitializeTransient() { | 1152 void AudioProcessingImpl::InitializeTransient() { |
| 1153 // Called from several threads, thread check not possible. | |
| 1107 if (transient_suppressor_enabled_) { | 1154 if (transient_suppressor_enabled_) { |
| 1108 if (!transient_suppressor_.get()) { | 1155 if (!transient_suppressor_.get()) { |
| 1109 transient_suppressor_.reset(new TransientSuppressor()); | 1156 transient_suppressor_.reset(new TransientSuppressor()); |
| 1110 } | 1157 } |
| 1111 transient_suppressor_->Initialize( | 1158 transient_suppressor_->Initialize( |
| 1112 fwd_proc_format_.sample_rate_hz(), split_rate_, | 1159 fwd_proc_format_.sample_rate_hz(), split_rate_, |
| 1113 shared_state_.api_format_.output_stream().num_channels()); | 1160 shared_state_.api_format_.output_stream().num_channels()); |
| 1114 } | 1161 } |
| 1115 } | 1162 } |
| 1116 | 1163 |
| 1117 void AudioProcessingImpl::InitializeBeamformer() { | 1164 void AudioProcessingImpl::InitializeBeamformer() { |
| 1165 // Called from several threads, thread check not possible. | |
| 1118 if (beamformer_enabled_) { | 1166 if (beamformer_enabled_) { |
| 1119 if (!beamformer_) { | 1167 if (!beamformer_) { |
| 1120 beamformer_.reset( | 1168 beamformer_.reset( |
| 1121 new NonlinearBeamformer(array_geometry_, target_direction_)); | 1169 new NonlinearBeamformer(array_geometry_, target_direction_)); |
| 1122 } | 1170 } |
| 1123 beamformer_->Initialize(kChunkSizeMs, split_rate_); | 1171 beamformer_->Initialize(kChunkSizeMs, split_rate_); |
| 1124 } | 1172 } |
| 1125 } | 1173 } |
| 1126 | 1174 |
| 1127 void AudioProcessingImpl::InitializeIntelligibility() { | 1175 void AudioProcessingImpl::InitializeIntelligibility() { |
| 1176 // Called from several threads, thread check not possible. | |
| 1128 if (intelligibility_enabled_) { | 1177 if (intelligibility_enabled_) { |
| 1129 IntelligibilityEnhancer::Config config; | 1178 IntelligibilityEnhancer::Config config; |
| 1130 config.sample_rate_hz = split_rate_; | 1179 config.sample_rate_hz = split_rate_; |
| 1131 config.num_capture_channels = capture_audio_->num_channels(); | 1180 config.num_capture_channels = capture_audio_->num_channels(); |
| 1132 config.num_render_channels = render_audio_->num_channels(); | 1181 config.num_render_channels = render_audio_->num_channels(); |
| 1133 intelligibility_enhancer_.reset(new IntelligibilityEnhancer(config)); | 1182 intelligibility_enhancer_.reset(new IntelligibilityEnhancer(config)); |
| 1134 } | 1183 } |
| 1135 } | 1184 } |
| 1136 | 1185 |
| 1137 void AudioProcessingImpl::MaybeUpdateHistograms() { | 1186 void AudioProcessingImpl::MaybeUpdateHistograms() { |
| 1187 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1138 static const int kMinDiffDelayMs = 60; | 1188 static const int kMinDiffDelayMs = 60; |
| 1139 | 1189 |
| 1140 if (echo_cancellation()->is_enabled()) { | 1190 if (echo_cancellation()->is_enabled()) { |
| 1141 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. | 1191 // Activate delay_jumps_ counters if we know echo_cancellation is runnning. |
| 1142 // If a stream has echo we know that the echo_cancellation is in process. | 1192 // If a stream has echo we know that the echo_cancellation is in process. |
| 1143 if (stream_delay_jumps_ == -1 && echo_cancellation()->stream_has_echo()) { | 1193 if (stream_delay_jumps_ == -1 && echo_cancellation()->stream_has_echo()) { |
| 1144 stream_delay_jumps_ = 0; | 1194 stream_delay_jumps_ = 0; |
| 1145 } | 1195 } |
| 1146 if (aec_system_delay_jumps_ == -1 && | 1196 if (aec_system_delay_jumps_ == -1 && |
| 1147 echo_cancellation()->stream_has_echo()) { | 1197 echo_cancellation()->stream_has_echo()) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1174 if (aec_system_delay_jumps_ == -1) { | 1224 if (aec_system_delay_jumps_ == -1) { |
| 1175 aec_system_delay_jumps_ = 0; // Activate counter if needed. | 1225 aec_system_delay_jumps_ = 0; // Activate counter if needed. |
| 1176 } | 1226 } |
| 1177 aec_system_delay_jumps_++; | 1227 aec_system_delay_jumps_++; |
| 1178 } | 1228 } |
| 1179 last_aec_system_delay_ms_ = aec_system_delay_ms; | 1229 last_aec_system_delay_ms_ = aec_system_delay_ms; |
| 1180 } | 1230 } |
| 1181 } | 1231 } |
| 1182 | 1232 |
| 1183 void AudioProcessingImpl::UpdateHistogramsOnCallEnd() { | 1233 void AudioProcessingImpl::UpdateHistogramsOnCallEnd() { |
| 1234 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1184 CriticalSectionScoped crit_scoped(crit_); | 1235 CriticalSectionScoped crit_scoped(crit_); |
| 1185 if (stream_delay_jumps_ > -1) { | 1236 if (stream_delay_jumps_ > -1) { |
| 1186 RTC_HISTOGRAM_ENUMERATION( | 1237 RTC_HISTOGRAM_ENUMERATION( |
| 1187 "WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps", | 1238 "WebRTC.Audio.NumOfPlatformReportedStreamDelayJumps", |
| 1188 stream_delay_jumps_, 51); | 1239 stream_delay_jumps_, 51); |
| 1189 } | 1240 } |
| 1190 stream_delay_jumps_ = -1; | 1241 stream_delay_jumps_ = -1; |
| 1191 last_stream_delay_ms_ = 0; | 1242 last_stream_delay_ms_ = 0; |
| 1192 | 1243 |
| 1193 if (aec_system_delay_jumps_ > -1) { | 1244 if (aec_system_delay_jumps_ > -1) { |
| 1194 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", | 1245 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.NumOfAecSystemDelayJumps", |
| 1195 aec_system_delay_jumps_, 51); | 1246 aec_system_delay_jumps_, 51); |
| 1196 } | 1247 } |
| 1197 aec_system_delay_jumps_ = -1; | 1248 aec_system_delay_jumps_ = -1; |
| 1198 last_aec_system_delay_ms_ = 0; | 1249 last_aec_system_delay_ms_ = 0; |
| 1199 } | 1250 } |
| 1200 | 1251 |
| 1201 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP | 1252 #ifdef WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1202 int AudioProcessingImpl::WriteMessageToDebugFile() { | 1253 int AudioProcessingImpl::WriteMessageToDebugFile() { |
| 1254 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1203 int32_t size = event_msg_->ByteSize(); | 1255 int32_t size = event_msg_->ByteSize(); |
| 1204 if (size <= 0) { | 1256 if (size <= 0) { |
| 1205 return kUnspecifiedError; | 1257 return kUnspecifiedError; |
| 1206 } | 1258 } |
| 1207 #if defined(WEBRTC_ARCH_BIG_ENDIAN) | 1259 #if defined(WEBRTC_ARCH_BIG_ENDIAN) |
| 1208 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be | 1260 // TODO(ajm): Use little-endian "on the wire". For the moment, we can be |
| 1209 // pretty safe in assuming little-endian. | 1261 // pretty safe in assuming little-endian. |
| 1210 #endif | 1262 #endif |
| 1211 | 1263 |
| 1212 if (!event_msg_->SerializeToString(&event_str_)) { | 1264 if (!event_msg_->SerializeToString(&event_str_)) { |
| 1213 return kUnspecifiedError; | 1265 return kUnspecifiedError; |
| 1214 } | 1266 } |
| 1215 | 1267 |
| 1216 // Write message preceded by its size. | 1268 // Write message preceded by its size. |
| 1217 if (!debug_file_->Write(&size, sizeof(int32_t))) { | 1269 if (!debug_file_->Write(&size, sizeof(int32_t))) { |
| 1218 return kFileError; | 1270 return kFileError; |
| 1219 } | 1271 } |
| 1220 if (!debug_file_->Write(event_str_.data(), event_str_.length())) { | 1272 if (!debug_file_->Write(event_str_.data(), event_str_.length())) { |
| 1221 return kFileError; | 1273 return kFileError; |
| 1222 } | 1274 } |
| 1223 | 1275 |
| 1224 event_msg_->Clear(); | 1276 event_msg_->Clear(); |
| 1225 | 1277 |
| 1226 return kNoError; | 1278 return kNoError; |
| 1227 } | 1279 } |
| 1228 | 1280 |
| 1229 int AudioProcessingImpl::WriteInitMessage() { | 1281 int AudioProcessingImpl::WriteInitMessage() { |
| 1282 // Called from both render and capture threads, not threadchecker possible. | |
| 1230 event_msg_->set_type(audioproc::Event::INIT); | 1283 event_msg_->set_type(audioproc::Event::INIT); |
| 1231 audioproc::Init* msg = event_msg_->mutable_init(); | 1284 audioproc::Init* msg = event_msg_->mutable_init(); |
| 1232 msg->set_sample_rate( | 1285 msg->set_sample_rate( |
| 1233 shared_state_.api_format_.input_stream().sample_rate_hz()); | 1286 shared_state_.api_format_.input_stream().sample_rate_hz()); |
| 1234 msg->set_num_input_channels( | 1287 msg->set_num_input_channels( |
| 1235 shared_state_.api_format_.input_stream().num_channels()); | 1288 shared_state_.api_format_.input_stream().num_channels()); |
| 1236 msg->set_num_output_channels( | 1289 msg->set_num_output_channels( |
| 1237 shared_state_.api_format_.output_stream().num_channels()); | 1290 shared_state_.api_format_.output_stream().num_channels()); |
| 1238 msg->set_num_reverse_channels( | 1291 msg->set_num_reverse_channels( |
| 1239 shared_state_.api_format_.reverse_input_stream().num_channels()); | 1292 shared_state_.api_format_.reverse_input_stream().num_channels()); |
| 1240 msg->set_reverse_sample_rate( | 1293 msg->set_reverse_sample_rate( |
| 1241 shared_state_.api_format_.reverse_input_stream().sample_rate_hz()); | 1294 shared_state_.api_format_.reverse_input_stream().sample_rate_hz()); |
| 1242 msg->set_output_sample_rate( | 1295 msg->set_output_sample_rate( |
| 1243 shared_state_.api_format_.output_stream().sample_rate_hz()); | 1296 shared_state_.api_format_.output_stream().sample_rate_hz()); |
| 1244 // TODO(ekmeyerson): Add reverse output fields to event_msg_. | 1297 // TODO(ekmeyerson): Add reverse output fields to event_msg_. |
| 1245 | 1298 |
| 1246 RETURN_ON_ERR(WriteMessageToDebugFile()); | 1299 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 1247 return kNoError; | 1300 return kNoError; |
| 1248 } | 1301 } |
| 1249 | 1302 |
| 1250 int AudioProcessingImpl::WriteConfigMessage(bool forced) { | 1303 int AudioProcessingImpl::WriteConfigMessage(bool forced) { |
| 1304 RTC_DCHECK(capture_thread_checker_.CalledOnValidThread()); | |
| 1251 audioproc::Config config; | 1305 audioproc::Config config; |
| 1252 | 1306 |
| 1253 config.set_aec_enabled(echo_cancellation_->is_enabled()); | 1307 config.set_aec_enabled(echo_cancellation_->is_enabled()); |
| 1254 config.set_aec_delay_agnostic_enabled( | 1308 config.set_aec_delay_agnostic_enabled( |
| 1255 echo_cancellation_->is_delay_agnostic_enabled()); | 1309 echo_cancellation_->is_delay_agnostic_enabled()); |
| 1256 config.set_aec_drift_compensation_enabled( | 1310 config.set_aec_drift_compensation_enabled( |
| 1257 echo_cancellation_->is_drift_compensation_enabled()); | 1311 echo_cancellation_->is_drift_compensation_enabled()); |
| 1258 config.set_aec_extended_filter_enabled( | 1312 config.set_aec_extended_filter_enabled( |
| 1259 echo_cancellation_->is_extended_filter_enabled()); | 1313 echo_cancellation_->is_extended_filter_enabled()); |
| 1260 config.set_aec_suppression_level( | 1314 config.set_aec_suppression_level( |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1287 | 1341 |
| 1288 event_msg_->set_type(audioproc::Event::CONFIG); | 1342 event_msg_->set_type(audioproc::Event::CONFIG); |
| 1289 event_msg_->mutable_config()->CopyFrom(config); | 1343 event_msg_->mutable_config()->CopyFrom(config); |
| 1290 | 1344 |
| 1291 RETURN_ON_ERR(WriteMessageToDebugFile()); | 1345 RETURN_ON_ERR(WriteMessageToDebugFile()); |
| 1292 return kNoError; | 1346 return kNoError; |
| 1293 } | 1347 } |
| 1294 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP | 1348 #endif // WEBRTC_AUDIOPROC_DEBUG_DUMP |
| 1295 | 1349 |
| 1296 } // namespace webrtc | 1350 } // namespace webrtc |
| OLD | NEW |