OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <algorithm> | |
12 #include <limits> | |
13 #include <memory> | |
14 #include <vector> | |
15 | |
16 #include "webrtc/base/array_view.h" | |
17 #include "webrtc/modules/include/module_common_types.h" | |
18 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" | |
19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
20 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" | |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" | |
22 #include "webrtc/test/gmock.h" | |
23 #include "webrtc/test/gtest.h" | |
24 | |
25 namespace webrtc { | |
26 namespace { | |
27 | |
28 using ::testing::ElementsAreArray; | |
29 using ::testing::Le; | |
30 using ::testing::SizeIs; | |
31 using ::testing::Each; | |
32 | |
33 const size_t kMaxPayloadSize = 1200; | |
34 | |
35 uint8_t kTestPayload[kMaxPayloadSize]; | |
36 | |
37 std::vector<size_t> NextPacketFillPayloadSizes( | |
38 RtpPacketizerGeneric* packetizer) { | |
39 RtpPacketToSend packet(nullptr); | |
40 std::vector<size_t> result; | |
41 while (packetizer->NextPacket(&packet)) { | |
42 result.push_back(packet.payload_size()); | |
43 } | |
44 return result; | |
45 } | |
46 | |
47 size_t GetEffectivePacketsSizeDifference(std::vector<size_t> payload_sizes, | |
danilchap
2017/05/15 11:03:18
may be
const std::vector<size_t>& or
rtc::ArrayVie
ilnik
2017/05/15 12:11:38
It should have been const reference. Totally a typ
| |
48 size_t last_packet_reduction_len) { | |
49 // Account for larger last packet header. | |
50 size_t min = payload_sizes.back() + last_packet_reduction_len; | |
51 size_t max = min; | |
52 for (size_t i = 0; i + 1 < payload_sizes.size(); ++i) { | |
danilchap
2017/05/15 11:03:18
may be use c++ for loop:
for (size_t payload_size
ilnik
2017/05/15 12:11:38
Done.
| |
53 min = std::min(payload_sizes[i], min); | |
54 max = std::max(payload_sizes[i], max); | |
55 } | |
56 return max - min; | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 TEST(RtpPacketizerVideoGeneric, RespectsMaxPayloadSize1) { | |
62 const size_t max_payload_length = 5; | |
63 const size_t last_packet_reduction_len = 2; | |
64 const size_t payload_size = 12; | |
65 const size_t min_num_packets = 4; // Computed by hand. | |
66 RtpPacketizerGeneric packetizer(kVideoFrameKey, max_payload_length, | |
67 last_packet_reduction_len); | |
68 size_t num_packets = | |
69 packetizer.SetPayloadData(kTestPayload, payload_size, nullptr); | |
70 auto payload_sizes = NextPacketFillPayloadSizes(&packetizer); | |
71 | |
72 EXPECT_THAT(payload_sizes, SizeIs(num_packets)); | |
danilchap
2017/05/15 11:03:17
this check probably do not belong to this test, bu
ilnik
2017/05/15 12:11:38
Done.
| |
73 EXPECT_EQ(num_packets, min_num_packets); | |
74 EXPECT_THAT(payload_sizes, Each(Le(max_payload_length))); | |
75 EXPECT_LE(payload_sizes.back(), | |
76 max_payload_length - last_packet_reduction_len); | |
77 size_t sizes_difference = GetEffectivePacketsSizeDifference( | |
78 payload_sizes, last_packet_reduction_len); | |
79 EXPECT_LE(sizes_difference, 1u); | |
danilchap
2017/05/15 11:03:17
this check probably better to move to 'GeneratePac
ilnik
2017/05/15 12:11:38
Done.
| |
80 } | |
81 | |
82 TEST(RtpPacketizerVideoGeneric, RespectsMaxPayloadSize2) { | |
danilchap
2017/05/15 11:03:17
instead of 1/2, can you name tests describing what
ilnik
2017/05/15 12:11:38
Done.
| |
83 const size_t max_payload_length = 6; | |
84 const size_t last_packet_reduction_len = 2; | |
85 const size_t payload_size = 13; | |
86 const size_t min_num_packets = 3; // Computed by hand. | |
87 RtpPacketizerGeneric packetizer(kVideoFrameKey, max_payload_length, | |
88 last_packet_reduction_len); | |
89 size_t num_packets = | |
90 packetizer.SetPayloadData(kTestPayload, payload_size, nullptr); | |
91 auto payload_sizes = NextPacketFillPayloadSizes(&packetizer); | |
92 | |
93 EXPECT_THAT(payload_sizes, SizeIs(num_packets)); | |
94 EXPECT_EQ(num_packets, min_num_packets); | |
95 EXPECT_THAT(payload_sizes, Each(Le(max_payload_length))); | |
96 EXPECT_LE(payload_sizes.back(), | |
97 max_payload_length - last_packet_reduction_len); | |
98 size_t sizes_difference = GetEffectivePacketsSizeDifference( | |
99 payload_sizes, last_packet_reduction_len); | |
100 EXPECT_LE(sizes_difference, 1u); | |
101 } | |
102 | |
103 TEST(RtpPacketizerVideoGeneric, RespectsLastPacketReductionLength1) { | |
danilchap
2017/05/15 11:03:18
It is good that you check it in a separate test,
b
ilnik
2017/05/15 12:11:38
Done.
| |
104 const size_t max_payload_length = 6; | |
105 const size_t last_packet_reduction_len = 2; | |
106 const size_t payload_size = 13; | |
107 const size_t min_num_packets = 3; // Computed by hand. | |
108 RtpPacketizerGeneric packetizer(kVideoFrameKey, max_payload_length, | |
109 last_packet_reduction_len); | |
110 size_t num_packets = | |
111 packetizer.SetPayloadData(kTestPayload, payload_size, nullptr); | |
112 auto payload_sizes = NextPacketFillPayloadSizes(&packetizer); | |
113 | |
114 EXPECT_THAT(payload_sizes, SizeIs(num_packets)); | |
115 EXPECT_EQ(num_packets, min_num_packets); | |
116 EXPECT_THAT(payload_sizes, Each(Le(max_payload_length))); | |
117 EXPECT_LE(payload_sizes.back(), | |
118 max_payload_length - last_packet_reduction_len); | |
119 size_t sizes_difference = GetEffectivePacketsSizeDifference( | |
120 payload_sizes, last_packet_reduction_len); | |
121 EXPECT_LE(sizes_difference, 1u); | |
122 } | |
123 | |
124 TEST(RtpPacketizerVideoGeneric, RespectsLastPacketReductionLength2) { | |
125 const size_t max_payload_length = 6; | |
126 const size_t last_packet_reduction_len = 3; | |
127 const size_t payload_size = 13; | |
128 const size_t min_num_packets = 4; // Computed by hand. | |
129 RtpPacketizerGeneric packetizer(kVideoFrameKey, max_payload_length, | |
130 last_packet_reduction_len); | |
131 size_t num_packets = | |
132 packetizer.SetPayloadData(kTestPayload, payload_size, nullptr); | |
133 auto payload_sizes = NextPacketFillPayloadSizes(&packetizer); | |
134 | |
135 EXPECT_THAT(payload_sizes, SizeIs(num_packets)); | |
136 EXPECT_EQ(num_packets, min_num_packets); | |
137 EXPECT_THAT(payload_sizes, Each(Le(max_payload_length))); | |
138 EXPECT_LE(payload_sizes.back(), | |
139 max_payload_length - last_packet_reduction_len); | |
140 size_t sizes_difference = GetEffectivePacketsSizeDifference( | |
141 payload_sizes, last_packet_reduction_len); | |
142 EXPECT_LE(sizes_difference, 1u); | |
143 } | |
144 | |
145 } // namespace webrtc | |
OLD | NEW |