blob: b7921e5c6daa9b943fa4ab6f74f958ee2e0a131f [file] [log] [blame]
philipelc707ab72016-04-01 02:01:54 -07001/*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <cstring>
12#include <limits>
kwiberg84be5112016-04-27 01:19:58 -070013#include <memory>
philipela1059872016-05-09 11:41:48 +020014#include <utility>
philipelc707ab72016-04-01 02:01:54 -070015
16#include "webrtc/modules/video_coding/frame_object.h"
17#include "webrtc/modules/video_coding/packet_buffer.h"
18
19#include "testing/gtest/include/gtest/gtest.h"
20#include "webrtc/base/random.h"
21
22namespace webrtc {
23namespace video_coding {
24
25class TestPacketBuffer : public ::testing::Test,
26 public OnCompleteFrameCallback {
27 protected:
28 TestPacketBuffer()
philipelf4139332016-04-20 10:26:34 +020029 : rand_(0x8739211),
philipela1059872016-05-09 11:41:48 +020030 packet_buffer_(new PacketBuffer(kStartSize, kMaxSize, this)),
31 frames_from_callback_(FrameComp()) {}
philipelc707ab72016-04-01 02:01:54 -070032
33 uint16_t Rand() { return rand_.Rand(std::numeric_limits<uint16_t>::max()); }
34
35 void OnCompleteFrame(std::unique_ptr<FrameObject> frame) override {
philipelf4139332016-04-20 10:26:34 +020036 uint16_t pid = frame->picture_id;
philipela1059872016-05-09 11:41:48 +020037 uint16_t sidx = frame->spatial_layer;
38 auto frame_it = frames_from_callback_.find(std::make_pair(pid, sidx));
philipelf4139332016-04-20 10:26:34 +020039 if (frame_it != frames_from_callback_.end()) {
philipela1059872016-05-09 11:41:48 +020040 ADD_FAILURE() << "Already received frame with (pid:sidx): ("
41 << pid << ":" << sidx << ")";
philipelf4139332016-04-20 10:26:34 +020042 return;
43 }
44
45 frames_from_callback_.insert(
philipela1059872016-05-09 11:41:48 +020046 std::make_pair(std::make_pair(pid, sidx), std::move(frame)));
philipelc707ab72016-04-01 02:01:54 -070047 }
48
49 void TearDown() override {
philipelf4139332016-04-20 10:26:34 +020050 // All frame objects must be destroyed before the packet buffer since
51 // a frame object will try to remove itself from the packet buffer
philipelc707ab72016-04-01 02:01:54 -070052 // upon destruction.
53 frames_from_callback_.clear();
54 }
55
philipela1059872016-05-09 11:41:48 +020056 // Short version of true and false.
57 enum {
58 kT = true,
59 kF = false
60 };
61
philipelf4139332016-04-20 10:26:34 +020062 // Insert a generic packet into the packet buffer.
63 void InsertGeneric(uint16_t seq_num, // packet sequence number
64 bool keyframe, // is keyframe
65 bool first, // is first packet of frame
66 bool last, // is last packet of frame
67 size_t data_size = 0, // size of data
68 uint8_t* data = nullptr) { // data pointer
69 VCMPacket packet;
70 packet.codec = kVideoCodecGeneric;
71 packet.seqNum = seq_num;
72 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
73 packet.isFirstPacket = first;
74 packet.markerBit = last;
75 packet.sizeBytes = data_size;
76 packet.dataPtr = data;
77
78 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
79 }
80
81 // Insert a Vp8 packet into the packet buffer.
82 void InsertVp8(uint16_t seq_num, // packet sequence number
83 bool keyframe, // is keyframe
84 bool first, // is first packet of frame
85 bool last, // is last packet of frame
86 bool sync = false, // is sync frame
87 int32_t pid = kNoPictureId, // picture id
88 uint8_t tid = kNoTemporalIdx, // temporal id
89 int32_t tl0 = kNoTl0PicIdx, // tl0 pic index
90 size_t data_size = 0, // size of data
91 uint8_t* data = nullptr) { // data pointer
92 VCMPacket packet;
93 packet.codec = kVideoCodecVP8;
94 packet.seqNum = seq_num;
95 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
96 packet.isFirstPacket = first;
97 packet.markerBit = last;
98 packet.sizeBytes = data_size;
99 packet.dataPtr = data;
100 packet.codecSpecificHeader.codecHeader.VP8.pictureId = pid % (1 << 15);
101 packet.codecSpecificHeader.codecHeader.VP8.temporalIdx = tid;
102 packet.codecSpecificHeader.codecHeader.VP8.tl0PicIdx = tl0;
103 packet.codecSpecificHeader.codecHeader.VP8.layerSync = sync;
104
105 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
106 }
107
philipela1059872016-05-09 11:41:48 +0200108 // Insert a Vp9 packet into the packet buffer.
109 void InsertVp9Gof(uint16_t seq_num, // packet sequence number
110 bool keyframe, // is keyframe
111 bool first, // is first packet of frame
112 bool last, // is last packet of frame
113 bool up = false, // frame is up-switch point
114 int32_t pid = kNoPictureId, // picture id
115 uint8_t sid = kNoSpatialIdx, // spatial id
116 uint8_t tid = kNoTemporalIdx, // temporal id
117 int32_t tl0 = kNoTl0PicIdx, // tl0 pic index
118 GofInfoVP9* ss = nullptr, // scalability structure
119 size_t data_size = 0, // size of data
120 uint8_t* data = nullptr) { // data pointer
121 VCMPacket packet;
122 packet.codec = kVideoCodecVP9;
123 packet.seqNum = seq_num;
124 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
125 packet.isFirstPacket = first;
126 packet.markerBit = last;
127 packet.sizeBytes = data_size;
128 packet.dataPtr = data;
129 packet.codecSpecificHeader.codecHeader.VP9.flexible_mode = false;
130 packet.codecSpecificHeader.codecHeader.VP9.picture_id = pid % (1 << 15);
131 packet.codecSpecificHeader.codecHeader.VP9.temporal_idx = tid;
132 packet.codecSpecificHeader.codecHeader.VP9.spatial_idx = sid;
133 packet.codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = tl0;
134 packet.codecSpecificHeader.codecHeader.VP9.temporal_up_switch = up;
135 if (ss != nullptr) {
136 packet.codecSpecificHeader.codecHeader.VP9.ss_data_available = true;
137 packet.codecSpecificHeader.codecHeader.VP9.gof = *ss;
138 }
139
140 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
141 }
142
143 // Insert a Vp9 packet into the packet buffer.
144 void InsertVp9Flex(uint16_t seq_num, // packet sequence number
145 bool keyframe, // is keyframe
146 bool first, // is first packet of frame
147 bool last, // is last packet of frame
148 bool inter, // depends on S-1 layer
149 int32_t pid = kNoPictureId, // picture id
150 uint8_t sid = kNoSpatialIdx, // spatial id
151 uint8_t tid = kNoTemporalIdx, // temporal id
152 int32_t tl0 = kNoTl0PicIdx, // tl0 pic index
153 std::vector<uint8_t> refs =
154 std::vector<uint8_t>(), // frame references
155 size_t data_size = 0, // size of data
156 uint8_t* data = nullptr) { // data pointer
157 VCMPacket packet;
158 packet.codec = kVideoCodecVP9;
159 packet.seqNum = seq_num;
160 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
161 packet.isFirstPacket = first;
162 packet.markerBit = last;
163 packet.sizeBytes = data_size;
164 packet.dataPtr = data;
165 packet.codecSpecificHeader.codecHeader.VP9.inter_layer_predicted = inter;
166 packet.codecSpecificHeader.codecHeader.VP9.flexible_mode = true;
167 packet.codecSpecificHeader.codecHeader.VP9.picture_id = pid % (1 << 15);
168 packet.codecSpecificHeader.codecHeader.VP9.temporal_idx = tid;
169 packet.codecSpecificHeader.codecHeader.VP9.spatial_idx = sid;
170 packet.codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = tl0;
171 packet.codecSpecificHeader.codecHeader.VP9.num_ref_pics = refs.size();
172 for (size_t i = 0; i < refs.size(); ++i)
173 packet.codecSpecificHeader.codecHeader.VP9.pid_diff[i] = refs[i];
174
175 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
176 }
177
178 // Check if a frame with picture id |pid| and spatial index |sidx| has been
179 // delivered from the packet buffer, and if so, if it has the references
180 // specified by |refs|.
philipelf4139332016-04-20 10:26:34 +0200181 template <typename... T>
philipela1059872016-05-09 11:41:48 +0200182 void CheckReferences(uint16_t pid, uint16_t sidx, T... refs) const {
183 auto frame_it = frames_from_callback_.find(std::make_pair(pid, sidx));
philipelf4139332016-04-20 10:26:34 +0200184 if (frame_it == frames_from_callback_.end()) {
philipela1059872016-05-09 11:41:48 +0200185 ADD_FAILURE() << "Could not find frame with (pid:sidx): ("
186 << pid << ":" << sidx << ")";
philipelf4139332016-04-20 10:26:34 +0200187 return;
188 }
189
190 std::set<uint16_t> actual_refs;
191 for (uint8_t r = 0; r < frame_it->second->num_references; ++r) {
192 actual_refs.insert(frame_it->second->references[r]);
193 }
194
195 std::set<uint16_t> expected_refs;
196 RefsToSet(&expected_refs, refs...);
197
198 ASSERT_EQ(expected_refs, actual_refs);
199 }
200
201 template <typename... T>
philipela1059872016-05-09 11:41:48 +0200202 void CheckReferencesGeneric(uint16_t pid, T... refs) const {
203 CheckReferences(pid, 0, refs...);
204 }
205
206 template <typename... T>
207 void CheckReferencesVp8(uint16_t pid, T... refs) const {
208 CheckReferences(pid, 0, refs...);
209 }
210
211 template <typename... T>
212 void CheckReferencesVp9(uint16_t pid, uint8_t sidx, T... refs) const {
213 CheckReferences(pid, sidx, refs...);
214 }
215
216 template <typename... T>
philipelf4139332016-04-20 10:26:34 +0200217 void RefsToSet(std::set<uint16_t>* m, uint16_t ref, T... refs) const {
218 m->insert(ref);
219 RefsToSet(m, refs...);
220 }
221
222 void RefsToSet(std::set<uint16_t>* m) const {}
223
philipelc707ab72016-04-01 02:01:54 -0700224 const int kStartSize = 16;
225 const int kMaxSize = 64;
226
227 Random rand_;
philipelf4139332016-04-20 10:26:34 +0200228 std::unique_ptr<PacketBuffer> packet_buffer_;
philipela1059872016-05-09 11:41:48 +0200229 struct FrameComp {
230 bool operator()(const std::pair<uint16_t, uint8_t> f1,
231 const std::pair<uint16_t, uint8_t> f2) const {
232 if (f1.first == f2.first)
233 return f1.second < f2.second;
234 return f1.first < f2.first;
235 }
236 };
237 std::map<std::pair<uint16_t, uint8_t>,
238 std::unique_ptr<FrameObject>,
239 FrameComp> frames_from_callback_;
philipelc707ab72016-04-01 02:01:54 -0700240};
241
242TEST_F(TestPacketBuffer, InsertOnePacket) {
243 VCMPacket packet;
244 packet.seqNum = Rand();
philipelf4139332016-04-20 10:26:34 +0200245 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700246}
247
248TEST_F(TestPacketBuffer, InsertMultiplePackets) {
249 VCMPacket packet;
250 packet.seqNum = Rand();
philipelf4139332016-04-20 10:26:34 +0200251 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700252 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200253 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700254 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200255 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700256}
257
258TEST_F(TestPacketBuffer, InsertDuplicatePacket) {
259 VCMPacket packet;
260 packet.seqNum = Rand();
philipelf4139332016-04-20 10:26:34 +0200261 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700262 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200263 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
264 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700265}
266
267TEST_F(TestPacketBuffer, ExpandBuffer) {
philipelf4139332016-04-20 10:26:34 +0200268 uint16_t seq_num = Rand();
philipelc707ab72016-04-01 02:01:54 -0700269
270 for (int i = 0; i < kStartSize + 1; ++i) {
philipela1059872016-05-09 11:41:48 +0200271 // seq_num , kf, frst, lst
272 InsertGeneric(seq_num + i, kT , kT, kT);
philipelc707ab72016-04-01 02:01:54 -0700273 }
274}
275
276TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
philipelf4139332016-04-20 10:26:34 +0200277 uint16_t seq_num = Rand();
philipelc707ab72016-04-01 02:01:54 -0700278
279 for (int i = 0; i < kMaxSize; ++i) {
philipela1059872016-05-09 11:41:48 +0200280 // seq_num , kf, frst, lst
281 InsertGeneric(seq_num + i, kT, kT , kT);
philipelc707ab72016-04-01 02:01:54 -0700282 }
283
philipelf4139332016-04-20 10:26:34 +0200284 VCMPacket packet;
285 packet.seqNum = seq_num + kMaxSize + 1;
286 packet.sizeBytes = 1;
287 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700288}
289
philipelf4139332016-04-20 10:26:34 +0200290TEST_F(TestPacketBuffer, GenericOnePacketOneFrame) {
philipela1059872016-05-09 11:41:48 +0200291 // seq_num, kf, frst, lst
292 InsertGeneric(Rand() , kT, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200293 ASSERT_EQ(1UL, frames_from_callback_.size());
philipelc707ab72016-04-01 02:01:54 -0700294}
295
philipelf4139332016-04-20 10:26:34 +0200296TEST_F(TestPacketBuffer, GenericTwoPacketsTwoFrames) {
297 uint16_t seq_num = Rand();
298
philipela1059872016-05-09 11:41:48 +0200299 // seq_num , kf, frst, lst
300 InsertGeneric(seq_num , kT, kT , kT);
301 InsertGeneric(seq_num + 1, kT, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200302
philipelc707ab72016-04-01 02:01:54 -0700303 EXPECT_EQ(2UL, frames_from_callback_.size());
304}
305
philipelf4139332016-04-20 10:26:34 +0200306TEST_F(TestPacketBuffer, GenericTwoPacketsOneFrames) {
307 uint16_t seq_num = Rand();
308
philipela1059872016-05-09 11:41:48 +0200309 // seq_num , kf, frst, lst
310 InsertGeneric(seq_num , kT, kT , kF);
311 InsertGeneric(seq_num + 1, kT, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200312
philipelc707ab72016-04-01 02:01:54 -0700313 EXPECT_EQ(1UL, frames_from_callback_.size());
314}
315
philipelf4139332016-04-20 10:26:34 +0200316TEST_F(TestPacketBuffer, GenericThreePacketReorderingOneFrame) {
317 uint16_t seq_num = Rand();
philipelc707ab72016-04-01 02:01:54 -0700318
philipela1059872016-05-09 11:41:48 +0200319 // seq_num , kf, frst, lst
320 InsertGeneric(seq_num , kT, kT , kF);
321 InsertGeneric(seq_num + 2, kT, kF , kT);
322 InsertGeneric(seq_num + 1, kT, kF , kF);
philipelf4139332016-04-20 10:26:34 +0200323
philipelc707ab72016-04-01 02:01:54 -0700324 EXPECT_EQ(1UL, frames_from_callback_.size());
325}
326
327TEST_F(TestPacketBuffer, DiscardOldPacket) {
328 uint16_t seq_num = Rand();
329 VCMPacket packet;
330 packet.seqNum = Rand();
philipelf4139332016-04-20 10:26:34 +0200331 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700332 packet.seqNum += 2;
philipelf4139332016-04-20 10:26:34 +0200333 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700334
335 for (int i = 3; i < kMaxSize; ++i) {
336 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200337 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700338 }
339
340 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200341 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
342 packet_buffer_->ClearTo(seq_num + 1);
343 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700344}
345
346TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) {
347 uint16_t seq_num = Rand();
348 VCMPacket packet;
349 packet.seqNum = seq_num;
philipelf4139332016-04-20 10:26:34 +0200350 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700351 packet.seqNum += 2;
philipelf4139332016-04-20 10:26:34 +0200352 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700353
354 for (int i = 3; i < kMaxSize; ++i) {
355 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200356 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700357 }
358
philipelf4139332016-04-20 10:26:34 +0200359 packet_buffer_->ClearTo(seq_num + 15);
philipelc707ab72016-04-01 02:01:54 -0700360 for (int i = 0; i < 15; ++i) {
361 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200362 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700363 }
364 for (int i = 15; i < kMaxSize; ++i) {
365 ++packet.seqNum;
philipelf4139332016-04-20 10:26:34 +0200366 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700367 }
368}
369
philipelf4139332016-04-20 10:26:34 +0200370TEST_F(TestPacketBuffer, GenericFrames) {
371 uint16_t seq_num = Rand();
372
373 // seq_num , keyf , first, last
374 InsertGeneric(seq_num , true , true , true);
375 InsertGeneric(seq_num + 1, false, true , true);
376 InsertGeneric(seq_num + 2, false, true , true);
377 InsertGeneric(seq_num + 3, false, true , true);
378
379 ASSERT_EQ(4UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200380 CheckReferencesGeneric(seq_num);
381 CheckReferencesGeneric(seq_num + 1, seq_num);
382 CheckReferencesGeneric(seq_num + 2, seq_num + 1);
383 CheckReferencesGeneric(seq_num + 3, seq_num + 2);
philipelf4139332016-04-20 10:26:34 +0200384}
385
386TEST_F(TestPacketBuffer, GenericFramesReordered) {
387 uint16_t seq_num = Rand();
388
389 // seq_num , keyf , first, last
390 InsertGeneric(seq_num + 1, false, true , true);
391 InsertGeneric(seq_num , true , true , true);
392 InsertGeneric(seq_num + 3, false, true , true);
393 InsertGeneric(seq_num + 2, false, true , true);
394
395 ASSERT_EQ(4UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200396 CheckReferencesGeneric(seq_num);
397 CheckReferencesGeneric(seq_num + 1, seq_num);
398 CheckReferencesGeneric(seq_num + 2, seq_num + 1);
399 CheckReferencesGeneric(seq_num + 3, seq_num + 2);
philipelf4139332016-04-20 10:26:34 +0200400}
401
philipelc707ab72016-04-01 02:01:54 -0700402TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
403 // "many bitstream, such data" with null termination.
404 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
405 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
406 0x65, 0x61, 0x6d, 0x2c, 0x20};
407 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
408 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
409 uint8_t
410 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
411
philipelf4139332016-04-20 10:26:34 +0200412 uint16_t seq_num = Rand();
philipelc707ab72016-04-01 02:01:54 -0700413
philipela1059872016-05-09 11:41:48 +0200414 // seq_num , kf, frst, lst, data_size , data
415 InsertGeneric(seq_num , kT, kT , kF , sizeof(many) , many);
416 InsertGeneric(seq_num + 1, kF, kF , kF , sizeof(bitstream), bitstream);
417 InsertGeneric(seq_num + 2, kF, kF , kF , sizeof(such) , such);
418 InsertGeneric(seq_num + 3, kF, kF , kT , sizeof(data) , data);
philipelf4139332016-04-20 10:26:34 +0200419
420 ASSERT_EQ(1UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200421 CheckReferencesVp8(seq_num + 3);
422 EXPECT_TRUE(frames_from_callback_[std::make_pair(seq_num + 3, 0)]->
423 GetBitstream(result));
philipelf4139332016-04-20 10:26:34 +0200424 EXPECT_EQ(std::strcmp("many bitstream, such data",
425 reinterpret_cast<char*>(result)),
426 0);
philipelc707ab72016-04-01 02:01:54 -0700427}
428
429TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
philipelf4139332016-04-20 10:26:34 +0200430 uint16_t seq_num = Rand();
431
philipela1059872016-05-09 11:41:48 +0200432 // seq_num , kf, frst, lst
433 InsertGeneric(seq_num , kT, kT , kF);
434 InsertGeneric(seq_num + 1, kF, kF , kF);
435 InsertGeneric(seq_num + 2, kF, kF , kT);
philipelc707ab72016-04-01 02:01:54 -0700436 EXPECT_EQ(1UL, frames_from_callback_.size());
437
438 frames_from_callback_.clear();
439
philipela1059872016-05-09 11:41:48 +0200440 // seq_num , kf, frst, lst
441 InsertGeneric(seq_num , kT, kT , kF);
442 InsertGeneric(seq_num + 1, kF, kF , kF);
443 InsertGeneric(seq_num + 2, kF, kF , kT);
philipelc707ab72016-04-01 02:01:54 -0700444 EXPECT_EQ(1UL, frames_from_callback_.size());
445}
446
447TEST_F(TestPacketBuffer, Flush) {
philipelf4139332016-04-20 10:26:34 +0200448 uint16_t seq_num = Rand();
449
philipela1059872016-05-09 11:41:48 +0200450 // seq_num , kf, frst, lst
451 InsertGeneric(seq_num , kT, kT , kF);
452 InsertGeneric(seq_num + 1, kF, kF , kF);
453 InsertGeneric(seq_num + 2, kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200454 EXPECT_EQ(1UL, frames_from_callback_.size());
455
456 packet_buffer_->Flush();
457
philipela1059872016-05-09 11:41:48 +0200458 // seq_num , kf, frst, lst
459 InsertGeneric(seq_num + kStartSize , kT, kT , kF);
460 InsertGeneric(seq_num + kStartSize + 1, kF, kF , kF);
461 InsertGeneric(seq_num + kStartSize + 2, kF, kF , kT);
philipelc707ab72016-04-01 02:01:54 -0700462 EXPECT_EQ(2UL, frames_from_callback_.size());
463}
464
465TEST_F(TestPacketBuffer, InvalidateFrameByFlushing) {
466 VCMPacket packet;
philipelf4139332016-04-20 10:26:34 +0200467 packet.codec = kVideoCodecGeneric;
468 packet.frameType = kVideoFrameKey;
philipela1059872016-05-09 11:41:48 +0200469 packet.isFirstPacket = kT;
470 packet.markerBit = kT;
philipelc707ab72016-04-01 02:01:54 -0700471 packet.seqNum = Rand();
philipelf4139332016-04-20 10:26:34 +0200472 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
philipelc707ab72016-04-01 02:01:54 -0700473 ASSERT_EQ(1UL, frames_from_callback_.size());
474
philipelf4139332016-04-20 10:26:34 +0200475 packet_buffer_->Flush();
476 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
477}
478
479TEST_F(TestPacketBuffer, Vp8NoPictureId) {
480 uint16_t seq_num = Rand();
481
philipela1059872016-05-09 11:41:48 +0200482 // seq_num , kf, frst, lst
483 InsertVp8(seq_num , kT, kT , kF);
484 InsertVp8(seq_num + 1 , kF, kF , kF);
485 InsertVp8(seq_num + 2 , kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200486 ASSERT_EQ(1UL, frames_from_callback_.size());
487
philipela1059872016-05-09 11:41:48 +0200488 InsertVp8(seq_num + 3 , kF, kT , kF);
489 InsertVp8(seq_num + 4 , kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200490 ASSERT_EQ(2UL, frames_from_callback_.size());
491
philipela1059872016-05-09 11:41:48 +0200492 InsertVp8(seq_num + 5 , kF, kT , kF);
493 InsertVp8(seq_num + 6 , kF, kF , kF);
494 InsertVp8(seq_num + 7 , kF, kF , kF);
495 InsertVp8(seq_num + 8 , kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200496 ASSERT_EQ(3UL, frames_from_callback_.size());
497
philipela1059872016-05-09 11:41:48 +0200498 InsertVp8(seq_num + 9 , kF, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200499 ASSERT_EQ(4UL, frames_from_callback_.size());
500
philipela1059872016-05-09 11:41:48 +0200501 InsertVp8(seq_num + 10, kF, kT , kF);
502 InsertVp8(seq_num + 11, kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200503 ASSERT_EQ(5UL, frames_from_callback_.size());
504
philipela1059872016-05-09 11:41:48 +0200505 InsertVp8(seq_num + 12, kT, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200506 ASSERT_EQ(6UL, frames_from_callback_.size());
507
philipela1059872016-05-09 11:41:48 +0200508 InsertVp8(seq_num + 13, kF, kT , kF);
509 InsertVp8(seq_num + 14, kF, kF , kF);
510 InsertVp8(seq_num + 15, kF, kF , kF);
511 InsertVp8(seq_num + 16, kF, kF , kF);
512 InsertVp8(seq_num + 17, kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200513 ASSERT_EQ(7UL, frames_from_callback_.size());
514
philipela1059872016-05-09 11:41:48 +0200515 InsertVp8(seq_num + 18, kF, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200516 ASSERT_EQ(8UL, frames_from_callback_.size());
517
philipela1059872016-05-09 11:41:48 +0200518 InsertVp8(seq_num + 19, kF, kT , kF);
519 InsertVp8(seq_num + 20, kF, kF , kT);
philipelf4139332016-04-20 10:26:34 +0200520 ASSERT_EQ(9UL, frames_from_callback_.size());
521
philipela1059872016-05-09 11:41:48 +0200522 InsertVp8(seq_num + 21, kF, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200523
524 ASSERT_EQ(10UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200525 CheckReferencesVp8(seq_num + 2);
526 CheckReferencesVp8(seq_num + 4, seq_num + 2);
527 CheckReferencesVp8(seq_num + 8, seq_num + 4);
528 CheckReferencesVp8(seq_num + 9, seq_num + 8);
529 CheckReferencesVp8(seq_num + 11, seq_num + 9);
530 CheckReferencesVp8(seq_num + 12);
531 CheckReferencesVp8(seq_num + 17, seq_num + 12);
532 CheckReferencesVp8(seq_num + 18, seq_num + 17);
533 CheckReferencesVp8(seq_num + 20, seq_num + 18);
534 CheckReferencesVp8(seq_num + 21, seq_num + 20);
philipelf4139332016-04-20 10:26:34 +0200535}
536
537TEST_F(TestPacketBuffer, Vp8NoPictureIdReordered) {
538 uint16_t seq_num = 0xfffa;
539
philipela1059872016-05-09 11:41:48 +0200540 // seq_num , kf, frst, lst
541 InsertVp8(seq_num + 1 , kF, kF , kF);
542 InsertVp8(seq_num , kT, kT , kF);
543 InsertVp8(seq_num + 2 , kF, kF , kT);
544 InsertVp8(seq_num + 4 , kF, kF , kT);
545 InsertVp8(seq_num + 6 , kF, kF , kF);
546 InsertVp8(seq_num + 3 , kF, kT , kF);
547 InsertVp8(seq_num + 7 , kF, kF , kF);
548 InsertVp8(seq_num + 5 , kF, kT , kF);
549 InsertVp8(seq_num + 9 , kF, kT , kT);
550 InsertVp8(seq_num + 10, kF, kT , kF);
551 InsertVp8(seq_num + 8 , kF, kF , kT);
552 InsertVp8(seq_num + 13, kF, kT , kF);
553 InsertVp8(seq_num + 14, kF, kF , kF);
554 InsertVp8(seq_num + 12, kT, kT , kT);
555 InsertVp8(seq_num + 11, kF, kF , kT);
556 InsertVp8(seq_num + 16, kF, kF , kF);
557 InsertVp8(seq_num + 19, kF, kT , kF);
558 InsertVp8(seq_num + 15, kF, kF , kF);
559 InsertVp8(seq_num + 17, kF, kF , kT);
560 InsertVp8(seq_num + 20, kF, kF , kT);
561 InsertVp8(seq_num + 21, kF, kT , kT);
562 InsertVp8(seq_num + 18, kF, kT , kT);
philipelf4139332016-04-20 10:26:34 +0200563
564 ASSERT_EQ(10UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200565 CheckReferencesVp8(seq_num + 2);
566 CheckReferencesVp8(seq_num + 4, seq_num + 2);
567 CheckReferencesVp8(seq_num + 8, seq_num + 4);
568 CheckReferencesVp8(seq_num + 9, seq_num + 8);
569 CheckReferencesVp8(seq_num + 11, seq_num + 9);
570 CheckReferencesVp8(seq_num + 12);
571 CheckReferencesVp8(seq_num + 17, seq_num + 12);
572 CheckReferencesVp8(seq_num + 18, seq_num + 17);
573 CheckReferencesVp8(seq_num + 20, seq_num + 18);
574 CheckReferencesVp8(seq_num + 21, seq_num + 20);
philipelf4139332016-04-20 10:26:34 +0200575}
576
577
578TEST_F(TestPacketBuffer, Vp8KeyFrameReferences) {
579 uint16_t pid = Rand();
philipela1059872016-05-09 11:41:48 +0200580 // seq_num, kf, frst, lst, sync, pid, tid, tl0
581 InsertVp8(Rand() , kT, kT , kT , kF , pid, 0 , 0);
philipelf4139332016-04-20 10:26:34 +0200582
583 ASSERT_EQ(1UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200584 CheckReferencesVp8(pid);
philipelf4139332016-04-20 10:26:34 +0200585}
586
587// Test with 1 temporal layer.
588TEST_F(TestPacketBuffer, Vp8TemporalLayers_0) {
589 uint16_t pid = Rand();
590 uint16_t seq_num = Rand();
591
philipela1059872016-05-09 11:41:48 +0200592 // seq_num , kf, frst, lst, sync, pid , tid, tl0
593 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0 , 1);
594 InsertVp8(seq_num + 1, kF, kT , kT , kF , pid + 1, 0 , 2);
595 InsertVp8(seq_num + 2, kF, kT , kT , kF , pid + 2, 0 , 3);
596 InsertVp8(seq_num + 3, kF, kT , kT , kF , pid + 3, 0 , 4);
philipelf4139332016-04-20 10:26:34 +0200597
598 ASSERT_EQ(4UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200599 CheckReferencesVp8(pid);
600 CheckReferencesVp8(pid + 1, pid);
601 CheckReferencesVp8(pid + 2, pid + 1);
602 CheckReferencesVp8(pid + 3, pid + 2);
philipelf4139332016-04-20 10:26:34 +0200603}
604
605// Test with 1 temporal layer.
606TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0) {
607 uint16_t pid = Rand();
608 uint16_t seq_num = Rand();
609
philipela1059872016-05-09 11:41:48 +0200610 // seq_num , kf, frst, lst, sync, pid , tid, tl0
611 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0 , 1);
612 InsertVp8(seq_num + 1, kF, kT , kT , kF , pid + 1, 0 , 2);
613 InsertVp8(seq_num + 3, kF, kT , kT , kF , pid + 3, 0 , 4);
614 InsertVp8(seq_num + 2, kF, kT , kT , kF , pid + 2, 0 , 3);
615 InsertVp8(seq_num + 5, kF, kT , kT , kF , pid + 5, 0 , 6);
616 InsertVp8(seq_num + 6, kF, kT , kT , kF , pid + 6, 0 , 7);
617 InsertVp8(seq_num + 4, kF, kT , kT , kF , pid + 4, 0 , 5);
philipelf4139332016-04-20 10:26:34 +0200618
619 ASSERT_EQ(7UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200620 CheckReferencesVp8(pid);
621 CheckReferencesVp8(pid + 1, pid);
622 CheckReferencesVp8(pid + 2, pid + 1);
623 CheckReferencesVp8(pid + 3, pid + 2);
624 CheckReferencesVp8(pid + 4, pid + 3);
625 CheckReferencesVp8(pid + 5, pid + 4);
626 CheckReferencesVp8(pid + 6, pid + 5);
philipelf4139332016-04-20 10:26:34 +0200627}
628
629// Test with 2 temporal layers in a 01 pattern.
630TEST_F(TestPacketBuffer, Vp8TemporalLayers_01) {
631 uint16_t pid = Rand();
632 uint16_t seq_num = Rand();
633
philipela1059872016-05-09 11:41:48 +0200634 // seq_num , kf, frst, lst, sync, pid , tid, tl0
635 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0, 255);
636 InsertVp8(seq_num + 1, kF, kT , kT , kT , pid + 1, 1, 255);
637 InsertVp8(seq_num + 2, kF, kT , kT , kF , pid + 2, 0, 0);
638 InsertVp8(seq_num + 3, kF, kT , kT , kF , pid + 3, 1, 0);
philipelf4139332016-04-20 10:26:34 +0200639
640 ASSERT_EQ(4UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200641 CheckReferencesVp8(pid);
642 CheckReferencesVp8(pid + 1, pid);
643 CheckReferencesVp8(pid + 2, pid);
644 CheckReferencesVp8(pid + 3, pid + 1, pid + 2);
philipelf4139332016-04-20 10:26:34 +0200645}
646
647// Test with 2 temporal layers in a 01 pattern.
648TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_01) {
649 uint16_t pid = Rand();
650 uint16_t seq_num = Rand();
651
philipela1059872016-05-09 11:41:48 +0200652 // seq_num , kf, frst, lst, sync, pid , tid, tl0
653 InsertVp8(seq_num + 1, kF, kT , kT , kT , pid + 1, 1 , 255);
654 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0 , 255);
655 InsertVp8(seq_num + 3, kF, kT , kT , kF , pid + 3, 1 , 0);
656 InsertVp8(seq_num + 5, kF, kT , kT , kF , pid + 5, 1 , 1);
657 InsertVp8(seq_num + 2, kF, kT , kT , kF , pid + 2, 0 , 0);
658 InsertVp8(seq_num + 4, kF, kT , kT , kF , pid + 4, 0 , 1);
659 InsertVp8(seq_num + 6, kF, kT , kT , kF , pid + 6, 0 , 2);
660 InsertVp8(seq_num + 7, kF, kT , kT , kF , pid + 7, 1 , 2);
philipelf4139332016-04-20 10:26:34 +0200661
662 ASSERT_EQ(8UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200663 CheckReferencesVp8(pid);
664 CheckReferencesVp8(pid + 1, pid);
665 CheckReferencesVp8(pid + 2, pid);
666 CheckReferencesVp8(pid + 3, pid + 1, pid + 2);
667 CheckReferencesVp8(pid + 4, pid + 2);
668 CheckReferencesVp8(pid + 5, pid + 3, pid + 4);
669 CheckReferencesVp8(pid + 6, pid + 4);
670 CheckReferencesVp8(pid + 7, pid + 5, pid + 6);
philipelf4139332016-04-20 10:26:34 +0200671}
672
673// Test with 3 temporal layers in a 0212 pattern.
674TEST_F(TestPacketBuffer, Vp8TemporalLayers_0212) {
675 uint16_t pid = Rand();
676 uint16_t seq_num = Rand();
677
philipela1059872016-05-09 11:41:48 +0200678 // seq_num , kf, frst, lst, sync, pid , tid, tl0
679 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0 , 55);
680 InsertVp8(seq_num + 1 , kF, kT , kT , kT , pid + 1 , 2 , 55);
681 InsertVp8(seq_num + 2 , kF, kT , kT , kT , pid + 2 , 1 , 55);
682 InsertVp8(seq_num + 3 , kF, kT , kT , kF , pid + 3 , 2 , 55);
683 InsertVp8(seq_num + 4 , kF, kT , kT , kF , pid + 4 , 0 , 56);
684 InsertVp8(seq_num + 5 , kF, kT , kT , kF , pid + 5 , 2 , 56);
685 InsertVp8(seq_num + 6 , kF, kT , kT , kF , pid + 6 , 1 , 56);
686 InsertVp8(seq_num + 7 , kF, kT , kT , kF , pid + 7 , 2 , 56);
687 InsertVp8(seq_num + 8 , kF, kT , kT , kF , pid + 8 , 0 , 57);
688 InsertVp8(seq_num + 9 , kF, kT , kT , kT , pid + 9 , 2 , 57);
689 InsertVp8(seq_num + 10, kF, kT , kT , kT , pid + 10, 1 , 57);
690 InsertVp8(seq_num + 11, kF, kT , kT , kF , pid + 11, 2 , 57);
philipelf4139332016-04-20 10:26:34 +0200691
692 ASSERT_EQ(12UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200693 CheckReferencesVp8(pid);
694 CheckReferencesVp8(pid + 1 , pid);
695 CheckReferencesVp8(pid + 2 , pid);
696 CheckReferencesVp8(pid + 3 , pid, pid + 1, pid + 2);
697 CheckReferencesVp8(pid + 4 , pid);
698 CheckReferencesVp8(pid + 5 , pid + 2, pid + 3, pid + 4);
699 CheckReferencesVp8(pid + 6 , pid + 2, pid + 4);
700 CheckReferencesVp8(pid + 7 , pid + 4, pid + 5, pid + 6);
701 CheckReferencesVp8(pid + 8 , pid + 4);
702 CheckReferencesVp8(pid + 9 , pid + 8);
703 CheckReferencesVp8(pid + 10, pid + 8);
704 CheckReferencesVp8(pid + 11, pid + 8, pid + 9, pid + 10);
philipelf4139332016-04-20 10:26:34 +0200705}
706
707// Test with 3 temporal layers in a 0212 pattern.
708TEST_F(TestPacketBuffer, Vp8TemporalLayersReordering_0212) {
709 uint16_t pid = 126;
710 uint16_t seq_num = Rand();
711
philipela1059872016-05-09 11:41:48 +0200712 // seq_num , kf, frst, lst, sync, pid , tid, tl0
713 InsertVp8(seq_num + 1 , kF, kT , kT , kT , pid + 1 , 2 , 55);
714 InsertVp8(seq_num , kT, kT , kT , kF , pid , 0 , 55);
715 InsertVp8(seq_num + 2 , kF, kT , kT , kT , pid + 2 , 1 , 55);
716 InsertVp8(seq_num + 4 , kF, kT , kT , kF , pid + 4 , 0 , 56);
717 InsertVp8(seq_num + 5 , kF, kT , kT , kF , pid + 5 , 2 , 56);
718 InsertVp8(seq_num + 3 , kF, kT , kT , kF , pid + 3 , 2 , 55);
719 InsertVp8(seq_num + 7 , kF, kT , kT , kF , pid + 7 , 2 , 56);
720 InsertVp8(seq_num + 9 , kF, kT , kT , kT , pid + 9 , 2 , 57);
721 InsertVp8(seq_num + 6 , kF, kT , kT , kF , pid + 6 , 1 , 56);
722 InsertVp8(seq_num + 8 , kF, kT , kT , kF , pid + 8 , 0 , 57);
723 InsertVp8(seq_num + 11, kF, kT , kT , kF , pid + 11, 2 , 57);
724 InsertVp8(seq_num + 10, kF, kT , kT , kT , pid + 10, 1 , 57);
philipelf4139332016-04-20 10:26:34 +0200725
726 ASSERT_EQ(12UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200727 CheckReferencesVp8(pid);
728 CheckReferencesVp8(pid + 1 , pid);
729 CheckReferencesVp8(pid + 2 , pid);
730 CheckReferencesVp8(pid + 3 , pid, pid + 1, pid + 2);
731 CheckReferencesVp8(pid + 4 , pid);
732 CheckReferencesVp8(pid + 5 , pid + 2, pid + 3, pid + 4);
733 CheckReferencesVp8(pid + 6 , pid + 2, pid + 4);
734 CheckReferencesVp8(pid + 7 , pid + 4, pid + 5, pid + 6);
735 CheckReferencesVp8(pid + 8 , pid + 4);
736 CheckReferencesVp8(pid + 9 , pid + 8);
737 CheckReferencesVp8(pid + 10, pid + 8);
738 CheckReferencesVp8(pid + 11, pid + 8, pid + 9, pid + 10);
philipelf4139332016-04-20 10:26:34 +0200739}
740
741TEST_F(TestPacketBuffer, Vp8InsertManyFrames_0212) {
742 uint16_t pid = Rand();
743 uint16_t seq_num = Rand();
744
745 const int keyframes_to_insert = 50;
746 const int frames_per_keyframe = 120; // Should be a multiple of 4.
747 uint8_t tl0 = 128;
748
749 for (int k = 0; k < keyframes_to_insert; ++k) {
philipela1059872016-05-09 11:41:48 +0200750 // seq_num , keyf, frst, lst, sync, pid , tid, tl0
751 InsertVp8(seq_num , kT , kT , kT , kF , pid , 0 , tl0);
752 InsertVp8(seq_num + 1, kF , kT , kT , kT , pid + 1, 2 , tl0);
753 InsertVp8(seq_num + 2, kF , kT , kT , kT , pid + 2, 1 , tl0);
754 InsertVp8(seq_num + 3, kF , kT , kT , kF , pid + 3, 2 , tl0);
755 CheckReferencesVp8(pid);
756 CheckReferencesVp8(pid + 1, pid);
757 CheckReferencesVp8(pid + 2, pid);
758 CheckReferencesVp8(pid + 3, pid, pid + 1, pid + 2);
philipelf4139332016-04-20 10:26:34 +0200759 frames_from_callback_.clear();
760 ++tl0;
761
762 for (int f = 4; f < frames_per_keyframe; f += 4) {
763 uint16_t sf = seq_num + f;
764 uint16_t pidf = pid + f;
765
philipela1059872016-05-09 11:41:48 +0200766 // seq_num, keyf, frst, lst, sync, pid , tid, tl0
767 InsertVp8(sf , kF , kT , kT , kF , pidf , 0 , tl0);
768 InsertVp8(sf + 1 , kF , kT , kT , kF , pidf + 1, 2 , tl0);
769 InsertVp8(sf + 2 , kF , kT , kT , kF , pidf + 2, 1 , tl0);
770 InsertVp8(sf + 3 , kF , kT , kT , kF , pidf + 3, 2 , tl0);
771 CheckReferencesVp8(pidf, pidf - 4);
772 CheckReferencesVp8(pidf + 1, pidf, pidf - 1, pidf - 2);
773 CheckReferencesVp8(pidf + 2, pidf, pidf - 2);
774 CheckReferencesVp8(pidf + 3, pidf, pidf + 1, pidf + 2);
philipelf4139332016-04-20 10:26:34 +0200775 frames_from_callback_.clear();
776 ++tl0;
777 }
778
779 pid += frames_per_keyframe;
780 seq_num += frames_per_keyframe;
781 }
782}
783
784TEST_F(TestPacketBuffer, Vp8LayerSync) {
785 uint16_t pid = Rand();
786 uint16_t seq_num = Rand();
787
philipela1059872016-05-09 11:41:48 +0200788 // seq_num , keyf, frst, lst, sync, pid , tid, tl0
789 InsertVp8(seq_num , kT , kT , kT , kF , pid , 0 , 0);
790 InsertVp8(seq_num + 1 , kF , kT , kT , kT , pid + 1 , 1 , 0);
791 InsertVp8(seq_num + 2 , kF , kT , kT , kF , pid + 2 , 0 , 1);
philipelf4139332016-04-20 10:26:34 +0200792 ASSERT_EQ(3UL, frames_from_callback_.size());
793
philipela1059872016-05-09 11:41:48 +0200794 InsertVp8(seq_num + 4 , kF , kT , kT , kF , pid + 4 , 0 , 2);
795 InsertVp8(seq_num + 5 , kF , kT , kT , kT , pid + 5 , 1 , 2);
796 InsertVp8(seq_num + 6 , kF , kT , kT , kF , pid + 6 , 0 , 3);
797 InsertVp8(seq_num + 7 , kF , kT , kT , kF , pid + 7 , 1 , 3);
philipelf4139332016-04-20 10:26:34 +0200798
799 ASSERT_EQ(7UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200800 CheckReferencesVp8(pid);
801 CheckReferencesVp8(pid + 1, pid);
802 CheckReferencesVp8(pid + 2, pid);
803 CheckReferencesVp8(pid + 4, pid + 2);
804 CheckReferencesVp8(pid + 5, pid + 4);
805 CheckReferencesVp8(pid + 6, pid + 4);
806 CheckReferencesVp8(pid + 7, pid + 6, pid + 5);
philipelf4139332016-04-20 10:26:34 +0200807}
808
809TEST_F(TestPacketBuffer, Vp8InsertLargeFrames) {
810 packet_buffer_.reset(new PacketBuffer(1 << 3, 1 << 12, this));
811 uint16_t pid = Rand();
812 uint16_t seq_num = Rand();
813
814 const uint16_t packets_per_frame = 1000;
815 uint16_t current = seq_num;
816 uint16_t end = current + packets_per_frame;
817
philipela1059872016-05-09 11:41:48 +0200818 // seq_num , keyf, frst, lst, sync, pid, tid, tl0
819 InsertVp8(current++, kT , kT , kF , kF , pid, 0 , 0);
philipelf4139332016-04-20 10:26:34 +0200820 while (current != end)
philipela1059872016-05-09 11:41:48 +0200821 InsertVp8(current++, kF , kF , kF , kF , pid, 0 , 0);
822 InsertVp8(current++, kF , kF , kT , kF , pid, 0 , 0);
philipelf4139332016-04-20 10:26:34 +0200823 end = current + packets_per_frame;
824
825 for (int f = 1; f < 4; ++f) {
philipela1059872016-05-09 11:41:48 +0200826 InsertVp8(current++, kF , kT , kF , kF , pid + f, 0, f);
philipelf4139332016-04-20 10:26:34 +0200827 while (current != end)
philipela1059872016-05-09 11:41:48 +0200828 InsertVp8(current++, kF , kF , kF , kF , pid + f, 0, f);
829 InsertVp8(current++, kF , kF , kT , kF , pid + f, 0, f);
philipelf4139332016-04-20 10:26:34 +0200830 end = current + packets_per_frame;
831 }
832
833 ASSERT_EQ(4UL, frames_from_callback_.size());
philipela1059872016-05-09 11:41:48 +0200834 CheckReferencesVp8(pid);
835 CheckReferencesVp8(pid + 1, pid);
836 CheckReferencesVp8(pid + 2, pid + 1);
837 CheckReferencesVp8(pid + 3, pid + 2);
838}
839
840TEST_F(TestPacketBuffer, Vp9GofInsertOneFrame) {
841 uint16_t pid = Rand();
842 uint16_t seq_num = Rand();
843 GofInfoVP9 ss;
844 ss.SetGofInfoVP9(kTemporalStructureMode1);
845
846 // seq_num, keyf, frst, lst, up, pid, sid, tid, tl0, ss
847 InsertVp9Gof(seq_num, kT , kT , kT , kF, pid, 0 , 0 , 0 , &ss);
848
849 CheckReferencesVp9(pid, 0);
850}
851
852TEST_F(TestPacketBuffer, Vp9NoPictureIdReordered) {
853 uint16_t sn = 0xfffa;
854
855 // sn , kf, frst, lst
856 InsertVp9Gof(sn + 1 , kF, kF , kF);
857 InsertVp9Gof(sn , kT, kT , kF);
858 InsertVp9Gof(sn + 2 , kF, kF , kT);
859 InsertVp9Gof(sn + 4 , kF, kF , kT);
860 InsertVp9Gof(sn + 6 , kF, kF , kF);
861 InsertVp9Gof(sn + 3 , kF, kT , kF);
862 InsertVp9Gof(sn + 7 , kF, kF , kF);
863 InsertVp9Gof(sn + 5 , kF, kT , kF);
864 InsertVp9Gof(sn + 9 , kF, kT , kT);
865 InsertVp9Gof(sn + 10, kF, kT , kF);
866 InsertVp9Gof(sn + 8 , kF, kF , kT);
867 InsertVp9Gof(sn + 13, kF, kT , kF);
868 InsertVp9Gof(sn + 14, kF, kF , kF);
869 InsertVp9Gof(sn + 12, kT, kT , kT);
870 InsertVp9Gof(sn + 11, kF, kF , kT);
871 InsertVp9Gof(sn + 16, kF, kF , kF);
872 InsertVp9Gof(sn + 19, kF, kT , kF);
873 InsertVp9Gof(sn + 15, kF, kF , kF);
874 InsertVp9Gof(sn + 17, kF, kF , kT);
875 InsertVp9Gof(sn + 20, kF, kF , kT);
876 InsertVp9Gof(sn + 21, kF, kT , kT);
877 InsertVp9Gof(sn + 18, kF, kT , kT);
878
879 ASSERT_EQ(10UL, frames_from_callback_.size());
880 CheckReferencesVp9(sn + 2 , 0);
881 CheckReferencesVp9(sn + 4 , 0, sn + 2);
882 CheckReferencesVp9(sn + 8 , 0, sn + 4);
883 CheckReferencesVp9(sn + 9 , 0, sn + 8);
884 CheckReferencesVp9(sn + 11, 0, sn + 9);
885 CheckReferencesVp9(sn + 12, 0);
886 CheckReferencesVp9(sn + 17, 0, sn + 12);
887 CheckReferencesVp9(sn + 18, 0, sn + 17);
888 CheckReferencesVp9(sn + 20, 0, sn + 18);
889 CheckReferencesVp9(sn + 21, 0, sn + 20);
890}
891
892TEST_F(TestPacketBuffer, Vp9GofTemporalLayers_0) {
893 uint16_t pid = Rand();
894 uint16_t sn = Rand();
895 GofInfoVP9 ss;
896 ss.SetGofInfoVP9(kTemporalStructureMode1); // Only 1 spatial layer.
897
898 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
899 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
900 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 0 , 1);
901 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 0 , 2);
902 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 0 , 3);
903 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 4);
904 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 0 , 5);
905 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 0 , 6);
906 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 0 , 7);
907 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 8);
908 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 0 , 9);
909 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 0 , 10);
910 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 0 , 11);
911 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 12);
912 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 0 , 13);
913 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 0 , 14);
914 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 0 , 15);
915 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 16);
916 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 0 , 17);
917 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 0 , 18);
918 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 0 , 19);
919
920 ASSERT_EQ(20UL, frames_from_callback_.size());
921 CheckReferencesVp9(pid, 0);
922 CheckReferencesVp9(pid + 1 , 0, pid);
923 CheckReferencesVp9(pid + 2 , 0, pid + 1);
924 CheckReferencesVp9(pid + 3 , 0, pid + 2);
925 CheckReferencesVp9(pid + 4 , 0, pid + 3);
926 CheckReferencesVp9(pid + 5 , 0, pid + 4);
927 CheckReferencesVp9(pid + 6 , 0, pid + 5);
928 CheckReferencesVp9(pid + 7 , 0, pid + 6);
929 CheckReferencesVp9(pid + 8 , 0, pid + 7);
930 CheckReferencesVp9(pid + 9 , 0, pid + 8);
931 CheckReferencesVp9(pid + 10, 0, pid + 9);
932 CheckReferencesVp9(pid + 11, 0, pid + 10);
933 CheckReferencesVp9(pid + 12, 0, pid + 11);
934 CheckReferencesVp9(pid + 13, 0, pid + 12);
935 CheckReferencesVp9(pid + 14, 0, pid + 13);
936 CheckReferencesVp9(pid + 15, 0, pid + 14);
937 CheckReferencesVp9(pid + 16, 0, pid + 15);
938 CheckReferencesVp9(pid + 17, 0, pid + 16);
939 CheckReferencesVp9(pid + 18, 0, pid + 17);
940 CheckReferencesVp9(pid + 19, 0, pid + 18);
941}
942
943TEST_F(TestPacketBuffer, Vp9GofTemporalLayersReordered_0) {
944 uint16_t pid = Rand();
945 uint16_t sn = Rand();
946 GofInfoVP9 ss;
947 ss.SetGofInfoVP9(kTemporalStructureMode1); // Only 1 spatial layer.
948
949 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
950 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 0 , 2);
951 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 0 , 1);
952 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
953 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 4);
954 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 0 , 3);
955 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 0 , 5);
956 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 0 , 7);
957 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 0 , 6);
958 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 8);
959 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 0 , 10);
960 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 0 , 13);
961 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 0 , 11);
962 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 0 , 9);
963 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 16);
964 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 0 , 14);
965 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 0 , 15);
966 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 12);
967 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 0 , 17);
968 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 0 , 19);
969 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 0 , 18);
970
971 ASSERT_EQ(20UL, frames_from_callback_.size());
972 CheckReferencesVp9(pid, 0);
973 CheckReferencesVp9(pid + 1 , 0, pid);
974 CheckReferencesVp9(pid + 2 , 0, pid + 1);
975 CheckReferencesVp9(pid + 3 , 0, pid + 2);
976 CheckReferencesVp9(pid + 4 , 0, pid + 3);
977 CheckReferencesVp9(pid + 5 , 0, pid + 4);
978 CheckReferencesVp9(pid + 6 , 0, pid + 5);
979 CheckReferencesVp9(pid + 7 , 0, pid + 6);
980 CheckReferencesVp9(pid + 8 , 0, pid + 7);
981 CheckReferencesVp9(pid + 9 , 0, pid + 8);
982 CheckReferencesVp9(pid + 10, 0, pid + 9);
983 CheckReferencesVp9(pid + 11, 0, pid + 10);
984 CheckReferencesVp9(pid + 12, 0, pid + 11);
985 CheckReferencesVp9(pid + 13, 0, pid + 12);
986 CheckReferencesVp9(pid + 14, 0, pid + 13);
987 CheckReferencesVp9(pid + 15, 0, pid + 14);
988 CheckReferencesVp9(pid + 16, 0, pid + 15);
989 CheckReferencesVp9(pid + 17, 0, pid + 16);
990 CheckReferencesVp9(pid + 18, 0, pid + 17);
991 CheckReferencesVp9(pid + 19, 0, pid + 18);
992}
993
994TEST_F(TestPacketBuffer, Vp9GofTemporalLayers_01) {
995 uint16_t pid = Rand();
996 uint16_t sn = Rand();
997 GofInfoVP9 ss;
998 ss.SetGofInfoVP9(kTemporalStructureMode2); // 0101 pattern
999
1000 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1001 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1002 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 1 , 0);
1003 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 0 , 1);
1004 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 1 , 1);
1005 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 2);
1006 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 1 , 2);
1007 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 0 , 3);
1008 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 1 , 3);
1009 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 4);
1010 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 1 , 4);
1011 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 0 , 5);
1012 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 1 , 5);
1013 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 6);
1014 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 1 , 6);
1015 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 0 , 7);
1016 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 1 , 7);
1017 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 8);
1018 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 1 , 8);
1019 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 0 , 9);
1020 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 1 , 9);
1021
1022 ASSERT_EQ(20UL, frames_from_callback_.size());
1023 CheckReferencesVp9(pid, 0);
1024 CheckReferencesVp9(pid + 1 , 0, pid);
1025 CheckReferencesVp9(pid + 2 , 0, pid);
1026 CheckReferencesVp9(pid + 3 , 0, pid + 2);
1027 CheckReferencesVp9(pid + 4 , 0, pid + 2);
1028 CheckReferencesVp9(pid + 5 , 0, pid + 4);
1029 CheckReferencesVp9(pid + 6 , 0, pid + 4);
1030 CheckReferencesVp9(pid + 7 , 0, pid + 6);
1031 CheckReferencesVp9(pid + 8 , 0, pid + 6);
1032 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1033 CheckReferencesVp9(pid + 10, 0, pid + 8);
1034 CheckReferencesVp9(pid + 11, 0, pid + 10);
1035 CheckReferencesVp9(pid + 12, 0, pid + 10);
1036 CheckReferencesVp9(pid + 13, 0, pid + 12);
1037 CheckReferencesVp9(pid + 14, 0, pid + 12);
1038 CheckReferencesVp9(pid + 15, 0, pid + 14);
1039 CheckReferencesVp9(pid + 16, 0, pid + 14);
1040 CheckReferencesVp9(pid + 17, 0, pid + 16);
1041 CheckReferencesVp9(pid + 18, 0, pid + 16);
1042 CheckReferencesVp9(pid + 19, 0, pid + 18);
1043}
1044
1045TEST_F(TestPacketBuffer, Vp9GofTemporalLayersReordered_01) {
1046 uint16_t pid = Rand();
1047 uint16_t sn = Rand();
1048 GofInfoVP9 ss;
1049 ss.SetGofInfoVP9(kTemporalStructureMode2); // 01 pattern
1050
1051 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1052 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 1 , 0);
1053 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1054 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 0 , 1);
1055 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 2);
1056 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 1 , 1);
1057 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 1 , 2);
1058 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 1 , 3);
1059 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 0 , 3);
1060 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 0 , 5);
1061 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 4);
1062 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 1 , 4);
1063 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 1 , 5);
1064 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 1 , 6);
1065 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 8);
1066 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 6);
1067 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 0 , 7);
1068 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 1 , 8);
1069 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 1 , 9);
1070 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 1 , 7);
1071 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 0 , 9);
1072
1073 ASSERT_EQ(20UL, frames_from_callback_.size());
1074 CheckReferencesVp9(pid, 0);
1075 CheckReferencesVp9(pid + 1 , 0, pid);
1076 CheckReferencesVp9(pid + 2 , 0, pid);
1077 CheckReferencesVp9(pid + 3 , 0, pid + 2);
1078 CheckReferencesVp9(pid + 4 , 0, pid + 2);
1079 CheckReferencesVp9(pid + 5 , 0, pid + 4);
1080 CheckReferencesVp9(pid + 6 , 0, pid + 4);
1081 CheckReferencesVp9(pid + 7 , 0, pid + 6);
1082 CheckReferencesVp9(pid + 8 , 0, pid + 6);
1083 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1084 CheckReferencesVp9(pid + 10, 0, pid + 8);
1085 CheckReferencesVp9(pid + 11, 0, pid + 10);
1086 CheckReferencesVp9(pid + 12, 0, pid + 10);
1087 CheckReferencesVp9(pid + 13, 0, pid + 12);
1088 CheckReferencesVp9(pid + 14, 0, pid + 12);
1089 CheckReferencesVp9(pid + 15, 0, pid + 14);
1090 CheckReferencesVp9(pid + 16, 0, pid + 14);
1091 CheckReferencesVp9(pid + 17, 0, pid + 16);
1092 CheckReferencesVp9(pid + 18, 0, pid + 16);
1093 CheckReferencesVp9(pid + 19, 0, pid + 18);
1094}
1095
1096TEST_F(TestPacketBuffer, Vp9GofTemporalLayers_0212) {
1097 uint16_t pid = Rand();
1098 uint16_t sn = Rand();
1099 GofInfoVP9 ss;
1100 ss.SetGofInfoVP9(kTemporalStructureMode3); // 0212 pattern
1101
1102 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1103 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1104 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 2 , 0);
1105 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 1 , 0);
1106 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 2 , 0);
1107 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 1);
1108 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 2 , 1);
1109 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 1 , 1);
1110 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 2 , 1);
1111 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 2);
1112 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 2 , 2);
1113 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 1 , 2);
1114 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 2 , 2);
1115 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 3);
1116 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 2 , 3);
1117 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 1 , 3);
1118 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 2 , 3);
1119 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 4);
1120 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 2 , 4);
1121 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 1 , 4);
1122 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 2 , 4);
1123
1124 ASSERT_EQ(20UL, frames_from_callback_.size());
1125 CheckReferencesVp9(pid, 0);
1126 CheckReferencesVp9(pid + 1 , 0, pid);
1127 CheckReferencesVp9(pid + 2 , 0, pid);
1128 CheckReferencesVp9(pid + 3 , 0, pid + 1, pid + 2);
1129 CheckReferencesVp9(pid + 4 , 0, pid);
1130 CheckReferencesVp9(pid + 5 , 0, pid + 4);
1131 CheckReferencesVp9(pid + 6 , 0, pid + 4);
1132 CheckReferencesVp9(pid + 7 , 0, pid + 5, pid + 6);
1133 CheckReferencesVp9(pid + 8 , 0, pid + 4);
1134 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1135 CheckReferencesVp9(pid + 10, 0, pid + 8);
1136 CheckReferencesVp9(pid + 11, 0, pid + 9, pid + 10);
1137 CheckReferencesVp9(pid + 12, 0, pid + 8);
1138 CheckReferencesVp9(pid + 13, 0, pid + 12);
1139 CheckReferencesVp9(pid + 14, 0, pid + 12);
1140 CheckReferencesVp9(pid + 15, 0, pid + 13, pid + 14);
1141 CheckReferencesVp9(pid + 16, 0, pid + 12);
1142 CheckReferencesVp9(pid + 17, 0, pid + 16);
1143 CheckReferencesVp9(pid + 18, 0, pid + 16);
1144 CheckReferencesVp9(pid + 19, 0, pid + 17, pid + 18);
1145}
1146
1147TEST_F(TestPacketBuffer, Vp9GofTemporalLayersReordered_0212) {
1148 uint16_t pid = Rand();
1149 uint16_t sn = Rand();
1150 GofInfoVP9 ss;
1151 ss.SetGofInfoVP9(kTemporalStructureMode3); // 0212 pattern
1152
1153 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1154 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 1 , 0);
1155 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 2 , 0);
1156 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1157 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 2 , 0);
1158 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 1 , 1);
1159 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 2 , 1);
1160 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 1);
1161 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 2 , 2);
1162 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 2 , 1);
1163 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 2);
1164 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 2 , 2);
1165 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 1 , 2);
1166 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 2 , 3);
1167 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 3);
1168 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 1 , 3);
1169 InsertVp9Gof(sn + 16, kF, kT , kT , kF, pid + 16, 0 , 0 , 4);
1170 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 2 , 3);
1171 InsertVp9Gof(sn + 17, kF, kT , kT , kF, pid + 17, 0 , 2 , 4);
1172 InsertVp9Gof(sn + 19, kF, kT , kT , kF, pid + 19, 0 , 2 , 4);
1173 InsertVp9Gof(sn + 18, kF, kT , kT , kF, pid + 18, 0 , 1 , 4);
1174
1175 ASSERT_EQ(20UL, frames_from_callback_.size());
1176 CheckReferencesVp9(pid, 0);
1177 CheckReferencesVp9(pid + 1 , 0, pid);
1178 CheckReferencesVp9(pid + 2 , 0, pid);
1179 CheckReferencesVp9(pid + 3 , 0, pid + 1, pid + 2);
1180 CheckReferencesVp9(pid + 4 , 0, pid);
1181 CheckReferencesVp9(pid + 5 , 0, pid + 4);
1182 CheckReferencesVp9(pid + 6 , 0, pid + 4);
1183 CheckReferencesVp9(pid + 7 , 0, pid + 5, pid + 6);
1184 CheckReferencesVp9(pid + 8 , 0, pid + 4);
1185 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1186 CheckReferencesVp9(pid + 10, 0, pid + 8);
1187 CheckReferencesVp9(pid + 11, 0, pid + 9, pid + 10);
1188 CheckReferencesVp9(pid + 12, 0, pid + 8);
1189 CheckReferencesVp9(pid + 13, 0, pid + 12);
1190 CheckReferencesVp9(pid + 14, 0, pid + 12);
1191 CheckReferencesVp9(pid + 15, 0, pid + 13, pid + 14);
1192 CheckReferencesVp9(pid + 16, 0, pid + 12);
1193 CheckReferencesVp9(pid + 17, 0, pid + 16);
1194 CheckReferencesVp9(pid + 18, 0, pid + 16);
1195 CheckReferencesVp9(pid + 19, 0, pid + 17, pid + 18);
1196}
1197
1198TEST_F(TestPacketBuffer, Vp9GofTemporalLayersUpSwitch_02120212) {
1199 uint16_t pid = Rand();
1200 uint16_t sn = Rand();
1201 GofInfoVP9 ss;
1202 ss.SetGofInfoVP9(kTemporalStructureMode4); // 02120212 pattern
1203
1204 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1205 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1206 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 2 , 0);
1207 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 1 , 0);
1208 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 2 , 0);
1209 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 1);
1210 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 2 , 1);
1211 InsertVp9Gof(sn + 6 , kF, kT , kT , kT, pid + 6 , 0 , 1 , 1);
1212 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 2 , 1);
1213 InsertVp9Gof(sn + 8 , kF, kT , kT , kT, pid + 8 , 0 , 0 , 2);
1214 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 2 , 2);
1215 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 1 , 2);
1216 InsertVp9Gof(sn + 11, kF, kT , kT , kT, pid + 11, 0 , 2 , 2);
1217 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 3);
1218 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 2 , 3);
1219 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 1 , 3);
1220 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 2 , 3);
1221
1222 ASSERT_EQ(16UL, frames_from_callback_.size());
1223 CheckReferencesVp9(pid, 0);
1224 CheckReferencesVp9(pid + 1 , 0, pid);
1225 CheckReferencesVp9(pid + 2 , 0, pid);
1226 CheckReferencesVp9(pid + 3 , 0, pid + 1, pid + 2);
1227 CheckReferencesVp9(pid + 4 , 0, pid);
1228 CheckReferencesVp9(pid + 5 , 0, pid + 3, pid + 4);
1229 CheckReferencesVp9(pid + 6 , 0, pid + 2, pid + 4);
1230 CheckReferencesVp9(pid + 7 , 0, pid + 6);
1231 CheckReferencesVp9(pid + 8 , 0, pid + 4);
1232 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1233 CheckReferencesVp9(pid + 10, 0, pid + 8);
1234 CheckReferencesVp9(pid + 11, 0, pid + 9, pid + 10);
1235 CheckReferencesVp9(pid + 12, 0, pid + 8);
1236 CheckReferencesVp9(pid + 13, 0, pid + 11, pid + 12);
1237 CheckReferencesVp9(pid + 14, 0, pid + 10, pid + 12);
1238 CheckReferencesVp9(pid + 15, 0, pid + 13, pid + 14);
1239}
1240
1241TEST_F(TestPacketBuffer, Vp9GofTemporalLayersUpSwitchReordered_02120212) {
1242 uint16_t pid = Rand();
1243 uint16_t sn = Rand();
1244 GofInfoVP9 ss;
1245 ss.SetGofInfoVP9(kTemporalStructureMode4); // 02120212 pattern
1246
1247 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1248 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 2 , 0);
1249 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1250 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 1);
1251 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 1 , 0);
1252 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 2 , 1);
1253 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 2 , 0);
1254 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 2 , 1);
1255 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 2 , 2);
1256 InsertVp9Gof(sn + 6 , kF, kT , kT , kT, pid + 6 , 0 , 1 , 1);
1257 InsertVp9Gof(sn + 12, kF, kT , kT , kF, pid + 12, 0 , 0 , 3);
1258 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 1 , 2);
1259 InsertVp9Gof(sn + 8 , kF, kT , kT , kT, pid + 8 , 0 , 0 , 2);
1260 InsertVp9Gof(sn + 11, kF, kT , kT , kT, pid + 11, 0 , 2 , 2);
1261 InsertVp9Gof(sn + 13, kF, kT , kT , kF, pid + 13, 0 , 2 , 3);
1262 InsertVp9Gof(sn + 15, kF, kT , kT , kF, pid + 15, 0 , 2 , 3);
1263 InsertVp9Gof(sn + 14, kF, kT , kT , kF, pid + 14, 0 , 1 , 3);
1264
1265 ASSERT_EQ(16UL, frames_from_callback_.size());
1266 CheckReferencesVp9(pid, 0);
1267 CheckReferencesVp9(pid + 1 , 0, pid);
1268 CheckReferencesVp9(pid + 2 , 0, pid);
1269 CheckReferencesVp9(pid + 3 , 0, pid + 1, pid + 2);
1270 CheckReferencesVp9(pid + 4 , 0, pid);
1271 CheckReferencesVp9(pid + 5 , 0, pid + 3, pid + 4);
1272 CheckReferencesVp9(pid + 6 , 0, pid + 2, pid + 4);
1273 CheckReferencesVp9(pid + 7 , 0, pid + 6);
1274 CheckReferencesVp9(pid + 8 , 0, pid + 4);
1275 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1276 CheckReferencesVp9(pid + 10, 0, pid + 8);
1277 CheckReferencesVp9(pid + 11, 0, pid + 9, pid + 10);
1278 CheckReferencesVp9(pid + 12, 0, pid + 8);
1279 CheckReferencesVp9(pid + 13, 0, pid + 11, pid + 12);
1280 CheckReferencesVp9(pid + 14, 0, pid + 10, pid + 12);
1281 CheckReferencesVp9(pid + 15, 0, pid + 13, pid + 14);
1282}
1283
1284TEST_F(TestPacketBuffer, Vp9GofTemporalLayersReordered_01_0212) {
1285 uint16_t pid = Rand();
1286 uint16_t sn = Rand();
1287 GofInfoVP9 ss;
1288 ss.SetGofInfoVP9(kTemporalStructureMode2); // 01 pattern
1289
1290 // sn , kf, frst, lst, up, pid , sid, tid, tl0, ss
1291 InsertVp9Gof(sn + 1 , kF, kT , kT , kF, pid + 1 , 0 , 1 , 0);
1292 InsertVp9Gof(sn , kT, kT , kT , kF, pid , 0 , 0 , 0 , &ss);
1293 InsertVp9Gof(sn + 3 , kF, kT , kT , kF, pid + 3 , 0 , 1 , 1);
1294 InsertVp9Gof(sn + 6 , kF, kT , kT , kF, pid + 6 , 0 , 1 , 2);
1295 ss.SetGofInfoVP9(kTemporalStructureMode3); // 0212 pattern
1296 InsertVp9Gof(sn + 4 , kF, kT , kT , kF, pid + 4 , 0 , 0 , 2 , &ss);
1297 InsertVp9Gof(sn + 2 , kF, kT , kT , kF, pid + 2 , 0 , 0 , 1);
1298 InsertVp9Gof(sn + 5 , kF, kT , kT , kF, pid + 5 , 0 , 2 , 2);
1299 InsertVp9Gof(sn + 8 , kF, kT , kT , kF, pid + 8 , 0 , 0 , 3);
1300 InsertVp9Gof(sn + 10, kF, kT , kT , kF, pid + 10, 0 , 1 , 3);
1301 InsertVp9Gof(sn + 7 , kF, kT , kT , kF, pid + 7 , 0 , 2 , 2);
1302 InsertVp9Gof(sn + 11, kF, kT , kT , kF, pid + 11, 0 , 2 , 3);
1303 InsertVp9Gof(sn + 9 , kF, kT , kT , kF, pid + 9 , 0 , 2 , 3);
1304
1305 ASSERT_EQ(12UL, frames_from_callback_.size());
1306 CheckReferencesVp9(pid, 0);
1307 CheckReferencesVp9(pid + 1 , 0, pid);
1308 CheckReferencesVp9(pid + 2 , 0, pid);
1309 CheckReferencesVp9(pid + 3 , 0, pid + 2);
1310 CheckReferencesVp9(pid + 4 , 0, pid);
1311 CheckReferencesVp9(pid + 5 , 0, pid + 4);
1312 CheckReferencesVp9(pid + 6 , 0, pid + 4);
1313 CheckReferencesVp9(pid + 7 , 0, pid + 5, pid + 6);
1314 CheckReferencesVp9(pid + 8 , 0, pid + 4);
1315 CheckReferencesVp9(pid + 9 , 0, pid + 8);
1316 CheckReferencesVp9(pid + 10, 0, pid + 8);
1317 CheckReferencesVp9(pid + 11, 0, pid + 9, pid + 10);
1318}
1319
1320TEST_F(TestPacketBuffer, Vp9FlexibleModeOneFrame) {
1321 uint16_t pid = Rand();
1322 uint16_t sn = Rand();
1323
1324 // sn, kf, frst, lst, intr, pid, sid, tid, tl0
1325 InsertVp9Flex(sn, kT, kT , kT , kF , pid, 0 , 0 , 0);
1326
1327 ASSERT_EQ(1UL, frames_from_callback_.size());
1328 CheckReferencesVp9(pid, 0);
1329}
1330
1331TEST_F(TestPacketBuffer, Vp9FlexibleModeTwoSpatialLayers) {
1332 uint16_t pid = Rand();
1333 uint16_t sn = Rand();
1334
1335 // sn , kf, frst, lst, intr, pid , sid, tid, tl0, refs
1336 InsertVp9Flex(sn , kT, kT , kT , kF , pid , 0 , 0 , 0);
1337 InsertVp9Flex(sn + 1 , kT, kT , kT , kT , pid , 1 , 0 , 0);
1338 InsertVp9Flex(sn + 2 , kF, kT , kT , kF , pid + 1, 1 , 0 , 0 , {1});
1339 InsertVp9Flex(sn + 3 , kF, kT , kT , kF , pid + 2, 0 , 0 , 1 , {2});
1340 InsertVp9Flex(sn + 4 , kF, kT , kT , kF , pid + 2, 1 , 0 , 1 , {1});
1341 InsertVp9Flex(sn + 5 , kF, kT , kT , kF , pid + 3, 1 , 0 , 1 , {1});
1342 InsertVp9Flex(sn + 6 , kF, kT , kT , kF , pid + 4, 0 , 0 , 2 , {2});
1343 InsertVp9Flex(sn + 7 , kF, kT , kT , kF , pid + 4, 1 , 0 , 2 , {1});
1344 InsertVp9Flex(sn + 8 , kF, kT , kT , kF , pid + 5, 1 , 0 , 2 , {1});
1345 InsertVp9Flex(sn + 9 , kF, kT , kT , kF , pid + 6, 0 , 0 , 3 , {2});
1346 InsertVp9Flex(sn + 10, kF, kT , kT , kF , pid + 6, 1 , 0 , 3 , {1});
1347 InsertVp9Flex(sn + 11, kF, kT , kT , kF , pid + 7, 1 , 0 , 3 , {1});
1348 InsertVp9Flex(sn + 12, kF, kT , kT , kF , pid + 8, 0 , 0 , 4 , {2});
1349 InsertVp9Flex(sn + 13, kF, kT , kT , kF , pid + 8, 1 , 0 , 4 , {1});
1350
1351 ASSERT_EQ(14UL, frames_from_callback_.size());
1352 CheckReferencesVp9(pid , 0);
1353 CheckReferencesVp9(pid , 1);
1354 CheckReferencesVp9(pid + 1, 1, pid);
1355 CheckReferencesVp9(pid + 2, 0, pid);
1356 CheckReferencesVp9(pid + 2, 1, pid + 1);
1357 CheckReferencesVp9(pid + 3, 1, pid + 2);
1358 CheckReferencesVp9(pid + 4, 0, pid + 2);
1359 CheckReferencesVp9(pid + 4, 1, pid + 3);
1360 CheckReferencesVp9(pid + 5, 1, pid + 4);
1361 CheckReferencesVp9(pid + 6, 0, pid + 4);
1362 CheckReferencesVp9(pid + 6, 1, pid + 5);
1363 CheckReferencesVp9(pid + 7, 1, pid + 6);
1364 CheckReferencesVp9(pid + 8, 0, pid + 6);
1365 CheckReferencesVp9(pid + 8, 1, pid + 7);
1366}
1367
1368TEST_F(TestPacketBuffer, Vp9FlexibleModeTwoSpatialLayersReordered) {
1369 uint16_t pid = Rand();
1370 uint16_t sn = Rand();
1371
1372 // sn , kf, frst, lst, intr, pid , sid, tid, tl0, refs
1373 InsertVp9Flex(sn + 1 , kT, kT , kT , kT , pid , 1 , 0 , 0);
1374 InsertVp9Flex(sn + 2 , kF, kT , kT , kF , pid + 1, 1 , 0 , 0 , {1});
1375 InsertVp9Flex(sn , kT, kT , kT , kF , pid , 0 , 0 , 0);
1376 InsertVp9Flex(sn + 4 , kF, kT , kT , kF , pid + 2, 1 , 0 , 1 , {1});
1377 InsertVp9Flex(sn + 5 , kF, kT , kT , kF , pid + 3, 1 , 0 , 1 , {1});
1378 InsertVp9Flex(sn + 3 , kF, kT , kT , kF , pid + 2, 0 , 0 , 1 , {2});
1379 InsertVp9Flex(sn + 7 , kF, kT , kT , kF , pid + 4, 1 , 0 , 2 , {1});
1380 InsertVp9Flex(sn + 6 , kF, kT , kT , kF , pid + 4, 0 , 0 , 2 , {2});
1381 InsertVp9Flex(sn + 8 , kF, kT , kT , kF , pid + 5, 1 , 0 , 2 , {1});
1382 InsertVp9Flex(sn + 9 , kF, kT , kT , kF , pid + 6, 0 , 0 , 3 , {2});
1383 InsertVp9Flex(sn + 11, kF, kT , kT , kF , pid + 7, 1 , 0 , 3 , {1});
1384 InsertVp9Flex(sn + 10, kF, kT , kT , kF , pid + 6, 1 , 0 , 3 , {1});
1385 InsertVp9Flex(sn + 13, kF, kT , kT , kF , pid + 8, 1 , 0 , 4 , {1});
1386 InsertVp9Flex(sn + 12, kF, kT , kT , kF , pid + 8, 0 , 0 , 4 , {2});
1387
1388 ASSERT_EQ(14UL, frames_from_callback_.size());
1389 CheckReferencesVp9(pid , 0);
1390 CheckReferencesVp9(pid , 1);
1391 CheckReferencesVp9(pid + 1, 1, pid);
1392 CheckReferencesVp9(pid + 2, 0, pid);
1393 CheckReferencesVp9(pid + 2, 1, pid + 1);
1394 CheckReferencesVp9(pid + 3, 1, pid + 2);
1395 CheckReferencesVp9(pid + 4, 0, pid + 2);
1396 CheckReferencesVp9(pid + 4, 1, pid + 3);
1397 CheckReferencesVp9(pid + 5, 1, pid + 4);
1398 CheckReferencesVp9(pid + 6, 0, pid + 4);
1399 CheckReferencesVp9(pid + 6, 1, pid + 5);
1400 CheckReferencesVp9(pid + 7, 1, pid + 6);
1401 CheckReferencesVp9(pid + 8, 0, pid + 6);
1402 CheckReferencesVp9(pid + 8, 1, pid + 7);
philipelc707ab72016-04-01 02:01:54 -07001403}
1404
1405} // namespace video_coding
1406} // namespace webrtc