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 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 // The audio device will be created on the audio thread, and when that is | 178 // The audio device will be created on the audio thread, and when that is |
| 179 // done, the event handler will receive an OnCreated() call from that same | 179 // done, the event handler will receive an OnCreated() call from that same |
| 180 // thread. |user_input_monitor| is used for typing detection and can be NULL. | 180 // thread. |user_input_monitor| is used for typing detection and can be NULL. |
| 181 static scoped_refptr<AudioInputController> CreateLowLatency( | 181 static scoped_refptr<AudioInputController> CreateLowLatency( |
| 182 AudioManager* audio_manager, | 182 AudioManager* audio_manager, |
| 183 EventHandler* event_handler, | 183 EventHandler* event_handler, |
| 184 const AudioParameters& params, | 184 const AudioParameters& params, |
| 185 const std::string& device_id, | 185 const std::string& device_id, |
| 186 // External synchronous writer for audio controller. | 186 // External synchronous writer for audio controller. |
| 187 SyncWriter* sync_writer, | 187 SyncWriter* sync_writer, |
| 188 std::unique_ptr<AudioInputWriter> debug_writer, | |
|
Henrik Grunell
2016/10/13 07:26:11
It seems unnecessary to always pass a debug writer
| |
| 188 UserInputMonitor* user_input_monitor, | 189 UserInputMonitor* user_input_monitor, |
| 189 const bool agc_is_enabled); | 190 const bool agc_is_enabled); |
| 190 | 191 |
| 191 // Factory method for creating an AudioInputController with an existing | 192 // Factory method for creating an AudioInputController with an existing |
| 192 // |stream| for low-latency mode, taking ownership of |stream|. The stream | 193 // |stream| for low-latency mode, taking ownership of |stream|. The stream |
| 193 // will be opened on the audio thread, and when that is done, the event | 194 // will be opened on the audio thread, and when that is done, the event |
| 194 // handler will receive an OnCreated() call from that same thread. | 195 // handler will receive an OnCreated() call from that same thread. |
| 195 // |user_input_monitor| is used for typing detection and can be NULL. | 196 // |user_input_monitor| is used for typing detection and can be NULL. |
| 196 static scoped_refptr<AudioInputController> CreateForStream( | 197 static scoped_refptr<AudioInputController> CreateForStream( |
| 197 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 198 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 198 EventHandler* event_handler, | 199 EventHandler* event_handler, |
| 199 AudioInputStream* stream, | 200 AudioInputStream* stream, |
| 200 // External synchronous writer for audio controller. | 201 // External synchronous writer for audio controller. |
| 201 SyncWriter* sync_writer, | 202 SyncWriter* sync_writer, |
| 203 std::unique_ptr<AudioInputWriter> debug_writer, | |
| 202 UserInputMonitor* user_input_monitor); | 204 UserInputMonitor* user_input_monitor); |
| 203 | 205 |
| 204 // Starts recording using the created audio input stream. | 206 // Starts recording using the created audio input stream. |
| 205 // This method is called on the creator thread. | 207 // This method is called on the creator thread. |
| 206 virtual void Record(); | 208 virtual void Record(); |
| 207 | 209 |
| 208 // Closes the audio input stream. The state is changed and the resources | 210 // Closes the audio input stream. The state is changed and the resources |
| 209 // are freed on the audio thread. |closed_task| is then executed on the thread | 211 // are freed on the audio thread. |closed_task| is then executed on the thread |
| 210 // that called Close(). | 212 // that called Close(). |
| 211 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| | 213 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 223 // device-specific implementation. | 225 // device-specific implementation. |
| 224 void OnData(AudioInputStream* stream, | 226 void OnData(AudioInputStream* stream, |
| 225 const AudioBus* source, | 227 const AudioBus* source, |
| 226 uint32_t hardware_delay_bytes, | 228 uint32_t hardware_delay_bytes, |
| 227 double volume) override; | 229 double volume) override; |
| 228 void OnError(AudioInputStream* stream) override; | 230 void OnError(AudioInputStream* stream) override; |
| 229 | 231 |
| 230 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } | 232 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } |
| 231 | 233 |
| 232 // Enable debug recording of audio input. | 234 // Enable debug recording of audio input. |
| 233 void EnableDebugRecording(AudioInputWriter* input_writer); | 235 void EnableDebugRecording(const base::FilePath& file_name); |
| 234 | 236 |
| 235 // Disbale debug recording of audio input. Must be called before owner of | 237 // Disable debug recording of audio input. |
| 236 // |input_writer| deletes it. | 238 void DisableDebugRecording(); |
| 237 void DisableDebugRecording(const base::Closure& callback); | |
| 238 | 239 |
| 239 protected: | 240 protected: |
| 240 friend class base::RefCountedThreadSafe<AudioInputController>; | 241 friend class base::RefCountedThreadSafe<AudioInputController>; |
| 241 | 242 |
| 242 // Used to log the result of capture startup. | 243 // Used to log the result of capture startup. |
| 243 // This was previously logged as a boolean with only the no callback and OK | 244 // This was previously logged as a boolean with only the no callback and OK |
| 244 // options. The enum order is kept to ensure backwards compatibility. | 245 // options. The enum order is kept to ensure backwards compatibility. |
| 245 // Elements in this enum should not be deleted or rearranged; the only | 246 // Elements in this enum should not be deleted or rearranged; the only |
| 246 // permitted operation is to add new elements before | 247 // permitted operation is to add new elements before |
| 247 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. | 248 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 SILENCE_STATE_NO_MEASUREMENT = 0, | 282 SILENCE_STATE_NO_MEASUREMENT = 0, |
| 282 SILENCE_STATE_ONLY_AUDIO = 1, | 283 SILENCE_STATE_ONLY_AUDIO = 1, |
| 283 SILENCE_STATE_ONLY_SILENCE = 2, | 284 SILENCE_STATE_ONLY_SILENCE = 2, |
| 284 SILENCE_STATE_AUDIO_AND_SILENCE = 3, | 285 SILENCE_STATE_AUDIO_AND_SILENCE = 3, |
| 285 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE | 286 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE |
| 286 }; | 287 }; |
| 287 #endif | 288 #endif |
| 288 | 289 |
| 289 AudioInputController(EventHandler* handler, | 290 AudioInputController(EventHandler* handler, |
| 290 SyncWriter* sync_writer, | 291 SyncWriter* sync_writer, |
| 292 std::unique_ptr<AudioInputWriter> debug_writer, | |
| 291 UserInputMonitor* user_input_monitor, | 293 UserInputMonitor* user_input_monitor, |
| 292 const bool agc_is_enabled); | 294 const bool agc_is_enabled); |
| 293 ~AudioInputController() override; | 295 ~AudioInputController() override; |
| 294 | 296 |
| 295 // Methods called on the audio thread (owned by the AudioManager). | 297 // Methods called on the audio thread (owned by the AudioManager). |
| 296 void DoCreate(AudioManager* audio_manager, | 298 void DoCreate(AudioManager* audio_manager, |
| 297 const AudioParameters& params, | 299 const AudioParameters& params, |
| 298 const std::string& device_id); | 300 const std::string& device_id); |
| 299 void DoCreateForLowLatency(AudioManager* audio_manager, | 301 void DoCreateForLowLatency(AudioManager* audio_manager, |
| 300 const AudioParameters& params, | 302 const AudioParameters& params, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 318 // Logs the silence state as UMA stat. | 320 // Logs the silence state as UMA stat. |
| 319 void LogSilenceState(SilenceState value); | 321 void LogSilenceState(SilenceState value); |
| 320 #endif | 322 #endif |
| 321 | 323 |
| 322 // Logs the result of creating an AudioInputController. | 324 // Logs the result of creating an AudioInputController. |
| 323 // Only logs once, even if it is called several times. | 325 // Only logs once, even if it is called several times. |
| 324 void LogCaptureStartupResult(CaptureStartupResult result); | 326 void LogCaptureStartupResult(CaptureStartupResult result); |
| 325 | 327 |
| 326 // Enable and disable debug recording of audio input. Called on the audio | 328 // Enable and disable debug recording of audio input. Called on the audio |
| 327 // thread. | 329 // thread. |
| 328 void DoEnableDebugRecording(AudioInputWriter* input_writer); | 330 void DoEnableDebugRecording(const base::FilePath& file_name); |
| 329 void DoDisableDebugRecording(); | 331 void DoDisableDebugRecording(); |
| 330 | 332 |
| 331 // Called on the audio thread. | 333 // Called on the audio thread. |
| 332 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); | 334 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); |
| 333 | 335 |
| 334 // Called by the stream with log messages. | 336 // Called by the stream with log messages. |
| 335 void LogMessage(const std::string& message); | 337 void LogMessage(const std::string& message); |
| 336 | 338 |
| 337 // Gives access to the task runner of the creating thread. | 339 // Gives access to the task runner of the creating thread. |
| 338 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; | 340 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 // The silence report sent as UMA stat at the end of a session. | 385 // The silence report sent as UMA stat at the end of a session. |
| 384 SilenceState silence_state_; | 386 SilenceState silence_state_; |
| 385 #endif | 387 #endif |
| 386 | 388 |
| 387 size_t prev_key_down_count_; | 389 size_t prev_key_down_count_; |
| 388 | 390 |
| 389 // Time when a low-latency stream is created. | 391 // Time when a low-latency stream is created. |
| 390 base::TimeTicks low_latency_create_time_; | 392 base::TimeTicks low_latency_create_time_; |
| 391 | 393 |
| 392 // Used for audio debug recordings. Accessed on audio thread. | 394 // Used for audio debug recordings. Accessed on audio thread. |
| 393 AudioInputWriter* input_writer_; | 395 const std::unique_ptr<AudioInputWriter> debug_writer_; |
| 394 | 396 |
| 395 private: | 397 private: |
| 396 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
| 397 }; | 399 }; |
| 398 | 400 |
| 399 } // namespace media | 401 } // namespace media |
| 400 | 402 |
| 401 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
| OLD | NEW |