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

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

Issue 9956169: Improved timer implementation in AudioInputController (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
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/callback.h" 10 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/timer.h" 16 #include "base/timer.h"
16 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_io.h"
17 #include "media/audio/audio_manager_base.h" 18 #include "media/audio/audio_manager_base.h"
18 19
(...skipping 16 matching lines...) Expand all
35 // 36 //
36 // * Initial state 37 // * Initial state
37 // 38 //
38 // State sequences (assuming low-latency): 39 // State sequences (assuming low-latency):
39 // 40 //
40 // [Creating Thread] [Audio Thread] 41 // [Creating Thread] [Audio Thread]
41 // 42 //
42 // User AudioInputController EventHandler 43 // User AudioInputController EventHandler
43 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 44 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44 // CrateLowLatency() ==> DoCreate() 45 // CrateLowLatency() ==> DoCreate()
45 // AudioManager::MakeAudioInputStream() 46 // AudioManager::MakeAudioInputStream()
46 // AudioInputStream::Open() 47 // AudioInputStream::Open()
47 // .- - - - - - - - - - - - -> OnError() 48 // .- - - - - - - - - - - - -> OnError()
48 // DoResetNoDataTimer (posted on creating tread) 49 // create the data timer
49 // .-------------------------> OnCreated() 50 // .-------------------------> OnCreated()
50 // kCreated 51 // kCreated
51 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 // Record() ==> DoRecord() 53 // Record() ==> DoRecord()
53 // AudioInputStream::Start() 54 // AudioInputStream::Start()
54 // .-------------------------> OnRecording() 55 // .-------------------------> OnRecording()
56 // DoResetNoDataTimer()
55 // kRecording 57 // kRecording
56 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 58 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57 // Close() ==> DoClose() 59 // Close() ==> DoClose()
58 // state_ = kClosed 60 // delete the data timer
59 // AudioInputStream::Stop() 61 // state_ = kClosed
60 // AudioInputStream::Close() 62 // AudioInputStream::Stop()
61 // SyncWriter::Close() 63 // AudioInputStream::Close()
64 // SyncWriter::Close()
62 // Closure::Run() <--------------. 65 // Closure::Run() <--------------.
63 // (closure-task) 66 // (closure-task)
64 // 67 //
65 // The audio thread itself is owned by the AudioManager that the 68 // The audio thread itself is owned by the AudioManager that the
66 // AudioInputController holds a reference to. When performing tasks on the 69 // AudioInputController holds a reference to. When performing tasks on the
67 // audio thread, the controller must not add or release references to the 70 // audio thread, the controller must not add or release references to the
68 // AudioManager or itself (since it in turn holds a reference to the manager). 71 // AudioManager or itself (since it in turn holds a reference to the manager).
69 // 72 //
70 namespace media { 73 namespace media {
71 74
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Methods called on the audio thread (owned by the AudioManager). 195 // Methods called on the audio thread (owned by the AudioManager).
193 void DoCreate(AudioManager* audio_manager, const AudioParameters& params, 196 void DoCreate(AudioManager* audio_manager, const AudioParameters& params,
194 const std::string& device_id); 197 const std::string& device_id);
195 void DoRecord(); 198 void DoRecord();
196 void DoClose(); 199 void DoClose();
197 void DoReportError(int code); 200 void DoReportError(int code);
198 void DoSetVolume(double volume); 201 void DoSetVolume(double volume);
199 void DoSetAutomaticGainControl(bool enabled); 202 void DoSetAutomaticGainControl(bool enabled);
200 203
201 // Methods which ensures that OnError() is triggered when data recording 204 // Methods which ensures that OnError() is triggered when data recording
202 // times out. Both are called on the creating thread. 205 // times out. Both are called on the audio thread.
203 void DoReportNoDataError(); 206 void DoCheckForNoData();
204 void DoResetNoDataTimer(); 207 void DoResetNoDataTimer();
205 208
206 // Helper method that stops, closes, and NULL:s |*stream_|. 209 // Helper method that stops, closes, and NULL:s |*stream_|.
207 // Signals event when done if the event is not NULL. 210 // Signals event when done if the event is not NULL.
208 void DoStopCloseAndClearStream(base::WaitableEvent* done); 211 void DoStopCloseAndClearStream(base::WaitableEvent* done);
209 212
213 void SetDataIsActive(bool enabled);
214 bool GetDataIsActive();
215
210 // Gives access to the message loop of the creating thread. 216 // Gives access to the message loop of the creating thread.
211 scoped_refptr<base::MessageLoopProxy> creator_loop_; 217 scoped_refptr<base::MessageLoopProxy> creator_loop_;
212 218
213 // The message loop of audio-manager thread that this object runs on. 219 // The message loop of audio-manager thread that this object runs on.
214 scoped_refptr<base::MessageLoopProxy> message_loop_; 220 scoped_refptr<base::MessageLoopProxy> message_loop_;
215 221
216 // Contains the AudioInputController::EventHandler which receives state 222 // Contains the AudioInputController::EventHandler which receives state
217 // notifications from this class. 223 // notifications from this class.
218 EventHandler* handler_; 224 EventHandler* handler_;
219 225
220 // Pointer to the audio input stream object. 226 // Pointer to the audio input stream object.
221 AudioInputStream* stream_; 227 AudioInputStream* stream_;
222 228
223 // |no_data_timer_| is used to call DoReportNoDataError() when we stop 229 // |no_data_timer_| is used to call OnError() when we stop receiving
224 // receiving OnData() calls without an OnClose() call. This can occur 230 // OnData() calls without an OnClose() call. This can occur
225 // when an audio input device is unplugged whilst recording on Windows. 231 // when an audio input device is unplugged whilst recording on Windows.
226 // See http://crbug.com/79936 for details. 232 // See http://crbug.com/79936 for details.
227 // This member is only touched by the creating thread. 233 // This member is only touched by the audio thread.
228 scoped_ptr<base::DelayTimer<AudioInputController> > no_data_timer_; 234 scoped_ptr<base::DelayTimer<AudioInputController> > no_data_timer_;
229 235
236 // This flag is used to signal that we are receiving OnData() calls, i.e,
237 // that data is active. It can be touched by the audio thread and by the
238 // low-level audio thread which calls OnData(). E.g. on Windows, the
239 // low-level audio thread is called wasapi_capture_thread.
240 base::subtle::Atomic32 data_is_active_;
241
230 // |state_| is written on the audio thread and is read on the hardware audio 242 // |state_| is written on the audio thread and is read on the hardware audio
231 // thread. These operations need to be locked. But lock is not required for 243 // thread. These operations need to be locked. But lock is not required for
232 // reading on the audio input controller thread. 244 // reading on the audio input controller thread.
233 State state_; 245 State state_;
234 246
235 base::Lock lock_; 247 base::Lock lock_;
236 248
237 // SyncWriter is used only in low-latency mode for synchronous writing. 249 // SyncWriter is used only in low-latency mode for synchronous writing.
238 SyncWriter* sync_writer_; 250 SyncWriter* sync_writer_;
239 251
240 static Factory* factory_; 252 static Factory* factory_;
241 253
242 double max_volume_; 254 double max_volume_;
243 255
244 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 256 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
245 }; 257 };
246 258
247 } // namespace media 259 } // namespace media
248 260
249 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 261 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_input_controller.cc » ('j') | media/audio/audio_input_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698