blob: 95a879b36d554fe8586447769e00c5fe77174558 [file] [log] [blame]
philipelbe7a9e52016-05-19 12:19:35 +02001/*
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 "webrtc/modules/video_coding/frame_buffer2.h"
12
13#include <algorithm>
14#include <cstring>
15#include <limits>
16#include <vector>
17
philipelbe7a9e52016-05-19 12:19:35 +020018#include "webrtc/modules/video_coding/frame_object.h"
19#include "webrtc/modules/video_coding/jitter_estimator.h"
20#include "webrtc/modules/video_coding/sequence_number_util.h"
21#include "webrtc/modules/video_coding/timing.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020022#include "webrtc/rtc_base/platform_thread.h"
23#include "webrtc/rtc_base/random.h"
philipelbe7a9e52016-05-19 12:19:35 +020024#include "webrtc/system_wrappers/include/clock.h"
kwibergac9f8762016-09-30 22:29:43 -070025#include "webrtc/test/gmock.h"
26#include "webrtc/test/gtest.h"
philipelbe7a9e52016-05-19 12:19:35 +020027
philipela45102f2017-02-22 05:30:39 -080028using testing::_;
29using testing::Return;
30
philipelbe7a9e52016-05-19 12:19:35 +020031namespace webrtc {
32namespace video_coding {
33
34class VCMTimingFake : public VCMTiming {
35 public:
36 explicit VCMTimingFake(Clock* clock) : VCMTiming(clock) {}
37
38 int64_t RenderTimeMs(uint32_t frame_timestamp,
39 int64_t now_ms) const override {
40 if (last_ms_ == -1) {
41 last_ms_ = now_ms + kDelayMs;
42 last_timestamp_ = frame_timestamp;
43 }
44
45 uint32_t diff = MinDiff(frame_timestamp, last_timestamp_);
46 if (AheadOf(frame_timestamp, last_timestamp_))
47 last_ms_ += diff / 90;
48 else
49 last_ms_ -= diff / 90;
50
51 last_timestamp_ = frame_timestamp;
52 return last_ms_;
53 }
54
55 uint32_t MaxWaitingTime(int64_t render_time_ms,
56 int64_t now_ms) const override {
57 return std::max<int>(0, render_time_ms - now_ms - kDecodeTime);
58 }
59
philipela45102f2017-02-22 05:30:39 -080060 bool GetTimings(int* decode_ms,
61 int* max_decode_ms,
62 int* current_delay_ms,
63 int* target_delay_ms,
64 int* jitter_buffer_ms,
65 int* min_playout_delay_ms,
66 int* render_delay_ms) const override {
67 return true;
68 }
69
philipelbe7a9e52016-05-19 12:19:35 +020070 private:
71 static constexpr int kDelayMs = 50;
72 static constexpr int kDecodeTime = kDelayMs / 2;
73 mutable uint32_t last_timestamp_ = 0;
74 mutable int64_t last_ms_ = -1;
75};
76
77class VCMJitterEstimatorMock : public VCMJitterEstimator {
78 public:
79 explicit VCMJitterEstimatorMock(Clock* clock) : VCMJitterEstimator(clock) {}
80
81 MOCK_METHOD1(UpdateRtt, void(int64_t rttMs));
82 MOCK_METHOD3(UpdateEstimate,
83 void(int64_t frameDelayMs,
84 uint32_t frameSizeBytes,
85 bool incompleteFrame));
philipel4f6cd6a2016-08-03 10:59:32 +020086 MOCK_METHOD1(GetJitterEstimate, int(double rttMultiplier));
philipelbe7a9e52016-05-19 12:19:35 +020087};
88
philipelb4d31082016-07-11 08:46:29 -070089class FrameObjectFake : public FrameObject {
philipelbe7a9e52016-05-19 12:19:35 +020090 public:
philipelb4d31082016-07-11 08:46:29 -070091 bool GetBitstream(uint8_t* destination) const override { return true; }
92
93 uint32_t Timestamp() const override { return timestamp; }
94
95 int64_t ReceivedTime() const override { return 0; }
96
97 int64_t RenderTime() const override { return _renderTimeMs; }
philipela45102f2017-02-22 05:30:39 -080098
99 // In EncodedImage |_length| is used to descibe its size and |_size| to
100 // describe its capacity.
101 void SetSize(int size) { _length = size; }
102};
103
104class VCMReceiveStatisticsCallbackMock : public VCMReceiveStatisticsCallback {
105 public:
106 MOCK_METHOD2(OnReceiveRatesUpdated,
107 void(uint32_t bitRate, uint32_t frameRate));
108 MOCK_METHOD2(OnCompleteFrame, void(bool is_keyframe, size_t size_bytes));
109 MOCK_METHOD1(OnDiscardedPacketsUpdated, void(int discarded_packets));
110 MOCK_METHOD1(OnFrameCountsUpdated, void(const FrameCounts& frame_counts));
111 MOCK_METHOD7(OnFrameBufferTimingsUpdated,
112 void(int decode_ms,
113 int max_decode_ms,
114 int current_delay_ms,
115 int target_delay_ms,
116 int jitter_buffer_ms,
117 int min_playout_delay_ms,
118 int render_delay_ms));
ilnik2edc6842017-07-06 03:06:50 -0700119 MOCK_METHOD1(OnTimingFrameInfoUpdated, void(const TimingFrameInfo& info));
philipelbe7a9e52016-05-19 12:19:35 +0200120};
121
122class TestFrameBuffer2 : public ::testing::Test {
123 protected:
124 static constexpr int kMaxReferences = 5;
125 static constexpr int kFps1 = 1000;
126 static constexpr int kFps10 = kFps1 / 10;
127 static constexpr int kFps20 = kFps1 / 20;
128
129 TestFrameBuffer2()
130 : clock_(0),
131 timing_(&clock_),
132 jitter_estimator_(&clock_),
philipela45102f2017-02-22 05:30:39 -0800133 buffer_(&clock_, &jitter_estimator_, &timing_, &stats_callback_),
philipelbe7a9e52016-05-19 12:19:35 +0200134 rand_(0x34678213),
135 tear_down_(false),
136 extract_thread_(&ExtractLoop, this, "Extract Thread"),
137 trigger_extract_event_(false, false),
138 crit_acquired_event_(false, false) {}
139
140 void SetUp() override { extract_thread_.Start(); }
141
142 void TearDown() override {
143 tear_down_ = true;
144 trigger_extract_event_.Set();
145 extract_thread_.Stop();
146 }
147
148 template <typename... T>
philipele0b2f152016-09-28 10:23:49 +0200149 int InsertFrame(uint16_t picture_id,
150 uint8_t spatial_layer,
151 int64_t ts_ms,
152 bool inter_layer_predicted,
153 T... refs) {
philipelbe7a9e52016-05-19 12:19:35 +0200154 static_assert(sizeof...(refs) <= kMaxReferences,
155 "To many references specified for FrameObject.");
156 std::array<uint16_t, sizeof...(refs)> references = {{refs...}};
157
philipelb4d31082016-07-11 08:46:29 -0700158 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
philipelbe7a9e52016-05-19 12:19:35 +0200159 frame->picture_id = picture_id;
160 frame->spatial_layer = spatial_layer;
161 frame->timestamp = ts_ms * 90;
162 frame->num_references = references.size();
163 frame->inter_layer_predicted = inter_layer_predicted;
164 for (size_t r = 0; r < references.size(); ++r)
165 frame->references[r] = references[r];
166
philipele0b2f152016-09-28 10:23:49 +0200167 return buffer_.InsertFrame(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200168 }
169
philipel628ac592017-08-11 03:41:44 -0700170 void ExtractFrame(int64_t max_wait_time = 0, bool keyframe_required = false) {
philipelbe7a9e52016-05-19 12:19:35 +0200171 crit_.Enter();
172 if (max_wait_time == 0) {
philipel75562822016-09-05 10:57:41 +0200173 std::unique_ptr<FrameObject> frame;
philipel628ac592017-08-11 03:41:44 -0700174 FrameBuffer::ReturnReason res =
175 buffer_.NextFrame(0, &frame, keyframe_required);
philipel75562822016-09-05 10:57:41 +0200176 if (res != FrameBuffer::ReturnReason::kStopped)
177 frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200178 crit_.Leave();
179 } else {
180 max_wait_time_ = max_wait_time;
181 trigger_extract_event_.Set();
182 crit_.Leave();
183 // Make sure |crit_| is aquired by |extract_thread_| before returning.
184 crit_acquired_event_.Wait(rtc::Event::kForever);
185 }
186 }
187
188 void CheckFrame(size_t index, int picture_id, int spatial_layer) {
189 rtc::CritScope lock(&crit_);
190 ASSERT_LT(index, frames_.size());
191 ASSERT_TRUE(frames_[index]);
192 ASSERT_EQ(picture_id, frames_[index]->picture_id);
193 ASSERT_EQ(spatial_layer, frames_[index]->spatial_layer);
194 }
195
196 void CheckNoFrame(size_t index) {
197 rtc::CritScope lock(&crit_);
198 ASSERT_LT(index, frames_.size());
199 ASSERT_FALSE(frames_[index]);
200 }
201
tommi0f8b4032017-02-22 11:22:05 -0800202 static void ExtractLoop(void* obj) {
philipelbe7a9e52016-05-19 12:19:35 +0200203 TestFrameBuffer2* tfb = static_cast<TestFrameBuffer2*>(obj);
204 while (true) {
205 tfb->trigger_extract_event_.Wait(rtc::Event::kForever);
206 {
207 rtc::CritScope lock(&tfb->crit_);
208 tfb->crit_acquired_event_.Set();
209 if (tfb->tear_down_)
tommi0f8b4032017-02-22 11:22:05 -0800210 return;
philipelbe7a9e52016-05-19 12:19:35 +0200211
philipel75562822016-09-05 10:57:41 +0200212 std::unique_ptr<FrameObject> frame;
213 FrameBuffer::ReturnReason res =
214 tfb->buffer_.NextFrame(tfb->max_wait_time_, &frame);
215 if (res != FrameBuffer::ReturnReason::kStopped)
216 tfb->frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200217 }
218 }
219 }
220
221 uint32_t Rand() { return rand_.Rand<uint32_t>(); }
222
223 SimulatedClock clock_;
224 VCMTimingFake timing_;
philipel4f6cd6a2016-08-03 10:59:32 +0200225 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_;
philipelbe7a9e52016-05-19 12:19:35 +0200226 FrameBuffer buffer_;
227 std::vector<std::unique_ptr<FrameObject>> frames_;
228 Random rand_;
philipela45102f2017-02-22 05:30:39 -0800229 ::testing::NiceMock<VCMReceiveStatisticsCallbackMock> stats_callback_;
philipelbe7a9e52016-05-19 12:19:35 +0200230
231 int64_t max_wait_time_;
232 bool tear_down_;
233 rtc::PlatformThread extract_thread_;
234 rtc::Event trigger_extract_event_;
235 rtc::Event crit_acquired_event_;
236 rtc::CriticalSection crit_;
237};
238
philipel6e8224f2016-05-19 17:07:44 +0200239// Following tests are timing dependent. Either the timeouts have to
240// be increased by a large margin, which would slow down all trybots,
241// or we disable them for the very slow ones, like we do here.
242#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER)
philipelbe7a9e52016-05-19 12:19:35 +0200243TEST_F(TestFrameBuffer2, WaitForFrame) {
244 uint16_t pid = Rand();
245 uint32_t ts = Rand();
246
philipel6e8224f2016-05-19 17:07:44 +0200247 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200248 InsertFrame(pid, 0, ts, false);
249 CheckFrame(0, pid, 0);
250}
251
252TEST_F(TestFrameBuffer2, OneSuperFrame) {
253 uint16_t pid = Rand();
254 uint32_t ts = Rand();
255
philipele0b2f152016-09-28 10:23:49 +0200256 InsertFrame(pid, 0, ts, false);
257 ExtractFrame();
258 InsertFrame(pid, 1, ts, true);
259 ExtractFrame();
260
261 CheckFrame(0, pid, 0);
262 CheckFrame(1, pid, 1);
263}
264
gnishb2a318b2017-05-10 09:21:33 -0700265TEST_F(TestFrameBuffer2, SetPlayoutDelay) {
266 const PlayoutDelay kPlayoutDelayMs = {123, 321};
267 std::unique_ptr<FrameObjectFake> test_frame(new FrameObjectFake());
268 test_frame->SetPlayoutDelay(kPlayoutDelayMs);
269 buffer_.InsertFrame(std::move(test_frame));
270 EXPECT_EQ(kPlayoutDelayMs.min_ms, timing_.min_playout_delay());
271 EXPECT_EQ(kPlayoutDelayMs.max_ms, timing_.max_playout_delay());
272}
273
aleloi3e005282017-01-26 05:38:00 -0800274// Flaky test, see bugs.webrtc.org/7068.
275TEST_F(TestFrameBuffer2, DISABLED_OneUnorderedSuperFrame) {
philipele0b2f152016-09-28 10:23:49 +0200276 uint16_t pid = Rand();
277 uint32_t ts = Rand();
278
philipel6e8224f2016-05-19 17:07:44 +0200279 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200280 InsertFrame(pid, 1, ts, true);
281 InsertFrame(pid, 0, ts, false);
282 ExtractFrame();
283
284 CheckFrame(0, pid, 0);
285 CheckFrame(1, pid, 1);
286}
287
philipel94616b32016-05-20 10:43:01 +0200288TEST_F(TestFrameBuffer2, DISABLED_OneLayerStreamReordered) {
philipel6e8224f2016-05-19 17:07:44 +0200289 uint16_t pid = Rand();
290 uint32_t ts = Rand();
291
292 InsertFrame(pid, 0, ts, false);
293 ExtractFrame();
294 CheckFrame(0, pid, 0);
295 for (int i = 1; i < 10; i += 2) {
296 ExtractFrame(50);
297 InsertFrame(pid + i + 1, 0, ts + (i + 1) * kFps10, false, pid + i);
298 clock_.AdvanceTimeMilliseconds(kFps10);
299 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
300 clock_.AdvanceTimeMilliseconds(kFps10);
301 ExtractFrame();
302 CheckFrame(i, pid + i, 0);
303 CheckFrame(i + 1, pid + i + 1, 0);
304 }
305}
306#endif // Timing dependent tests.
307
308TEST_F(TestFrameBuffer2, ExtractFromEmptyBuffer) {
309 ExtractFrame();
310 CheckNoFrame(0);
311}
312
philipel93e451b2016-10-06 12:25:13 +0200313TEST_F(TestFrameBuffer2, MissingFrame) {
314 uint16_t pid = Rand();
315 uint32_t ts = Rand();
316
317 InsertFrame(pid, 0, ts, false);
318 InsertFrame(pid + 2, 0, ts, false, pid);
319 InsertFrame(pid + 3, 0, ts, false, pid + 1, pid + 2);
320 ExtractFrame();
321 ExtractFrame();
322 ExtractFrame();
323
324 CheckFrame(0, pid, 0);
325 CheckFrame(1, pid + 2, 0);
326 CheckNoFrame(2);
327}
328
philipelbe7a9e52016-05-19 12:19:35 +0200329TEST_F(TestFrameBuffer2, OneLayerStream) {
330 uint16_t pid = Rand();
331 uint32_t ts = Rand();
332
333 InsertFrame(pid, 0, ts, false);
334 ExtractFrame();
335 CheckFrame(0, pid, 0);
336 for (int i = 1; i < 10; ++i) {
337 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
338 ExtractFrame();
339 clock_.AdvanceTimeMilliseconds(kFps10);
340 CheckFrame(i, pid + i, 0);
341 }
342}
343
philipelbe7a9e52016-05-19 12:19:35 +0200344TEST_F(TestFrameBuffer2, DropTemporalLayerSlowDecoder) {
345 uint16_t pid = Rand();
346 uint32_t ts = Rand();
347
348 InsertFrame(pid, 0, ts, false);
philipelfd5a20f2016-11-15 00:57:57 -0800349 InsertFrame(pid + 1, 0, ts + kFps20, false, pid);
philipelbe7a9e52016-05-19 12:19:35 +0200350 for (int i = 2; i < 10; i += 2) {
351 uint32_t ts_tl0 = ts + i / 2 * kFps10;
352 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 2);
353 InsertFrame(pid + i + 1, 0, ts_tl0 + kFps20, false, pid + i, pid + i - 1);
354 }
355
356 for (int i = 0; i < 10; ++i) {
357 ExtractFrame();
358 clock_.AdvanceTimeMilliseconds(60);
359 }
360
361 CheckFrame(0, pid, 0);
362 CheckFrame(1, pid + 1, 0);
363 CheckFrame(2, pid + 2, 0);
364 CheckFrame(3, pid + 4, 0);
365 CheckFrame(4, pid + 6, 0);
366 CheckFrame(5, pid + 8, 0);
367 CheckNoFrame(6);
368 CheckNoFrame(7);
369 CheckNoFrame(8);
370 CheckNoFrame(9);
371}
372
373TEST_F(TestFrameBuffer2, DropSpatialLayerSlowDecoder) {
374 uint16_t pid = Rand();
375 uint32_t ts = Rand();
376
377 InsertFrame(pid, 0, ts, false);
378 InsertFrame(pid, 1, ts, false);
379 for (int i = 1; i < 6; ++i) {
380 uint32_t ts_tl0 = ts + i * kFps10;
381 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 1);
382 InsertFrame(pid + i, 1, ts_tl0, false, pid + i - 1);
383 }
384
385 ExtractFrame();
386 ExtractFrame();
387 clock_.AdvanceTimeMilliseconds(55);
388 for (int i = 2; i < 12; ++i) {
389 ExtractFrame();
390 clock_.AdvanceTimeMilliseconds(55);
391 }
392
393 CheckFrame(0, pid, 0);
394 CheckFrame(1, pid, 1);
395 CheckFrame(2, pid + 1, 0);
396 CheckFrame(3, pid + 1, 1);
397 CheckFrame(4, pid + 2, 0);
398 CheckFrame(5, pid + 2, 1);
399 CheckFrame(6, pid + 3, 0);
400 CheckFrame(7, pid + 4, 0);
401 CheckFrame(8, pid + 5, 0);
402 CheckNoFrame(9);
403 CheckNoFrame(10);
404 CheckNoFrame(11);
405}
406
407TEST_F(TestFrameBuffer2, InsertLateFrame) {
408 uint16_t pid = Rand();
409 uint32_t ts = Rand();
410
411 InsertFrame(pid, 0, ts, false);
412 ExtractFrame();
413 InsertFrame(pid + 2, 0, ts, false);
414 ExtractFrame();
415 InsertFrame(pid + 1, 0, ts, false, pid);
416 ExtractFrame();
417
418 CheckFrame(0, pid, 0);
419 CheckFrame(1, pid + 2, 0);
420 CheckNoFrame(2);
421}
422
philipel4f6cd6a2016-08-03 10:59:32 +0200423TEST_F(TestFrameBuffer2, ProtectionMode) {
424 uint16_t pid = Rand();
425 uint32_t ts = Rand();
426
427 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(1.0));
428 InsertFrame(pid, 0, ts, false);
429 ExtractFrame();
430
431 buffer_.SetProtectionMode(kProtectionNackFEC);
432 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(0.0));
433 InsertFrame(pid + 1, 0, ts, false);
434 ExtractFrame();
435}
436
philipele0b2f152016-09-28 10:23:49 +0200437TEST_F(TestFrameBuffer2, NoContinuousFrame) {
438 uint16_t pid = Rand();
439 uint32_t ts = Rand();
440
441 EXPECT_EQ(-1, InsertFrame(pid + 1, 0, ts, false, pid));
442}
443
444TEST_F(TestFrameBuffer2, LastContinuousFrameSingleLayer) {
445 uint16_t pid = Rand();
446 uint32_t ts = Rand();
447
448 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
449 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
450 EXPECT_EQ(pid + 2, InsertFrame(pid + 1, 0, ts, false, pid));
451 EXPECT_EQ(pid + 2, InsertFrame(pid + 4, 0, ts, false, pid + 3));
452 EXPECT_EQ(pid + 5, InsertFrame(pid + 5, 0, ts, false));
453}
454
455TEST_F(TestFrameBuffer2, LastContinuousFrameTwoLayers) {
456 uint16_t pid = Rand();
457 uint32_t ts = Rand();
458
459 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
460 EXPECT_EQ(pid, InsertFrame(pid, 1, ts, true));
461 EXPECT_EQ(pid, InsertFrame(pid + 1, 1, ts, true, pid));
462 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
463 EXPECT_EQ(pid, InsertFrame(pid + 2, 1, ts, true, pid + 1));
464 EXPECT_EQ(pid, InsertFrame(pid + 3, 0, ts, false, pid + 2));
465 EXPECT_EQ(pid + 3, InsertFrame(pid + 1, 0, ts, false, pid));
466 EXPECT_EQ(pid + 3, InsertFrame(pid + 3, 1, ts, true, pid + 2));
467}
468
philipelfcc60062017-01-18 05:35:20 -0800469TEST_F(TestFrameBuffer2, PictureIdJumpBack) {
470 uint16_t pid = Rand();
471 uint32_t ts = Rand();
472
473 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
474 EXPECT_EQ(pid + 1, InsertFrame(pid + 1, 0, ts + 1, false, pid));
475 ExtractFrame();
476 CheckFrame(0, pid, 0);
477
478 // Jump back in pid but increase ts.
479 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false));
480 ExtractFrame();
481 ExtractFrame();
482 CheckFrame(1, pid - 1, 0);
483 CheckNoFrame(2);
484}
485
philipela45102f2017-02-22 05:30:39 -0800486TEST_F(TestFrameBuffer2, StatsCallback) {
487 uint16_t pid = Rand();
488 uint32_t ts = Rand();
489 const int kFrameSize = 5000;
490
491 EXPECT_CALL(stats_callback_, OnCompleteFrame(true, kFrameSize));
492 EXPECT_CALL(stats_callback_,
493 OnFrameBufferTimingsUpdated(_, _, _, _, _, _, _));
494
495 {
496 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
497 frame->SetSize(kFrameSize);
498 frame->picture_id = pid;
499 frame->spatial_layer = 0;
500 frame->timestamp = ts;
501 frame->num_references = 0;
502 frame->inter_layer_predicted = false;
503
504 EXPECT_EQ(buffer_.InsertFrame(std::move(frame)), pid);
505 }
506
507 ExtractFrame();
508 CheckFrame(0, pid, 0);
509}
510
philipel146a48b2017-04-20 04:04:38 -0700511TEST_F(TestFrameBuffer2, ForwardJumps) {
512 EXPECT_EQ(5453, InsertFrame(5453, 0, 1, false));
513 ExtractFrame();
514 EXPECT_EQ(5454, InsertFrame(5454, 0, 1, false, 5453));
515 ExtractFrame();
516 EXPECT_EQ(15670, InsertFrame(15670, 0, 1, false));
517 ExtractFrame();
518 EXPECT_EQ(29804, InsertFrame(29804, 0, 1, false));
519 ExtractFrame();
520 EXPECT_EQ(29805, InsertFrame(29805, 0, 1, false, 29804));
521 ExtractFrame();
522 EXPECT_EQ(29806, InsertFrame(29806, 0, 1, false, 29805));
523 ExtractFrame();
524 EXPECT_EQ(33819, InsertFrame(33819, 0, 1, false));
525 ExtractFrame();
526 EXPECT_EQ(41248, InsertFrame(41248, 0, 1, false));
527 ExtractFrame();
528}
529
philipelf6842692017-04-28 03:29:15 -0700530TEST_F(TestFrameBuffer2, DuplicateFrames) {
531 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
532 ExtractFrame();
533 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
534}
535
philipel112adf92017-06-15 09:06:21 -0700536// TODO(philipel): implement more unittests related to invalid references.
537TEST_F(TestFrameBuffer2, InvalidReferences) {
538 EXPECT_EQ(-1, InsertFrame(0, 0, 1000, false, 2));
539 EXPECT_EQ(1, InsertFrame(1, 0, 2000, false));
540 ExtractFrame();
541 EXPECT_EQ(2, InsertFrame(2, 0, 3000, false, 1));
542}
543
philipel628ac592017-08-11 03:41:44 -0700544TEST_F(TestFrameBuffer2, KeyframeRequired) {
545 EXPECT_EQ(1, InsertFrame(1, 0, 1000, false));
546 EXPECT_EQ(2, InsertFrame(2, 0, 2000, false, 1));
547 EXPECT_EQ(3, InsertFrame(3, 0, 3000, false));
548 ExtractFrame();
549 ExtractFrame(0, true);
550 ExtractFrame();
551
552 CheckFrame(0, 1, 0);
553 CheckFrame(1, 3, 0);
554 CheckNoFrame(2);
555}
556
philipelbe7a9e52016-05-19 12:19:35 +0200557} // namespace video_coding
558} // namespace webrtc