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

Unified Diff: media/audio/audio_output_dispatcher_impl.h

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_output_dispatcher_impl.h
===================================================================
--- media/audio/audio_output_dispatcher_impl.h (revision 0)
+++ media/audio/audio_output_dispatcher_impl.h (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (c) 2012 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.
+
+// AudioOutputDispatcherImpl is an implementation of AudioOutputDispatcher.
+//
+// To avoid opening and closing audio devices more frequently than necessary,
+// 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 via the
+// constructor).
+//
+
+#ifndef MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_
+#define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_
+
+#include <list>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/timer.h"
+#include "media/audio/audio_io.h"
+#include "media/audio/audio_manager.h"
+#include "media/audio/audio_output_dispatcher.h"
+#include "media/audio/audio_parameters.h"
+
+class AudioOutputProxy;
+class MessageLoop;
+
+class MEDIA_EXPORT AudioOutputDispatcherImpl
+ : public AudioOutputDispatcher {
+ public:
+ // |close_delay_ms| specifies delay after the stream is paused until
+ // the audio device is closed.
+ AudioOutputDispatcherImpl(AudioManager* audio_manager,
+ const AudioParameters& params,
+ base::TimeDelta close_delay);
tommi (sloooow) - chröme 2012/04/03 13:47:51 const &
enal1 2012/04/04 18:46:55 Done.
+
+ // Opens a new physical stream if there are no pending streams in
+ // |idle_streams_|.
+ virtual bool StreamOpened() OVERRIDE;
+
+ // If there are pending streams in |idle_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.
+ virtual AudioOutputStream* StreamStarted(
+ AudioOutputStream::AudioSourceCallback* callback,
+ AudioOutputProxy* stream_proxy) OVERRIDE;
+
+ // Holds the stream temporarily in |pausing_streams_| and then |stream| is
+ // added to the pool of pending streams (i.e. |idle_streams_|).
+ virtual void StreamStopped(AudioOutputStream* physical_stream,
+ AudioOutputProxy* stream_proxy) OVERRIDE;
+
+ virtual void StreamVolumeSet(AudioOutputStream* physical_stream,
+ double volume) OVERRIDE;
+
+ virtual void StreamClosed(AudioOutputProxy* stream_proxy) OVERRIDE;
+
+ virtual void Shutdown() OVERRIDE;
+
+ private:
+ friend class base::RefCountedThreadSafe<AudioOutputDispatcherImpl>;
+ ~AudioOutputDispatcherImpl();
tommi (sloooow) - chröme 2012/04/03 13:47:51 virtual?
enal1 2012/04/04 18:46:55 Done.
+
+ friend class AudioOutputProxyTest;
+
+ // Creates a new physical output stream, opens it and pushes to
+ // |idle_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 |idle_streams_|.
+ void OpenTask();
+
+ // Before a stream is reused, it should sit idle for a bit. This task is
+ // called once that time has elapsed.
+ void StopStreamTask();
+
+ // Called by |close_timer_|. Closes all pending streams.
+ void ClosePendingStreams();
+
+ base::TimeDelta pause_delay_;
+ size_t paused_proxies_;
+ typedef std::list<AudioOutputStream*> AudioOutputStreamList;
+ AudioOutputStreamList idle_streams_;
+ AudioOutputStreamList pausing_streams_;
+
+ // Used to post delayed tasks to ourselves that we cancel inside Shutdown().
+ base::WeakPtrFactory<AudioOutputDispatcherImpl> weak_this_;
+ base::DelayTimer<AudioOutputDispatcherImpl> close_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcherImpl);
+};
+
+#endif // MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698