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