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

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

Issue 663123002: Reduce power logging and UMA stats when AGC is disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 1 month 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 <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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // The audio device will be created on the audio thread, and when that is 181 // The audio device will be created on the audio thread, and when that is
182 // done, the event handler will receive an OnCreated() call from that same 182 // done, the event handler will receive an OnCreated() call from that same
183 // thread. |user_input_monitor| is used for typing detection and can be NULL. 183 // thread. |user_input_monitor| is used for typing detection and can be NULL.
184 static scoped_refptr<AudioInputController> CreateLowLatency( 184 static scoped_refptr<AudioInputController> CreateLowLatency(
185 AudioManager* audio_manager, 185 AudioManager* audio_manager,
186 EventHandler* event_handler, 186 EventHandler* event_handler,
187 const AudioParameters& params, 187 const AudioParameters& params,
188 const std::string& device_id, 188 const std::string& device_id,
189 // External synchronous writer for audio controller. 189 // External synchronous writer for audio controller.
190 SyncWriter* sync_writer, 190 SyncWriter* sync_writer,
191 UserInputMonitor* user_input_monitor); 191 UserInputMonitor* user_input_monitor,
192 const bool agc_is_enabled);
192 193
193 // Factory method for creating an AudioInputController with an existing 194 // Factory method for creating an AudioInputController with an existing
194 // |stream| for low-latency mode, taking ownership of |stream|. The stream 195 // |stream| for low-latency mode, taking ownership of |stream|. The stream
195 // will be opened on the audio thread, and when that is done, the event 196 // will be opened on the audio thread, and when that is done, the event
196 // handler will receive an OnCreated() call from that same thread. 197 // handler will receive an OnCreated() call from that same thread.
197 // |user_input_monitor| is used for typing detection and can be NULL. 198 // |user_input_monitor| is used for typing detection and can be NULL.
198 static scoped_refptr<AudioInputController> CreateForStream( 199 static scoped_refptr<AudioInputController> CreateForStream(
199 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 200 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
200 EventHandler* event_handler, 201 EventHandler* event_handler,
201 AudioInputStream* stream, 202 AudioInputStream* stream,
(...skipping 12 matching lines...) Expand all
214 // is called. 215 // is called.
215 // It is safe to call this method more than once. Calls after the first one 216 // It is safe to call this method more than once. Calls after the first one
216 // will have no effect. 217 // will have no effect.
217 // This method trampolines to the audio thread. 218 // This method trampolines to the audio thread.
218 virtual void Close(const base::Closure& closed_task); 219 virtual void Close(const base::Closure& closed_task);
219 220
220 // Sets the capture volume of the input stream. The value 0.0 corresponds 221 // Sets the capture volume of the input stream. The value 0.0 corresponds
221 // to muted and 1.0 to maximum volume. 222 // to muted and 1.0 to maximum volume.
222 virtual void SetVolume(double volume); 223 virtual void SetVolume(double volume);
223 224
224 // Sets the Automatic Gain Control (AGC) state of the input stream.
225 // Changing the AGC state is not supported while recording is active.
226 virtual void SetAutomaticGainControl(bool enabled);
227
228 // AudioInputCallback implementation. Threading details depends on the 225 // AudioInputCallback implementation. Threading details depends on the
229 // device-specific implementation. 226 // device-specific implementation.
230 void OnData(AudioInputStream* stream, 227 void OnData(AudioInputStream* stream,
231 const AudioBus* source, 228 const AudioBus* source,
232 uint32 hardware_delay_bytes, 229 uint32 hardware_delay_bytes,
233 double volume) override; 230 double volume) override;
234 void OnError(AudioInputStream* stream) override; 231 void OnError(AudioInputStream* stream) override;
235 232
236 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } 233 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; }
237 234
(...skipping 22 matching lines...) Expand all
260 SILENCE_STATE_NO_MEASUREMENT = 0, 257 SILENCE_STATE_NO_MEASUREMENT = 0,
261 SILENCE_STATE_ONLY_AUDIO = 1, 258 SILENCE_STATE_ONLY_AUDIO = 1,
262 SILENCE_STATE_ONLY_SILENCE = 2, 259 SILENCE_STATE_ONLY_SILENCE = 2,
263 SILENCE_STATE_AUDIO_AND_SILENCE = 3, 260 SILENCE_STATE_AUDIO_AND_SILENCE = 3,
264 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE 261 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE
265 }; 262 };
266 #endif 263 #endif
267 264
268 AudioInputController(EventHandler* handler, 265 AudioInputController(EventHandler* handler,
269 SyncWriter* sync_writer, 266 SyncWriter* sync_writer,
270 UserInputMonitor* user_input_monitor); 267 UserInputMonitor* user_input_monitor,
271 ~AudioInputController() override; 268 const bool agc_is_enabled);
269 virtual ~AudioInputController();
272 270
273 // Methods called on the audio thread (owned by the AudioManager). 271 // Methods called on the audio thread (owned by the AudioManager).
274 void DoCreate(AudioManager* audio_manager, 272 void DoCreate(AudioManager* audio_manager,
275 const AudioParameters& params, 273 const AudioParameters& params,
276 const std::string& device_id); 274 const std::string& device_id);
277 void DoCreateForLowLatency(AudioManager* audio_manager, 275 void DoCreateForLowLatency(AudioManager* audio_manager,
278 const AudioParameters& params, 276 const AudioParameters& params,
279 const std::string& device_id); 277 const std::string& device_id);
280 void DoCreateForStream(AudioInputStream* stream_to_control); 278 void DoCreateForStream(AudioInputStream* stream_to_control);
281 void DoRecord(); 279 void DoRecord();
282 void DoClose(); 280 void DoClose();
283 void DoReportError(); 281 void DoReportError();
284 void DoSetVolume(double volume); 282 void DoSetVolume(double volume);
285 void DoSetAutomaticGainControl(bool enabled);
286 void DoOnData(scoped_ptr<AudioBus> data); 283 void DoOnData(scoped_ptr<AudioBus> data);
287 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); 284 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent);
288 285
289 // Method to check if we get recorded data after a stream was started, 286 // Method to check if we get recorded data after a stream was started,
290 // and log the result to UMA. 287 // and log the result to UMA.
291 void FirstCheckForNoData(); 288 void FirstCheckForNoData();
292 289
293 // Method which ensures that OnError() is triggered when data recording 290 // Method which ensures that OnError() is triggered when data recording
294 // times out. Called on the audio thread. 291 // times out. Called on the audio thread.
295 void DoCheckForNoData(); 292 void DoCheckForNoData();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 341
345 // SyncWriter is used only in low-latency mode for synchronous writing. 342 // SyncWriter is used only in low-latency mode for synchronous writing.
346 SyncWriter* sync_writer_; 343 SyncWriter* sync_writer_;
347 344
348 static Factory* factory_; 345 static Factory* factory_;
349 346
350 double max_volume_; 347 double max_volume_;
351 348
352 UserInputMonitor* user_input_monitor_; 349 UserInputMonitor* user_input_monitor_;
353 350
351 const bool agc_is_enabled_;
352
354 #if defined(AUDIO_POWER_MONITORING) 353 #if defined(AUDIO_POWER_MONITORING)
355 // Enabled in DoCrete() but not in DoCreateForStream(). 354 // Enabled in DoCrete() but not in DoCreateForStream().
356 bool power_measurement_is_enabled_; 355 bool power_measurement_is_enabled_;
357 356
358 // Updated each time a power measurement is performed. 357 // Updated each time a power measurement is performed.
359 base::TimeTicks last_audio_level_log_time_; 358 base::TimeTicks last_audio_level_log_time_;
360 359
361 // Whether the silence state should sent as UMA stat. 360 // Whether the silence state should sent as UMA stat.
362 bool log_silence_state_; 361 bool log_silence_state_;
363 362
364 // The silence report sent as UMA stat at the end of a session. 363 // The silence report sent as UMA stat at the end of a session.
365 SilenceState silence_state_; 364 SilenceState silence_state_;
366 #endif 365 #endif
367 366
368 size_t prev_key_down_count_; 367 size_t prev_key_down_count_;
369 368
370 // Time when a low-latency stream is created. 369 // Time when a low-latency stream is created.
371 base::TimeTicks low_latency_create_time_; 370 base::TimeTicks low_latency_create_time_;
372 371
373 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 372 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
374 }; 373 };
375 374
376 } // namespace media 375 } // namespace media
377 376
378 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 377 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_input_renderer_host.cc ('k') | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698