cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / cast / framer / frame_buffer_unittest.cc
blob26998f5fd7ea3cde311b8747637e2fdd5834fdf8
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/cast/framer/frame_buffer.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace media {
9 namespace cast {
11 class FrameBufferTest : public ::testing::Test {
12 protected:
13 FrameBufferTest() {}
15 ~FrameBufferTest() {}
17 void SetUp() {
18 payload_.assign(kIpPacketSize, 0);
20 // Build a default one packet frame - populate webrtc header.
21 rtp_header_.is_key_frame = false;
22 rtp_header_.frame_id = 0;
23 rtp_header_.packet_id = 0;
24 rtp_header_.max_packet_id = 0;
25 rtp_header_.is_reference = false;
26 rtp_header_.reference_frame_id = 0;
29 FrameBuffer buffer_;
30 std::vector<uint8> payload_;
31 RtpCastHeader rtp_header_;
34 TEST_F(FrameBufferTest, EmptyBuffer) {
35 EXPECT_FALSE(buffer_.Complete());
36 EXPECT_FALSE(buffer_.is_key_frame());
37 EncodedVideoFrame frame;
38 uint32 rtp_timestamp;
39 EXPECT_FALSE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
42 TEST_F(FrameBufferTest, DefaultOnePacketFrame) {
43 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
44 EXPECT_TRUE(buffer_.Complete());
45 EXPECT_FALSE(buffer_.is_key_frame());
46 EncodedVideoFrame frame;
47 uint32 rtp_timestamp;
48 EXPECT_TRUE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
49 EXPECT_EQ(payload_.size(), frame.data.size());
52 TEST_F(FrameBufferTest, MultiplePacketFrame) {
53 rtp_header_.is_key_frame = true;
54 rtp_header_.max_packet_id = 2;
55 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
56 ++rtp_header_.packet_id;
57 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
58 ++rtp_header_.packet_id;
59 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
60 ++rtp_header_.packet_id;
61 EXPECT_TRUE(buffer_.Complete());
62 EXPECT_TRUE(buffer_.is_key_frame());
63 EncodedVideoFrame frame;
64 uint32 rtp_timestamp;
65 EXPECT_TRUE(buffer_.GetEncodedVideoFrame(&frame, &rtp_timestamp));
66 EXPECT_EQ(3 * payload_.size(), frame.data.size());
69 TEST_F(FrameBufferTest, InCompleteFrame) {
70 rtp_header_.max_packet_id = 4;
71 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
72 ++rtp_header_.packet_id;
73 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
74 ++rtp_header_.packet_id;
75 // Increment again - skip packet #2.
76 ++rtp_header_.packet_id;
77 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
78 ++rtp_header_.packet_id;
79 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
80 EXPECT_FALSE(buffer_.Complete());
81 // Insert missing packet.
82 rtp_header_.packet_id = 2;
83 buffer_.InsertPacket(payload_.data(), payload_.size(), rtp_header_);
84 EXPECT_TRUE(buffer_.Complete());
87 } // namespace media
88 } // namespace cast