1 /*
2 * Copyright (c) 2018 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 "modules/rtp_rtcp/source/fec_private_tables_bursty.h"
12
13 #include "modules/rtp_rtcp/source/fec_private_tables_random.h"
14 #include "modules/rtp_rtcp/source/forward_error_correction_internal.h"
15 #include "test/gtest.h"
16
17 namespace webrtc {
18 namespace {
19 constexpr uint8_t kMaskRandom15_6[] = {0x82, 0x08, 0x41, 0x04, 0x20, 0x82,
20 0x10, 0x40, 0x08, 0x20, 0x04, 0x10};
21 }
22
23 namespace fec_private_tables {
24
25 using internal::LookUpInFecTable;
26
TEST(FecTable,TestBurstyLookup)27 TEST(FecTable, TestBurstyLookup) {
28 rtc::ArrayView<const uint8_t> result;
29 result = LookUpInFecTable(&kPacketMaskBurstyTbl[0], 0, 0);
30 // Should match kMaskBursty1_1.
31 EXPECT_EQ(2u, result.size());
32 EXPECT_EQ(0x80u, result[0]);
33
34 result = LookUpInFecTable(&kPacketMaskBurstyTbl[0], 3, 0);
35 // Should match kMaskBursty4_1.
36 EXPECT_EQ(2u, result.size());
37 EXPECT_EQ(0xf0u, result[0]);
38 EXPECT_EQ(0x00u, result[1]);
39
40 result = LookUpInFecTable(&kPacketMaskBurstyTbl[0], 1, 1);
41 // Should match kMaskBursty2_2.
42 EXPECT_EQ(4u, result.size());
43 EXPECT_EQ(0x80u, result[0]);
44 EXPECT_EQ(0xc0u, result[2]);
45
46 result = LookUpInFecTable(&kPacketMaskBurstyTbl[0], 11, 11);
47 // Should match kMaskBursty12_12.
48 EXPECT_EQ(24u, result.size());
49 EXPECT_EQ(0x80u, result[0]);
50 EXPECT_EQ(0x30u, result[23]);
51 }
52
TEST(FecTable,TestRandomLookup)53 TEST(FecTable, TestRandomLookup) {
54 rtc::ArrayView<const uint8_t> result;
55 result = LookUpInFecTable(&kPacketMaskRandomTbl[0], 0, 0);
56 EXPECT_EQ(2u, result.size());
57 EXPECT_EQ(0x80u, result[0]);
58 EXPECT_EQ(0x00u, result[1]);
59
60 result = LookUpInFecTable(&kPacketMaskRandomTbl[0], 4, 1);
61 // kMaskRandom5_2.
62 EXPECT_EQ(4u, result.size());
63 EXPECT_EQ(0xa8u, result[0]);
64 EXPECT_EQ(0xd0u, result[2]);
65 }
66
TEST(FecTable,TestRandomGenerated)67 TEST(FecTable, TestRandomGenerated) {
68 FecMaskType fec_mask_type = kFecMaskRandom;
69 int num_media_packets = 15;
70 int num_fec_packets = 6;
71 size_t mask_size = sizeof(kMaskRandom15_6) / sizeof(uint8_t);
72 internal::PacketMaskTable mask_table(fec_mask_type, num_media_packets);
73 rtc::ArrayView<const uint8_t> mask =
74 mask_table.LookUp(num_media_packets, num_fec_packets);
75 EXPECT_EQ(mask.size(), mask_size);
76 for (size_t i = 0; i < mask_size; ++i) {
77 EXPECT_EQ(mask[i], kMaskRandom15_6[i]);
78 }
79 }
80
81 } // namespace fec_private_tables
82 } // namespace webrtc
83