OLD | NEW |
---|---|
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_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/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | |
11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "media/audio/audio_buffers_state.h" | 14 #include "media/audio/audio_buffers_state.h" |
14 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
15 #include "media/audio/audio_manager.h" | 16 #include "media/audio/audio_manager.h" |
16 #include "media/audio/simple_sources.h" | 17 #include "media/audio/simple_sources.h" |
17 | 18 |
18 class MessageLoop; | 19 class MessageLoop; |
19 | 20 |
20 // An AudioOutputController controls an AudioOutputStream and provides data | 21 // An AudioOutputController controls an AudioOutputStream and provides data |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 virtual bool DataReady() = 0; | 109 virtual bool DataReady() = 0; |
109 }; | 110 }; |
110 | 111 |
111 virtual ~AudioOutputController(); | 112 virtual ~AudioOutputController(); |
112 | 113 |
113 // Factory method for creating an AudioOutputController. | 114 // Factory method for creating an AudioOutputController. |
114 // If successful, an audio controller thread is created. The audio device | 115 // If successful, an audio controller thread is created. The audio device |
115 // will be created on the audio controller thread and when that is done | 116 // will be created on the audio controller thread and when that is done |
116 // event handler will receive a OnCreated() call. | 117 // event handler will receive a OnCreated() call. |
117 static scoped_refptr<AudioOutputController> Create( | 118 static scoped_refptr<AudioOutputController> Create( |
119 AudioManager* audio_manager, | |
118 EventHandler* event_handler, | 120 EventHandler* event_handler, |
119 const AudioParameters& params, | 121 const AudioParameters& params, |
120 // Soft limit for buffer capacity in this controller. This parameter | 122 // Soft limit for buffer capacity in this controller. This parameter |
121 // is used only in regular latency mode. | 123 // is used only in regular latency mode. |
122 uint32 buffer_capacity); | 124 uint32 buffer_capacity); |
123 | 125 |
124 // Factory method for creating a low latency audio stream. | 126 // Factory method for creating a low latency audio stream. |
125 static scoped_refptr<AudioOutputController> CreateLowLatency( | 127 static scoped_refptr<AudioOutputController> CreateLowLatency( |
128 AudioManager* audio_manager, | |
126 EventHandler* event_handler, | 129 EventHandler* event_handler, |
127 const AudioParameters& params, | 130 const AudioParameters& params, |
128 // External synchronous reader for audio controller. | 131 // External synchronous reader for audio controller. |
129 SyncReader* sync_reader); | 132 SyncReader* sync_reader); |
130 | 133 |
131 // Methods to control playback of the stream. | 134 // Methods to control playback of the stream. |
132 | 135 |
133 // Starts the playback of this audio output stream. | 136 // Starts the playback of this audio output stream. |
134 void Play(); | 137 void Play(); |
135 | 138 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 kPaused, | 182 kPaused, |
180 kClosed, | 183 kClosed, |
181 kError, | 184 kError, |
182 }; | 185 }; |
183 | 186 |
184 private: | 187 private: |
185 // We are polling sync reader if data became available. | 188 // We are polling sync reader if data became available. |
186 static const int kPollNumAttempts; | 189 static const int kPollNumAttempts; |
187 static const int kPollPauseInMilliseconds; | 190 static const int kPollPauseInMilliseconds; |
188 | 191 |
189 AudioOutputController(EventHandler* handler, | 192 AudioOutputController(AudioManager* audio_manager, |
193 EventHandler* handler, | |
190 uint32 capacity, SyncReader* sync_reader); | 194 uint32 capacity, SyncReader* sync_reader); |
191 | 195 |
192 // The following methods are executed on the audio controller thread. | 196 // The following methods are executed on the audio controller thread. |
193 void DoCreate(const AudioParameters& params); | 197 void DoCreate(const AudioParameters& params); |
194 void DoPlay(); | 198 void DoPlay(); |
195 void PollAndStartIfDataReady(); | 199 void PollAndStartIfDataReady(); |
196 void DoPause(); | 200 void DoPause(); |
197 void DoFlush(); | 201 void DoFlush(); |
198 void DoClose(const base::Closure& closed_task); | 202 void DoClose(const base::Closure& closed_task); |
199 void DoSetVolume(double volume); | 203 void DoSetVolume(double volume); |
200 void DoReportError(int code); | 204 void DoReportError(int code); |
201 | 205 |
202 // Helper method to submit a OnMoreData() call to the event handler. | 206 // Helper method to submit a OnMoreData() call to the event handler. |
203 void SubmitOnMoreData_Locked(); | 207 void SubmitOnMoreData_Locked(); |
204 | 208 |
205 // Helper method that starts physical stream. | 209 // Helper method that starts physical stream. |
206 void StartStream(); | 210 void StartStream(); |
207 | 211 |
208 // Helper method that stops, closes, and NULLs |*stream_|. | 212 // Helper method that stops, closes, and NULLs |*stream_|. |
209 void StopCloseAndClearStream(); | 213 void StopCloseAndClearStream(); |
210 | 214 |
215 scoped_refptr<AudioManager> audio_manager_; | |
211 // |handler_| may be called only if |state_| is not kClosed. | 216 // |handler_| may be called only if |state_| is not kClosed. |
212 EventHandler* handler_; | 217 EventHandler* handler_; |
213 AudioOutputStream* stream_; | 218 AudioOutputStream* stream_; |
214 | 219 |
215 // The current volume of the audio stream. | 220 // The current volume of the audio stream. |
216 double volume_; | 221 double volume_; |
217 | 222 |
218 // |state_| is written on the audio controller thread and is read on the | 223 // |state_| is written on the audio controller thread and is read on the |
219 // hardware audio thread. These operations need to be locked. But lock | 224 // hardware audio thread. These operations need to be locked. But lock |
220 // is not required for reading on the audio controller thread. | 225 // is not required for reading on the audio controller thread. |
(...skipping 11 matching lines...) Expand all Loading... | |
232 // SyncReader is used only in low latency mode for synchronous reading. | 237 // SyncReader is used only in low latency mode for synchronous reading. |
233 SyncReader* sync_reader_; | 238 SyncReader* sync_reader_; |
234 | 239 |
235 // The message loop of audio thread that this object runs on. | 240 // The message loop of audio thread that this object runs on. |
236 MessageLoop* message_loop_; | 241 MessageLoop* message_loop_; |
237 | 242 |
238 // When starting stream we wait for data to become available. | 243 // When starting stream we wait for data to become available. |
239 // Number of times left. | 244 // Number of times left. |
240 int number_polling_attempts_left_; | 245 int number_polling_attempts_left_; |
241 | 246 |
247 // Used to post delayed tasks to ourselves that we can cancel. | |
henrika (OOO until Aug 14)
2011/12/07 10:08:34
Can you add some more details on why you had to in
tommi (sloooow) - chröme
2011/12/07 12:26:44
Improved comment.
| |
248 base::WeakPtrFactory<AudioOutputController> weak_this_; | |
249 | |
242 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 250 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
243 }; | 251 }; |
244 | 252 |
245 } // namespace media | 253 } // namespace media |
246 | 254 |
247 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 255 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |