| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 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 executed after that. | 151 // are freed on the audio thread. |closed_task| is executed after that. |
| 152 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| | 152 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| |
| 153 // is called. | 153 // is called. |
| 154 // It is safe to call this method more than once. Calls after the first one | 154 // It is safe to call this method more than once. Calls after the first one |
| 155 // will have no effect. | 155 // will have no effect. |
| 156 // This method is called on the audio thread. | 156 // This method is called on the audio thread. |
| 157 virtual void Close(const base::Closure& closed_task); | 157 virtual void Close(const base::Closure& closed_task); |
| 158 | 158 |
| 159 // Sets the capture volume of the input stream. The value 0.0 corresponds |
| 160 // to muted and 1.0 to maximum volume. |
| 161 virtual void SetVolume(double volume); |
| 162 |
| 163 // Sets the Automatic Gain Control (AGC) state of the input stream. |
| 164 virtual void SetAutomaticGainControl(bool enabled); |
| 165 |
| 159 // AudioInputCallback implementation. Threading details depends on the | 166 // AudioInputCallback implementation. Threading details depends on the |
| 160 // device-specific implementation. | 167 // device-specific implementation. |
| 161 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, | 168 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, |
| 162 uint32 hardware_delay_bytes) OVERRIDE; | 169 uint32 hardware_delay_bytes, double volume) OVERRIDE; |
| 163 virtual void OnClose(AudioInputStream* stream) OVERRIDE; | 170 virtual void OnClose(AudioInputStream* stream) OVERRIDE; |
| 164 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE; | 171 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE; |
| 165 | 172 |
| 166 bool LowLatencyMode() const { return sync_writer_ != NULL; } | 173 bool LowLatencyMode() const { return sync_writer_ != NULL; } |
| 167 scoped_refptr<base::MessageLoopProxy> message_loop() const { | 174 scoped_refptr<base::MessageLoopProxy> message_loop() const { |
| 168 return message_loop_; | 175 return message_loop_; |
| 169 } | 176 } |
| 170 | 177 |
| 171 protected: | 178 protected: |
| 172 // Internal state of the source. | 179 // Internal state of the source. |
| 173 enum State { | 180 enum State { |
| 174 kEmpty, | 181 kEmpty, |
| 175 kCreated, | 182 kCreated, |
| 176 kRecording, | 183 kRecording, |
| 177 kClosed, | 184 kClosed, |
| 178 kError | 185 kError |
| 179 }; | 186 }; |
| 180 | 187 |
| 181 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 188 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); |
| 182 | 189 |
| 183 // Methods called on the audio thread (owned by the AudioManager). | 190 // Methods called on the audio thread (owned by the AudioManager). |
| 184 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 191 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, |
| 185 const std::string& device_id); | 192 const std::string& device_id); |
| 186 void DoRecord(); | 193 void DoRecord(); |
| 187 void DoClose(const base::Closure& closed_task); | 194 void DoClose(const base::Closure& closed_task); |
| 188 void DoReportError(int code); | 195 void DoReportError(int code); |
| 196 void DoSetVolume(double volume); |
| 197 void DoSetAutomaticGainControl(bool enabled); |
| 189 | 198 |
| 190 // Methods which ensures that OnError() is triggered when data recording | 199 // Methods which ensures that OnError() is triggered when data recording |
| 191 // times out. Both are called on the creating thread. | 200 // times out. Both are called on the creating thread. |
| 192 void DoReportNoDataError(); | 201 void DoReportNoDataError(); |
| 193 void DoResetNoDataTimer(); | 202 void DoResetNoDataTimer(); |
| 194 | 203 |
| 195 // Helper method that stops, closes, and NULL:s |*stream_|. | 204 // Helper method that stops, closes, and NULL:s |*stream_|. |
| 196 // Signals event when done if the event is not NULL. | 205 // Signals event when done if the event is not NULL. |
| 197 void DoStopCloseAndClearStream(base::WaitableEvent* done); | 206 void DoStopCloseAndClearStream(base::WaitableEvent* done); |
| 198 | 207 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 221 // reading on the audio input controller thread. | 230 // reading on the audio input controller thread. |
| 222 State state_; | 231 State state_; |
| 223 | 232 |
| 224 base::Lock lock_; | 233 base::Lock lock_; |
| 225 | 234 |
| 226 // SyncWriter is used only in low-latency mode for synchronous writing. | 235 // SyncWriter is used only in low-latency mode for synchronous writing. |
| 227 SyncWriter* sync_writer_; | 236 SyncWriter* sync_writer_; |
| 228 | 237 |
| 229 static Factory* factory_; | 238 static Factory* factory_; |
| 230 | 239 |
| 240 double max_volume_; |
| 241 |
| 231 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 242 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 232 }; | 243 }; |
| 233 | 244 |
| 234 } // namespace media | 245 } // namespace media |
| 235 | 246 |
| 236 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 247 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |