| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
| 17 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
| 18 #include "media/audio/audio_manager_base.h" | 18 #include "media/audio/audio_manager_base.h" |
| 19 #include "media/audio/audio_parameters.h" |
| 20 #include "media/audio/audio_power_monitor.h" |
| 21 #include "media/base/audio_bus.h" |
| 19 | 22 |
| 20 // An AudioInputController controls an AudioInputStream and records data | 23 // An AudioInputController controls an AudioInputStream and records data |
| 21 // from this input stream. The two main methods are Record() and Close() and | 24 // from this input stream. The two main methods are Record() and Close() and |
| 22 // they are both executed on the audio thread which is injected by the two | 25 // they are both executed on the audio thread which is injected by the two |
| 23 // alternative factory methods, Create() or CreateLowLatency(). | 26 // alternative factory methods, Create() or CreateLowLatency(). |
| 24 // | 27 // |
| 25 // All public methods of AudioInputController are non-blocking. | 28 // All public methods of AudioInputController are non-blocking. |
| 26 // | 29 // |
| 27 // Here is a state diagram for the AudioInputController: | 30 // Here is a state diagram for the AudioInputController: |
| 28 // | 31 // |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Closure::Run() <-----------------. | 68 // Closure::Run() <-----------------. |
| 66 // (closure-task) | 69 // (closure-task) |
| 67 // | 70 // |
| 68 // The audio thread itself is owned by the AudioManager that the | 71 // The audio thread itself is owned by the AudioManager that the |
| 69 // AudioInputController holds a reference to. When performing tasks on the | 72 // AudioInputController holds a reference to. When performing tasks on the |
| 70 // audio thread, the controller must not add or release references to the | 73 // audio thread, the controller must not add or release references to the |
| 71 // AudioManager or itself (since it in turn holds a reference to the manager). | 74 // AudioManager or itself (since it in turn holds a reference to the manager). |
| 72 // | 75 // |
| 73 namespace media { | 76 namespace media { |
| 74 | 77 |
| 78 // Only do power monitoring for non-mobile platforms to save resources. |
| 79 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 80 #define AUDIO_POWER_MONITORING |
| 81 #endif |
| 82 |
| 75 class UserInputMonitor; | 83 class UserInputMonitor; |
| 76 | 84 |
| 77 class MEDIA_EXPORT AudioInputController | 85 class MEDIA_EXPORT AudioInputController |
| 78 : public base::RefCountedThreadSafe<AudioInputController>, | 86 : public base::RefCountedThreadSafe<AudioInputController>, |
| 79 public AudioInputStream::AudioInputCallback { | 87 public AudioInputStream::AudioInputCallback { |
| 80 public: | 88 public: |
| 81 | 89 |
| 82 // Error codes to make native loggin more clear. These error codes are added | 90 // Error codes to make native loggin more clear. These error codes are added |
| 83 // to generic error strings to provide a higher degree of details. | 91 // to generic error strings to provide a higher degree of details. |
| 84 // Changing these values can lead to problems when matching native debug | 92 // Changing these values can lead to problems when matching native debug |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 | 310 |
| 303 // SyncWriter is used only in low-latency mode for synchronous writing. | 311 // SyncWriter is used only in low-latency mode for synchronous writing. |
| 304 SyncWriter* sync_writer_; | 312 SyncWriter* sync_writer_; |
| 305 | 313 |
| 306 static Factory* factory_; | 314 static Factory* factory_; |
| 307 | 315 |
| 308 double max_volume_; | 316 double max_volume_; |
| 309 | 317 |
| 310 UserInputMonitor* user_input_monitor_; | 318 UserInputMonitor* user_input_monitor_; |
| 311 | 319 |
| 320 #if defined(AUDIO_POWER_MONITORING) |
| 321 // Scans audio samples from OnData() as input to compute audio levels. |
| 322 scoped_ptr<AudioPowerMonitor> audio_level_; |
| 323 |
| 324 // We need these to be able to feed data to the AudioPowerMonitor. |
| 325 scoped_ptr<AudioBus> audio_bus_; |
| 326 media::AudioParameters audio_params_; |
| 327 base::TimeTicks last_audio_level_log_time_; |
| 328 #endif |
| 329 |
| 312 size_t prev_key_down_count_; | 330 size_t prev_key_down_count_; |
| 313 | 331 |
| 314 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 332 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 315 }; | 333 }; |
| 316 | 334 |
| 317 } // namespace media | 335 } // namespace media |
| 318 | 336 |
| 319 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 337 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |