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

Side by Side Diff: webrtc/modules/audio_coding/neteq/red_payload_splitter_unittest.cc

Issue 2342443005: Moved Opus-specific payload splitting into AudioDecoderOpus. (Closed)
Patch Set: Some small fixes. 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 // Unit tests for PayloadSplitter class. 11 // Unit tests for RedPayloadSplitter class.
12 12
13 #include "webrtc/modules/audio_coding/neteq/payload_splitter.h" 13 #include "webrtc/modules/audio_coding/neteq/red_payload_splitter.h"
14 14
15 #include <assert.h> 15 #include <assert.h>
16 16
17 #include <memory> 17 #include <memory>
18 #include <utility> // pair 18 #include <utility> // pair
19 19
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h" 21 #include "webrtc/modules/audio_coding/codecs/builtin_audio_decoder_factory.h"
22 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" 22 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
23 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h" 23 #include "webrtc/modules/audio_coding/neteq/mock/mock_decoder_database.h"
(...skipping 15 matching lines...) Expand all
39 // 39 //
40 // 0 1 2 3 40 // 0 1 2 3
41 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 41 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 42 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
43 // |0|0|0|0|1|0|0|0|x|1|x|x|x|x|x|x|x| | 43 // |0|0|0|0|1|0|0|0|x|1|x|x|x|x|x|x|x| |
44 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 44 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
45 // | Compressed frame 1 (N-2 bytes)... : 45 // | Compressed frame 1 (N-2 bytes)... :
46 // : | 46 // : |
47 // | | 47 // | |
48 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 48 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 void CreateOpusFecPayload(uint8_t* payload, size_t payload_length, 49 void CreateOpusFecPayload(uint8_t* payload,
50 size_t payload_length,
50 uint8_t payload_value) { 51 uint8_t payload_value) {
51 if (payload_length < 2) { 52 if (payload_length < 2) {
52 return; 53 return;
53 } 54 }
54 payload[0] = 0x08; 55 payload[0] = 0x08;
55 payload[1] = 0x40; 56 payload[1] = 0x40;
56 memset(&payload[2], payload_value, payload_length - 2); 57 memset(&payload[2], payload_value, payload_length - 2);
57 } 58 }
58 59
59 // RED headers (according to RFC 2198): 60 // RED headers (according to RFC 2198):
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 static_cast<uint8_t>(i)); 115 static_cast<uint8_t>(i));
115 } else { 116 } else {
116 memset(payload_ptr, static_cast<int>(i), kPayloadLength); 117 memset(payload_ptr, static_cast<int>(i), kPayloadLength);
117 } 118 }
118 payload_ptr += kPayloadLength; 119 payload_ptr += kPayloadLength;
119 } 120 }
120 return packet; 121 return packet;
121 } 122 }
122 123
123 // Create a packet with all payload bytes set to |payload_value|. 124 // Create a packet with all payload bytes set to |payload_value|.
124 Packet* CreatePacket(uint8_t payload_type, size_t payload_length, 125 Packet* CreatePacket(uint8_t payload_type,
125 uint8_t payload_value, bool opus_fec = false) { 126 size_t payload_length,
127 uint8_t payload_value,
128 bool opus_fec = false) {
126 Packet* packet = new Packet; 129 Packet* packet = new Packet;
127 packet->header.payloadType = payload_type; 130 packet->header.payloadType = payload_type;
128 packet->header.timestamp = kBaseTimestamp; 131 packet->header.timestamp = kBaseTimestamp;
129 packet->header.sequenceNumber = kSequenceNumber; 132 packet->header.sequenceNumber = kSequenceNumber;
130 packet->payload.SetSize(payload_length); 133 packet->payload.SetSize(payload_length);
131 if (opus_fec) { 134 if (opus_fec) {
132 CreateOpusFecPayload(packet->payload.data(), packet->payload.size(), 135 CreateOpusFecPayload(packet->payload.data(), packet->payload.size(),
133 payload_value); 136 payload_value);
134 } else { 137 } else {
135 memset(packet->payload.data(), payload_value, packet->payload.size()); 138 memset(packet->payload.data(), payload_value, packet->payload.size());
136 } 139 }
137 return packet; 140 return packet;
138 } 141 }
139 142
140 // Checks that |packet| has the attributes given in the remaining parameters. 143 // Checks that |packet| has the attributes given in the remaining parameters.
141 void VerifyPacket(const Packet* packet, 144 void VerifyPacket(const Packet* packet,
142 size_t payload_length, 145 size_t payload_length,
143 uint8_t payload_type, 146 uint8_t payload_type,
144 uint16_t sequence_number, 147 uint16_t sequence_number,
145 uint32_t timestamp, 148 uint32_t timestamp,
146 uint8_t payload_value, 149 uint8_t payload_value,
147 bool primary = true) { 150 Packet::Priority priority) {
148 EXPECT_EQ(payload_length, packet->payload.size()); 151 EXPECT_EQ(payload_length, packet->payload.size());
149 EXPECT_EQ(payload_type, packet->header.payloadType); 152 EXPECT_EQ(payload_type, packet->header.payloadType);
150 EXPECT_EQ(sequence_number, packet->header.sequenceNumber); 153 EXPECT_EQ(sequence_number, packet->header.sequenceNumber);
151 EXPECT_EQ(timestamp, packet->header.timestamp); 154 EXPECT_EQ(timestamp, packet->header.timestamp);
152 EXPECT_EQ(primary, packet->primary); 155 EXPECT_EQ(priority, packet->priority);
153 ASSERT_FALSE(packet->payload.empty()); 156 ASSERT_FALSE(packet->payload.empty());
154 for (size_t i = 0; i < packet->payload.size(); ++i) { 157 for (size_t i = 0; i < packet->payload.size(); ++i) {
155 ASSERT_EQ(payload_value, packet->payload.data()[i]); 158 ASSERT_EQ(payload_value, packet->payload.data()[i]);
156 } 159 }
157 } 160 }
158 161
162 void VerifyPacket(const Packet* packet,
163 size_t payload_length,
164 uint8_t payload_type,
165 uint16_t sequence_number,
166 uint32_t timestamp,
167 uint8_t payload_value,
168 bool primary) {
169 return VerifyPacket(packet, payload_length, payload_type, sequence_number,
170 timestamp, payload_value,
171 Packet::Priority{0, primary ? 0 : 1});
172 }
173
159 // Start of test definitions. 174 // Start of test definitions.
160 175
161 TEST(PayloadSplitter, CreateAndDestroy) { 176 TEST(RedPayloadSplitter, CreateAndDestroy) {
162 PayloadSplitter* splitter = new PayloadSplitter; 177 RedPayloadSplitter* splitter = new RedPayloadSplitter;
163 delete splitter; 178 delete splitter;
164 } 179 }
165 180
166 // Packet A is split into A1 and A2. 181 // Packet A is split into A1 and A2.
167 TEST(RedPayloadSplitter, OnePacketTwoPayloads) { 182 TEST(RedPayloadSplitter, OnePacketTwoPayloads) {
168 uint8_t payload_types[] = {0, 0}; 183 uint8_t payload_types[] = {0, 0};
169 const int kTimestampOffset = 160; 184 const int kTimestampOffset = 160;
170 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset); 185 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset);
171 PacketList packet_list; 186 PacketList packet_list;
172 packet_list.push_back(packet); 187 packet_list.push_back(packet);
173 PayloadSplitter splitter; 188 RedPayloadSplitter splitter;
174 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); 189 EXPECT_TRUE(splitter.SplitRed(&packet_list));
175 ASSERT_EQ(2u, packet_list.size()); 190 ASSERT_EQ(2u, packet_list.size());
176 // Check first packet. The first in list should always be the primary payload. 191 // Check first packet. The first in list should always be the primary payload.
177 packet = packet_list.front(); 192 packet = packet_list.front();
178 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, 193 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber,
179 kBaseTimestamp, 1, true); 194 kBaseTimestamp, 1, true);
180 delete packet; 195 delete packet;
181 packet_list.pop_front(); 196 packet_list.pop_front();
182 // Check second packet. 197 // Check second packet.
183 packet = packet_list.front(); 198 packet = packet_list.front();
184 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, 199 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber,
185 kBaseTimestamp - kTimestampOffset, 0, false); 200 kBaseTimestamp - kTimestampOffset, 0, false);
186 delete packet; 201 delete packet;
187 } 202 }
188 203
189 // Packets A and B are not split at all. Only the RED header in each packet is 204 // Packets A and B are not split at all. Only the RED header in each packet is
190 // removed. 205 // removed.
191 TEST(RedPayloadSplitter, TwoPacketsOnePayload) { 206 TEST(RedPayloadSplitter, TwoPacketsOnePayload) {
192 uint8_t payload_types[] = {0}; 207 uint8_t payload_types[] = {0};
193 const int kTimestampOffset = 160; 208 const int kTimestampOffset = 160;
194 // Create first packet, with a single RED payload. 209 // Create first packet, with a single RED payload.
195 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset); 210 Packet* packet = CreateRedPayload(1, payload_types, kTimestampOffset);
196 PacketList packet_list; 211 PacketList packet_list;
197 packet_list.push_back(packet); 212 packet_list.push_back(packet);
198 // Create second packet, with a single RED payload. 213 // Create second packet, with a single RED payload.
199 packet = CreateRedPayload(1, payload_types, kTimestampOffset); 214 packet = CreateRedPayload(1, payload_types, kTimestampOffset);
200 // Manually change timestamp and sequence number of second packet. 215 // Manually change timestamp and sequence number of second packet.
201 packet->header.timestamp += kTimestampOffset; 216 packet->header.timestamp += kTimestampOffset;
202 packet->header.sequenceNumber++; 217 packet->header.sequenceNumber++;
203 packet_list.push_back(packet); 218 packet_list.push_back(packet);
204 PayloadSplitter splitter; 219 RedPayloadSplitter splitter;
205 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); 220 EXPECT_TRUE(splitter.SplitRed(&packet_list));
206 ASSERT_EQ(2u, packet_list.size()); 221 ASSERT_EQ(2u, packet_list.size());
207 // Check first packet. 222 // Check first packet.
208 packet = packet_list.front(); 223 packet = packet_list.front();
209 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, 224 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber,
210 kBaseTimestamp, 0, true); 225 kBaseTimestamp, 0, true);
211 delete packet; 226 delete packet;
212 packet_list.pop_front(); 227 packet_list.pop_front();
213 // Check second packet. 228 // Check second packet.
214 packet = packet_list.front(); 229 packet = packet_list.front();
215 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, 230 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1,
(...skipping 16 matching lines...) Expand all
232 // Create first packet, with 3 RED payloads. 247 // Create first packet, with 3 RED payloads.
233 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); 248 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset);
234 PacketList packet_list; 249 PacketList packet_list;
235 packet_list.push_back(packet); 250 packet_list.push_back(packet);
236 // Create first packet, with 3 RED payloads. 251 // Create first packet, with 3 RED payloads.
237 packet = CreateRedPayload(3, payload_types, kTimestampOffset); 252 packet = CreateRedPayload(3, payload_types, kTimestampOffset);
238 // Manually change timestamp and sequence number of second packet. 253 // Manually change timestamp and sequence number of second packet.
239 packet->header.timestamp += kTimestampOffset; 254 packet->header.timestamp += kTimestampOffset;
240 packet->header.sequenceNumber++; 255 packet->header.sequenceNumber++;
241 packet_list.push_back(packet); 256 packet_list.push_back(packet);
242 PayloadSplitter splitter; 257 RedPayloadSplitter splitter;
243 EXPECT_EQ(PayloadSplitter::kOK, splitter.SplitRed(&packet_list)); 258 EXPECT_TRUE(splitter.SplitRed(&packet_list));
244 ASSERT_EQ(6u, packet_list.size()); 259 ASSERT_EQ(6u, packet_list.size());
245 // Check first packet, A1. 260 // Check first packet, A1.
246 packet = packet_list.front(); 261 packet = packet_list.front();
247 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber, 262 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber,
248 kBaseTimestamp, 2, true); 263 kBaseTimestamp, 2, {0, 0});
249 delete packet; 264 delete packet;
250 packet_list.pop_front(); 265 packet_list.pop_front();
251 // Check second packet, A2. 266 // Check second packet, A2.
252 packet = packet_list.front(); 267 packet = packet_list.front();
253 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber, 268 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber,
254 kBaseTimestamp - kTimestampOffset, 1, false); 269 kBaseTimestamp - kTimestampOffset, 1, {0, 1});
255 delete packet; 270 delete packet;
256 packet_list.pop_front(); 271 packet_list.pop_front();
257 // Check third packet, A3. 272 // Check third packet, A3.
258 packet = packet_list.front(); 273 packet = packet_list.front();
259 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, 274 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber,
260 kBaseTimestamp - 2 * kTimestampOffset, 0, false); 275 kBaseTimestamp - 2 * kTimestampOffset, 0, {0, 2});
261 delete packet; 276 delete packet;
262 packet_list.pop_front(); 277 packet_list.pop_front();
263 // Check fourth packet, B1. 278 // Check fourth packet, B1.
264 packet = packet_list.front(); 279 packet = packet_list.front();
265 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber + 1, 280 VerifyPacket(packet, kPayloadLength, payload_types[2], kSequenceNumber + 1,
266 kBaseTimestamp + kTimestampOffset, 2, true); 281 kBaseTimestamp + kTimestampOffset, 2, {0, 0});
267 delete packet; 282 delete packet;
268 packet_list.pop_front(); 283 packet_list.pop_front();
269 // Check fifth packet, B2. 284 // Check fifth packet, B2.
270 packet = packet_list.front(); 285 packet = packet_list.front();
271 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber + 1, 286 VerifyPacket(packet, kPayloadLength, payload_types[1], kSequenceNumber + 1,
272 kBaseTimestamp, 1, false); 287 kBaseTimestamp, 1, {0, 1});
273 delete packet; 288 delete packet;
274 packet_list.pop_front(); 289 packet_list.pop_front();
275 // Check sixth packet, B3. 290 // Check sixth packet, B3.
276 packet = packet_list.front(); 291 packet = packet_list.front();
277 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1, 292 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber + 1,
278 kBaseTimestamp - kTimestampOffset, 0, false); 293 kBaseTimestamp - kTimestampOffset, 0, {0, 2});
279 delete packet; 294 delete packet;
280 } 295 }
281 296
282 // Creates a list with 4 packets with these payload types: 297 // Creates a list with 4 packets with these payload types:
283 // 0 = CNGnb 298 // 0 = CNGnb
284 // 1 = PCMu 299 // 1 = PCMu
285 // 2 = DTMF (AVT) 300 // 2 = DTMF (AVT)
286 // 3 = iLBC 301 // 3 = iLBC
287 // We expect the method CheckRedPayloads to discard the iLBC packet, since it 302 // We expect the method CheckRedPayloads to discard the iLBC packet, since it
288 // is a non-CNG, non-DTMF payload of another type than the first speech payload 303 // is a non-CNG, non-DTMF payload of another type than the first speech payload
289 // found in the list (which is PCMu). 304 // found in the list (which is PCMu).
290 TEST(RedPayloadSplitter, CheckRedPayloads) { 305 TEST(RedPayloadSplitter, CheckRedPayloads) {
291 PacketList packet_list; 306 PacketList packet_list;
292 for (uint8_t i = 0; i <= 3; ++i) { 307 for (uint8_t i = 0; i <= 3; ++i) {
293 // Create packet with payload type |i|, payload length 10 bytes, all 0. 308 // Create packet with payload type |i|, payload length 10 bytes, all 0.
294 Packet* packet = CreatePacket(i, 10, 0); 309 Packet* packet = CreatePacket(i, 10, 0);
295 packet_list.push_back(packet); 310 packet_list.push_back(packet);
296 } 311 }
297 312
298 // Use a real DecoderDatabase object here instead of a mock, since it is 313 // Use a real DecoderDatabase object here instead of a mock, since it is
299 // easier to just register the payload types and let the actual implementation 314 // easier to just register the payload types and let the actual implementation
300 // do its job. 315 // do its job.
301 DecoderDatabase decoder_database( 316 DecoderDatabase decoder_database(
302 new rtc::RefCountedObject<MockAudioDecoderFactory>); 317 new rtc::RefCountedObject<MockAudioDecoderFactory>);
303 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderCNGnb, "cng-nb"); 318 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderCNGnb, "cng-nb");
304 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu"); 319 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu");
305 decoder_database.RegisterPayload(2, NetEqDecoder::kDecoderAVT, "avt"); 320 decoder_database.RegisterPayload(2, NetEqDecoder::kDecoderAVT, "avt");
306 decoder_database.RegisterPayload(3, NetEqDecoder::kDecoderILBC, "ilbc"); 321 decoder_database.RegisterPayload(3, NetEqDecoder::kDecoderILBC, "ilbc");
307 322
308 PayloadSplitter splitter; 323 RedPayloadSplitter splitter;
309 splitter.CheckRedPayloads(&packet_list, decoder_database); 324 splitter.CheckRedPayloads(&packet_list, decoder_database);
310 325
311 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet. 326 ASSERT_EQ(3u, packet_list.size()); // Should have dropped the last packet.
312 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the 327 // Verify packets. The loop verifies that payload types 0, 1, and 2 are in the
313 // list. 328 // list.
314 for (int i = 0; i <= 2; ++i) { 329 for (int i = 0; i <= 2; ++i) {
315 Packet* packet = packet_list.front(); 330 Packet* packet = packet_list.front();
316 VerifyPacket(packet, 10, i, kSequenceNumber, kBaseTimestamp, 0, true); 331 VerifyPacket(packet, 10, i, kSequenceNumber, kBaseTimestamp, 0, true);
317 delete packet; 332 delete packet;
318 packet_list.pop_front(); 333 packet_list.pop_front();
319 } 334 }
320 EXPECT_TRUE(packet_list.empty()); 335 EXPECT_TRUE(packet_list.empty());
321 } 336 }
322 337
323 // Packet A is split into A1, A2 and A3. But the length parameter is off, so 338 // Packet A is split into A1, A2 and A3. But the length parameter is off, so
324 // the last payloads should be discarded. 339 // the last payloads should be discarded.
325 TEST(RedPayloadSplitter, WrongPayloadLength) { 340 TEST(RedPayloadSplitter, WrongPayloadLength) {
326 uint8_t payload_types[] = {0, 0, 0}; 341 uint8_t payload_types[] = {0, 0, 0};
327 const int kTimestampOffset = 160; 342 const int kTimestampOffset = 160;
328 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset); 343 Packet* packet = CreateRedPayload(3, payload_types, kTimestampOffset);
329 // Manually tamper with the payload length of the packet. 344 // Manually tamper with the payload length of the packet.
330 // This is one byte too short for the second payload (out of three). 345 // This is one byte too short for the second payload (out of three).
331 // We expect only the first payload to be returned. 346 // We expect only the first payload to be returned.
332 packet->payload.SetSize(packet->payload.size() - (kPayloadLength + 1)); 347 packet->payload.SetSize(packet->payload.size() - (kPayloadLength + 1));
333 PacketList packet_list; 348 PacketList packet_list;
334 packet_list.push_back(packet); 349 packet_list.push_back(packet);
335 PayloadSplitter splitter; 350 RedPayloadSplitter splitter;
336 EXPECT_EQ(PayloadSplitter::kRedLengthMismatch, 351 EXPECT_FALSE(splitter.SplitRed(&packet_list));
337 splitter.SplitRed(&packet_list));
338 ASSERT_EQ(1u, packet_list.size()); 352 ASSERT_EQ(1u, packet_list.size());
339 // Check first packet. 353 // Check first packet.
340 packet = packet_list.front(); 354 packet = packet_list.front();
341 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber, 355 VerifyPacket(packet, kPayloadLength, payload_types[0], kSequenceNumber,
342 kBaseTimestamp - 2 * kTimestampOffset, 0, false); 356 kBaseTimestamp - 2 * kTimestampOffset, 0, {0, 2});
343 delete packet; 357 delete packet;
344 packet_list.pop_front(); 358 packet_list.pop_front();
345 } 359 }
346
347 TEST(FecPayloadSplitter, MixedPayload) {
348 PacketList packet_list;
349 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory());
350
351 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus");
352 decoder_database.RegisterPayload(1, NetEqDecoder::kDecoderPCMu, "pcmu");
353
354 Packet* packet = CreatePacket(0, 10, 0xFF, true);
355 packet_list.push_back(packet);
356
357 packet = CreatePacket(0, 10, 0); // Non-FEC Opus payload.
358 packet_list.push_back(packet);
359
360 packet = CreatePacket(1, 10, 0); // Non-Opus payload.
361 packet_list.push_back(packet);
362
363 PayloadSplitter splitter;
364 EXPECT_EQ(PayloadSplitter::kOK,
365 splitter.SplitFec(&packet_list, &decoder_database));
366 EXPECT_EQ(4u, packet_list.size());
367
368 // Check first packet.
369 packet = packet_list.front();
370 EXPECT_EQ(0, packet->header.payloadType);
371 EXPECT_EQ(kBaseTimestamp - 20 * 48, packet->header.timestamp);
372 EXPECT_EQ(10U, packet->payload.size());
373 EXPECT_FALSE(packet->primary);
374 delete packet;
375 packet_list.pop_front();
376
377 // Check second packet.
378 packet = packet_list.front();
379 EXPECT_EQ(0, packet->header.payloadType);
380 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp);
381 EXPECT_EQ(10U, packet->payload.size());
382 EXPECT_TRUE(packet->primary);
383 delete packet;
384 packet_list.pop_front();
385
386 // Check third packet.
387 packet = packet_list.front();
388 VerifyPacket(packet, 10, 0, kSequenceNumber, kBaseTimestamp, 0, true);
389 delete packet;
390 packet_list.pop_front();
391
392 // Check fourth packet.
393 packet = packet_list.front();
394 VerifyPacket(packet, 10, 1, kSequenceNumber, kBaseTimestamp, 0, true);
395 delete packet;
396 }
397
398 TEST(FecPayloadSplitter, EmbedFecInRed) {
399 PacketList packet_list;
400 DecoderDatabase decoder_database(CreateBuiltinAudioDecoderFactory());
401
402 const int kTimestampOffset = 20 * 48; // 20 ms * 48 kHz.
403 uint8_t payload_types[] = {0, 0};
404 decoder_database.RegisterPayload(0, NetEqDecoder::kDecoderOpus, "opus");
405 Packet* packet = CreateRedPayload(2, payload_types, kTimestampOffset, true);
406 packet_list.push_back(packet);
407
408 PayloadSplitter splitter;
409 EXPECT_EQ(PayloadSplitter::kOK,
410 splitter.SplitRed(&packet_list));
411 EXPECT_EQ(PayloadSplitter::kOK,
412 splitter.SplitFec(&packet_list, &decoder_database));
413
414 EXPECT_EQ(4u, packet_list.size());
415
416 // Check first packet. FEC packet copied from primary payload in RED.
417 packet = packet_list.front();
418 EXPECT_EQ(0, packet->header.payloadType);
419 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp);
420 EXPECT_EQ(kPayloadLength, packet->payload.size());
421 EXPECT_FALSE(packet->primary);
422 EXPECT_EQ(packet->payload[3], 1);
423 delete packet;
424 packet_list.pop_front();
425
426 // Check second packet. Normal packet copied from primary payload in RED.
427 packet = packet_list.front();
428 EXPECT_EQ(0, packet->header.payloadType);
429 EXPECT_EQ(kBaseTimestamp, packet->header.timestamp);
430 EXPECT_EQ(kPayloadLength, packet->payload.size());
431 EXPECT_TRUE(packet->primary);
432 EXPECT_EQ(packet->payload[3], 1);
433 delete packet;
434 packet_list.pop_front();
435
436 // Check third packet. FEC packet copied from secondary payload in RED.
437 packet = packet_list.front();
438 EXPECT_EQ(0, packet->header.payloadType);
439 EXPECT_EQ(kBaseTimestamp - 2 * kTimestampOffset, packet->header.timestamp);
440 EXPECT_EQ(kPayloadLength, packet->payload.size());
441 EXPECT_FALSE(packet->primary);
442 EXPECT_EQ(packet->payload[3], 0);
443 delete packet;
444 packet_list.pop_front();
445
446 // Check fourth packet. Normal packet copied from primary payload in RED.
447 packet = packet_list.front();
448 EXPECT_EQ(0, packet->header.payloadType);
449 EXPECT_EQ(kBaseTimestamp - kTimestampOffset, packet->header.timestamp);
450 EXPECT_EQ(kPayloadLength, packet->payload.size());
451 EXPECT_TRUE(packet->primary);
452 EXPECT_EQ(packet->payload[3], 0);
453 delete packet;
454 packet_list.pop_front();
455 }
456 360
457 } // namespace webrtc 361 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698