blob: 7d792180d4c8c9cbbcb09c5a5725f4e78c0788da [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/frame_buffer2.h"
philipelbe7a9e52016-05-19 12:19:35 +020012
13#include <algorithm>
14#include <cstring>
15#include <limits>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/video_coding/frame_object.h"
19#include "modules/video_coding/jitter_estimator.h"
20#include "modules/video_coding/sequence_number_util.h"
21#include "modules/video_coding/timing.h"
22#include "rtc_base/platform_thread.h"
23#include "rtc_base/random.h"
24#include "system_wrappers/include/clock.h"
25#include "test/gmock.h"
26#include "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));
ilnik6d5b4d62017-08-30 03:32:14 -0700108 MOCK_METHOD3(OnCompleteFrame,
109 void(bool is_keyframe,
110 size_t size_bytes,
111 VideoContentType content_type));
philipela45102f2017-02-22 05:30:39 -0800112 MOCK_METHOD1(OnDiscardedPacketsUpdated, void(int discarded_packets));
113 MOCK_METHOD1(OnFrameCountsUpdated, void(const FrameCounts& frame_counts));
114 MOCK_METHOD7(OnFrameBufferTimingsUpdated,
115 void(int decode_ms,
116 int max_decode_ms,
117 int current_delay_ms,
118 int target_delay_ms,
119 int jitter_buffer_ms,
120 int min_playout_delay_ms,
121 int render_delay_ms));
ilnik2edc6842017-07-06 03:06:50 -0700122 MOCK_METHOD1(OnTimingFrameInfoUpdated, void(const TimingFrameInfo& info));
philipelbe7a9e52016-05-19 12:19:35 +0200123};
124
125class TestFrameBuffer2 : public ::testing::Test {
126 protected:
127 static constexpr int kMaxReferences = 5;
128 static constexpr int kFps1 = 1000;
129 static constexpr int kFps10 = kFps1 / 10;
130 static constexpr int kFps20 = kFps1 / 20;
131
132 TestFrameBuffer2()
133 : clock_(0),
134 timing_(&clock_),
135 jitter_estimator_(&clock_),
philipela45102f2017-02-22 05:30:39 -0800136 buffer_(&clock_, &jitter_estimator_, &timing_, &stats_callback_),
philipelbe7a9e52016-05-19 12:19:35 +0200137 rand_(0x34678213),
138 tear_down_(false),
139 extract_thread_(&ExtractLoop, this, "Extract Thread"),
140 trigger_extract_event_(false, false),
141 crit_acquired_event_(false, false) {}
142
143 void SetUp() override { extract_thread_.Start(); }
144
145 void TearDown() override {
146 tear_down_ = true;
147 trigger_extract_event_.Set();
148 extract_thread_.Stop();
149 }
150
151 template <typename... T>
philipele0b2f152016-09-28 10:23:49 +0200152 int InsertFrame(uint16_t picture_id,
153 uint8_t spatial_layer,
154 int64_t ts_ms,
155 bool inter_layer_predicted,
156 T... refs) {
philipelbe7a9e52016-05-19 12:19:35 +0200157 static_assert(sizeof...(refs) <= kMaxReferences,
158 "To many references specified for FrameObject.");
kwiberg5b9746e2017-08-16 04:52:35 -0700159 std::array<uint16_t, sizeof...(refs)> references = {
160 {rtc::checked_cast<uint16_t>(refs)...}};
philipelbe7a9e52016-05-19 12:19:35 +0200161
philipelb4d31082016-07-11 08:46:29 -0700162 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
philipelbe7a9e52016-05-19 12:19:35 +0200163 frame->picture_id = picture_id;
164 frame->spatial_layer = spatial_layer;
165 frame->timestamp = ts_ms * 90;
166 frame->num_references = references.size();
167 frame->inter_layer_predicted = inter_layer_predicted;
168 for (size_t r = 0; r < references.size(); ++r)
169 frame->references[r] = references[r];
170
philipele0b2f152016-09-28 10:23:49 +0200171 return buffer_.InsertFrame(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200172 }
173
philipel3042c2d2017-08-18 04:55:02 -0700174 void ExtractFrame(int64_t max_wait_time = 0, bool keyframe_required = false) {
philipelbe7a9e52016-05-19 12:19:35 +0200175 crit_.Enter();
176 if (max_wait_time == 0) {
philipel75562822016-09-05 10:57:41 +0200177 std::unique_ptr<FrameObject> frame;
philipel3042c2d2017-08-18 04:55:02 -0700178 FrameBuffer::ReturnReason res =
179 buffer_.NextFrame(0, &frame, keyframe_required);
philipel75562822016-09-05 10:57:41 +0200180 if (res != FrameBuffer::ReturnReason::kStopped)
181 frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200182 crit_.Leave();
183 } else {
184 max_wait_time_ = max_wait_time;
185 trigger_extract_event_.Set();
186 crit_.Leave();
187 // Make sure |crit_| is aquired by |extract_thread_| before returning.
188 crit_acquired_event_.Wait(rtc::Event::kForever);
189 }
190 }
191
192 void CheckFrame(size_t index, int picture_id, int spatial_layer) {
193 rtc::CritScope lock(&crit_);
194 ASSERT_LT(index, frames_.size());
195 ASSERT_TRUE(frames_[index]);
196 ASSERT_EQ(picture_id, frames_[index]->picture_id);
197 ASSERT_EQ(spatial_layer, frames_[index]->spatial_layer);
198 }
199
200 void CheckNoFrame(size_t index) {
201 rtc::CritScope lock(&crit_);
202 ASSERT_LT(index, frames_.size());
203 ASSERT_FALSE(frames_[index]);
204 }
205
tommi0f8b4032017-02-22 11:22:05 -0800206 static void ExtractLoop(void* obj) {
philipelbe7a9e52016-05-19 12:19:35 +0200207 TestFrameBuffer2* tfb = static_cast<TestFrameBuffer2*>(obj);
208 while (true) {
209 tfb->trigger_extract_event_.Wait(rtc::Event::kForever);
210 {
211 rtc::CritScope lock(&tfb->crit_);
212 tfb->crit_acquired_event_.Set();
213 if (tfb->tear_down_)
tommi0f8b4032017-02-22 11:22:05 -0800214 return;
philipelbe7a9e52016-05-19 12:19:35 +0200215
philipel75562822016-09-05 10:57:41 +0200216 std::unique_ptr<FrameObject> frame;
217 FrameBuffer::ReturnReason res =
218 tfb->buffer_.NextFrame(tfb->max_wait_time_, &frame);
219 if (res != FrameBuffer::ReturnReason::kStopped)
220 tfb->frames_.emplace_back(std::move(frame));
philipelbe7a9e52016-05-19 12:19:35 +0200221 }
222 }
223 }
224
225 uint32_t Rand() { return rand_.Rand<uint32_t>(); }
226
227 SimulatedClock clock_;
228 VCMTimingFake timing_;
philipel4f6cd6a2016-08-03 10:59:32 +0200229 ::testing::NiceMock<VCMJitterEstimatorMock> jitter_estimator_;
philipelbe7a9e52016-05-19 12:19:35 +0200230 FrameBuffer buffer_;
231 std::vector<std::unique_ptr<FrameObject>> frames_;
232 Random rand_;
philipela45102f2017-02-22 05:30:39 -0800233 ::testing::NiceMock<VCMReceiveStatisticsCallbackMock> stats_callback_;
philipelbe7a9e52016-05-19 12:19:35 +0200234
235 int64_t max_wait_time_;
236 bool tear_down_;
237 rtc::PlatformThread extract_thread_;
238 rtc::Event trigger_extract_event_;
239 rtc::Event crit_acquired_event_;
240 rtc::CriticalSection crit_;
241};
242
philipel6e8224f2016-05-19 17:07:44 +0200243// Following tests are timing dependent. Either the timeouts have to
244// be increased by a large margin, which would slow down all trybots,
245// or we disable them for the very slow ones, like we do here.
246#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER)
philipelbe7a9e52016-05-19 12:19:35 +0200247TEST_F(TestFrameBuffer2, WaitForFrame) {
248 uint16_t pid = Rand();
249 uint32_t ts = Rand();
250
philipel6e8224f2016-05-19 17:07:44 +0200251 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200252 InsertFrame(pid, 0, ts, false);
253 CheckFrame(0, pid, 0);
254}
255
256TEST_F(TestFrameBuffer2, OneSuperFrame) {
257 uint16_t pid = Rand();
258 uint32_t ts = Rand();
259
philipele0b2f152016-09-28 10:23:49 +0200260 InsertFrame(pid, 0, ts, false);
261 ExtractFrame();
262 InsertFrame(pid, 1, ts, true);
263 ExtractFrame();
264
265 CheckFrame(0, pid, 0);
266 CheckFrame(1, pid, 1);
267}
268
gnishb2a318b2017-05-10 09:21:33 -0700269TEST_F(TestFrameBuffer2, SetPlayoutDelay) {
270 const PlayoutDelay kPlayoutDelayMs = {123, 321};
271 std::unique_ptr<FrameObjectFake> test_frame(new FrameObjectFake());
272 test_frame->SetPlayoutDelay(kPlayoutDelayMs);
273 buffer_.InsertFrame(std::move(test_frame));
274 EXPECT_EQ(kPlayoutDelayMs.min_ms, timing_.min_playout_delay());
275 EXPECT_EQ(kPlayoutDelayMs.max_ms, timing_.max_playout_delay());
276}
277
aleloi3e005282017-01-26 05:38:00 -0800278// Flaky test, see bugs.webrtc.org/7068.
279TEST_F(TestFrameBuffer2, DISABLED_OneUnorderedSuperFrame) {
philipele0b2f152016-09-28 10:23:49 +0200280 uint16_t pid = Rand();
281 uint32_t ts = Rand();
282
philipel6e8224f2016-05-19 17:07:44 +0200283 ExtractFrame(50);
philipelbe7a9e52016-05-19 12:19:35 +0200284 InsertFrame(pid, 1, ts, true);
285 InsertFrame(pid, 0, ts, false);
286 ExtractFrame();
287
288 CheckFrame(0, pid, 0);
289 CheckFrame(1, pid, 1);
290}
291
philipel94616b32016-05-20 10:43:01 +0200292TEST_F(TestFrameBuffer2, DISABLED_OneLayerStreamReordered) {
philipel6e8224f2016-05-19 17:07:44 +0200293 uint16_t pid = Rand();
294 uint32_t ts = Rand();
295
296 InsertFrame(pid, 0, ts, false);
297 ExtractFrame();
298 CheckFrame(0, pid, 0);
299 for (int i = 1; i < 10; i += 2) {
300 ExtractFrame(50);
301 InsertFrame(pid + i + 1, 0, ts + (i + 1) * kFps10, false, pid + i);
302 clock_.AdvanceTimeMilliseconds(kFps10);
303 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
304 clock_.AdvanceTimeMilliseconds(kFps10);
305 ExtractFrame();
306 CheckFrame(i, pid + i, 0);
307 CheckFrame(i + 1, pid + i + 1, 0);
308 }
309}
310#endif // Timing dependent tests.
311
312TEST_F(TestFrameBuffer2, ExtractFromEmptyBuffer) {
313 ExtractFrame();
314 CheckNoFrame(0);
315}
316
philipel93e451b2016-10-06 12:25:13 +0200317TEST_F(TestFrameBuffer2, MissingFrame) {
318 uint16_t pid = Rand();
319 uint32_t ts = Rand();
320
321 InsertFrame(pid, 0, ts, false);
322 InsertFrame(pid + 2, 0, ts, false, pid);
323 InsertFrame(pid + 3, 0, ts, false, pid + 1, pid + 2);
324 ExtractFrame();
325 ExtractFrame();
326 ExtractFrame();
327
328 CheckFrame(0, pid, 0);
329 CheckFrame(1, pid + 2, 0);
330 CheckNoFrame(2);
331}
332
philipelbe7a9e52016-05-19 12:19:35 +0200333TEST_F(TestFrameBuffer2, OneLayerStream) {
334 uint16_t pid = Rand();
335 uint32_t ts = Rand();
336
337 InsertFrame(pid, 0, ts, false);
338 ExtractFrame();
339 CheckFrame(0, pid, 0);
340 for (int i = 1; i < 10; ++i) {
341 InsertFrame(pid + i, 0, ts + i * kFps10, false, pid + i - 1);
342 ExtractFrame();
343 clock_.AdvanceTimeMilliseconds(kFps10);
344 CheckFrame(i, pid + i, 0);
345 }
346}
347
philipelbe7a9e52016-05-19 12:19:35 +0200348TEST_F(TestFrameBuffer2, DropTemporalLayerSlowDecoder) {
349 uint16_t pid = Rand();
350 uint32_t ts = Rand();
351
352 InsertFrame(pid, 0, ts, false);
philipelfd5a20f2016-11-15 00:57:57 -0800353 InsertFrame(pid + 1, 0, ts + kFps20, false, pid);
philipelbe7a9e52016-05-19 12:19:35 +0200354 for (int i = 2; i < 10; i += 2) {
355 uint32_t ts_tl0 = ts + i / 2 * kFps10;
356 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 2);
357 InsertFrame(pid + i + 1, 0, ts_tl0 + kFps20, false, pid + i, pid + i - 1);
358 }
359
360 for (int i = 0; i < 10; ++i) {
361 ExtractFrame();
362 clock_.AdvanceTimeMilliseconds(60);
363 }
364
365 CheckFrame(0, pid, 0);
366 CheckFrame(1, pid + 1, 0);
367 CheckFrame(2, pid + 2, 0);
368 CheckFrame(3, pid + 4, 0);
369 CheckFrame(4, pid + 6, 0);
370 CheckFrame(5, pid + 8, 0);
371 CheckNoFrame(6);
372 CheckNoFrame(7);
373 CheckNoFrame(8);
374 CheckNoFrame(9);
375}
376
377TEST_F(TestFrameBuffer2, DropSpatialLayerSlowDecoder) {
378 uint16_t pid = Rand();
379 uint32_t ts = Rand();
380
381 InsertFrame(pid, 0, ts, false);
382 InsertFrame(pid, 1, ts, false);
383 for (int i = 1; i < 6; ++i) {
384 uint32_t ts_tl0 = ts + i * kFps10;
385 InsertFrame(pid + i, 0, ts_tl0, false, pid + i - 1);
386 InsertFrame(pid + i, 1, ts_tl0, false, pid + i - 1);
387 }
388
389 ExtractFrame();
390 ExtractFrame();
391 clock_.AdvanceTimeMilliseconds(55);
392 for (int i = 2; i < 12; ++i) {
393 ExtractFrame();
394 clock_.AdvanceTimeMilliseconds(55);
395 }
396
397 CheckFrame(0, pid, 0);
398 CheckFrame(1, pid, 1);
399 CheckFrame(2, pid + 1, 0);
400 CheckFrame(3, pid + 1, 1);
401 CheckFrame(4, pid + 2, 0);
402 CheckFrame(5, pid + 2, 1);
403 CheckFrame(6, pid + 3, 0);
404 CheckFrame(7, pid + 4, 0);
405 CheckFrame(8, pid + 5, 0);
406 CheckNoFrame(9);
407 CheckNoFrame(10);
408 CheckNoFrame(11);
409}
410
411TEST_F(TestFrameBuffer2, InsertLateFrame) {
412 uint16_t pid = Rand();
413 uint32_t ts = Rand();
414
415 InsertFrame(pid, 0, ts, false);
416 ExtractFrame();
417 InsertFrame(pid + 2, 0, ts, false);
418 ExtractFrame();
419 InsertFrame(pid + 1, 0, ts, false, pid);
420 ExtractFrame();
421
422 CheckFrame(0, pid, 0);
423 CheckFrame(1, pid + 2, 0);
424 CheckNoFrame(2);
425}
426
philipel4f6cd6a2016-08-03 10:59:32 +0200427TEST_F(TestFrameBuffer2, ProtectionMode) {
428 uint16_t pid = Rand();
429 uint32_t ts = Rand();
430
431 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(1.0));
432 InsertFrame(pid, 0, ts, false);
433 ExtractFrame();
434
435 buffer_.SetProtectionMode(kProtectionNackFEC);
436 EXPECT_CALL(jitter_estimator_, GetJitterEstimate(0.0));
437 InsertFrame(pid + 1, 0, ts, false);
438 ExtractFrame();
439}
440
philipele0b2f152016-09-28 10:23:49 +0200441TEST_F(TestFrameBuffer2, NoContinuousFrame) {
442 uint16_t pid = Rand();
443 uint32_t ts = Rand();
444
445 EXPECT_EQ(-1, InsertFrame(pid + 1, 0, ts, false, pid));
446}
447
448TEST_F(TestFrameBuffer2, LastContinuousFrameSingleLayer) {
449 uint16_t pid = Rand();
450 uint32_t ts = Rand();
451
452 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
453 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
454 EXPECT_EQ(pid + 2, InsertFrame(pid + 1, 0, ts, false, pid));
455 EXPECT_EQ(pid + 2, InsertFrame(pid + 4, 0, ts, false, pid + 3));
456 EXPECT_EQ(pid + 5, InsertFrame(pid + 5, 0, ts, false));
457}
458
459TEST_F(TestFrameBuffer2, LastContinuousFrameTwoLayers) {
460 uint16_t pid = Rand();
461 uint32_t ts = Rand();
462
463 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
464 EXPECT_EQ(pid, InsertFrame(pid, 1, ts, true));
465 EXPECT_EQ(pid, InsertFrame(pid + 1, 1, ts, true, pid));
466 EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, pid + 1));
467 EXPECT_EQ(pid, InsertFrame(pid + 2, 1, ts, true, pid + 1));
468 EXPECT_EQ(pid, InsertFrame(pid + 3, 0, ts, false, pid + 2));
469 EXPECT_EQ(pid + 3, InsertFrame(pid + 1, 0, ts, false, pid));
470 EXPECT_EQ(pid + 3, InsertFrame(pid + 3, 1, ts, true, pid + 2));
471}
472
philipelfcc60062017-01-18 05:35:20 -0800473TEST_F(TestFrameBuffer2, PictureIdJumpBack) {
474 uint16_t pid = Rand();
475 uint32_t ts = Rand();
476
477 EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false));
478 EXPECT_EQ(pid + 1, InsertFrame(pid + 1, 0, ts + 1, false, pid));
479 ExtractFrame();
480 CheckFrame(0, pid, 0);
481
482 // Jump back in pid but increase ts.
483 EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false));
484 ExtractFrame();
485 ExtractFrame();
486 CheckFrame(1, pid - 1, 0);
487 CheckNoFrame(2);
488}
489
philipela45102f2017-02-22 05:30:39 -0800490TEST_F(TestFrameBuffer2, StatsCallback) {
491 uint16_t pid = Rand();
492 uint32_t ts = Rand();
493 const int kFrameSize = 5000;
494
ilnik6d5b4d62017-08-30 03:32:14 -0700495 EXPECT_CALL(stats_callback_,
496 OnCompleteFrame(true, kFrameSize, VideoContentType::UNSPECIFIED));
philipela45102f2017-02-22 05:30:39 -0800497 EXPECT_CALL(stats_callback_,
498 OnFrameBufferTimingsUpdated(_, _, _, _, _, _, _));
499
500 {
501 std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
502 frame->SetSize(kFrameSize);
503 frame->picture_id = pid;
504 frame->spatial_layer = 0;
505 frame->timestamp = ts;
506 frame->num_references = 0;
507 frame->inter_layer_predicted = false;
508
509 EXPECT_EQ(buffer_.InsertFrame(std::move(frame)), pid);
510 }
511
512 ExtractFrame();
513 CheckFrame(0, pid, 0);
514}
515
philipel146a48b2017-04-20 04:04:38 -0700516TEST_F(TestFrameBuffer2, ForwardJumps) {
517 EXPECT_EQ(5453, InsertFrame(5453, 0, 1, false));
518 ExtractFrame();
519 EXPECT_EQ(5454, InsertFrame(5454, 0, 1, false, 5453));
520 ExtractFrame();
521 EXPECT_EQ(15670, InsertFrame(15670, 0, 1, false));
522 ExtractFrame();
523 EXPECT_EQ(29804, InsertFrame(29804, 0, 1, false));
524 ExtractFrame();
525 EXPECT_EQ(29805, InsertFrame(29805, 0, 1, false, 29804));
526 ExtractFrame();
527 EXPECT_EQ(29806, InsertFrame(29806, 0, 1, false, 29805));
528 ExtractFrame();
529 EXPECT_EQ(33819, InsertFrame(33819, 0, 1, false));
530 ExtractFrame();
531 EXPECT_EQ(41248, InsertFrame(41248, 0, 1, false));
532 ExtractFrame();
533}
534
philipelf6842692017-04-28 03:29:15 -0700535TEST_F(TestFrameBuffer2, DuplicateFrames) {
536 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
537 ExtractFrame();
538 EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false));
539}
540
philipel112adf92017-06-15 09:06:21 -0700541// TODO(philipel): implement more unittests related to invalid references.
542TEST_F(TestFrameBuffer2, InvalidReferences) {
543 EXPECT_EQ(-1, InsertFrame(0, 0, 1000, false, 2));
544 EXPECT_EQ(1, InsertFrame(1, 0, 2000, false));
545 ExtractFrame();
546 EXPECT_EQ(2, InsertFrame(2, 0, 3000, false, 1));
547}
548
philipel3042c2d2017-08-18 04:55:02 -0700549TEST_F(TestFrameBuffer2, KeyframeRequired) {
550 EXPECT_EQ(1, InsertFrame(1, 0, 1000, false));
551 EXPECT_EQ(2, InsertFrame(2, 0, 2000, false, 1));
552 EXPECT_EQ(3, InsertFrame(3, 0, 3000, false));
553 ExtractFrame();
554 ExtractFrame(0, true);
555 ExtractFrame();
556
557 CheckFrame(0, 1, 0);
558 CheckFrame(1, 3, 0);
559 CheckNoFrame(2);
560}
561
philipelbe7a9e52016-05-19 12:19:35 +0200562} // namespace video_coding
563} // namespace webrtc