OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // AudioOutputDispatcherImpl is an implementation of AudioOutputDispatcher. | |
6 // | |
7 // To avoid opening and closing audio devices more frequently than necessary, | |
8 // each dispatcher has a pool of inactive physical streams. A stream is closed | |
9 // only if it hasn't been used for a certain period of time (specified via the | |
10 // constructor). | |
11 // | |
12 | |
13 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ | |
14 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ | |
15 | |
16 #include <list> | |
17 | |
18 #include "base/basictypes.h" | |
19 #include "base/memory/ref_counted.h" | |
20 #include "base/memory/weak_ptr.h" | |
21 #include "base/timer.h" | |
22 #include "media/audio/audio_io.h" | |
23 #include "media/audio/audio_manager.h" | |
24 #include "media/audio/audio_output_dispatcher.h" | |
25 #include "media/audio/audio_parameters.h" | |
26 | |
27 class AudioOutputProxy; | |
28 class MessageLoop; | |
29 | |
30 class MEDIA_EXPORT AudioOutputDispatcherImpl | |
31 : public AudioOutputDispatcher { | |
32 public: | |
33 // |close_delay_ms| specifies delay after the stream is paused until | |
34 // the audio device is closed. | |
35 AudioOutputDispatcherImpl(AudioManager* audio_manager, | |
36 const AudioParameters& params, | |
37 base::TimeDelta close_delay); | |
tommi (sloooow) - chröme
2012/04/03 13:47:51
const &
enal1
2012/04/04 18:46:55
Done.
| |
38 | |
39 // Opens a new physical stream if there are no pending streams in | |
40 // |idle_streams_|. | |
41 virtual bool StreamOpened() OVERRIDE; | |
42 | |
43 // If there are pending streams in |idle_streams_| then it returns one of | |
44 // them, otherwise creates a new one. Returns a physical stream that must | |
45 // be used, or NULL if it fails to open audio device. | |
46 virtual AudioOutputStream* StreamStarted( | |
47 AudioOutputStream::AudioSourceCallback* callback, | |
48 AudioOutputProxy* stream_proxy) OVERRIDE; | |
49 | |
50 // Holds the stream temporarily in |pausing_streams_| and then |stream| is | |
51 // added to the pool of pending streams (i.e. |idle_streams_|). | |
52 virtual void StreamStopped(AudioOutputStream* physical_stream, | |
53 AudioOutputProxy* stream_proxy) OVERRIDE; | |
54 | |
55 virtual void StreamVolumeSet(AudioOutputStream* physical_stream, | |
56 double volume) OVERRIDE; | |
57 | |
58 virtual void StreamClosed(AudioOutputProxy* stream_proxy) OVERRIDE; | |
59 | |
60 virtual void Shutdown() OVERRIDE; | |
61 | |
62 private: | |
63 friend class base::RefCountedThreadSafe<AudioOutputDispatcherImpl>; | |
64 ~AudioOutputDispatcherImpl(); | |
tommi (sloooow) - chröme
2012/04/03 13:47:51
virtual?
enal1
2012/04/04 18:46:55
Done.
| |
65 | |
66 friend class AudioOutputProxyTest; | |
67 | |
68 // Creates a new physical output stream, opens it and pushes to | |
69 // |idle_streams_|. Returns false if the stream couldn't be created or | |
70 // opened. | |
71 bool CreateAndOpenStream(); | |
72 | |
73 // A task scheduled by StreamStarted(). Opens a new stream and puts | |
74 // it in |idle_streams_|. | |
75 void OpenTask(); | |
76 | |
77 // Before a stream is reused, it should sit idle for a bit. This task is | |
78 // called once that time has elapsed. | |
79 void StopStreamTask(); | |
80 | |
81 // Called by |close_timer_|. Closes all pending streams. | |
82 void ClosePendingStreams(); | |
83 | |
84 base::TimeDelta pause_delay_; | |
85 size_t paused_proxies_; | |
86 typedef std::list<AudioOutputStream*> AudioOutputStreamList; | |
87 AudioOutputStreamList idle_streams_; | |
88 AudioOutputStreamList pausing_streams_; | |
89 | |
90 // Used to post delayed tasks to ourselves that we cancel inside Shutdown(). | |
91 base::WeakPtrFactory<AudioOutputDispatcherImpl> weak_this_; | |
92 base::DelayTimer<AudioOutputDispatcherImpl> close_timer_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl); | |
95 }; | |
96 | |
97 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_ | |
OLD | NEW |