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

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

Issue 2269903002: Add FlexFEC header formatters. (pt. 5) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@header_reader_writer-pt4-generalize_header_formatting
Patch Set: Move tests so all FlexfecReaderTests are in line. Created 4 years, 3 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
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 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 std::unique_ptr<Packet> WriteHeader(const uint8_t* packet_mask, 51 std::unique_ptr<Packet> WriteHeader(const uint8_t* packet_mask,
52 size_t packet_mask_size) { 52 size_t packet_mask_size) {
53 UlpfecHeaderWriter writer; 53 UlpfecHeaderWriter writer;
54 std::unique_ptr<Packet> written_packet(new Packet()); 54 std::unique_ptr<Packet> written_packet(new Packet());
55 written_packet->length = kMediaPacketLength; 55 written_packet->length = kMediaPacketLength;
56 for (size_t i = 0; i < written_packet->length; ++i) { 56 for (size_t i = 0; i < written_packet->length; ++i) {
57 written_packet->data[i] = i; // Actual content doesn't matter. 57 written_packet->data[i] = i; // Actual content doesn't matter.
58 } 58 }
59 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask, packet_mask_size, 59 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask,
60 written_packet.get()); 60 packet_mask_size, written_packet.get());
61 return written_packet; 61 return written_packet;
62 } 62 }
63 63
64 std::unique_ptr<ReceivedFecPacket> ReadHeader(const Packet& written_packet) { 64 std::unique_ptr<ReceivedFecPacket> ReadHeader(const Packet& written_packet) {
65 UlpfecHeaderReader reader; 65 UlpfecHeaderReader reader;
66 std::unique_ptr<ReceivedFecPacket> read_packet(new ReceivedFecPacket()); 66 std::unique_ptr<ReceivedFecPacket> read_packet(new ReceivedFecPacket());
67 read_packet->ssrc = kMediaSsrc; 67 read_packet->ssrc = kMediaSsrc;
68 read_packet->pkt = rtc::scoped_refptr<Packet>(new Packet()); 68 read_packet->pkt = rtc::scoped_refptr<Packet>(new Packet());
69 memcpy(read_packet->pkt->data, written_packet.data, written_packet.length); 69 memcpy(read_packet->pkt->data, written_packet.data, written_packet.length);
70 read_packet->pkt->length = written_packet.length; 70 read_packet->pkt->length = written_packet.length;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 TEST(UlpfecHeaderWriterTest, CorrectlyFinalizesSmallHeader) { 148 TEST(UlpfecHeaderWriterTest, CorrectlyFinalizesSmallHeader) {
149 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitClear; 149 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitClear;
150 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); 150 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd);
151 Packet written_packet; 151 Packet written_packet;
152 written_packet.length = kMediaPacketLength; 152 written_packet.length = kMediaPacketLength;
153 for (size_t i = 0; i < written_packet.length; ++i) { 153 for (size_t i = 0; i < written_packet.length; ++i) {
154 written_packet.data[i] = i; 154 written_packet.data[i] = i;
155 } 155 }
156 UlpfecHeaderWriter writer; 156 UlpfecHeaderWriter writer;
157 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask.get(), 157 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask.get(),
158 packet_mask_size, &written_packet); 158 packet_mask_size, &written_packet);
159 159
160 const uint8_t* packet = written_packet.data; 160 const uint8_t* packet = written_packet.data;
161 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. 161 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit.
162 EXPECT_EQ(0x00, packet[0] & 0x40); // L bit. 162 EXPECT_EQ(0x00, packet[0] & 0x40); // L bit.
163 EXPECT_EQ(kMediaStartSeqNum, (packet[2] << 8) + packet[3]); 163 EXPECT_EQ(kMediaStartSeqNum, (packet[2] << 8) + packet[3]);
164 EXPECT_EQ( 164 EXPECT_EQ(
165 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitClear), 165 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitClear),
166 (packet[10] << 8) + packet[11]); 166 (packet[10] << 8) + packet[11]);
167 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), 167 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(),
168 packet_mask_size)); 168 packet_mask_size));
169 } 169 }
170 170
171 TEST(UlpfecHeaderWriterTest, CorrectlyFinalizesLargeHeader) { 171 TEST(UlpfecHeaderWriterTest, CorrectlyFinalizesLargeHeader) {
172 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet; 172 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet;
173 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); 173 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd);
174 Packet written_packet; 174 Packet written_packet;
175 written_packet.length = kMediaPacketLength; 175 written_packet.length = kMediaPacketLength;
176 for (size_t i = 0; i < written_packet.length; ++i) { 176 for (size_t i = 0; i < written_packet.length; ++i) {
177 written_packet.data[i] = i; 177 written_packet.data[i] = i;
178 } 178 }
179 UlpfecHeaderWriter writer; 179 UlpfecHeaderWriter writer;
180 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask.get(), 180 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask.get(),
181 packet_mask_size, &written_packet); 181 packet_mask_size, &written_packet);
182 182
183 const uint8_t* packet = written_packet.data; 183 const uint8_t* packet = written_packet.data;
184 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. 184 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit.
185 EXPECT_EQ(0x40, packet[0] & 0x40); // L bit. 185 EXPECT_EQ(0x40, packet[0] & 0x40); // L bit.
186 EXPECT_EQ(kMediaStartSeqNum, (packet[2] << 8) + packet[3]); 186 EXPECT_EQ(kMediaStartSeqNum, (packet[2] << 8) + packet[3]);
187 EXPECT_EQ( 187 EXPECT_EQ(
188 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitSet), 188 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitSet),
189 (packet[10] << 8) + packet[11]); 189 (packet[10] << 8) + packet[11]);
190 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), 190 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 TEST(UlpfecHeaderReaderWriterTest, WriteAndReadLargeHeader) { 225 TEST(UlpfecHeaderReaderWriterTest, WriteAndReadLargeHeader) {
226 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet; 226 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet;
227 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); 227 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd);
228 auto written_packet = WriteHeader(packet_mask.get(), packet_mask_size); 228 auto written_packet = WriteHeader(packet_mask.get(), packet_mask_size);
229 auto read_packet = ReadHeader(*written_packet); 229 auto read_packet = ReadHeader(*written_packet);
230 VerifyHeaders(kUlpfecHeaderSizeLBitSet, packet_mask.get(), packet_mask_size, 230 VerifyHeaders(kUlpfecHeaderSizeLBitSet, packet_mask.get(), packet_mask_size,
231 *written_packet, *read_packet); 231 *written_packet, *read_packet);
232 } 232 }
233 233
234 } // namespace webrtc 234 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698