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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 // exclusively. | 129 // exclusively. |
130 class MediaStreamAudioBus { | 130 class MediaStreamAudioBus { |
131 public: | 131 public: |
132 MediaStreamAudioBus(int channels, int frames) | 132 MediaStreamAudioBus(int channels, int frames) |
133 : bus_(media::AudioBus::Create(channels, frames)), | 133 : bus_(media::AudioBus::Create(channels, frames)), |
134 channel_ptrs_(new float*[channels]) { | 134 channel_ptrs_(new float*[channels]) { |
135 // May be created in the main render thread and used in the audio threads. | 135 // May be created in the main render thread and used in the audio threads. |
136 thread_checker_.DetachFromThread(); | 136 thread_checker_.DetachFromThread(); |
137 } | 137 } |
138 | 138 |
139 void ReattachThreadChecker() { | |
140 thread_checker_.DetachFromThread(); | |
141 DCHECK(thread_checker_.CalledOnValidThread()); | |
tommi (sloooow) - chröme
2016/06/13 14:15:20
nit: The DCHECK() part here isn't needed. Just ca
Henrik Grunell
2016/06/14 11:30:00
Well. There could be a context switch after detach
| |
142 } | |
143 | |
139 media::AudioBus* bus() { | 144 media::AudioBus* bus() { |
140 DCHECK(thread_checker_.CalledOnValidThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
141 return bus_.get(); | 146 return bus_.get(); |
142 } | 147 } |
143 | 148 |
144 float* const* channel_ptrs() { | 149 float* const* channel_ptrs() { |
145 DCHECK(thread_checker_.CalledOnValidThread()); | 150 DCHECK(thread_checker_.CalledOnValidThread()); |
146 for (int i = 0; i < bus_->channels(); ++i) { | 151 for (int i = 0; i < bus_->channels(); ++i) { |
147 channel_ptrs_[i] = bus_->channel(i); | 152 channel_ptrs_[i] = bus_->channel(i); |
148 } | 153 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 // possible, twice the larger of the two is a (probably) loose upper bound | 192 // possible, twice the larger of the two is a (probably) loose upper bound |
188 // on the FIFO size. | 193 // on the FIFO size. |
189 const int fifo_frames = 2 * std::max(source_frames, destination_frames); | 194 const int fifo_frames = 2 * std::max(source_frames, destination_frames); |
190 fifo_.reset(new media::AudioFifo(destination_channels, fifo_frames)); | 195 fifo_.reset(new media::AudioFifo(destination_channels, fifo_frames)); |
191 } | 196 } |
192 | 197 |
193 // May be created in the main render thread and used in the audio threads. | 198 // May be created in the main render thread and used in the audio threads. |
194 thread_checker_.DetachFromThread(); | 199 thread_checker_.DetachFromThread(); |
195 } | 200 } |
196 | 201 |
202 void ReattachThreadChecker() { | |
203 thread_checker_.DetachFromThread(); | |
204 DCHECK(thread_checker_.CalledOnValidThread()); | |
205 destination_->ReattachThreadChecker(); | |
206 } | |
207 | |
197 void Push(const media::AudioBus& source, base::TimeDelta audio_delay) { | 208 void Push(const media::AudioBus& source, base::TimeDelta audio_delay) { |
198 DCHECK(thread_checker_.CalledOnValidThread()); | 209 DCHECK(thread_checker_.CalledOnValidThread()); |
199 DCHECK_EQ(source.channels(), source_channels_); | 210 DCHECK_EQ(source.channels(), source_channels_); |
200 DCHECK_EQ(source.frames(), source_frames_); | 211 DCHECK_EQ(source.frames(), source_frames_); |
201 | 212 |
202 const media::AudioBus* source_to_push = &source; | 213 const media::AudioBus* source_to_push = &source; |
203 | 214 |
204 if (audio_source_intermediate_) { | 215 if (audio_source_intermediate_) { |
205 for (int i = 0; i < destination_->bus()->channels(); ++i) { | 216 for (int i = 0; i < destination_->bus()->channels(); ++i) { |
206 audio_source_intermediate_->SetChannelData( | 217 audio_source_intermediate_->SetChannelData( |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 } | 478 } |
468 | 479 |
469 void MediaStreamAudioProcessor::OnPlayoutDataSourceChanged() { | 480 void MediaStreamAudioProcessor::OnPlayoutDataSourceChanged() { |
470 DCHECK(main_thread_checker_.CalledOnValidThread()); | 481 DCHECK(main_thread_checker_.CalledOnValidThread()); |
471 // There is no need to hold a lock here since the caller guarantees that | 482 // There is no need to hold a lock here since the caller guarantees that |
472 // there is no more OnPlayoutData() callback on the render thread. | 483 // there is no more OnPlayoutData() callback on the render thread. |
473 render_thread_checker_.DetachFromThread(); | 484 render_thread_checker_.DetachFromThread(); |
474 render_fifo_.reset(); | 485 render_fifo_.reset(); |
475 } | 486 } |
476 | 487 |
488 void MediaStreamAudioProcessor::OnRenderThreadChanged() { | |
489 render_thread_checker_.DetachFromThread(); | |
490 DCHECK(render_thread_checker_.CalledOnValidThread()); | |
491 render_fifo_->ReattachThreadChecker(); | |
492 } | |
493 | |
477 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { | 494 void MediaStreamAudioProcessor::GetStats(AudioProcessorStats* stats) { |
478 stats->typing_noise_detected = | 495 stats->typing_noise_detected = |
479 (base::subtle::Acquire_Load(&typing_detected_) != false); | 496 (base::subtle::Acquire_Load(&typing_detected_) != false); |
480 GetAecStats(audio_processing_.get()->echo_cancellation(), stats); | 497 GetAecStats(audio_processing_.get()->echo_cancellation(), stats); |
481 } | 498 } |
482 | 499 |
483 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( | 500 void MediaStreamAudioProcessor::InitializeAudioProcessingModule( |
484 const blink::WebMediaConstraints& constraints, | 501 const blink::WebMediaConstraints& constraints, |
485 const MediaStreamDevice::AudioDeviceParameters& input_params) { | 502 const MediaStreamDevice::AudioDeviceParameters& input_params) { |
486 DCHECK(main_thread_checker_.CalledOnValidThread()); | 503 DCHECK(main_thread_checker_.CalledOnValidThread()); |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 if (echo_information_) { | 759 if (echo_information_) { |
743 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); | 760 echo_information_.get()->UpdateAecDelayStats(ap->echo_cancellation()); |
744 } | 761 } |
745 | 762 |
746 // Return 0 if the volume hasn't been changed, and otherwise the new volume. | 763 // Return 0 if the volume hasn't been changed, and otherwise the new volume. |
747 return (agc->stream_analog_level() == volume) ? | 764 return (agc->stream_analog_level() == volume) ? |
748 0 : agc->stream_analog_level(); | 765 0 : agc->stream_analog_level(); |
749 } | 766 } |
750 | 767 |
751 } // namespace content | 768 } // namespace content |
OLD | NEW |