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

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: Move Diverter interface into audio_io.h. Replace use of singleton with BrowserMainLoop. Created 7 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 | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // 59 //
60 // Since AudioOutputController uses AudioManager's message loop the controller 60 // Since AudioOutputController uses AudioManager's message loop the controller
61 // uses WeakPtr to allow safe cancellation of pending tasks. 61 // uses WeakPtr to allow safe cancellation of pending tasks.
62 // 62 //
63 63
64 namespace media { 64 namespace media {
65 65
66 class MEDIA_EXPORT AudioOutputController 66 class MEDIA_EXPORT AudioOutputController
67 : public base::RefCountedThreadSafe<AudioOutputController>, 67 : public base::RefCountedThreadSafe<AudioOutputController>,
68 public AudioOutputStream::AudioSourceCallback, 68 public AudioOutputStream::AudioSourceCallback,
69 public AudioOutputStream::AudioSourceDiverter,
69 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { 70 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) {
70 public: 71 public:
71 // An event handler that receives events from the AudioOutputController. The 72 // An event handler that receives events from the AudioOutputController. The
72 // following methods are called on the audio manager thread. 73 // following methods are called on the audio manager thread.
73 class MEDIA_EXPORT EventHandler { 74 class MEDIA_EXPORT EventHandler {
74 public: 75 public:
75 virtual void OnCreated(AudioOutputController* controller) = 0; 76 virtual void OnCreated(AudioOutputController* controller) = 0;
76 virtual void OnPlaying(AudioOutputController* controller) = 0; 77 virtual void OnPlaying(AudioOutputController* controller) = 0;
77 virtual void OnPaused(AudioOutputController* controller) = 0; 78 virtual void OnPaused(AudioOutputController* controller) = 0;
78 virtual void OnError(AudioOutputController* controller, int error_code) = 0; 79 virtual void OnError(AudioOutputController* controller, int error_code) = 0;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 AudioBuffersState buffers_state) OVERRIDE; 148 AudioBuffersState buffers_state) OVERRIDE;
148 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE; 149 virtual void OnError(AudioOutputStream* stream, int code) OVERRIDE;
149 virtual void WaitTillDataReady() OVERRIDE; 150 virtual void WaitTillDataReady() OVERRIDE;
150 151
151 // AudioDeviceListener implementation. When called AudioOutputController will 152 // AudioDeviceListener implementation. When called AudioOutputController will
152 // shutdown the existing |stream_|, transition to the kRecreating state, 153 // shutdown the existing |stream_|, transition to the kRecreating state,
153 // create a new stream, and then transition back to an equivalent state prior 154 // create a new stream, and then transition back to an equivalent state prior
154 // to being called. 155 // to being called.
155 virtual void OnDeviceChange() OVERRIDE; 156 virtual void OnDeviceChange() OVERRIDE;
156 157
158 // AudioSourceDiverter implementation.
159 virtual const AudioParameters& GetAudioParameters() OVERRIDE;
160 virtual void StartDiverting(AudioOutputStream* to_stream) OVERRIDE;
161 virtual void StopDiverting() OVERRIDE;
162
157 protected: 163 protected:
158 // Internal state of the source. 164 // Internal state of the source.
159 enum State { 165 enum State {
160 kEmpty, 166 kEmpty,
161 kCreated, 167 kCreated,
162 kPlaying, 168 kPlaying,
163 kStarting, 169 kStarting,
164 kPausedWhenStarting, 170 kPausedWhenStarting,
165 kPaused, 171 kPaused,
166 kClosed, 172 kClosed,
167 kError, 173 kError,
168 kRecreating, 174 kRecreating,
(...skipping 12 matching lines...) Expand all
181 187
182 // The following methods are executed on the audio manager thread. 188 // The following methods are executed on the audio manager thread.
183 void DoCreate(); 189 void DoCreate();
184 void DoPlay(); 190 void DoPlay();
185 void PollAndStartIfDataReady(); 191 void PollAndStartIfDataReady();
186 void DoPause(); 192 void DoPause();
187 void DoFlush(); 193 void DoFlush();
188 void DoClose(); 194 void DoClose();
189 void DoSetVolume(double volume); 195 void DoSetVolume(double volume);
190 void DoReportError(int code); 196 void DoReportError(int code);
197 void DoStartDiverting(AudioOutputStream* to_stream);
198 void DoStopDiverting();
191 199
192 // Helper method that starts physical stream. 200 // Helper method that starts physical stream.
193 void StartStream(); 201 void StartStream();
194 202
195 // Helper method that stops, closes, and NULLs |*stream_|. 203 // Helper method that stops, closes, and NULLs |*stream_|.
196 // Signals event when done if it is not NULL. 204 // Signals event when done if it is not NULL.
197 void DoStopCloseAndClearStream(base::WaitableEvent *done); 205 void DoStopCloseAndClearStream(base::WaitableEvent *done);
198 206
199 AudioManager* const audio_manager_; 207 AudioManager* const audio_manager_;
208 const AudioParameters params_;
200 209
201 // |handler_| may be called only if |state_| is not kClosed. 210 // |handler_| may be called only if |state_| is not kClosed.
202 EventHandler* handler_; 211 EventHandler* handler_;
203 212
204 // Note: It's important to invalidate the weak pointers whenever stream_ is 213 // Note: It's important to invalidate the weak pointers whenever stream_ is
205 // changed. See comment for weak_this_. 214 // changed. See comment for weak_this_.
206 AudioOutputStream* stream_; 215 AudioOutputStream* stream_;
207 216
217 // When non-NULL, audio is being diverted to this stream.
218 AudioOutputStream* diverting_to_stream_;
219
208 // The current volume of the audio stream. 220 // The current volume of the audio stream.
209 double volume_; 221 double volume_;
210 222
211 // |state_| is written on the audio manager thread and is read on the 223 // |state_| is written on the audio manager thread and is read on the
212 // hardware audio thread. These operations need to be locked. But lock 224 // hardware audio thread. These operations need to be locked. But lock
213 // is not required for reading on the audio manager thread. 225 // is not required for reading on the audio manager thread.
214 State state_; 226 State state_;
215 227
216 // The |lock_| must be acquired whenever we access |state_| from a thread 228 // The |lock_| must be acquired whenever we access |state_| from a thread
217 // other than the audio manager thread. 229 // other than the audio manager thread.
218 base::Lock lock_; 230 base::Lock lock_;
219 231
220 // SyncReader is used only in low latency mode for synchronous reading. 232 // SyncReader is used only in low latency mode for synchronous reading.
221 SyncReader* sync_reader_; 233 SyncReader* sync_reader_;
222 234
223 // The message loop of audio manager thread that this object runs on. 235 // The message loop of audio manager thread that this object runs on.
224 scoped_refptr<base::MessageLoopProxy> message_loop_; 236 scoped_refptr<base::MessageLoopProxy> message_loop_;
225 237
226 // When starting stream we wait for data to become available. 238 // When starting stream we wait for data to become available.
227 // Number of times left. 239 // Number of times left.
228 int number_polling_attempts_left_; 240 int number_polling_attempts_left_;
229 241
230 AudioParameters params_;
231
232 // Used to auto-cancel the delayed tasks that are created to poll for data 242 // Used to auto-cancel the delayed tasks that are created to poll for data
233 // (when starting-up a stream). 243 // (when starting-up a stream).
234 base::WeakPtrFactory<AudioOutputController> weak_this_; 244 base::WeakPtrFactory<AudioOutputController> weak_this_;
235 245
236 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 246 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
237 }; 247 };
238 248
239 } // namespace media 249 } // namespace media
240 250
241 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 251 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698