diff options
author | davej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-14 23:34:00 +0000 |
---|---|---|
committer | davej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-14 23:34:00 +0000 |
commit | 4841a4bde07696cad73224a0c7e28ea9343c9e1c (patch) | |
tree | 5750fda34ee1ed66d1a17b5e78bed0cf0630ba22 /media/audio/audio_output_dispatcher.h | |
parent | fb930c854c9d3d984411eb6be45242af793943b3 (diff) | |
download | chromium_src-4841a4bde07696cad73224a0c7e28ea9343c9e1c.zip chromium_src-4841a4bde07696cad73224a0c7e28ea9343c9e1c.tar.gz chromium_src-4841a4bde07696cad73224a0c7e28ea9343c9e1c.tar.bz2 |
Fix erratic HTML5 audio playback
This was affecting all platforms. The major issue was that he SetPlaybackRate(1) which is used to start playback was being done in the middle of the series of Seek operations. So doing Seek() followed by SetPlaybackRate(1) was done, the Seek could immediately stop the playback. To fix, Seek() was made atomic with regards to SetPlaybackRate() by delaying the execution of SetPlaybackRate until after the Seek sequence has completely finished.
To make things run even smoother, a short delay was added before recyclilng a used audio stream in the Dispatcher. This gives the stream time to 'power down' before being reused.
Tested on Linux, Chrome-OS (Cr48) and Mac with great results, making HTML5 audio much more usable for games.
BUG=73045,59369,59370,65618
TEST=Manual, Quickly playing/stopping HTML5 audio should play cleanly.
Review URL: http://codereview.chromium.org/6822019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_output_dispatcher.h')
-rw-r--r-- | media/audio/audio_output_dispatcher.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/media/audio/audio_output_dispatcher.h b/media/audio/audio_output_dispatcher.h index 2289e89..18e1b28 100644 --- a/media/audio/audio_output_dispatcher.h +++ b/media/audio/audio_output_dispatcher.h @@ -22,6 +22,7 @@ #define MEDIA_AUDIO_AUDIO_OUTPUT_DISPATCHER_H_ #include <vector> +#include <list> #include "base/basictypes.h" #include "base/memory/ref_counted.h" @@ -43,19 +44,20 @@ class AudioOutputDispatcher ~AudioOutputDispatcher(); // Called by AudioOutputProxy when the stream is closed. Opens a new - // physical stream if there are no pending streams in |streams_|. + // physical stream if there are no pending streams in |idle_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, + // 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. 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_|). + // Called by AudioOutputProxy when the stream is stopped. Holds the + // stream temporarily in |pausing_streams_| and then |stream| is + // added to the pool of pending streams (i.e. |idle_streams_|). // Ownership of the |stream| is passed to the dispatcher. void StreamStopped(AudioOutputStream* stream); @@ -68,14 +70,18 @@ class AudioOutputDispatcher 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 + // |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 |streams_|. + // 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 stream. void ClosePendingStreams(); @@ -83,8 +89,10 @@ class AudioOutputDispatcher MessageLoop* message_loop_; AudioParameters params_; + int64 pause_delay_milliseconds_; size_t paused_proxies_; - std::vector<AudioOutputStream*> streams_; + std::vector<AudioOutputStream*> idle_streams_; + std::list<AudioOutputStream*> pausing_streams_; base::DelayTimer<AudioOutputDispatcher> close_timer_; DISALLOW_COPY_AND_ASSIGN(AudioOutputDispatcher); |