OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/media_stream_audio_processor.h" | 5 #include "content/renderer/media/media_stream_audio_processor.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 StopEchoCancellationDump(audio_processing_.get()); | 425 StopEchoCancellationDump(audio_processing_.get()); |
426 } | 426 } |
427 | 427 |
428 void MediaStreamAudioProcessor::OnIpcClosing() { | 428 void MediaStreamAudioProcessor::OnIpcClosing() { |
429 DCHECK(main_thread_checker_.CalledOnValidThread()); | 429 DCHECK(main_thread_checker_.CalledOnValidThread()); |
430 aec_dump_message_filter_ = NULL; | 430 aec_dump_message_filter_ = NULL; |
431 } | 431 } |
432 | 432 |
433 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, | 433 void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus, |
434 int sample_rate, | 434 int sample_rate, |
435 int audio_delay_milliseconds) { | 435 int audio_delay_milliseconds, |
436 uint32_t skipped_frames) { | |
436 DCHECK(render_thread_checker_.CalledOnValidThread()); | 437 DCHECK(render_thread_checker_.CalledOnValidThread()); |
437 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ | 438 DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^ |
438 audio_processing_->echo_cancellation()->is_enabled()); | 439 audio_processing_->echo_cancellation()->is_enabled()); |
439 | 440 |
440 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); | 441 TRACE_EVENT0("audio", "MediaStreamAudioProcessor::OnPlayoutData"); |
441 DCHECK_LT(audio_delay_milliseconds, | 442 DCHECK_LT(audio_delay_milliseconds, |
442 std::numeric_limits<base::subtle::Atomic32>::max()); | 443 std::numeric_limits<base::subtle::Atomic32>::max()); |
443 base::subtle::Release_Store(&render_delay_ms_, audio_delay_milliseconds); | 444 base::subtle::Release_Store(&render_delay_ms_, audio_delay_milliseconds); |
444 | 445 |
445 InitializeRenderFifoIfNeeded(sample_rate, audio_bus->channels(), | 446 InitializeRenderFifoIfNeeded(sample_rate, audio_bus->channels(), |
446 audio_bus->frames()); | 447 audio_bus->frames()); |
447 | 448 |
448 render_fifo_->Push( | 449 render_fifo_->Push( |
449 *audio_bus, base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); | 450 *audio_bus, base::TimeDelta::FromMilliseconds(audio_delay_milliseconds)); |
451 | |
452 // Feed the APM with empty frames corresponding to |skipped_frames|. | |
453 if (skipped_frames > 0) { | |
454 MediaStreamAudioBus empty_bus(audio_bus->channels(), skipped_frames); | |
peah
2015/12/16 10:26:57
Does this call also set all samples in the empty_b
Henrik Grunell
2015/12/18 10:17:33
I doesn't. Fixed.
| |
455 audio_processing_->AnalyzeReverseStream( | |
456 empty_bus.channel_ptrs(), | |
457 empty_bus.bus()->frames(), | |
peah
2015/12/16 10:26:57
Is there any restriction on the values of skipped_
Henrik Grunell
2015/12/18 10:17:33
No, it can be any value. OK, I added storing the n
peah
2015/12/18 13:34:12
What does this mean? Does it mean that typically a
| |
458 sample_rate, | |
459 ChannelsToLayout(empty_bus.bus()->channels())); | |
460 } | |
461 | |
462 // Pull data from the fifo and feed the APM. | |
450 MediaStreamAudioBus* analysis_bus; | 463 MediaStreamAudioBus* analysis_bus; |
451 base::TimeDelta audio_delay; | 464 base::TimeDelta audio_delay; |
452 while (render_fifo_->Consume(&analysis_bus, &audio_delay)) { | 465 while (render_fifo_->Consume(&analysis_bus, &audio_delay)) { |
453 // TODO(ajm): Should AnalyzeReverseStream() account for the |audio_delay|? | 466 // TODO(ajm): Should AnalyzeReverseStream() account for the |audio_delay|? |
454 audio_processing_->AnalyzeReverseStream( | 467 audio_processing_->AnalyzeReverseStream( |
455 analysis_bus->channel_ptrs(), | 468 analysis_bus->channel_ptrs(), |
456 analysis_bus->bus()->frames(), | 469 analysis_bus->bus()->frames(), |
457 sample_rate, | 470 sample_rate, |
458 ChannelsToLayout(audio_bus->channels())); | 471 ChannelsToLayout(analysis_bus->bus()->channels())); |
459 } | 472 } |
460 } | 473 } |
461 | 474 |
462 void MediaStreamAudioProcessor::OnPlayoutDataSourceChanged() { | 475 void MediaStreamAudioProcessor::OnPlayoutDataSourceChanged() { |
463 DCHECK(main_thread_checker_.CalledOnValidThread()); | 476 DCHECK(main_thread_checker_.CalledOnValidThread()); |
464 // There is no need to hold a lock here since the caller guarantees that | 477 // There is no need to hold a lock here since the caller guarantees that |
465 // there is no more OnPlayoutData() callback on the render thread. | 478 // there is no more OnPlayoutData() callback on the render thread. |
466 render_thread_checker_.DetachFromThread(); | 479 render_thread_checker_.DetachFromThread(); |
467 render_fifo_.reset(); | 480 render_fifo_.reset(); |
468 } | 481 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 if (echo_information_) { | 757 if (echo_information_) { |
745 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); | 758 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); |
746 } | 759 } |
747 | 760 |
748 // Return 0 if the volume hasn't been changed, and otherwise the new volume. | 761 // Return 0 if the volume hasn't been changed, and otherwise the new volume. |
749 return (agc->stream_analog_level() == volume) ? | 762 return (agc->stream_analog_level() == volume) ? |
750 0 : agc->stream_analog_level(); | 763 0 : agc->stream_analog_level(); |
751 } | 764 } |
752 | 765 |
753 } // namespace content | 766 } // namespace content |
OLD | NEW |