diff options
author | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-15 21:51:27 +0000 |
---|---|---|
committer | enal@chromium.org <enal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-15 21:51:27 +0000 |
commit | 06e639cdc5cf9b7d3e97c7d7c57920b56b4b6e17 (patch) | |
tree | 048f6ff41defac63e23924bc88b16a6fb439ed4b /ppapi | |
parent | d466b8a0b44ef89c81fa4ede86de1b488b8ec07d (diff) | |
download | chromium_src-06e639cdc5cf9b7d3e97c7d7c57920b56b4b6e17.zip chromium_src-06e639cdc5cf9b7d3e97c7d7c57920b56b4b6e17.tar.gz chromium_src-06e639cdc5cf9b7d3e97c7d7c57920b56b4b6e17.tar.bz2 |
Fix problem when 'ended' event was fired before stream really ended.
That caused impression that rewind does not work. With that
change small JS program
var a = new Audio("file:///home/enal/temp/click2/click2.wav");
var num_played = 0;
a.addEventListener('canplaythrough', function() {
a.play();
});
a.addEventListener('ended', function() {
num_played ++;
if (num_played < 10) {
a.currentTime = 0;
a.play();
}
});
works correctly, you hear 10 clicks one after another, and it takes
~1.5 seconds to play all 10 sounds (one click is 146ms). Current
Chrome plays only beginnings of the first 9 clicks and then entire
10th click -- 'ended' event fires too early, so rewind stops audio
playback for all clicks but last one.
With that fix you can easily create pool of audio objects -- on 'ended'
event just add audio object to the pool.
Fix consists of 3 parts:
1) For low-latency code path pass entire "audio state" object to the renderer
process. That allows renderer take into account number of pending bytes
in the buffer.
2) When using low-latency code path renderer not only fills the buffer with
data, but also writes length of data into first word of the buffer. That
allows host process to pass correct byte counts to renderer.
3) Renderer now keeps track of the earliest time playback can end based on the
number of rendered bytes, and will not call 'ended' callback till that time.
BUG=http://code.google.com/p/chromium/issues/detail?id=78992
http://codereview.chromium.org/7328030
Review URL: http://codereview.chromium.org/7328030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92749 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/ppapi_shared.gypi | 1 | ||||
-rw-r--r-- | ppapi/shared_impl/audio_impl.cc | 21 |
2 files changed, 13 insertions, 9 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index b86c77e..6a6b121 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -12,6 +12,7 @@ '../base/base.gyp:base', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../build/temp_gyp/googleurl.gyp:googleurl', + '../media/media.gyp:media', '../skia/skia.gyp:skia', '../third_party/icu/icu.gyp:icuuc', '../ui/gfx/surface/surface.gyp:surface', diff --git a/ppapi/shared_impl/audio_impl.cc b/ppapi/shared_impl/audio_impl.cc index 42254f5..c77dbc9 100644 --- a/ppapi/shared_impl/audio_impl.cc +++ b/ppapi/shared_impl/audio_impl.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ppapi/shared_impl/audio_impl.h" - #include "base/logging.h" +#include "media/audio/audio_buffers_state.h" +#include "media/audio/audio_util.h" +#include "ppapi/shared_impl/audio_impl.h" namespace ppapi { @@ -83,13 +84,15 @@ void AudioImpl::StartThread() { } void AudioImpl::Run() { - int pending_data; - void* buffer = shared_memory_->memory(); - - while (sizeof(pending_data) == - socket_->Receive(&pending_data, sizeof(pending_data)) && - pending_data >= 0) { - callback_(buffer, shared_memory_size_, user_data_); + uint32 filled_size = media::GetMaxDataSizeInBytes(shared_memory_size_); + AudioBuffersState buffer_state; + + while (buffer_state.Receive(socket_.get()) && + (buffer_state.total_bytes() >= 0)) { + callback_(media::GetDataPointer(shared_memory_.get()), + filled_size, + user_data_); + media::SetActualDataSizeInBytes(shared_memory_.get(), filled_size); } } |