OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
12 | 12 |
13 #include <limits> | 13 #include <limits> |
14 #include <memory> | |
15 | 14 |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
19 | 18 |
20 using webrtc::rtcp::TransportFeedback; | 19 using webrtc::rtcp::TransportFeedback; |
21 | 20 |
22 namespace webrtc { | 21 namespace webrtc { |
23 namespace { | 22 namespace { |
24 | 23 |
(...skipping 12 matching lines...) Expand all Loading... |
37 | 36 |
38 void WithExpectedSize(size_t expected_size) { | 37 void WithExpectedSize(size_t expected_size) { |
39 expected_size_ = expected_size; | 38 expected_size_ = expected_size; |
40 } | 39 } |
41 | 40 |
42 void WithDefaultDelta(int64_t delta) { default_delta_ = delta; } | 41 void WithDefaultDelta(int64_t delta) { default_delta_ = delta; } |
43 | 42 |
44 void WithInput(const uint16_t received_seq[], | 43 void WithInput(const uint16_t received_seq[], |
45 const int64_t received_ts[], | 44 const int64_t received_ts[], |
46 uint16_t length) { | 45 uint16_t length) { |
47 std::unique_ptr<int64_t[]> temp_deltas; | 46 rtc::scoped_ptr<int64_t[]> temp_deltas; |
48 if (received_ts == nullptr) { | 47 if (received_ts == nullptr) { |
49 temp_deltas.reset(new int64_t[length]); | 48 temp_deltas.reset(new int64_t[length]); |
50 GenerateDeltas(received_seq, length, temp_deltas.get()); | 49 GenerateDeltas(received_seq, length, temp_deltas.get()); |
51 received_ts = temp_deltas.get(); | 50 received_ts = temp_deltas.get(); |
52 } | 51 } |
53 | 52 |
54 expected_seq_.clear(); | 53 expected_seq_.clear(); |
55 expected_deltas_.clear(); | 54 expected_deltas_.clear(); |
56 feedback_.reset(new TransportFeedback()); | 55 feedback_.reset(new TransportFeedback()); |
57 | 56 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 last_seq = seq[i]; | 129 last_seq = seq[i]; |
131 | 130 |
132 deltas[i] = offset + (last_seq * default_delta_); | 131 deltas[i] = offset + (last_seq * default_delta_); |
133 } | 132 } |
134 } | 133 } |
135 | 134 |
136 std::vector<uint16_t> expected_seq_; | 135 std::vector<uint16_t> expected_seq_; |
137 std::vector<int64_t> expected_deltas_; | 136 std::vector<int64_t> expected_deltas_; |
138 size_t expected_size_; | 137 size_t expected_size_; |
139 int64_t default_delta_; | 138 int64_t default_delta_; |
140 std::unique_ptr<TransportFeedback> feedback_; | 139 rtc::scoped_ptr<TransportFeedback> feedback_; |
141 rtc::Buffer serialized_; | 140 rtc::Buffer serialized_; |
142 }; | 141 }; |
143 | 142 |
144 TEST(RtcpPacketTest, TransportFeedback_OneBitVector) { | 143 TEST(RtcpPacketTest, TransportFeedback_OneBitVector) { |
145 const uint16_t kReceived[] = {1, 2, 7, 8, 9, 10, 13}; | 144 const uint16_t kReceived[] = {1, 2, 7, 8, 9, 10, 13}; |
146 const size_t kLength = sizeof(kReceived) / sizeof(uint16_t); | 145 const size_t kLength = sizeof(kReceived) / sizeof(uint16_t); |
147 const size_t kExpectedSizeBytes = | 146 const size_t kExpectedSizeBytes = |
148 kHeaderSize + kStatusChunkSize + (kLength * kSmallDeltaSize); | 147 kHeaderSize + kStatusChunkSize + (kLength * kSmallDeltaSize); |
149 | 148 |
150 FeedbackTester test; | 149 FeedbackTester test; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 int64_t expected_time = num_samples * kTooSmallDelta; | 349 int64_t expected_time = num_samples * kTooSmallDelta; |
351 ++num_samples; | 350 ++num_samples; |
352 | 351 |
353 EXPECT_NEAR(expected_time, accumulated_delta, | 352 EXPECT_NEAR(expected_time, accumulated_delta, |
354 TransportFeedback::kDeltaScaleFactor / 2); | 353 TransportFeedback::kDeltaScaleFactor / 2); |
355 } | 354 } |
356 } | 355 } |
357 | 356 |
358 TEST(RtcpPacketTest, TransportFeedback_Limits) { | 357 TEST(RtcpPacketTest, TransportFeedback_Limits) { |
359 // Sequence number wrap above 0x8000. | 358 // Sequence number wrap above 0x8000. |
360 std::unique_ptr<TransportFeedback> packet(new TransportFeedback()); | 359 rtc::scoped_ptr<TransportFeedback> packet(new TransportFeedback()); |
361 packet->WithBase(0, 0); | 360 packet->WithBase(0, 0); |
362 EXPECT_TRUE(packet->WithReceivedPacket(0x8000, 1000)); | 361 EXPECT_TRUE(packet->WithReceivedPacket(0x8000, 1000)); |
363 | 362 |
364 packet.reset(new TransportFeedback()); | 363 packet.reset(new TransportFeedback()); |
365 packet->WithBase(0, 0); | 364 packet->WithBase(0, 0); |
366 EXPECT_FALSE(packet->WithReceivedPacket(0x8000 + 1, 1000)); | 365 EXPECT_FALSE(packet->WithReceivedPacket(0x8000 + 1, 1000)); |
367 | 366 |
368 // Packet status count max 0xFFFF. | 367 // Packet status count max 0xFFFF. |
369 packet.reset(new TransportFeedback()); | 368 packet.reset(new TransportFeedback()); |
370 packet->WithBase(0, 0); | 369 packet->WithBase(0, 0); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 uint8_t mod_buffer[kExpectedSizeWithPadding]; | 439 uint8_t mod_buffer[kExpectedSizeWithPadding]; |
441 memcpy(mod_buffer, packet.data(), kExpectedSizeWords * 4); | 440 memcpy(mod_buffer, packet.data(), kExpectedSizeWords * 4); |
442 memset(&mod_buffer[kExpectedSizeWords * 4], 0, kPaddingBytes - 1); | 441 memset(&mod_buffer[kExpectedSizeWords * 4], 0, kPaddingBytes - 1); |
443 mod_buffer[kExpectedSizeWithPadding - 1] = kPaddingBytes; | 442 mod_buffer[kExpectedSizeWithPadding - 1] = kPaddingBytes; |
444 const uint8_t padding_flag = 1 << 5; | 443 const uint8_t padding_flag = 1 << 5; |
445 mod_buffer[0] |= padding_flag; | 444 mod_buffer[0] |= padding_flag; |
446 ByteWriter<uint16_t>::WriteBigEndian( | 445 ByteWriter<uint16_t>::WriteBigEndian( |
447 &mod_buffer[2], ByteReader<uint16_t>::ReadBigEndian(&mod_buffer[2]) + | 446 &mod_buffer[2], ByteReader<uint16_t>::ReadBigEndian(&mod_buffer[2]) + |
448 ((kPaddingBytes + 3) / 4)); | 447 ((kPaddingBytes + 3) / 4)); |
449 | 448 |
450 std::unique_ptr<TransportFeedback> parsed_packet( | 449 rtc::scoped_ptr<TransportFeedback> parsed_packet( |
451 TransportFeedback::ParseFrom(mod_buffer, kExpectedSizeWithPadding)); | 450 TransportFeedback::ParseFrom(mod_buffer, kExpectedSizeWithPadding)); |
452 ASSERT_TRUE(parsed_packet.get() != nullptr); | 451 ASSERT_TRUE(parsed_packet.get() != nullptr); |
453 EXPECT_EQ(kExpectedSizeWords * 4, packet.size()); // Padding not included. | 452 EXPECT_EQ(kExpectedSizeWords * 4, packet.size()); // Padding not included. |
454 } | 453 } |
455 | 454 |
456 TEST(RtcpPacketTest, TransportFeedback_CorrectlySplitsVectorChunks) { | 455 TEST(RtcpPacketTest, TransportFeedback_CorrectlySplitsVectorChunks) { |
457 const int kOneBitVectorCapacity = 14; | 456 const int kOneBitVectorCapacity = 14; |
458 const int64_t kLargeTimeDelta = | 457 const int64_t kLargeTimeDelta = |
459 TransportFeedback::kDeltaScaleFactor * (1 << 8); | 458 TransportFeedback::kDeltaScaleFactor * (1 << 8); |
460 | 459 |
461 // Test that a number of small deltas followed by a large delta results in a | 460 // Test that a number of small deltas followed by a large delta results in a |
462 // correct split into multiple chunks, as needed. | 461 // correct split into multiple chunks, as needed. |
463 | 462 |
464 for (int deltas = 0; deltas <= kOneBitVectorCapacity + 1; ++deltas) { | 463 for (int deltas = 0; deltas <= kOneBitVectorCapacity + 1; ++deltas) { |
465 TransportFeedback feedback; | 464 TransportFeedback feedback; |
466 feedback.WithBase(0, 0); | 465 feedback.WithBase(0, 0); |
467 for (int i = 0; i < deltas; ++i) | 466 for (int i = 0; i < deltas; ++i) |
468 feedback.WithReceivedPacket(i, i * 1000); | 467 feedback.WithReceivedPacket(i, i * 1000); |
469 feedback.WithReceivedPacket(deltas, deltas * 1000 + kLargeTimeDelta); | 468 feedback.WithReceivedPacket(deltas, deltas * 1000 + kLargeTimeDelta); |
470 | 469 |
471 rtc::Buffer serialized_packet = feedback.Build(); | 470 rtc::Buffer serialized_packet = feedback.Build(); |
472 std::unique_ptr<TransportFeedback> deserialized_packet = | 471 rtc::scoped_ptr<TransportFeedback> deserialized_packet = |
473 TransportFeedback::ParseFrom(serialized_packet.data(), | 472 TransportFeedback::ParseFrom(serialized_packet.data(), |
474 serialized_packet.size()); | 473 serialized_packet.size()); |
475 EXPECT_TRUE(deserialized_packet.get() != nullptr); | 474 EXPECT_TRUE(deserialized_packet.get() != nullptr); |
476 } | 475 } |
477 } | 476 } |
478 | 477 |
479 } // namespace | 478 } // namespace |
480 } // namespace webrtc | 479 } // namespace webrtc |
OLD | NEW |