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

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

Issue 5158003: Implement AudioOutputProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed memleak in the unittests Created 10 years, 1 month 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
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | media/audio/audio_output_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 // AudioOutputDispatcher dispatches creation and deletion of audio
6 // output streams. AudioOutputProxy objects use this class to allocate
7 // and recycle actual audio output streams. When playback is started,
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
10 // the stream back to the dispatcher by calling StreamStopped().
11 //
12 // To avoid opening and closing audio devices more frequently than it
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
15 // certain period of time (specified in the constructor).
16 //
17 // AudioManagerBase creates one AudioOutputDispatcher per each
18 // possible set of audio parameters, i.e. streams with different
19 // parameters are managed independently.
20
21 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
22 #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
23
24 #include <vector>
25
26 #include "base/basictypes.h"
27 #include "base/ref_counted.h"
28 #include "base/timer.h"
29 #include "media/audio/audio_manager.h"
30 #include "media/audio/audio_parameters.h"
31
32 class AudioOutputStream;
33 class MessageLoop;
34
35 class AudioOutputDispatcher
36 : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
37 public:
38 // |close_delay_ms| specifies delay after the stream is paused until
39 // the audio device is closed.
40 AudioOutputDispatcher(AudioManager* audio_manager,
41 const AudioParameters& params,
42 int close_delay_ms);
43 ~AudioOutputDispatcher();
44
45 // Called by AudioOutputProxy when the stream is closed. Opens a new
46 // physical stream if there are no pending streams in |streams_|.
47 // Returns false, if it fails to open it.
48 bool StreamOpened();
49
50 // Called by AudioOutputProxy when the stream is started. If there
51 // are pending streams in |streams_| then it returns one of them,
52 // otherwise creates a new one. Returns a physical stream that must
53 // be used, or NULL if it fails to open audio device. Ownership of
54 // the result is passed to the caller.
55 AudioOutputStream* StreamStarted();
56
57 // Called by AudioOutputProxy when the stream is stopped. Returns
58 // |stream| to the pool of pending streams (i.e. |streams_|).
59 // Ownership of the |stream| is passed to the dispatcher.
60 void StreamStopped(AudioOutputStream* stream);
61
62 // Called by AudioOutputProxy when the stream is closed.
63 void StreamClosed();
64
65 MessageLoop* message_loop();
66
67 private:
68 friend class AudioOutputProxyTest;
69
70 // Creates a new physical output stream, opens it and pushes to
71 // |streams_|. Returns false if the stream couldn't be created or
72 // opened.
73 bool CreateAndOpenStream();
74
75 // A task scheduled by StreamStarted(). Opens a new stream and puts
76 // it in |streams_|.
77 void OpenTask();
78
79 // Called by |close_timer_|. Closes all pending stream.
80 void ClosePendingStreams();
81
82 AudioManager* audio_manager_;
83 MessageLoop* message_loop_;
84 AudioParameters params_;
85
86 size_t paused_proxies_;
87 std::vector<AudioOutputStream*> streams_;
88 base::DelayTimer<AudioOutputDispatcher> close_timer_;
89
90 DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
91 };
92
93 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
OLDNEW
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | media/audio/audio_output_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698