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/base | |
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/base')
-rw-r--r-- | media/base/audio_decoder.h | 4 | ||||
-rw-r--r-- | media/base/audio_splicer.cc | 8 | ||||
-rw-r--r-- | media/base/audio_splicer.h | 10 | ||||
-rw-r--r-- | media/base/audio_splicer_unittest.cc | 76 | ||||
-rw-r--r-- | media/base/buffers.cc | 20 | ||||
-rw-r--r-- | media/base/buffers.h | 44 | ||||
-rw-r--r-- | media/base/buffers_unittest.cc | 85 | ||||
-rw-r--r-- | media/base/data_buffer.cc | 37 | ||||
-rw-r--r-- | media/base/data_buffer.h | 47 | ||||
-rw-r--r-- | media/base/data_buffer_unittest.cc | 41 | ||||
-rw-r--r-- | media/base/decoder_buffer.cc | 34 | ||||
-rw-r--r-- | media/base/decoder_buffer.h | 54 | ||||
-rw-r--r-- | media/base/decoder_buffer_queue.cc | 1 | ||||
-rw-r--r-- | media/base/decoder_buffer_queue_unittest.cc | 1 | ||||
-rw-r--r-- | media/base/decryptor.h | 4 | ||||
-rw-r--r-- | media/base/seekable_buffer.cc | 8 | ||||
-rw-r--r-- | media/base/seekable_buffer.h | 6 | ||||
-rw-r--r-- | media/base/stream_parser_buffer.cc | 1 |
18 files changed, 225 insertions, 256 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 { |