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"
11 class FrameBufferTest
: public ::testing::Test
{
14 payload_
.assign(kMaxIpPacketSize
, 0);
17 virtual ~FrameBufferTest() {}
20 std::vector
<uint8
> payload_
;
21 RtpCastHeader rtp_header_
;
23 DISALLOW_COPY_AND_ASSIGN(FrameBufferTest
);
26 TEST_F(FrameBufferTest
, OnePacketInsertSanity
) {
27 rtp_header_
.rtp_timestamp
= 3000;
28 rtp_header_
.is_key_frame
= true;
29 rtp_header_
.frame_id
= 5;
30 rtp_header_
.reference_frame_id
= 5;
31 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
32 transport::EncodedVideoFrame frame
;
33 EXPECT_TRUE(buffer_
.GetEncodedVideoFrame(&frame
));
34 EXPECT_EQ(5u, frame
.frame_id
);
35 EXPECT_TRUE(frame
.key_frame
);
36 EXPECT_EQ(3000u, frame
.rtp_timestamp
);
39 TEST_F(FrameBufferTest
, EmptyBuffer
) {
40 EXPECT_FALSE(buffer_
.Complete());
41 EXPECT_FALSE(buffer_
.is_key_frame());
42 transport::EncodedVideoFrame frame
;
43 EXPECT_FALSE(buffer_
.GetEncodedVideoFrame(&frame
));
46 TEST_F(FrameBufferTest
, DefaultOnePacketFrame
) {
47 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
48 EXPECT_TRUE(buffer_
.Complete());
49 EXPECT_FALSE(buffer_
.is_key_frame());
50 transport::EncodedVideoFrame frame
;
51 EXPECT_TRUE(buffer_
.GetEncodedVideoFrame(&frame
));
52 EXPECT_EQ(payload_
.size(), frame
.data
.size());
55 TEST_F(FrameBufferTest
, MultiplePacketFrame
) {
56 rtp_header_
.is_key_frame
= true;
57 rtp_header_
.max_packet_id
= 2;
58 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
59 ++rtp_header_
.packet_id
;
60 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
61 ++rtp_header_
.packet_id
;
62 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
63 ++rtp_header_
.packet_id
;
64 EXPECT_TRUE(buffer_
.Complete());
65 EXPECT_TRUE(buffer_
.is_key_frame());
66 transport::EncodedVideoFrame frame
;
67 EXPECT_TRUE(buffer_
.GetEncodedVideoFrame(&frame
));
68 EXPECT_EQ(3 * payload_
.size(), frame
.data
.size());
71 TEST_F(FrameBufferTest
, IncompleteFrame
) {
72 rtp_header_
.max_packet_id
= 4;
73 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
74 ++rtp_header_
.packet_id
;
75 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
76 ++rtp_header_
.packet_id
;
77 // Increment again - skip packet #2.
78 ++rtp_header_
.packet_id
;
79 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
80 ++rtp_header_
.packet_id
;
81 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
82 EXPECT_FALSE(buffer_
.Complete());
83 // Insert missing packet.
84 rtp_header_
.packet_id
= 2;
85 buffer_
.InsertPacket(payload_
.data(), payload_
.size(), rtp_header_
);
86 EXPECT_TRUE(buffer_
.Complete());