OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/rand_util.h" | 6 #include "base/rand_util.h" |
7 #include "media/cast/net/rtp/rtp_defines.h" | 7 #include "media/cast/net/rtp/rtp_defines.h" |
8 #include "media/cast/net/rtp/rtp_packet_builder.h" | 8 #include "media/cast/net/rtp/rtp_packet_builder.h" |
9 #include "media/cast/net/rtp/rtp_parser.h" | 9 #include "media/cast/net/rtp/rtp_parser.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 namespace cast { | 13 namespace cast { |
14 | 14 |
15 static const size_t kPacketLength = 1500; | 15 static const size_t kPacketLength = 1500; |
16 static const int kTestPayloadType = 127; | 16 static const int kTestPayloadType = 127; |
17 static const uint32 kTestSsrc = 1234; | 17 static const uint32_t kTestSsrc = 1234; |
18 static const uint32 kTestTimestamp = 111111; | 18 static const uint32_t kTestTimestamp = 111111; |
19 static const uint16 kTestSeqNum = 4321; | 19 static const uint16_t kTestSeqNum = 4321; |
20 static const uint8 kRefFrameId = 17; | 20 static const uint8_t kRefFrameId = 17; |
21 | 21 |
22 class RtpParserTest : public ::testing::Test { | 22 class RtpParserTest : public ::testing::Test { |
23 protected: | 23 protected: |
24 RtpParserTest() : rtp_parser_(kTestSsrc, kTestPayloadType) { | 24 RtpParserTest() : rtp_parser_(kTestSsrc, kTestPayloadType) { |
25 packet_builder_.SetSsrc(kTestSsrc); | 25 packet_builder_.SetSsrc(kTestSsrc); |
26 packet_builder_.SetSequenceNumber(kTestSeqNum); | 26 packet_builder_.SetSequenceNumber(kTestSeqNum); |
27 packet_builder_.SetTimestamp(kTestTimestamp); | 27 packet_builder_.SetTimestamp(kTestTimestamp); |
28 packet_builder_.SetPayloadType(kTestPayloadType); | 28 packet_builder_.SetPayloadType(kTestPayloadType); |
29 packet_builder_.SetMarkerBit(true); // Only one packet. | 29 packet_builder_.SetMarkerBit(true); // Only one packet. |
30 cast_header_.sender_ssrc = kTestSsrc; | 30 cast_header_.sender_ssrc = kTestSsrc; |
31 cast_header_.sequence_number = kTestSeqNum; | 31 cast_header_.sequence_number = kTestSeqNum; |
32 cast_header_.rtp_timestamp = kTestTimestamp; | 32 cast_header_.rtp_timestamp = kTestTimestamp; |
33 cast_header_.payload_type = kTestPayloadType; | 33 cast_header_.payload_type = kTestPayloadType; |
34 cast_header_.marker = true; | 34 cast_header_.marker = true; |
35 } | 35 } |
36 | 36 |
37 ~RtpParserTest() override {} | 37 ~RtpParserTest() override {} |
38 | 38 |
39 void ExpectParsesPacket() { | 39 void ExpectParsesPacket() { |
40 RtpCastHeader parsed_header; | 40 RtpCastHeader parsed_header; |
41 const uint8* payload = NULL; | 41 const uint8_t* payload = NULL; |
42 size_t payload_size = static_cast<size_t>(-1); | 42 size_t payload_size = static_cast<size_t>(-1); |
43 EXPECT_TRUE(rtp_parser_.ParsePacket( | 43 EXPECT_TRUE(rtp_parser_.ParsePacket( |
44 packet_, kPacketLength, &parsed_header, &payload, &payload_size)); | 44 packet_, kPacketLength, &parsed_header, &payload, &payload_size)); |
45 | 45 |
46 EXPECT_EQ(cast_header_.marker, parsed_header.marker); | 46 EXPECT_EQ(cast_header_.marker, parsed_header.marker); |
47 EXPECT_EQ(cast_header_.payload_type, parsed_header.payload_type); | 47 EXPECT_EQ(cast_header_.payload_type, parsed_header.payload_type); |
48 EXPECT_EQ(cast_header_.sequence_number, parsed_header.sequence_number); | 48 EXPECT_EQ(cast_header_.sequence_number, parsed_header.sequence_number); |
49 EXPECT_EQ(cast_header_.rtp_timestamp, parsed_header.rtp_timestamp); | 49 EXPECT_EQ(cast_header_.rtp_timestamp, parsed_header.rtp_timestamp); |
50 EXPECT_EQ(cast_header_.sender_ssrc, parsed_header.sender_ssrc); | 50 EXPECT_EQ(cast_header_.sender_ssrc, parsed_header.sender_ssrc); |
51 | 51 |
52 EXPECT_EQ(cast_header_.is_key_frame, parsed_header.is_key_frame); | 52 EXPECT_EQ(cast_header_.is_key_frame, parsed_header.is_key_frame); |
53 EXPECT_EQ(cast_header_.frame_id, parsed_header.frame_id); | 53 EXPECT_EQ(cast_header_.frame_id, parsed_header.frame_id); |
54 EXPECT_EQ(cast_header_.packet_id, parsed_header.packet_id); | 54 EXPECT_EQ(cast_header_.packet_id, parsed_header.packet_id); |
55 EXPECT_EQ(cast_header_.max_packet_id, parsed_header.max_packet_id); | 55 EXPECT_EQ(cast_header_.max_packet_id, parsed_header.max_packet_id); |
56 EXPECT_EQ(cast_header_.reference_frame_id, | 56 EXPECT_EQ(cast_header_.reference_frame_id, |
57 parsed_header.reference_frame_id); | 57 parsed_header.reference_frame_id); |
58 | 58 |
59 EXPECT_TRUE(payload); | 59 EXPECT_TRUE(payload); |
60 EXPECT_NE(static_cast<size_t>(-1), payload_size); | 60 EXPECT_NE(static_cast<size_t>(-1), payload_size); |
61 } | 61 } |
62 | 62 |
63 void ExpectDoesNotParsePacket() { | 63 void ExpectDoesNotParsePacket() { |
64 RtpCastHeader parsed_header; | 64 RtpCastHeader parsed_header; |
65 const uint8* payload = NULL; | 65 const uint8_t* payload = NULL; |
66 size_t payload_size = static_cast<size_t>(-1); | 66 size_t payload_size = static_cast<size_t>(-1); |
67 EXPECT_FALSE(rtp_parser_.ParsePacket( | 67 EXPECT_FALSE(rtp_parser_.ParsePacket( |
68 packet_, kPacketLength, &parsed_header, &payload, &payload_size)); | 68 packet_, kPacketLength, &parsed_header, &payload, &payload_size)); |
69 } | 69 } |
70 | 70 |
71 RtpPacketBuilder packet_builder_; | 71 RtpPacketBuilder packet_builder_; |
72 uint8 packet_[kPacketLength]; | 72 uint8_t packet_[kPacketLength]; |
73 RtpParser rtp_parser_; | 73 RtpParser rtp_parser_; |
74 RtpCastHeader cast_header_; | 74 RtpCastHeader cast_header_; |
75 }; | 75 }; |
76 | 76 |
77 TEST_F(RtpParserTest, ParseDefaultCastPacket) { | 77 TEST_F(RtpParserTest, ParseDefaultCastPacket) { |
78 packet_builder_.BuildHeader(packet_, kPacketLength); | 78 packet_builder_.BuildHeader(packet_, kPacketLength); |
79 ExpectParsesPacket(); | 79 ExpectParsesPacket(); |
80 } | 80 } |
81 | 81 |
82 TEST_F(RtpParserTest, ParseNonDefaultCastPacket) { | 82 TEST_F(RtpParserTest, ParseNonDefaultCastPacket) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 TEST_F(RtpParserTest, ParseCastPacketWithSpecificFrameReference) { | 158 TEST_F(RtpParserTest, ParseCastPacketWithSpecificFrameReference) { |
159 packet_builder_.SetFrameIds(kRefFrameId + 3, kRefFrameId); | 159 packet_builder_.SetFrameIds(kRefFrameId + 3, kRefFrameId); |
160 packet_builder_.BuildHeader(packet_, kPacketLength); | 160 packet_builder_.BuildHeader(packet_, kPacketLength); |
161 cast_header_.frame_id = kRefFrameId + 3; | 161 cast_header_.frame_id = kRefFrameId + 3; |
162 cast_header_.reference_frame_id = kRefFrameId; | 162 cast_header_.reference_frame_id = kRefFrameId; |
163 ExpectParsesPacket(); | 163 ExpectParsesPacket(); |
164 } | 164 } |
165 | 165 |
166 TEST_F(RtpParserTest, ParseExpandingFrameIdTo32Bits) { | 166 TEST_F(RtpParserTest, ParseExpandingFrameIdTo32Bits) { |
167 const uint32 kMaxFrameId = 1000; | 167 const uint32_t kMaxFrameId = 1000; |
168 packet_builder_.SetKeyFrame(true); | 168 packet_builder_.SetKeyFrame(true); |
169 cast_header_.is_key_frame = true; | 169 cast_header_.is_key_frame = true; |
170 for (uint32 frame_id = 0; frame_id <= kMaxFrameId; ++frame_id) { | 170 for (uint32_t frame_id = 0; frame_id <= kMaxFrameId; ++frame_id) { |
171 packet_builder_.SetFrameIds(frame_id, frame_id); | 171 packet_builder_.SetFrameIds(frame_id, frame_id); |
172 packet_builder_.BuildHeader(packet_, kPacketLength); | 172 packet_builder_.BuildHeader(packet_, kPacketLength); |
173 cast_header_.frame_id = frame_id; | 173 cast_header_.frame_id = frame_id; |
174 cast_header_.reference_frame_id = frame_id; | 174 cast_header_.reference_frame_id = frame_id; |
175 ExpectParsesPacket(); | 175 ExpectParsesPacket(); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 TEST_F(RtpParserTest, ParseExpandingReferenceFrameIdTo32Bits) { | 179 TEST_F(RtpParserTest, ParseExpandingReferenceFrameIdTo32Bits) { |
180 const uint32 kMaxFrameId = 1000; | 180 const uint32_t kMaxFrameId = 1000; |
181 const uint32 kMaxBackReferenceOffset = 10; | 181 const uint32_t kMaxBackReferenceOffset = 10; |
182 packet_builder_.SetKeyFrame(false); | 182 packet_builder_.SetKeyFrame(false); |
183 cast_header_.is_key_frame = false; | 183 cast_header_.is_key_frame = false; |
184 for (uint32 frame_id = kMaxBackReferenceOffset; | 184 for (uint32_t frame_id = kMaxBackReferenceOffset; frame_id <= kMaxFrameId; |
185 frame_id <= kMaxFrameId; ++frame_id) { | 185 ++frame_id) { |
186 const uint32 reference_frame_id = | 186 const uint32_t reference_frame_id = |
187 frame_id - base::RandInt(1, kMaxBackReferenceOffset); | 187 frame_id - base::RandInt(1, kMaxBackReferenceOffset); |
188 packet_builder_.SetFrameIds(frame_id, reference_frame_id); | 188 packet_builder_.SetFrameIds(frame_id, reference_frame_id); |
189 packet_builder_.BuildHeader(packet_, kPacketLength); | 189 packet_builder_.BuildHeader(packet_, kPacketLength); |
190 cast_header_.frame_id = frame_id; | 190 cast_header_.frame_id = frame_id; |
191 cast_header_.reference_frame_id = reference_frame_id; | 191 cast_header_.reference_frame_id = reference_frame_id; |
192 ExpectParsesPacket(); | 192 ExpectParsesPacket(); |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 } // namespace cast | 196 } // namespace cast |
197 } // namespace media | 197 } // namespace media |
OLD | NEW |