Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: content/renderer/media/audio_input_device.h

Issue 10790121: First step towards moving AudioDevice from content/ to media/audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: relaxing the notreached back to log(error) since nacl tests will otherwise fail Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Low-latency audio capturing unit utilizing audio input stream provided 5 // Low-latency audio capturing unit utilizing audio input stream provided
6 // by browser process through IPC. 6 // by browser process through IPC.
7 // 7 //
8 // Relationship of classes: 8 // Relationship of classes:
9 // 9 //
10 // AudioInputController AudioInputDevice 10 // AudioInputController AudioInputDevice
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 #include "content/renderer/media/audio_input_message_filter.h" 80 #include "content/renderer/media/audio_input_message_filter.h"
81 #include "content/renderer/media/scoped_loop_observer.h" 81 #include "content/renderer/media/scoped_loop_observer.h"
82 #include "media/audio/audio_parameters.h" 82 #include "media/audio/audio_parameters.h"
83 83
84 // TODO(henrika): This class is based on the AudioDevice class and it has 84 // TODO(henrika): This class is based on the AudioDevice class and it has
85 // many components in common. Investigate potential for re-factoring. 85 // many components in common. Investigate potential for re-factoring.
86 // TODO(henrika): Add support for event handling (e.g. OnStateChanged, 86 // TODO(henrika): Add support for event handling (e.g. OnStateChanged,
87 // OnCaptureStopped etc.) and ensure that we can deliver these notifications 87 // OnCaptureStopped etc.) and ensure that we can deliver these notifications
88 // to any clients using this class. 88 // to any clients using this class.
89 class CONTENT_EXPORT AudioInputDevice 89 class CONTENT_EXPORT AudioInputDevice
90 : public AudioInputMessageFilter::Delegate, 90 : NON_EXPORTED_BASE(public media::AudioInputDeviceIPCDelegate),
91 NON_EXPORTED_BASE(public ScopedLoopObserver), 91 NON_EXPORTED_BASE(public ScopedLoopObserver),
92 public base::RefCountedThreadSafe<AudioInputDevice> { 92 public base::RefCountedThreadSafe<AudioInputDevice> {
93 public: 93 public:
94 class CONTENT_EXPORT CaptureCallback { 94 class CONTENT_EXPORT CaptureCallback {
95 public: 95 public:
96 virtual void Capture(const std::vector<float*>& audio_data, 96 virtual void Capture(const std::vector<float*>& audio_data,
97 int number_of_frames, 97 int number_of_frames,
98 int audio_delay_milliseconds, 98 int audio_delay_milliseconds,
99 double volume) = 0; 99 double volume) = 0;
100 virtual void OnCaptureError() = 0; 100 virtual void OnCaptureError() = 0;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 int buffer_size() const { 149 int buffer_size() const {
150 return audio_parameters_.frames_per_buffer(); 150 return audio_parameters_.frames_per_buffer();
151 } 151 }
152 152
153 // Sets the Automatic Gain Control state to on or off. 153 // Sets the Automatic Gain Control state to on or off.
154 // This method must be called before Start(). It will not have any effect 154 // This method must be called before Start(). It will not have any effect
155 // if it is called while capturing has already started. 155 // if it is called while capturing has already started.
156 void SetAutomaticGainControl(bool enabled); 156 void SetAutomaticGainControl(bool enabled);
157 157
158 // Methods called on IO thread ---------------------------------------------- 158 // Methods called on IO thread ----------------------------------------------
159 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter. 159 // media::AudioInputDeviceIPCDelegate implementation.
160 virtual void OnStreamCreated(base::SharedMemoryHandle handle, 160 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
161 base::SyncSocket::Handle socket_handle, 161 base::SyncSocket::Handle socket_handle,
162 uint32 length) OVERRIDE; 162 uint32 length) OVERRIDE;
163 virtual void OnVolume(double volume) OVERRIDE; 163 virtual void OnVolume(double volume) OVERRIDE;
164 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; 164 virtual void OnStateChanged(
165 media::AudioInputDeviceIPCDelegate::State state) OVERRIDE;
165 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; 166 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE;
167 virtual void OnIPCClosed() OVERRIDE;
166 168
167 protected: 169 protected:
168 virtual ~AudioInputDevice(); 170 virtual ~AudioInputDevice();
169 171
170 private: 172 private:
171 friend class base::RefCountedThreadSafe<AudioInputDevice>; 173 friend class base::RefCountedThreadSafe<AudioInputDevice>;
172 174
173 // Methods called on IO thread ---------------------------------------------- 175 // Methods called on IO thread ----------------------------------------------
174 // The following methods are tasks posted on the IO thread that needs to 176 // The following methods are tasks posted on the IO thread that needs to
175 // be executed on that thread. They interact with AudioInputMessageFilter and 177 // be executed on that thread. They interact with AudioInputMessageFilter and
176 // sends IPC messages on that thread. 178 // sends IPC messages on that thread.
177 void InitializeOnIOThread(); 179 void InitializeOnIOThread();
178 void SetSessionIdOnIOThread(int session_id); 180 void SetSessionIdOnIOThread(int session_id);
179 void StartOnIOThread(); 181 void StartOnIOThread();
180 void ShutDownOnIOThread(); 182 void ShutDownOnIOThread();
181 void SetVolumeOnIOThread(double volume); 183 void SetVolumeOnIOThread(double volume);
182 void SetAutomaticGainControlOnIOThread(bool enabled); 184 void SetAutomaticGainControlOnIOThread(bool enabled);
183 185
184 void Send(IPC::Message* message);
185
186 // MessageLoop::DestructionObserver implementation for the IO loop. 186 // MessageLoop::DestructionObserver implementation for the IO loop.
187 // If the IO loop dies before we do, we shut down the audio thread from here. 187 // If the IO loop dies before we do, we shut down the audio thread from here.
188 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 188 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
189 189
190 // Format 190 // Format
191 media::AudioParameters audio_parameters_; 191 media::AudioParameters audio_parameters_;
192 192
193 CaptureCallback* callback_; 193 CaptureCallback* callback_;
194 CaptureEventHandler* event_handler_; 194 CaptureEventHandler* event_handler_;
195 195
196 // The current volume scaling [0.0, 1.0] of the audio stream. 196 media::AudioInputDeviceIPC* ipc_;
197 double volume_;
198
199 // Cached audio input message filter (lives on the main render thread).
200 scoped_refptr<AudioInputMessageFilter> filter_;
201 197
202 // Our stream ID on the message filter. Only modified on the IO thread. 198 // Our stream ID on the message filter. Only modified on the IO thread.
203 int32 stream_id_; 199 int32 stream_id_;
204 200
205 // The media session ID used to identify which input device to be started. 201 // The media session ID used to identify which input device to be started.
206 // Only modified on the IO thread. 202 // Only modified on the IO thread.
207 int session_id_; 203 int session_id_;
208 204
209 // State variable used to indicate it is waiting for a OnDeviceReady() 205 // State variable used to indicate it is waiting for a OnDeviceReady()
210 // callback. Only modified on the IO thread. 206 // callback. Only modified on the IO thread.
211 bool pending_device_ready_; 207 bool pending_device_ready_;
212 208
213 // Stores the Automatic Gain Control state. Default is false. 209 // Stores the Automatic Gain Control state. Default is false.
214 // Only modified on the IO thread. 210 // Only modified on the IO thread.
215 bool agc_is_enabled_; 211 bool agc_is_enabled_;
216 212
217 // Our audio thread callback class. See source file for details. 213 // Our audio thread callback class. See source file for details.
218 class AudioThreadCallback; 214 class AudioThreadCallback;
219 215
220 // In order to avoid a race between OnStreamCreated and Stop(), we use this 216 // In order to avoid a race between OnStreamCreated and Stop(), we use this
221 // guard to control stopping and starting the audio thread. 217 // guard to control stopping and starting the audio thread.
222 base::Lock audio_thread_lock_; 218 base::Lock audio_thread_lock_;
223 AudioDeviceThread audio_thread_; 219 AudioDeviceThread audio_thread_;
224 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; 220 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_;
225 221
226 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); 222 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
227 }; 223 };
228 224
229 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ 225 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698