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

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

Issue 1272223003: Implement writing mic audio input data to file for debugging purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 years, 4 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 <string> 8 #include <string>
9 #include "base/atomicops.h" 9 #include "base/atomicops.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/files/file.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
17 #include "media/audio/audio_io.h" 18 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager_base.h" 19 #include "media/audio/audio_manager_base.h"
19 #include "media/audio/audio_parameters.h" 20 #include "media/audio/audio_parameters.h"
20 #include "media/base/audio_bus.h" 21 #include "media/base/audio_bus.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // audio thread, the controller must not add or release references to the 73 // audio thread, the controller must not add or release references to the
73 // AudioManager or itself (since it in turn holds a reference to the manager). 74 // AudioManager or itself (since it in turn holds a reference to the manager).
74 // 75 //
75 namespace media { 76 namespace media {
76 77
77 // Only do power monitoring for non-mobile platforms to save resources. 78 // Only do power monitoring for non-mobile platforms to save resources.
78 #if !defined(OS_ANDROID) && !defined(OS_IOS) 79 #if !defined(OS_ANDROID) && !defined(OS_IOS)
79 #define AUDIO_POWER_MONITORING 80 #define AUDIO_POWER_MONITORING
80 #endif 81 #endif
81 82
83 class AudioInputWriter;
82 class UserInputMonitor; 84 class UserInputMonitor;
83 85
84 class MEDIA_EXPORT AudioInputController 86 class MEDIA_EXPORT AudioInputController
85 : public base::RefCountedThreadSafe<AudioInputController>, 87 : public base::RefCountedThreadSafe<AudioInputController>,
86 public AudioInputStream::AudioInputCallback { 88 public AudioInputStream::AudioInputCallback {
87 public: 89 public:
88 90
89 // Error codes to make native loggin more clear. These error codes are added 91 // Error codes to make native loggin more clear. These error codes are added
90 // to generic error strings to provide a higher degree of details. 92 // to generic error strings to provide a higher degree of details.
91 // Changing these values can lead to problems when matching native debug 93 // Changing these values can lead to problems when matching native debug
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // AudioInputCallback implementation. Threading details depends on the 227 // AudioInputCallback implementation. Threading details depends on the
226 // device-specific implementation. 228 // device-specific implementation.
227 void OnData(AudioInputStream* stream, 229 void OnData(AudioInputStream* stream,
228 const AudioBus* source, 230 const AudioBus* source,
229 uint32 hardware_delay_bytes, 231 uint32 hardware_delay_bytes,
230 double volume) override; 232 double volume) override;
231 void OnError(AudioInputStream* stream) override; 233 void OnError(AudioInputStream* stream) override;
232 234
233 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; } 235 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; }
234 236
237 // Enable debug recording of audio input.
238 void EnableDebugRecording(AudioInputWriter* input_writer);
239
240 // Disbale debug recording of audio input. Must be called before owner of
241 // |input_writer| deletes it.
242 void DisableDebugRecording(const base::Closure& callback);
243
235 protected: 244 protected:
236 friend class base::RefCountedThreadSafe<AudioInputController>; 245 friend class base::RefCountedThreadSafe<AudioInputController>;
237 246
238 // Internal state of the source. 247 // Internal state of the source.
239 enum State { 248 enum State {
240 CREATED, 249 CREATED,
241 RECORDING, 250 RECORDING,
242 CLOSED 251 CLOSED
243 }; 252 };
244 253
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 308
300 #if defined(AUDIO_POWER_MONITORING) 309 #if defined(AUDIO_POWER_MONITORING)
301 // Updates the silence state, see enum SilenceState above for state 310 // Updates the silence state, see enum SilenceState above for state
302 // transitions. 311 // transitions.
303 void UpdateSilenceState(bool silence); 312 void UpdateSilenceState(bool silence);
304 313
305 // Logs the silence state as UMA stat. 314 // Logs the silence state as UMA stat.
306 void LogSilenceState(SilenceState value); 315 void LogSilenceState(SilenceState value);
307 #endif 316 #endif
308 317
318 // Enable and disable debug recording of audio input. Called on the audio
319 // thread.
320 void DoEnableDebugRecording(AudioInputWriter* input_writer);
321 void DoDisableDebugRecording();
322
323 // Called on the audio thread.
324 void WriteInputDataForDebugging(scoped_ptr<AudioBus> data);
325
309 // Gives access to the task runner of the creating thread. 326 // Gives access to the task runner of the creating thread.
310 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; 327 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_;
311 328
312 // The task runner of audio-manager thread that this object runs on. 329 // The task runner of audio-manager thread that this object runs on.
313 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 330 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
314 331
315 // Contains the AudioInputController::EventHandler which receives state 332 // Contains the AudioInputController::EventHandler which receives state
316 // notifications from this class. 333 // notifications from this class.
317 EventHandler* handler_; 334 EventHandler* handler_;
318 335
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 379
363 // The silence report sent as UMA stat at the end of a session. 380 // The silence report sent as UMA stat at the end of a session.
364 SilenceState silence_state_; 381 SilenceState silence_state_;
365 #endif 382 #endif
366 383
367 size_t prev_key_down_count_; 384 size_t prev_key_down_count_;
368 385
369 // Time when a low-latency stream is created. 386 // Time when a low-latency stream is created.
370 base::TimeTicks low_latency_create_time_; 387 base::TimeTicks low_latency_create_time_;
371 388
389 // Used for audio debug recordings. Accessed on audio thread.
390 AudioInputWriter* input_writer_;
391
372 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 392 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
373 }; 393 };
374 394
375 } // namespace media 395 } // namespace media
376 396
377 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 397 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698