OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | 10 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 EXPECT_TRUE(packet.HasRawExtension(kTransmissionOffsetExtensionId)); | 357 EXPECT_TRUE(packet.HasRawExtension(kTransmissionOffsetExtensionId)); |
358 | 358 |
359 int32_t time_offset = 0; | 359 int32_t time_offset = 0; |
360 auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId); | 360 auto raw_extension = packet.GetRawExtension(kTransmissionOffsetExtensionId); |
361 EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes); | 361 EXPECT_EQ(raw_extension.size(), TransmissionOffset::kValueSizeBytes); |
362 EXPECT_TRUE(TransmissionOffset::Parse(raw_extension, &time_offset)); | 362 EXPECT_TRUE(TransmissionOffset::Parse(raw_extension, &time_offset)); |
363 | 363 |
364 EXPECT_EQ(time_offset, kTimeOffset); | 364 EXPECT_EQ(time_offset, kTimeOffset); |
365 } | 365 } |
366 | 366 |
| 367 TEST(RtpPacketTest, ParseDynamicSizeExtension) { |
| 368 // clang-format off |
| 369 const uint8_t kPacket1[] = { |
| 370 0x90, kPayloadType, 0x00, kSeqNum, |
| 371 0x65, 0x43, 0x12, 0x78, // Timestamp. |
| 372 0x12, 0x34, 0x56, 0x78, // Ssrc. |
| 373 0xbe, 0xde, 0x00, 0x02, // Extensions block of size 2x32bit words. |
| 374 0x21, 'H', 'D', // Extension with id = 2, size = (1+1). |
| 375 0x12, 'r', 't', 'x', // Extension with id = 1, size = (2+1). |
| 376 0x00}; // Extension padding. |
| 377 const uint8_t kPacket2[] = { |
| 378 0x90, kPayloadType, 0x00, kSeqNum, |
| 379 0x65, 0x43, 0x12, 0x78, // Timestamp. |
| 380 0x12, 0x34, 0x56, 0x79, // Ssrc. |
| 381 0xbe, 0xde, 0x00, 0x01, // Extensions block of size 1x32bit words. |
| 382 0x11, 'H', 'D', // Extension with id = 1, size = (1+1). |
| 383 0x00}; // Extension padding. |
| 384 // clang-format on |
| 385 RtpPacketReceived::ExtensionManager extensions; |
| 386 extensions.Register<RtpStreamId>(1); |
| 387 extensions.Register<RepairedRtpStreamId>(2); |
| 388 RtpPacketReceived packet(&extensions); |
| 389 ASSERT_TRUE(packet.Parse(kPacket1, sizeof(kPacket1))); |
| 390 |
| 391 std::string rsid; |
| 392 EXPECT_TRUE(packet.GetExtension<RtpStreamId>(&rsid)); |
| 393 EXPECT_EQ(rsid, "rtx"); |
| 394 |
| 395 std::string repaired_rsid; |
| 396 EXPECT_TRUE(packet.GetExtension<RepairedRtpStreamId>(&repaired_rsid)); |
| 397 EXPECT_EQ(repaired_rsid, "HD"); |
| 398 |
| 399 // Parse another packet with RtpStreamId extension of different size. |
| 400 ASSERT_TRUE(packet.Parse(kPacket2, sizeof(kPacket2))); |
| 401 EXPECT_TRUE(packet.GetExtension<RtpStreamId>(&rsid)); |
| 402 EXPECT_EQ(rsid, "HD"); |
| 403 EXPECT_FALSE(packet.GetExtension<RepairedRtpStreamId>(&repaired_rsid)); |
| 404 } |
| 405 |
367 TEST(RtpPacketTest, RawExtensionFunctionsAcceptZeroIdAndReturnFalse) { | 406 TEST(RtpPacketTest, RawExtensionFunctionsAcceptZeroIdAndReturnFalse) { |
368 RtpPacketReceived::ExtensionManager extensions; | 407 RtpPacketReceived::ExtensionManager extensions; |
369 RtpPacketReceived packet(&extensions); | 408 RtpPacketReceived packet(&extensions); |
370 // Use ExtensionManager to set kInvalidId to 0 to demonstrate natural way for | 409 // Use ExtensionManager to set kInvalidId to 0 to demonstrate natural way for |
371 // using zero value as a parameter to Packet::*RawExtension functions. | 410 // using zero value as a parameter to Packet::*RawExtension functions. |
372 const int kInvalidId = extensions.GetId(TransmissionOffset::kId); | 411 const int kInvalidId = extensions.GetId(TransmissionOffset::kId); |
373 ASSERT_EQ(kInvalidId, 0); | 412 ASSERT_EQ(kInvalidId, 0); |
374 | 413 |
375 ASSERT_TRUE(packet.Parse(kPacket, sizeof(kPacket))); | 414 ASSERT_TRUE(packet.Parse(kPacket, sizeof(kPacket))); |
376 | 415 |
377 EXPECT_FALSE(packet.HasRawExtension(kInvalidId)); | 416 EXPECT_FALSE(packet.HasRawExtension(kInvalidId)); |
378 EXPECT_THAT(packet.GetRawExtension(kInvalidId), IsEmpty()); | 417 EXPECT_THAT(packet.GetRawExtension(kInvalidId), IsEmpty()); |
379 const uint8_t kExtension[] = {'e', 'x', 't'}; | 418 const uint8_t kExtension[] = {'e', 'x', 't'}; |
380 EXPECT_FALSE(packet.SetRawExtension(kInvalidId, kExtension)); | 419 EXPECT_FALSE(packet.SetRawExtension(kInvalidId, kExtension)); |
381 EXPECT_THAT(packet.AllocateRawExtension(kInvalidId, 3), IsEmpty()); | 420 EXPECT_THAT(packet.AllocateRawExtension(kInvalidId, 3), IsEmpty()); |
382 } | 421 } |
383 | 422 |
384 } // namespace webrtc | 423 } // namespace webrtc |
OLD | NEW |