| 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 MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 6 #define MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 class SyncWriter { | 90 class SyncWriter { |
| 91 public: | 91 public: |
| 92 virtual ~SyncWriter() {} | 92 virtual ~SyncWriter() {} |
| 93 | 93 |
| 94 // Notify the synchronous writer about the number of bytes in the | 94 // Notify the synchronous writer about the number of bytes in the |
| 95 // soundcard which has been recorded. | 95 // soundcard which has been recorded. |
| 96 virtual void UpdateRecordedBytes(uint32 bytes) = 0; | 96 virtual void UpdateRecordedBytes(uint32 bytes) = 0; |
| 97 | 97 |
| 98 // Write certain amount of data from |data|. This method returns | 98 // Write certain amount of data from |data|. This method returns |
| 99 // number of written bytes. | 99 // number of written bytes. |
| 100 virtual uint32 Write(const void* data, uint32 size) = 0; | 100 virtual uint32 Write(const void* data, uint32 size, double volume) = 0; |
| 101 | 101 |
| 102 // Close this synchronous writer. | 102 // Close this synchronous writer. |
| 103 virtual void Close() = 0; | 103 virtual void Close() = 0; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // AudioInputController::Create() can use the currently registered Factory | 106 // AudioInputController::Create() can use the currently registered Factory |
| 107 // to create the AudioInputController. Factory is intended for testing only. | 107 // to create the AudioInputController. Factory is intended for testing only. |
| 108 class Factory { | 108 class Factory { |
| 109 public: | 109 public: |
| 110 virtual AudioInputController* Create(AudioManager* audio_manager, | 110 virtual AudioInputController* Create(AudioManager* audio_manager, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Closes the audio input stream. The state is changed and the resources | 150 // Closes the audio input stream. The state is changed and the resources |
| 151 // are freed on the audio thread. |closed_task| is then executed on the thread | 151 // are freed on the audio thread. |closed_task| is then executed on the thread |
| 152 // that called Close(). | 152 // that called Close(). |
| 153 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| | 153 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| |
| 154 // is called. | 154 // is called. |
| 155 // It is safe to call this method more than once. Calls after the first one | 155 // It is safe to call this method more than once. Calls after the first one |
| 156 // will have no effect. | 156 // will have no effect. |
| 157 // This method trampolines to the audio thread. | 157 // This method trampolines to the audio thread. |
| 158 virtual void Close(const base::Closure& closed_task); | 158 virtual void Close(const base::Closure& closed_task); |
| 159 | 159 |
| 160 // Sets the capture volume of the input stream. The value 0.0 corresponds |
| 161 // to muted and 1.0 to maximum volume. |
| 162 virtual void SetVolume(double volume); |
| 163 |
| 164 // Sets the Automatic Gain Control (AGC) state of the input stream. |
| 165 // Changing the AGC state is not supported while recording is active. |
| 166 virtual void SetAutomaticGainControl(bool enabled); |
| 167 |
| 160 // AudioInputCallback implementation. Threading details depends on the | 168 // AudioInputCallback implementation. Threading details depends on the |
| 161 // device-specific implementation. | 169 // device-specific implementation. |
| 162 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, | 170 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, |
| 163 uint32 hardware_delay_bytes) OVERRIDE; | 171 uint32 hardware_delay_bytes, double volume) OVERRIDE; |
| 164 virtual void OnClose(AudioInputStream* stream) OVERRIDE; | 172 virtual void OnClose(AudioInputStream* stream) OVERRIDE; |
| 165 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE; | 173 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE; |
| 166 | 174 |
| 167 bool LowLatencyMode() const { return sync_writer_ != NULL; } | 175 bool LowLatencyMode() const { return sync_writer_ != NULL; } |
| 168 scoped_refptr<base::MessageLoopProxy> message_loop() const { | 176 scoped_refptr<base::MessageLoopProxy> message_loop() const { |
| 169 return message_loop_; | 177 return message_loop_; |
| 170 } | 178 } |
| 171 | 179 |
| 172 protected: | 180 protected: |
| 173 // Internal state of the source. | 181 // Internal state of the source. |
| 174 enum State { | 182 enum State { |
| 175 kEmpty, | 183 kEmpty, |
| 176 kCreated, | 184 kCreated, |
| 177 kRecording, | 185 kRecording, |
| 178 kClosed, | 186 kClosed, |
| 179 kError | 187 kError |
| 180 }; | 188 }; |
| 181 | 189 |
| 182 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 190 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); |
| 183 | 191 |
| 184 // Methods called on the audio thread (owned by the AudioManager). | 192 // Methods called on the audio thread (owned by the AudioManager). |
| 185 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 193 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, |
| 186 const std::string& device_id); | 194 const std::string& device_id); |
| 187 void DoRecord(); | 195 void DoRecord(); |
| 188 void DoClose(); | 196 void DoClose(); |
| 189 void DoReportError(int code); | 197 void DoReportError(int code); |
| 198 void DoSetVolume(double volume); |
| 199 void DoSetAutomaticGainControl(bool enabled); |
| 190 | 200 |
| 191 // Methods which ensures that OnError() is triggered when data recording | 201 // Methods which ensures that OnError() is triggered when data recording |
| 192 // times out. Both are called on the creating thread. | 202 // times out. Both are called on the creating thread. |
| 193 void DoReportNoDataError(); | 203 void DoReportNoDataError(); |
| 194 void DoResetNoDataTimer(); | 204 void DoResetNoDataTimer(); |
| 195 | 205 |
| 196 // Helper method that stops, closes, and NULL:s |*stream_|. | 206 // Helper method that stops, closes, and NULL:s |*stream_|. |
| 197 // Signals event when done if the event is not NULL. | 207 // Signals event when done if the event is not NULL. |
| 198 void DoStopCloseAndClearStream(base::WaitableEvent* done); | 208 void DoStopCloseAndClearStream(base::WaitableEvent* done); |
| 199 | 209 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 222 // reading on the audio input controller thread. | 232 // reading on the audio input controller thread. |
| 223 State state_; | 233 State state_; |
| 224 | 234 |
| 225 base::Lock lock_; | 235 base::Lock lock_; |
| 226 | 236 |
| 227 // SyncWriter is used only in low-latency mode for synchronous writing. | 237 // SyncWriter is used only in low-latency mode for synchronous writing. |
| 228 SyncWriter* sync_writer_; | 238 SyncWriter* sync_writer_; |
| 229 | 239 |
| 230 static Factory* factory_; | 240 static Factory* factory_; |
| 231 | 241 |
| 242 double max_volume_; |
| 243 |
| 232 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 244 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 233 }; | 245 }; |
| 234 | 246 |
| 235 } // namespace media | 247 } // namespace media |
| 236 | 248 |
| 237 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 249 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |