Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 creates an AudioSourceCallback to | |
| 161 // provide audio data to some other destination. The given object will always | |
| 162 // return data when OnMoreData() is invoked, even if the underlying | |
| 163 // implementation is paused/stopped. AudioOutputController retains ownership | |
| 164 // of the returned object. | |
| 165 AudioOutputStream::AudioSourceCallback* Divert(); | |
|
DaleCurtis
2012/12/05 23:35:14
Hmm, this is odd since AudioOutputController is ge
miu
2012/12/11 02:30:45
It's a pull model, not a push model (the AudioSour
| |
| 166 | |
| 167 // Restores normal audio output behavior for the current playback state. | |
| 168 // |asc| is the pointer returned by the previous call to Divert() and becomes | |
| 169 // invalid once this method is called. | |
| 170 void Revert(AudioOutputStream::AudioSourceCallback* asc); | |
| 171 | |
| 157 protected: | 172 protected: |
| 158 // Internal state of the source. | 173 // Internal state of the source. |
| 159 enum State { | 174 enum State { |
| 160 kEmpty, | 175 kEmpty, |
| 161 kCreated, | 176 kCreated, |
| 162 kPlaying, | 177 kPlaying, |
| 163 kStarting, | 178 kStarting, |
| 164 kPausedWhenStarting, | 179 kPausedWhenStarting, |
| 165 kPaused, | 180 kPaused, |
| 166 kClosed, | 181 kClosed, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 189 void DoSetVolume(double volume); | 204 void DoSetVolume(double volume); |
| 190 void DoReportError(int code); | 205 void DoReportError(int code); |
| 191 | 206 |
| 192 // Helper method that starts physical stream. | 207 // Helper method that starts physical stream. |
| 193 void StartStream(); | 208 void StartStream(); |
| 194 | 209 |
| 195 // Helper method that stops, closes, and NULLs |*stream_|. | 210 // Helper method that stops, closes, and NULLs |*stream_|. |
| 196 // Signals event when done if it is not NULL. | 211 // Signals event when done if it is not NULL. |
| 197 void DoStopCloseAndClearStream(base::WaitableEvent *done); | 212 void DoStopCloseAndClearStream(base::WaitableEvent *done); |
| 198 | 213 |
| 199 AudioManager* audio_manager_; | 214 AudioManager* const audio_manager_; |
| 215 const AudioParameters params_; | |
| 200 | 216 |
| 201 // |handler_| may be called only if |state_| is not kClosed. | 217 // |handler_| may be called only if |state_| is not kClosed. |
| 202 EventHandler* handler_; | 218 EventHandler* handler_; |
| 219 | |
| 220 // AudioManager-owned stream. Note that this could be NULL during state | |
| 221 // kCreated, kPlaying, etc.; if audio is currently being diverted. | |
| 203 AudioOutputStream* stream_; | 222 AudioOutputStream* stream_; |
| 204 | 223 |
| 205 // The current volume of the audio stream. | 224 // The current volume of the audio stream. |
| 206 double volume_; | 225 double volume_; |
| 207 | 226 |
| 208 // |state_| is written on the audio manager thread and is read on the | 227 // |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 | 228 // hardware audio thread. These operations need to be locked. But lock |
| 210 // is not required for reading on the audio manager thread. | 229 // is not required for reading on the audio manager thread. |
| 211 State state_; | 230 State state_; |
| 212 | 231 |
| 213 // The |lock_| must be acquired whenever we access |state_| from a thread | 232 // The |lock_| must be acquired whenever we access |state_| from a thread |
| 214 // other than the audio manager thread. | 233 // other than the audio manager thread. |
| 215 base::Lock lock_; | 234 base::Lock lock_; |
| 216 | 235 |
| 217 // SyncReader is used only in low latency mode for synchronous reading. | 236 // SyncReader is used only in low latency mode for synchronous reading. |
| 218 SyncReader* sync_reader_; | 237 SyncReader* sync_reader_; |
| 219 | 238 |
| 220 // The message loop of audio manager thread that this object runs on. | 239 // The message loop of audio manager thread that this object runs on. |
| 221 scoped_refptr<base::MessageLoopProxy> message_loop_; | 240 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 222 | 241 |
| 223 // When starting stream we wait for data to become available. | 242 // When starting stream we wait for data to become available. |
| 224 // Number of times left. | 243 // Number of times left. |
| 225 int number_polling_attempts_left_; | 244 int number_polling_attempts_left_; |
| 226 | 245 |
| 227 AudioParameters params_; | |
| 228 | |
| 229 // Used to post delayed tasks to ourselves that we can cancel. | 246 // 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 | 247 // 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. | 248 // 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. | 249 // Also, if we're shutting down, we do not want to poll for more data. |
| 233 base::WeakPtrFactory<AudioOutputController> weak_this_; | 250 base::WeakPtrFactory<AudioOutputController> weak_this_; |
| 234 | 251 |
| 235 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 252 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
| 236 }; | 253 }; |
| 237 | 254 |
| 238 } // namespace media | 255 } // namespace media |
| 239 | 256 |
| 240 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 257 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
| OLD | NEW |