| 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/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 class MEDIA_EXPORT AudioInputController | 75 class MEDIA_EXPORT AudioInputController |
| 76 : public base::RefCountedThreadSafe<AudioInputController>, | 76 : public base::RefCountedThreadSafe<AudioInputController>, |
| 77 public AudioInputStream::AudioInputCallback { | 77 public AudioInputStream::AudioInputCallback { |
| 78 public: | 78 public: |
| 79 // An event handler that receives events from the AudioInputController. The | 79 // An event handler that receives events from the AudioInputController. The |
| 80 // following methods are all called on the audio thread. | 80 // following methods are all called on the audio thread. |
| 81 class MEDIA_EXPORT EventHandler { | 81 class MEDIA_EXPORT EventHandler { |
| 82 public: | 82 public: |
| 83 virtual void OnCreated(AudioInputController* controller) = 0; | 83 virtual void OnCreated(AudioInputController* controller) = 0; |
| 84 virtual void OnRecording(AudioInputController* controller) = 0; | 84 virtual void OnRecording(AudioInputController* controller) = 0; |
| 85 virtual void OnError(AudioInputController* controller, int error_code) = 0; | 85 virtual void OnError(AudioInputController* controller) = 0; |
| 86 virtual void OnData(AudioInputController* controller, const uint8* data, | 86 virtual void OnData(AudioInputController* controller, const uint8* data, |
| 87 uint32 size) = 0; | 87 uint32 size) = 0; |
| 88 | 88 |
| 89 protected: | 89 protected: |
| 90 virtual ~EventHandler() {} | 90 virtual ~EventHandler() {} |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // A synchronous writer interface used by AudioInputController for | 93 // A synchronous writer interface used by AudioInputController for |
| 94 // synchronous writing. | 94 // synchronous writing. |
| 95 class SyncWriter { | 95 class SyncWriter { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 177 |
| 178 // Sets the Automatic Gain Control (AGC) state of the input stream. | 178 // Sets the Automatic Gain Control (AGC) state of the input stream. |
| 179 // Changing the AGC state is not supported while recording is active. | 179 // Changing the AGC state is not supported while recording is active. |
| 180 virtual void SetAutomaticGainControl(bool enabled); | 180 virtual void SetAutomaticGainControl(bool enabled); |
| 181 | 181 |
| 182 // AudioInputCallback implementation. Threading details depends on the | 182 // AudioInputCallback implementation. Threading details depends on the |
| 183 // device-specific implementation. | 183 // device-specific implementation. |
| 184 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, | 184 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, |
| 185 uint32 hardware_delay_bytes, double volume) OVERRIDE; | 185 uint32 hardware_delay_bytes, double volume) OVERRIDE; |
| 186 virtual void OnClose(AudioInputStream* stream) OVERRIDE; | 186 virtual void OnClose(AudioInputStream* stream) OVERRIDE; |
| 187 virtual void OnError(AudioInputStream* stream, int code) OVERRIDE; | 187 virtual void OnError(AudioInputStream* stream) OVERRIDE; |
| 188 | 188 |
| 189 bool LowLatencyMode() const { return sync_writer_ != NULL; } | 189 bool LowLatencyMode() const { return sync_writer_ != NULL; } |
| 190 | 190 |
| 191 protected: | 191 protected: |
| 192 friend class base::RefCountedThreadSafe<AudioInputController>; | 192 friend class base::RefCountedThreadSafe<AudioInputController>; |
| 193 | 193 |
| 194 // Internal state of the source. | 194 // Internal state of the source. |
| 195 enum State { | 195 enum State { |
| 196 kEmpty, | 196 kEmpty, |
| 197 kCreated, | 197 kCreated, |
| 198 kRecording, | 198 kRecording, |
| 199 kClosed, | 199 kClosed, |
| 200 kError | 200 kError |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); | 203 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); |
| 204 virtual ~AudioInputController(); | 204 virtual ~AudioInputController(); |
| 205 | 205 |
| 206 // Methods called on the audio thread (owned by the AudioManager). | 206 // Methods called on the audio thread (owned by the AudioManager). |
| 207 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 207 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, |
| 208 const std::string& device_id); | 208 const std::string& device_id); |
| 209 void DoCreateForStream(AudioInputStream* stream_to_control); | 209 void DoCreateForStream(AudioInputStream* stream_to_control); |
| 210 void DoRecord(); | 210 void DoRecord(); |
| 211 void DoClose(); | 211 void DoClose(); |
| 212 void DoReportError(int code); | 212 void DoReportError(); |
| 213 void DoSetVolume(double volume); | 213 void DoSetVolume(double volume); |
| 214 void DoSetAutomaticGainControl(bool enabled); | 214 void DoSetAutomaticGainControl(bool enabled); |
| 215 | 215 |
| 216 // Method which ensures that OnError() is triggered when data recording | 216 // Method which ensures that OnError() is triggered when data recording |
| 217 // times out. Called on the audio thread. | 217 // times out. Called on the audio thread. |
| 218 void DoCheckForNoData(); | 218 void DoCheckForNoData(); |
| 219 | 219 |
| 220 // Helper method that stops, closes, and NULL:s |*stream_|. | 220 // Helper method that stops, closes, and NULL:s |*stream_|. |
| 221 // Signals event when done if the event is not NULL. | 221 // Signals event when done if the event is not NULL. |
| 222 void DoStopCloseAndClearStream(base::WaitableEvent* done); | 222 void DoStopCloseAndClearStream(base::WaitableEvent* done); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 static Factory* factory_; | 263 static Factory* factory_; |
| 264 | 264 |
| 265 double max_volume_; | 265 double max_volume_; |
| 266 | 266 |
| 267 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 267 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 } // namespace media | 270 } // namespace media |
| 271 | 271 |
| 272 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 272 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |