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

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: 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
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 11 matching lines...) Expand all
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), packet_buffer_(kStartSize, kMaxSize, this) {}
28 28
29 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); } 29 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); }
30 30
31 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override { 31 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override {
32 frames_from_callback_.emplace_back(std::move(frame)); 32 uint16_t pid = frame->picture_id;
33 auto frame_it = frames_from_callback_.find(pid);
34 if (frame_it != frames_from_callback_.end()) {
35 ADD_FAILURE() << "Already received frame with picture id: " << pid;
36 return;
37 }
38
39 frames_from_callback_.insert(
40 make_pair(frame->picture_id, std::move(frame)));
33 } 41 }
34 42
35 void TearDown() override { 43 void TearDown() override {
36 // All FrameObjects must be destroyed before the PacketBuffer since 44 // All frame objects must be destroyed before the packet buffer since
37 // a FrameObject will try to remove itself from the packet buffer 45 // a frame object will try to remove itself from the packet buffer
38 // upon destruction. 46 // upon destruction.
39 frames_from_callback_.clear(); 47 frames_from_callback_.clear();
40 } 48 }
41 49
50 // Insert a generic packet into the packet buffer.
51 void InsertGeneric(uint16_t seq_num, // packet sequence number
52 bool keyframe, // is keyframe
53 bool first, // is first packet of frame
54 bool last, // is last packet of frame
55 size_t data_size = 0, // size of data
56 uint8_t* data = nullptr) { // data pointer
57 VCMPacket packet;
58 packet.codec = kVideoCodecGeneric;
59 packet.seqNum = seq_num;
60 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
61 packet.isFirstPacket = first;
62 packet.markerBit = last;
63 packet.sizeBytes = data_size;
64 packet.dataPtr = data;
65
66 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
67 }
68
69 // Insert a Vp8 packet into the packet buffer.
70 void InsertVp8(uint16_t seq_num, // packet sequence number
71 bool keyframe, // is keyframe
72 bool first, // is first packet of frame
73 bool last, // is last packet of frame
74 bool sync = false, // is sync frame
75 int32_t pid = kNoPictureId, // picture id
76 uint8_t tid = kNoTemporalIdx, // temporal id
77 int16_t tl0 = kNoTl0PicIdx, // tl0 pic index
78 size_t data_size = 0, // size of data
79 uint8_t* data = nullptr) { // data pointer
80 VCMPacket packet;
81 packet.codec = kVideoCodecVP8;
82 packet.seqNum = seq_num;
83 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
84 packet.isFirstPacket = first;
85 packet.markerBit = last;
86 packet.sizeBytes = data_size;
87 packet.dataPtr = data;
88 packet.codecSpecificHeader.codecHeader.VP8.pictureId = pid;
89 packet.codecSpecificHeader.codecHeader.VP8.temporalIdx = tid;
90 packet.codecSpecificHeader.codecHeader.VP8.tl0PicIdx = tl0;
91 packet.codecSpecificHeader.codecHeader.VP8.layerSync = sync;
92
93 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
94 }
95
96 // Check if a frame with picture id |pid| has been delivered from the packet
97 // buffer, and if so, if it has the references specified by |refs|.
98 template <typename... T>
99 void CheckReferences(int16_t pid, T... refs) const {
100 auto frame_it = frames_from_callback_.find(pid);
101 if (frame_it == frames_from_callback_.end()) {
102 ADD_FAILURE() << "Could not find frame with picture id " << pid;
103 return;
104 }
105
106 std::set<uint16_t> actual_refs;
107 for (uint8_t r = 0; r < frame_it->second->num_references; ++r) {
108 actual_refs.insert(frame_it->second->references[r]);
109 }
110
111 std::set<uint16_t> expected_refs;
112 RefsToSet(&expected_refs, refs...);
113
114 ASSERT_EQ(expected_refs, actual_refs);
115 }
116
117 template <typename... T>
118 void RefsToSet(std::set<uint16_t>* m, uint16_t ref, T... refs) const {
119 m->insert(ref);
120 RefsToSet(m, refs...);
121 }
122
123 void RefsToSet(std::set<uint16_t>* m) const {}
124
42 const int kStartSize = 16; 125 const int kStartSize = 16;
43 const int kMaxSize = 64; 126 const int kMaxSize = 64;
44 127
45 Random rand_; 128 Random rand_;
46 PacketBuffer packet_buffer_; 129 PacketBuffer packet_buffer_;
47 std::vector<std::unique_ptr<FrameObject>> frames_from_callback_; 130 std::map<uint16_t, std::unique_ptr<FrameObject>> frames_from_callback_;
48 }; 131 };
49 132
50 TEST_F(TestPacketBuffer, InsertOnePacket) { 133 TEST_F(TestPacketBuffer, InsertOnePacket) {
51 VCMPacket packet; 134 VCMPacket packet;
52 packet.seqNum = Rand(); 135 packet.seqNum = Rand();
53 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 136 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
54 } 137 }
55 138
56 TEST_F(TestPacketBuffer, InsertMultiplePackets) { 139 TEST_F(TestPacketBuffer, InsertMultiplePackets) {
57 VCMPacket packet; 140 VCMPacket packet;
58 packet.seqNum = Rand(); 141 packet.seqNum = Rand();
59 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 142 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
60 ++packet.seqNum; 143 ++packet.seqNum;
61 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 144 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
62 ++packet.seqNum; 145 ++packet.seqNum;
63 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 146 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
64 } 147 }
65 148
66 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { 149 TEST_F(TestPacketBuffer, InsertDuplicatePacket) {
67 VCMPacket packet; 150 VCMPacket packet;
68 packet.seqNum = Rand(); 151 packet.seqNum = Rand();
69 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 152 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
70 ++packet.seqNum; 153 ++packet.seqNum;
71 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 154 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
72 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 155 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
73 ++packet.seqNum;
74 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
75 } 156 }
76 157
77 TEST_F(TestPacketBuffer, ExpandBuffer) { 158 TEST_F(TestPacketBuffer, ExpandBuffer) {
78 VCMPacket packet; 159 uint16_t seq_num = Rand();
79 packet.seqNum = Rand();
80 160
81 for (int i = 0; i < kStartSize + 1; ++i) { 161 for (int i = 0; i < kStartSize + 1; ++i) {
82 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 162 // seq_num , keyframe, first, last
83 ++packet.seqNum; 163 InsertGeneric(seq_num + i, true , true , true);
84 } 164 }
85 } 165 }
86 166
87 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { 167 TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
88 VCMPacket packet; 168 uint16_t seq_num = Rand();
89 packet.seqNum = Rand();
90 169
91 for (int i = 0; i < kMaxSize; ++i) { 170 for (int i = 0; i < kMaxSize; ++i) {
92 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 171 // seq_num , keyframe, first, last
93 ++packet.seqNum; 172 InsertGeneric(seq_num + i, true , true , true);
94 } 173 }
95 174
175 VCMPacket packet;
176 packet.seqNum = seq_num + kMaxSize + 1;
177 packet.sizeBytes = 1;
96 EXPECT_FALSE(packet_buffer_.InsertPacket(packet)); 178 EXPECT_FALSE(packet_buffer_.InsertPacket(packet));
97 } 179 }
98 180
99 TEST_F(TestPacketBuffer, OnePacketOneFrame) { 181 TEST_F(TestPacketBuffer, GenericOnePacketOneFrame) {
100 VCMPacket packet; 182 // seq_num, keyframe, first, last
101 packet.isFirstPacket = true; 183 InsertGeneric(Rand() , true , true , true);
102 packet.markerBit = true; 184 ASSERT_EQ(1UL, frames_from_callback_.size());
103 packet.seqNum = Rand(); 185 }
104 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 186
187 TEST_F(TestPacketBuffer, GenericTwoPacketsTwoFrames) {
188 uint16_t seq_num = Rand();
189
190 // seq_num , keyframe, first, last
191 InsertGeneric(seq_num , true , true , true);
192 InsertGeneric(seq_num + 1, true , true , true);
193
194 EXPECT_EQ(2UL, frames_from_callback_.size());
195 }
196
197 TEST_F(TestPacketBuffer, GenericTwoPacketsOneFrames) {
198 uint16_t seq_num = Rand();
199
200 // seq_num , keyframe, first, last
201 InsertGeneric(seq_num , true , true , false);
202 InsertGeneric(seq_num + 1, true , false, true);
203
105 EXPECT_EQ(1UL, frames_from_callback_.size()); 204 EXPECT_EQ(1UL, frames_from_callback_.size());
106 } 205 }
107 206
108 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { 207 TEST_F(TestPacketBuffer, GenericThreePacketReorderingOneFrame) {
109 VCMPacket packet; 208 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 209
119 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { 210 // seq_num , keyframe, first, last
120 VCMPacket packet; 211 InsertGeneric(seq_num , true , true , false);
121 packet.isFirstPacket = true; 212 InsertGeneric(seq_num + 2, true , false, true);
122 packet.seqNum = Rand(); 213 InsertGeneric(seq_num + 1, true , false, false);
123 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 214
124 packet.markerBit = true;
125 ++packet.seqNum;
126 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
127 EXPECT_EQ(1UL, frames_from_callback_.size()); 215 EXPECT_EQ(1UL, frames_from_callback_.size());
128 } 216 }
129 217
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) { 218 TEST_F(TestPacketBuffer, DiscardOldPacket) {
167 uint16_t seq_num = Rand(); 219 uint16_t seq_num = Rand();
168 VCMPacket packet; 220 VCMPacket packet;
169 packet.seqNum = Rand(); 221 packet.seqNum = Rand();
170 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 222 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
171 packet.seqNum += 2; 223 packet.seqNum += 2;
172 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 224 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
173 225
174 for (int i = 3; i < kMaxSize; ++i) { 226 for (int i = 3; i < kMaxSize; ++i) {
175 ++packet.seqNum; 227 ++packet.seqNum;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { 261 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
210 // "many bitstream, such data" with null termination. 262 // "many bitstream, such data" with null termination.
211 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 263 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
212 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 264 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
213 0x65, 0x61, 0x6d, 0x2c, 0x20}; 265 0x65, 0x61, 0x6d, 0x2c, 0x20};
214 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 266 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
215 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 267 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
216 uint8_t 268 uint8_t
217 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 269 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
218 270
219 VCMPacket packet; 271 uint16_t seq_num = Rand();
220 packet.isFirstPacket = true; 272
221 packet.seqNum = 0xfffe; 273 // seq_num , keyf , first, last , data_size , data
222 packet.dataPtr = many; 274 InsertGeneric(seq_num , true , true , false, sizeof(many) , many);
223 packet.sizeBytes = sizeof(many); 275 InsertGeneric(seq_num + 1, false, false, false, sizeof(bitstream), bitstream);
224 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 276 InsertGeneric(seq_num + 2, false, false, false, sizeof(such) , such);
225 packet.isFirstPacket = false; 277 InsertGeneric(seq_num + 3, false, false, true , sizeof(data) , data);
226 ++packet.seqNum; 278
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()); 279 ASSERT_EQ(1UL, frames_from_callback_.size());
241 280 CheckReferences(seq_num + 3);
242 EXPECT_TRUE(frames_from_callback_[0]->GetBitstream(result)); 281 EXPECT_TRUE(frames_from_callback_[seq_num + 3]->GetBitstream(result));
243 EXPECT_EQ( 282 EXPECT_EQ(std::strcmp("many bitstream, such data",
244 std::strcmp("many bitstream, such data", reinterpret_cast<char*>(result)), 283 reinterpret_cast<char*>(result)),
245 0); 284 0);
246 } 285 }
247 286
248 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { 287 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
249 VCMPacket packet; 288 uint16_t seq_num = Rand();
250 packet.isFirstPacket = true; 289
251 packet.seqNum = Rand(); 290 // seq_num , keyf , first, last
252 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 291 InsertGeneric(seq_num , true , true , false);
253 EXPECT_EQ(0UL, frames_from_callback_.size()); 292 InsertGeneric(seq_num + 1, false, false, false);
254 packet.isFirstPacket = false; 293 InsertGeneric(seq_num + 2, false, false, true);
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()); 294 EXPECT_EQ(1UL, frames_from_callback_.size());
262 295
263 frames_from_callback_.clear(); 296 frames_from_callback_.clear();
264 297
265 packet.isFirstPacket = true; 298 // seq_num , keyf , first, last
266 packet.markerBit = false; 299 InsertGeneric(seq_num , true , true , false);
267 packet.seqNum = Rand(); 300 InsertGeneric(seq_num + 1, false, false, false);
268 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 301 InsertGeneric(seq_num + 2, false, false, true);
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()); 302 EXPECT_EQ(1UL, frames_from_callback_.size());
278 } 303 }
279 304
280 TEST_F(TestPacketBuffer, Flush) { 305 TEST_F(TestPacketBuffer, Flush) {
281 VCMPacket packet; 306 uint16_t seq_num = Rand();
282 packet.isFirstPacket = true; 307
283 packet.markerBit = true; 308 // seq_num , keyf , first, last
284 packet.seqNum = Rand(); 309 InsertGeneric(seq_num , true , true , false);
285 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 310 InsertGeneric(seq_num + 1, false, false, false);
286 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 311 InsertGeneric(seq_num + 2, false, false, true);
312 EXPECT_EQ(1UL, frames_from_callback_.size());
313
287 packet_buffer_.Flush(); 314 packet_buffer_.Flush();
288 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 315
316 // seq_num , keyf , first, last
317 InsertGeneric(seq_num + kStartSize , true , true , false);
318 InsertGeneric(seq_num + kStartSize + 1, false, false, false);
319 InsertGeneric(seq_num + kStartSize + 2, false, false, true);
289 EXPECT_EQ(2UL, frames_from_callback_.size()); 320 EXPECT_EQ(2UL, frames_from_callback_.size());
290 } 321 }
291 322
292 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) { 323 TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
293 VCMPacket packet; 324 VCMPacket packet;
325 packet.frameType = kVideoFrameKey;
294 packet.isFirstPacket = true; 326 packet.isFirstPacket = true;
295 packet.markerBit = true; 327 packet.markerBit = true;
296 packet.seqNum = Rand(); 328 packet.seqNum = Rand();
297 EXPECT_TRUE(packet_buffer_.InsertPacket(packet)); 329 EXPECT_TRUE(packet_buffer_.InsertPacket(packet));
298 ASSERT_EQ(1UL, frames_from_callback_.size()); 330 ASSERT_EQ(1UL, frames_from_callback_.size());
299 331
300 packet_buffer_.Flush(); 332 packet_buffer_.Flush();
301 EXPECT_FALSE(frames_from_callback_[0]->GetBitstream(nullptr)); 333 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
334 }
335
336 TEST_F(TestPacketBuffer, Vp8NoPictureId) {
337 uint16_t seq_num = Rand();
338
339 // seq_num , keyf , first, last
340 InsertVp8(seq_num , true , true , false);
341 InsertVp8(seq_num + 1 , false, false, false);
342 InsertVp8(seq_num + 2 , false, false, true);
343 ASSERT_EQ(1UL, frames_from_callback_.size());
344
345 InsertVp8(seq_num + 3 , false, true , false);
346 InsertVp8(seq_num + 4 , false, false, true);
347 ASSERT_EQ(2UL, frames_from_callback_.size());
348
349 InsertVp8(seq_num + 5 , false, true , false);
350 InsertVp8(seq_num + 6 , false, false, false);
351 InsertVp8(seq_num + 7 , false, false, false);
352 InsertVp8(seq_num + 8 , false, false, true);
353 ASSERT_EQ(3UL, frames_from_callback_.size());
354
355 InsertVp8(seq_num + 9 , false, true , true);
356 ASSERT_EQ(4UL, frames_from_callback_.size());
357
358 InsertVp8(seq_num + 10, false, true , false);
359 InsertVp8(seq_num + 11, false, false, true);
360 ASSERT_EQ(5UL, frames_from_callback_.size());
361
362 InsertVp8(seq_num + 12, true , true , true);
363 ASSERT_EQ(6UL, frames_from_callback_.size());
364
365 InsertVp8(seq_num + 13, false, true , false);
366 InsertVp8(seq_num + 14, false, false, false);
367 InsertVp8(seq_num + 15, false, false, false);
368 InsertVp8(seq_num + 16, false, false, false);
369 InsertVp8(seq_num + 17, false, false, true);
370 ASSERT_EQ(7UL, frames_from_callback_.size());
371
372 InsertVp8(seq_num + 18, false, true , true);
373 ASSERT_EQ(8UL, frames_from_callback_.size());
374
375 InsertVp8(seq_num + 19, false, true , false);
376 InsertVp8(seq_num + 20, false, false, true);
377 ASSERT_EQ(9UL, frames_from_callback_.size());
378
379 InsertVp8(seq_num + 21, false, true , true);
380
381 ASSERT_EQ(10UL, frames_from_callback_.size());
382 CheckReferences(seq_num + 2);
383 CheckReferences(seq_num + 4, seq_num + 2);
384 CheckReferences(seq_num + 8, seq_num + 4);
385 CheckReferences(seq_num + 9, seq_num + 8);
386 CheckReferences(seq_num + 11, seq_num + 9);
387 CheckReferences(seq_num + 12);
388 CheckReferences(seq_num + 17, seq_num + 12);
389 CheckReferences(seq_num + 18, seq_num + 17);
390 CheckReferences(seq_num + 20, seq_num + 18);
391 CheckReferences(seq_num + 21, seq_num + 20);
392 }
393
394 TEST_F(TestPacketBuffer, Vp8NoPictureIdReordered) {
395 uint16_t seq_num = 0xfffa;
396
397 // seq_num , keyf , first, last
398 InsertVp8(seq_num + 1 , false, false, false);
399 InsertVp8(seq_num , true , true , false);
400 InsertVp8(seq_num + 2 , false, false, true);
401 InsertVp8(seq_num + 4 , false, false, true);
402 InsertVp8(seq_num + 6 , false, false, false);
403 InsertVp8(seq_num + 3 , false, true , false);
404 InsertVp8(seq_num + 7 , false, false, false);
405 InsertVp8(seq_num + 5 , false, true , false);
406 InsertVp8(seq_num + 9 , false, true , true);
407 InsertVp8(seq_num + 10, false, true , false);
408 InsertVp8(seq_num + 8 , false, false, true);
409 InsertVp8(seq_num + 13, false, true , false);
410 InsertVp8(seq_num + 14, false, false, false);
411 InsertVp8(seq_num + 12, true , true , true);
412 InsertVp8(seq_num + 11, false, false, true);
413 InsertVp8(seq_num + 16, false, false, false);
414 InsertVp8(seq_num + 19, false, true , false);
415 InsertVp8(seq_num + 15, false, false, false);
416 InsertVp8(seq_num + 17, false, false, true);
417 InsertVp8(seq_num + 20, false, false, true);
418 InsertVp8(seq_num + 21, false, true , true);
419 InsertVp8(seq_num + 18, false, true , true);
420
421 ASSERT_EQ(10UL, frames_from_callback_.size());
422 CheckReferences(seq_num + 2);
423 CheckReferences(seq_num + 4, seq_num + 2);
424 CheckReferences(seq_num + 8, seq_num + 4);
425 CheckReferences(seq_num + 9, seq_num + 8);
426 CheckReferences(seq_num + 11, seq_num + 9);
427 CheckReferences(seq_num + 12);
428 CheckReferences(seq_num + 17, seq_num + 12);
429 CheckReferences(seq_num + 18, seq_num + 17);
430 CheckReferences(seq_num + 20, seq_num + 18);
431 CheckReferences(seq_num + 21, seq_num + 20);
432 }
433
434
435 TEST_F(TestPacketBuffer, Vp8KeyFrameReferences) {
436 uint16_t pid = Rand();
437 // seq_num, keyf, first, last, sync , pid, tid, tl0
438 InsertVp8(Rand() , true, true , true, false, pid, 0 , 0);
439
440 ASSERT_EQ(1UL, frames_from_callback_.size());
441 CheckReferences(pid % PacketBuffer::kPicIdLength);
442 }
443
444 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0) {
445 uint16_t pid = Rand();
446 uint16_t seq_num = Rand();
447
448 // seq_num , keyf , first, last, sync , pid , tid, tl0
449 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
450 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
451 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
452 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
453
454 ASSERT_EQ(4UL, frames_from_callback_.size());
455 pid = pid % PacketBuffer::kPicIdLength;
456 CheckReferences(pid);
457 CheckReferences(pid + 1, pid);
458 CheckReferences(pid + 2, pid + 1);
459 CheckReferences(pid + 3, pid + 2);
460 }
461
462 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0) {
463 uint16_t pid = Rand();
464 uint16_t seq_num = Rand();
465
466 // seq_num , keyf , first, last, sync , pid , tid, tl0
467 InsertVp8(seq_num , true , true , true, false, pid , 0 , 1);
468 InsertVp8(seq_num + 1, false, true , true, false, pid + 1, 0 , 2);
469 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 0 , 4);
470 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 3);
471 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 0 , 6);
472 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 7);
473 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 5);
474
475 ASSERT_EQ(7UL, frames_from_callback_.size());
476 pid = pid % PacketBuffer::kPicIdLength;
477 CheckReferences(pid);
478 CheckReferences(pid + 1, pid);
479 CheckReferences(pid + 2, pid + 1);
480 CheckReferences(pid + 3, pid + 2);
481 CheckReferences(pid + 4, pid + 3);
482 CheckReferences(pid + 5, pid + 4);
483 CheckReferences(pid + 6, pid + 5);
484 }
485
486 TEST_F(TestPacketBuffer, Vp8TemporalLayers_01) {
487 uint16_t pid = Rand();
488 uint16_t seq_num = Rand();
489
490 // seq_num , keyf , first, last, sync , pid , tid, tl0
491 InsertVp8(seq_num , true , true , true, false, pid , 0, 255);
492 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1, 255);
493 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0, 0);
494 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1, 0);
495
496 ASSERT_EQ(4UL, frames_from_callback_.size());
497 pid = pid % PacketBuffer::kPicIdLength;
498 CheckReferences(pid);
499 CheckReferences(pid + 1, pid);
500 CheckReferences(pid + 2, pid);
501 CheckReferences(pid + 3, pid + 1, pid + 2);
502 }
503
504 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_01) {
505 uint16_t pid = Rand();
506 uint16_t seq_num = Rand();
507
508 // seq_num , keyf , first, last, sync , pid , tid, tl0
509 InsertVp8(seq_num + 1, false, true , true, true , pid + 1, 1 , 255);
510 InsertVp8(seq_num , true , true , true, false, pid , 0 , 255);
511 InsertVp8(seq_num + 3, false, true , true, false, pid + 3, 1 , 0);
512 InsertVp8(seq_num + 5, false, true , true, false, pid + 5, 1 , 1);
513 InsertVp8(seq_num + 2, false, true , true, false, pid + 2, 0 , 0);
514 InsertVp8(seq_num + 4, false, true , true, false, pid + 4, 0 , 1);
515 InsertVp8(seq_num + 6, false, true , true, false, pid + 6, 0 , 2);
516 InsertVp8(seq_num + 7, false, true , true, false, pid + 7, 1 , 2);
517
518 ASSERT_EQ(8UL, frames_from_callback_.size());
519 pid = pid % PacketBuffer::kPicIdLength;
520 CheckReferences(pid);
521 CheckReferences(pid + 1, pid);
522 CheckReferences(pid + 2, pid);
523 CheckReferences(pid + 3, pid + 1, pid + 2);
524 CheckReferences(pid + 4, pid + 2);
525 CheckReferences(pid + 5, pid + 3, pid + 4);
526 CheckReferences(pid + 6, pid + 4);
527 CheckReferences(pid + 7, pid + 5, pid + 6);
528 }
529
530 TEST_F(TestPacketBuffer, Vp8TemporalLayers_0212) {
pbos-webrtc 2016/04/01 14:24:45 Can you put some comments on what these are doing
philipel 2016/04/05 12:40:50 Done.
531 uint16_t pid = Rand();
532 uint16_t seq_num = Rand();
533
534 // seq_num , keyf , first, last, sync , pid , tid, tl0
535 InsertVp8(seq_num , true , true , true , false, pid , 0 , 55);
536 InsertVp8(seq_num + 1 , false, true , true , true , pid + 1 , 2 , 55);
537 InsertVp8(seq_num + 2 , false, true , true , true , pid + 2 , 1 , 55);
538 InsertVp8(seq_num + 3 , false, true , true , false, pid + 3 , 2 , 55);
539 InsertVp8(seq_num + 4 , false, true , true , false, pid + 4 , 0 , 56);
540 InsertVp8(seq_num + 5 , false, true , true , false, pid + 5 , 2 , 56);
541 InsertVp8(seq_num + 6 , false, true , true , false, pid + 6 , 1 , 56);
542 InsertVp8(seq_num + 7 , false, true , true , false, pid + 7 , 2 , 56);
543 InsertVp8(seq_num + 8 , false, true , true , false, pid + 8 , 0 , 57);
544 InsertVp8(seq_num + 9 , false, true , true , true , pid + 9 , 2 , 57);
545 InsertVp8(seq_num + 10, false, true , true , true , pid + 10, 1 , 57);
546 InsertVp8(seq_num + 11, false, true , true , false, pid + 11, 2 , 57);
547
548 ASSERT_EQ(12UL, frames_from_callback_.size());
549 pid = pid % PacketBuffer::kPicIdLength;
550 CheckReferences(pid);
551 CheckReferences(pid + 1 , pid);
552 CheckReferences(pid + 2 , pid);
553 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
554 CheckReferences(pid + 4 , pid);
555 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
556 CheckReferences(pid + 6 , pid + 2, pid + 4);
557 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
558 CheckReferences(pid + 8 , pid + 4);
559 CheckReferences(pid + 9 , pid + 8);
560 CheckReferences(pid + 10, pid + 8);
561 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
562 }
563
564 TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0212) {
565 uint16_t pid = 126;
566 uint16_t seq_num = Rand();
567
568 // seq_num , keyf , first, last, sync , pid , tid, tl0
569 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 2 , 55);
570 ASSERT_EQ(0UL, frames_from_callback_.size());
571 InsertVp8(seq_num , true , true , true, false, pid , 0 , 55);
572 ASSERT_EQ(2UL, frames_from_callback_.size());
573 InsertVp8(seq_num + 2 , false, true , true, true , pid + 2 , 1 , 55);
574 ASSERT_EQ(3UL, frames_from_callback_.size());
575 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 56);
576 InsertVp8(seq_num + 5 , false, true , true, false, pid + 5 , 2 , 56);
577 ASSERT_EQ(4UL, frames_from_callback_.size());
578 InsertVp8(seq_num + 3 , false, true , true, false, pid + 3 , 2 , 55);
579 ASSERT_EQ(6UL, frames_from_callback_.size());
580 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 2 , 56);
581 InsertVp8(seq_num + 9 , false, true , true, true , pid + 9 , 2 , 57);
582 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 1 , 56);
583 InsertVp8(seq_num + 8 , false, true , true, false, pid + 8 , 0 , 57);
584 InsertVp8(seq_num + 11, false, true , true, false, pid + 11, 2 , 57);
585 InsertVp8(seq_num + 10, false, true , true, true , pid + 10, 1 , 57);
586
587 ASSERT_EQ(12UL, frames_from_callback_.size());
588 pid = pid % PacketBuffer::kPicIdLength;
589 CheckReferences(pid);
590 CheckReferences(pid + 1 , pid);
591 CheckReferences(pid + 2 , pid);
592 CheckReferences(pid + 3 , pid, pid + 1, pid + 2);
593 CheckReferences(pid + 4 , pid);
594 CheckReferences(pid + 5 , pid + 2, pid + 3, pid + 4);
595 CheckReferences(pid + 6 , pid + 2, pid + 4);
596 CheckReferences(pid + 7 , pid + 4, pid + 5, pid + 6);
597 CheckReferences(pid + 8 , pid + 4);
598 CheckReferences(pid + 9 , pid + 8);
599 CheckReferences(pid + 10, pid + 8);
600 CheckReferences(pid + 11, pid + 8, pid + 9, pid + 10);
601 }
602
603 TEST_F(TestPacketBuffer, Vp8LayerSync) {
604 uint16_t pid = Rand();
605 uint16_t seq_num = Rand();
606
607 // seq_num , keyf , first, last, sync , pid , tid, tl0
608 InsertVp8(seq_num , true , true , true, false, pid , 0 , 0);
609 InsertVp8(seq_num + 1 , false, true , true, true , pid + 1 , 1 , 0);
610 InsertVp8(seq_num + 2 , false, true , true, false, pid + 2 , 0 , 1);
611 ASSERT_EQ(3UL, frames_from_callback_.size());
612
613 InsertVp8(seq_num + 4 , false, true , true, false, pid + 4 , 0 , 2);
614 InsertVp8(seq_num + 5 , false, true , true, true , pid + 5 , 1 , 2);
615 InsertVp8(seq_num + 6 , false, true , true, false, pid + 6 , 0 , 3);
616 InsertVp8(seq_num + 7 , false, true , true, false, pid + 7 , 1 , 3);
617
618 ASSERT_EQ(7UL, frames_from_callback_.size());
619 pid = pid % PacketBuffer::kPicIdLength;
620 CheckReferences(pid);
621 CheckReferences(pid + 1, pid);
622 CheckReferences(pid + 2, pid);
623 CheckReferences(pid + 4, pid + 2);
624 CheckReferences(pid + 5, pid + 4);
625 CheckReferences(pid + 6, pid + 4);
626 CheckReferences(pid + 7, pid + 6, pid + 5);
302 } 627 }
303 628
304 } // namespace video_coding 629 } // namespace video_coding
305 } // namespace webrtc 630 } // namespace webrtc
OLDNEW
« webrtc/modules/video_coding/packet_buffer.cc ('K') | « 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