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 "base/optional.h" | |
16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/timer/timer.h" | |
17 #include "media/audio/audio_debug_file_writer.h" | 19 #include "media/audio/audio_debug_file_writer.h" |
18 #include "media/audio/audio_io.h" | 20 #include "media/audio/audio_io.h" |
19 #include "media/audio/audio_manager_base.h" | 21 #include "media/audio/audio_manager_base.h" |
20 #include "media/base/audio_bus.h" | 22 #include "media/base/audio_bus.h" |
21 #include "media/base/audio_parameters.h" | 23 #include "media/base/audio_parameters.h" |
22 #include "media/base/media_switches.h" | 24 #include "media/base/media_switches.h" |
23 | 25 |
24 // An AudioInputController controls an AudioInputStream and records data | 26 // An AudioInputController controls an AudioInputStream and records data |
25 // from this input stream. The two main methods are Record() and Close() and | 27 // from this input stream. The two main methods are Record() and Close() and |
26 // they are both executed on the audio thread which is injected by the two | 28 // they are both executed on the audio thread which is injected by the two |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 102 |
101 // An event handler that receives events from the AudioInputController. The | 103 // An event handler that receives events from the AudioInputController. The |
102 // following methods are all called on the audio thread. | 104 // following methods are all called on the audio thread. |
103 class MEDIA_EXPORT EventHandler { | 105 class MEDIA_EXPORT EventHandler { |
104 public: | 106 public: |
105 virtual void OnCreated(AudioInputController* controller) = 0; | 107 virtual void OnCreated(AudioInputController* controller) = 0; |
106 virtual void OnError(AudioInputController* controller, | 108 virtual void OnError(AudioInputController* controller, |
107 ErrorCode error_code) = 0; | 109 ErrorCode error_code) = 0; |
108 virtual void OnLog(AudioInputController* controller, | 110 virtual void OnLog(AudioInputController* controller, |
109 const std::string& message) = 0; | 111 const std::string& message) = 0; |
112 virtual void OnMuted(AudioInputController* controller, bool is_muted) = 0; | |
110 | 113 |
111 protected: | 114 protected: |
112 virtual ~EventHandler() {} | 115 virtual ~EventHandler() {} |
113 }; | 116 }; |
114 | 117 |
115 // A synchronous writer interface used by AudioInputController for | 118 // A synchronous writer interface used by AudioInputController for |
116 // synchronous writing. | 119 // synchronous writing. |
117 class MEDIA_EXPORT SyncWriter { | 120 class MEDIA_EXPORT SyncWriter { |
118 public: | 121 public: |
119 virtual ~SyncWriter() {} | 122 virtual ~SyncWriter() {} |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 // Called on the hw callback thread. | 319 // Called on the hw callback thread. |
317 // Returns true iff average power and mic volume was returned and should | 320 // Returns true iff average power and mic volume was returned and should |
318 // be posted to DoLogAudioLevels on the audio thread. | 321 // be posted to DoLogAudioLevels on the audio thread. |
319 // Returns false if either power measurements are disabled or aren't needed | 322 // Returns false if either power measurements are disabled or aren't needed |
320 // right now (they're done periodically). | 323 // right now (they're done periodically). |
321 bool CheckAudioPower(const AudioBus* source, | 324 bool CheckAudioPower(const AudioBus* source, |
322 double volume, | 325 double volume, |
323 float* average_power_dbfs, | 326 float* average_power_dbfs, |
324 int* mic_volume_percent); | 327 int* mic_volume_percent); |
325 | 328 |
329 void CheckMutedState(); | |
330 | |
326 static StreamType ParamsToStreamType(const AudioParameters& params); | 331 static StreamType ParamsToStreamType(const AudioParameters& params); |
327 | 332 |
328 // Gives access to the task runner of the creating thread. | 333 // Gives access to the task runner of the creating thread. |
329 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; | 334 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; |
330 | 335 |
331 // The task runner of audio-manager thread that this object runs on. | 336 // The task runner of audio-manager thread that this object runs on. |
332 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; | 337 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; |
333 | 338 |
334 // Contains the AudioInputController::EventHandler which receives state | 339 // Contains the AudioInputController::EventHandler which receives state |
335 // notifications from this class. | 340 // notifications from this class. |
(...skipping 24 matching lines...) Expand all Loading... | |
360 | 365 |
361 // The silence report sent as UMA stat at the end of a session. | 366 // The silence report sent as UMA stat at the end of a session. |
362 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; | 367 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; |
363 #endif | 368 #endif |
364 | 369 |
365 size_t prev_key_down_count_ = 0; | 370 size_t prev_key_down_count_ = 0; |
366 | 371 |
367 // Time when the stream started recording. | 372 // Time when the stream started recording. |
368 base::TimeTicks stream_create_time_; | 373 base::TimeTicks stream_create_time_; |
369 | 374 |
375 bool is_muted_ = false; | |
376 // The timer needs to be destroyed on the correct thread, so we can't leave | |
o1ka
2017/06/02 16:27:27
nit: empty line before the comment
ossu-chromium
2017/06/07 17:27:06
Will fix!
| |
377 // that to our destructor. | |
378 base::Optional<base::RepeatingTimer> check_muted_state_timer_; | |
379 | |
370 #if BUILDFLAG(ENABLE_WEBRTC) | 380 #if BUILDFLAG(ENABLE_WEBRTC) |
371 // Used for audio debug recordings. Accessed on audio thread. | 381 // Used for audio debug recordings. Accessed on audio thread. |
372 AudioDebugRecordingHelper debug_recording_helper_; | 382 AudioDebugRecordingHelper debug_recording_helper_; |
373 #endif | 383 #endif |
374 | 384 |
375 class AudioCallback; | 385 class AudioCallback; |
376 // Holds a pointer to the callback object that receives audio data from | 386 // Holds a pointer to the callback object that receives audio data from |
377 // the lower audio layer. Valid only while 'recording' (between calls to | 387 // the lower audio layer. Valid only while 'recording' (between calls to |
378 // stream_->Start() and stream_->Stop()). | 388 // stream_->Start() and stream_->Stop()). |
379 // The value of this pointer is only set and read on the audio thread while | 389 // The value of this pointer is only set and read on the audio thread while |
(...skipping 14 matching lines...) Expand all Loading... | |
394 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated | 404 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated |
395 // at the end of DoClose. | 405 // at the end of DoClose. |
396 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; | 406 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; |
397 | 407 |
398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 408 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
399 }; | 409 }; |
400 | 410 |
401 } // namespace media | 411 } // namespace media |
402 | 412 |
403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 413 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
OLD | NEW |