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

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

Issue 2702323002: Move AudioDebugFileWriter from content/ to media/. (Closed)
Patch Set: Code review, unit test fix and rebase. Created 3 years, 10 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
« no previous file with comments | « media/audio/audio_file_writer.h ('k') | media/audio/audio_input_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/audio/audio_file_writer.h" 16 #include "media/audio/audio_debug_file_writer.h"
17 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_manager_base.h" 18 #include "media/audio/audio_manager_base.h"
19 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
20 #include "media/base/audio_parameters.h" 20 #include "media/base/audio_parameters.h"
21 21
22 // An AudioInputController controls an AudioInputStream and records data 22 // An AudioInputController controls an AudioInputStream and records data
23 // from this input stream. The two main methods are Record() and Close() and 23 // from this input stream. The two main methods are Record() and Close() and
24 // they are both executed on the audio thread which is injected by the two 24 // they are both executed on the audio thread which is injected by the two
25 // alternative factory methods, Create() or CreateForStream(). 25 // alternative factory methods, Create() or CreateForStream().
26 // 26 //
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 }; 153 };
154 154
155 // Sets the factory used by the static method Create(). AudioInputController 155 // Sets the factory used by the static method Create(). AudioInputController
156 // does not take ownership of |factory|. A value of NULL results in an 156 // does not take ownership of |factory|. A value of NULL results in an
157 // AudioInputController being created directly. 157 // AudioInputController being created directly.
158 static void set_factory_for_testing(Factory* factory) { factory_ = factory; } 158 static void set_factory_for_testing(Factory* factory) { factory_ = factory; }
159 AudioInputStream* stream_for_testing() { return stream_; } 159 AudioInputStream* stream_for_testing() { return stream_; }
160 160
161 // The audio device will be created on the audio thread, and when that is 161 // The audio device will be created on the audio thread, and when that is
162 // done, the event handler will receive an OnCreated() call from that same 162 // done, the event handler will receive an OnCreated() call from that same
163 // thread. |user_input_monitor| is used for typing detection and can be NULL, 163 // thread. |user_input_monitor| is used for typing detection and can be NULL.
164 // and |debug_writer| can be null if debug recording is not required. 164 // |file_task_runner| is used for debug recordings.
165 // TODO(grunell): Move handling of debug recording to AudioManager.
165 static scoped_refptr<AudioInputController> Create( 166 static scoped_refptr<AudioInputController> Create(
166 AudioManager* audio_manager, 167 AudioManager* audio_manager,
167 EventHandler* event_handler, 168 EventHandler* event_handler,
168 SyncWriter* sync_writer, 169 SyncWriter* sync_writer,
169 UserInputMonitor* user_input_monitor, 170 UserInputMonitor* user_input_monitor,
170 std::unique_ptr<AudioFileWriter> debug_writer,
171 const AudioParameters& params, 171 const AudioParameters& params,
172 const std::string& device_id, 172 const std::string& device_id,
173 // External synchronous writer for audio controller. 173 // External synchronous writer for audio controller.
174 bool agc_is_enabled); 174 bool agc_is_enabled,
175 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
175 176
176 // Factory method for creating an AudioInputController with an existing 177 // Factory method for creating an AudioInputController with an existing
177 // |stream|. The stream will be opened on the audio thread, and when that is 178 // |stream|. The stream will be opened on the audio thread, and when that is
178 // done, the event handler will receive an OnCreated() call from that same 179 // done, the event handler will receive an OnCreated() call from that same
179 // thread. |user_input_monitor| is used for typing detection and can be NULL. 180 // thread. |user_input_monitor| is used for typing detection and can be NULL.
181 // |file_task_runner| and |params| are used for debug recordings.
180 static scoped_refptr<AudioInputController> CreateForStream( 182 static scoped_refptr<AudioInputController> CreateForStream(
181 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 183 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
182 EventHandler* event_handler, 184 EventHandler* event_handler,
183 AudioInputStream* stream, 185 AudioInputStream* stream,
184 // External synchronous writer for audio controller. 186 // External synchronous writer for audio controller.
185 SyncWriter* sync_writer, 187 SyncWriter* sync_writer,
186 std::unique_ptr<AudioFileWriter> debug_writer, 188 UserInputMonitor* user_input_monitor,
187 UserInputMonitor* user_input_monitor); 189 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
190 const AudioParameters& params);
188 191
189 // Starts recording using the created audio input stream. 192 // Starts recording using the created audio input stream.
190 // This method is called on the creator thread. 193 // This method is called on the creator thread.
191 virtual void Record(); 194 virtual void Record();
192 195
193 // Closes the audio input stream. The state is changed and the resources 196 // Closes the audio input stream. The state is changed and the resources
194 // are freed on the audio thread. |closed_task| is then executed on the thread 197 // are freed on the audio thread. |closed_task| is then executed on the thread
195 // that called Close(). 198 // that called Close().
196 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task| 199 // Callbacks (EventHandler and SyncWriter) must exist until |closed_task|
197 // is called. 200 // is called.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // SILENCE_STATE_NO_MEASUREMENT 249 // SILENCE_STATE_NO_MEASUREMENT
247 enum SilenceState { 250 enum SilenceState {
248 SILENCE_STATE_NO_MEASUREMENT = 0, 251 SILENCE_STATE_NO_MEASUREMENT = 0,
249 SILENCE_STATE_ONLY_AUDIO = 1, 252 SILENCE_STATE_ONLY_AUDIO = 1,
250 SILENCE_STATE_ONLY_SILENCE = 2, 253 SILENCE_STATE_ONLY_SILENCE = 2,
251 SILENCE_STATE_AUDIO_AND_SILENCE = 3, 254 SILENCE_STATE_AUDIO_AND_SILENCE = 3,
252 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE 255 SILENCE_STATE_MAX = SILENCE_STATE_AUDIO_AND_SILENCE
253 }; 256 };
254 #endif 257 #endif
255 258
256 AudioInputController(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 259 AudioInputController(
257 EventHandler* handler, 260 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
258 SyncWriter* sync_writer, 261 EventHandler* handler,
259 std::unique_ptr<AudioFileWriter> debug_writer, 262 SyncWriter* sync_writer,
260 UserInputMonitor* user_input_monitor, 263 UserInputMonitor* user_input_monitor,
261 StreamType type); 264 const AudioParameters& params,
265 StreamType type,
266 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner);
262 virtual ~AudioInputController(); 267 virtual ~AudioInputController();
263 268
264 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting() 269 const scoped_refptr<base::SingleThreadTaskRunner>& GetTaskRunnerForTesting()
265 const { 270 const {
266 return task_runner_; 271 return task_runner_;
267 } 272 }
268 273
269 EventHandler* GetHandlerForTesting() const { return handler_; } 274 EventHandler* GetHandlerForTesting() const { return handler_; }
270 275
271 private: 276 private:
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // 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.
361 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT; 366 SilenceState silence_state_ = SILENCE_STATE_NO_MEASUREMENT;
362 #endif 367 #endif
363 368
364 size_t prev_key_down_count_ = 0; 369 size_t prev_key_down_count_ = 0;
365 370
366 // Time when the stream started recording. 371 // Time when the stream started recording.
367 base::TimeTicks stream_create_time_; 372 base::TimeTicks stream_create_time_;
368 373
369 // Used for audio debug recordings. Accessed on audio thread. 374 // Used for audio debug recordings. Accessed on audio thread.
370 const std::unique_ptr<AudioFileWriter> debug_writer_; 375 const std::unique_ptr<AudioDebugFileWriter> debug_writer_;
371 376
372 class AudioCallback; 377 class AudioCallback;
373 // Holds a pointer to the callback object that receives audio data from 378 // Holds a pointer to the callback object that receives audio data from
374 // the lower audio layer. Valid only while 'recording' (between calls to 379 // the lower audio layer. Valid only while 'recording' (between calls to
375 // stream_->Start() and stream_->Stop()). 380 // stream_->Start() and stream_->Stop()).
376 // The value of this pointer is only set and read on the audio thread while 381 // The value of this pointer is only set and read on the audio thread while
377 // the callbacks themselves occur on the hw callback thread. More details 382 // the callbacks themselves occur on the hw callback thread. More details
378 // in the AudioCallback class in the cc file. 383 // in the AudioCallback class in the cc file.
379 std::unique_ptr<AudioCallback> audio_callback_; 384 std::unique_ptr<AudioCallback> audio_callback_;
380 385
(...skipping 10 matching lines...) Expand all
391 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated 396 // The weak_ptr_factory_ and all outstanding weak pointers, are invalidated
392 // at the end of DoClose. 397 // at the end of DoClose.
393 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_; 398 base::WeakPtrFactory<AudioInputController> weak_ptr_factory_;
394 399
395 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 400 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
396 }; 401 };
397 402
398 } // namespace media 403 } // namespace media
399 404
400 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 405 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « media/audio/audio_file_writer.h ('k') | media/audio/audio_input_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698