blob: 88f841048c013f25904efb21877b49fe1f94fd34 [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.");
kwiberg5b9746e2017-08-16 04:52:35 -0700156 std::array<uint16_t, sizeof...(refs)> references = {
157 {rtc::checked_cast<uint16_t>(refs)...}};
philipelbe7a9e52016-05-19 12:19:35 +0200158
philipelb4d31082016-07-11 08:46:29 -0700159 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
philipelbe7a9e52016-05-19 12:19:35 +0200160 frame->picture_id = picture_id;
161 frame->spatial_layer = spatial_layer;
162 frame->timestamp = ts_ms * 90;
163 frame->num_references = references.size();
164 frame->inter_layer_predicted = inter_layer_predicted;
165 for (size_t r = 0; r < references.size(); ++r)
166 frame->references[r] = references[r];
167
philipele0b2f152016-09-28 10:23:49 +0200168 return buffer_.InsertFrame(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200169 }
170
philipel628ac592017-08-11 03:41:44 -0700171 void ExtractFrame(int64_t max_wait_time = 0, bool keyframe_required = false) {
philipelbe7a9e52016-05-19 12:19:35 +0200172 crit_.Enter();
173 if (max_wait_time == 0) {
philipel75562822016-09-05 10:57:41 +0200174 std::unique_ptr<FrameObject> frame;
philipel628ac592017-08-11 03:41:44 -0700175 FrameBuffer::ReturnReason res =
176 buffer_.NextFrame(0, &frame, keyframe_required);
philipel75562822016-09-05 10:57:41 +0200177 if (res != FrameBuffer::ReturnReason::kStopped)
178 frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200179 crit_.Leave();
180 } else {
181 max_wait_time_ = max_wait_time;
182 trigger_extract_event_.Set();
183 crit_.Leave();
184 // Make sure |crit_| is aquired by |extract_thread_| before returning.
185 crit_acquired_event_.Wait(rtc::Event::kForever);
186 }
187 }
188
189 void CheckFrame(size_t index, int picture_id, int spatial_layer) {
190 rtc::CritScope lock(&crit_);
191 ASSERT_LT(index, frames_.size());
192 ASSERT_TRUE(frames_[index]);
193 ASSERT_EQ(picture_id, frames_[index]->picture_id);
194 ASSERT_EQ(spatial_layer, frames_[index]->spatial_layer);
195 }
196
197 void CheckNoFrame(size_t index) {
198 rtc::CritScope lock(&crit_);
199 ASSERT_LT(index, frames_.size());
200 ASSERT_FALSE(frames_[index]);
201 }
202
tommi0f8b4032017-02-22 11:22:05 -0800203 static void ExtractLoop(void* obj) {
philipelbe7a9e52016-05-19 12:19:35 +0200204 TestFrameBuffer2* tfb = static_cast<TestFrameBuffer2*>(obj);
205 while (true) {
206 tfb->trigger_extract_event_.Wait(rtc::Event::kForever);
207 {
208 rtc::CritScope lock(&tfb->crit_);
209 tfb->crit_acquired_event_.Set();
210 if (tfb->tear_down_)
tommi0f8b4032017-02-22 11:22:05 -0800211 return;
philipelbe7a9e52016-05-19 12:19:35 +0200212
philipel75562822016-09-05 10:57:41 +0200213 std::unique_ptr<FrameObject> frame;
214 FrameBuffer::ReturnReason res =
215 tfb->buffer_.NextFrame(tfb->max_wait_time_, &frame);
216 if (res != FrameBuffer::ReturnReason::kStopped)
217 tfb->frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200218 }
219 }
220 }
221
222 uint32_t Rand() { return rand_.Rand<uint32_t>(); }
223
224 SimulatedClock clock_;
225 VCMTimingFake timing_;
philipel4f6cd6a2016-08-03 10:59:32 +0200226 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_;
philipelbe7a9e52016-05-19 12:19:35 +0200227 FrameBuffer buffer_;
228 std::vector<std::unique_ptr<FrameObject>> frames_;
229 Random rand_;
philipela45102f2017-02-22 05:30:39 -0800230 ::testing::NiceMock<VCMReceiveStatisticsCallbackMock> stats_callback_;
philipelbe7a9e52016-05-19 12:19:35 +0200231
232 int64_t max_wait_time_;
233 bool tear_down_;
234 rtc::PlatformThread extract_thread_;
235 rtc::Event trigger_extract_event_;
236 rtc::Event crit_acquired_event_;
237 rtc::CriticalSection crit_;
238};
239
philipel6e8224f2016-05-19 17:07:44 +0200240// Following tests are timing dependent. Either the timeouts have to
241// be increased by a large margin, which would slow down all trybots,
242// or we disable them for the very slow ones, like we do here.
243#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER)
philipelbe7a9e52016-05-19 12:19:35 +0200244TEST_F(TestFrameBuffer2, WaitForFrame) {
245 uint16_t pid = Rand();
246 uint32_t ts = Rand();
247
philipel6e8224f2016-05-19 17:07:44 +0200248 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200249 InsertFrame(pid, 0, ts, false);
250 CheckFrame(0, pid, 0);
251}
252
253TEST_F(TestFrameBuffer2, OneSuperFrame) {
254 uint16_t pid = Rand();
255 uint32_t ts = Rand();
256
philipele0b2f152016-09-28 10:23:49 +0200257 InsertFrame(pid, 0, ts, false);
258 ExtractFrame();
259 InsertFrame(pid, 1, ts, true);
260 ExtractFrame();
261
262 CheckFrame(0, pid, 0);
263 CheckFrame(1, pid, 1);
264}
265
gnishb2a318b2017-05-10 09:21:33 -0700266TEST_F(TestFrameBuffer2, SetPlayoutDelay) {
267 const PlayoutDelay kPlayoutDelayMs = {123, 321};
268 std::unique_ptr<FrameObjectFake> test_frame(new FrameObjectFake());
269 test_frame->SetPlayoutDelay(kPlayoutDelayMs);
270 buffer_.InsertFrame(std::move(test_frame));
271 EXPECT_EQ(kPlayoutDelayMs.min_ms, timing_.min_playout_delay());
272 EXPECT_EQ(kPlayoutDelayMs.max_ms, timing_.max_playout_delay());
273}
274
aleloi3e005282017-01-26 05:38:00 -0800275// Flaky test, see bugs.webrtc.org/7068.
276TEST_F(TestFrameBuffer2, DISABLED_OneUnorderedSuperFrame) {
philipele0b2f152016-09-28 10:23:49 +0200277 uint16_t pid = Rand();
278 uint32_t ts = Rand();
279
philipel6e8224f2016-05-19 17:07:44 +0200280 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200281 InsertFrame(pid, 1, ts, true);
282 InsertFrame(pid, 0, ts, false);
283 ExtractFrame();
284
285 CheckFrame(0, pid, 0);
286 CheckFrame(1, pid, 1);
287}
288
philipel94616b32016-05-20 10:43:01 +0200289TEST_F(TestFrameBuffer2, DISABLED_OneLayerStreamReordered) {
philipel6e8224f2016-05-19 17:07:44 +0200290 uint16_t pid = Rand();
291 uint32_t ts = Rand();
292
293 InsertFrame(pid, 0, ts, false);
294 ExtractFrame();
295 CheckFrame(0, pid, 0);
296 for (int i = 1; i < 10; i += 2) {
297 ExtractFrame(50);
298 InsertFrame(pid + i + 1, 0, ts + (i + 1) * kFps10, false, pid + i);
299 clock_.AdvanceTimeMilliseconds(kFps10);
300 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
301 clock_.AdvanceTimeMilliseconds(kFps10);
302 ExtractFrame();
303 CheckFrame(i, pid + i, 0);
304 CheckFrame(i + 1, pid + i + 1, 0);
305 }
306}
307#endif // Timing dependent tests.
308
309TEST_F(TestFrameBuffer2, ExtractFromEmptyBuffer) {
310 ExtractFrame();
311 CheckNoFrame(0);
312}
313
philipel93e451b2016-10-06 12:25:13 +0200314TEST_F(TestFrameBuffer2, MissingFrame) {
315 uint16_t pid = Rand();
316 uint32_t ts = Rand();
317
318 InsertFrame(pid, 0, ts, false);
319 InsertFrame(pid + 2, 0, ts, false, pid);
320 InsertFrame(pid + 3, 0, ts, false, pid + 1, pid + 2);
321 ExtractFrame();
322 ExtractFrame();
323 ExtractFrame();
324
325 CheckFrame(0, pid, 0);
326 CheckFrame(1, pid + 2, 0);
327 CheckNoFrame(2);
328}
329
philipelbe7a9e52016-05-19 12:19:35 +0200330TEST_F(TestFrameBuffer2, OneLayerStream) {
331 uint16_t pid = Rand();
332 uint32_t ts = Rand();
333
334 InsertFrame(pid, 0, ts, false);
335 ExtractFrame();
336 CheckFrame(0, pid, 0);
337 for (int i = 1; i < 10; ++i) {
338 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
339 ExtractFrame();
340 clock_.AdvanceTimeMilliseconds(kFps10);
341 CheckFrame(i, pid + i, 0);
342 }
343}
344
philipelbe7a9e52016-05-19 12:19:35 +0200345TEST_F(TestFrameBuffer2, DropTemporalLayerSlowDecoder) {
346 uint16_t pid = Rand();
347 uint32_t ts = Rand();
348
349 InsertFrame(pid, 0, ts, false);
philipelfd5a20f2016-11-15 00:57:57 -0800350 InsertFrame(pid + 1, 0, ts + kFps20, false, pid);
philipelbe7a9e52016-05-19 12:19:35 +0200351 for (int i = 2; i < 10; i += 2) {
352 uint32_t ts_tl0 = ts + i / 2 * kFps10;
353 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 2);
354 InsertFrame(pid + i + 1, 0, ts_tl0 + kFps20, false, pid + i, pid + i - 1);
355 }
356
357 for (int i = 0; i < 10; ++i) {
358 ExtractFrame();
359 clock_.AdvanceTimeMilliseconds(60);
360 }
361
362 CheckFrame(0, pid, 0);
363 CheckFrame(1, pid + 1, 0);
364 CheckFrame(2, pid + 2, 0);
365 CheckFrame(3, pid + 4, 0);
366 CheckFrame(4, pid + 6, 0);
367 CheckFrame(5, pid + 8, 0);
368 CheckNoFrame(6);
369 CheckNoFrame(7);
370 CheckNoFrame(8);
371 CheckNoFrame(9);
372}
373
374TEST_F(TestFrameBuffer2, DropSpatialLayerSlowDecoder) {
375 uint16_t pid = Rand();
376 uint32_t ts = Rand();
377
378 InsertFrame(pid, 0, ts, false);
379 InsertFrame(pid, 1, ts, false);
380 for (int i = 1; i < 6; ++i) {
381 uint32_t ts_tl0 = ts + i * kFps10;
382 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 1);
383 InsertFrame(pid + i, 1, ts_tl0, false, pid + i - 1);
384 }
385
386 ExtractFrame();
387 ExtractFrame();
388 clock_.AdvanceTimeMilliseconds(55);
389 for (int i = 2; i < 12; ++i) {
390 ExtractFrame();
391 clock_.AdvanceTimeMilliseconds(55);
392 }
393
394 CheckFrame(0, pid, 0);
395 CheckFrame(1, pid, 1);
396 CheckFrame(2, pid + 1, 0);
397 CheckFrame(3, pid + 1, 1);
398 CheckFrame(4, pid + 2, 0);
399 CheckFrame(5, pid + 2, 1);
400 CheckFrame(6, pid + 3, 0);
401 CheckFrame(7, pid + 4, 0);
402 CheckFrame(8, pid + 5, 0);
403 CheckNoFrame(9);
404 CheckNoFrame(10);
405 CheckNoFrame(11);
406}
407
408TEST_F(TestFrameBuffer2, InsertLateFrame) {
409 uint16_t pid = Rand();
410 uint32_t ts = Rand();
411
412 InsertFrame(pid, 0, ts, false);
413 ExtractFrame();
414 InsertFrame(pid + 2, 0, ts, false);
415 ExtractFrame();
416 InsertFrame(pid + 1, 0, ts, false, pid);
417 ExtractFrame();
418
419 CheckFrame(0, pid, 0);
420 CheckFrame(1, pid + 2, 0);
421 CheckNoFrame(2);
422}
423
philipel4f6cd6a2016-08-03 10:59:32 +0200424TEST_F(TestFrameBuffer2, ProtectionMode) {
425 uint16_t pid = Rand();
426 uint32_t ts = Rand();
427
428 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(1.0));
429 InsertFrame(pid, 0, ts, false);
430 ExtractFrame();
431
432 buffer_.SetProtectionMode(kProtectionNackFEC);
433 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(0.0));
434 InsertFrame(pid + 1, 0, ts, false);
435 ExtractFrame();
436}
437
philipele0b2f152016-09-28 10:23:49 +0200438TEST_F(TestFrameBuffer2, NoContinuousFrame) {
439 uint16_t pid = Rand();
440 uint32_t ts = Rand();
441
442 EXPECT_EQ(-1, InsertFrame(pid + 1, 0, ts, false, pid));
443}
444
445TEST_F(TestFrameBuffer2, LastContinuousFrameSingleLayer) {
446 uint16_t pid = Rand();
447 uint32_t ts = Rand();
448
449 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
450 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
451 EXPECT_EQ(pid + 2, InsertFrame(pid + 1, 0, ts, false, pid));
452 EXPECT_EQ(pid + 2, InsertFrame(pid + 4, 0, ts, false, pid + 3));
453 EXPECT_EQ(pid + 5, InsertFrame(pid + 5, 0, ts, false));
454}
455
456TEST_F(TestFrameBuffer2, LastContinuousFrameTwoLayers) {
457 uint16_t pid = Rand();
458 uint32_t ts = Rand();
459
460 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
461 EXPECT_EQ(pid, InsertFrame(pid, 1, ts, true));
462 EXPECT_EQ(pid, InsertFrame(pid + 1, 1, ts, true, pid));
463 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
464 EXPECT_EQ(pid, InsertFrame(pid + 2, 1, ts, true, pid + 1));
465 EXPECT_EQ(pid, InsertFrame(pid + 3, 0, ts, false, pid + 2));
466 EXPECT_EQ(pid + 3, InsertFrame(pid + 1, 0, ts, false, pid));
467 EXPECT_EQ(pid + 3, InsertFrame(pid + 3, 1, ts, true, pid + 2));
468}
469
philipelfcc60062017-01-18 05:35:20 -0800470TEST_F(TestFrameBuffer2, PictureIdJumpBack) {
471 uint16_t pid = Rand();
472 uint32_t ts = Rand();
473
474 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
475 EXPECT_EQ(pid + 1, InsertFrame(pid + 1, 0, ts + 1, false, pid));
476 ExtractFrame();
477 CheckFrame(0, pid, 0);
478
479 // Jump back in pid but increase ts.
480 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false));
481 ExtractFrame();
482 ExtractFrame();
483 CheckFrame(1, pid - 1, 0);
484 CheckNoFrame(2);
485}
486
philipela45102f2017-02-22 05:30:39 -0800487TEST_F(TestFrameBuffer2, StatsCallback) {
488 uint16_t pid = Rand();
489 uint32_t ts = Rand();
490 const int kFrameSize = 5000;
491
492 EXPECT_CALL(stats_callback_, OnCompleteFrame(true, kFrameSize));
493 EXPECT_CALL(stats_callback_,
494 OnFrameBufferTimingsUpdated(_, _, _, _, _, _, _));
495
496 {
497 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
498 frame->SetSize(kFrameSize);
499 frame->picture_id = pid;
500 frame->spatial_layer = 0;
501 frame->timestamp = ts;
502 frame->num_references = 0;
503 frame->inter_layer_predicted = false;
504
505 EXPECT_EQ(buffer_.InsertFrame(std::move(frame)), pid);
506 }
507
508 ExtractFrame();
509 CheckFrame(0, pid, 0);
510}
511
philipel146a48b2017-04-20 04:04:38 -0700512TEST_F(TestFrameBuffer2, ForwardJumps) {
513 EXPECT_EQ(5453, InsertFrame(5453, 0, 1, false));
514 ExtractFrame();
515 EXPECT_EQ(5454, InsertFrame(5454, 0, 1, false, 5453));
516 ExtractFrame();
517 EXPECT_EQ(15670, InsertFrame(15670, 0, 1, false));
518 ExtractFrame();
519 EXPECT_EQ(29804, InsertFrame(29804, 0, 1, false));
520 ExtractFrame();
521 EXPECT_EQ(29805, InsertFrame(29805, 0, 1, false, 29804));
522 ExtractFrame();
523 EXPECT_EQ(29806, InsertFrame(29806, 0, 1, false, 29805));
524 ExtractFrame();
525 EXPECT_EQ(33819, InsertFrame(33819, 0, 1, false));
526 ExtractFrame();
527 EXPECT_EQ(41248, InsertFrame(41248, 0, 1, false));
528 ExtractFrame();
529}
530
philipelf6842692017-04-28 03:29:15 -0700531TEST_F(TestFrameBuffer2, DuplicateFrames) {
532 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
533 ExtractFrame();
534 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
535}
536
philipel112adf92017-06-15 09:06:21 -0700537// TODO(philipel): implement more unittests related to invalid references.
538TEST_F(TestFrameBuffer2, InvalidReferences) {
539 EXPECT_EQ(-1, InsertFrame(0, 0, 1000, false, 2));
540 EXPECT_EQ(1, InsertFrame(1, 0, 2000, false));
541 ExtractFrame();
542 EXPECT_EQ(2, InsertFrame(2, 0, 3000, false, 1));
543}
544
philipel628ac592017-08-11 03:41:44 -0700545TEST_F(TestFrameBuffer2, KeyframeRequired) {
546 EXPECT_EQ(1, InsertFrame(1, 0, 1000, false));
547 EXPECT_EQ(2, InsertFrame(2, 0, 2000, false, 1));
548 EXPECT_EQ(3, InsertFrame(3, 0, 3000, false));
549 ExtractFrame();
550 ExtractFrame(0, true);
551 ExtractFrame();
552
553 CheckFrame(0, 1, 0);
554 CheckFrame(1, 3, 0);
555 CheckNoFrame(2);
556}
557
philipelbe7a9e52016-05-19 12:19:35 +0200558} // namespace video_coding
559} // namespace webrtc