1 /*
2 * Copyright (c) 2019 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 "modules/video_coding/utility/decoded_frames_history.h"
12
13 #include "test/gtest.h"
14
15 namespace webrtc {
16 namespace video_coding {
17 namespace {
18
19 constexpr int kHistorySize = 1 << 13;
20
TEST(DecodedFramesHistory,RequestOnEmptyHistory)21 TEST(DecodedFramesHistory, RequestOnEmptyHistory) {
22 DecodedFramesHistory history(kHistorySize);
23 EXPECT_EQ(history.WasDecoded(1234), false);
24 }
25
TEST(DecodedFramesHistory,FindsLastDecodedFrame)26 TEST(DecodedFramesHistory, FindsLastDecodedFrame) {
27 DecodedFramesHistory history(kHistorySize);
28 history.InsertDecoded(1234, 0);
29 EXPECT_EQ(history.WasDecoded(1234), true);
30 }
31
TEST(DecodedFramesHistory,FindsPreviousFrame)32 TEST(DecodedFramesHistory, FindsPreviousFrame) {
33 DecodedFramesHistory history(kHistorySize);
34 history.InsertDecoded(1234, 0);
35 history.InsertDecoded(1235, 0);
36 EXPECT_EQ(history.WasDecoded(1234), true);
37 }
38
TEST(DecodedFramesHistory,ReportsMissingFrame)39 TEST(DecodedFramesHistory, ReportsMissingFrame) {
40 DecodedFramesHistory history(kHistorySize);
41 history.InsertDecoded(1234, 0);
42 history.InsertDecoded(1236, 0);
43 EXPECT_EQ(history.WasDecoded(1235), false);
44 }
45
TEST(DecodedFramesHistory,ClearsHistory)46 TEST(DecodedFramesHistory, ClearsHistory) {
47 DecodedFramesHistory history(kHistorySize);
48 history.InsertDecoded(1234, 0);
49 history.Clear();
50 EXPECT_EQ(history.WasDecoded(1234), false);
51 EXPECT_EQ(history.GetLastDecodedFrameId(), absl::nullopt);
52 EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), absl::nullopt);
53 }
54
TEST(DecodedFramesHistory,HandlesBigJumpInPictureId)55 TEST(DecodedFramesHistory, HandlesBigJumpInPictureId) {
56 DecodedFramesHistory history(kHistorySize);
57 history.InsertDecoded(1234, 0);
58 history.InsertDecoded(1235, 0);
59 history.InsertDecoded(1236, 0);
60 history.InsertDecoded(1236 + kHistorySize / 2, 0);
61 EXPECT_EQ(history.WasDecoded(1234), true);
62 EXPECT_EQ(history.WasDecoded(1237), false);
63 }
64
TEST(DecodedFramesHistory,ForgetsTooOldHistory)65 TEST(DecodedFramesHistory, ForgetsTooOldHistory) {
66 DecodedFramesHistory history(kHistorySize);
67 history.InsertDecoded(1234, 0);
68 history.InsertDecoded(1235, 0);
69 history.InsertDecoded(1236, 0);
70 history.InsertDecoded(1236 + kHistorySize * 2, 0);
71 EXPECT_EQ(history.WasDecoded(1234), false);
72 EXPECT_EQ(history.WasDecoded(1237), false);
73 }
74
TEST(DecodedFramesHistory,ReturnsLastDecodedFrameId)75 TEST(DecodedFramesHistory, ReturnsLastDecodedFrameId) {
76 DecodedFramesHistory history(kHistorySize);
77 EXPECT_EQ(history.GetLastDecodedFrameId(), absl::nullopt);
78 history.InsertDecoded(1234, 0);
79 EXPECT_EQ(history.GetLastDecodedFrameId(), 1234);
80 history.InsertDecoded(1235, 0);
81 EXPECT_EQ(history.GetLastDecodedFrameId(), 1235);
82 }
83
TEST(DecodedFramesHistory,ReturnsLastDecodedFrameTimestamp)84 TEST(DecodedFramesHistory, ReturnsLastDecodedFrameTimestamp) {
85 DecodedFramesHistory history(kHistorySize);
86 EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), absl::nullopt);
87 history.InsertDecoded(1234, 12345);
88 EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), 12345u);
89 history.InsertDecoded(1235, 12366);
90 EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), 12366u);
91 }
92
TEST(DecodedFramesHistory,NegativePictureIds)93 TEST(DecodedFramesHistory, NegativePictureIds) {
94 DecodedFramesHistory history(kHistorySize);
95 history.InsertDecoded(-1234, 12345);
96 history.InsertDecoded(-1233, 12366);
97 EXPECT_EQ(*history.GetLastDecodedFrameId(), -1233);
98
99 history.InsertDecoded(-1, 12377);
100 history.InsertDecoded(0, 12388);
101 EXPECT_EQ(*history.GetLastDecodedFrameId(), 0);
102
103 history.InsertDecoded(1, 12399);
104 EXPECT_EQ(*history.GetLastDecodedFrameId(), 1);
105
106 EXPECT_EQ(history.WasDecoded(-1234), true);
107 EXPECT_EQ(history.WasDecoded(-1), true);
108 EXPECT_EQ(history.WasDecoded(0), true);
109 EXPECT_EQ(history.WasDecoded(1), true);
110 }
111
112 } // namespace
113 } // namespace video_coding
114 } // namespace webrtc
115