Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/atomicops.h" | |
| 15 #include "base/callback.h" | |
| 16 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 17 #include "base/macros.h" | |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "base/synchronization/lock.h" | |
| 20 #include "base/synchronization/waitable_event.h" | |
| 21 #include "base/threading/thread.h" | |
| 22 #include "build/build_config.h" | |
| 23 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
| 24 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
| 25 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
| 26 #include "media/base/audio_parameters.h" | 18 #include "media/base/audio_parameters.h" |
| 27 | 19 |
| 28 // An AudioInputController controls an AudioInputStream and records data | 20 // An AudioInputController controls an AudioInputStream and records data |
| 29 // from this input stream. The two main methods are Record() and Close() and | 21 // from this input stream. The two main methods are Record() and Close() and |
| 30 // they are both executed on the audio thread which is injected by the two | 22 // they are both executed on the audio thread which is injected by the two |
| 31 // alternative factory methods, Create() or CreateLowLatency(). | 23 // alternative factory methods, Create() or CreateLowLatency(). |
| 32 // | 24 // |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 48 // | 40 // |
| 49 // [Creating Thread] [Audio Thread] | 41 // [Creating Thread] [Audio Thread] |
| 50 // | 42 // |
| 51 // User AudioInputController EventHandler | 43 // User AudioInputController EventHandler |
| 52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 44 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 53 // CrateLowLatency() ==> DoCreate() | 45 // CrateLowLatency() ==> DoCreate() |
| 54 // AudioManager::MakeAudioInputStream() | 46 // AudioManager::MakeAudioInputStream() |
| 55 // AudioInputStream::Open() | 47 // AudioInputStream::Open() |
| 56 // .- - - - - - - - - - - - -> OnError() | 48 // .- - - - - - - - - - - - -> OnError() |
| 57 // .-------------------------> OnCreated() | 49 // .-------------------------> OnCreated() |
| 58 // kCreated | |
| 59 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 50 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 60 // Record() ==> DoRecord() | 51 // Record() ==> DoRecord() |
| 61 // AudioInputStream::Start() | 52 // AudioInputStream::Start() |
| 62 // kRecording | |
| 63 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 53 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 64 // Close() ==> DoClose() | 54 // Close() ==> DoClose() |
| 65 // state_ = kClosed | |
| 66 // AudioInputStream::Stop() | 55 // AudioInputStream::Stop() |
| 67 // AudioInputStream::Close() | 56 // AudioInputStream::Close() |
| 68 // SyncWriter::Close() | 57 // SyncWriter::Close() |
| 69 // Closure::Run() <-----------------. | 58 // Closure::Run() <-----------------. |
| 70 // (closure-task) | 59 // (closure-task) |
| 71 // | 60 // |
| 72 // The audio thread itself is owned by the AudioManager that the | 61 // The audio thread itself is owned by the AudioManager that the |
| 73 // AudioInputController holds a reference to. When performing tasks on the | 62 // AudioInputController holds a reference to. When performing tasks on the |
| 74 // audio thread, the controller must not add or release references to the | 63 // audio thread, the controller must not add or release references to the |
| 75 // AudioManager or itself (since it in turn holds a reference to the manager). | 64 // AudioManager or itself (since it in turn holds a reference to the manager). |
| 76 // | 65 // |
| 77 namespace media { | 66 namespace media { |
| 78 | 67 |
| 79 // Only do power monitoring for non-mobile platforms to save resources. | 68 // Only do power monitoring for non-mobile platforms to save resources. |
| 80 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 69 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 81 #define AUDIO_POWER_MONITORING | 70 #define AUDIO_POWER_MONITORING |
| 82 #endif | 71 #endif |
| 83 | 72 |
| 84 class AudioInputWriter; | 73 class AudioInputWriter; |
| 85 class UserInputMonitor; | 74 class UserInputMonitor; |
| 86 | 75 |
| 87 class MEDIA_EXPORT AudioInputController | 76 class MEDIA_EXPORT AudioInputController |
| 88 : public base::RefCountedThreadSafe<AudioInputController>, | 77 : public base::RefCountedThreadSafe<AudioInputController> { |
| 89 public AudioInputStream::AudioInputCallback { | |
| 90 public: | 78 public: |
| 91 // Error codes to make native logging more clear. These error codes are added | 79 // Error codes to make native logging more clear. These error codes are added |
| 92 // to generic error strings to provide a higher degree of details. | 80 // to generic error strings to provide a higher degree of details. |
| 93 // Changing these values can lead to problems when matching native debug | 81 // Changing these values can lead to problems when matching native debug |
| 94 // logs with the actual cause of error. | 82 // logs with the actual cause of error. |
| 95 enum ErrorCode { | 83 enum ErrorCode { |
| 96 // An unspecified error occured. | 84 // An unspecified error occured. |
| 97 UNKNOWN_ERROR = 0, | 85 UNKNOWN_ERROR = 0, |
| 98 | 86 |
| 99 // Failed to create an audio input stream. | 87 // Failed to create an audio input stream. |
| 100 STREAM_CREATE_ERROR, // = 1 | 88 STREAM_CREATE_ERROR, // = 1 |
| 101 | 89 |
| 102 // Failed to open an audio input stream. | 90 // Failed to open an audio input stream. |
| 103 STREAM_OPEN_ERROR, // = 2 | 91 STREAM_OPEN_ERROR, // = 2 |
| 104 | 92 |
| 105 // Native input stream reports an error. Exact reason differs between | 93 // Native input stream reports an error. Exact reason differs between |
| 106 // platforms. | 94 // platforms. |
| 107 STREAM_ERROR, // = 3 | 95 STREAM_ERROR, // = 3 |
| 108 }; | 96 }; |
| 109 | 97 |
| 110 // An event handler that receives events from the AudioInputController. The | 98 // An event handler that receives events from the AudioInputController. The |
| 111 // following methods are all called on the audio thread. | 99 // following methods are all called on the audio thread. |
| 112 class MEDIA_EXPORT EventHandler { | 100 class MEDIA_EXPORT EventHandler { |
| 113 public: | 101 public: |
| 114 virtual void OnCreated(AudioInputController* controller) = 0; | 102 virtual void OnCreated(AudioInputController* controller) = 0; |
| 115 virtual void OnError(AudioInputController* controller, | 103 virtual void OnError(AudioInputController* controller, |
| 116 ErrorCode error_code) = 0; | 104 ErrorCode error_code) = 0; |
| 117 virtual void OnData(AudioInputController* controller, | |
| 118 const AudioBus* data) = 0; | |
| 119 virtual void OnLog(AudioInputController* controller, | 105 virtual void OnLog(AudioInputController* controller, |
| 120 const std::string& message) = 0; | 106 const std::string& message) = 0; |
| 121 | 107 |
| 122 protected: | 108 protected: |
| 123 virtual ~EventHandler() {} | 109 virtual ~EventHandler() {} |
| 124 }; | 110 }; |
| 125 | 111 |
| 126 // A synchronous writer interface used by AudioInputController for | 112 // A synchronous writer interface used by AudioInputController for |
| 127 // synchronous writing. | 113 // synchronous writing. |
| 128 class MEDIA_EXPORT SyncWriter { | 114 class MEDIA_EXPORT SyncWriter { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 157 }; | 143 }; |
| 158 | 144 |
| 159 // Factory method for creating an AudioInputController. | 145 // Factory method for creating an AudioInputController. |
| 160 // The audio device will be created on the audio thread, and when that is | 146 // The audio device will be created on the audio thread, and when that is |
| 161 // done, the event handler will receive an OnCreated() call from that same | 147 // done, the event handler will receive an OnCreated() call from that same |
| 162 // thread. |device_id| is the unique ID of the audio device to be opened. | 148 // thread. |device_id| is the unique ID of the audio device to be opened. |
| 163 // |user_input_monitor| is used for typing detection and can be NULL. | 149 // |user_input_monitor| is used for typing detection and can be NULL. |
| 164 static scoped_refptr<AudioInputController> Create( | 150 static scoped_refptr<AudioInputController> Create( |
| 165 AudioManager* audio_manager, | 151 AudioManager* audio_manager, |
| 166 EventHandler* event_handler, | 152 EventHandler* event_handler, |
| 153 SyncWriter* sync_writer, | |
| 167 const AudioParameters& params, | 154 const AudioParameters& params, |
| 168 const std::string& device_id, | 155 const std::string& device_id, |
| 169 UserInputMonitor* user_input_monitor); | 156 UserInputMonitor* user_input_monitor); |
| 170 | 157 |
| 171 // Sets the factory used by the static method Create(). AudioInputController | 158 // Sets the factory used by the static method Create(). AudioInputController |
| 172 // does not take ownership of |factory|. A value of NULL results in an | 159 // does not take ownership of |factory|. A value of NULL results in an |
| 173 // AudioInputController being created directly. | 160 // AudioInputController being created directly. |
| 174 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } | 161 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } |
| 175 AudioInputStream* stream_for_testing() { return stream_; } | 162 AudioInputStream* stream_for_testing() { return stream_; } |
| 176 | 163 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 // is called. | 201 // is called. |
| 215 // It is safe to call this method more than once. Calls after the first one | 202 // It is safe to call this method more than once. Calls after the first one |
| 216 // will have no effect. | 203 // will have no effect. |
| 217 // This method trampolines to the audio thread. | 204 // This method trampolines to the audio thread. |
| 218 virtual void Close(const base::Closure& closed_task); | 205 virtual void Close(const base::Closure& closed_task); |
| 219 | 206 |
| 220 // Sets the capture volume of the input stream. The value 0.0 corresponds | 207 // Sets the capture volume of the input stream. The value 0.0 corresponds |
| 221 // to muted and 1.0 to maximum volume. | 208 // to muted and 1.0 to maximum volume. |
| 222 virtual void SetVolume(double volume); | 209 virtual void SetVolume(double volume); |
| 223 | 210 |
| 224 // AudioInputCallback implementation. Threading details depends on the | |
| 225 // device-specific implementation. | |
| 226 void OnData(AudioInputStream* stream, | |
| 227 const AudioBus* source, | |
| 228 uint32_t hardware_delay_bytes, | |
| 229 double volume) override; | |
| 230 void OnError(AudioInputStream* stream) override; | |
| 231 | |
| 232 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } | |
| 233 | |
| 234 // Enable debug recording of audio input. | 211 // Enable debug recording of audio input. |
| 235 virtual void EnableDebugRecording(const base::FilePath& file_name); | 212 virtual void EnableDebugRecording(const base::FilePath& file_name); |
| 236 | 213 |
| 237 // Disable debug recording of audio input. | 214 // Disable debug recording of audio input. |
| 238 virtual void DisableDebugRecording(); | 215 virtual void DisableDebugRecording(); |
| 239 | 216 |
| 240 protected: | 217 protected: |
| 241 friend class base::RefCountedThreadSafe<AudioInputController>; | 218 friend class base::RefCountedThreadSafe<AudioInputController>; |
| 242 | 219 |
| 243 // Used to log the result of capture startup. | 220 // Used to log the result of capture startup. |
| 244 // This was previously logged as a boolean with only the no callback and OK | 221 // This was previously logged as a boolean with only the no callback and OK |
| 245 // options. The enum order is kept to ensure backwards compatibility. | 222 // options. The enum order is kept to ensure backwards compatibility. |
| 246 // Elements in this enum should not be deleted or rearranged; the only | 223 // Elements in this enum should not be deleted or rearranged; the only |
| 247 // permitted operation is to add new elements before | 224 // permitted operation is to add new elements before |
| 248 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. | 225 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. |
| 249 // | 226 // |
| 250 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA, | 227 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA, |
| 251 // and there are also other histograms such as | 228 // and there are also other histograms such as |
| 252 // Media.Audio.InputStartupSuccessMac to cover issues similar | 229 // Media.Audio.InputStartupSuccessMac to cover issues similar |
| 253 // to the ones the NO_DATA_CALLBACK was intended for. | 230 // to the ones the NO_DATA_CALLBACK was intended for. |
| 254 enum CaptureStartupResult { | 231 enum CaptureStartupResult { |
| 255 CAPTURE_STARTUP_NO_DATA_CALLBACK = 0, // no longer used. | 232 CAPTURE_STARTUP_NO_DATA_CALLBACK = 0, // no longer used. |
| 256 CAPTURE_STARTUP_OK = 1, | 233 CAPTURE_STARTUP_OK = 1, |
| 257 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 2, | 234 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 2, |
| 258 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 3, | 235 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 3, |
| 259 CAPTURE_STARTUP_NEVER_GOT_DATA = 4, | 236 CAPTURE_STARTUP_NEVER_GOT_DATA = 4, |
| 260 CAPTURE_STARTUP_RESULT_MAX = CAPTURE_STARTUP_NEVER_GOT_DATA | 237 CAPTURE_STARTUP_RESULT_MAX = CAPTURE_STARTUP_NEVER_GOT_DATA |
| 261 }; | 238 }; |
| 262 | 239 |
| 263 // Internal state of the source. | |
| 264 enum State { | |
| 265 CREATED, | |
| 266 RECORDING, | |
| 267 CLOSED | |
| 268 }; | |
| 269 | |
| 270 #if defined(AUDIO_POWER_MONITORING) | 240 #if defined(AUDIO_POWER_MONITORING) |
| 271 // Used to log a silence report (see OnData). | 241 // Used to log a silence report (see OnData). |
| 272 // Elements in this enum should not be deleted or rearranged; the only | 242 // Elements in this enum should not be deleted or rearranged; the only |
| 273 // permitted operation is to add new elements before SILENCE_STATE_MAX and | 243 // permitted operation is to add new elements before SILENCE_STATE_MAX and |
| 274 // update SILENCE_STATE_MAX. | 244 // update SILENCE_STATE_MAX. |
| 275 // Possible silence state transitions: | 245 // Possible silence state transitions: |
| 276 // SILENCE_STATE_AUDIO_AND_SILENCE | 246 // SILENCE_STATE_AUDIO_AND_SILENCE |
| 277 // ^ ^ | 247 // ^ ^ |
| 278 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE | 248 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE |
| 279 // ^ ^ | 249 // ^ ^ |
| 280 // SILENCE_STATE_NO_MEASUREMENT | 250 // SILENCE_STATE_NO_MEASUREMENT |
| 281 enum SilenceState { | 251 enum SilenceState { |
| 282 SILENCE_STATE_NO_MEASUREMENT = 0, | 252 SILENCE_STATE_NO_MEASUREMENT = 0, |
| 283 SILENCE_STATE_ONLY_AUDIO = 1, | 253 SILENCE_STATE_ONLY_AUDIO = 1, |
| 284 SILENCE_STATE_ONLY_SILENCE = 2, | 254 SILENCE_STATE_ONLY_SILENCE = 2, |
| 285 SILENCE_STATE_AUDIO_AND_SILENCE = 3, | 255 SILENCE_STATE_AUDIO_AND_SILENCE = 3, |
| 286 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE | 256 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE |
| 287 }; | 257 }; |
| 288 #endif | 258 #endif |
| 289 | 259 |
| 290 AudioInputController(EventHandler* handler, | 260 AudioInputController(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 261 EventHandler* handler, | |
| 291 SyncWriter* sync_writer, | 262 SyncWriter* sync_writer, |
| 292 std::unique_ptr<AudioInputWriter> debug_writer, | 263 std::unique_ptr<AudioInputWriter> debug_writer, |
| 293 UserInputMonitor* user_input_monitor, | 264 UserInputMonitor* user_input_monitor, |
| 294 const bool agc_is_enabled); | 265 const bool agc_is_enabled); |
| 295 ~AudioInputController() override; | 266 virtual ~AudioInputController(); |
| 296 | 267 |
| 268 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting() | |
| 269 const { | |
| 270 return task_runner_; | |
| 271 } | |
| 272 | |
| 273 EventHandler* GetHandlerForTesting() const { return handler_; } | |
| 274 | |
| 275 private: | |
| 297 // Methods called on the audio thread (owned by the AudioManager). | 276 // Methods called on the audio thread (owned by the AudioManager). |
| 298 void DoCreate(AudioManager* audio_manager, | 277 void DoCreate(AudioManager* audio_manager, |
| 299 const AudioParameters& params, | 278 const AudioParameters& params, |
| 300 const std::string& device_id); | 279 const std::string& device_id); |
| 301 void DoCreateForLowLatency(AudioManager* audio_manager, | 280 void DoCreateForLowLatency(AudioManager* audio_manager, |
| 302 const AudioParameters& params, | 281 const AudioParameters& params, |
| 303 const std::string& device_id); | 282 const std::string& device_id); |
| 304 void DoCreateForStream(AudioInputStream* stream_to_control); | 283 void DoCreateForStream(AudioInputStream* stream_to_control); |
| 305 void DoRecord(); | 284 void DoRecord(); |
| 306 void DoClose(); | 285 void DoClose(); |
| 307 void DoReportError(); | 286 void DoReportError(); |
| 308 void DoSetVolume(double volume); | 287 void DoSetVolume(double volume); |
| 309 void DoOnData(std::unique_ptr<AudioBus> data); | |
| 310 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); | 288 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); |
| 311 | 289 |
| 312 // Helper method that stops, closes, and NULL:s |*stream_|. | |
| 313 void DoStopCloseAndClearStream(); | |
| 314 | |
| 315 #if defined(AUDIO_POWER_MONITORING) | 290 #if defined(AUDIO_POWER_MONITORING) |
| 316 // Updates the silence state, see enum SilenceState above for state | 291 // Updates the silence state, see enum SilenceState above for state |
| 317 // transitions. | 292 // transitions. |
| 318 void UpdateSilenceState(bool silence); | 293 void UpdateSilenceState(bool silence); |
| 319 | 294 |
| 320 // Logs the silence state as UMA stat. | 295 // Logs the silence state as UMA stat. |
| 321 void LogSilenceState(SilenceState value); | 296 void LogSilenceState(SilenceState value); |
| 322 #endif | 297 #endif |
| 323 | 298 |
| 324 // Logs the result of creating an AudioInputController. | 299 // Logs the result of creating an AudioInputController. |
| 325 // Only logs once, even if it is called several times. | 300 // Only logs once, even if it is called several times. |
| 326 void LogCaptureStartupResult(CaptureStartupResult result); | 301 void LogCaptureStartupResult(CaptureStartupResult result); |
| 327 | 302 |
| 328 // Enable and disable debug recording of audio input. Called on the audio | 303 // Enable and disable debug recording of audio input. Called on the audio |
| 329 // thread. | 304 // thread. |
| 330 void DoEnableDebugRecording(const base::FilePath& file_name); | 305 void DoEnableDebugRecording(const base::FilePath& file_name); |
| 331 void DoDisableDebugRecording(); | 306 void DoDisableDebugRecording(); |
| 332 | 307 |
| 333 // Called on the audio thread. | 308 // Called on the audio thread. |
| 334 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); | 309 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); |
| 335 | 310 |
| 336 // Called by the stream with log messages. | 311 // Called by the stream with log messages. |
| 337 void LogMessage(const std::string& message); | 312 void LogMessage(const std::string& message); |
| 338 | 313 |
| 314 // Called on the hw callback thread. Checks for keyboard input if | |
| 315 // user_input_monitor_ is set otherwise returns false. | |
| 316 bool CheckForKeyboardInput(); | |
| 317 | |
| 318 // Does power monitoring on supported platforms. | |
| 319 // Called on the hw callback thread. | |
| 320 void CheckAudioPower(const AudioBus* source, double volume); | |
| 321 | |
| 339 // Gives access to the task runner of the creating thread. | 322 // Gives access to the task runner of the creating thread. |
| 340 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; | 323 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; |
| 341 | 324 |
| 342 // The task runner of audio-manager thread that this object runs on. | 325 // The task runner of audio-manager thread that this object runs on. |
| 343 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 326 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; |
| 344 | 327 |
| 345 // Contains the AudioInputController::EventHandler which receives state | 328 // Contains the AudioInputController::EventHandler which receives state |
| 346 // notifications from this class. | 329 // notifications from this class. |
| 347 EventHandler* handler_; | 330 EventHandler* const handler_; |
| 348 | 331 |
| 349 // Pointer to the audio input stream object. | 332 // Pointer to the audio input stream object. |
| 333 // Only used on the audio thread. | |
| 350 AudioInputStream* stream_; | 334 AudioInputStream* stream_; |
| 351 | 335 |
| 352 // Flag for whether CaptureStartupResults shall be reported. | |
| 353 // A value of 1 means that stats shall be reported, | |
| 354 // any other value means that stats have already been reported. | |
| 355 base::AtomicRefCount should_report_stats; | |
| 356 | |
| 357 // |state_| is written on the audio thread and is read on the hardware audio | |
| 358 // thread. These operations need to be locked. But lock is not required for | |
| 359 // reading on the audio input controller thread. | |
| 360 State state_; | |
| 361 | |
| 362 base::Lock lock_; | |
| 363 | |
| 364 // SyncWriter is used only in low-latency mode for synchronous writing. | 336 // SyncWriter is used only in low-latency mode for synchronous writing. |
| 365 SyncWriter* sync_writer_; | 337 SyncWriter* const sync_writer_; |
| 366 | 338 |
| 367 static Factory* factory_; | 339 static Factory* factory_; |
| 368 | 340 |
| 369 double max_volume_; | 341 double max_volume_; |
| 370 | 342 |
| 371 UserInputMonitor* user_input_monitor_; | 343 UserInputMonitor* const user_input_monitor_; |
| 372 | 344 |
| 373 const bool agc_is_enabled_; | 345 const bool agc_is_enabled_; |
| 374 | 346 |
| 375 #if defined(AUDIO_POWER_MONITORING) | 347 #if defined(AUDIO_POWER_MONITORING) |
| 376 // Enabled in DoCrete() but not in DoCreateForStream(). | 348 // Enabled in DoCrete() but not in DoCreateForStream(). |
|
o1ka
2017/01/12 12:07:39
This comment is not quite clear (I know it's an ol
tommi (sloooow) - chröme
2017/01/12 14:21:01
Yeah it could be more clear :) I looked at the im
henrika (OOO until Aug 14)
2017/01/12 15:16:14
When we first added the power monitor, the goal we
o1ka
2017/01/12 17:27:15
Thank you both for clarification!
| |
| 377 bool power_measurement_is_enabled_; | 349 bool power_measurement_is_enabled_; |
| 378 | 350 |
| 379 // Updated each time a power measurement is performed. | 351 // Updated each time a power measurement is performed. |
| 380 base::TimeTicks last_audio_level_log_time_; | 352 base::TimeTicks last_audio_level_log_time_; |
| 381 | 353 |
| 382 // Whether the silence state should sent as UMA stat. | 354 // Whether the silence state should sent as UMA stat. |
| 383 bool log_silence_state_; | 355 bool log_silence_state_; |
| 384 | 356 |
| 385 // The silence report sent as UMA stat at the end of a session. | 357 // The silence report sent as UMA stat at the end of a session. |
| 386 SilenceState silence_state_; | 358 SilenceState silence_state_; |
| 387 #endif | 359 #endif |
| 388 | 360 |
| 389 size_t prev_key_down_count_; | 361 size_t prev_key_down_count_; |
| 390 | 362 |
| 391 // Time when a low-latency stream is created. | 363 // Time when a low-latency stream is created. |
| 392 base::TimeTicks low_latency_create_time_; | 364 base::TimeTicks low_latency_create_time_; |
| 393 | 365 |
| 394 // Used for audio debug recordings. Accessed on audio thread. | 366 // Used for audio debug recordings. Accessed on audio thread. |
| 395 const std::unique_ptr<AudioInputWriter> debug_writer_; | 367 const std::unique_ptr<AudioInputWriter> debug_writer_; |
| 396 | 368 |
| 369 class AudioCallback; | |
| 370 // Holds a pointer to the callback object that receives audio data from | |
| 371 // the lower audio layer. Valid only while 'recording' (aka capturing). | |
| 372 // The value of this pointer is only set and read on the audio thread. | |
|
o1ka
2017/01/12 12:07:39
It is also accessed on audio callback thread. Does
tommi (sloooow) - chröme
2017/01/12 14:21:01
Thanks for pointing out that documentation. It's
o1ka
2017/01/12 17:27:15
It's not obvious from platform-specific implementa
tommi (sloooow) - chröme
2017/01/12 18:58:20
I was trying to convey that with "Valid only while
| |
| 373 std::unique_ptr<AudioCallback> audio_callback_; | |
| 374 | |
| 397 private: | 375 private: |
| 398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 376 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 399 }; | 377 }; |
| 400 | 378 |
| 401 } // namespace media | 379 } // namespace media |
| 402 | 380 |
| 403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 381 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |