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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/synchronization/condition_variable.h" | |
tommi (sloooow) - chröme
2013/02/08 14:56:57
remove
phoglund_chromium
2013/02/08 16:10:38
Done.
| |
13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
15 #include "content/renderer/media/webrtc_audio_device_impl.h" | 16 #include "content/renderer/media/webrtc_audio_device_impl.h" |
16 #include "content/renderer/media/webrtc_local_audio_renderer.h" | 17 #include "content/renderer/media/webrtc_local_audio_renderer.h" |
17 #include "media/audio/audio_input_device.h" | 18 #include "media/audio/audio_input_device.h" |
18 #include "media/base/audio_capturer_source.h" | 19 #include "media/base/audio_capturer_source.h" |
19 #include "media/base/audio_fifo.h" | 20 #include "media/base/audio_fifo.h" |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 class AudioBus; | 23 class AudioBus; |
23 } | 24 } |
24 | 25 |
25 namespace content { | 26 namespace content { |
26 | 27 |
27 class WebRtcAudioCapturerSink; | 28 class WebRtcAudioCapturerSink; |
28 class WebRtcLocalAudioRenderer; | 29 class WebRtcLocalAudioRenderer; |
30 class CaptureBuffer; | |
tommi (sloooow) - chröme
2013/02/08 14:56:57
can we make this a private class inside WebRtcAudi
phoglund_chromium
2013/02/08 16:10:38
Done.
| |
29 | 31 |
30 // This class manages the capture data flow by getting data from its | 32 // This class manages the capture data flow by getting data from its |
31 // |source_|, and passing it to its |sink_|. | 33 // |source_|, and passing it to its |sink_|. |
32 // It allows clients to inject their own capture data source by calling | 34 // It allows clients to inject their own capture data source by calling |
33 // SetCapturerSource(). It is also possible to enable a local sink and | 35 // SetCapturerSource(). It is also possible to enable a local sink and |
34 // register a callback which the sink can call when it wants to read captured | 36 // register a callback which the sink can call when it wants to read captured |
35 // data cached in a FIFO for local loopback rendering. | 37 // data cached in a FIFO for local loopback rendering. |
36 // The threading model for this class is rather complex since it will be | 38 // The threading model for this class is rather complex since it will be |
37 // created on the main render thread, captured data is provided on a dedicated | 39 // created on the main render thread, captured data is provided on a dedicated |
38 // AudioInputDevice thread, and methods can be called either on the Libjingle | 40 // AudioInputDevice thread, and methods can be called either on the Libjingle |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 160 |
159 protected: | 161 protected: |
160 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; | 162 friend class base::RefCountedThreadSafe<WebRtcAudioCapturer>; |
161 virtual ~WebRtcAudioCapturer(); | 163 virtual ~WebRtcAudioCapturer(); |
162 | 164 |
163 private: | 165 private: |
164 typedef std::list<WebRtcAudioCapturerSink*> SinkList; | 166 typedef std::list<WebRtcAudioCapturerSink*> SinkList; |
165 | 167 |
166 WebRtcAudioCapturer(); | 168 WebRtcAudioCapturer(); |
167 | 169 |
170 // Reconfigures the capturer with a new buffer size and capture parameters. | |
171 // Must be called without holding the lock. Returns true on success. | |
172 bool Reconfigure(int sample_rate, media::AudioParameters::Format format, | |
173 media::ChannelLayout channel_layout); | |
174 | |
168 // Used to DCHECK that we are called on the correct thread. | 175 // Used to DCHECK that we are called on the correct thread. |
169 base::ThreadChecker thread_checker_; | 176 base::ThreadChecker thread_checker_; |
170 | 177 |
171 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|, | 178 // Protects |source_|, |sinks_|, |running_|, |on_device_stopped_cb_|, |
172 // |loopback_fifo_| and |buffering_|. | 179 // |loopback_fifo_|, |params| and |buffering_|. |
tommi (sloooow) - chröme
2013/02/08 14:56:57
params_
phoglund_chromium
2013/02/08 16:10:38
Done.
| |
173 base::Lock lock_; | 180 base::Lock lock_; |
174 | 181 |
175 // A list of sinks that the audio data is fed to. | 182 // A list of sinks that the audio data is fed to. |
176 SinkList sinks_; | 183 SinkList sinks_; |
177 | 184 |
178 // The audio data source from the browser process. | 185 // The audio data source from the browser process. |
179 scoped_refptr<media::AudioCapturerSource> source_; | 186 scoped_refptr<media::AudioCapturerSource> source_; |
180 | 187 |
181 // Cached values of utilized audio parameters. Platform dependent. | 188 // Cached values of utilized audio parameters. Platform dependent. |
182 media::AudioParameters params_; | 189 media::AudioParameters params_; |
183 | 190 |
184 // Buffers used for temporary storage during capture callbacks. | 191 // Buffers used for temporary storage during capture callbacks. |
185 // Allocated during initialization. | 192 // Allocated during initialization. |
186 scoped_array<int16> buffer_; | 193 scoped_refptr<CaptureBuffer> buffer_; |
187 std::string device_id_; | 194 std::string device_id_; |
188 bool running_; | 195 bool running_; |
189 | 196 |
190 // Callback object which is called during OnDeviceStopped(). | 197 // Callback object which is called during OnDeviceStopped(). |
191 // Informs a local sink that it should stop asking for data. | 198 // Informs a local sink that it should stop asking for data. |
192 base::Closure on_device_stopped_cb_; | 199 base::Closure on_device_stopped_cb_; |
193 | 200 |
194 // Contains copies of captured audio frames. Only utilized in loopback | 201 // Contains copies of captured audio frames. Only utilized in loopback |
195 // mode when a local sink has been set. | 202 // mode when a local sink has been set. |
196 scoped_ptr<media::AudioFifo> loopback_fifo_; | 203 scoped_ptr<media::AudioFifo> loopback_fifo_; |
197 | 204 |
198 // True when FIFO is utilized, false otherwise. | 205 // True when FIFO is utilized, false otherwise. |
199 bool buffering_; | 206 bool buffering_; |
200 | 207 |
201 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); | 208 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); |
202 }; | 209 }; |
203 | 210 |
204 } // namespace content | 211 } // namespace content |
205 | 212 |
206 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ | 213 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ |
OLD | NEW |