OLD | NEW |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 uint8_t* data = nullptr) { // data pointer | 57 uint8_t* data = nullptr) { // data pointer |
58 VCMPacket packet; | 58 VCMPacket packet; |
59 packet.codec = kVideoCodecGeneric; | 59 packet.codec = kVideoCodecGeneric; |
60 packet.seqNum = seq_num; | 60 packet.seqNum = seq_num; |
61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta; | 61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta; |
62 packet.isFirstPacket = first == kFirst; | 62 packet.isFirstPacket = first == kFirst; |
63 packet.markerBit = last == kLast; | 63 packet.markerBit = last == kLast; |
64 packet.sizeBytes = data_size; | 64 packet.sizeBytes = data_size; |
65 packet.dataPtr = data; | 65 packet.dataPtr = data; |
66 | 66 |
67 return packet_buffer_->InsertPacket(packet); | 67 return packet_buffer_->InsertPacket(&packet); |
68 } | 68 } |
69 | 69 |
70 void CheckFrame(uint16_t first_seq_num) { | 70 void CheckFrame(uint16_t first_seq_num) { |
71 auto frame_it = frames_from_callback_.find(first_seq_num); | 71 auto frame_it = frames_from_callback_.find(first_seq_num); |
72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) | 72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) |
73 << "Could not find frame with first sequence number " << first_seq_num | 73 << "Could not find frame with first sequence number " << first_seq_num |
74 << "."; | 74 << "."; |
75 } | 75 } |
76 | 76 |
77 const int kStartSize = 16; | 77 const int kStartSize = 16; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 const uint16_t seq_num = Rand(); | 135 const uint16_t seq_num = Rand(); |
136 | 136 |
137 VCMPacket packet; | 137 VCMPacket packet; |
138 packet.codec = kVideoCodecGeneric; | 138 packet.codec = kVideoCodecGeneric; |
139 packet.seqNum = seq_num; | 139 packet.seqNum = seq_num; |
140 packet.frameType = kVideoFrameKey; | 140 packet.frameType = kVideoFrameKey; |
141 packet.isFirstPacket = true; | 141 packet.isFirstPacket = true; |
142 packet.markerBit = false; | 142 packet.markerBit = false; |
143 packet.timesNacked = 0; | 143 packet.timesNacked = 0; |
144 | 144 |
145 packet_buffer_->InsertPacket(packet); | 145 packet_buffer_->InsertPacket(&packet); |
146 | 146 |
147 packet.seqNum++; | 147 packet.seqNum++; |
148 packet.isFirstPacket = false; | 148 packet.isFirstPacket = false; |
149 packet.timesNacked = 1; | 149 packet.timesNacked = 1; |
150 packet_buffer_->InsertPacket(packet); | 150 packet_buffer_->InsertPacket(&packet); |
151 | 151 |
152 packet.seqNum++; | 152 packet.seqNum++; |
153 packet.timesNacked = 3; | 153 packet.timesNacked = 3; |
154 packet_buffer_->InsertPacket(packet); | 154 packet_buffer_->InsertPacket(&packet); |
155 | 155 |
156 packet.seqNum++; | 156 packet.seqNum++; |
157 packet.markerBit = true; | 157 packet.markerBit = true; |
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* data1 = new uint8_t[5](); | 168 uint8_t* data1 = new uint8_t[5](); |
169 uint8_t* data2 = new uint8_t[5](); | 169 uint8_t* data2 = new uint8_t[5](); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 358 |
359 VCMPacket packet; | 359 VCMPacket packet; |
360 packet.seqNum = seq_num; | 360 packet.seqNum = seq_num; |
361 packet.codec = kVideoCodecH264; | 361 packet.codec = kVideoCodecH264; |
362 packet.insertStartCode = true; | 362 packet.insertStartCode = true; |
363 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; | 363 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; |
364 packet.dataPtr = data; | 364 packet.dataPtr = data; |
365 packet.sizeBytes = sizeof(data_data); | 365 packet.sizeBytes = sizeof(data_data); |
366 packet.isFirstPacket = true; | 366 packet.isFirstPacket = true; |
367 packet.markerBit = true; | 367 packet.markerBit = true; |
368 packet_buffer_->InsertPacket(packet); | 368 packet_buffer_->InsertPacket(&packet); |
369 | 369 |
370 ASSERT_EQ(1UL, frames_from_callback_.size()); | 370 ASSERT_EQ(1UL, frames_from_callback_.size()); |
371 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._length, | 371 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._length, |
372 sizeof(data_data)); | 372 sizeof(data_data)); |
373 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._size, | 373 EXPECT_EQ(frames_from_callback_[seq_num]->EncodedImage()._size, |
374 sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264); | 374 sizeof(data_data) + EncodedImage::kBufferPaddingBytesH264); |
375 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result.get())); | 375 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result.get())); |
376 EXPECT_EQ(memcmp(result.get(), data, sizeof(data_data)), 0); | 376 EXPECT_EQ(memcmp(result.get(), data, sizeof(data_data)), 0); |
377 } | 377 } |
378 | 378 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 packet_buffer_->ClearTo(9025); | 431 packet_buffer_->ClearTo(9025); |
432 Insert(9057, kDeltaFrame, kFirst, kLast); | 432 Insert(9057, kDeltaFrame, kFirst, kLast); |
433 Insert(9026, kDeltaFrame, kFirst, kLast); | 433 Insert(9026, kDeltaFrame, kFirst, kLast); |
434 | 434 |
435 CheckFrame(9024); | 435 CheckFrame(9024); |
436 CheckFrame(9025); | 436 CheckFrame(9025); |
437 CheckFrame(9026); | 437 CheckFrame(9026); |
438 CheckFrame(9057); | 438 CheckFrame(9057); |
439 } | 439 } |
440 | 440 |
| 441 TEST_F(TestPacketBuffer, DontLeakPayloadData) { |
| 442 // NOTE! Any eventual leak is suppose to be detected by valgrind |
| 443 // or any other similar tool. |
| 444 uint8_t* data1 = new uint8_t[5]; |
| 445 uint8_t* data2 = new uint8_t[5]; |
| 446 uint8_t* data3 = new uint8_t[5]; |
| 447 uint8_t* data4 = new uint8_t[5]; |
| 448 |
| 449 // Expected to free data1 upon PacketBuffer destruction. |
| 450 EXPECT_TRUE(Insert(2, kKeyFrame, kFirst, kNotLast, 5, data1)); |
| 451 |
| 452 // Expect to free data2 upon insertion. |
| 453 EXPECT_TRUE(Insert(2, kKeyFrame, kFirst, kNotLast, 5, data2)); |
| 454 |
| 455 // Expect to free data3 upon insertion (old packet). |
| 456 packet_buffer_->ClearTo(1); |
| 457 EXPECT_FALSE(Insert(1, kKeyFrame, kFirst, kNotLast, 5, data3)); |
| 458 |
| 459 // Expect to free data4 upon insertion (packet buffer is full). |
| 460 EXPECT_FALSE(Insert(2 + kMaxSize, kKeyFrame, kFirst, kNotLast, 5, data4)); |
| 461 } |
| 462 |
441 } // namespace video_coding | 463 } // namespace video_coding |
442 } // namespace webrtc | 464 } // namespace webrtc |
OLD | NEW |