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

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

Issue 7129057: Fix bug when unplugging an audio input device whilst using speech input. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Removed unnecessary includes Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/timer.h"
12 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
13 #include "media/audio/audio_manager.h" 14 #include "media/audio/audio_manager.h"
14 15
15 // An AudioInputController controls an AudioInputStream and records data 16 // An AudioInputController controls an AudioInputStream and records data
16 // from this input stream. It has an important function that it executes 17 // from this input stream. It has an important function that it executes
17 // audio operations like record, pause, stop, etc. on a separate thread. 18 // audio operations like record, pause, stop, etc. on a separate thread.
18 // 19 //
19 // All the public methods of AudioInputController are non-blocking except 20 // All the public methods of AudioInputController are non-blocking except
20 // close, the actual operations are performed on the audio input controller 21 // close, the actual operations are performed on the audio input controller
21 // thread. 22 // thread.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 EventHandler* event_handler, 94 EventHandler* event_handler,
94 AudioParameters params, 95 AudioParameters params,
95 // External synchronous reader for audio controller. 96 // External synchronous reader for audio controller.
96 SyncWriter* sync_writer); 97 SyncWriter* sync_writer);
97 98
98 // Sets the factory used by the static method Create. AudioInputController 99 // Sets the factory used by the static method Create. AudioInputController
99 // does not take ownership of |factory|. A value of NULL results in an 100 // does not take ownership of |factory|. A value of NULL results in an
100 // AudioInputController being created directly. 101 // AudioInputController being created directly.
101 #if defined(UNIT_TEST) 102 #if defined(UNIT_TEST)
102 static void set_factory(Factory* factory) { factory_ = factory; } 103 static void set_factory(Factory* factory) { factory_ = factory; }
104 AudioInputStream* stream() { return stream_; }
103 #endif 105 #endif
104 106
105 // Starts recording in this audio input stream. 107 // Starts recording in this audio input stream.
106 virtual void Record(); 108 virtual void Record();
107 109
108 // Closes the audio input stream and shutdown the audio input controller 110 // Closes the audio input stream and shutdown the audio input controller
109 // thread. This method returns only after all operations are completed. This 111 // thread. This method returns only after all operations are completed. This
110 // input controller cannot be used after this method is called. 112 // input controller cannot be used after this method is called.
111 // 113 //
112 // It is safe to call this method more than once. Calls after the first one 114 // It is safe to call this method more than once. Calls after the first one
(...skipping 18 matching lines...) Expand all
131 kError 133 kError
132 }; 134 };
133 135
134 AudioInputController(EventHandler* handler, SyncWriter* sync_writer); 136 AudioInputController(EventHandler* handler, SyncWriter* sync_writer);
135 137
136 // The following methods are executed on the audio controller thread. 138 // The following methods are executed on the audio controller thread.
137 void DoCreate(AudioParameters params); 139 void DoCreate(AudioParameters params);
138 void DoRecord(); 140 void DoRecord();
139 void DoClose(); 141 void DoClose();
140 void DoReportError(int code); 142 void DoReportError(int code);
143 void DoReportTimeoutError();
144 void DoTimerReset();
141 145
142 EventHandler* handler_; 146 EventHandler* handler_;
143 AudioInputStream* stream_; 147 AudioInputStream* stream_;
144 148
149 // |timer_| is used to call DoReportTimeoutError when we stop receiving
150 // OnData calls without an OnClose call. This can occur when an audio input
151 // device is unplugged whilst recording on Windows.
152 // See http://crbug.com/79936 for details.
153 base::DelayTimer<AudioInputController> timer_;
Satish 2011/06/15 10:23:27 'timer_' and 'DoTimerReset' seem very generic name
allanwoj 2011/06/15 11:11:17 Done.
154
145 // |state_| is written on the audio input controller thread and is read on 155 // |state_| is written on the audio input controller thread and is read on
146 // the hardware audio thread. These operations need to be locked. But lock 156 // the hardware audio thread. These operations need to be locked. But lock
147 // is not required for reading on the audio input controller thread. 157 // is not required for reading on the audio input controller thread.
148 State state_; 158 State state_;
149 159
150 base::Lock lock_; 160 base::Lock lock_;
151 161
152 // The audio input controller thread that this object runs on. 162 // The audio input controller thread that this object runs on.
153 base::Thread thread_; 163 base::Thread thread_;
154 164
155 // SyncWriter is used only in low latency mode for synchronous writing. 165 // SyncWriter is used only in low latency mode for synchronous writing.
156 SyncWriter* sync_writer_; 166 SyncWriter* sync_writer_;
157 167
158 static Factory* factory_; 168 static Factory* factory_;
159 169
160 DISALLOW_COPY_AND_ASSIGN(AudioInputController); 170 DISALLOW_COPY_AND_ASSIGN(AudioInputController);
161 }; 171 };
162 172
163 } // namespace media 173 } // namespace media
164 174
165 #endif // MEDIA_AUDIO_AUDIO_INPUT_CONTROLLER_H_ 175 #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