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/files/file.h" | 14 #include "base/files/file.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "media/audio/audio_file_writer.h" | |
| 16 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
| 17 #include "media/audio/audio_manager_base.h" | 18 #include "media/audio/audio_manager_base.h" |
| 18 #include "media/base/audio_bus.h" | 19 #include "media/base/audio_bus.h" |
| 19 #include "media/base/audio_parameters.h" | 20 #include "media/base/audio_parameters.h" |
| 20 | 21 |
| 21 // An AudioInputController controls an AudioInputStream and records data | 22 // An AudioInputController controls an AudioInputStream and records data |
| 22 // from this input stream. The two main methods are Record() and Close() and | 23 // from this input stream. The two main methods are Record() and Close() and |
| 23 // they are both executed on the audio thread which is injected by the two | 24 // they are both executed on the audio thread which is injected by the two |
| 24 // alternative factory methods, Create() or CreateLowLatency(). | 25 // alternative factory methods, Create() or CreateForStream(). |
| 25 // | 26 // |
| 26 // All public methods of AudioInputController are non-blocking. | 27 // All public methods of AudioInputController are non-blocking. |
| 27 // | 28 // |
| 28 // Here is a state diagram for the AudioInputController: | 29 // Here is a state diagram for the AudioInputController: |
| 29 // | 30 // |
| 30 // .--> [ Closed / Error ] <--. | 31 // .--> [ Closed / Error ] <--. |
| 31 // | | | 32 // | | |
| 32 // | | | 33 // | | |
| 33 // [ Created ] ----------> [ Recording ] | 34 // [ Created ] ----------> [ Recording ] |
| 34 // ^ | 35 // ^ |
| 35 // | | 36 // | |
| 36 // *[ Empty ] | 37 // *[ Empty ] |
| 37 // | 38 // |
| 38 // * Initial state | 39 // * Initial state |
| 39 // | 40 // |
| 40 // State sequences (assuming low-latency): | 41 // State sequences: |
| 41 // | 42 // |
| 42 // [Creating Thread] [Audio Thread] | 43 // [Creating Thread] [Audio Thread] |
| 43 // | 44 // |
| 44 // User AudioInputController EventHandler | 45 // User AudioInputController EventHandler |
| 45 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 46 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 46 // CrateLowLatency() ==> DoCreate() | 47 // Crate() ==> DoCreate() |
|
tommi (sloooow) - chröme
2017/02/01 21:07:25
nit: Create
| |
| 47 // AudioManager::MakeAudioInputStream() | 48 // AudioManager::MakeAudioInputStream() |
| 48 // AudioInputStream::Open() | 49 // AudioInputStream::Open() |
| 49 // .- - - - - - - - - - - - -> OnError() | 50 // .- - - - - - - - - - - - -> OnError() |
| 50 // .-------------------------> OnCreated() | 51 // .-------------------------> OnCreated() |
| 51 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 52 // Record() ==> DoRecord() | 53 // Record() ==> DoRecord() |
| 53 // AudioInputStream::Start() | 54 // AudioInputStream::Start() |
| 54 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 55 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 55 // Close() ==> DoClose() | 56 // Close() ==> DoClose() |
| 56 // AudioInputStream::Stop() | 57 // AudioInputStream::Stop() |
| 57 // AudioInputStream::Close() | 58 // AudioInputStream::Close() |
| 58 // SyncWriter::Close() | 59 // SyncWriter::Close() |
| 59 // Closure::Run() <-----------------. | 60 // Closure::Run() <-----------------. |
| 60 // (closure-task) | 61 // (closure-task) |
| 61 // | 62 // |
| 62 // The audio thread itself is owned by the AudioManager that the | 63 // The audio thread itself is owned by the AudioManager that the |
| 63 // AudioInputController holds a reference to. When performing tasks on the | 64 // AudioInputController holds a reference to. When performing tasks on the |
| 64 // audio thread, the controller must not add or release references to the | 65 // audio thread, the controller must not add or release references to the |
| 65 // AudioManager or itself (since it in turn holds a reference to the manager). | 66 // AudioManager or itself (since it in turn holds a reference to the manager). |
| 66 // | 67 // |
| 67 namespace media { | 68 namespace media { |
| 68 | 69 |
| 69 // Only do power monitoring for non-mobile platforms to save resources. | 70 // Only do power monitoring for non-mobile platforms to save resources. |
| 70 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 71 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 71 #define AUDIO_POWER_MONITORING | 72 #define AUDIO_POWER_MONITORING |
| 72 #endif | 73 #endif |
| 73 | 74 |
| 74 class AudioFileWriter; | |
| 75 class UserInputMonitor; | 75 class UserInputMonitor; |
| 76 | 76 |
| 77 class MEDIA_EXPORT AudioInputController | 77 class MEDIA_EXPORT AudioInputController |
| 78 : public base::RefCountedThreadSafe<AudioInputController> { | 78 : public base::RefCountedThreadSafe<AudioInputController> { |
| 79 public: | 79 public: |
| 80 // Error codes to make native logging more clear. These error codes are added | 80 // Error codes to make native logging more clear. These error codes are added |
| 81 // to generic error strings to provide a higher degree of details. | 81 // to generic error strings to provide a higher degree of details. |
| 82 // Changing these values can lead to problems when matching native debug | 82 // Changing these values can lead to problems when matching native debug |
| 83 // logs with the actual cause of error. | 83 // logs with the actual cause of error. |
| 84 enum ErrorCode { | 84 enum ErrorCode { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 // Write certain amount of data from |data|. | 119 // Write certain amount of data from |data|. |
| 120 virtual void Write(const AudioBus* data, | 120 virtual void Write(const AudioBus* data, |
| 121 double volume, | 121 double volume, |
| 122 bool key_pressed, | 122 bool key_pressed, |
| 123 uint32_t hardware_delay_bytes) = 0; | 123 uint32_t hardware_delay_bytes) = 0; |
| 124 | 124 |
| 125 // Close this synchronous writer. | 125 // Close this synchronous writer. |
| 126 virtual void Close() = 0; | 126 virtual void Close() = 0; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 // enum used for determining what UMA stats to report. | |
| 130 enum Type { | |
|
tommi (sloooow) - chröme
2017/02/01 21:07:25
can we call this StreamType or InputStreamType? T
| |
| 131 VIRTUAL = 0, | |
| 132 HIGH_LATENCY = 1, | |
| 133 LOW_LATENCY = 2, | |
| 134 FAKE = 3, | |
| 135 }; | |
| 136 | |
| 129 // AudioInputController::Create() can use the currently registered Factory | 137 // AudioInputController::Create() can use the currently registered Factory |
| 130 // to create the AudioInputController. Factory is intended for testing only. | 138 // to create the AudioInputController. Factory is intended for testing only. |
| 131 // |user_input_monitor| is used for typing detection and can be NULL. | 139 // |user_input_monitor| is used for typing detection and can be NULL. |
| 132 class Factory { | 140 class Factory { |
| 133 public: | 141 public: |
| 134 virtual AudioInputController* Create( | 142 virtual AudioInputController* Create( |
| 135 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 143 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 136 SyncWriter* sync_writer, | 144 SyncWriter* sync_writer, |
| 137 AudioManager* audio_manager, | 145 AudioManager* audio_manager, |
| 138 EventHandler* event_handler, | 146 EventHandler* event_handler, |
| 139 AudioParameters params, | 147 AudioParameters params, |
| 140 UserInputMonitor* user_input_monitor) = 0; | 148 UserInputMonitor* user_input_monitor, |
| 149 Type type) = 0; | |
| 141 | 150 |
| 142 protected: | 151 protected: |
| 143 virtual ~Factory() {} | 152 virtual ~Factory() {} |
| 144 }; | 153 }; |
| 145 | 154 |
| 146 // Factory method for creating an AudioInputController. | |
| 147 // The audio device will be created on the audio thread, and when that is | |
| 148 // done, the event handler will receive an OnCreated() call from that same | |
| 149 // thread. |device_id| is the unique ID of the audio device to be opened. | |
| 150 // |user_input_monitor| is used for typing detection and can be NULL. | |
| 151 static scoped_refptr<AudioInputController> Create( | |
| 152 AudioManager* audio_manager, | |
| 153 EventHandler* event_handler, | |
| 154 SyncWriter* sync_writer, | |
| 155 const AudioParameters& params, | |
| 156 const std::string& device_id, | |
| 157 UserInputMonitor* user_input_monitor); | |
| 158 | |
| 159 // Sets the factory used by the static method Create(). AudioInputController | 155 // Sets the factory used by the static method Create(). AudioInputController |
| 160 // does not take ownership of |factory|. A value of NULL results in an | 156 // does not take ownership of |factory|. A value of NULL results in an |
| 161 // AudioInputController being created directly. | 157 // AudioInputController being created directly. |
| 162 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } | 158 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } |
| 163 AudioInputStream* stream_for_testing() { return stream_; } | 159 AudioInputStream* stream_for_testing() { return stream_; } |
| 164 | 160 |
| 165 // Factory method for creating an AudioInputController for low-latency mode. | |
| 166 // The audio device will be created on the audio thread, and when that is | 161 // The audio device will be created on the audio thread, and when that is |
| 167 // done, the event handler will receive an OnCreated() call from that same | 162 // done, the event handler will receive an OnCreated() call from that same |
| 168 // thread. |user_input_monitor| is used for typing detection and can be NULL. | 163 // thread. |user_input_monitor| is used for typing detection and can be NULL, |
| 169 static scoped_refptr<AudioInputController> CreateLowLatency( | 164 // and |debug_writer| can be null if debug recording is not required. |
| 165 static scoped_refptr<AudioInputController> Create( | |
| 170 AudioManager* audio_manager, | 166 AudioManager* audio_manager, |
| 171 EventHandler* event_handler, | 167 EventHandler* event_handler, |
| 168 SyncWriter* sync_writer, | |
| 169 UserInputMonitor* user_input_monitor, | |
| 170 std::unique_ptr<AudioFileWriter> debug_writer, | |
| 172 const AudioParameters& params, | 171 const AudioParameters& params, |
| 173 const std::string& device_id, | 172 const std::string& device_id, |
| 174 // External synchronous writer for audio controller. | 173 // External synchronous writer for audio controller. |
| 175 SyncWriter* sync_writer, | 174 bool agc_is_enabled); |
| 176 std::unique_ptr<AudioFileWriter> debug_writer, | |
| 177 UserInputMonitor* user_input_monitor, | |
| 178 const bool agc_is_enabled); | |
| 179 | 175 |
| 180 // Factory method for creating an AudioInputController with an existing | 176 // Factory method for creating an AudioInputController with an existing |
| 181 // |stream| for low-latency mode, taking ownership of |stream|. The stream | 177 // |stream|. The stream will be opened on the audio thread, and when that is |
| 182 // will be opened on the audio thread, and when that is done, the event | 178 // done, the event handler will receive an OnCreated() call from that same |
| 183 // handler will receive an OnCreated() call from that same thread. | 179 // thread. |user_input_monitor| is used for typing detection and can be NULL. |
| 184 // |user_input_monitor| is used for typing detection and can be NULL. | |
| 185 static scoped_refptr<AudioInputController> CreateForStream( | 180 static scoped_refptr<AudioInputController> CreateForStream( |
| 186 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 181 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 187 EventHandler* event_handler, | 182 EventHandler* event_handler, |
| 188 AudioInputStream* stream, | 183 AudioInputStream* stream, |
| 189 // External synchronous writer for audio controller. | 184 // External synchronous writer for audio controller. |
| 190 SyncWriter* sync_writer, | 185 SyncWriter* sync_writer, |
| 191 std::unique_ptr<AudioFileWriter> debug_writer, | 186 std::unique_ptr<AudioFileWriter> debug_writer, |
| 192 UserInputMonitor* user_input_monitor); | 187 UserInputMonitor* user_input_monitor); |
| 193 | 188 |
| 194 // Starts recording using the created audio input stream. | 189 // Starts recording using the created audio input stream. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 223 // options. The enum order is kept to ensure backwards compatibility. | 218 // options. The enum order is kept to ensure backwards compatibility. |
| 224 // Elements in this enum should not be deleted or rearranged; the only | 219 // Elements in this enum should not be deleted or rearranged; the only |
| 225 // permitted operation is to add new elements before | 220 // permitted operation is to add new elements before |
| 226 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. | 221 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. |
| 227 // | 222 // |
| 228 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA, | 223 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA, |
| 229 // and there are also other histograms such as | 224 // and there are also other histograms such as |
| 230 // Media.Audio.InputStartupSuccessMac to cover issues similar | 225 // Media.Audio.InputStartupSuccessMac to cover issues similar |
| 231 // to the ones the NO_DATA_CALLBACK was intended for. | 226 // to the ones the NO_DATA_CALLBACK was intended for. |
| 232 enum CaptureStartupResult { | 227 enum CaptureStartupResult { |
| 233 CAPTURE_STARTUP_NO_DATA_CALLBACK = 0, // no longer used. | 228 CAPTURE_STARTUP_OK = 0, |
|
tommi (sloooow) - chröme
2017/02/01 21:07:26
can we avoid the numeric change? Even though the
Max Morin
2017/02/02 09:54:56
The old stats are left intact (since the histogram
tommi (sloooow) - chröme
2017/02/02 14:14:21
ah, sorry, I thought I had deleted this comment. I
| |
| 234 CAPTURE_STARTUP_OK = 1, | 229 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 1, |
| 235 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 2, | 230 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 2, |
| 236 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 3, | 231 CAPTURE_STARTUP_NEVER_GOT_DATA = 3, |
| 237 CAPTURE_STARTUP_NEVER_GOT_DATA = 4, | 232 CAPTURE_STARTUP_STOPPED_EARLY = 4, |
| 238 CAPTURE_STARTUP_STOPPED_EARLY = 5, | 233 CAPTURE_STARTUP_RESULT_MAX = CAPTURE_STARTUP_STOPPED_EARLY, |
| 239 CAPTURE_STARTUP_CREATE_LOW_LATENCY_STREAM_FAILED = 6, | |
| 240 CAPTURE_STARTUP_OPEN_LOW_LATENCY_STREAM_FAILED = 7, | |
| 241 CAPTURE_STARTUP_RESULT_MAX = | |
| 242 CAPTURE_STARTUP_CREATE_LOW_LATENCY_STREAM_FAILED | |
| 243 }; | 234 }; |
| 244 | 235 |
| 245 #if defined(AUDIO_POWER_MONITORING) | 236 #if defined(AUDIO_POWER_MONITORING) |
| 246 // Used to log a silence report (see OnData). | 237 // Used to log a silence report (see OnData). |
| 247 // Elements in this enum should not be deleted or rearranged; the only | 238 // Elements in this enum should not be deleted or rearranged; the only |
| 248 // permitted operation is to add new elements before SILENCE_STATE_MAX and | 239 // permitted operation is to add new elements before SILENCE_STATE_MAX and |
| 249 // update SILENCE_STATE_MAX. | 240 // update SILENCE_STATE_MAX. |
| 250 // Possible silence state transitions: | 241 // Possible silence state transitions: |
| 251 // SILENCE_STATE_AUDIO_AND_SILENCE | 242 // SILENCE_STATE_AUDIO_AND_SILENCE |
| 252 // ^ ^ | 243 // ^ ^ |
| 253 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE | 244 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE |
| 254 // ^ ^ | 245 // ^ ^ |
| 255 // SILENCE_STATE_NO_MEASUREMENT | 246 // SILENCE_STATE_NO_MEASUREMENT |
| 256 enum SilenceState { | 247 enum SilenceState { |
| 257 SILENCE_STATE_NO_MEASUREMENT = 0, | 248 SILENCE_STATE_NO_MEASUREMENT = 0, |
| 258 SILENCE_STATE_ONLY_AUDIO = 1, | 249 SILENCE_STATE_ONLY_AUDIO = 1, |
| 259 SILENCE_STATE_ONLY_SILENCE = 2, | 250 SILENCE_STATE_ONLY_SILENCE = 2, |
| 260 SILENCE_STATE_AUDIO_AND_SILENCE = 3, | 251 SILENCE_STATE_AUDIO_AND_SILENCE = 3, |
| 261 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE | 252 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE |
| 262 }; | 253 }; |
| 263 #endif | 254 #endif |
| 264 | 255 |
| 265 AudioInputController(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 256 AudioInputController(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 266 EventHandler* handler, | 257 EventHandler* handler, |
| 267 SyncWriter* sync_writer, | 258 SyncWriter* sync_writer, |
| 268 std::unique_ptr<AudioFileWriter> debug_writer, | 259 std::unique_ptr<AudioFileWriter> debug_writer, |
| 269 UserInputMonitor* user_input_monitor, | 260 UserInputMonitor* user_input_monitor, |
| 270 const bool agc_is_enabled); | 261 Type type); |
| 271 virtual ~AudioInputController(); | 262 virtual ~AudioInputController(); |
| 272 | 263 |
| 273 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting() | 264 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting() |
| 274 const { | 265 const { |
| 275 return task_runner_; | 266 return task_runner_; |
| 276 } | 267 } |
| 277 | 268 |
| 278 EventHandler* GetHandlerForTesting() const { return handler_; } | 269 EventHandler* GetHandlerForTesting() const { return handler_; } |
| 279 | 270 |
| 280 private: | 271 private: |
| 281 // Methods called on the audio thread (owned by the AudioManager). | 272 // Methods called on the audio thread (owned by the AudioManager). |
| 282 void DoCreate(AudioManager* audio_manager, | 273 void DoCreate(AudioManager* audio_manager, |
| 283 const AudioParameters& params, | 274 const AudioParameters& params, |
| 284 const std::string& device_id); | 275 const std::string& device_id, |
| 285 void DoCreateForLowLatency(AudioManager* audio_manager, | 276 bool enable_agc); |
| 286 const AudioParameters& params, | 277 void DoCreateForStream(AudioInputStream* stream_to_control, bool enable_agc); |
| 287 const std::string& device_id); | |
| 288 void DoCreateForStream(AudioInputStream* stream_to_control, bool low_latency); | |
| 289 void DoRecord(); | 278 void DoRecord(); |
| 290 void DoClose(); | 279 void DoClose(); |
| 291 void DoReportError(); | 280 void DoReportError(); |
| 292 void DoSetVolume(double volume); | 281 void DoSetVolume(double volume); |
| 293 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); | 282 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); |
| 294 | 283 |
| 295 #if defined(AUDIO_POWER_MONITORING) | 284 #if defined(AUDIO_POWER_MONITORING) |
| 296 // Updates the silence state, see enum SilenceState above for state | 285 // Updates the silence state, see enum SilenceState above for state |
| 297 // transitions. | 286 // transitions. |
| 298 void UpdateSilenceState(bool silence); | 287 void UpdateSilenceState(bool silence); |
| 299 | 288 |
| 300 // Logs the silence state as UMA stat. | 289 // Logs the silence state as UMA stat. |
| 301 void LogSilenceState(SilenceState value); | 290 void LogSilenceState(SilenceState value); |
| 302 #endif | 291 #endif |
| 303 | 292 |
| 304 // Logs the result of creating an AudioInputController. | 293 // Logs the result of creating an AudioInputController. |
| 305 // Only logs once, even if it is called several times. | |
| 306 void LogCaptureStartupResult(CaptureStartupResult result); | 294 void LogCaptureStartupResult(CaptureStartupResult result); |
| 307 | 295 |
| 296 // Logs whether an error was encountered suring the stream. | |
| 297 void LogCallbackError(); | |
| 298 | |
| 308 // Enable and disable debug recording of audio input. Called on the audio | 299 // Enable and disable debug recording of audio input. Called on the audio |
| 309 // thread. | 300 // thread. |
| 310 void DoEnableDebugRecording(const base::FilePath& file_name); | 301 void DoEnableDebugRecording(const base::FilePath& file_name); |
| 311 void DoDisableDebugRecording(); | 302 void DoDisableDebugRecording(); |
| 312 | 303 |
| 313 // Called on the audio thread. | 304 // Called on the audio thread. |
| 314 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); | 305 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); |
| 315 | 306 |
| 316 // Called by the stream with log messages. | 307 // Called by the stream with log messages. |
| 317 void LogMessage(const std::string& message); | 308 void LogMessage(const std::string& message); |
| 318 | 309 |
| 319 // Called on the hw callback thread. Checks for keyboard input if | 310 // Called on the hw callback thread. Checks for keyboard input if |
| 320 // user_input_monitor_ is set otherwise returns false. | 311 // user_input_monitor_ is set otherwise returns false. |
| 321 bool CheckForKeyboardInput(); | 312 bool CheckForKeyboardInput(); |
| 322 | 313 |
| 323 // Does power monitoring on supported platforms. | 314 // Does power monitoring on supported platforms. |
| 324 // Called on the hw callback thread. | 315 // Called on the hw callback thread. |
| 325 // Returns true iff average power and mic volume was returned and should | 316 // Returns true iff average power and mic volume was returned and should |
| 326 // be posted to DoLogAudioLevels on the audio thread. | 317 // be posted to DoLogAudioLevels on the audio thread. |
| 327 // Returns false if either power measurements are disabled or aren't needed | 318 // Returns false if either power measurements are disabled or aren't needed |
| 328 // right now (they're done periodically). | 319 // right now (they're done periodically). |
| 329 bool CheckAudioPower(const AudioBus* source, | 320 bool CheckAudioPower(const AudioBus* source, |
| 330 double volume, | 321 double volume, |
| 331 float* average_power_dbfs, | 322 float* average_power_dbfs, |
| 332 int* mic_volume_percent); | 323 int* mic_volume_percent); |
| 333 | 324 |
| 325 static Type ParamsToType(const AudioParameters& params); | |
| 326 | |
| 334 // Gives access to the task runner of the creating thread. | 327 // Gives access to the task runner of the creating thread. |
| 335 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; | 328 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; |
| 336 | 329 |
| 337 // The task runner of audio-manager thread that this object runs on. | 330 // The task runner of audio-manager thread that this object runs on. |
| 338 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; | 331 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; |
| 339 | 332 |
| 340 // Contains the AudioInputController::EventHandler which receives state | 333 // Contains the AudioInputController::EventHandler which receives state |
| 341 // notifications from this class. | 334 // notifications from this class. |
| 342 EventHandler* const handler_; | 335 EventHandler* const handler_; |
| 343 | 336 |
| 344 // Pointer to the audio input stream object. | 337 // Pointer to the audio input stream object. |
| 345 // Only used on the audio thread. | 338 // Only used on the audio thread. |
| 346 AudioInputStream* stream_; | 339 AudioInputStream* stream_ = nullptr; |
| 347 | 340 |
| 348 // SyncWriter is used only in low-latency mode for synchronous writing. | 341 // SyncWriter is used only in low-latency mode for synchronous writing. |
| 349 SyncWriter* const sync_writer_; | 342 SyncWriter* const sync_writer_; |
| 350 | 343 |
| 344 Type type_; | |
| 345 | |
| 351 static Factory* factory_; | 346 static Factory* factory_; |
| 352 | 347 |
| 353 double max_volume_; | 348 double max_volume_ = 0.0; |
| 354 | 349 |
| 355 UserInputMonitor* const user_input_monitor_; | 350 UserInputMonitor* const user_input_monitor_; |
| 356 | 351 |
| 357 const bool agc_is_enabled_; | |
| 358 | |
| 359 #if defined(AUDIO_POWER_MONITORING) | 352 #if defined(AUDIO_POWER_MONITORING) |
| 360 // Will be set to true if an AGC is supported and enabled (see DoCreate and | 353 // Will be set to true if an AGC is supported and enabled (see DoCreate and |
| 361 // DoCreateForStream). By default set to false. | 354 // DoCreateForStream). By default set to false. |
| 362 bool power_measurement_is_enabled_; | 355 bool power_measurement_is_enabled_ = false; |
|
tommi (sloooow) - chröme
2017/02/01 21:07:26
initializing variables here does mean that some ar
Max Morin
2017/02/02 09:54:56
Should be fine, I don't see anything about it in a
tommi (sloooow) - chröme
2017/02/02 14:14:21
Acknowledged. Looks neater this way.
| |
| 363 | 356 |
| 364 // Updated each time a power measurement is performed. | 357 // Updated each time a power measurement is performed. |
| 365 base::TimeTicks last_audio_level_log_time_; | 358 base::TimeTicks last_audio_level_log_time_; |
| 366 | 359 |
| 367 // Whether the silence state should sent as UMA stat. | 360 // Whether the silence state should sent as UMA stat. |
| 368 bool log_silence_state_; | 361 bool log_silence_state_ = false; |
| 369 | 362 |
| 370 // The silence report sent as UMA stat at the end of a session. | 363 // The silence report sent as UMA stat at the end of a session. |
| 371 SilenceState silence_state_; | 364 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; |
| 372 #endif | 365 #endif |
| 373 | 366 |
| 374 size_t prev_key_down_count_; | 367 size_t prev_key_down_count_ = 0; |
| 375 | 368 |
| 376 // Time when a low-latency stream is created. | 369 // Time when the stream started recording. |
| 377 base::TimeTicks low_latency_create_time_; | 370 base::TimeTicks stream_create_time_; |
| 378 | 371 |
| 379 // Used for audio debug recordings. Accessed on audio thread. | 372 // Used for audio debug recordings. Accessed on audio thread. |
| 380 const std::unique_ptr<AudioFileWriter> debug_writer_; | 373 const std::unique_ptr<AudioFileWriter> debug_writer_; |
| 381 | 374 |
| 382 class AudioCallback; | 375 class AudioCallback; |
| 383 // Holds a pointer to the callback object that receives audio data from | 376 // Holds a pointer to the callback object that receives audio data from |
| 384 // the lower audio layer. Valid only while 'recording' (between calls to | 377 // the lower audio layer. Valid only while 'recording' (between calls to |
| 385 // stream_->Start() and stream_->Stop()). | 378 // stream_->Start() and stream_->Stop()). |
| 386 // The value of this pointer is only set and read on the audio thread while | 379 // The value of this pointer is only set and read on the audio thread while |
| 387 // the callbacks themselves occur on the hw callback thread. More details | 380 // the callbacks themselves occur on the hw callback thread. More details |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 401 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated | 394 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated |
| 402 // at the end of DoClose. | 395 // at the end of DoClose. |
| 403 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; | 396 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; |
| 404 | 397 |
| 405 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 406 }; | 399 }; |
| 407 | 400 |
| 408 } // namespace media | 401 } // namespace media |
| 409 | 402 |
| 410 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |