| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 // Only do power monitoring for non-mobile platforms to save resources. | 78 // Only do power monitoring for non-mobile platforms to save resources. |
| 79 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 79 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 80 #define AUDIO_POWER_MONITORING | 80 #define AUDIO_POWER_MONITORING |
| 81 #endif | 81 #endif |
| 82 | 82 |
| 83 class UserInputMonitor; | 83 class UserInputMonitor; |
| 84 | 84 |
| 85 class MEDIA_EXPORT AudioInputController | 85 class MEDIA_EXPORT AudioInputController |
| 86 : public base::RefCountedThreadSafe<AudioInputController>, | 86 : public base::RefCountedThreadSafe<AudioInputController>, |
| 87 public AudioInputStream::AudioInputCallback { | 87 public AudioInputStream::AudioInputCallback, |
| 88 public AudioManager::StateChangeListener { |
| 88 public: | 89 public: |
| 89 | 90 |
| 90 // Error codes to make native loggin more clear. These error codes are added | 91 // Error codes to make native loggin more clear. These error codes are added |
| 91 // to generic error strings to provide a higher degree of details. | 92 // to generic error strings to provide a higher degree of details. |
| 92 // Changing these values can lead to problems when matching native debug | 93 // Changing these values can lead to problems when matching native debug |
| 93 // logs with the actual cause of error. | 94 // logs with the actual cause of error. |
| 94 enum ErrorCode { | 95 enum ErrorCode { |
| 95 // An unspecified error occured. | 96 // An unspecified error occured. |
| 96 UNKNOWN_ERROR = 0, | 97 UNKNOWN_ERROR = 0, |
| 97 | 98 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 virtual void SetAutomaticGainControl(bool enabled); | 228 virtual void SetAutomaticGainControl(bool enabled); |
| 228 | 229 |
| 229 // AudioInputCallback implementation. Threading details depends on the | 230 // AudioInputCallback implementation. Threading details depends on the |
| 230 // device-specific implementation. | 231 // device-specific implementation. |
| 231 virtual void OnData(AudioInputStream* stream, | 232 virtual void OnData(AudioInputStream* stream, |
| 232 const AudioBus* source, | 233 const AudioBus* source, |
| 233 uint32 hardware_delay_bytes, | 234 uint32 hardware_delay_bytes, |
| 234 double volume) OVERRIDE; | 235 double volume) OVERRIDE; |
| 235 virtual void OnError(AudioInputStream* stream) OVERRIDE; | 236 virtual void OnError(AudioInputStream* stream) OVERRIDE; |
| 236 | 237 |
| 238 virtual void OnStateChange(const std::string& state) OVERRIDE; |
| 239 |
| 237 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } | 240 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } |
| 238 | 241 |
| 239 protected: | 242 protected: |
| 240 friend class base::RefCountedThreadSafe<AudioInputController>; | 243 friend class base::RefCountedThreadSafe<AudioInputController>; |
| 241 | 244 |
| 242 // Internal state of the source. | 245 // Internal state of the source. |
| 243 enum State { | 246 enum State { |
| 244 CREATED, | 247 CREATED, |
| 245 RECORDING, | 248 RECORDING, |
| 246 CLOSED | 249 CLOSED |
| (...skipping 12 matching lines...) Expand all Loading... |
| 259 // SILENCE_STATE_NO_MEASUREMENT | 262 // SILENCE_STATE_NO_MEASUREMENT |
| 260 enum SilenceState { | 263 enum SilenceState { |
| 261 SILENCE_STATE_NO_MEASUREMENT = 0, | 264 SILENCE_STATE_NO_MEASUREMENT = 0, |
| 262 SILENCE_STATE_ONLY_AUDIO = 1, | 265 SILENCE_STATE_ONLY_AUDIO = 1, |
| 263 SILENCE_STATE_ONLY_SILENCE = 2, | 266 SILENCE_STATE_ONLY_SILENCE = 2, |
| 264 SILENCE_STATE_AUDIO_AND_SILENCE = 3, | 267 SILENCE_STATE_AUDIO_AND_SILENCE = 3, |
| 265 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE | 268 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE |
| 266 }; | 269 }; |
| 267 #endif | 270 #endif |
| 268 | 271 |
| 269 AudioInputController(EventHandler* handler, | 272 AudioInputController(AudioManager* audio_manager, |
| 273 EventHandler* handler, |
| 270 SyncWriter* sync_writer, | 274 SyncWriter* sync_writer, |
| 271 UserInputMonitor* user_input_monitor); | 275 UserInputMonitor* user_input_monitor); |
| 272 virtual ~AudioInputController(); | 276 virtual ~AudioInputController(); |
| 273 | 277 |
| 274 // Methods called on the audio thread (owned by the AudioManager). | 278 // Methods called on the audio thread (owned by the AudioManager). |
| 275 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 279 void DoCreate(const AudioParameters& params, const std::string& device_id); |
| 276 const std::string& device_id); | |
| 277 void DoCreateForLowLatency(AudioManager* audio_manager, | |
| 278 const AudioParameters& params, | |
| 279 const std::string& device_id); | |
| 280 void DoCreateForStream(AudioInputStream* stream_to_control); | 280 void DoCreateForStream(AudioInputStream* stream_to_control); |
| 281 void DoRecord(); | 281 void DoRecord(); |
| 282 void DoClose(); | 282 void DoClose(); |
| 283 void DoReportError(); | 283 void DoReportError(); |
| 284 void DoSetVolume(double volume); | 284 void DoSetVolume(double volume); |
| 285 void DoSetAutomaticGainControl(bool enabled); | 285 void DoSetAutomaticGainControl(bool enabled); |
| 286 void DoOnData(scoped_ptr<AudioBus> data); | 286 void DoOnData(scoped_ptr<AudioBus> data); |
| 287 void DoLogAudioLevel(float level_dbfs); | 287 void DoLogAudioLevel(float level_dbfs); |
| 288 | 288 |
| 289 // Method to check if we get recorded data after a stream was started, | 289 // Method to check if we get recorded data after a stream was started, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 312 // Gives access to the task runner of the creating thread. | 312 // Gives access to the task runner of the creating thread. |
| 313 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; | 313 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; |
| 314 | 314 |
| 315 // The task runner of audio-manager thread that this object runs on. | 315 // The task runner of audio-manager thread that this object runs on. |
| 316 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 316 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 317 | 317 |
| 318 // Contains the AudioInputController::EventHandler which receives state | 318 // Contains the AudioInputController::EventHandler which receives state |
| 319 // notifications from this class. | 319 // notifications from this class. |
| 320 EventHandler* handler_; | 320 EventHandler* handler_; |
| 321 | 321 |
| 322 media::AudioManager* const audio_manager_; |
| 323 |
| 322 // Pointer to the audio input stream object. | 324 // Pointer to the audio input stream object. |
| 323 AudioInputStream* stream_; | 325 AudioInputStream* stream_; |
| 324 | 326 |
| 325 // |no_data_timer_| is used to call OnError() when we stop receiving | 327 // |no_data_timer_| is used to call OnError() when we stop receiving |
| 326 // OnData() calls. This can occur when an audio input device is unplugged | 328 // OnData() calls. This can occur when an audio input device is unplugged |
| 327 // whilst recording on Windows. | 329 // whilst recording on Windows. |
| 328 // See http://crbug.com/79936 for details. | 330 // See http://crbug.com/79936 for details. |
| 329 // This member is only touched by the audio thread. | 331 // This member is only touched by the audio thread. |
| 330 scoped_ptr<base::Timer> no_data_timer_; | 332 scoped_ptr<base::Timer> no_data_timer_; |
| 331 | 333 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 #endif | 369 #endif |
| 368 | 370 |
| 369 size_t prev_key_down_count_; | 371 size_t prev_key_down_count_; |
| 370 | 372 |
| 371 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 373 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 372 }; | 374 }; |
| 373 | 375 |
| 374 } // namespace media | 376 } // namespace media |
| 375 | 377 |
| 376 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 378 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |