diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 19:50:09 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 19:50:09 +0000 |
commit | b3341733befdca5563123e90b65adbd92b97b2ad (patch) | |
tree | 2821621c5dc84f07b3939ede66e7edbb6afaa982 /media | |
parent | 48697d8a33d2b98f7401a3b1e657c86cf3dba981 (diff) | |
download | chromium_src-b3341733befdca5563123e90b65adbd92b97b2ad.zip chromium_src-b3341733befdca5563123e90b65adbd92b97b2ad.tar.gz chromium_src-b3341733befdca5563123e90b65adbd92b97b2ad.tar.bz2 |
Eliminate media::Buffer as a base class for media::DecoderBuffer and media::DataBuffer.
It was never a good idea in the first place.
Our usage is exclusively with DecoderBuffers or DataBuffers. There's never a case where we benefit from using Buffer as a base class aside from hiding GetWriteableData(), however it's not a compelling enough reason to keep Buffer around.
BUG=169614
TBR=dmichael
Review URL: https://codereview.chromium.org/11880008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176956 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
32 files changed, 261 insertions, 287 deletions
diff --git a/media/base/audio_decoder.h b/media/base/audio_decoder.h index e6f09ed..ca43ecc 100644 --- a/media/base/audio_decoder.h +++ b/media/base/audio_decoder.h @@ -13,7 +13,7 @@ namespace media { -class Buffer; +class DataBuffer; class DemuxerStream; class MEDIA_EXPORT AudioDecoder @@ -43,7 +43,7 @@ class MEDIA_EXPORT AudioDecoder // indicate the end of the stream. A NULL buffer pointer indicates an aborted // Read(). This can happen if the DemuxerStream gets flushed and doesn't have // any more data to return. - typedef base::Callback<void(Status, const scoped_refptr<Buffer>&)> ReadCB; + typedef base::Callback<void(Status, const scoped_refptr<DataBuffer>&)> ReadCB; virtual void Read(const ReadCB& read_cb) = 0; // Reset decoder state, dropping any queued encoded data. diff --git a/media/base/audio_splicer.cc b/media/base/audio_splicer.cc index 2efbba9..e78cd2b 100644 --- a/media/base/audio_splicer.cc +++ b/media/base/audio_splicer.cc @@ -35,7 +35,7 @@ void AudioSplicer::Reset() { received_end_of_stream_ = false; } -bool AudioSplicer::AddInput(const scoped_refptr<Buffer>& input){ +bool AudioSplicer::AddInput(const scoped_refptr<DataBuffer>& input){ DCHECK(!received_end_of_stream_ || input->IsEndOfStream()); if (input->IsEndOfStream()) { @@ -125,13 +125,13 @@ bool AudioSplicer::HasNextBuffer() const { return !output_buffers_.empty(); } -scoped_refptr<Buffer> AudioSplicer::GetNextBuffer() { - scoped_refptr<Buffer> ret = output_buffers_.front(); +scoped_refptr<DataBuffer> AudioSplicer::GetNextBuffer() { + scoped_refptr<DataBuffer> ret = output_buffers_.front(); output_buffers_.pop_front(); return ret; } -void AudioSplicer::AddOutputBuffer(const scoped_refptr<Buffer>& buffer) { +void AudioSplicer::AddOutputBuffer(const scoped_refptr<DataBuffer>& buffer) { output_timestamp_helper_.AddBytes(buffer->GetDataSize()); output_buffers_.push_back(buffer); } diff --git a/media/base/audio_splicer.h b/media/base/audio_splicer.h index aa97fae..22cce47 100644 --- a/media/base/audio_splicer.h +++ b/media/base/audio_splicer.h @@ -14,7 +14,7 @@ namespace media { class AudioDecoderConfig; -class Buffer; +class DataBuffer; // Helper class that handles filling gaps and resolving overlaps. class MEDIA_EXPORT AudioSplicer { @@ -29,17 +29,17 @@ class MEDIA_EXPORT AudioSplicer { // Adds a new buffer full of samples or end of stream buffer to the splicer. // Returns true if the buffer was accepted. False is returned if an error // occurred. - bool AddInput(const scoped_refptr<Buffer>& input); + bool AddInput(const scoped_refptr<DataBuffer>& input); // Returns true if the splicer has a buffer to return. bool HasNextBuffer() const; // Removes the next buffer from the output buffer queue and returns it. // This should only be called if HasNextBuffer() returns true. - scoped_refptr<Buffer> GetNextBuffer(); + scoped_refptr<DataBuffer> GetNextBuffer(); private: - void AddOutputBuffer(const scoped_refptr<Buffer>& buffer); + void AddOutputBuffer(const scoped_refptr<DataBuffer>& buffer); AudioTimestampHelper output_timestamp_helper_; @@ -49,7 +49,7 @@ class MEDIA_EXPORT AudioSplicer { // in the source content. int min_gap_size_; - std::deque<scoped_refptr<Buffer> > output_buffers_; + std::deque<scoped_refptr<DataBuffer> > output_buffers_; bool received_end_of_stream_; DISALLOW_IMPLICIT_CONSTRUCTORS(AudioSplicer); diff --git a/media/base/audio_splicer_unittest.cc b/media/base/audio_splicer_unittest.cc index 2096789..20c923f 100644 --- a/media/base/audio_splicer_unittest.cc +++ b/media/base/audio_splicer_unittest.cc @@ -23,11 +23,11 @@ class AudioSplicerTest : public ::testing::Test { input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta()); } - scoped_refptr<Buffer> GetNextInputBuffer(uint8 value) { + scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value) { return GetNextInputBuffer(value, kDefaultBufferSize); } - scoped_refptr<Buffer> GetNextInputBuffer(uint8 value, int size) { + scoped_refptr<DataBuffer> GetNextInputBuffer(uint8 value, int size) { scoped_refptr<DataBuffer> buffer = new DataBuffer(size); buffer->SetDataSize(size); memset(buffer->GetWritableData(), value, buffer->GetDataSize()); @@ -57,30 +57,30 @@ TEST_F(AudioSplicerTest, PassThru) { EXPECT_FALSE(splicer_.HasNextBuffer()); // Test single buffer pass-thru behavior. - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); EXPECT_EQ(input_1->GetDataSize(), output_1->GetDataSize()); // Test that multiple buffers can be queued in the splicer. - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2); - scoped_refptr<Buffer> input_3 = GetNextInputBuffer(3); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); EXPECT_TRUE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.AddInput(input_3)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_TRUE(splicer_.HasNextBuffer()); EXPECT_EQ(input_2->GetTimestamp(), output_2->GetTimestamp()); EXPECT_EQ(input_2->GetDuration(), output_2->GetDuration()); EXPECT_EQ(input_2->GetDataSize(), output_2->GetDataSize()); - scoped_refptr<Buffer> output_3 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_3->GetTimestamp(), output_3->GetTimestamp()); EXPECT_EQ(input_3->GetDuration(), output_3->GetDuration()); @@ -88,7 +88,7 @@ TEST_F(AudioSplicerTest, PassThru) { } TEST_F(AudioSplicerTest, Reset) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.HasNextBuffer()); @@ -102,11 +102,11 @@ TEST_F(AudioSplicerTest, Reset) { input_timestamp_helper_.AddBytes(100 * kBytesPerFrame); // Verify that a new input buffer passes through as expected. - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); EXPECT_TRUE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_2->GetTimestamp(), output_2->GetTimestamp()); EXPECT_EQ(input_2->GetDuration(), output_2->GetDuration()); @@ -114,17 +114,17 @@ TEST_F(AudioSplicerTest, Reset) { } TEST_F(AudioSplicerTest, EndOfStream) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); - scoped_refptr<Buffer> input_2 = new DataBuffer(0); // End of stream. - scoped_refptr<Buffer> input_3 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_2 = new DataBuffer(0); // End of stream. + scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(2); EXPECT_TRUE(input_2->IsEndOfStream()); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); EXPECT_EQ(input_1->GetDuration(), output_1->GetDuration()); @@ -135,7 +135,7 @@ TEST_F(AudioSplicerTest, EndOfStream) { // Verify that buffers can be added again after Reset(). splicer_.Reset(); EXPECT_TRUE(splicer_.AddInput(input_3)); - scoped_refptr<Buffer> output_3 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_3->GetTimestamp(), output_3->GetTimestamp()); EXPECT_EQ(input_3->GetDuration(), output_3->GetDuration()); @@ -152,23 +152,23 @@ TEST_F(AudioSplicerTest, EndOfStream) { // |11111111111111|0000|22222222222222| // +--------------+----+--------------+ TEST_F(AudioSplicerTest, GapInsertion) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); // Add bytes to the timestamp helper so that the next buffer // will have a starting timestamp that indicates a gap is // present. const int kGapSize = 7 * kBytesPerFrame; input_timestamp_helper_.AddBytes(kGapSize); - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.AddInput(input_2)); // Verify that a gap buffer is generated. EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); - scoped_refptr<Buffer> output_3 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_3 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); // Verify that the first input buffer passed through unmodified. @@ -198,19 +198,19 @@ TEST_F(AudioSplicerTest, GapInsertion) { // Test that an error is signalled when the gap between input buffers is // too large. TEST_F(AudioSplicerTest, GapTooLarge) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); // Add a seconds worth of bytes so that an unacceptably large // gap exists between |input_1| and |input_2|. const int kGapSize = kDefaultSampleRate * kBytesPerFrame; input_timestamp_helper_.AddBytes(kGapSize); - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_FALSE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); // Verify that the first input buffer passed through unmodified. EXPECT_EQ(input_1->GetTimestamp(), output_1->GetTimestamp()); @@ -227,10 +227,10 @@ TEST_F(AudioSplicerTest, GapTooLarge) { input_1->GetTimestamp() + input_1->GetDuration()); // Verify that valid buffers are still accepted. - scoped_refptr<Buffer> input_3 = GetNextInputBuffer(3); + scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); EXPECT_TRUE(splicer_.AddInput(input_3)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); EXPECT_EQ(input_3->GetTimestamp(), output_2->GetTimestamp()); EXPECT_EQ(input_3->GetDuration(), output_2->GetDuration()); @@ -244,12 +244,12 @@ TEST_F(AudioSplicerTest, GapTooLarge) { TEST_F(AudioSplicerTest, BufferAddedBeforeBase) { input_timestamp_helper_.SetBaseTimestamp( base::TimeDelta::FromMicroseconds(10)); - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); // Reset the timestamp helper so the next buffer will have a timestamp earlier // than |input_1|. input_timestamp_helper_.SetBaseTimestamp(base::TimeDelta::FromSeconds(0)); - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(1); EXPECT_GT(input_1->GetTimestamp(), input_2->GetTimestamp()); EXPECT_TRUE(splicer_.AddInput(input_1)); @@ -269,7 +269,7 @@ TEST_F(AudioSplicerTest, BufferAddedBeforeBase) { // |11111111111111|2222222222| // +--------------+----------+ TEST_F(AudioSplicerTest, PartialOverlap) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); // Reset timestamp helper so that the next buffer will have a // timestamp that starts in the middle of |input_1|. @@ -277,14 +277,14 @@ TEST_F(AudioSplicerTest, PartialOverlap) { input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); input_timestamp_helper_.AddBytes(input_1->GetDataSize() - kOverlapSize); - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); // Verify that the first input buffer passed through unmodified. @@ -323,7 +323,7 @@ TEST_F(AudioSplicerTest, PartialOverlap) { // |11111111111111|3333333333333| // +--------------+-------------+ TEST_F(AudioSplicerTest, DropBuffer) { - scoped_refptr<Buffer> input_1 = GetNextInputBuffer(1); + scoped_refptr<DataBuffer> input_1 = GetNextInputBuffer(1); // Reset timestamp helper so that the next buffer will have a // timestamp that starts in the middle of |input_1|. @@ -332,21 +332,21 @@ TEST_F(AudioSplicerTest, DropBuffer) { input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); input_timestamp_helper_.AddBytes(kOverlapOffset); - scoped_refptr<Buffer> input_2 = GetNextInputBuffer(2, kOverlapSize); + scoped_refptr<DataBuffer> input_2 = GetNextInputBuffer(2, kOverlapSize); // Reset the timestamp helper so the next buffer will be right after // |input_1|. input_timestamp_helper_.SetBaseTimestamp(input_1->GetTimestamp()); input_timestamp_helper_.AddBytes(input_1->GetDataSize()); - scoped_refptr<Buffer> input_3 = GetNextInputBuffer(3); + scoped_refptr<DataBuffer> input_3 = GetNextInputBuffer(3); EXPECT_TRUE(splicer_.AddInput(input_1)); EXPECT_TRUE(splicer_.AddInput(input_2)); EXPECT_TRUE(splicer_.AddInput(input_3)); EXPECT_TRUE(splicer_.HasNextBuffer()); - scoped_refptr<Buffer> output_1 = splicer_.GetNextBuffer(); - scoped_refptr<Buffer> output_2 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_1 = splicer_.GetNextBuffer(); + scoped_refptr<DataBuffer> output_2 = splicer_.GetNextBuffer(); EXPECT_FALSE(splicer_.HasNextBuffer()); // Verify that the first input buffer passed through unmodified. diff --git a/media/base/buffers.cc b/media/base/buffers.cc deleted file mode 100644 index 63802c6..0000000 --- a/media/base/buffers.cc +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#include "media/base/buffers.h" - -namespace media { - -Buffer::Buffer(base::TimeDelta timestamp, base::TimeDelta duration) - : timestamp_(timestamp), - duration_(duration) { -} - -Buffer::~Buffer() {} - -bool Buffer::IsEndOfStream() const { - return GetData() == NULL; -} - -} // namespace media diff --git a/media/base/buffers.h b/media/base/buffers.h index d14f4db..7eecd5b 100644 --- a/media/base/buffers.h +++ b/media/base/buffers.h @@ -2,11 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Defines a base class for representing timestamped media data. Every buffer -// contains a timestamp in microseconds describing the relative position of -// the buffer within the media stream, and the duration in microseconds for -// the length of time the buffer will be rendered. -// // Timestamps are derived directly from the encoded media file and are commonly // known as the presentation timestamp (PTS). Durations are a best-guess and // are usually derived from the sample/frame rate of the media file. @@ -33,6 +28,8 @@ namespace media { +// TODO(scherkus): Move the contents of this file elsewhere. + // Indicates an invalid or missing timestamp. MEDIA_EXPORT extern inline base::TimeDelta kNoTimestamp() { return base::TimeDelta::FromMicroseconds(kint64min); @@ -43,43 +40,6 @@ MEDIA_EXPORT extern inline base::TimeDelta kInfiniteDuration() { return base::TimeDelta::FromMicroseconds(kint64max); } -class MEDIA_EXPORT Buffer : public base::RefCountedThreadSafe<Buffer> { - public: - // Returns a read only pointer to the buffer data. - virtual const uint8* GetData() const = 0; - - // Returns the size of valid data in bytes. - virtual int GetDataSize() const = 0; - - // If there's no data in this buffer, it represents end of stream. - bool IsEndOfStream() const; - - base::TimeDelta GetTimestamp() const { - return timestamp_; - } - void SetTimestamp(const base::TimeDelta& timestamp) { - timestamp_ = timestamp; - } - - base::TimeDelta GetDuration() const { - return duration_; - } - void SetDuration(const base::TimeDelta& duration) { - duration_ = duration; - } - - protected: - friend class base::RefCountedThreadSafe<Buffer>; - Buffer(base::TimeDelta timestamp, base::TimeDelta duration); - virtual ~Buffer(); - - private: - base::TimeDelta timestamp_; - base::TimeDelta duration_; - - DISALLOW_COPY_AND_ASSIGN(Buffer); -}; - } // namespace media #endif // MEDIA_BASE_BUFFERS_H_ diff --git a/media/base/buffers_unittest.cc b/media/base/buffers_unittest.cc deleted file mode 100644 index a96b40b..0000000 --- a/media/base/buffers_unittest.cc +++ /dev/null @@ -1,85 +0,0 @@ -// 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. - -#include "base/string_util.h" -#include "media/base/buffers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace media { - -namespace { - -// Simple implementation of Buffer to test base class functionality. -class TestBuffer : public Buffer { - public: - TestBuffer() - : Buffer(base::TimeDelta(), base::TimeDelta()) { - } - - // Sets |data_| and |size_| members for testing purposes. Does not take - // ownership of |data|. - TestBuffer(const uint8* data, int size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - data_(data), - size_(size) { - } - - // Buffer implementation. - virtual const uint8* GetData() const OVERRIDE { return data_; } - virtual int GetDataSize() const OVERRIDE { return size_; } - - protected: - virtual ~TestBuffer() {} - - private: - const uint8* data_; - int size_; - - DISALLOW_COPY_AND_ASSIGN(TestBuffer); -}; - -} // namespace - -TEST(BufferTest, Timestamp) { - const base::TimeDelta kZero; - const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); - const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234); - - scoped_refptr<TestBuffer> buffer = new TestBuffer(); - EXPECT_TRUE(buffer->GetTimestamp() == kZero); - - buffer->SetTimestamp(kTimestampA); - EXPECT_TRUE(buffer->GetTimestamp() == kTimestampA); - - buffer->SetTimestamp(kTimestampB); - EXPECT_TRUE(buffer->GetTimestamp() == kTimestampB); -} - -TEST(BufferTest, Duration) { - const base::TimeDelta kZero; - const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1337); - const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(1234); - - scoped_refptr<TestBuffer> buffer = new TestBuffer(); - EXPECT_TRUE(buffer->GetDuration() == kZero); - - buffer->SetDuration(kDurationA); - EXPECT_TRUE(buffer->GetDuration() == kDurationA); - - buffer->SetDuration(kDurationB); - EXPECT_TRUE(buffer->GetDuration() == kDurationB); -} - -TEST(BufferTest, IsEndOfStream) { - const uint8 kData[] = { 0x00, 0xFF }; - const int kDataSize = arraysize(kData); - - scoped_refptr<TestBuffer> buffer = new TestBuffer(NULL, 0); - EXPECT_TRUE(buffer->IsEndOfStream()); - - buffer = new TestBuffer(kData, kDataSize); - EXPECT_FALSE(buffer->IsEndOfStream()); -} - -} // namespace media diff --git a/media/base/data_buffer.cc b/media/base/data_buffer.cc index 28ca491..a342023 100644 --- a/media/base/data_buffer.cc +++ b/media/base/data_buffer.cc @@ -9,22 +9,19 @@ namespace media { DataBuffer::DataBuffer(scoped_array<uint8> buffer, int buffer_size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - data_(buffer.Pass()), + : data_(buffer.Pass()), buffer_size_(buffer_size), data_size_(buffer_size) { } DataBuffer::DataBuffer(int buffer_size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - buffer_size_(buffer_size), + : buffer_size_(buffer_size), data_size_(0) { Initialize(); } DataBuffer::DataBuffer(const uint8* data, int data_size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - buffer_size_(data_size), + : buffer_size_(data_size), data_size_(data_size) { Initialize(); memcpy(data_.get(), data, data_size_); @@ -43,18 +40,38 @@ void DataBuffer::Initialize() { data_.reset(new uint8[buffer_size_]); } -const uint8* DataBuffer::GetData() const { - return data_.get(); +base::TimeDelta DataBuffer::GetTimestamp() const { + return timestamp_; } -int DataBuffer::GetDataSize() const { - return data_size_; +void DataBuffer::SetTimestamp(const base::TimeDelta& timestamp) { + timestamp_ = timestamp; +} + +base::TimeDelta DataBuffer::GetDuration() const { + return duration_; +} + +void DataBuffer::SetDuration(const base::TimeDelta& duration) { + duration_ = duration; +} + +bool DataBuffer::IsEndOfStream() const { + return data_ == NULL; +} + +const uint8* DataBuffer::GetData() const { + return data_.get(); } uint8* DataBuffer::GetWritableData() { return data_.get(); } +int DataBuffer::GetDataSize() const { + return data_size_; +} + void DataBuffer::SetDataSize(int data_size) { DCHECK_LE(data_size, buffer_size_); data_size_ = data_size; diff --git a/media/base/data_buffer.h b/media/base/data_buffer.h index 96e9af5..d3ccd37 100644 --- a/media/base/data_buffer.h +++ b/media/base/data_buffer.h @@ -2,53 +2,68 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A simple implementation of Buffer that takes ownership of the given data -// pointer. -// -// DataBuffer assumes that memory was allocated with new uint8[]. - #ifndef MEDIA_BASE_DATA_BUFFER_H_ #define MEDIA_BASE_DATA_BUFFER_H_ +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "media/base/buffers.h" +#include "base/time.h" +#include "media/base/media_export.h" namespace media { -class MEDIA_EXPORT DataBuffer : public Buffer { +// A simple buffer that takes ownership of the given data pointer or allocates +// as necessary. +// +// Unlike DecoderBuffer, allocations are assumed to be allocated with the +// default memory allocator (i.e., new uint8[]). +class MEDIA_EXPORT DataBuffer : public base::RefCountedThreadSafe<DataBuffer> { public: // Assumes valid data of size |buffer_size|. DataBuffer(scoped_array<uint8> buffer, int buffer_size); // Allocates buffer of size |buffer_size|. If |buffer_size| is 0, |data_| is - // set to a NULL ptr. + // set to NULL and this becomes an end of stream buffer. + // + // TODO(scherkus): Enforce calling CreateEOSBuffer() instead of passing 0 and + // sprinkle DCHECK()s everywhere. explicit DataBuffer(int buffer_size); // Allocates buffer of size |data_size|, copies [data,data+data_size) to // the allocated buffer and sets data size to |data_size|. DataBuffer(const uint8* data, int data_size); - // Buffer implementation. - virtual const uint8* GetData() const OVERRIDE; - virtual int GetDataSize() const OVERRIDE; + base::TimeDelta GetTimestamp() const; + void SetTimestamp(const base::TimeDelta& timestamp); - // Returns a read-write pointer to the buffer data. - virtual uint8* GetWritableData(); + base::TimeDelta GetDuration() const; + void SetDuration(const base::TimeDelta& duration); - // Updates the size of valid data in bytes, which must be less than or equal + const uint8* GetData() const; + uint8* GetWritableData(); + + // The size of valid data in bytes, which must be less than or equal // to GetBufferSize(). - virtual void SetDataSize(int data_size); + int GetDataSize() const; + void SetDataSize(int data_size); // Returns the size of the underlying buffer. - virtual int GetBufferSize() const; + int GetBufferSize() const; + + // If there's no data in this buffer, it represents end of stream. + bool IsEndOfStream() const; protected: + friend class base::RefCountedThreadSafe<DataBuffer>; virtual ~DataBuffer(); private: // Constructor helper method for memory allocations. void Initialize(); + base::TimeDelta timestamp_; + base::TimeDelta duration_; + scoped_array<uint8> data_; int buffer_size_; int data_size_; diff --git a/media/base/data_buffer_unittest.cc b/media/base/data_buffer_unittest.cc index 71d8389..0daa5f6 100644 --- a/media/base/data_buffer_unittest.cc +++ b/media/base/data_buffer_unittest.cc @@ -28,6 +28,47 @@ TEST(DataBufferTest, Constructors) { ASSERT_NE(0, memcmp(buffer3->GetData(), kTestData, kTestDataSize)); } +TEST(DataBufferTest, Timestamp) { + const base::TimeDelta kZero; + const base::TimeDelta kTimestampA = base::TimeDelta::FromMicroseconds(1337); + const base::TimeDelta kTimestampB = base::TimeDelta::FromMicroseconds(1234); + + scoped_refptr<DataBuffer> buffer = new DataBuffer(0); + EXPECT_TRUE(buffer->GetTimestamp() == kZero); + + buffer->SetTimestamp(kTimestampA); + EXPECT_TRUE(buffer->GetTimestamp() == kTimestampA); + + buffer->SetTimestamp(kTimestampB); + EXPECT_TRUE(buffer->GetTimestamp() == kTimestampB); +} + +TEST(DataBufferTest, Duration) { + const base::TimeDelta kZero; + const base::TimeDelta kDurationA = base::TimeDelta::FromMicroseconds(1337); + const base::TimeDelta kDurationB = base::TimeDelta::FromMicroseconds(1234); + + scoped_refptr<DataBuffer> buffer = new DataBuffer(0); + EXPECT_TRUE(buffer->GetDuration() == kZero); + + buffer->SetDuration(kDurationA); + EXPECT_TRUE(buffer->GetDuration() == kDurationA); + + buffer->SetDuration(kDurationB); + EXPECT_TRUE(buffer->GetDuration() == kDurationB); +} + +TEST(DataBufferTest, IsEndOfStream) { + const uint8 kData[] = { 0x00, 0xFF }; + const int kDataSize = arraysize(kData); + + scoped_refptr<DataBuffer> buffer = new DataBuffer(0); + EXPECT_TRUE(buffer->IsEndOfStream()); + + buffer = new DataBuffer(kData, kDataSize); + EXPECT_FALSE(buffer->IsEndOfStream()); +} + TEST(DataBufferTest, ReadingWriting) { const char kData[] = "hello"; const int kDataSize = arraysize(kData); diff --git a/media/base/decoder_buffer.cc b/media/base/decoder_buffer.cc index e4af00e..9cc54ae 100644 --- a/media/base/decoder_buffer.cc +++ b/media/base/decoder_buffer.cc @@ -10,14 +10,12 @@ namespace media { DecoderBuffer::DecoderBuffer(int buffer_size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - buffer_size_(buffer_size) { + : buffer_size_(buffer_size) { Initialize(); } DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) - : Buffer(base::TimeDelta(), base::TimeDelta()), - buffer_size_(buffer_size) { + : buffer_size_(buffer_size) { // Prevent invalid allocations. Also used to create end of stream buffers. if (!data || buffer_size <= 0) { buffer_size_ = 0; @@ -47,16 +45,32 @@ scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { return make_scoped_refptr(new DecoderBuffer(NULL, 0)); } +base::TimeDelta DecoderBuffer::GetTimestamp() const { + return timestamp_; +} + +void DecoderBuffer::SetTimestamp(const base::TimeDelta& timestamp) { + timestamp_ = timestamp; +} + +base::TimeDelta DecoderBuffer::GetDuration() const { + return duration_; +} + +void DecoderBuffer::SetDuration(const base::TimeDelta& duration) { + duration_ = duration; +} + const uint8* DecoderBuffer::GetData() const { return data_.get(); } -int DecoderBuffer::GetDataSize() const { - return buffer_size_; +uint8* DecoderBuffer::GetWritableData() const { + return data_.get(); } -uint8* DecoderBuffer::GetWritableData() { - return data_.get(); +int DecoderBuffer::GetDataSize() const { + return buffer_size_; } const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { @@ -67,4 +81,8 @@ void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { decrypt_config_ = decrypt_config.Pass(); } +bool DecoderBuffer::IsEndOfStream() const { + return data_ == NULL; +} + } // namespace media diff --git a/media/base/decoder_buffer.h b/media/base/decoder_buffer.h index 50b0855..dca8776 100644 --- a/media/base/decoder_buffer.h +++ b/media/base/decoder_buffer.h @@ -2,26 +2,29 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A specialized buffer for interfacing with audio / video decoders. -// -// Specifically ensures that data is aligned and padded as necessary by the -// underlying decoding framework. On desktop platforms this means memory is -// allocated using FFmpeg with particular alignment and padding requirements. -// -// Also includes decoder specific functionality for decryption. - #ifndef MEDIA_BASE_DECODER_BUFFER_H_ #define MEDIA_BASE_DECODER_BUFFER_H_ #include "base/memory/aligned_memory.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/time.h" #include "build/build_config.h" -#include "media/base/buffers.h" -#include "media/base/decrypt_config.h" +#include "media/base/media_export.h" namespace media { -class MEDIA_EXPORT DecoderBuffer : public Buffer { +class DecryptConfig; + +// A specialized buffer for interfacing with audio / video decoders. +// +// Specifically ensures that data is aligned and padded as necessary by the +// underlying decoding framework. On desktop platforms this means memory is +// allocated using FFmpeg with particular alignment and padding requirements. +// +// Also includes decoder specific functionality for decryption. +class MEDIA_EXPORT DecoderBuffer + : public base::RefCountedThreadSafe<DecoderBuffer> { public: enum { kPaddingSize = 16, @@ -44,17 +47,29 @@ class MEDIA_EXPORT DecoderBuffer : public Buffer { // and GetWritableData() will return NULL and GetDataSize() will return 0. static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); - // Buffer implementation. - virtual const uint8* GetData() const OVERRIDE; - virtual int GetDataSize() const OVERRIDE; + base::TimeDelta GetTimestamp() const; + void SetTimestamp(const base::TimeDelta& timestamp); - // Returns a read-write pointer to the buffer data. - virtual uint8* GetWritableData(); + base::TimeDelta GetDuration() const; + void SetDuration(const base::TimeDelta& duration); - virtual const DecryptConfig* GetDecryptConfig() const; - virtual void SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config); + const uint8* GetData() const; + uint8* GetWritableData() const; + + int GetDataSize() const; + + const DecryptConfig* GetDecryptConfig() const; + void SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config); + + // If there's no data in this buffer, it represents end of stream. + // + // TODO(scherkus): Change to be an actual settable flag as opposed to being + // based on the value of |data_|, see http://crbug.com/169133 + bool IsEndOfStream() const; protected: + friend class base::RefCountedThreadSafe<DecoderBuffer>; + // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer // will be padded and aligned as necessary. If |data| is NULL then |data_| is // set to NULL and |buffer_size_| to 0. @@ -62,6 +77,9 @@ class MEDIA_EXPORT DecoderBuffer : public Buffer { virtual ~DecoderBuffer(); private: + base::TimeDelta timestamp_; + base::TimeDelta duration_; + int buffer_size_; scoped_ptr<uint8, base::ScopedPtrAlignedFree> data_; scoped_ptr<DecryptConfig> decrypt_config_; diff --git a/media/base/decoder_buffer_queue.cc b/media/base/decoder_buffer_queue.cc index ad91c37..ab24c2d 100644 --- a/media/base/decoder_buffer_queue.cc +++ b/media/base/decoder_buffer_queue.cc @@ -5,6 +5,7 @@ #include "media/base/decoder_buffer_queue.h" #include "base/logging.h" +#include "media/base/buffers.h" #include "media/base/decoder_buffer.h" namespace media { diff --git a/media/base/decoder_buffer_queue_unittest.cc b/media/base/decoder_buffer_queue_unittest.cc index 02cd541..243e465 100644 --- a/media/base/decoder_buffer_queue_unittest.cc +++ b/media/base/decoder_buffer_queue_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "media/base/buffers.h" #include "media/base/decoder_buffer.h" #include "media/base/decoder_buffer_queue.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/media/base/decryptor.h b/media/base/decryptor.h index 4cc05a1..f27a7bf 100644 --- a/media/base/decryptor.h +++ b/media/base/decryptor.h @@ -17,7 +17,7 @@ namespace media { class AudioDecoderConfig; -class Buffer; +class DataBuffer; class DecoderBuffer; class VideoDecoderConfig; class VideoFrame; @@ -146,7 +146,7 @@ class MEDIA_EXPORT Decryptor { // Helper structure for managing multiple decoded audio buffers per input. // TODO(xhwang): Rename this to AudioFrames. - typedef std::list<scoped_refptr<Buffer> > AudioBuffers; + typedef std::list<scoped_refptr<DataBuffer> > AudioBuffers; // Indicates completion of audio/video decrypt-and-decode operation. // diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc index 48c0858..b23457e 100644 --- a/media/base/seekable_buffer.cc +++ b/media/base/seekable_buffer.cc @@ -60,14 +60,14 @@ bool SeekableBuffer::GetCurrentChunk(const uint8** data, int* size) const { return true; } -bool SeekableBuffer::Append(Buffer* buffer_in) { +bool SeekableBuffer::Append(const scoped_refptr<DataBuffer>& buffer_in) { if (buffers_.empty() && buffer_in->GetTimestamp() != kNoTimestamp()) { current_time_ = buffer_in->GetTimestamp(); } // Since the forward capacity is only used to check the criteria for buffer // full, we always append data to the buffer. - buffers_.push_back(scoped_refptr<Buffer>(buffer_in)); + buffers_.push_back(buffer_in); // After we have written the first buffer, update |current_buffer_| to point // to it. @@ -172,7 +172,7 @@ void SeekableBuffer::EvictBackwardBuffers() { BufferQueue::iterator i = buffers_.begin(); if (i == current_buffer_) break; - scoped_refptr<Buffer> buffer = *i; + scoped_refptr<DataBuffer> buffer = *i; backward_bytes_ -= buffer->GetDataSize(); DCHECK_GE(backward_bytes_, 0); @@ -196,7 +196,7 @@ int SeekableBuffer::InternalRead(uint8* data, int size, if (current_buffer == buffers_.end()) break; - scoped_refptr<Buffer> buffer = *current_buffer; + scoped_refptr<DataBuffer> buffer = *current_buffer; int remaining_bytes_in_buffer = buffer->GetDataSize() - current_buffer_offset; diff --git a/media/base/seekable_buffer.h b/media/base/seekable_buffer.h index 0a3ff72..41d26fe 100644 --- a/media/base/seekable_buffer.h +++ b/media/base/seekable_buffer.h @@ -41,6 +41,8 @@ namespace media { +class DataBuffer; + class MEDIA_EXPORT SeekableBuffer { public: // Constructs an instance with |forward_capacity| and |backward_capacity|. @@ -75,7 +77,7 @@ class MEDIA_EXPORT SeekableBuffer { // Appends |buffer_in| to this buffer. Returns false if forward_bytes() is // greater than or equals to forward_capacity(), true otherwise. The data // is added to the buffer in any case. - bool Append(Buffer* buffer_in); + bool Append(const scoped_refptr<DataBuffer>& buffer_in); // Appends |size| bytes of |data| to the buffer. Result is the same // as for Append(Buffer*). @@ -128,7 +130,7 @@ class MEDIA_EXPORT SeekableBuffer { private: // Definition of the buffer queue. - typedef std::list<scoped_refptr<Buffer> > BufferQueue; + typedef std::list<scoped_refptr<DataBuffer> > BufferQueue; // A helper method to evict buffers in the backward direction until backward // bytes is within the backward capacity. diff --git a/media/base/stream_parser_buffer.cc b/media/base/stream_parser_buffer.cc index 04f9513..13e649e 100644 --- a/media/base/stream_parser_buffer.cc +++ b/media/base/stream_parser_buffer.cc @@ -5,6 +5,7 @@ #include "media/base/stream_parser_buffer.h" #include "base/logging.h" +#include "media/base/buffers.h" namespace media { diff --git a/media/filters/audio_renderer_algorithm.cc b/media/filters/audio_renderer_algorithm.cc index 9e84b9b..bdd3d4c 100644 --- a/media/filters/audio_renderer_algorithm.cc +++ b/media/filters/audio_renderer_algorithm.cc @@ -10,12 +10,12 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "media/audio/audio_util.h" -#include "media/base/buffers.h" +#include "media/base/data_buffer.h" namespace media { // The starting size in bytes for |audio_buffer_|. -// Previous usage maintained a deque of 16 Buffers, each of size 4Kb. This +// Previous usage maintained a deque of 16 DataBuffers, each of size 4Kb. This // worked well, so we maintain this number of bytes (16 * 4096). static const int kStartingBufferSizeInBytes = 65536; @@ -388,7 +388,8 @@ base::TimeDelta AudioRendererAlgorithm::GetTime() { return audio_buffer_.current_time(); } -void AudioRendererAlgorithm::EnqueueBuffer(Buffer* buffer_in) { +void AudioRendererAlgorithm::EnqueueBuffer( + const scoped_refptr<DataBuffer>& buffer_in) { DCHECK(!buffer_in->IsEndOfStream()); audio_buffer_.Append(buffer_in); needs_more_data_ = false; diff --git a/media/filters/audio_renderer_algorithm.h b/media/filters/audio_renderer_algorithm.h index 080a11d..354e208 100644 --- a/media/filters/audio_renderer_algorithm.h +++ b/media/filters/audio_renderer_algorithm.h @@ -23,12 +23,13 @@ #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ #include "base/callback.h" +#include "base/memory/ref_counted.h" #include "media/audio/audio_parameters.h" #include "media/base/seekable_buffer.h" namespace media { -class Buffer; +class DataBuffer; class MEDIA_EXPORT AudioRendererAlgorithm { public: @@ -61,7 +62,7 @@ class MEDIA_EXPORT AudioRendererAlgorithm { // Enqueues a buffer. It is called from the owner of the algorithm after a // read completes. - void EnqueueBuffer(Buffer* buffer_in); + void EnqueueBuffer(const scoped_refptr<DataBuffer>& buffer_in); float playback_rate() const { return playback_rate_; } void SetPlaybackRate(float new_rate); diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc index 2e78218..95f803b 100644 --- a/media/filters/audio_renderer_impl.cc +++ b/media/filters/audio_renderer_impl.cc @@ -17,6 +17,7 @@ #include "media/audio/audio_util.h" #include "media/base/audio_splicer.h" #include "media/base/bind_to_loop.h" +#include "media/base/data_buffer.h" #include "media/base/demuxer_stream.h" #include "media/base/media_switches.h" #include "media/filters/audio_decoder_selector.h" @@ -324,8 +325,9 @@ AudioRendererImpl::~AudioRendererImpl() { DCHECK(!algorithm_.get()); } -void AudioRendererImpl::DecodedAudioReady(AudioDecoder::Status status, - const scoped_refptr<Buffer>& buffer) { +void AudioRendererImpl::DecodedAudioReady( + AudioDecoder::Status status, + const scoped_refptr<DataBuffer>& buffer) { base::AutoLock auto_lock(lock_); DCHECK(state_ == kPaused || state_ == kPrerolling || state_ == kPlaying || state_ == kUnderflow || state_ == kRebuffering || state_ == kStopped); @@ -367,7 +369,7 @@ void AudioRendererImpl::DecodedAudioReady(AudioDecoder::Status status, } bool AudioRendererImpl::HandleSplicerBuffer( - const scoped_refptr<Buffer>& buffer) { + const scoped_refptr<DataBuffer>& buffer) { if (buffer->IsEndOfStream()) { received_end_of_stream_ = true; @@ -440,7 +442,7 @@ void AudioRendererImpl::SetPlaybackRate(float playback_rate) { } bool AudioRendererImpl::IsBeforePrerollTime( - const scoped_refptr<Buffer>& buffer) { + const scoped_refptr<DataBuffer>& buffer) { return (state_ == kPrerolling) && buffer && !buffer->IsEndOfStream() && (buffer->GetTimestamp() + buffer->GetDuration()) < preroll_timestamp_; } diff --git a/media/filters/audio_renderer_impl.h b/media/filters/audio_renderer_impl.h index 9158aa1..96bda86 100644 --- a/media/filters/audio_renderer_impl.h +++ b/media/filters/audio_renderer_impl.h @@ -28,7 +28,6 @@ #include "media/base/audio_decoder.h" #include "media/base/audio_renderer.h" #include "media/base/audio_renderer_sink.h" -#include "media/base/buffers.h" #include "media/base/decryptor.h" #include "media/filters/audio_renderer_algorithm.h" @@ -84,11 +83,11 @@ class MEDIA_EXPORT AudioRendererImpl // Callback from the audio decoder delivering decoded audio samples. void DecodedAudioReady(AudioDecoder::Status status, - const scoped_refptr<Buffer>& buffer); + const scoped_refptr<DataBuffer>& buffer); // Handles buffers that come out of |splicer_|. // Returns true if more buffers are needed. - bool HandleSplicerBuffer(const scoped_refptr<Buffer>& buffer); + bool HandleSplicerBuffer(const scoped_refptr<DataBuffer>& buffer); // Helper functions for AudioDecoder::Status values passed to // DecodedAudioReady(). @@ -140,7 +139,7 @@ class MEDIA_EXPORT AudioRendererImpl // Returns true if the data in the buffer is all before // |preroll_timestamp_|. This can only return true while // in the kPrerolling state. - bool IsBeforePrerollTime(const scoped_refptr<Buffer>& buffer); + bool IsBeforePrerollTime(const scoped_refptr<DataBuffer>& buffer); // Called when |decoder_selector_| selected the |selected_decoder|. // |decrypting_demuxer_stream| was also populated if a DecryptingDemuxerStream diff --git a/media/filters/decrypting_audio_decoder.cc b/media/filters/decrypting_audio_decoder.cc index 10232f2..9775bb9 100644 --- a/media/filters/decrypting_audio_decoder.cc +++ b/media/filters/decrypting_audio_decoder.cc @@ -250,7 +250,7 @@ void DecryptingAudioDecoder::DoRead(const ReadCB& read_cb) { // Return empty (end-of-stream) frames if decoding has finished. if (state_ == kDecodeFinished) { - read_cb.Run(kOk, scoped_refptr<Buffer>(new DataBuffer(0))); + read_cb.Run(kOk, new DataBuffer(0)); return; } @@ -421,8 +421,7 @@ void DecryptingAudioDecoder::DoDeliverFrame( DVLOG(2) << "DoDeliverFrame() - kNeedMoreData"; if (scoped_pending_buffer_to_decode->IsEndOfStream()) { state_ = kDecodeFinished; - base::ResetAndReturn(&read_cb_).Run( - kOk, scoped_refptr<Buffer>(new DataBuffer(0))); + base::ResetAndReturn(&read_cb_).Run(kOk, (new DataBuffer(0))); return; } @@ -482,7 +481,7 @@ void DecryptingAudioDecoder::EnqueueFrames( for (Decryptor::AudioBuffers::iterator iter = queued_audio_frames_.begin(); iter != queued_audio_frames_.end(); ++iter) { - scoped_refptr<Buffer>& frame = *iter; + scoped_refptr<DataBuffer>& frame = *iter; DCHECK(!frame->IsEndOfStream()) << "EOS frame returned."; DCHECK_GT(frame->GetDataSize(), 0) << "Empty frame returned."; diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc index a601fe6..d493481 100644 --- a/media/filters/decrypting_audio_decoder_unittest.cc +++ b/media/filters/decrypting_audio_decoder_unittest.cc @@ -122,7 +122,7 @@ class DecryptingAudioDecoderTest : public testing::Test { void ReadAndExpectFrameReadyWith( AudioDecoder::Status status, - const scoped_refptr<Buffer>& audio_frame) { + const scoped_refptr<DataBuffer>& audio_frame) { if (status != AudioDecoder::kOk) EXPECT_CALL(*this, FrameReady(status, IsNull())); else if (audio_frame->IsEndOfStream()) @@ -217,7 +217,7 @@ class DecryptingAudioDecoderTest : public testing::Test { MOCK_METHOD1(RequestDecryptorNotification, void(const DecryptorReadyCB&)); MOCK_METHOD2(FrameReady, void(AudioDecoder::Status, - const scoped_refptr<Buffer>&)); + const scoped_refptr<DataBuffer>&)); MessageLoop message_loop_; scoped_refptr<DecryptingAudioDecoder> decoder_; @@ -233,8 +233,8 @@ class DecryptingAudioDecoderTest : public testing::Test { // Constant buffer/frames to be returned by the |demuxer_| and |decryptor_|. scoped_refptr<DecoderBuffer> encrypted_buffer_; - scoped_refptr<Buffer> decoded_frame_; - scoped_refptr<Buffer> end_of_stream_frame_; + scoped_refptr<DataBuffer> decoded_frame_; + scoped_refptr<DataBuffer> end_of_stream_frame_; Decryptor::AudioBuffers decoded_frame_list_; private: diff --git a/media/filters/ffmpeg_audio_decoder.cc b/media/filters/ffmpeg_audio_decoder.cc index 3f1e81a..912aa42 100644 --- a/media/filters/ffmpeg_audio_decoder.cc +++ b/media/filters/ffmpeg_audio_decoder.cc @@ -23,11 +23,12 @@ namespace media { // Helper structure for managing multiple decoded audio frames per packet. struct QueuedAudioBuffer { AudioDecoder::Status status; - scoped_refptr<Buffer> buffer; + scoped_refptr<DataBuffer> buffer; }; // Returns true if the decode result was end of stream. -static inline bool IsEndOfStream(int result, int decoded_size, Buffer* input) { +static inline bool IsEndOfStream(int result, int decoded_size, + const scoped_refptr<DecoderBuffer>& input) { // Three conditions to meet to declare end of stream for this decoder: // 1. FFmpeg didn't read anything. // 2. FFmpeg didn't output anything. diff --git a/media/filters/ffmpeg_audio_decoder_unittest.cc b/media/filters/ffmpeg_audio_decoder_unittest.cc index 6c3a2e0..605e007 100644 --- a/media/filters/ffmpeg_audio_decoder_unittest.cc +++ b/media/filters/ffmpeg_audio_decoder_unittest.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/message_loop.h" #include "base/stringprintf.h" +#include "media/base/data_buffer.h" #include "media/base/decoder_buffer.h" #include "media/base/mock_filters.h" #include "media/base/test_data_util.h" @@ -94,7 +95,7 @@ class FFmpegAudioDecoderTest : public testing::Test { } void DecodeFinished(AudioDecoder::Status status, - const scoped_refptr<Buffer>& buffer) { + const scoped_refptr<DataBuffer>& buffer) { decoded_audio_.push_back(buffer); } @@ -120,7 +121,7 @@ class FFmpegAudioDecoderTest : public testing::Test { scoped_refptr<DecoderBuffer> vorbis_extradata_; std::deque<scoped_refptr<DecoderBuffer> > encoded_audio_; - std::deque<scoped_refptr<Buffer> > decoded_audio_; + std::deque<scoped_refptr<DataBuffer> > decoded_audio_; AudioDecoderConfig config_; }; diff --git a/media/filters/gpu_video_decoder.cc b/media/filters/gpu_video_decoder.cc index f36bff0..287c1f1 100644 --- a/media/filters/gpu_video_decoder.cc +++ b/media/filters/gpu_video_decoder.cc @@ -300,7 +300,7 @@ void GpuVideoDecoder::RequestBufferDecode( } void GpuVideoDecoder::RecordBufferData( - const BitstreamBuffer& bitstream_buffer, const Buffer& buffer) { + const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer) { input_buffer_data_.push_front(BufferData( bitstream_buffer.id(), buffer.GetTimestamp(), demuxer_stream_->video_decoder_config().visible_rect(), diff --git a/media/filters/gpu_video_decoder.h b/media/filters/gpu_video_decoder.h index b7f2632..beeda7e 100644 --- a/media/filters/gpu_video_decoder.h +++ b/media/filters/gpu_video_decoder.h @@ -125,7 +125,7 @@ class MEDIA_EXPORT GpuVideoDecoder void ReusePictureBuffer(int64 picture_buffer_id); void RecordBufferData( - const BitstreamBuffer& bitstream_buffer, const Buffer& buffer); + const BitstreamBuffer& bitstream_buffer, const DecoderBuffer& buffer); void GetBufferData(int32 id, base::TimeDelta* timetamp, gfx::Rect* visible_rect, gfx::Size* natural_size); diff --git a/media/filters/opus_audio_decoder.cc b/media/filters/opus_audio_decoder.cc index 8837d2c..711bbc8 100644 --- a/media/filters/opus_audio_decoder.cc +++ b/media/filters/opus_audio_decoder.cc @@ -11,6 +11,7 @@ #include "base/sys_byteorder.h" #include "media/base/audio_decoder_config.h" #include "media/base/audio_timestamp_helper.h" +#include "media/base/buffers.h" #include "media/base/data_buffer.h" #include "media/base/decoder_buffer.h" #include "media/base/demuxer.h" @@ -29,7 +30,8 @@ static uint16 ReadLE16(const uint8* data, size_t data_size, int read_offset) { } // Returns true if the decode result was end of stream. -static inline bool IsEndOfStream(int decoded_size, Buffer* input) { +static inline bool IsEndOfStream(int decoded_size, + const scoped_refptr<DecoderBuffer>& input) { // Two conditions to meet to declare end of stream for this decoder: // 1. Opus didn't output anything. // 2. An end of stream buffer is received. diff --git a/media/media.gyp b/media/media.gyp index 17447e5..f0c03e2 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -194,7 +194,6 @@ 'base/bitstream_buffer.h', 'base/bit_reader.cc', 'base/bit_reader.h', - 'base/buffers.cc', 'base/buffers.h', 'base/byte_queue.cc', 'base/byte_queue.h', @@ -692,7 +691,6 @@ 'base/audio_timestamp_helper_unittest.cc', 'base/bit_reader_unittest.cc', 'base/bind_to_loop_unittest.cc', - 'base/buffers_unittest.cc', 'base/channel_mixer_unittest.cc', 'base/clock_unittest.cc', 'base/data_buffer_unittest.cc', diff --git a/media/mp4/track_run_iterator.cc b/media/mp4/track_run_iterator.cc index 5538562..a7f64cd 100644 --- a/media/mp4/track_run_iterator.cc +++ b/media/mp4/track_run_iterator.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "media/base/buffers.h" #include "media/base/stream_parser_buffer.h" #include "media/mp4/rcheck.h" diff --git a/media/webm/webm_cluster_parser.cc b/media/webm/webm_cluster_parser.cc index 1506ad2..785a89d 100644 --- a/media/webm/webm_cluster_parser.cc +++ b/media/webm/webm_cluster_parser.cc @@ -7,7 +7,7 @@ #include <vector> #include "base/logging.h" -#include "media/base/data_buffer.h" +#include "media/base/buffers.h" #include "media/base/decrypt_config.h" #include "media/webm/webm_constants.h" |