Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_video_generic_unittest.cc

Issue 2871173008: Fix packetization logic to leave space for extensions in the last packet (Closed)
Patch Set: Implement generic video packetizer unittests Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 <memory>
12 #include <vector>
13
14 #include "webrtc/base/array_view.h"
15 #include "webrtc/modules/include/module_common_types.h"
16 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h"
17 #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
18 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
20 #include "webrtc/test/gmock.h"
21 #include "webrtc/test/gtest.h"
22
23 namespace webrtc {
24 namespace RtpFormatVideoGeneric {
danilchap 2017/05/12 18:56:15 do not use this namespace
ilnik 2017/05/15 09:38:33 Done.
25 namespace {
26
27 using ::testing::ElementsAreArray;
28
29 constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
30 const size_t kMaxPayloadSize = 1200;
31 // const size_t kGenericHeaderLen = 1;
32
33 uint8_t test_payload_buffer[kMaxPayloadSize];
34
35 void VerifyPacketsSizes(size_t payload_length, size_t max_payload_length,
36 size_t extensions_length,
37 std::vector<size_t> expected_sizes) {
danilchap 2017/05/12 18:56:15 Likely it is more readable when helpers do not con
ilnik 2017/05/15 09:38:33 Done.
38 size_t total_expected_bytes = 0;
39 for (size_t i = 0; i < expected_sizes.size(); i++)
40 total_expected_bytes += expected_sizes[i] - 1;
41 RTC_CHECK_EQ(total_expected_bytes, payload_length) << "Incorrect unittest. "
42 "Sum of packets sizes, sans 1-byte headers, should be equal to payload "
43 "length";
44 RtpPacketizerGeneric packetizer(kVideoFrameKey,
45 max_payload_length,
46 extensions_length);
47 size_t num_packets =
48 packetizer.SetPayloadData(test_payload_buffer, payload_length, nullptr);
49 ASSERT_EQ(num_packets, expected_sizes.size());
50 RtpPacketToSend packet(kNoExtensions);
danilchap 2017/05/12 18:56:15 alternative ways are ... packet(nullptr /* extensi
ilnik 2017/05/15 09:38:33 Done.
51 for (size_t i = 0; i < num_packets; i++) {
52 EXPECT_TRUE(packetizer.NextPacket(&packet));
53 EXPECT_EQ(packet.payload_size(), expected_sizes[i]);
54 }
55 EXPECT_FALSE(packetizer.NextPacket(&packet));
56 }
57
58 } // namespace
59
60
61 TEST(RtpPacketizerVideoGeneric, FourPackets) {
62 VerifyPacketsSizes(12, 5, 2, {5, 5, 4, 2});
63 }
64
65 TEST(RtpPacketizerVideoGeneric, NoExtensions) {
66 VerifyPacketsSizes(12, 5, 0, {5, 5, 5});
67 }
68
69 TEST(RtpPacketizerVideoGeneric, FitsInSinglePacket) {
70 VerifyPacketsSizes(12, 16, 0, {13});
71 }
72
73 TEST(RtpPacketizerVideoGeneric, ExtensionforsesSecondPacket) {
74 VerifyPacketsSizes(12, 16, 4, {9, 5});
75 }
76
77
78
79 } // namespace RtpFormatVideoGeneric
80 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698