OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 bool is_recording() const { return running_; } | 129 bool is_recording() const { return running_; } |
130 | 130 |
131 // Returns true if a local renderer has called PrepareLoopback() and it can | 131 // Returns true if a local renderer has called PrepareLoopback() and it can |
132 // be utilized to prevent more than one local renderer. | 132 // be utilized to prevent more than one local renderer. |
133 // Called on the main render thread. | 133 // Called on the main render thread. |
134 bool IsInLoopbackMode(); | 134 bool IsInLoopbackMode(); |
135 | 135 |
136 // Audio parameters utilized by the audio capturer. Can be utilized by | 136 // Audio parameters utilized by the audio capturer. Can be utilized by |
137 // a local renderer to set up a renderer using identical parameters as the | 137 // a local renderer to set up a renderer using identical parameters as the |
138 // capturer. | 138 // capturer. |
139 const media::AudioParameters& audio_parameter() const { return params_; } | 139 // TODO(phoglund): This accessor is inherently unsafe since the returned |
140 // parameters can become outdated at any time. Think over the implications | |
141 // of this accessor and if we can remove it. | |
142 media::AudioParameters audio_parameters(); | |
tommi (sloooow) - chröme
2013/02/08 20:00:39
nit: I think it's still OK to keep the constness o
phoglund_chromium
2013/02/11 09:18:57
Done.
| |
140 | 143 |
141 // AudioCapturerSource::CaptureCallback implementation. | 144 // AudioCapturerSource::CaptureCallback implementation. |
142 // Called on the AudioInputDevice audio thread. | 145 // Called on the AudioInputDevice audio thread. |
143 virtual void Capture(media::AudioBus* audio_source, | 146 virtual void Capture(media::AudioBus* audio_source, |
144 int audio_delay_milliseconds, | 147 int audio_delay_milliseconds, |
145 double volume) OVERRIDE; | 148 double volume) OVERRIDE; |
146 virtual void OnCaptureError() OVERRIDE; | 149 virtual void OnCaptureError() OVERRIDE; |
147 | 150 |
148 // AudioCapturerSource::CaptureEventHandler implementation. | 151 // AudioCapturerSource::CaptureEventHandler implementation. |
149 // Called on the IO thread. | 152 // Called on the IO thread. |
150 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE; | 153 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE; |
151 virtual void OnDeviceStopped() OVERRIDE; | 154 virtual void OnDeviceStopped() OVERRIDE; |
152 | 155 |
153 // WebRtcLocalAudioRenderer::LocalRenderCallback implementation. | 156 // WebRtcLocalAudioRenderer::LocalRenderCallback implementation. |
154 // Reads stored captured data from a local FIFO. This method is used in | 157 // Reads stored captured data from a local FIFO. This method is used in |
155 // combination with a local sink to render captured audio in loopback. | 158 // combination with a local sink to render captured audio in loopback. |
156 // This method is called on the AudioOutputDevice worker thread. | 159 // This method is called on the AudioOutputDevice worker thread. |
157 virtual void ProvideInput(media::AudioBus* dest) OVERRIDE; | 160 virtual void ProvideInput(media::AudioBus* dest) OVERRIDE; |
158 | 161 |
159 protected: | 162 protected: |
160 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; | 163 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; |
161 virtual ~WebRtcAudioCapturer(); | 164 virtual ~WebRtcAudioCapturer(); |
162 | 165 |
163 private: | 166 private: |
164 typedef std::list<WebRtcAudioCapturerSink*> SinkList; | 167 typedef std::list<WebRtcAudioCapturerSink*> SinkList; |
165 | 168 |
166 WebRtcAudioCapturer(); | 169 WebRtcAudioCapturer(); |
167 | 170 |
171 // Reconfigures the capturer with a new buffer size and capture parameters. | |
172 // Must be called without holding the lock. Returns true on success. | |
173 bool Reconfigure(int sample_rate, media::AudioParameters::Format format, | |
174 media::ChannelLayout channel_layout); | |
175 | |
168 // Used to DCHECK that we are called on the correct thread. | 176 // Used to DCHECK that we are called on the correct thread. |
169 base::ThreadChecker thread_checker_; | 177 base::ThreadChecker thread_checker_; |
170 | 178 |
171 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|, | 179 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|, |
172 // |loopback_fifo_| and |buffering_|. | 180 // |loopback_fifo_|, |params_| and |buffering_|. |
173 base::Lock lock_; | 181 base::Lock lock_; |
174 | 182 |
175 // A list of sinks that the audio data is fed to. | 183 // A list of sinks that the audio data is fed to. |
176 SinkList sinks_; | 184 SinkList sinks_; |
177 | 185 |
178 // The audio data source from the browser process. | 186 // The audio data source from the browser process. |
179 scoped_refptr<media::AudioCapturerSource> source_; | 187 scoped_refptr<media::AudioCapturerSource> source_; |
180 | 188 |
181 // Cached values of utilized audio parameters. Platform dependent. | |
182 media::AudioParameters params_; | |
183 | |
184 // Buffers used for temporary storage during capture callbacks. | 189 // Buffers used for temporary storage during capture callbacks. |
185 // Allocated during initialization. | 190 // Allocated during initialization. |
186 scoped_array<int16> buffer_; | 191 class ConfiguredBuffer; |
192 scoped_refptr<ConfiguredBuffer> buffer_; | |
187 std::string device_id_; | 193 std::string device_id_; |
188 bool running_; | 194 bool running_; |
189 | 195 |
190 // Callback object which is called during OnDeviceStopped(). | 196 // Callback object which is called during OnDeviceStopped(). |
191 // Informs a local sink that it should stop asking for data. | 197 // Informs a local sink that it should stop asking for data. |
192 base::Closure on_device_stopped_cb_; | 198 base::Closure on_device_stopped_cb_; |
193 | 199 |
194 // Contains copies of captured audio frames. Only utilized in loopback | 200 // Contains copies of captured audio frames. Only utilized in loopback |
195 // mode when a local sink has been set. | 201 // mode when a local sink has been set. |
196 scoped_ptr<media::AudioFifo> loopback_fifo_; | 202 scoped_ptr<media::AudioFifo> loopback_fifo_; |
197 | 203 |
198 // True when FIFO is utilized, false otherwise. | 204 // True when FIFO is utilized, false otherwise. |
199 bool buffering_; | 205 bool buffering_; |
200 | 206 |
201 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 207 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
202 }; | 208 }; |
203 | 209 |
204 } // namespace content | 210 } // namespace content |
205 | 211 |
206 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 212 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
OLD | NEW |