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

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

Issue 1847193003: Convert Vp8 Rtp headers to frame references. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 8 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
« 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
11 #include <cstring> 11 #include <cstring>
12 #include <limits> 12 #include <limits>
13 13
14 #include "webrtc/modules/video_coding/frame_object.h" 14 #include "webrtc/modules/video_coding/frame_object.h"
15 #include "webrtc/modules/video_coding/packet_buffer.h" 15 #include "webrtc/modules/video_coding/packet_buffer.h"
16 16
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/random.h" 18 #include "webrtc/base/random.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 namespace video_coding { 21 namespace video_coding {
22 22
23 class TestPacketBuffer : public ::testing::Test, 23 class TestPacketBuffer : public ::testing::Test,
24 public OnCompleteFrameCallback { 24 public OnCompleteFrameCallback {
25 protected: 25 protected:
26 TestPacketBuffer() 26 TestPacketBuffer()
27 : rand_(0x8739211), packet_buffer_(kStartSize, kMaxSize, this) {} 27 : rand_(0x8739211),
28 packet_buffer_(new PacketBuffer(kStartSize, kMaxSize, this)) {}
28 29
29 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); } 30 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); }
30 31
31 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override { 32 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override {
32 frames_from_callback_.emplace_back(std::move(frame)); 33 uint16_t pid = frame->picture_id;
34 auto frame_it = frames_from_callback_.find(pid);
35 if (frame_it != frames_from_callback_.end()) {
36 ADD_FAILURE() << "Already received frame with picture id: " << pid;
37 return;
38 }
39
40 frames_from_callback_.insert(
41 make_pair(frame->picture_id, std::move(frame)));
33 } 42 }
34 43
35 void TearDown() override { 44 void TearDown() override {
36 // All FrameObjects must be destroyed before the PacketBuffer since 45 // All frame objects must be destroyed before the packet buffer since
37 // a FrameObject will try to remove itself from the packet buffer 46 // a frame object will try to remove itself from the packet buffer
38 // upon destruction. 47 // upon destruction.
39 frames_from_callback_.clear(); 48 frames_from_callback_.clear();
40 } 49 }
41 50
51 // Insert a generic packet into the packet buffer.
52 void InsertGeneric(uint16_t seq_num, // packet sequence number
53 bool keyframe, // is keyframe
54 bool first, // is first packet of frame
55 bool last, // is last packet of frame
56 size_t data_size = 0, // size of data
57 uint8_t* data = nullptr) { // data pointer
58 VCMPacket packet;
59 packet.codec = kVideoCodecGeneric;
60 packet.seqNum = seq_num;
61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
62 packet.isFirstPacket = first;
63 packet.markerBit = last;
64 packet.sizeBytes = data_size;
65 packet.dataPtr = data;
66
67 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
68 }
69
70 // Insert a Vp8 packet into the packet buffer.
71 void InsertVp8(uint16_t seq_num, // packet sequence number
72 bool keyframe, // is keyframe
73 bool first, // is first packet of frame
74 bool last, // is last packet of frame
75 bool sync = false, // is sync frame
76 int32_t pid = kNoPictureId, // picture id
77 uint8_t tid = kNoTemporalIdx, // temporal id
78 int32_t tl0 = kNoTl0PicIdx, // tl0 pic index
79 size_t data_size = 0, // size of data
80 uint8_t* data = nullptr) { // data pointer
81 VCMPacket packet;
82 packet.codec = kVideoCodecVP8;
83 packet.seqNum = seq_num;
84 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
85 packet.isFirstPacket = first;
86 packet.markerBit = last;
87 packet.sizeBytes = data_size;
88 packet.dataPtr = data;
89 packet.codecSpecificHeader.codecHeader.VP8.pictureId = pid % (1 << 15);
90 packet.codecSpecificHeader.codecHeader.VP8.temporalIdx = tid;
91 packet.codecSpecificHeader.codecHeader.VP8.tl0PicIdx = tl0;
92 packet.codecSpecificHeader.codecHeader.VP8.layerSync = sync;
93
94 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
95 }
96
97 // Check if a frame with picture id |pid| has been delivered from the packet
98 // buffer, and if so, if it has the references specified by |refs|.
99 template <typename... T>
100 void CheckReferences(uint16_t pid, T... refs) const {
101 auto frame_it = frames_from_callback_.find(pid);
102 if (frame_it == frames_from_callback_.end()) {
103 ADD_FAILURE() << "Could not find frame with picture id " << pid;
104 return;
105 }
106
107 std::set<uint16_t> actual_refs;
108 for (uint8_t r = 0; r < frame_it->second->num_references; ++r) {
109 actual_refs.insert(frame_it->second->references[r]);
110 }
111
112 std::set<uint16_t> expected_refs;
113 RefsToSet(&expected_refs, refs...);
114
115 ASSERT_EQ(expected_refs, actual_refs);
116 }
117
118 template <typename... T>
119 void RefsToSet(std::set<uint16_t>* m, uint16_t ref, T... refs) const {
120 m->insert(ref);
121 RefsToSet(m, refs...);
122 }
123
124 void RefsToSet(std::set<uint16_t>* m) const {}
125
42 const int kStartSize = 16; 126 const int kStartSize = 16;
43 const int kMaxSize = 64; 127 const int kMaxSize = 64;
44 128
45 Random rand_; 129 Random rand_;
46 PacketBuffer packet_buffer_; 130 std::unique_ptr<PacketBuffer> packet_buffer_;
47 std::vector<std::unique_ptr<FrameObject>> frames_from_callback_; 131 std::map<uint16_t, std::unique_ptr<FrameObject>> frames_from_callback_;
48 }; 132 };
49 133
50 TEST_F(TestPacketBuffer, InsertOnePacket) { 134 TEST_F(TestPacketBuffer, InsertOnePacket) {
51 VCMPacket packet; 135 VCMPacket packet;
52 packet.seqNum = Rand(); 136 packet.seqNum = Rand();
53 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 137 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
54 } 138 }
55 139
56 TEST_F(TestPacketBuffer, InsertMultiplePackets) { 140 TEST_F(TestPacketBuffer, InsertMultiplePackets) {
57 VCMPacket packet; 141 VCMPacket packet;
58 packet.seqNum = Rand(); 142 packet.seqNum = Rand();
59 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 143 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
60 ++packet.seqNum; 144 ++packet.seqNum;
61 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 145 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
62 ++packet.seqNum; 146 ++packet.seqNum;
63 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 147 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
64 } 148 }
65 149
66 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { 150 TEST_F(TestPacketBuffer, InsertDuplicatePacket) {
67 VCMPacket packet; 151 VCMPacket packet;
68 packet.seqNum = Rand(); 152 packet.seqNum = Rand();
69 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 153 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
70 ++packet.seqNum; 154 ++packet.seqNum;
71 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 155 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
72 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 156 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
73 ++packet.seqNum;
74 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
75 } 157 }
76 158
77 TEST_F(TestPacketBuffer, ExpandBuffer) { 159 TEST_F(TestPacketBuffer, ExpandBuffer) {
78 VCMPacket packet; 160 uint16_t seq_num = Rand();
79 packet.seqNum = Rand();
80 161
81 for (int i = 0; i < kStartSize + 1; ++i) { 162 for (int i = 0; i < kStartSize + 1; ++i) {
82 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 163 // seq_num , keyframe, first, last
83 ++packet.seqNum; 164 InsertGeneric(seq_num + i, true , true , true);
84 } 165 }
85 } 166 }
86 167
87 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { 168 TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
88 VCMPacket packet; 169 uint16_t seq_num = Rand();
89 packet.seqNum = Rand();
90 170
91 for (int i = 0; i < kMaxSize; ++i) { 171 for (int i = 0; i < kMaxSize; ++i) {
92 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 172 // seq_num , keyframe, first, last
93 ++packet.seqNum; 173 InsertGeneric(seq_num + i, true , true , true);
94 } 174 }
95 175
96 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 176 VCMPacket packet;
177 packet.seqNum = seq_num + kMaxSize + 1;
178 packet.sizeBytes = 1;
179 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
97 } 180 }
98 181
99 TEST_F(TestPacketBuffer, OnePacketOneFrame) { 182 TEST_F(TestPacketBuffer, GenericOnePacketOneFrame) {
100 VCMPacket packet; 183 // seq_num, keyframe, first, last
101 packet.isFirstPacket = true; 184 InsertGeneric(Rand() , true , true , true);
102 packet.markerBit = true; 185 ASSERT_EQ(1UL, frames_from_callback_.size());
103 packet.seqNum = Rand(); 186 }
104 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 187
188 TEST_F(TestPacketBuffer, GenericTwoPacketsTwoFrames) {
189 uint16_t seq_num = Rand();
190
191 // seq_num , keyframe, first, last
192 InsertGeneric(seq_num , true , true , true);
193 InsertGeneric(seq_num + 1, true , true , true);
194
195 EXPECT_EQ(2UL, frames_from_callback_.size());
196 }
197
198 TEST_F(TestPacketBuffer, GenericTwoPacketsOneFrames) {
199 uint16_t seq_num = Rand();
200
201 // seq_num , keyframe, first, last
202 InsertGeneric(seq_num , true , true , false);
203 InsertGeneric(seq_num + 1, true , false, true);
204
105 EXPECT_EQ(1UL, frames_from_callback_.size()); 205 EXPECT_EQ(1UL, frames_from_callback_.size());
106 } 206 }
107 207
108 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { 208 TEST_F(TestPacketBuffer, GenericThreePacketReorderingOneFrame) {
109 VCMPacket packet; 209 uint16_t seq_num = Rand();
110 packet.isFirstPacket = true;
111 packet.markerBit = true;
112 packet.seqNum = Rand();
113 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
114 ++packet.seqNum;
115 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
116 EXPECT_EQ(2UL, frames_from_callback_.size());
117 }
118 210
119 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { 211 // seq_num , keyframe, first, last
120 VCMPacket packet; 212 InsertGeneric(seq_num , true , true , false);
121 packet.isFirstPacket = true; 213 InsertGeneric(seq_num + 2, true , false, true);
122 packet.seqNum = Rand(); 214 InsertGeneric(seq_num + 1, true , false, false);
123 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 215
124 packet.markerBit = true;
125 ++packet.seqNum;
126 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
127 EXPECT_EQ(1UL, frames_from_callback_.size()); 216 EXPECT_EQ(1UL, frames_from_callback_.size());
128 } 217 }
129 218
130 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) {
131 VCMPacket packet;
132 packet.isFirstPacket = true;
133 packet.seqNum = Rand();
134 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
135 EXPECT_EQ(0UL, frames_from_callback_.size());
136 packet.isFirstPacket = false;
137 packet.markerBit = true;
138 packet.seqNum += 2;
139 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
140 EXPECT_EQ(0UL, frames_from_callback_.size());
141 packet.markerBit = false;
142 packet.seqNum -= 1;
143 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
144 EXPECT_EQ(1UL, frames_from_callback_.size());
145 }
146
147 TEST_F(TestPacketBuffer, IndexWrapOneFrame) {
148 VCMPacket packet;
149 packet.isFirstPacket = true;
150 packet.seqNum = kStartSize - 1;
151 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
152 EXPECT_EQ(0UL, frames_from_callback_.size());
153 packet.isFirstPacket = false;
154 ++packet.seqNum;
155 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
156 EXPECT_EQ(0UL, frames_from_callback_.size());
157 ++packet.seqNum;
158 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
159 EXPECT_EQ(0UL, frames_from_callback_.size());
160 packet.markerBit = true;
161 ++packet.seqNum;
162 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
163 EXPECT_EQ(1UL, frames_from_callback_.size());
164 }
165
166 TEST_F(TestPacketBuffer, DiscardOldPacket) { 219 TEST_F(TestPacketBuffer, DiscardOldPacket) {
167 uint16_t seq_num = Rand(); 220 uint16_t seq_num = Rand();
168 VCMPacket packet; 221 VCMPacket packet;
169 packet.seqNum = Rand(); 222 packet.seqNum = Rand();
170 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 223 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
171 packet.seqNum += 2; 224 packet.seqNum += 2;
172 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 225 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
173 226
174 for (int i = 3; i < kMaxSize; ++i) { 227 for (int i = 3; i < kMaxSize; ++i) {
175 ++packet.seqNum; 228 ++packet.seqNum;
176 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 229 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
177 } 230 }
178 231
179 ++packet.seqNum; 232 ++packet.seqNum;
180 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 233 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
181 packet_buffer_.ClearTo(seq_num + 1); 234 packet_buffer_->ClearTo(seq_num + 1);
182 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 235 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
183 } 236 }
184 237
185 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) { 238 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) {
186 uint16_t seq_num = Rand(); 239 uint16_t seq_num = Rand();
187 VCMPacket packet; 240 VCMPacket packet;
188 packet.seqNum = seq_num; 241 packet.seqNum = seq_num;
189 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 242 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
190 packet.seqNum += 2; 243 packet.seqNum += 2;
191 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 244 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
192 245
193 for (int i = 3; i < kMaxSize; ++i) { 246 for (int i = 3; i < kMaxSize; ++i) {
194 ++packet.seqNum; 247 ++packet.seqNum;
195 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 248 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
196 } 249 }
197 250
198 packet_buffer_.ClearTo(seq_num + 15); 251 packet_buffer_->ClearTo(seq_num + 15);
199 for (int i = 0; i < 15; ++i) { 252 for (int i = 0; i < 15; ++i) {
200 ++packet.seqNum; 253 ++packet.seqNum;
201 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 254 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
202 } 255 }
203 for (int i = 15; i < kMaxSize; ++i) { 256 for (int i = 15; i < kMaxSize; ++i) {
204 ++packet.seqNum; 257 ++packet.seqNum;
205 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 258 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
206 } 259 }
207 } 260 }
208 261
262 TEST_F(TestPacketBuffer, GenericFrames) {
263 uint16_t seq_num = Rand();
264
265 // seq_num , keyf , first, last
266 InsertGeneric(seq_num , true , true , true);
267 InsertGeneric(seq_num + 1, false, true , true);
268 InsertGeneric(seq_num + 2, false, true , true);
269 InsertGeneric(seq_num + 3, false, true , true);
270
271 ASSERT_EQ(4UL, frames_from_callback_.size());
272 CheckReferences(seq_num);
273 CheckReferences(seq_num + 1, seq_num);
274 CheckReferences(seq_num + 2, seq_num + 1);
275 CheckReferences(seq_num + 3, seq_num + 2);
276 }
277
278 TEST_F(TestPacketBuffer, GenericFramesReordered) {
279 uint16_t seq_num = Rand();
280
281 // seq_num , keyf , first, last
282 InsertGeneric(seq_num + 1, false, true , true);
283 InsertGeneric(seq_num , true , true , true);
284 InsertGeneric(seq_num + 3, false, true , true);
285 InsertGeneric(seq_num + 2, false, true , true);
286
287 ASSERT_EQ(4UL, frames_from_callback_.size());
288 CheckReferences(seq_num);
289 CheckReferences(seq_num + 1, seq_num);
290 CheckReferences(seq_num + 2, seq_num + 1);
291 CheckReferences(seq_num + 3, seq_num + 2);
292 }
293
209 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { 294 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
210 // "many bitstream, such data" with null termination. 295 // "many bitstream, such data" with null termination.
211 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 296 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
212 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 297 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
213 0x65, 0x61, 0x6d, 0x2c, 0x20}; 298 0x65, 0x61, 0x6d, 0x2c, 0x20};
214 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 299 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
215 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 300 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
216 uint8_t 301 uint8_t
217 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 302 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
218 303
304 uint16_t seq_num = Rand();
305
306 // seq_num , keyf , first, last , data_size , data
307 InsertGeneric(seq_num , true , true , false, sizeof(many) , many);
308 InsertGeneric(seq_num + 1, false, false, false, sizeof(bitstream), bitstream);
309 InsertGeneric(seq_num + 2, false, false, false, sizeof(such) , such);
310 InsertGeneric(seq_num + 3, false, false, true , sizeof(data) , data);
311
312 ASSERT_EQ(1UL, frames_from_callback_.size());
313 CheckReferences(seq_num + 3);
314 EXPECT_TRUE(frames_from_callback_[seq_num + 3]->GetBitstream(result));
315 EXPECT_EQ(std::strcmp("many bitstream, such data",
316 reinterpret_cast<char*>(result)),
317 0);
318 }
319
320 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
321 uint16_t seq_num = Rand();
322
323 // seq_num , keyf , first, last
324 InsertGeneric(seq_num , true , true , false);
325 InsertGeneric(seq_num + 1, false, false, false);
326 InsertGeneric(seq_num + 2, false, false, true);
327 EXPECT_EQ(1UL, frames_from_callback_.size());
328
329 frames_from_callback_.clear();
330
331 // seq_num , keyf , first, last
332 InsertGeneric(seq_num , true , true , false);
333 InsertGeneric(seq_num + 1, false, false, false);
334 InsertGeneric(seq_num + 2, false, false, true);
335 EXPECT_EQ(1UL, frames_from_callback_.size());
336 }
337
338 TEST_F(TestPacketBuffer, Flush) {
339 uint16_t seq_num = Rand();
340
341 // seq_num , keyf , first, last
342 InsertGeneric(seq_num , true , true , false);
343 InsertGeneric(seq_num + 1, false, false, false);
344 InsertGeneric(seq_num + 2, false, false, true);
345 EXPECT_EQ(1UL, frames_from_callback_.size());
346
347 packet_buffer_->Flush();
348
349 // seq_num , keyf , first, last
350 InsertGeneric(seq_num + kStartSize , true , true , false);
351 InsertGeneric(seq_num + kStartSize + 1, false, false, false);
352 InsertGeneric(seq_num + kStartSize + 2, false, false, true);
353 EXPECT_EQ(2UL, frames_from_callback_.size());
354 }
355
356 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
219 VCMPacket packet; 357 VCMPacket packet;
220 packet.isFirstPacket = true; 358 packet.codec = kVideoCodecGeneric;
221 packet.seqNum = 0xfffe; 359 packet.frameType = kVideoFrameKey;
222 packet.dataPtr = many;
223 packet.sizeBytes = sizeof(many);
224 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
225 packet.isFirstPacket = false;
226 ++packet.seqNum;
227 packet.dataPtr = bitstream;
228 packet.sizeBytes = sizeof(bitstream);
229 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
230 ++packet.seqNum;
231 packet.dataPtr = such;
232 packet.sizeBytes = sizeof(such);
233 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
234 packet.markerBit = true;
235 ++packet.seqNum;
236 packet.dataPtr = data;
237 packet.sizeBytes = sizeof(data);
238 EXPECT_EQ(0UL, frames_from_callback_.size());
239 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
240 ASSERT_EQ(1UL, frames_from_callback_.size());
241
242 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result));
243 EXPECT_EQ(
244 std::strcmp("many bitstream, such data", reinterpret_cast<char*>(result)),
245 0);
246 }
247
248 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
249 VCMPacket packet;
250 packet.isFirstPacket = true;
251 packet.seqNum = Rand();
252 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
253 EXPECT_EQ(0UL, frames_from_callback_.size());
254 packet.isFirstPacket = false;
255 ++packet.seqNum;
256 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
257 EXPECT_EQ(0UL, frames_from_callback_.size());
258 ++packet.seqNum;
259 packet.markerBit = true;
260 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
261 EXPECT_EQ(1UL, frames_from_callback_.size());
262
263 frames_from_callback_.clear();
264
265 packet.isFirstPacket = true;
266 packet.markerBit = false;
267 packet.seqNum = Rand();
268 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
269 EXPECT_EQ(0UL, frames_from_callback_.size());
270 packet.isFirstPacket = false;
271 ++packet.seqNum;
272 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
273 EXPECT_EQ(0UL, frames_from_callback_.size());
274 ++packet.seqNum;
275 packet.markerBit = true;
276 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
277 EXPECT_EQ(1UL, frames_from_callback_.size());
278 }
279
280 TEST_F(TestPacketBuffer, Flush) {
281 VCMPacket packet;
282 packet.isFirstPacket = true; 360 packet.isFirstPacket = true;
283 packet.markerBit = true; 361 packet.markerBit = true;
284 packet.seqNum = Rand(); 362 packet.seqNum = Rand();
285 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 363 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
286 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
287 packet_buffer_.Flush();
288 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
289 EXPECT_EQ(2UL, frames_from_callback_.size());
290 }
291
292 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
293 VCMPacket packet;
294 packet.isFirstPacket = true;
295 packet.markerBit = true;
296 packet.seqNum = Rand();
297 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
298 ASSERT_EQ(1UL, frames_from_callback_.size()); 364 ASSERT_EQ(1UL, frames_from_callback_.size());
299 365
300 packet_buffer_.Flush(); 366 packet_buffer_->Flush();
301 EXPECT_FALSE(frames_from_callback_[0]->GetBitstream(nullptr)); 367 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
368 }
369
370 TEST_F(TestPacketBuffer, Vp8NoPictureId) {
371 uint16_t seq_num = Rand();
372
373 // seq_num , keyf , first, last
374 InsertVp8(seq_num , true , true , false);
375 InsertVp8(seq_num + 1 , false, false, false);
376 InsertVp8(seq_num + 2 , false, false, true);
377 ASSERT_EQ(1UL, frames_from_callback_.size());
378
379 InsertVp8(seq_num + 3 , false, true , false);
380 InsertVp8(seq_num + 4 , false, false, true);
381 ASSERT_EQ(2UL, frames_from_callback_.size());
382
383 InsertVp8(seq_num + 5 , false, true , false);
384 InsertVp8(seq_num + 6 , false, false, false);
385 InsertVp8(seq_num + 7 , false, false, false);
386 InsertVp8(seq_num + 8 , false, false, true);
387 ASSERT_EQ(3UL, frames_from_callback_.size());
388
389 InsertVp8(seq_num + 9 , false, true , true);
390 ASSERT_EQ(4UL, frames_from_callback_.size());
391
392 InsertVp8(seq_num + 10, false, true , false);
393 InsertVp8(seq_num + 11, false, false, true);
394 ASSERT_EQ(5UL, frames_from_callback_.size());
395
396 InsertVp8(seq_num + 12, true , true , true);
397 ASSERT_EQ(6UL, frames_from_callback_.size());
398
399 InsertVp8(seq_num + 13, false, true , false);
400 InsertVp8(seq_num + 14, false, false, false);
401 InsertVp8(seq_num + 15, false, false, false);
402 InsertVp8(seq_num + 16, false, false, false);
403 InsertVp8(seq_num + 17, false, false, true);
404 ASSERT_EQ(7UL, frames_from_callback_.size());
405
406 InsertVp8(seq_num + 18, false, true , true);
407 ASSERT_EQ(8UL, frames_from_callback_.size());
408
409 InsertVp8(seq_num + 19, false, true , false);
410 InsertVp8(seq_num + 20, false, false, true);
411 ASSERT_EQ(9UL, frames_from_callback_.size());
412
413 InsertVp8(seq_num + 21, false, true , true);
414
415 ASSERT_EQ(10UL, frames_from_callback_.size());
416 CheckReferences(seq_num + 2);
417 CheckReferences(seq_num + 4, seq_num + 2);
418 CheckReferences(seq_num + 8, seq_num + 4);
419 CheckReferences(seq_num + 9, seq_num + 8);
420 CheckReferences(seq_num + 11, seq_num + 9);
421 CheckReferences(seq_num + 12);
422 CheckReferences(seq_num + 17, seq_num + 12);
423 CheckReferences(seq_num + 18, seq_num + 17);
424 CheckReferences(seq_num + 20, seq_num + 18);
425 CheckReferences(seq_num + 21, seq_num + 20);
426 }
427
428 TEST_F(TestPacketBuffer, Vp8NoPictureIdReordered) {
429 uint16_t seq_num = 0xfffa;
430
431 // seq_num , keyf , first, last
432 InsertVp8(seq_num + 1 , false, false, false);
433 InsertVp8(seq_num , true , true , false);
434 InsertVp8(seq_num + 2 , false, false, true);
435 InsertVp8(seq_num + 4 , false, false, true);
436 InsertVp8(seq_num + 6 , false, false, false);
437 InsertVp8(seq_num + 3 , false, true , false);
438 InsertVp8(seq_num + 7 , false, false, false);
439 InsertVp8(seq_num + 5 , false, true , false);
440 InsertVp8(seq_num + 9 , false, true , true);
441 InsertVp8(seq_num + 10, false, true , false);
442 InsertVp8(seq_num + 8 , false, false, true);
443 InsertVp8(seq_num + 13, false, true , false);
444 InsertVp8(seq_num + 14, false, false, false);
445 InsertVp8(seq_num + 12, true , true , true);
446 InsertVp8(seq_num + 11, false, false, true);
447 InsertVp8(seq_num + 16, false, false, false);
448 InsertVp8(seq_num + 19, false, true , false);
449 InsertVp8(seq_num + 15, false, false, false);
450 InsertVp8(seq_num + 17, false, false, true);
451 InsertVp8(seq_num + 20, false, false, true);
452 InsertVp8(seq_num + 21, false, true , true);
453 InsertVp8(seq_num + 18, false, true , true);
454
455 ASSERT_EQ(10UL, frames_from_callback_.size());
456 CheckReferences(seq_num + 2);
457 CheckReferences(seq_num + 4, seq_num + 2);
458 CheckReferences(seq_num + 8, seq_num + 4);
459 CheckReferences(seq_num + 9, seq_num + 8);
460 CheckReferences(seq_num + 11, seq_num + 9);
461 CheckReferences(seq_num + 12);
462 CheckReferences(seq_num + 17, seq_num + 12);
463 CheckReferences(seq_num + 18, seq_num + 17);
464 CheckReferences(seq_num + 20, seq_num + 18);
465 CheckReferences(seq_num + 21, seq_num + 20);
466 }
467
468
469 TEST_F(TestPacketBuffer, Vp8KeyFrameReferences) {
470 uint16_t pid = Rand();
471 // seq_num, keyf, first, last, sync , pid, tid, tl0
472 InsertVp8(Rand() , true, true , true, false, pid, 0 , 0);
473
474 ASSERT_EQ(1UL, frames_from_callback_.size());
475 CheckReferences(pid);
476 }
477
478 // Test with 1 temporal layer.
479 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0) {
480 uint16_t pid = Rand();
481 uint16_t seq_num = Rand();
482
483 // seq_num , keyf , first, last, sync , pid , tid, tl0
484 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
485 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
486 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
487 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
488
489 ASSERT_EQ(4UL, frames_from_callback_.size());
490 CheckReferences(pid);
491 CheckReferences(pid + 1, pid);
492 CheckReferences(pid + 2, pid + 1);
493 CheckReferences(pid + 3, pid + 2);
494 }
495
496 // Test with 1 temporal layer.
497 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0) {
498 uint16_t pid = Rand();
499 uint16_t seq_num = Rand();
500
501 // seq_num , keyf , first, last, sync , pid , tid, tl0
502 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
503 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
504 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
505 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
506 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 0 , 6);
507 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 7);
508 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 5);
509
510 ASSERT_EQ(7UL, frames_from_callback_.size());
511 CheckReferences(pid);
512 CheckReferences(pid + 1, pid);
513 CheckReferences(pid + 2, pid + 1);
514 CheckReferences(pid + 3, pid + 2);
515 CheckReferences(pid + 4, pid + 3);
516 CheckReferences(pid + 5, pid + 4);
517 CheckReferences(pid + 6, pid + 5);
518 }
519
520 // Test with 2 temporal layers in a 01 pattern.
521 TEST_F(TestPacketBuffer, Vp8TemporalLayers_01) {
522 uint16_t pid = Rand();
523 uint16_t seq_num = Rand();
524
525 // seq_num , keyf , first, last, sync , pid , tid, tl0
526 InsertVp8(seq_num , true , true , true, false, pid , 0, 255);
527 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1, 255);
528 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0, 0);
529 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1, 0);
530
531 ASSERT_EQ(4UL, frames_from_callback_.size());
532 CheckReferences(pid);
533 CheckReferences(pid + 1, pid);
534 CheckReferences(pid + 2, pid);
535 CheckReferences(pid + 3, pid + 1, pid + 2);
536 }
537
538 // Test with 2 temporal layers in a 01 pattern.
539 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_01) {
540 uint16_t pid = Rand();
541 uint16_t seq_num = Rand();
542
543 // seq_num , keyf , first, last, sync , pid , tid, tl0
544 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1 , 255);
545 InsertVp8(seq_num , true , true , true, false, pid , 0 , 255);
546 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1 , 0);
547 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 1 , 1);
548 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 0);
549 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 1);
550 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 2);
551 InsertVp8(seq_num + 7, false, true , true, false, pid + 7, 1 , 2);
552
553 ASSERT_EQ(8UL, frames_from_callback_.size());
554 CheckReferences(pid);
555 CheckReferences(pid + 1, pid);
556 CheckReferences(pid + 2, pid);
557 CheckReferences(pid + 3, pid + 1, pid + 2);
558 CheckReferences(pid + 4, pid + 2);
559 CheckReferences(pid + 5, pid + 3, pid + 4);
560 CheckReferences(pid + 6, pid + 4);
561 CheckReferences(pid + 7, pid + 5, pid + 6);
562 }
563
564 // Test with 3 temporal layers in a 0212 pattern.
565 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0212) {
566 uint16_t pid = Rand();
567 uint16_t seq_num = Rand();
568
569 // seq_num , keyf , first, last, sync , pid , tid, tl0
570 InsertVp8(seq_num , true , true , true , false, pid , 0 , 55);
571 InsertVp8(seq_num + 1 , false, true , true , true , pid + 1 , 2 , 55);
572 InsertVp8(seq_num + 2 , false, true , true , true , pid + 2 , 1 , 55);
573 InsertVp8(seq_num + 3 , false, true , true , false, pid + 3 , 2 , 55);
574 InsertVp8(seq_num + 4 , false, true , true , false, pid + 4 , 0 , 56);
575 InsertVp8(seq_num + 5 , false, true , true , false, pid + 5 , 2 , 56);
576 InsertVp8(seq_num + 6 , false, true , true , false, pid + 6 , 1 , 56);
577 InsertVp8(seq_num + 7 , false, true , true , false, pid + 7 , 2 , 56);
578 InsertVp8(seq_num + 8 , false, true , true , false, pid + 8 , 0 , 57);
579 InsertVp8(seq_num + 9 , false, true , true , true , pid + 9 , 2 , 57);
580 InsertVp8(seq_num + 10, false, true , true , true , pid + 10, 1 , 57);
581 InsertVp8(seq_num + 11, false, true , true , false, pid + 11, 2 , 57);
582
583 ASSERT_EQ(12UL, frames_from_callback_.size());
584 CheckReferences(pid);
585 CheckReferences(pid + 1 , pid);
586 CheckReferences(pid + 2 , pid);
587 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
588 CheckReferences(pid + 4 , pid);
589 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
590 CheckReferences(pid + 6 , pid + 2, pid + 4);
591 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
592 CheckReferences(pid + 8 , pid + 4);
593 CheckReferences(pid + 9 , pid + 8);
594 CheckReferences(pid + 10, pid + 8);
595 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
596 }
597
598 // Test with 3 temporal layers in a 0212 pattern.
599 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0212) {
600 uint16_t pid = 126;
601 uint16_t seq_num = Rand();
602
603 // seq_num , keyf , first, last, sync , pid , tid, tl0
604 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 2 , 55);
605 InsertVp8(seq_num , true , true , true, false, pid , 0 , 55);
606 InsertVp8(seq_num + 2 , false, true , true, true , pid + 2 , 1 , 55);
607 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 56);
608 InsertVp8(seq_num + 5 , false, true , true, false, pid + 5 , 2 , 56);
609 InsertVp8(seq_num + 3 , false, true , true, false, pid + 3 , 2 , 55);
610 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 2 , 56);
611 InsertVp8(seq_num + 9 , false, true , true, true , pid + 9 , 2 , 57);
612 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 1 , 56);
613 InsertVp8(seq_num + 8 , false, true , true, false, pid + 8 , 0 , 57);
614 InsertVp8(seq_num + 11, false, true , true, false, pid + 11, 2 , 57);
615 InsertVp8(seq_num + 10, false, true , true, true , pid + 10, 1 , 57);
616
617 ASSERT_EQ(12UL, frames_from_callback_.size());
618 CheckReferences(pid);
619 CheckReferences(pid + 1 , pid);
620 CheckReferences(pid + 2 , pid);
621 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
622 CheckReferences(pid + 4 , pid);
623 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
624 CheckReferences(pid + 6 , pid + 2, pid + 4);
625 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
626 CheckReferences(pid + 8 , pid + 4);
627 CheckReferences(pid + 9 , pid + 8);
628 CheckReferences(pid + 10, pid + 8);
629 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
630 }
631
632 TEST_F(TestPacketBuffer, Vp8InsertManyFrames_0212) {
633 uint16_t pid = Rand();
634 uint16_t seq_num = Rand();
635
636 const int keyframes_to_insert = 50;
637 const int frames_per_keyframe = 120; // Should be a multiple of 4.
638 uint8_t tl0 = 128;
639
640 for (int k = 0; k < keyframes_to_insert; ++k) {
641 // seq_num , keyf , first, last , sync , pid , tid, tl0
642 InsertVp8(seq_num , true , true , true , false, pid , 0 , tl0);
643 InsertVp8(seq_num + 1, false, true , true , true , pid + 1, 2 , tl0);
644 InsertVp8(seq_num + 2, false, true , true , true , pid + 2, 1 , tl0);
645 InsertVp8(seq_num + 3, false, true , true , false, pid + 3, 2 , tl0);
646 CheckReferences(pid);
647 CheckReferences(pid + 1, pid);
648 CheckReferences(pid + 2, pid);
649 CheckReferences(pid + 3, pid, pid + 1, pid + 2);
650 frames_from_callback_.clear();
651 ++tl0;
652
653 for (int f = 4; f < frames_per_keyframe; f += 4) {
654 uint16_t sf = seq_num + f;
655 uint16_t pidf = pid + f;
656
657 // seq_num, keyf , first, last, sync , pid , tid, tl0
658 InsertVp8(sf , false, true , true, false, pidf , 0 , tl0);
659 InsertVp8(sf + 1 , false, true , true, false, pidf + 1, 2 , tl0);
660 InsertVp8(sf + 2 , false, true , true, false, pidf + 2, 1 , tl0);
661 InsertVp8(sf + 3 , false, true , true, false, pidf + 3, 2 , tl0);
662 CheckReferences(pidf, pidf - 4);
663 CheckReferences(pidf + 1, pidf, pidf - 1, pidf - 2);
664 CheckReferences(pidf + 2, pidf, pidf - 2);
665 CheckReferences(pidf + 3, pidf, pidf + 1, pidf + 2);
666 frames_from_callback_.clear();
667 ++tl0;
668 }
669
670 pid += frames_per_keyframe;
671 seq_num += frames_per_keyframe;
672 }
673 }
674
675 TEST_F(TestPacketBuffer, Vp8LayerSync) {
676 uint16_t pid = Rand();
677 uint16_t seq_num = Rand();
678
679 // seq_num , keyf , first, last, sync , pid , tid, tl0
680 InsertVp8(seq_num , true , true , true, false, pid , 0 , 0);
681 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 1 , 0);
682 InsertVp8(seq_num + 2 , false, true , true, false, pid + 2 , 0 , 1);
683 ASSERT_EQ(3UL, frames_from_callback_.size());
684
685 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 2);
686 InsertVp8(seq_num + 5 , false, true , true, true , pid + 5 , 1 , 2);
687 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 0 , 3);
688 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 1 , 3);
689
690 ASSERT_EQ(7UL, frames_from_callback_.size());
691 CheckReferences(pid);
692 CheckReferences(pid + 1, pid);
693 CheckReferences(pid + 2, pid);
694 CheckReferences(pid + 4, pid + 2);
695 CheckReferences(pid + 5, pid + 4);
696 CheckReferences(pid + 6, pid + 4);
697 CheckReferences(pid + 7, pid + 6, pid + 5);
698 }
699
700 TEST_F(TestPacketBuffer, Vp8InsertLargeFrames) {
701 packet_buffer_.reset(new PacketBuffer(1 << 3, 1 << 12, this));
702 uint16_t pid = Rand();
703 uint16_t seq_num = Rand();
704
705 const uint16_t packets_per_frame = 1000;
706 uint16_t current = seq_num;
707 uint16_t end = current + packets_per_frame;
708
709 // seq_num , keyf , first, last , sync , pid, tid, tl0
710 InsertVp8(current++, true , true , false, false, pid, 0 , 0);
711 while (current != end)
712 InsertVp8(current++, false, false, false, false, pid, 0 , 0);
713 InsertVp8(current++, false, false, true , false, pid, 0 , 0);
714 end = current + packets_per_frame;
715
716 for (int f = 1; f < 4; ++f) {
717 InsertVp8(current++, false, true , false, false, pid + f, 0, f);
718 while (current != end)
719 InsertVp8(current++, false, false, false, false, pid + f, 0, f);
720 InsertVp8(current++, false, false, true , false, pid + f, 0, f);
721 end = current + packets_per_frame;
722 }
723
724 ASSERT_EQ(4UL, frames_from_callback_.size());
725 CheckReferences(pid);
726 CheckReferences(pid + 1, pid);
727 CheckReferences(pid + 2, pid + 1);
728 CheckReferences(pid + 3, pid + 2);
302 } 729 }
303 730
304 } // namespace video_coding 731 } // namespace video_coding
305 } // namespace webrtc 732 } // 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