| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // An event handler that receives events from the AudioInputController. The | 112 // An event handler that receives events from the AudioInputController. The |
| 113 // following methods are all called on the audio thread. | 113 // following methods are all called on the audio thread. |
| 114 class MEDIA_EXPORT EventHandler { | 114 class MEDIA_EXPORT EventHandler { |
| 115 public: | 115 public: |
| 116 virtual void OnCreated(AudioInputController* controller) = 0; | 116 virtual void OnCreated(AudioInputController* controller) = 0; |
| 117 virtual void OnRecording(AudioInputController* controller) = 0; | 117 virtual void OnRecording(AudioInputController* controller) = 0; |
| 118 virtual void OnError(AudioInputController* controller, | 118 virtual void OnError(AudioInputController* controller, |
| 119 ErrorCode error_code) = 0; | 119 ErrorCode error_code) = 0; |
| 120 virtual void OnData(AudioInputController* controller, const uint8* data, | 120 virtual void OnData(AudioInputController* controller, |
| 121 uint32 size) = 0; | 121 const AudioBus* data) = 0; |
| 122 virtual void OnLog(AudioInputController* controller, | 122 virtual void OnLog(AudioInputController* controller, |
| 123 const std::string& message) = 0; | 123 const std::string& message) = 0; |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 virtual ~EventHandler() {} | 126 virtual ~EventHandler() {} |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 // A synchronous writer interface used by AudioInputController for | 129 // A synchronous writer interface used by AudioInputController for |
| 130 // synchronous writing. | 130 // synchronous writing. |
| 131 class SyncWriter { | 131 class SyncWriter { |
| 132 public: | 132 public: |
| 133 virtual ~SyncWriter() {} | 133 virtual ~SyncWriter() {} |
| 134 | 134 |
| 135 // Notify the synchronous writer about the number of bytes in the | 135 // Notify the synchronous writer about the number of bytes in the |
| 136 // soundcard which has been recorded. | 136 // soundcard which has been recorded. |
| 137 virtual void UpdateRecordedBytes(uint32 bytes) = 0; | 137 virtual void UpdateRecordedBytes(uint32 bytes) = 0; |
| 138 | 138 |
| 139 // Write certain amount of data from |data|. This method returns | 139 // Write certain amount of data from |data|. |
| 140 // number of written bytes. | 140 virtual void Write(const AudioBus* data, |
| 141 virtual uint32 Write(const void* data, | 141 double volume, |
| 142 uint32 size, | 142 bool key_pressed) = 0; |
| 143 double volume, | |
| 144 bool key_pressed) = 0; | |
| 145 | 143 |
| 146 // Close this synchronous writer. | 144 // Close this synchronous writer. |
| 147 virtual void Close() = 0; | 145 virtual void Close() = 0; |
| 148 }; | 146 }; |
| 149 | 147 |
| 150 // AudioInputController::Create() can use the currently registered Factory | 148 // AudioInputController::Create() can use the currently registered Factory |
| 151 // to create the AudioInputController. Factory is intended for testing only. | 149 // to create the AudioInputController. Factory is intended for testing only. |
| 152 // |user_input_monitor| is used for typing detection and can be NULL. | 150 // |user_input_monitor| is used for typing detection and can be NULL. |
| 153 class Factory { | 151 class Factory { |
| 154 public: | 152 public: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Sets the capture volume of the input stream. The value 0.0 corresponds | 221 // Sets the capture volume of the input stream. The value 0.0 corresponds |
| 224 // to muted and 1.0 to maximum volume. | 222 // to muted and 1.0 to maximum volume. |
| 225 virtual void SetVolume(double volume); | 223 virtual void SetVolume(double volume); |
| 226 | 224 |
| 227 // Sets the Automatic Gain Control (AGC) state of the input stream. | 225 // Sets the Automatic Gain Control (AGC) state of the input stream. |
| 228 // Changing the AGC state is not supported while recording is active. | 226 // Changing the AGC state is not supported while recording is active. |
| 229 virtual void SetAutomaticGainControl(bool enabled); | 227 virtual void SetAutomaticGainControl(bool enabled); |
| 230 | 228 |
| 231 // AudioInputCallback implementation. Threading details depends on the | 229 // AudioInputCallback implementation. Threading details depends on the |
| 232 // device-specific implementation. | 230 // device-specific implementation. |
| 233 virtual void OnData(AudioInputStream* stream, const uint8* src, uint32 size, | 231 virtual void OnData(AudioInputStream* stream, |
| 234 uint32 hardware_delay_bytes, double volume) OVERRIDE; | 232 const AudioBus* source, |
| 233 uint32 hardware_delay_bytes, |
| 234 double volume) OVERRIDE; |
| 235 virtual void OnError(AudioInputStream* stream) OVERRIDE; | 235 virtual void OnError(AudioInputStream* stream) OVERRIDE; |
| 236 | 236 |
| 237 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } | 237 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } |
| 238 | 238 |
| 239 protected: | 239 protected: |
| 240 friend class base::RefCountedThreadSafe<AudioInputController>; | 240 friend class base::RefCountedThreadSafe<AudioInputController>; |
| 241 | 241 |
| 242 // Internal state of the source. | 242 // Internal state of the source. |
| 243 enum State { | 243 enum State { |
| 244 CREATED, | 244 CREATED, |
| 245 RECORDING, | 245 RECORDING, |
| 246 CLOSED | 246 CLOSED |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 AudioInputController(EventHandler* handler, | 249 AudioInputController(EventHandler* handler, |
| 250 SyncWriter* sync_writer, | 250 SyncWriter* sync_writer, |
| 251 UserInputMonitor* user_input_monitor); | 251 UserInputMonitor* user_input_monitor); |
| 252 virtual ~AudioInputController(); | 252 virtual ~AudioInputController(); |
| 253 | 253 |
| 254 // Methods called on the audio thread (owned by the AudioManager). | 254 // Methods called on the audio thread (owned by the AudioManager). |
| 255 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 255 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, |
| 256 const std::string& device_id); | 256 const std::string& device_id); |
| 257 void DoCreateForStream(AudioInputStream* stream_to_control, | 257 void DoCreateForStream(AudioInputStream* stream_to_control, |
| 258 bool enable_nodata_timer); | 258 bool enable_nodata_timer); |
| 259 void DoRecord(); | 259 void DoRecord(); |
| 260 void DoClose(); | 260 void DoClose(); |
| 261 void DoReportError(); | 261 void DoReportError(); |
| 262 void DoSetVolume(double volume); | 262 void DoSetVolume(double volume); |
| 263 void DoSetAutomaticGainControl(bool enabled); | 263 void DoSetAutomaticGainControl(bool enabled); |
| 264 void DoOnData(scoped_ptr<uint8[]> data, uint32 size); | 264 void DoOnData(scoped_ptr<AudioBus> data); |
| 265 void DoLogAudioLevel(float level_dbfs); | 265 void DoLogAudioLevel(float level_dbfs); |
| 266 | 266 |
| 267 // Method to check if we get recorded data after a stream was started, | 267 // Method to check if we get recorded data after a stream was started, |
| 268 // and log the result to UMA. | 268 // and log the result to UMA. |
| 269 void FirstCheckForNoData(); | 269 void FirstCheckForNoData(); |
| 270 | 270 |
| 271 // Method which ensures that OnError() is triggered when data recording | 271 // Method which ensures that OnError() is triggered when data recording |
| 272 // times out. Called on the audio thread. | 272 // times out. Called on the audio thread. |
| 273 void DoCheckForNoData(); | 273 void DoCheckForNoData(); |
| 274 | 274 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 double max_volume_; | 319 double max_volume_; |
| 320 | 320 |
| 321 UserInputMonitor* user_input_monitor_; | 321 UserInputMonitor* user_input_monitor_; |
| 322 | 322 |
| 323 #if defined(AUDIO_POWER_MONITORING) | 323 #if defined(AUDIO_POWER_MONITORING) |
| 324 // Scans audio samples from OnData() as input to compute audio levels. | 324 // Scans audio samples from OnData() as input to compute audio levels. |
| 325 scoped_ptr<AudioPowerMonitor> audio_level_; | 325 scoped_ptr<AudioPowerMonitor> audio_level_; |
| 326 | 326 |
| 327 // We need these to be able to feed data to the AudioPowerMonitor. | 327 // We need these to be able to feed data to the AudioPowerMonitor. |
| 328 scoped_ptr<AudioBus> audio_bus_; | |
| 329 media::AudioParameters audio_params_; | 328 media::AudioParameters audio_params_; |
| 330 base::TimeTicks last_audio_level_log_time_; | 329 base::TimeTicks last_audio_level_log_time_; |
| 331 #endif | 330 #endif |
| 332 | 331 |
| 333 size_t prev_key_down_count_; | 332 size_t prev_key_down_count_; |
| 334 | 333 |
| 335 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 334 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 336 }; | 335 }; |
| 337 | 336 |
| 338 } // namespace media | 337 } // namespace media |
| 339 | 338 |
| 340 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 339 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |