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/webrtc_local_audio_source_provider.h" | 5 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/renderer/render_thread_impl.h" | 8 #include "content/renderer/render_thread_impl.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/audio_fifo.h" | 10 #include "media/base/audio_fifo.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 media::CHANNEL_LAYOUT_STEREO, 2, 0, sample_rate, 16, | 36 media::CHANNEL_LAYOUT_STEREO, 2, 0, sample_rate, 16, |
37 kWebAudioRenderBufferSize); | 37 kWebAudioRenderBufferSize); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 WebRtcLocalAudioSourceProvider::~WebRtcLocalAudioSourceProvider() { | 41 WebRtcLocalAudioSourceProvider::~WebRtcLocalAudioSourceProvider() { |
42 if (audio_converter_.get()) | 42 if (audio_converter_.get()) |
43 audio_converter_->RemoveInput(this); | 43 audio_converter_->RemoveInput(this); |
44 } | 44 } |
45 | 45 |
46 void WebRtcLocalAudioSourceProvider::SetCaptureFormat( | 46 void WebRtcLocalAudioSourceProvider::OnSetFormat( |
47 const media::AudioParameters& params) { | 47 const media::AudioParameters& params) { |
48 // We need detach the thread here because it will be a new capture thread | 48 // We need detach the thread here because it will be a new capture thread |
49 // calling SetCaptureFormat() and CaptureData() if the source is restarted. | 49 // calling OnSetFormat() and OnData() if the source is restarted. |
50 capture_thread_checker_.DetachFromThread(); | 50 capture_thread_checker_.DetachFromThread(); |
51 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 51 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
52 DCHECK(params.IsValid()); | 52 DCHECK(params.IsValid()); |
53 DCHECK(sink_params_.IsValid()); | 53 DCHECK(sink_params_.IsValid()); |
54 | 54 |
55 base::AutoLock auto_lock(lock_); | 55 base::AutoLock auto_lock(lock_); |
56 source_params_ = params; | 56 source_params_ = params; |
57 // Create the audio converter with |disable_fifo| as false so that the | 57 // Create the audio converter with |disable_fifo| as false so that the |
58 // converter will request source_params.frames_per_buffer() each time. | 58 // converter will request source_params.frames_per_buffer() each time. |
59 // This will not increase the complexity as there is only one client to | 59 // This will not increase the complexity as there is only one client to |
60 // the converter. | 60 // the converter. |
61 audio_converter_.reset( | 61 audio_converter_.reset( |
62 new media::AudioConverter(params, sink_params_, false)); | 62 new media::AudioConverter(params, sink_params_, false)); |
63 audio_converter_->AddInput(this); | 63 audio_converter_->AddInput(this); |
64 fifo_.reset(new media::AudioFifo( | 64 fifo_.reset(new media::AudioFifo( |
65 params.channels(), | 65 params.channels(), |
66 kMaxNumberOfBuffers * params.frames_per_buffer())); | 66 kMaxNumberOfBuffers * params.frames_per_buffer())); |
67 input_bus_ = media::AudioBus::Create(params.channels(), | 67 input_bus_ = media::AudioBus::Create(params.channels(), |
68 params.frames_per_buffer()); | 68 params.frames_per_buffer()); |
69 } | 69 } |
70 | 70 |
71 int WebRtcLocalAudioSourceProvider::CaptureData( | 71 void WebRtcLocalAudioSourceProvider::OnData( |
72 const std::vector<int>& channels, | |
73 const int16* audio_data, | 72 const int16* audio_data, |
74 int sample_rate, | 73 int sample_rate, |
75 int number_of_channels, | 74 int number_of_channels, |
76 int number_of_frames, | 75 int number_of_frames) { |
77 int audio_delay_milliseconds, | |
78 int current_volume, | |
79 bool need_audio_processing, | |
80 bool key_pressed) { | |
81 DCHECK(capture_thread_checker_.CalledOnValidThread()); | 76 DCHECK(capture_thread_checker_.CalledOnValidThread()); |
82 base::AutoLock auto_lock(lock_); | 77 base::AutoLock auto_lock(lock_); |
83 if (!is_enabled_) | 78 if (!is_enabled_) |
84 return 0; | 79 return; |
85 | 80 |
86 DCHECK(fifo_.get()); | 81 DCHECK(fifo_.get()); |
87 | 82 |
88 // TODO(xians): A better way to handle the interleaved and deinterleaved | 83 // TODO(xians): A better way to handle the interleaved and deinterleaved |
89 // format switching, see issue/317710. | 84 // format switching, see issue/317710. |
90 DCHECK(input_bus_->frames() == number_of_frames); | 85 DCHECK(input_bus_->frames() == number_of_frames); |
91 DCHECK(input_bus_->channels() == number_of_channels); | 86 DCHECK(input_bus_->channels() == number_of_channels); |
92 input_bus_->FromInterleaved(audio_data, number_of_frames, 2); | 87 input_bus_->FromInterleaved(audio_data, number_of_frames, 2); |
93 | 88 |
94 if (fifo_->frames() + number_of_frames <= fifo_->max_frames()) { | 89 if (fifo_->frames() + number_of_frames <= fifo_->max_frames()) { |
95 fifo_->Push(input_bus_.get()); | 90 fifo_->Push(input_bus_.get()); |
96 } else { | 91 } else { |
97 // This can happen if the data in FIFO is too slowed to be consumed or | 92 // This can happen if the data in FIFO is too slowed to be consumed or |
98 // WebAudio stops consuming data. | 93 // WebAudio stops consuming data. |
99 DLOG(WARNING) << "Local source provicer FIFO is full" << fifo_->frames(); | 94 DLOG(WARNING) << "Local source provicer FIFO is full" << fifo_->frames(); |
100 } | 95 } |
101 | |
102 return 0; | |
103 } | 96 } |
104 | 97 |
105 void WebRtcLocalAudioSourceProvider::setClient( | 98 void WebRtcLocalAudioSourceProvider::setClient( |
106 blink::WebAudioSourceProviderClient* client) { | 99 blink::WebAudioSourceProviderClient* client) { |
107 NOTREACHED(); | 100 NOTREACHED(); |
108 } | 101 } |
109 | 102 |
110 void WebRtcLocalAudioSourceProvider::provideInput( | 103 void WebRtcLocalAudioSourceProvider::provideInput( |
111 const WebVector<float*>& audio_data, size_t number_of_frames) { | 104 const WebVector<float*>& audio_data, size_t number_of_frames) { |
112 DCHECK_EQ(number_of_frames, kWebAudioRenderBufferSize); | 105 DCHECK_EQ(number_of_frames, kWebAudioRenderBufferSize); |
(...skipping 27 matching lines...) Expand all Loading... |
140 | 133 |
141 return 1.0; | 134 return 1.0; |
142 } | 135 } |
143 | 136 |
144 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting( | 137 void WebRtcLocalAudioSourceProvider::SetSinkParamsForTesting( |
145 const media::AudioParameters& sink_params) { | 138 const media::AudioParameters& sink_params) { |
146 sink_params_ = sink_params; | 139 sink_params_ = sink_params; |
147 } | 140 } |
148 | 141 |
149 } // namespace content | 142 } // namespace content |
OLD | NEW |