This source file includes following definitions.
- ToTimeDelta
- CreateBuffer
- CreateBuffer
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#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"
namespace media {
static base::TimeDelta ToTimeDelta(int seconds) {
if (seconds < 0)
return kNoTimestamp();
return base::TimeDelta::FromSeconds(seconds);
}
static scoped_refptr<DecoderBuffer> CreateBuffer(int timestamp) {
scoped_refptr<DecoderBuffer> buffer = new DecoderBuffer(0);
buffer->set_timestamp(ToTimeDelta(timestamp));
buffer->set_duration(ToTimeDelta(0));
return buffer;
}
static scoped_refptr<DecoderBuffer> CreateBuffer(int timestamp, int size) {
scoped_refptr<DecoderBuffer> buffer = new DecoderBuffer(size);
buffer->set_timestamp(ToTimeDelta(timestamp));
buffer->set_duration(ToTimeDelta(0));
return buffer;
}
TEST(DecoderBufferQueueTest, IsEmpty) {
DecoderBufferQueue queue;
EXPECT_TRUE(queue.IsEmpty());
queue.Push(CreateBuffer(0));
EXPECT_FALSE(queue.IsEmpty());
}
TEST(DecoderBufferQueueTest, Clear) {
DecoderBufferQueue queue;
queue.Push(CreateBuffer(0));
queue.Push(CreateBuffer(1));
EXPECT_FALSE(queue.IsEmpty());
EXPECT_EQ(1, queue.Duration().InSeconds());
queue.Clear();
EXPECT_TRUE(queue.IsEmpty());
EXPECT_EQ(0, queue.Duration().InSeconds());
}
TEST(DecoderBufferQueueTest, Duration) {
DecoderBufferQueue queue;
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Push(CreateBuffer(0));
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Push(CreateBuffer(1));
EXPECT_EQ(1, queue.Duration().InSeconds());
queue.Push(CreateBuffer(2));
EXPECT_EQ(2, queue.Duration().InSeconds());
queue.Push(CreateBuffer(4));
EXPECT_EQ(4, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(3, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(2, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
}
TEST(DecoderBufferQueueTest, Duration_OutOfOrder) {
DecoderBufferQueue queue;
queue.Push(CreateBuffer(10));
queue.Push(CreateBuffer(12));
EXPECT_EQ(2, queue.Duration().InSeconds());
queue.Push(CreateBuffer(8));
EXPECT_EQ(2, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Push(CreateBuffer(11));
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Push(CreateBuffer(14));
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Push(CreateBuffer(17));
EXPECT_EQ(3, queue.Duration().InSeconds());
}
TEST(DecoderBufferQueueTest, Duration_NoTimestamp) {
DecoderBufferQueue queue;
queue.Push(CreateBuffer(0));
queue.Push(CreateBuffer(4));
EXPECT_EQ(4, queue.Duration().InSeconds());
queue.Push(CreateBuffer(-1));
EXPECT_EQ(4, queue.Duration().InSeconds());
queue.Push(CreateBuffer(6));
EXPECT_EQ(6, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(2, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
queue.Pop();
EXPECT_EQ(0, queue.Duration().InSeconds());
}
TEST(DecoderBufferQueueTest, DataSize) {
DecoderBufferQueue queue;
EXPECT_EQ(queue.data_size(), 0u);
queue.Push(CreateBuffer(0, 1200u));
EXPECT_EQ(queue.data_size(), 1200u);
queue.Push(CreateBuffer(1, 1000u));
EXPECT_EQ(queue.data_size(), 2200u);
queue.Pop();
EXPECT_EQ(queue.data_size(), 1000u);
queue.Push(CreateBuffer(2, 999u));
queue.Push(CreateBuffer(3, 999u));
EXPECT_EQ(queue.data_size(), 2998u);
queue.Clear();
EXPECT_EQ(queue.data_size(), 0u);
queue.Push(CreateBuffer(4, 1400u));
EXPECT_EQ(queue.data_size(), 1400u);
}
}