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

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

Issue 2624403002: Refactor AudioInputController and related interfaces. (Closed)
Patch Set: Address comments Created 3 years, 11 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/atomicops.h"
15 #include "base/callback.h"
16 #include "base/files/file.h" 14 #include "base/files/file.h"
17 #include "base/macros.h" 15 #include "base/memory/weak_ptr.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/synchronization/lock.h"
20 #include "base/synchronization/waitable_event.h"
21 #include "base/threading/thread.h"
22 #include "build/build_config.h"
23 #include "media/audio/audio_io.h" 16 #include "media/audio/audio_io.h"
24 #include "media/audio/audio_manager_base.h" 17 #include "media/audio/audio_manager_base.h"
25 #include "media/base/audio_bus.h" 18 #include "media/base/audio_bus.h"
26 #include "media/base/audio_parameters.h" 19 #include "media/base/audio_parameters.h"
27 20
28 // An AudioInputController controls an AudioInputStream and records data 21 // An AudioInputController controls an AudioInputStream and records data
29 // from this input stream. The two main methods are Record() and Close() and 22 // from this input stream. The two main methods are Record() and Close() and
30 // they are both executed on the audio thread which is injected by the two 23 // they are both executed on the audio thread which is injected by the two
31 // alternative factory methods, Create() or CreateLowLatency(). 24 // alternative factory methods, Create() or CreateLowLatency().
32 // 25 //
(...skipping 15 matching lines...) Expand all
48 // 41 //
49 // [Creating Thread] [Audio Thread] 42 // [Creating Thread] [Audio Thread]
50 // 43 //
51 // User AudioInputController EventHandler 44 // User AudioInputController EventHandler
52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 45 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53 // CrateLowLatency() ==> DoCreate() 46 // CrateLowLatency() ==> DoCreate()
54 // AudioManager::MakeAudioInputStream() 47 // AudioManager::MakeAudioInputStream()
55 // AudioInputStream::Open() 48 // AudioInputStream::Open()
56 // .- - - - - - - - - - - - -> OnError() 49 // .- - - - - - - - - - - - -> OnError()
57 // .-------------------------> OnCreated() 50 // .-------------------------> OnCreated()
58 // kCreated
59 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 51 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60 // Record() ==> DoRecord() 52 // Record() ==> DoRecord()
61 // AudioInputStream::Start() 53 // AudioInputStream::Start()
62 // kRecording
63 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 54 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64 // Close() ==> DoClose() 55 // Close() ==> DoClose()
65 // state_ = kClosed
66 // AudioInputStream::Stop() 56 // AudioInputStream::Stop()
67 // AudioInputStream::Close() 57 // AudioInputStream::Close()
68 // SyncWriter::Close() 58 // SyncWriter::Close()
69 // Closure::Run() <-----------------. 59 // Closure::Run() <-----------------.
70 // (closure-task) 60 // (closure-task)
71 // 61 //
72 // The audio thread itself is owned by the AudioManager that the 62 // The audio thread itself is owned by the AudioManager that the
73 // AudioInputController holds a reference to. When performing tasks on the 63 // AudioInputController holds a reference to. When performing tasks on the
74 // audio thread, the controller must not add or release references to the 64 // audio thread, the controller must not add or release references to the
75 // AudioManager or itself (since it in turn holds a reference to the manager). 65 // AudioManager or itself (since it in turn holds a reference to the manager).
76 // 66 //
77 namespace media { 67 namespace media {
78 68
79 // Only do power monitoring for non-mobile platforms to save resources. 69 // Only do power monitoring for non-mobile platforms to save resources.
80 #if !defined(OS_ANDROID) && !defined(OS_IOS) 70 #if !defined(OS_ANDROID) && !defined(OS_IOS)
81 #define AUDIO_POWER_MONITORING 71 #define AUDIO_POWER_MONITORING
82 #endif 72 #endif
83 73
84 class AudioFileWriter; 74 class AudioFileWriter;
85 class UserInputMonitor; 75 class UserInputMonitor;
86 76
87 class MEDIA_EXPORT AudioInputController 77 class MEDIA_EXPORT AudioInputController
88 : public base::RefCountedThreadSafe<AudioInputController>, 78 : public base::RefCountedThreadSafe<AudioInputController> {
89 public AudioInputStream::AudioInputCallback {
90 public: 79 public:
91 // Error codes to make native logging more clear. These error codes are added 80 // Error codes to make native logging more clear. These error codes are added
92 // to generic error strings to provide a higher degree of details. 81 // to generic error strings to provide a higher degree of details.
93 // Changing these values can lead to problems when matching native debug 82 // Changing these values can lead to problems when matching native debug
94 // logs with the actual cause of error. 83 // logs with the actual cause of error.
95 enum ErrorCode { 84 enum ErrorCode {
96 // An unspecified error occured. 85 // An unspecified error occured.
97 UNKNOWN_ERROR = 0, 86 UNKNOWN_ERROR = 0,
98 87
99 // Failed to create an audio input stream. 88 // Failed to create an audio input stream.
100 STREAM_CREATE_ERROR, // = 1 89 STREAM_CREATE_ERROR, // = 1
101 90
102 // Failed to open an audio input stream. 91 // Failed to open an audio input stream.
103 STREAM_OPEN_ERROR, // = 2 92 STREAM_OPEN_ERROR, // = 2
104 93
105 // Native input stream reports an error. Exact reason differs between 94 // Native input stream reports an error. Exact reason differs between
106 // platforms. 95 // platforms.
107 STREAM_ERROR, // = 3 96 STREAM_ERROR, // = 3
108 }; 97 };
109 98
110 // An event handler that receives events from the AudioInputController. The 99 // An event handler that receives events from the AudioInputController. The
111 // following methods are all called on the audio thread. 100 // following methods are all called on the audio thread.
112 class MEDIA_EXPORT EventHandler { 101 class MEDIA_EXPORT EventHandler {
113 public: 102 public:
114 virtual void OnCreated(AudioInputController* controller) = 0; 103 virtual void OnCreated(AudioInputController* controller) = 0;
115 virtual void OnError(AudioInputController* controller, 104 virtual void OnError(AudioInputController* controller,
116 ErrorCode error_code) = 0; 105 ErrorCode error_code) = 0;
117 virtual void OnData(AudioInputController* controller,
118 const AudioBus* data) = 0;
119 virtual void OnLog(AudioInputController* controller, 106 virtual void OnLog(AudioInputController* controller,
120 const std::string& message) = 0; 107 const std::string& message) = 0;
121 108
122 protected: 109 protected:
123 virtual ~EventHandler() {} 110 virtual ~EventHandler() {}
124 }; 111 };
125 112
126 // A synchronous writer interface used by AudioInputController for 113 // A synchronous writer interface used by AudioInputController for
127 // synchronous writing. 114 // synchronous writing.
128 class MEDIA_EXPORT SyncWriter { 115 class MEDIA_EXPORT SyncWriter {
(...skipping 28 matching lines...) Expand all
157 }; 144 };
158 145
159 // Factory method for creating an AudioInputController. 146 // Factory method for creating an AudioInputController.
160 // The audio device will be created on the audio thread, and when that is 147 // The audio device will be created on the audio thread, and when that is
161 // done, the event handler will receive an OnCreated() call from that same 148 // done, the event handler will receive an OnCreated() call from that same
162 // thread. |device_id| is the unique ID of the audio device to be opened. 149 // thread. |device_id| is the unique ID of the audio device to be opened.
163 // |user_input_monitor| is used for typing detection and can be NULL. 150 // |user_input_monitor| is used for typing detection and can be NULL.
164 static scoped_refptr<AudioInputController> Create( 151 static scoped_refptr<AudioInputController> Create(
165 AudioManager* audio_manager, 152 AudioManager* audio_manager,
166 EventHandler* event_handler, 153 EventHandler* event_handler,
154 SyncWriter* sync_writer,
167 const AudioParameters& params, 155 const AudioParameters& params,
168 const std::string& device_id, 156 const std::string& device_id,
169 UserInputMonitor* user_input_monitor); 157 UserInputMonitor* user_input_monitor);
170 158
171 // Sets the factory used by the static method Create(). AudioInputController 159 // Sets the factory used by the static method Create(). AudioInputController
172 // does not take ownership of |factory|. A value of NULL results in an 160 // does not take ownership of |factory|. A value of NULL results in an
173 // AudioInputController being created directly. 161 // AudioInputController being created directly.
174 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } 162 static void set_factory_for_testing(Factory* factory) { factory_ = factory; }
175 AudioInputStream* stream_for_testing() { return stream_; } 163 AudioInputStream* stream_for_testing() { return stream_; }
176 164
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // is called. 202 // is called.
215 // It is safe to call this method more than once. Calls after the first one 203 // It is safe to call this method more than once. Calls after the first one
216 // will have no effect. 204 // will have no effect.
217 // This method trampolines to the audio thread. 205 // This method trampolines to the audio thread.
218 virtual void Close(const base::Closure& closed_task); 206 virtual void Close(const base::Closure& closed_task);
219 207
220 // Sets the capture volume of the input stream. The value 0.0 corresponds 208 // Sets the capture volume of the input stream. The value 0.0 corresponds
221 // to muted and 1.0 to maximum volume. 209 // to muted and 1.0 to maximum volume.
222 virtual void SetVolume(double volume); 210 virtual void SetVolume(double volume);
223 211
224 // AudioInputCallback implementation. Threading details depends on the
225 // device-specific implementation.
226 void OnData(AudioInputStream* stream,
227 const AudioBus* source,
228 uint32_t hardware_delay_bytes,
229 double volume) override;
230 void OnError(AudioInputStream* stream) override;
231
232 bool SharedMemoryAndSyncSocketMode() const { return sync_writer_ != NULL; }
233
234 // Enable debug recording of audio input. 212 // Enable debug recording of audio input.
235 virtual void EnableDebugRecording(const base::FilePath& file_name); 213 virtual void EnableDebugRecording(const base::FilePath& file_name);
236 214
237 // Disable debug recording of audio input. 215 // Disable debug recording of audio input.
238 virtual void DisableDebugRecording(); 216 virtual void DisableDebugRecording();
239 217
240 protected: 218 protected:
241 friend class base::RefCountedThreadSafe<AudioInputController>; 219 friend class base::RefCountedThreadSafe<AudioInputController>;
242 220
243 // Used to log the result of capture startup. 221 // Used to log the result of capture startup.
244 // This was previously logged as a boolean with only the no callback and OK 222 // This was previously logged as a boolean with only the no callback and OK
245 // options. The enum order is kept to ensure backwards compatibility. 223 // options. The enum order is kept to ensure backwards compatibility.
246 // Elements in this enum should not be deleted or rearranged; the only 224 // Elements in this enum should not be deleted or rearranged; the only
247 // permitted operation is to add new elements before 225 // permitted operation is to add new elements before
248 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX. 226 // CAPTURE_STARTUP_RESULT_MAX and update CAPTURE_STARTUP_RESULT_MAX.
249 // 227 //
250 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA, 228 // The NO_DATA_CALLBACK enum has been replaced with NEVER_GOT_DATA,
251 // and there are also other histograms such as 229 // and there are also other histograms such as
252 // Media.Audio.InputStartupSuccessMac to cover issues similar 230 // Media.Audio.InputStartupSuccessMac to cover issues similar
253 // to the ones the NO_DATA_CALLBACK was intended for. 231 // to the ones the NO_DATA_CALLBACK was intended for.
254 enum CaptureStartupResult { 232 enum CaptureStartupResult {
255 CAPTURE_STARTUP_NO_DATA_CALLBACK = 0, // no longer used. 233 CAPTURE_STARTUP_NO_DATA_CALLBACK = 0, // no longer used.
256 CAPTURE_STARTUP_OK = 1, 234 CAPTURE_STARTUP_OK = 1,
257 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 2, 235 CAPTURE_STARTUP_CREATE_STREAM_FAILED = 2,
258 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 3, 236 CAPTURE_STARTUP_OPEN_STREAM_FAILED = 3,
259 CAPTURE_STARTUP_NEVER_GOT_DATA = 4, 237 CAPTURE_STARTUP_NEVER_GOT_DATA = 4,
260 CAPTURE_STARTUP_RESULT_MAX = CAPTURE_STARTUP_NEVER_GOT_DATA 238 CAPTURE_STARTUP_RESULT_MAX = CAPTURE_STARTUP_NEVER_GOT_DATA
261 }; 239 };
262 240
263 // Internal state of the source.
264 enum State {
265 CREATED,
266 RECORDING,
267 CLOSED
268 };
269
270 #if defined(AUDIO_POWER_MONITORING) 241 #if defined(AUDIO_POWER_MONITORING)
271 // Used to log a silence report (see OnData). 242 // Used to log a silence report (see OnData).
272 // Elements in this enum should not be deleted or rearranged; the only 243 // Elements in this enum should not be deleted or rearranged; the only
273 // permitted operation is to add new elements before SILENCE_STATE_MAX and 244 // permitted operation is to add new elements before SILENCE_STATE_MAX and
274 // update SILENCE_STATE_MAX. 245 // update SILENCE_STATE_MAX.
275 // Possible silence state transitions: 246 // Possible silence state transitions:
276 // SILENCE_STATE_AUDIO_AND_SILENCE 247 // SILENCE_STATE_AUDIO_AND_SILENCE
277 // ^ ^ 248 // ^ ^
278 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE 249 // SILENCE_STATE_ONLY_AUDIO SILENCE_STATE_ONLY_SILENCE
279 // ^ ^ 250 // ^ ^
280 // SILENCE_STATE_NO_MEASUREMENT 251 // SILENCE_STATE_NO_MEASUREMENT
281 enum SilenceState { 252 enum SilenceState {
282 SILENCE_STATE_NO_MEASUREMENT = 0, 253 SILENCE_STATE_NO_MEASUREMENT = 0,
283 SILENCE_STATE_ONLY_AUDIO = 1, 254 SILENCE_STATE_ONLY_AUDIO = 1,
284 SILENCE_STATE_ONLY_SILENCE = 2, 255 SILENCE_STATE_ONLY_SILENCE = 2,
285 SILENCE_STATE_AUDIO_AND_SILENCE = 3, 256 SILENCE_STATE_AUDIO_AND_SILENCE = 3,
286 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE 257 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE
287 }; 258 };
288 #endif 259 #endif
289 260
290 AudioInputController(EventHandler* handler, 261 AudioInputController(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
262 EventHandler* handler,
291 SyncWriter* sync_writer, 263 SyncWriter* sync_writer,
292 std::unique_ptr<AudioFileWriter> debug_writer, 264 std::unique_ptr<AudioFileWriter> debug_writer,
293 UserInputMonitor* user_input_monitor, 265 UserInputMonitor* user_input_monitor,
294 const bool agc_is_enabled); 266 const bool agc_is_enabled);
295 ~AudioInputController() override; 267 virtual ~AudioInputController();
296 268
269 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting()
270 const {
271 return task_runner_;
272 }
273
274 EventHandler* GetHandlerForTesting() const { return handler_; }
275
276 private:
297 // Methods called on the audio thread (owned by the AudioManager). 277 // Methods called on the audio thread (owned by the AudioManager).
298 void DoCreate(AudioManager* audio_manager, 278 void DoCreate(AudioManager* audio_manager,
299 const AudioParameters& params, 279 const AudioParameters& params,
300 const std::string& device_id); 280 const std::string& device_id);
301 void DoCreateForLowLatency(AudioManager* audio_manager, 281 void DoCreateForLowLatency(AudioManager* audio_manager,
302 const AudioParameters& params, 282 const AudioParameters& params,
303 const std::string& device_id); 283 const std::string& device_id);
304 void DoCreateForStream(AudioInputStream* stream_to_control); 284 void DoCreateForStream(AudioInputStream* stream_to_control);
305 void DoRecord(); 285 void DoRecord();
306 void DoClose(); 286 void DoClose();
307 void DoReportError(); 287 void DoReportError();
308 void DoSetVolume(double volume); 288 void DoSetVolume(double volume);
309 void DoOnData(std::unique_ptr<AudioBus> data);
310 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent); 289 void DoLogAudioLevels(float level_dbfs, int microphone_volume_percent);
311 290
312 // Helper method that stops, closes, and NULL:s |*stream_|.
313 void DoStopCloseAndClearStream();
314
315 #if defined(AUDIO_POWER_MONITORING) 291 #if defined(AUDIO_POWER_MONITORING)
316 // Updates the silence state, see enum SilenceState above for state 292 // Updates the silence state, see enum SilenceState above for state
317 // transitions. 293 // transitions.
318 void UpdateSilenceState(bool silence); 294 void UpdateSilenceState(bool silence);
319 295
320 // Logs the silence state as UMA stat. 296 // Logs the silence state as UMA stat.
321 void LogSilenceState(SilenceState value); 297 void LogSilenceState(SilenceState value);
322 #endif 298 #endif
323 299
324 // Logs the result of creating an AudioInputController. 300 // Logs the result of creating an AudioInputController.
325 // Only logs once, even if it is called several times. 301 // Only logs once, even if it is called several times.
326 void LogCaptureStartupResult(CaptureStartupResult result); 302 void LogCaptureStartupResult(CaptureStartupResult result);
327 303
328 // Enable and disable debug recording of audio input. Called on the audio 304 // Enable and disable debug recording of audio input. Called on the audio
329 // thread. 305 // thread.
330 void DoEnableDebugRecording(const base::FilePath& file_name); 306 void DoEnableDebugRecording(const base::FilePath& file_name);
331 void DoDisableDebugRecording(); 307 void DoDisableDebugRecording();
332 308
333 // Called on the audio thread. 309 // Called on the audio thread.
334 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data); 310 void WriteInputDataForDebugging(std::unique_ptr<AudioBus> data);
335 311
336 // Called by the stream with log messages. 312 // Called by the stream with log messages.
337 void LogMessage(const std::string& message); 313 void LogMessage(const std::string& message);
338 314
315 // Called on the hw callback thread. Checks for keyboard input if
316 // user_input_monitor_ is set otherwise returns false.
317 bool CheckForKeyboardInput();
318
319 // Does power monitoring on supported platforms.
320 // Called on the hw callback thread.
321 // Returns true iff average power and mic volume was returned and should
322 // be posted to DoLogAudioLevels on the audio thread.
323 // Returns false if either power measurements are disabled or aren't needed
324 // right now (they're done periodically).
325 bool CheckAudioPower(const AudioBus* source,
326 double volume,
327 float* average_power_dbfs,
328 int* mic_volume_percent);
329
339 // Gives access to the task runner of the creating thread. 330 // Gives access to the task runner of the creating thread.
340 scoped_refptr<base::SingleThreadTaskRunner> creator_task_runner_; 331 scoped_refptr<base::SingleThreadTaskRunner> const creator_task_runner_;
341 332
342 // The task runner of audio-manager thread that this object runs on. 333 // The task runner of audio-manager thread that this object runs on.
343 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 334 scoped_refptr<base::SingleThreadTaskRunner> const task_runner_;
344 335
345 // Contains the AudioInputController::EventHandler which receives state 336 // Contains the AudioInputController::EventHandler which receives state
346 // notifications from this class. 337 // notifications from this class.
347 EventHandler* handler_; 338 EventHandler* const handler_;
348 339
349 // Pointer to the audio input stream object. 340 // Pointer to the audio input stream object.
341 // Only used on the audio thread.
350 AudioInputStream* stream_; 342 AudioInputStream* stream_;
351 343
352 // Flag for whether CaptureStartupResults shall be reported.
353 // A value of 1 means that stats shall be reported,
354 // any other value means that stats have already been reported.
355 base::AtomicRefCount should_report_stats;
356
357 // |state_| is written on the audio thread and is read on the hardware audio
358 // thread. These operations need to be locked. But lock is not required for
359 // reading on the audio input controller thread.
360 State state_;
361
362 base::Lock lock_;
363
364 // SyncWriter is used only in low-latency mode for synchronous writing. 344 // SyncWriter is used only in low-latency mode for synchronous writing.
365 SyncWriter* sync_writer_; 345 SyncWriter* const sync_writer_;
366 346
367 static Factory* factory_; 347 static Factory* factory_;
368 348
369 double max_volume_; 349 double max_volume_;
370 350
371 UserInputMonitor* user_input_monitor_; 351 UserInputMonitor* const user_input_monitor_;
372 352
373 const bool agc_is_enabled_; 353 const bool agc_is_enabled_;
374 354
375 #if defined(AUDIO_POWER_MONITORING) 355 #if defined(AUDIO_POWER_MONITORING)
376 // Enabled in DoCrete() but not in DoCreateForStream(). 356 // Will be set to true if an AGC is supported and enabled (see DoCreate and
357 // DoCreateForStream). By default set to false.
377 bool power_measurement_is_enabled_; 358 bool power_measurement_is_enabled_;
378 359
379 // Updated each time a power measurement is performed. 360 // Updated each time a power measurement is performed.
380 base::TimeTicks last_audio_level_log_time_; 361 base::TimeTicks last_audio_level_log_time_;
381 362
382 // Whether the silence state should sent as UMA stat. 363 // Whether the silence state should sent as UMA stat.
383 bool log_silence_state_; 364 bool log_silence_state_;
384 365
385 // 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.
386 SilenceState silence_state_; 367 SilenceState silence_state_;
387 #endif 368 #endif
388 369
389 size_t prev_key_down_count_; 370 size_t prev_key_down_count_;
390 371
391 // Time when a low-latency stream is created. 372 // Time when a low-latency stream is created.
392 base::TimeTicks low_latency_create_time_; 373 base::TimeTicks low_latency_create_time_;
393 374
394 // Used for audio debug recordings. Accessed on audio thread. 375 // Used for audio debug recordings. Accessed on audio thread.
395 const std::unique_ptr<AudioFileWriter> debug_writer_; 376 const std::unique_ptr<AudioFileWriter> debug_writer_;
396 377
397 private: 378 class AudioCallback;
379 // Holds a pointer to the callback object that receives audio data from
380 // the lower audio layer. Valid only while 'recording' (between calls to
381 // stream_->Start() and stream_->Stop()).
382 // The value of this pointer is only set and read on the audio thread while
383 // the callbacks themselves occur on the hw callback thread. More details
384 // in the AudioCallback class in the cc file.
385 std::unique_ptr<AudioCallback> audio_callback_;
386
387 // A weak pointer factory that we use when posting tasks to the audio thread
388 // that we want to be automatically discarded after Close() has been called
389 // and that we do not want to keep the AudioInputController instance alive
390 // beyond what is desired by the user of the instance (e.g.
391 // AudioInputRendererHost). An example of where this is important is when
392 // we fire error notifications from the hw callback thread, post them to
393 // the audio thread. In that case, we do not want the error notification to
394 // keep the AudioInputController alive for as long as the error notification
395 // is pending and then make a callback from an AudioInputController that has
396 // already been closed.
397 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated
398 // at the end of DoClose.
399 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_;
400
398 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 401 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
399 }; 402 };
400 403
401 } // namespace media 404 } // namespace media
402 405
403 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 406 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer_impl_unittest.cc ('k') | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698