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 // AudioOutputDispatcher is a single-threaded class that dispatches creation and | 5 // AudioOutputDispatcher is a single-threaded class that dispatches creation and |
6 // deletion of audio output streams. AudioOutputProxy objects use this class to | 6 // deletion of audio output streams. AudioOutputProxy objects use this class to |
7 // allocate and recycle actual audio output streams. When playback is started, | 7 // allocate and recycle actual audio output streams. When playback is started, |
8 // the proxy calls StreamStarted() to get an output stream that it uses to play | 8 // the proxy calls StreamStarted() to get an output stream that it uses to play |
9 // audio. When playback is stopped, the proxy returns the stream back to the | 9 // audio. When playback is stopped, the proxy returns the stream back to the |
10 // dispatcher by calling StreamStopped(). | 10 // dispatcher by calling StreamStopped(). |
(...skipping 28 matching lines...) Expand all Loading... | |
39 class AudioOutputStream; | 39 class AudioOutputStream; |
40 | 40 |
41 class MEDIA_EXPORT AudioOutputDispatcher | 41 class MEDIA_EXPORT AudioOutputDispatcher |
42 : public base::RefCountedThreadSafe<AudioOutputDispatcher> { | 42 : public base::RefCountedThreadSafe<AudioOutputDispatcher> { |
43 public: | 43 public: |
44 // |close_delay_ms| specifies delay after the stream is paused until | 44 // |close_delay_ms| specifies delay after the stream is paused until |
45 // the audio device is closed. | 45 // the audio device is closed. |
46 AudioOutputDispatcher(AudioManager* audio_manager, | 46 AudioOutputDispatcher(AudioManager* audio_manager, |
47 const AudioParameters& params, | 47 const AudioParameters& params, |
48 base::TimeDelta close_delay); | 48 base::TimeDelta close_delay); |
49 ~AudioOutputDispatcher(); | |
50 | 49 |
51 // Called by AudioOutputProxy when the stream is closed. Opens a new | 50 // Called by AudioOutputProxy when the stream is closed. Opens a new |
52 // physical stream if there are no pending streams in |idle_streams_|. | 51 // physical stream if there are no pending streams in |idle_streams_|. |
53 // Returns false, if it fails to open it. | 52 // Returns false, if it fails to open it. |
54 bool StreamOpened(); | 53 bool StreamOpened(); |
55 | 54 |
56 // Called by AudioOutputProxy when the stream is started. If there | 55 // Called by AudioOutputProxy when the stream is started. If there |
57 // are pending streams in |idle_streams_| then it returns one of them, | 56 // are pending streams in |idle_streams_| then it returns one of them, |
58 // otherwise creates a new one. Returns a physical stream that must | 57 // otherwise creates a new one. Returns a physical stream that must |
59 // be used, or NULL if it fails to open audio device. Ownership of | 58 // be used, or NULL if it fails to open audio device. Ownership of |
60 // the result is passed to the caller. | 59 // the result is passed to the caller. |
61 AudioOutputStream* StreamStarted(); | 60 AudioOutputStream* StreamStarted(); |
62 | 61 |
63 // Called by AudioOutputProxy when the stream is stopped. Holds the | 62 // Called by AudioOutputProxy when the stream is stopped. Holds the |
64 // stream temporarily in |pausing_streams_| and then |stream| is | 63 // stream temporarily in |pausing_streams_| and then |stream| is |
65 // added to the pool of pending streams (i.e. |idle_streams_|). | 64 // added to the pool of pending streams (i.e. |idle_streams_|). |
66 // Ownership of the |stream| is passed to the dispatcher. | 65 // Ownership of the |stream| is passed to the dispatcher. |
67 void StreamStopped(AudioOutputStream* stream); | 66 void StreamStopped(AudioOutputStream* stream); |
68 | 67 |
69 // Called by AudioOutputProxy when the stream is closed. | 68 // Called by AudioOutputProxy when the stream is closed. |
70 void StreamClosed(); | 69 void StreamClosed(); |
71 | 70 |
72 // Called on the audio thread when the AudioManager is shutting down. | 71 // Called on the audio thread when the AudioManager is shutting down. |
73 void Shutdown(); | 72 void Shutdown(); |
74 | 73 |
75 private: | 74 private: |
75 friend base::RefCountedThreadSafe<AudioOutputDispatcher>; | |
76 friend class AudioOutputProxyTest; | 76 friend class AudioOutputProxyTest; |
77 ~AudioOutputDispatcher(); | |
scherkus (not reviewing)
2012/04/13 18:06:53
+virtual
| |
77 | 78 |
78 // Creates a new physical output stream, opens it and pushes to | 79 // Creates a new physical output stream, opens it and pushes to |
79 // |idle_streams_|. Returns false if the stream couldn't be created or | 80 // |idle_streams_|. Returns false if the stream couldn't be created or |
80 // opened. | 81 // opened. |
81 bool CreateAndOpenStream(); | 82 bool CreateAndOpenStream(); |
82 | 83 |
83 // A task scheduled by StreamStarted(). Opens a new stream and puts | 84 // A task scheduled by StreamStarted(). Opens a new stream and puts |
84 // it in |idle_streams_|. | 85 // it in |idle_streams_|. |
85 void OpenTask(); | 86 void OpenTask(); |
86 | 87 |
(...skipping 19 matching lines...) Expand all Loading... | |
106 // Used to post delayed tasks to ourselves that we cancel inside Shutdown(). | 107 // Used to post delayed tasks to ourselves that we cancel inside Shutdown(). |
107 base::WeakPtrFactory<AudioOutputDispatcher> weak_this_; | 108 base::WeakPtrFactory<AudioOutputDispatcher> weak_this_; |
108 base::DelayTimer<AudioOutputDispatcher> close_timer_; | 109 base::DelayTimer<AudioOutputDispatcher> close_timer_; |
109 | 110 |
110 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); | 111 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); |
111 }; | 112 }; |
112 | 113 |
113 } // namespace media | 114 } // namespace media |
114 | 115 |
115 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ | 116 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ |
OLD | NEW |