Chromium Code Reviews| 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 // 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 : public AudioInputMessageFilter::Delegate, |
| 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 size_t number_of_frames, | 97 size_t number_of_frames, |
| 98 size_t audio_delay_milliseconds) = 0; | 98 size_t audio_delay_milliseconds, |
| 99 double volume) = 0; | |
| 99 virtual void OnCaptureError() = 0; | 100 virtual void OnCaptureError() = 0; |
| 100 protected: | 101 protected: |
| 101 virtual ~CaptureCallback() {} | 102 virtual ~CaptureCallback() {} |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 class CONTENT_EXPORT CaptureEventHandler { | 105 class CONTENT_EXPORT CaptureEventHandler { |
| 105 public: | 106 public: |
| 106 // Notification to the client that the device with the specific |device_id| | 107 // Notification to the client that the device with the specific |device_id| |
| 107 // has been started. | 108 // has been started. |
| 108 // This callback is triggered as a result of StartDevice(). | 109 // This callback is triggered as a result of StartDevice(). |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 137 void Stop(); | 138 void Stop(); |
| 138 | 139 |
| 139 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive. | 140 // Sets the capture volume scaling, with range [0.0, 1.0] inclusive. |
| 140 // Returns |true| on success. | 141 // Returns |true| on success. |
| 141 bool SetVolume(double volume); | 142 bool SetVolume(double volume); |
| 142 | 143 |
| 143 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive. | 144 // Gets the capture volume scaling, with range [0.0, 1.0] inclusive. |
| 144 // Returns |true| on success. | 145 // Returns |true| on success. |
| 145 bool GetVolume(double* volume); | 146 bool GetVolume(double* volume); |
| 146 | 147 |
| 148 // Sets the Automatic Gain Control state to on or off. | |
| 149 // TODO(henrika): extend the comments here... | |
|
tommi (sloooow) - chröme
2012/03/16 13:31:05
ping (or just remove the todo)
scherkus (not reviewing)
2012/03/20 13:49:41
ping again! :P
henrika (OOO until Aug 14)
2012/03/21 10:16:04
Much better now ;-)
| |
| 150 void SetAutomaticGainControl(bool enabled); | |
| 151 | |
| 147 double sample_rate() const { return audio_parameters_.sample_rate; } | 152 double sample_rate() const { return audio_parameters_.sample_rate; } |
| 148 size_t buffer_size() const { return audio_parameters_.samples_per_packet; } | 153 size_t buffer_size() const { return audio_parameters_.samples_per_packet; } |
| 149 | 154 |
| 150 // Methods called on IO thread ---------------------------------------------- | 155 // Methods called on IO thread ---------------------------------------------- |
| 151 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter | 156 // AudioInputMessageFilter::Delegate impl., called by AudioInputMessageFilter |
| 152 virtual void OnStreamCreated(base::SharedMemoryHandle handle, | 157 virtual void OnStreamCreated(base::SharedMemoryHandle handle, |
| 153 base::SyncSocket::Handle socket_handle, | 158 base::SyncSocket::Handle socket_handle, |
| 154 uint32 length) OVERRIDE; | 159 uint32 length) OVERRIDE; |
| 155 virtual void OnVolume(double volume) OVERRIDE; | 160 virtual void OnVolume(double volume) OVERRIDE; |
| 156 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; | 161 virtual void OnStateChanged(AudioStreamState state) OVERRIDE; |
| 157 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; | 162 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE; |
| 158 | 163 |
| 159 private: | 164 private: |
| 160 // Methods called on IO thread ---------------------------------------------- | 165 // Methods called on IO thread ---------------------------------------------- |
| 161 // The following methods are tasks posted on the IO thread that needs to | 166 // The following methods are tasks posted on the IO thread that needs to |
| 162 // be executed on that thread. They interact with AudioInputMessageFilter and | 167 // be executed on that thread. They interact with AudioInputMessageFilter and |
| 163 // sends IPC messages on that thread. | 168 // sends IPC messages on that thread. |
| 164 void InitializeOnIOThread(); | 169 void InitializeOnIOThread(); |
| 165 void SetSessionIdOnIOThread(int session_id); | 170 void SetSessionIdOnIOThread(int session_id); |
| 166 void StartOnIOThread(); | 171 void StartOnIOThread(); |
| 167 void ShutDownOnIOThread(); | 172 void ShutDownOnIOThread(); |
| 168 void SetVolumeOnIOThread(double volume); | 173 void SetVolumeOnIOThread(double volume); |
| 174 void SetAutomaticGainControlOnIOThread(bool enabled); | |
| 169 | 175 |
| 170 void Send(IPC::Message* message); | 176 void Send(IPC::Message* message); |
| 171 | 177 |
| 172 // MessageLoop::DestructionObserver implementation for the IO loop. | 178 // MessageLoop::DestructionObserver implementation for the IO loop. |
| 173 // If the IO loop dies before we do, we shut down the audio thread from here. | 179 // If the IO loop dies before we do, we shut down the audio thread from here. |
| 174 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | 180 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
| 175 | 181 |
| 176 // Format | 182 // Format |
| 177 AudioParameters audio_parameters_; | 183 AudioParameters audio_parameters_; |
| 178 | 184 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 189 int32 stream_id_; | 195 int32 stream_id_; |
| 190 | 196 |
| 191 // The media session ID used to identify which input device to be started. | 197 // The media session ID used to identify which input device to be started. |
| 192 // Only modified on the IO thread. | 198 // Only modified on the IO thread. |
| 193 int session_id_; | 199 int session_id_; |
| 194 | 200 |
| 195 // State variable used to indicate it is waiting for a OnDeviceReady() | 201 // State variable used to indicate it is waiting for a OnDeviceReady() |
| 196 // callback. Only modified on the IO thread. | 202 // callback. Only modified on the IO thread. |
| 197 bool pending_device_ready_; | 203 bool pending_device_ready_; |
| 198 | 204 |
| 205 // Stores the Automatic Gain Control state. Default is false. | |
| 206 // Only modified on the IO thread. | |
| 207 bool agc_is_enabled_; | |
| 208 | |
| 199 // Our audio thread callback class. See source file for details. | 209 // Our audio thread callback class. See source file for details. |
| 200 class AudioThreadCallback; | 210 class AudioThreadCallback; |
| 201 | 211 |
| 202 // In order to avoid a race between OnStreamCreated and Stop(), we use this | 212 // In order to avoid a race between OnStreamCreated and Stop(), we use this |
| 203 // guard to control stopping and starting the audio thread. | 213 // guard to control stopping and starting the audio thread. |
| 204 base::Lock audio_thread_lock_; | 214 base::Lock audio_thread_lock_; |
| 205 AudioDeviceThread audio_thread_; | 215 AudioDeviceThread audio_thread_; |
| 206 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; | 216 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; |
| 207 | 217 |
| 208 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); | 218 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); |
| 209 }; | 219 }; |
| 210 | 220 |
| 211 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ | 221 #endif // CONTENT_RENDERER_MEDIA_AUDIO_INPUT_DEVICE_H_ |
| OLD | NEW |