This source file includes following definitions.
- CreateFrame
- CheckPoolSize
- TEST_F
- TEST_F
- TEST_F
#include "media/base/video_frame_pool.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace media {
class VideoFramePoolTest : public ::testing::Test {
public:
VideoFramePoolTest() : pool_(new VideoFramePool()) {}
scoped_refptr<VideoFrame> CreateFrame(VideoFrame::Format format,
int timestamp_ms) {
gfx::Size coded_size(320,240);
gfx::Rect visible_rect(coded_size);
gfx::Size natural_size(coded_size);
scoped_refptr<VideoFrame> frame =
pool_->CreateFrame(
format, coded_size, visible_rect, natural_size,
base::TimeDelta::FromMilliseconds(timestamp_ms));
EXPECT_EQ(format, frame->format());
EXPECT_EQ(base::TimeDelta::FromMilliseconds(timestamp_ms),
frame->GetTimestamp());
EXPECT_EQ(coded_size, frame->coded_size());
EXPECT_EQ(visible_rect, frame->visible_rect());
EXPECT_EQ(natural_size, frame->natural_size());
return frame;
}
void CheckPoolSize(size_t size) const {
EXPECT_EQ(size, pool_->GetPoolSizeForTesting());
}
protected:
scoped_ptr<VideoFramePool> pool_;
};
TEST_F(VideoFramePoolTest, SimpleFrameReuse) {
scoped_refptr<VideoFrame> frame = CreateFrame(VideoFrame::YV12, 10);
const uint8* old_y_data = frame->data(VideoFrame::kYPlane);
frame = NULL;
scoped_refptr<VideoFrame> new_frame = CreateFrame(VideoFrame::YV12, 20);
EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane));
}
TEST_F(VideoFramePoolTest, SimpleFormatChange) {
scoped_refptr<VideoFrame> frame_a = CreateFrame(VideoFrame::YV12, 10);
scoped_refptr<VideoFrame> frame_b = CreateFrame(VideoFrame::YV12, 10);
frame_a = NULL;
frame_b = NULL;
CheckPoolSize(2u);
scoped_refptr<VideoFrame> new_frame = CreateFrame(VideoFrame::YV12A, 10);
CheckPoolSize(0u);
}
TEST_F(VideoFramePoolTest, FrameValidAfterPoolDestruction) {
scoped_refptr<VideoFrame> frame = CreateFrame(VideoFrame::YV12, 10);
pool_.reset();
memset(frame->data(VideoFrame::kYPlane), 0xff,
frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane));
}
}