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

Unified Diff: media/base/seekable_buffer.cc

Issue 9395057: Fix muted audio when playback rate != 1.0 or 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase ToT Created 8 years, 10 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
« no previous file with comments | « media/base/seekable_buffer.h ('k') | media/filters/audio_renderer_algorithm_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/seekable_buffer.cc
diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc
index b9ad7a43013e7f121c6aace8c3c1ac2d8fbfe26b..49df43f895192d29d4ae305c17315b2b9d9190a0 100644
--- a/media/base/seekable_buffer.cc
+++ b/media/base/seekable_buffer.cc
@@ -36,12 +36,12 @@ void SeekableBuffer::Clear() {
size_t SeekableBuffer::Read(uint8* data, size_t size) {
DCHECK(data);
- return InternalRead(data, size, true);
+ return InternalRead(data, size, true, 0);
}
-size_t SeekableBuffer::Peek(uint8* data, size_t size) {
+size_t SeekableBuffer::Peek(uint8* data, size_t size, size_t forward_offset) {
DCHECK(data);
- return InternalRead(data, size, false);
+ return InternalRead(data, size, false, forward_offset);
}
bool SeekableBuffer::GetCurrentChunk(const uint8** data, size_t* size) const {
@@ -113,7 +113,7 @@ bool SeekableBuffer::SeekForward(size_t size) {
return false;
// Do a read of |size| bytes.
- size_t taken = InternalRead(NULL, size, true);
+ size_t taken = InternalRead(NULL, size, true, 0);
DCHECK_EQ(taken, size);
return true;
}
@@ -183,13 +183,15 @@ void SeekableBuffer::EvictBackwardBuffers() {
}
size_t SeekableBuffer::InternalRead(uint8* data, size_t size,
- bool advance_position) {
+ bool advance_position,
+ size_t forward_offset) {
// Counts how many bytes are actually read from the buffer queue.
size_t taken = 0;
BufferQueue::iterator current_buffer = current_buffer_;
size_t current_buffer_offset = current_buffer_offset_;
+ size_t bytes_to_skip = forward_offset;
while (taken < size) {
// |current_buffer| is valid since the first time this buffer is appended
// with data.
@@ -198,22 +200,31 @@ size_t SeekableBuffer::InternalRead(uint8* data, size_t size,
scoped_refptr<Buffer> buffer = *current_buffer;
- // Find the right amount to copy from the current buffer referenced by
- // |buffer|. We shall copy no more than |size| bytes in total and each
- // single step copied no more than the current buffer size.
- size_t copied = std::min(size - taken,
- buffer->GetDataSize() - current_buffer_offset);
-
- // |data| is NULL if we are seeking forward, so there's no need to copy.
- if (data)
- memcpy(data + taken, buffer->GetData() + current_buffer_offset, copied);
-
- // Increase total number of bytes copied, which regulates when to end this
- // loop.
- taken += copied;
-
- // We have read |copied| bytes from the current buffer. Advances the offset.
- current_buffer_offset += copied;
+ size_t remaining_bytes_in_buffer =
+ buffer->GetDataSize() - current_buffer_offset;
+
+ if (bytes_to_skip == 0) {
+ // Find the right amount to copy from the current buffer referenced by
+ // |buffer|. We shall copy no more than |size| bytes in total and each
+ // single step copied no more than the current buffer size.
+ size_t copied = std::min(size - taken, remaining_bytes_in_buffer);
+
+ // |data| is NULL if we are seeking forward, so there's no need to copy.
+ if (data)
+ memcpy(data + taken, buffer->GetData() + current_buffer_offset, copied);
+
+ // Increase total number of bytes copied, which regulates when to end this
+ // loop.
+ taken += copied;
+
+ // We have read |copied| bytes from the current buffer. Advances the
+ // offset.
+ current_buffer_offset += copied;
+ } else {
+ size_t skipped = std::min(remaining_bytes_in_buffer, bytes_to_skip);
+ current_buffer_offset += skipped;
+ bytes_to_skip -= skipped;
+ }
// The buffer has been consumed.
if (current_buffer_offset == buffer->GetDataSize()) {
« no previous file with comments | « media/base/seekable_buffer.h ('k') | media/filters/audio_renderer_algorithm_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698