Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: media/audio/audio_output_dispatcher.h

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 base class that dispatches
6 // deletion of audio output streams. AudioOutputProxy objects use this class to 6 // creation and deletion of audio output streams. AudioOutputProxy objects use
7 // allocate and recycle actual audio output streams. When playback is started, 7 // this class to allocate and recycle actual audio output streams. When playback
8 // the proxy calls StreamStarted() to get an output stream that it uses to play 8 // is started, the proxy calls StreamStarted() to get an output stream that it
9 // audio. When playback is stopped, the proxy returns the stream back to the 9 // uses to play audio. When playback is stopped, the proxy returns the stream
10 // dispatcher by calling StreamStopped(). 10 // back to the dispatcher by calling StreamStopped().
11 // 11 //
12 // To avoid opening and closing audio devices more frequently than necessary, 12 // AudioManagerBase creates one specialization of AudioOutputDispatcher on the
13 // each dispatcher has a pool of inactive physical streams. A stream is closed 13 // audio thread for each possible set of audio parameters. I.e streams with
14 // only if it hasn't been used for a certain period of time (specified via the 14 // different parameters are managed independently. The AudioOutputDispatcher
15 // constructor). 15 // instance is then deleted on the audio thread when the AudioManager shuts
16 // 16 // down.
17 // AudioManagerBase creates one AudioOutputDispatcher on the audio thread for
18 // each possible set of audio parameters. I.e streams with different parameters
19 // are managed independently. The AudioOutputDispatcher instance is then
20 // deleted on the audio thread when the AudioManager shuts down.
21 17
22 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 18 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
23 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 19 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
24 20
25 #include <vector> 21 #include <vector>
26 #include <list> 22 #include <list>
27 23
28 #include "base/basictypes.h" 24 #include "base/basictypes.h"
29 #include "base/memory/ref_counted.h" 25 #include "base/memory/ref_counted.h"
30 #include "base/memory/weak_ptr.h"
31 #include "base/timer.h" 26 #include "base/timer.h"
27 #include "media/audio/audio_io.h"
32 #include "media/audio/audio_manager.h" 28 #include "media/audio/audio_manager.h"
33 #include "media/audio/audio_parameters.h" 29 #include "media/audio/audio_parameters.h"
34 30
35 class AudioOutputStream; 31 class AudioOutputProxy;
36 class MessageLoop; 32 class MessageLoop;
37 33
38 class MEDIA_EXPORT AudioOutputDispatcher 34 class MEDIA_EXPORT AudioOutputDispatcher
39 : public base::RefCountedThreadSafe<AudioOutputDispatcher> { 35 : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
40 public: 36 public:
41 // |close_delay_ms| specifies delay after the stream is paused until
42 // the audio device is closed.
43 AudioOutputDispatcher(AudioManager* audio_manager, 37 AudioOutputDispatcher(AudioManager* audio_manager,
44 const AudioParameters& params, 38 const AudioParameters& params);
45 base::TimeDelta close_delay);
46 ~AudioOutputDispatcher();
47 39
48 // Called by AudioOutputProxy when the stream is closed. Opens a new 40 // Called by AudioOutputProxy when the stream is opened.
49 // physical stream if there are no pending streams in |idle_streams_|.
50 // Returns false, if it fails to open it. 41 // Returns false, if it fails to open it.
51 bool StreamOpened(); 42 virtual bool StreamOpened() = 0;
tommi (sloooow) - chröme 2012/04/03 13:47:51 Can you change this method name to OpenStream. As
enal1 2012/04/04 18:46:55 Done.
52 43
53 // Called by AudioOutputProxy when the stream is started. If there 44 // Called by AudioOutputProxy when the stream is started.
54 // are pending streams in |idle_streams_| then it returns one of them, 45 // Ownership of the result is passed to the caller.
55 // otherwise creates a new one. Returns a physical stream that must 46 virtual AudioOutputStream* StreamStarted(
56 // be used, or NULL if it fails to open audio device. Ownership of 47 AudioOutputStream::AudioSourceCallback* callback,
tommi (sloooow) - chröme 2012/04/03 13:47:51 add documentation for the new parameters
enal1 2012/04/04 18:46:55 Done.
57 // the result is passed to the caller. 48 AudioOutputProxy* stream_proxy) = 0;
58 AudioOutputStream* StreamStarted();
59 49
60 // Called by AudioOutputProxy when the stream is stopped. Holds the 50 // Called by AudioOutputProxy when the stream is stopped.
61 // stream temporarily in |pausing_streams_| and then |stream| is
62 // added to the pool of pending streams (i.e. |idle_streams_|).
63 // Ownership of the |stream| is passed to the dispatcher. 51 // Ownership of the |stream| is passed to the dispatcher.
64 void StreamStopped(AudioOutputStream* stream); 52 virtual void StreamStopped(AudioOutputStream* physical_stream,
tommi (sloooow) - chröme 2012/04/03 13:47:51 documentation for the parameters
enal1 2012/04/04 18:46:55 Done.
53 AudioOutputProxy* stream_proxy) = 0;
54
55
56 // Called by AudioOutputProxy when the volume is set.
57 virtual void StreamVolumeSet(AudioOutputStream* physical_stream,
58 double volume) = 0;
65 59
66 // Called by AudioOutputProxy when the stream is closed. 60 // Called by AudioOutputProxy when the stream is closed.
67 void StreamClosed(); 61 virtual void StreamClosed(AudioOutputProxy* stream_proxy) = 0;
68 62
69 // Called on the audio thread when the AudioManager is shutting down. 63 // Called on the audio thread when the AudioManager is shutting down.
70 void Shutdown(); 64 virtual void Shutdown() = 0;
71 65
72 private: 66 protected:
73 friend class AudioOutputProxyTest; 67 friend class base::RefCountedThreadSafe<AudioOutputDispatcher>;
74 68 ~AudioOutputDispatcher();
75 // Creates a new physical output stream, opens it and pushes to
76 // |idle_streams_|. Returns false if the stream couldn't be created or
77 // opened.
78 bool CreateAndOpenStream();
79
80 // A task scheduled by StreamStarted(). Opens a new stream and puts
81 // it in |idle_streams_|.
82 void OpenTask();
83
84 // Before a stream is reused, it should sit idle for a bit. This task is
85 // called once that time has elapsed.
86 void StopStreamTask();
87
88 // Called by |close_timer_|. Closes all pending stream.
89 void ClosePendingStreams();
90 69
91 // A no-reference-held pointer (we don't want circular references) back to the 70 // A no-reference-held pointer (we don't want circular references) back to the
92 // AudioManager that owns this object. 71 // AudioManager that owns this object.
93 AudioManager* audio_manager_; 72 AudioManager* audio_manager_;
94 MessageLoop* message_loop_; 73 MessageLoop* message_loop_;
95 AudioParameters params_; 74 AudioParameters params_;
96 75
97 base::TimeDelta pause_delay_; 76 private:
98 size_t paused_proxies_;
99 typedef std::list<AudioOutputStream*> AudioOutputStreamList;
100 AudioOutputStreamList idle_streams_;
101 AudioOutputStreamList pausing_streams_;
102
103 // Used to post delayed tasks to ourselves that we cancel inside Shutdown().
104 base::WeakPtrFactory<AudioOutputDispatcher> weak_this_;
105 base::DelayTimer<AudioOutputDispatcher> close_timer_;
106
107 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); 77 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
108 }; 78 };
109 79
110 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ 80 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698