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 35b8d9fa24ebc69814515ac97a65f10dfd01821e..6061ed3025f3bb6271c52458d4bed6d0221c2d8b 100644 |
--- a/content/renderer/media/media_stream_audio_processor.cc |
+++ b/content/renderer/media/media_stream_audio_processor.cc |
@@ -141,8 +141,10 @@ class MediaStreamAudioProcessor::MediaStreamAudioConverter |
MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
const media::AudioParameters& source_params, |
const blink::WebMediaConstraints& constraints, |
- int effects) |
- : render_delay_ms_(0) { |
+ int effects, |
+ WebRtcAudioDeviceImpl* audio_device) |
+ : render_delay_ms_(0), |
+ audio_device_(audio_device) { |
capture_thread_checker_.DetachFromThread(); |
render_thread_checker_.DetachFromThread(); |
InitializeAudioProcessingModule(constraints, effects); |
@@ -150,7 +152,6 @@ MediaStreamAudioProcessor::MediaStreamAudioProcessor( |
} |
MediaStreamAudioProcessor::~MediaStreamAudioProcessor() { |
- DCHECK(main_thread_checker_.CalledOnValidThread()); |
StopAudioProcessing(); |
} |
@@ -159,42 +160,11 @@ void MediaStreamAudioProcessor::PushCaptureData(media::AudioBus* audio_source) { |
capture_converter_->Push(audio_source); |
} |
-void MediaStreamAudioProcessor::PushRenderData( |
- const int16* render_audio, int sample_rate, int number_of_channels, |
- int number_of_frames, base::TimeDelta render_delay) { |
- DCHECK(render_thread_checker_.CalledOnValidThread()); |
- |
- // Return immediately if the echo cancellation is off. |
- if (!audio_processing_ || |
- !audio_processing_->echo_cancellation()->is_enabled()) { |
- return; |
- } |
- |
- TRACE_EVENT0("audio", |
- "MediaStreamAudioProcessor::FeedRenderDataToAudioProcessing"); |
- int64 new_render_delay_ms = render_delay.InMilliseconds(); |
- DCHECK_LT(new_render_delay_ms, |
- std::numeric_limits<base::subtle::Atomic32>::max()); |
- base::subtle::Release_Store(&render_delay_ms_, new_render_delay_ms); |
- |
- InitializeRenderConverterIfNeeded(sample_rate, number_of_channels, |
- number_of_frames); |
- |
- // TODO(xians): Avoid this extra interleave/deinterleave. |
- render_data_bus_->FromInterleaved(render_audio, |
- render_data_bus_->frames(), |
- sizeof(render_audio[0])); |
- render_converter_->Push(render_data_bus_.get()); |
- while (render_converter_->Convert(&render_frame_)) |
- audio_processing_->AnalyzeReverseStream(&render_frame_); |
-} |
- |
bool MediaStreamAudioProcessor::ProcessAndConsumeData( |
base::TimeDelta capture_delay, int volume, bool key_pressed, |
int16** out) { |
DCHECK(capture_thread_checker_.CalledOnValidThread()); |
- TRACE_EVENT0("audio", |
- "MediaStreamAudioProcessor::ProcessAndConsumeData"); |
+ TRACE_EVENT0("audio", "MediaStreamAudioProcessor::ProcessAndConsumeData"); |
if (!capture_converter_->Convert(&capture_frame_)) |
return false; |
@@ -213,6 +183,30 @@ const media::AudioParameters& MediaStreamAudioProcessor::OutputFormat() const { |
return capture_converter_->sink_parameters(); |
} |
+void MediaStreamAudioProcessor::RenderData(media::AudioBus* audio_bus, |
+ int sample_rate, |
+ int audio_delay_milliseconds) { |
+ DCHECK(render_thread_checker_.CalledOnValidThread()); |
+ DCHECK(audio_processing_->echo_cancellation()->is_enabled()); |
+ |
+ TRACE_EVENT0("audio", "MediaStreamAudioProcessor::RenderData"); |
+ DCHECK_LT(audio_delay_milliseconds, |
+ std::numeric_limits<base::subtle::Atomic32>::max()); |
+ base::subtle::Release_Store(&render_delay_ms_, audio_delay_milliseconds); |
+ |
+ InitializeRenderConverterIfNeeded(sample_rate, audio_bus->channels(), |
+ audio_bus->frames()); |
+ |
+ render_converter_->Push(audio_bus); |
+ while (render_converter_->Convert(&render_frame_)) |
+ audio_processing_->AnalyzeReverseStream(&render_frame_); |
+} |
+ |
+void MediaStreamAudioProcessor::RemoveAudioRenderer( |
+ WebRtcAudioRenderer* renderer) { |
+ NOTREACHED(); |
+} |
+ |
void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
const blink::WebMediaConstraints& constraints, int effects) { |
DCHECK(!audio_processing_); |
@@ -261,6 +255,9 @@ void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
EnableEchoCancellation(audio_processing_.get()); |
if (enable_experimental_aec) |
EnableExperimentalEchoCancellation(audio_processing_.get()); |
+ |
+ if (audio_device_) |
+ audio_device_->AddRenderDataObserver(this); |
} |
if (enable_ns) |
@@ -383,6 +380,9 @@ void MediaStreamAudioProcessor::StopAudioProcessing() { |
if (!audio_processing_.get()) |
return; |
+ if (audio_device_) |
+ audio_device_->RemoveRenderDataObserver(this); |
+ |
audio_processing_.reset(); |
} |