Skip to content

Commit

Permalink
Eliminate media::Buffer as a base class for media::DecoderBuffer and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
scherkus@chromium.org committed Jan 15, 2013
1 parent 48697d8 commit b334173
Show file tree
Hide file tree
Showing 35 changed files with 264 additions and 287 deletions.
4 changes: 2 additions & 2 deletions media/base/audio_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace media {

class Buffer;
class DataBuffer;
class DemuxerStream;

class MEDIA_EXPORT AudioDecoder
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions media/base/audio_splicer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions media/base/audio_splicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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_;

Expand All @@ -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);
Expand Down
76 changes: 38 additions & 38 deletions media/base/audio_splicer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -57,38 +57,38 @@ 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());
EXPECT_EQ(input_3->GetDataSize(), output_3->GetDataSize());
}

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());

Expand All @@ -102,29 +102,29 @@ 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());
EXPECT_EQ(input_2->GetDataSize(), output_2->GetDataSize());
}

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());
Expand All @@ -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());
Expand All @@ -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.
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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));
Expand All @@ -269,22 +269,22 @@ 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|.
const int kOverlapSize = input_1->GetDataSize() / 4;
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.
Expand Down Expand Up @@ -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|.
Expand All @@ -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.
Expand Down
20 changes: 0 additions & 20 deletions media/base/buffers.cc

This file was deleted.

Loading

0 comments on commit b334173

Please sign in to comment.