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

Side by Side Diff: webrtc/modules/video_coding/video_packet_buffer_unittest.cc

Issue 2476283002: PacketBuffer no longer copy the bitstream data of incoming packets. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 packet.timesNacked = 1; 158 packet.timesNacked = 1;
159 packet_buffer_->InsertPacket(packet); 159 packet_buffer_->InsertPacket(packet);
160 160
161 ASSERT_EQ(1UL, frames_from_callback_.size()); 161 ASSERT_EQ(1UL, frames_from_callback_.size());
162 RtpFrameObject* frame = frames_from_callback_.begin()->second.get(); 162 RtpFrameObject* frame = frames_from_callback_.begin()->second.get();
163 EXPECT_EQ(3, frame->times_nacked()); 163 EXPECT_EQ(3, frame->times_nacked());
164 } 164 }
165 165
166 TEST_F(TestPacketBuffer, FrameSize) { 166 TEST_F(TestPacketBuffer, FrameSize) {
167 const uint16_t seq_num = Rand(); 167 const uint16_t seq_num = Rand();
168 uint8_t data[] = {1, 2, 3, 4, 5}; 168 uint8_t* data1 = new uint8_t[5]();
169 uint8_t* data2 = new uint8_t[5]();
170 uint8_t* data3 = new uint8_t[5]();
171 uint8_t* data4 = new uint8_t[5]();
169 172
170 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, 5, data)); 173 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, 5, data1));
171 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data)); 174 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data2));
172 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data)); 175 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data3));
173 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data)); 176 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data4));
174 177
175 ASSERT_EQ(1UL, frames_from_callback_.size()); 178 ASSERT_EQ(1UL, frames_from_callback_.size());
176 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size()); 179 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size());
177 } 180 }
178 181
179 TEST_F(TestPacketBuffer, ExpandBuffer) { 182 TEST_F(TestPacketBuffer, ExpandBuffer) {
180 const uint16_t seq_num = Rand(); 183 const uint16_t seq_num = Rand();
181 184
182 for (int i = 0; i < kStartSize + 1; ++i) { 185 for (int i = 0; i < kStartSize + 1; ++i) {
183 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast)); 186 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 303
301 ASSERT_EQ(4UL, frames_from_callback_.size()); 304 ASSERT_EQ(4UL, frames_from_callback_.size());
302 CheckFrame(seq_num); 305 CheckFrame(seq_num);
303 CheckFrame(seq_num + 1); 306 CheckFrame(seq_num + 1);
304 CheckFrame(seq_num + 2); 307 CheckFrame(seq_num + 2);
305 CheckFrame(seq_num + 3); 308 CheckFrame(seq_num + 3);
306 } 309 }
307 310
308 TEST_F(TestPacketBuffer, GetBitstream) { 311 TEST_F(TestPacketBuffer, GetBitstream) {
309 // "many bitstream, such data" with null termination. 312 // "many bitstream, such data" with null termination.
310 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 313 uint8_t many_data[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
311 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 314 uint8_t bitstream_data[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
312 0x65, 0x61, 0x6d, 0x2c, 0x20}; 315 0x65, 0x61, 0x6d, 0x2c, 0x20};
313 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 316 uint8_t such_data[] = {0x73, 0x75, 0x63, 0x68, 0x20};
314 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 317 uint8_t data_data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
315 uint8_t 318
316 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 319 uint8_t* many = new uint8_t[sizeof(many_data)];
320 uint8_t* bitstream = new uint8_t[sizeof(bitstream_data)];
321 uint8_t* such = new uint8_t[sizeof(such_data)];
322 uint8_t* data = new uint8_t[sizeof(data_data)];
323
324 memcpy(many, many_data, sizeof(many_data));
325 memcpy(bitstream, bitstream_data, sizeof(bitstream_data));
326 memcpy(such, such_data, sizeof(such_data));
327 memcpy(data, data_data, sizeof(data_data));
328
329 uint8_t result[sizeof(many_data) + sizeof(bitstream_data) +
330 sizeof(such_data) + sizeof(data_data)];
317 331
318 const uint16_t seq_num = Rand(); 332 const uint16_t seq_num = Rand();
319 333
320 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many)); 334 EXPECT_TRUE(
335 Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many_data), many));
321 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, 336 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast,
322 sizeof(bitstream), bitstream)); 337 sizeof(bitstream_data), bitstream));
323 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, 338 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast,
324 sizeof(such), such)); 339 sizeof(such_data), such));
325 EXPECT_TRUE( 340 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast,
326 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data)); 341 sizeof(data_data), data));
327 342
328 ASSERT_EQ(1UL, frames_from_callback_.size()); 343 ASSERT_EQ(1UL, frames_from_callback_.size());
329 CheckFrame(seq_num); 344 CheckFrame(seq_num);
330 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); 345 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result));
331 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); 346 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0);
332 } 347 }
333 348
334 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) { 349 TEST_F(TestPacketBuffer, GetBitstreamH264BufferPadding) {
335 uint16_t seq_num = Rand(); 350 uint16_t seq_num = Rand();
336 uint8_t data[] = "some plain old data"; 351 uint8_t data_data[] = "some plain old data";
352 uint8_t* data = new uint8_t[sizeof(data_data)];
353 memcpy(data, data_data, sizeof(data_data));
337 354
338 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time. 355 // EncodedImage::kBufferPaddingBytesH264 is unknown at compile time.
339 uint8_t* result = 356 std::unique_ptr<uint8_t[]> result(
340 new uint8_t[sizeof(data) + EncodedImage::kBufferPaddingBytesH264]; 357 new uint8_t[sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264]);
341 358
342 VCMPacket packet; 359 VCMPacket packet;
343 packet.seqNum = seq_num; 360 packet.seqNum = seq_num;
344 packet.codec = kVideoCodecH264; 361 packet.codec = kVideoCodecH264;
345 packet.insertStartCode = true; 362 packet.insertStartCode = true;
346 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; 363 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu;
347 packet.dataPtr = data; 364 packet.dataPtr = data;
348 packet.sizeBytes = sizeof(data); 365 packet.sizeBytes = sizeof(data_data);
349 packet.isFirstPacket = true; 366 packet.isFirstPacket = true;
350 packet.markerBit = true; 367 packet.markerBit = true;
351 packet_buffer_->InsertPacket(packet); 368 packet_buffer_->InsertPacket(packet);
352 369
353 ASSERT_EQ(1UL, frames_from_callback_.size()); 370 ASSERT_EQ(1UL, frames_from_callback_.size());
354 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._length, 371 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._length,
355 sizeof(data)); 372 sizeof(data_data));
356 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._size, 373 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._size,
357 sizeof(data) + EncodedImage::kBufferPaddingBytesH264); 374 sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264);
358 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); 375 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result.get()));
359 EXPECT_EQ(memcmp(result, data, sizeof(data)), 0); 376 EXPECT_EQ(memcmp(result.get(), data, sizeof(data_data)), 0);
360 delete[] result;
361 } 377 }
362 378
363 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { 379 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
364 const uint16_t seq_num = Rand(); 380 const uint16_t seq_num = Rand();
365 381
366 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast)); 382 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
367 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast)); 383 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast));
368 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast)); 384 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast));
369 EXPECT_EQ(1UL, frames_from_callback_.size()); 385 EXPECT_EQ(1UL, frames_from_callback_.size());
370 CheckFrame(seq_num); 386 CheckFrame(seq_num);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 420
405 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast)); 421 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
406 ASSERT_EQ(1UL, frames_from_callback_.size()); 422 ASSERT_EQ(1UL, frames_from_callback_.size());
407 423
408 packet_buffer_->Clear(); 424 packet_buffer_->Clear();
409 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); 425 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
410 } 426 }
411 427
412 } // namespace video_coding 428 } // namespace video_coding
413 } // namespace webrtc 429 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/packet_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698