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