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

Unified Diff: content/renderer/media/media_stream_audio_processor.cc

Issue 1528473003: Feed the WebRTC APM with empty far-end frames for the number of frames skipped by OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review. Rebase. Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_audio_processor.cc
diff --git a/content/renderer/media/media_stream_audio_processor.cc b/content/renderer/media/media_stream_audio_processor.cc
index 5e4c1c0569d0c01044246d82c01ab07a12b74392..b3ae7c6efcc762b4d407ebb0e91f0f18d8409242 100644
--- a/content/renderer/media/media_stream_audio_processor.cc
+++ b/content/renderer/media/media_stream_audio_processor.cc
@@ -279,7 +279,8 @@ MediaStreamAudioProcessor::MediaStreamAudioProcessor(
playout_data_source_(playout_data_source),
audio_mirroring_(false),
typing_detected_(false),
- stopped_(false) {
+ stopped_(false),
+ skipped_output_frames_(0) {
capture_thread_checker_.DetachFromThread();
render_thread_checker_.DetachFromThread();
InitializeAudioProcessingModule(constraints, input_params);
@@ -432,7 +433,8 @@ void MediaStreamAudioProcessor::OnIpcClosing() {
void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus,
int sample_rate,
- int audio_delay_milliseconds) {
+ int audio_delay_milliseconds,
+ uint32_t skipped_frames) {
DCHECK(render_thread_checker_.CalledOnValidThread());
DCHECK(audio_processing_->echo_control_mobile()->is_enabled() ^
audio_processing_->echo_cancellation()->is_enabled());
@@ -447,6 +449,25 @@ void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus,
render_fifo_->Push(
*audio_bus, base::TimeDelta::FromMilliseconds(audio_delay_milliseconds));
+
+ // Feed the APM with empty frames if frames have been skipped. The APM only
+ // accepts 10 ms chunks.
+ skipped_output_frames_ += skipped_frames;
+ uint32_t frames_per_10ms = static_cast<uint32_t>(sample_rate / 100);
+ if (skipped_output_frames_ > frames_per_10ms) {
+ MediaStreamAudioBus empty_bus(audio_bus->channels(), frames_per_10ms);
+ empty_bus.bus()->Zero();
+ while (skipped_output_frames_ > frames_per_10ms) {
+ audio_processing_->AnalyzeReverseStream(
+ empty_bus.channel_ptrs(),
+ empty_bus.bus()->frames(),
+ sample_rate,
+ ChannelsToLayout(empty_bus.bus()->channels()));
+ skipped_output_frames_ -= frames_per_10ms;
+ }
+ }
+
+ // Pull data from the fifo and feed the APM.
MediaStreamAudioBus* analysis_bus;
base::TimeDelta audio_delay;
while (render_fifo_->Consume(&analysis_bus, &audio_delay)) {
@@ -455,7 +476,7 @@ void MediaStreamAudioProcessor::OnPlayoutData(media::AudioBus* audio_bus,
analysis_bus->channel_ptrs(),
analysis_bus->bus()->frames(),
sample_rate,
- ChannelsToLayout(audio_bus->channels()));
+ ChannelsToLayout(analysis_bus->bus()->channels()));
}
}
« no previous file with comments | « content/renderer/media/media_stream_audio_processor.h ('k') | content/renderer/media/media_stream_audio_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698