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

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

Issue 11413078: Tab Audio Capture: Browser-side connect/disconnect functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify! Created 8 years 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_OUTPUT_CONTROLLER_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 AudioBuffersState buffers_state) OVERRIDE; 147 AudioBuffersState buffers_state) OVERRIDE;
148 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; 148 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
149 virtual void WaitTillDataReady() OVERRIDE; 149 virtual void WaitTillDataReady() OVERRIDE;
150 150
151 // AudioDeviceListener implementation. When called AudioOutputController will 151 // AudioDeviceListener implementation. When called AudioOutputController will
152 // shutdown the existing |stream_|, transition to the kRecreating state, 152 // shutdown the existing |stream_|, transition to the kRecreating state,
153 // create a new stream, and then transition back to an equivalent state prior 153 // create a new stream, and then transition back to an equivalent state prior
154 // to being called. 154 // to being called.
155 virtual void OnDeviceChange() OVERRIDE; 155 virtual void OnDeviceChange() OVERRIDE;
156 156
157 // Accessor to audio output parameters.
158 const AudioParameters& params() const { return params_; }
159
160 // Stops the normal audio output stream and begins providing audio data to
161 // another destination. |to_stream| remains under complete control of
162 // AudioOutputController until RevertDiversion() is called. Caller retains
163 // ownership of |to_stream| but it must remain alive until RevertDiversion()
164 // is called.
165 void DivertToStream(AudioOutputStream* to_stream);
166
167 // Restores normal audio output behavior. The stream that was provided in the
168 // previous call to DivertToStream() is closed.
169 void RevertDiversion();
DaleCurtis 2012/12/17 20:00:47 Naming is a bit odd; but my suggestions sound wonk
tommi (sloooow) - chröme 2012/12/18 13:41:26 RevertDivert? yeah, hard to come up with a good on
miu 2012/12/19 00:22:57 Done.
170
157 protected: 171 protected:
158 // Internal state of the source. 172 // Internal state of the source.
159 enum State { 173 enum State {
160 kEmpty, 174 kEmpty,
161 kCreated, 175 kCreated,
162 kPlaying, 176 kPlaying,
163 kStarting, 177 kStarting,
164 kPausedWhenStarting, 178 kPausedWhenStarting,
165 kPaused, 179 kPaused,
166 kClosed, 180 kClosed,
(...skipping 22 matching lines...) Expand all
189 void DoSetVolume(double volume); 203 void DoSetVolume(double volume);
190 void DoReportError(int code); 204 void DoReportError(int code);
191 205
192 // Helper method that starts physical stream. 206 // Helper method that starts physical stream.
193 void StartStream(); 207 void StartStream();
194 208
195 // Helper method that stops, closes, and NULLs |*stream_|. 209 // Helper method that stops, closes, and NULLs |*stream_|.
196 // Signals event when done if it is not NULL. 210 // Signals event when done if it is not NULL.
197 void DoStopCloseAndClearStream(base::WaitableEvent *done); 211 void DoStopCloseAndClearStream(base::WaitableEvent *done);
198 212
199 AudioManager* audio_manager_; 213 AudioManager* const audio_manager_;
214 const AudioParameters params_;
200 215
201 // |handler_| may be called only if |state_| is not kClosed. 216 // |handler_| may be called only if |state_| is not kClosed.
202 EventHandler* handler_; 217 EventHandler* handler_;
218
219 // Currently open stream.
203 AudioOutputStream* stream_; 220 AudioOutputStream* stream_;
204 221
222 // When non-NULL, audio is being diverted to this stream.
223 AudioOutputStream* diverting_to_stream_;
224
205 // The current volume of the audio stream. 225 // The current volume of the audio stream.
206 double volume_; 226 double volume_;
207 227
208 // |state_| is written on the audio manager thread and is read on the 228 // |state_| is written on the audio manager thread and is read on the
209 // hardware audio thread. These operations need to be locked. But lock 229 // hardware audio thread. These operations need to be locked. But lock
210 // is not required for reading on the audio manager thread. 230 // is not required for reading on the audio manager thread.
211 State state_; 231 State state_;
212 232
213 // The |lock_| must be acquired whenever we access |state_| from a thread 233 // The |lock_| must be acquired whenever we access |state_| from a thread
214 // other than the audio manager thread. 234 // other than the audio manager thread.
215 base::Lock lock_; 235 base::Lock lock_;
216 236
217 // SyncReader is used only in low latency mode for synchronous reading. 237 // SyncReader is used only in low latency mode for synchronous reading.
218 SyncReader* sync_reader_; 238 SyncReader* sync_reader_;
219 239
220 // The message loop of audio manager thread that this object runs on. 240 // The message loop of audio manager thread that this object runs on.
221 scoped_refptr<base::MessageLoopProxy> message_loop_; 241 scoped_refptr<base::MessageLoopProxy> message_loop_;
222 242
223 // When starting stream we wait for data to become available. 243 // When starting stream we wait for data to become available.
224 // Number of times left. 244 // Number of times left.
225 int number_polling_attempts_left_; 245 int number_polling_attempts_left_;
226 246
227 AudioParameters params_;
228
229 // Used to post delayed tasks to ourselves that we can cancel. 247 // Used to post delayed tasks to ourselves that we can cancel.
230 // We don't want the tasks to hold onto a reference as it will slow down 248 // We don't want the tasks to hold onto a reference as it will slow down
231 // shutdown and force it to wait for the most delayed task. 249 // shutdown and force it to wait for the most delayed task.
232 // Also, if we're shutting down, we do not want to poll for more data. 250 // Also, if we're shutting down, we do not want to poll for more data.
233 base::WeakPtrFactory<AudioOutputController> weak_this_; 251 base::WeakPtrFactory<AudioOutputController> weak_this_;
234 252
235 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 253 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
236 }; 254 };
237 255
238 } // namespace media 256 } // namespace media
239 257
240 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 258 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698