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 // Initially, an AudioInputController is considered not muted. If the | |
113 // underlying stream is actually muted, an OnMuted callback will follow | |
114 // shortly after OnCreated. It is also called whenever the muted state of | |
115 // the underlying stream changes. | |
116 virtual void OnMuted(AudioInputController* controller, bool is_muted) = 0; | |
110 | 117 |
111 protected: | 118 protected: |
112 virtual ~EventHandler() {} | 119 virtual ~EventHandler() {} |
113 }; | 120 }; |
114 | 121 |
115 // A synchronous writer interface used by AudioInputController for | 122 // A synchronous writer interface used by AudioInputController for |
116 // synchronous writing. | 123 // synchronous writing. |
117 class MEDIA_EXPORT SyncWriter { | 124 class MEDIA_EXPORT SyncWriter { |
118 public: | 125 public: |
119 virtual ~SyncWriter() {} | 126 virtual ~SyncWriter() {} |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 // Called on the hw callback thread. | 323 // Called on the hw callback thread. |
317 // Returns true iff average power and mic volume was returned and should | 324 // Returns true iff average power and mic volume was returned and should |
318 // be posted to DoLogAudioLevels on the audio thread. | 325 // be posted to DoLogAudioLevels on the audio thread. |
319 // Returns false if either power measurements are disabled or aren't needed | 326 // Returns false if either power measurements are disabled or aren't needed |
320 // right now (they're done periodically). | 327 // right now (they're done periodically). |
321 bool CheckAudioPower(const AudioBus* source, | 328 bool CheckAudioPower(const AudioBus* source, |
322 double volume, | 329 double volume, |
323 float* average_power_dbfs, | 330 float* average_power_dbfs, |
324 int* mic_volume_percent); | 331 int* mic_volume_percent); |
325 | 332 |
333 void CheckMutedState(); | |
334 | |
326 static StreamType ParamsToStreamType(const AudioParameters& params); | 335 static StreamType ParamsToStreamType(const AudioParameters& params); |
327 | 336 |
328 // Gives access to the task runner of the creating thread. | 337 // Gives access to the task runner of the creating thread. |
329 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; | 338 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; |
330 | 339 |
331 // The task runner of audio-manager thread that this object runs on. | 340 // The task runner of audio-manager thread that this object runs on. |
332 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; | 341 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; |
333 | 342 |
334 // Contains the AudioInputController::EventHandler which receives state | 343 // Contains the AudioInputController::EventHandler which receives state |
335 // notifications from this class. | 344 // notifications from this class. |
(...skipping 24 matching lines...) Expand all Loading... | |
360 | 369 |
361 // The silence report sent as UMA stat at the end of a session. | 370 // The silence report sent as UMA stat at the end of a session. |
362 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; | 371 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; |
363 #endif | 372 #endif |
364 | 373 |
365 size_t prev_key_down_count_ = 0; | 374 size_t prev_key_down_count_ = 0; |
366 | 375 |
367 // Time when the stream started recording. | 376 // Time when the stream started recording. |
368 base::TimeTicks stream_create_time_; | 377 base::TimeTicks stream_create_time_; |
369 | 378 |
379 bool is_muted_ = false; | |
380 | |
381 // The timer needs to be destroyed on the correct thread, so we can't leave | |
382 // that to our destructor. | |
383 base::Optional<base::RepeatingTimer> check_muted_state_timer_; | |
DaleCurtis
2017/06/15 18:44:00
Drop Optional in favor of just IsRunning().
ossu-chromium
2017/06/20 12:25:15
I was quite sure I was unable to get the timer to
| |
384 | |
370 #if BUILDFLAG(ENABLE_WEBRTC) | 385 #if BUILDFLAG(ENABLE_WEBRTC) |
371 // Used for audio debug recordings. Accessed on audio thread. | 386 // Used for audio debug recordings. Accessed on audio thread. |
372 AudioDebugRecordingHelper debug_recording_helper_; | 387 AudioDebugRecordingHelper debug_recording_helper_; |
373 #endif | 388 #endif |
374 | 389 |
375 class AudioCallback; | 390 class AudioCallback; |
376 // Holds a pointer to the callback object that receives audio data from | 391 // Holds a pointer to the callback object that receives audio data from |
377 // the lower audio layer. Valid only while 'recording' (between calls to | 392 // the lower audio layer. Valid only while 'recording' (between calls to |
378 // stream_->Start() and stream_->Stop()). | 393 // stream_->Start() and stream_->Stop()). |
379 // The value of this pointer is only set and read on the audio thread while | 394 // 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 | 409 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated |
395 // at the end of DoClose. | 410 // at the end of DoClose. |
396 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; | 411 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; |
397 | 412 |
398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); | 413 DISALLOW_COPY_AND_ASSIGN(AudioInputController); |
399 }; | 414 }; |
400 | 415 |
401 } // namespace media | 416 } // namespace media |
402 | 417 |
403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ | 418 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ |
OLD | NEW |