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 <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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 158 |
| 159 protected: | 159 protected: |
| 160 virtual ~Factory() {} | 160 virtual ~Factory() {} |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Factory method for creating an AudioInputController. | 163 // Factory method for creating an AudioInputController. |
| 164 // The audio device will be created on the audio thread, and when that is | 164 // The audio device will be created on the audio thread, and when that is |
| 165 // done, the event handler will receive an OnCreated() call from that same | 165 // done, the event handler will receive an OnCreated() call from that same |
| 166 // thread. |device_id| is the unique ID of the audio device to be opened. | 166 // thread. |device_id| is the unique ID of the audio device to be opened. |
| 167 // |user_input_monitor| is used for typing detection and can be NULL. | 167 // |user_input_monitor| is used for typing detection and can be NULL. |
| 168 static scoped_refptr<AudioInputController> Create( | 168 static scoped_refptr<AudioInputController> Create( |
|
no longer working on chromium
2014/08/21 09:11:56
FYI, this method is used by speech.
Henrik Grunell
2014/08/21 11:06:10
Acknowledged.
| |
| 169 AudioManager* audio_manager, | 169 AudioManager* audio_manager, |
| 170 EventHandler* event_handler, | 170 EventHandler* event_handler, |
| 171 const AudioParameters& params, | 171 const AudioParameters& params, |
| 172 const std::string& device_id, | 172 const std::string& device_id, |
| 173 UserInputMonitor* user_input_monitor); | 173 UserInputMonitor* user_input_monitor); |
| 174 | 174 |
| 175 // Sets the factory used by the static method Create(). AudioInputController | 175 // Sets the factory used by the static method Create(). AudioInputController |
| 176 // does not take ownership of |factory|. A value of NULL results in an | 176 // does not take ownership of |factory|. A value of NULL results in an |
| 177 // AudioInputController being created directly. | 177 // AudioInputController being created directly. |
| 178 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } | 178 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } |
| 179 AudioInputStream* stream_for_testing() { return stream_; } | 179 AudioInputStream* stream_for_testing() { return stream_; } |
| 180 | 180 |
| 181 // Factory method for creating an AudioInputController for low-latency mode. | 181 // Factory method for creating an AudioInputController for low-latency mode. |
| 182 // The audio device will be created on the audio thread, and when that is | 182 // The audio device will be created on the audio thread, and when that is |
| 183 // done, the event handler will receive an OnCreated() call from that same | 183 // done, the event handler will receive an OnCreated() call from that same |
| 184 // thread. |user_input_monitor| is used for typing detection and can be NULL. | 184 // thread. |user_input_monitor| is used for typing detection and can be NULL. |
| 185 static scoped_refptr<AudioInputController> CreateLowLatency( | 185 static scoped_refptr<AudioInputController> CreateLowLatency( |
|
no longer working on chromium
2014/08/21 09:11:56
I think you should do the logic control here, and
Henrik Grunell
2014/08/21 11:06:10
Not possible; it's a static function.
| |
| 186 AudioManager* audio_manager, | 186 AudioManager* audio_manager, |
| 187 EventHandler* event_handler, | 187 EventHandler* event_handler, |
| 188 const AudioParameters& params, | 188 const AudioParameters& params, |
| 189 const std::string& device_id, | 189 const std::string& device_id, |
| 190 // External synchronous writer for audio controller. | 190 // External synchronous writer for audio controller. |
| 191 SyncWriter* sync_writer, | 191 SyncWriter* sync_writer, |
| 192 UserInputMonitor* user_input_monitor); | 192 UserInputMonitor* user_input_monitor); |
| 193 | 193 |
| 194 // Factory method for creating an AudioInputController for low-latency mode, | 194 // Factory method for creating an AudioInputController for low-latency mode, |
|
no longer working on chromium
2014/08/21 09:11:56
:( confusing comment. It is definitely not the sco
Henrik Grunell
2014/08/21 11:06:10
Changed. I hope it's clearer.
| |
| 195 // taking ownership of |stream|. The stream will be opened on the audio | 195 // taking ownership of |stream|. The stream will be opened on the audio |
| 196 // thread, and when that is done, the event handler will receive an | 196 // thread, and when that is done, the event handler will receive an |
| 197 // OnCreated() call from that same thread. |user_input_monitor| is used for | 197 // OnCreated() call from that same thread. |user_input_monitor| is used for |
| 198 // typing detection and can be NULL. | 198 // typing detection and can be NULL. |
| 199 static scoped_refptr<AudioInputController> CreateForStream( | 199 static scoped_refptr<AudioInputController> CreateForStream( |
|
no longer working on chromium
2014/08/21 09:11:56
FYI, this create method is used by cast.
Henrik Grunell
2014/08/21 11:06:10
Acknowledged.
| |
| 200 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 200 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 201 EventHandler* event_handler, | 201 EventHandler* event_handler, |
| 202 AudioInputStream* stream, | 202 AudioInputStream* stream, |
| 203 // External synchronous writer for audio controller. | 203 // External synchronous writer for audio controller. |
| 204 SyncWriter* sync_writer, | 204 SyncWriter* sync_writer, |
| 205 UserInputMonitor* user_input_monitor); | 205 UserInputMonitor* user_input_monitor); |
| 206 | 206 |
| 207 // Starts recording using the created audio input stream. | 207 // Starts recording using the created audio input stream. |
| 208 // This method is called on the creator thread. | 208 // This method is called on the creator thread. |
| 209 virtual void Record(); | 209 virtual void Record(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 CREATED, | 244 CREATED, |
| 245 RECORDING, | 245 RECORDING, |
| 246 CLOSED | 246 CLOSED |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 #if defined(AUDIO_POWER_MONITORING) | 249 #if defined(AUDIO_POWER_MONITORING) |
| 250 // Used to log a silence report (see OnData). | 250 // Used to log a silence report (see OnData). |
| 251 // Elements in this enum should not be deleted or rearranged; the only | 251 // Elements in this enum should not be deleted or rearranged; the only |
| 252 // permitted operation is to add new elements before SILENCE_STATE_MAX and | 252 // permitted operation is to add new elements before SILENCE_STATE_MAX and |
| 253 // update SILENCE_STATE_MAX. | 253 // update SILENCE_STATE_MAX. |
| 254 // Possible silence state transitions: | |
| 255 // SILENCE_STATE_AUDIO_AND_SILENCE | |
| 256 // ^ ^ | |
| 257 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE | |
| 258 // ^ ^ | |
| 259 // SILENCE_STATE_NO_MEASUREMENT | |
| 254 enum SilenceState { | 260 enum SilenceState { |
| 255 SILENCE_STATE_NO_MEASUREMENT = 0, | 261 SILENCE_STATE_NO_MEASUREMENT = 0, |
| 256 SILENCE_STATE_ONLY_AUDIO = 1, | 262 SILENCE_STATE_ONLY_AUDIO = 1, |
| 257 SILENCE_STATE_ONLY_SILENCE = 2, | 263 SILENCE_STATE_ONLY_SILENCE = 2, |
| 258 SILENCE_STATE_AUDIO_AND_SILENCE = 3, | 264 SILENCE_STATE_AUDIO_AND_SILENCE = 3, |
| 259 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE | 265 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE |
| 260 }; | 266 }; |
| 261 #endif | 267 #endif |
| 262 | 268 |
| 263 AudioInputController(EventHandler* handler, | 269 AudioInputController(EventHandler* handler, |
| 264 SyncWriter* sync_writer, | 270 SyncWriter* sync_writer, |
| 265 UserInputMonitor* user_input_monitor); | 271 UserInputMonitor* user_input_monitor); |
| 266 virtual ~AudioInputController(); | 272 virtual ~AudioInputController(); |
| 267 | 273 |
| 268 // Methods called on the audio thread (owned by the AudioManager). | 274 // Methods called on the audio thread (owned by the AudioManager). |
| 269 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, | 275 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, |
| 270 const std::string& device_id); | 276 const std::string& device_id); |
| 277 void DoCreateForLowLatency(AudioManager* audio_manager, | |
|
no longer working on chromium
2014/08/21 09:11:56
Please see comments above, I don't think you need
Henrik Grunell
2014/08/21 11:06:10
See comment above.
| |
| 278 const AudioParameters& params, | |
| 279 const std::string& device_id); | |
| 271 void DoCreateForStream(AudioInputStream* stream_to_control); | 280 void DoCreateForStream(AudioInputStream* stream_to_control); |
| 272 void DoRecord(); | 281 void DoRecord(); |
| 273 void DoClose(); | 282 void DoClose(); |
| 274 void DoReportError(); | 283 void DoReportError(); |
| 275 void DoSetVolume(double volume); | 284 void DoSetVolume(double volume); |
| 276 void DoSetAutomaticGainControl(bool enabled); | 285 void DoSetAutomaticGainControl(bool enabled); |
| 277 void DoOnData(scoped_ptr<AudioBus> data); | 286 void DoOnData(scoped_ptr<AudioBus> data); |
| 278 void DoLogAudioLevel(float level_dbfs); | 287 void DoLogAudioLevel(float level_dbfs); |
| 279 | 288 |
| 280 // 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, |
| 281 // and log the result to UMA. | 290 // and log the result to UMA. |
| 282 void FirstCheckForNoData(); | 291 void FirstCheckForNoData(); |
| 283 | 292 |
| 284 // Method which ensures that OnError() is triggered when data recording | 293 // Method which ensures that OnError() is triggered when data recording |
| 285 // times out. Called on the audio thread. | 294 // times out. Called on the audio thread. |
| 286 void DoCheckForNoData(); | 295 void DoCheckForNoData(); |
| 287 | 296 |
| 288 // Helper method that stops, closes, and NULL:s |*stream_|. | 297 // Helper method that stops, closes, and NULL:s |*stream_|. |
| 289 void DoStopCloseAndClearStream(); | 298 void DoStopCloseAndClearStream(); |
| 290 | 299 |
| 291 void SetDataIsActive(bool enabled); | 300 void SetDataIsActive(bool enabled); |
| 292 bool GetDataIsActive(); | 301 bool GetDataIsActive(); |
| 293 | 302 |
| 294 #if defined(AUDIO_POWER_MONITORING) | 303 #if defined(AUDIO_POWER_MONITORING) |
| 304 // Updates the silence state, see enum SilenceState above for state | |
| 305 // transitions. | |
| 306 void UpdateSilenceState(bool silence); | |
| 307 | |
| 308 // Logs the silence state as UMA stat. | |
| 295 void LogSilenceState(SilenceState value); | 309 void LogSilenceState(SilenceState value); |
| 296 #endif | 310 #endif |
| 297 | 311 |
| 298 // Gives access to the task runner of the creating thread. | 312 // Gives access to the task runner of the creating thread. |
| 299 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; | 313 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; |
| 300 | 314 |
| 301 // 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. |
| 302 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 316 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 303 | 317 |
| 304 // Contains the AudioInputController::EventHandler which receives state | 318 // Contains the AudioInputController::EventHandler which receives state |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 UserInputMonitor* user_input_monitor_; | 352 UserInputMonitor* user_input_monitor_; |
| 339 | 353 |
| 340 #if defined(AUDIO_POWER_MONITORING) | 354 #if defined(AUDIO_POWER_MONITORING) |
| 341 // Scans audio samples from OnData() as input to compute audio levels. | 355 // Scans audio samples from OnData() as input to compute audio levels. |
| 342 scoped_ptr<AudioPowerMonitor> audio_level_; | 356 scoped_ptr<AudioPowerMonitor> audio_level_; |
| 343 | 357 |
| 344 // We need these to be able to feed data to the AudioPowerMonitor. | 358 // We need these to be able to feed data to the AudioPowerMonitor. |
| 345 media::AudioParameters audio_params_; | 359 media::AudioParameters audio_params_; |
| 346 base::TimeTicks last_audio_level_log_time_; | 360 base::TimeTicks last_audio_level_log_time_; |
| 347 | 361 |
| 362 // Whether the silence state should sent as UMA stat. | |
| 363 bool log_silence_state_; | |
| 364 | |
| 348 // The silence report sent as UMA stat at the end of a session. | 365 // The silence report sent as UMA stat at the end of a session. |
| 349 SilenceState silence_state_; | 366 SilenceState silence_state_; |
| 350 #endif | 367 #endif |
| 351 | 368 |
| 352 size_t prev_key_down_count_; | 369 size_t prev_key_down_count_; |
| 353 | 370 |
| 354 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 371 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 355 }; | 372 }; |
| 356 | 373 |
| 357 } // namespace media | 374 } // namespace media |
| 358 | 375 |
| 359 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 376 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |