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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_output_controller.cc ('k') | media/audio/audio_output_dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_output_dispatcher.h
diff --git a/media/audio/audio_output_dispatcher.h b/media/audio/audio_output_dispatcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..0fa701094e0889be927ef01c6f82fb48d6ca5799
--- /dev/null
+++ b/media/audio/audio_output_dispatcher.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// AudioOutputDispatcher dispatches creation and deletion of audio
+// output streams. AudioOutputProxy objects use this class to allocate
+// and recycle actual audio output streams. When playback is started,
+// the proxy calls StreamStarted() to get an output stream that it
+// uses to play the sound. When playback is stopped, the proxy returns
+// the stream back to the dispatcher by calling StreamStopped().
+//
+// To avoid opening and closing audio devices more frequently than it
+// is neccessary, each dispatcher has a pool of inactive physical
+// streams. A stream is closed only if it hasn't been used for a
+// certain period of time (specified in the constructor).
+//
+// AudioManagerBase creates one AudioOutputDispatcher per each
+// possible set of audio parameters, i.e. streams with different
+// parameters are managed independently.
+
+#ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
+#define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/timer.h"
+#include "media/audio/audio_manager.h"
+#include "media/audio/audio_parameters.h"
+
+class AudioOutputStream;
+class MessageLoop;
+
+class AudioOutputDispatcher
+ : public base::RefCountedThreadSafe<AudioOutputDispatcher> {
+ public:
+ // |close_delay_ms| specifies delay after the stream is paused until
+ // the audio device is closed.
+ AudioOutputDispatcher(AudioManager* audio_manager,
+ const AudioParameters& params,
+ int close_delay_ms);
+ ~AudioOutputDispatcher();
+
+ // Called by AudioOutputProxy when the stream is closed. Opens a new
+ // physical stream if there are no pending streams in |streams_|.
+ // Returns false, if it fails to open it.
+ bool StreamOpened();
+
+ // Called by AudioOutputProxy when the stream is started. If there
+ // are pending streams in |streams_| then it returns one of them,
+ // otherwise creates a new one. Returns a physical stream that must
+ // be used, or NULL if it fails to open audio device. Ownership of
+ // the result is passed to the caller.
+ AudioOutputStream* StreamStarted();
+
+ // Called by AudioOutputProxy when the stream is stopped. Returns
+ // |stream| to the pool of pending streams (i.e. |streams_|).
+ // Ownership of the |stream| is passed to the dispatcher.
+ void StreamStopped(AudioOutputStream* stream);
+
+ // Called by AudioOutputProxy when the stream is closed.
+ void StreamClosed();
+
+ MessageLoop* message_loop();
+
+ private:
+ friend class AudioOutputProxyTest;
+
+ // Creates a new physical output stream, opens it and pushes to
+ // |streams_|. Returns false if the stream couldn't be created or
+ // opened.
+ bool CreateAndOpenStream();
+
+ // A task scheduled by StreamStarted(). Opens a new stream and puts
+ // it in |streams_|.
+ void OpenTask();
+
+ // Called by |close_timer_|. Closes all pending stream.
+ void ClosePendingStreams();
+
+ AudioManager* audio_manager_;
+ MessageLoop* message_loop_;
+ AudioParameters params_;
+
+ size_t paused_proxies_;
+ std::vector<AudioOutputStream*> streams_;
+ base::DelayTimer<AudioOutputDispatcher> close_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher);
+};
+
+#endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_
« 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