summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 19:01:38 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 19:01:38 +0000
commit87e6b1b69003191a0548325d7acac019e0f3777e (patch)
tree9f65b0c00e5419f87299eeb4a12028ff70327671 /media/audio
parent4d220800e2b19f161868732e7e848031a96291cb (diff)
downloadchromium_src-87e6b1b69003191a0548325d7acac019e0f3777e.zip
chromium_src-87e6b1b69003191a0548325d7acac019e0f3777e.tar.gz
chromium_src-87e6b1b69003191a0548325d7acac019e0f3777e.tar.bz2
Flush audio data after seek
There is about 400 to 600 ms of audio that needs to be flushed after seek, this have a pretty UX effect. This is partially fixed in this patch by reducing the amount of data down to about at most 500 ms stored in the hardware buffer. This patch clears data in the software buffer in the browser process when seek happens. We could reduce the amount of hardware buffer to further reduce the amount of lag but that can be fixed by subsequent patch. BUG=24150 TEST=audio still works, audio still play after seek the playback of old data after seek is substantially reduced. Few changes in this patch: 1. Flush software buffer after seek in browser process 2. Get rid of prerolling, this actually has not effect at all, so getting rid of useless code Needs to be done after this patch: 1. Further reduce the remaining data after seek and pause 2. Still hit the DCHECK in ClockImpl::Play(), this doesn't seem to be a new problem introduced in this patch Review URL: http://codereview.chromium.org/1508021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43983 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/simple_sources.cc13
-rw-r--r--media/audio/simple_sources.h12
-rw-r--r--media/audio/simple_sources_unittest.cc5
-rw-r--r--media/audio/win/audio_output_win_unittest.cc2
4 files changed, 17 insertions, 15 deletions
diff --git a/media/audio/simple_sources.cc b/media/audio/simple_sources.cc
index 228057b..1edd2b2 100644
--- a/media/audio/simple_sources.cc
+++ b/media/audio/simple_sources.cc
@@ -50,9 +50,8 @@ void SineWaveAudioSource::OnError(AudioOutputStream* stream, int code) {
//////////////////////////////////////////////////////////////////////////////
// PushSource implementation.
-PushSource::PushSource(uint32 packet_size)
- : packet_size_(packet_size),
- buffered_bytes_(0),
+PushSource::PushSource()
+ : buffered_bytes_(0),
front_buffer_consumed_(0) {
}
@@ -115,12 +114,18 @@ uint32 PushSource::UnProcessedBytes() {
return buffered_bytes_;
}
+void PushSource::ClearAll() {
+ // Cleanup() will discard all the data.
+ CleanUp();
+}
+
void PushSource::CleanUp() {
AutoLock auto_lock(lock_);
PacketList::const_iterator it;
for (it = packets_.begin(); it != packets_.end(); ++it) {
delete [] it->buffer;
- buffered_bytes_ -= it->size;
}
packets_.clear();
+ buffered_bytes_ = 0;
+ front_buffer_consumed_ = 0;
}
diff --git a/media/audio/simple_sources.h b/media/audio/simple_sources.h
index 9d0619f..9d8c5fa 100644
--- a/media/audio/simple_sources.h
+++ b/media/audio/simple_sources.h
@@ -58,14 +58,10 @@ class PushAudioOutput {
class PushSource : public AudioOutputStream::AudioSourceCallback,
public PushAudioOutput {
public:
- // Construct the audio source. Pass the same |packet_size| specified in the
- // AudioOutputStream::Open() here.
- // TODO(hclam): |packet_size| is not used anymore, remove it.
- explicit PushSource(uint32 packet_size);
+ explicit PushSource();
virtual ~PushSource();
- // Write one buffer. The ideal size is |packet_size| but smaller sizes are
- // accepted.
+ // Write one buffer.
virtual bool Write(const void* data, uint32 len);
// Return the total number of bytes not given to the audio device yet.
@@ -77,6 +73,9 @@ class PushSource : public AudioOutputStream::AudioSourceCallback,
virtual void OnClose(AudioOutputStream* stream);
virtual void OnError(AudioOutputStream* stream, int code);
+ // Discard all buffered data and reset to initial state.
+ void ClearAll();
+
private:
// Defines the unit of playback. We own the memory pointed by |buffer|.
struct Packet {
@@ -87,7 +86,6 @@ class PushSource : public AudioOutputStream::AudioSourceCallback,
// Free acquired resources.
void CleanUp();
- const uint32 packet_size_;
typedef std::list<Packet> PacketList;
PacketList packets_;
uint32 buffered_bytes_;
diff --git a/media/audio/simple_sources_unittest.cc b/media/audio/simple_sources_unittest.cc
index 6436170..118ec6f 100644
--- a/media/audio/simple_sources_unittest.cc
+++ b/media/audio/simple_sources_unittest.cc
@@ -39,9 +39,8 @@ TEST(SimpleSourcesTest, PushSourceSmallerWrite) {
const uint32 kReadSize = 293;
scoped_array<char> read_data(new char[kReadSize]);
- // Create a PushSource that assumes the hardware audio buffer size is always
- // bigger than the write size.
- PushSource push_source(kReadSize);
+ // Create a PushSource.
+ PushSource push_source;
EXPECT_EQ(0u, push_source.UnProcessedBytes());
// Write everything into this push source.
diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc
index 0bb18a2..6a06274 100644
--- a/media/audio/win/audio_output_win_unittest.cc
+++ b/media/audio/win/audio_output_win_unittest.cc
@@ -465,7 +465,7 @@ TEST(WinAudioTest, PushSourceFile16KHz) {
// We buffer and play at the same time, buffering happens every ~10ms and the
// consuming of the buffer happens every ~50ms. We do 100 buffers which
// effectively wrap around the file more than once.
- PushSource push_source(kSize50ms);
+ PushSource push_source;
for (uint32 ix = 0; ix != 100; ++ix) {
push_source.Write(file_reader.GetChunkAt(offset), kSize50ms);
if (ix == 2) {