Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: media/audio/audio_input_controller.h

Issue 2919793002: Detect AudioInputStream muting and propagate to MediaStreamAudioSource. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/timer/timer.h"
17 #include "media/audio/audio_debug_file_writer.h" 18 #include "media/audio/audio_debug_file_writer.h"
18 #include "media/audio/audio_io.h" 19 #include "media/audio/audio_io.h"
19 #include "media/audio/audio_manager_base.h" 20 #include "media/audio/audio_manager_base.h"
20 #include "media/base/audio_bus.h" 21 #include "media/base/audio_bus.h"
21 #include "media/base/audio_parameters.h" 22 #include "media/base/audio_parameters.h"
22 #include "media/base/media_switches.h" 23 #include "media/base/media_switches.h"
23 24
24 // An AudioInputController controls an AudioInputStream and records data 25 // An AudioInputController controls an AudioInputStream and records data
25 // from this input stream. The two main methods are Record() and Close() and 26 // 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 27 // 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
100 101
101 // An event handler that receives events from the AudioInputController. The 102 // An event handler that receives events from the AudioInputController. The
102 // following methods are all called on the audio thread. 103 // following methods are all called on the audio thread.
103 class MEDIA_EXPORT EventHandler { 104 class MEDIA_EXPORT EventHandler {
104 public: 105 public:
105 virtual void OnCreated(AudioInputController* controller) = 0; 106 virtual void OnCreated(AudioInputController* controller) = 0;
106 virtual void OnError(AudioInputController* controller, 107 virtual void OnError(AudioInputController* controller,
107 ErrorCode error_code) = 0; 108 ErrorCode error_code) = 0;
108 virtual void OnLog(AudioInputController* controller, 109 virtual void OnLog(AudioInputController* controller,
109 const std::string& message) = 0; 110 const std::string& message) = 0;
111 virtual void OnMuted(AudioInputController* controller, bool is_muted) = 0;
110 112
111 protected: 113 protected:
112 virtual ~EventHandler() {} 114 virtual ~EventHandler() {}
113 }; 115 };
114 116
115 // A synchronous writer interface used by AudioInputController for 117 // A synchronous writer interface used by AudioInputController for
116 // synchronous writing. 118 // synchronous writing.
117 class MEDIA_EXPORT SyncWriter { 119 class MEDIA_EXPORT SyncWriter {
118 public: 120 public:
119 virtual ~SyncWriter() {} 121 virtual ~SyncWriter() {}
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Called on the hw callback thread. 318 // Called on the hw callback thread.
317 // Returns true iff average power and mic volume was returned and should 319 // Returns true iff average power and mic volume was returned and should
318 // be posted to DoLogAudioLevels on the audio thread. 320 // be posted to DoLogAudioLevels on the audio thread.
319 // Returns false if either power measurements are disabled or aren't needed 321 // Returns false if either power measurements are disabled or aren't needed
320 // right now (they're done periodically). 322 // right now (they're done periodically).
321 bool CheckAudioPower(const AudioBus* source, 323 bool CheckAudioPower(const AudioBus* source,
322 double volume, 324 double volume,
323 float* average_power_dbfs, 325 float* average_power_dbfs,
324 int* mic_volume_percent); 326 int* mic_volume_percent);
325 327
328 void CheckMutedState();
329
326 static StreamType ParamsToStreamType(const AudioParameters& params); 330 static StreamType ParamsToStreamType(const AudioParameters& params);
327 331
328 // Gives access to the task runner of the creating thread. 332 // Gives access to the task runner of the creating thread.
329 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_; 333 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_;
330 334
331 // The task runner of audio-manager thread that this object runs on. 335 // The task runner of audio-manager thread that this object runs on.
332 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_; 336 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_;
333 337
334 // Contains the AudioInputController::EventHandler which receives state 338 // Contains the AudioInputController::EventHandler which receives state
335 // notifications from this class. 339 // notifications from this class.
(...skipping 24 matching lines...) Expand all
360 364
361 // 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.
362 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; 366 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT;
363 #endif 367 #endif
364 368
365 size_t prev_key_down_count_ = 0; 369 size_t prev_key_down_count_ = 0;
366 370
367 // Time when the stream started recording. 371 // Time when the stream started recording.
368 base::TimeTicks stream_create_time_; 372 base::TimeTicks stream_create_time_;
369 373
374 bool is_muted_ = false;
375 std::unique_ptr<base::RepeatingTimer> check_muted_state_timer_;
Max Morin 2017/06/02 09:56:05 Does this need to be allocated separately? Otherwi
ossu-chromium 2017/06/02 10:48:00 I'll try to get it as a regular object instead, se
Guido Urdaneta 2017/06/02 13:33:45 Using a regular object should suffice. From the do
376
370 #if BUILDFLAG(ENABLE_WEBRTC) 377 #if BUILDFLAG(ENABLE_WEBRTC)
371 // Used for audio debug recordings. Accessed on audio thread. 378 // Used for audio debug recordings. Accessed on audio thread.
372 AudioDebugRecordingHelper debug_recording_helper_; 379 AudioDebugRecordingHelper debug_recording_helper_;
373 #endif 380 #endif
374 381
375 class AudioCallback; 382 class AudioCallback;
376 // Holds a pointer to the callback object that receives audio data from 383 // Holds a pointer to the callback object that receives audio data from
377 // the lower audio layer. Valid only while 'recording' (between calls to 384 // the lower audio layer. Valid only while 'recording' (between calls to
378 // stream_->Start() and stream_->Stop()). 385 // stream_->Start() and stream_->Stop()).
379 // The value of this pointer is only set and read on the audio thread while 386 // The value of this pointer is only set and read on the audio thread while
(...skipping 14 matching lines...) Expand all
394 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated 401 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated
395 // at the end of DoClose. 402 // at the end of DoClose.
396 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; 403 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_;
397 404
398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 405 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
399 }; 406 };
400 407
401 } // namespace media 408 } // namespace media
402 409
403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 410 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698