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 // AudioOutputDispatcher dispatches creation and deletion of audio | 5 // AudioOutputDispatcher dispatches creation and deletion of audio |
6 // output streams. AudioOutputProxy objects use this class to allocate | 6 // output streams. AudioOutputProxy objects use this class to allocate |
7 // and recycle actual audio output streams. When playback is started, | 7 // and recycle actual audio output streams. When playback is started, |
8 // the proxy calls StreamStarted() to get an output stream that it | 8 // the proxy calls StreamStarted() to get an output stream that it |
9 // uses to play the sound. When playback is stopped, the proxy returns | 9 // uses to play the sound. When playback is stopped, the proxy returns |
10 // the stream back to the dispatcher by calling StreamStopped(). | 10 // the stream back to the dispatcher by calling StreamStopped(). |
11 // | 11 // |
12 // To avoid opening and closing audio devices more frequently than it | 12 // To avoid opening and closing audio devices more frequently than it |
13 // is neccessary, each dispatcher has a pool of inactive physical | 13 // is neccessary, each dispatcher has a pool of inactive physical |
14 // streams. A stream is closed only if it hasn't been used for a | 14 // streams. A stream is closed only if it hasn't been used for a |
15 // certain period of time (specified in the constructor). | 15 // certain period of time (specified in the constructor). |
16 // | 16 // |
17 // AudioManagerBase creates one AudioOutputDispatcher per each | 17 // AudioManagerBase creates one AudioOutputDispatcher per each |
18 // possible set of audio parameters, i.e. streams with different | 18 // possible set of audio parameters, i.e. streams with different |
19 // parameters are managed independently. | 19 // parameters are managed independently. |
20 | 20 |
21 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ | 21 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ |
22 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ | 22 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ |
23 | 23 |
24 #include <vector> | 24 #include <vector> |
25 #include <list> | 25 #include <list> |
26 | 26 |
27 #include "base/basictypes.h" | 27 #include "base/basictypes.h" |
28 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
29 #include "base/memory/weak_ptr.h" | |
29 #include "base/timer.h" | 30 #include "base/timer.h" |
30 #include "media/audio/audio_manager.h" | 31 #include "media/audio/audio_manager.h" |
31 #include "media/audio/audio_parameters.h" | 32 #include "media/audio/audio_parameters.h" |
32 | 33 |
33 class AudioOutputStream; | 34 class AudioOutputStream; |
34 class MessageLoop; | 35 class MessageLoop; |
35 | 36 |
36 class MEDIA_EXPORT AudioOutputDispatcher | 37 class MEDIA_EXPORT AudioOutputDispatcher |
37 : public base::RefCountedThreadSafe<AudioOutputDispatcher> { | 38 : public base::RefCountedThreadSafe<AudioOutputDispatcher> { |
38 public: | 39 public: |
(...skipping 18 matching lines...) Expand all Loading... | |
57 | 58 |
58 // Called by AudioOutputProxy when the stream is stopped. Holds the | 59 // Called by AudioOutputProxy when the stream is stopped. Holds the |
59 // stream temporarily in |pausing_streams_| and then |stream| is | 60 // stream temporarily in |pausing_streams_| and then |stream| is |
60 // added to the pool of pending streams (i.e. |idle_streams_|). | 61 // added to the pool of pending streams (i.e. |idle_streams_|). |
61 // Ownership of the |stream| is passed to the dispatcher. | 62 // Ownership of the |stream| is passed to the dispatcher. |
62 void StreamStopped(AudioOutputStream* stream); | 63 void StreamStopped(AudioOutputStream* stream); |
63 | 64 |
64 // Called by AudioOutputProxy when the stream is closed. | 65 // Called by AudioOutputProxy when the stream is closed. |
65 void StreamClosed(); | 66 void StreamClosed(); |
66 | 67 |
68 // Called on the audio thread when the AudioManager is shutting down. | |
69 void Shutdown(); | |
70 | |
67 MessageLoop* message_loop(); | 71 MessageLoop* message_loop(); |
68 | 72 |
69 private: | 73 private: |
70 friend class AudioOutputProxyTest; | 74 friend class AudioOutputProxyTest; |
71 | 75 |
72 // Creates a new physical output stream, opens it and pushes to | 76 // Creates a new physical output stream, opens it and pushes to |
73 // |idle_streams_|. Returns false if the stream couldn't be created or | 77 // |idle_streams_|. Returns false if the stream couldn't be created or |
74 // opened. | 78 // opened. |
75 bool CreateAndOpenStream(); | 79 bool CreateAndOpenStream(); |
76 | 80 |
77 // A task scheduled by StreamStarted(). Opens a new stream and puts | 81 // A task scheduled by StreamStarted(). Opens a new stream and puts |
78 // it in |idle_streams_|. | 82 // it in |idle_streams_|. |
79 void OpenTask(); | 83 void OpenTask(); |
80 | 84 |
81 // Before a stream is reused, it should sit idle for a bit. This task is | 85 // Before a stream is reused, it should sit idle for a bit. This task is |
82 // called once that time has elapsed. | 86 // called once that time has elapsed. |
83 void StopStreamTask(); | 87 void StopStreamTask(); |
84 | 88 |
85 // Called by |close_timer_|. Closes all pending stream. | 89 // Called by |close_timer_|. Closes all pending stream. |
86 void ClosePendingStreams(); | 90 void ClosePendingStreams(); |
87 | 91 |
88 AudioManager* audio_manager_; | 92 AudioManager* audio_manager_; |
89 MessageLoop* message_loop_; | 93 MessageLoop* message_loop_; |
90 AudioParameters params_; | 94 AudioParameters params_; |
91 | 95 |
92 int64 pause_delay_milliseconds_; | 96 int64 pause_delay_milliseconds_; |
93 size_t paused_proxies_; | 97 size_t paused_proxies_; |
94 std::vector<AudioOutputStream*> idle_streams_; | 98 typedef std::list<AudioOutputStream*> AudioOutputStreamList; |
95 std::list<AudioOutputStream*> pausing_streams_; | 99 AudioOutputStreamList idle_streams_; |
100 AudioOutputStreamList pausing_streams_; | |
101 // Used to post delayed tasks to ourselves that we can cancel. | |
henrika (OOO until Aug 14)
2011/12/07 10:08:34
Nit, empty line above comment.
tommi (sloooow) - chröme
2011/12/07 12:26:44
Done.
| |
102 base::WeakPtrFactory<AudioOutputDispatcher> weak_this_; | |
96 base::DelayTimer<AudioOutputDispatcher> close_timer_; | 103 base::DelayTimer<AudioOutputDispatcher> close_timer_; |
97 | 104 |
98 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); | 105 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); |
99 }; | 106 }; |
100 | 107 |
101 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ | 108 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ |
OLD | NEW |