• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, 0}), false);
24 }
25 
TEST(DecodedFramesHistory,FindsLastDecodedFrame)26 TEST(DecodedFramesHistory, FindsLastDecodedFrame) {
27   DecodedFramesHistory history(kHistorySize);
28   history.InsertDecoded({1234, 0}, 0);
29   EXPECT_EQ(history.WasDecoded({1234, 0}), true);
30 }
31 
TEST(DecodedFramesHistory,FindsPreviousFrame)32 TEST(DecodedFramesHistory, FindsPreviousFrame) {
33   DecodedFramesHistory history(kHistorySize);
34   history.InsertDecoded({1234, 0}, 0);
35   history.InsertDecoded({1235, 0}, 0);
36   EXPECT_EQ(history.WasDecoded({1234, 0}), true);
37 }
38 
TEST(DecodedFramesHistory,ReportsMissingFrame)39 TEST(DecodedFramesHistory, ReportsMissingFrame) {
40   DecodedFramesHistory history(kHistorySize);
41   history.InsertDecoded({1234, 0}, 0);
42   history.InsertDecoded({1236, 0}, 0);
43   EXPECT_EQ(history.WasDecoded({1235, 0}), false);
44 }
45 
TEST(DecodedFramesHistory,ClearsHistory)46 TEST(DecodedFramesHistory, ClearsHistory) {
47   DecodedFramesHistory history(kHistorySize);
48   history.InsertDecoded({1234, 0}, 0);
49   history.Clear();
50   EXPECT_EQ(history.WasDecoded({1234, 0}), false);
51   EXPECT_EQ(history.GetLastDecodedFrameId(), absl::nullopt);
52   EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), absl::nullopt);
53 }
54 
TEST(DecodedFramesHistory,HandlesMultipleLayers)55 TEST(DecodedFramesHistory, HandlesMultipleLayers) {
56   DecodedFramesHistory history(kHistorySize);
57   history.InsertDecoded({1234, 0}, 0);
58   history.InsertDecoded({1234, 1}, 0);
59   history.InsertDecoded({1235, 0}, 0);
60   history.InsertDecoded({1236, 0}, 0);
61   history.InsertDecoded({1236, 1}, 0);
62   EXPECT_EQ(history.WasDecoded({1235, 0}), true);
63   EXPECT_EQ(history.WasDecoded({1235, 1}), false);
64 }
65 
TEST(DecodedFramesHistory,HandlesNewLayer)66 TEST(DecodedFramesHistory, HandlesNewLayer) {
67   DecodedFramesHistory history(kHistorySize);
68   history.InsertDecoded({1234, 0}, 0);
69   history.InsertDecoded({1234, 1}, 0);
70   history.InsertDecoded({1235, 0}, 0);
71   history.InsertDecoded({1235, 1}, 0);
72   history.InsertDecoded({1236, 0}, 0);
73   history.InsertDecoded({1236, 1}, 0);
74   EXPECT_EQ(history.WasDecoded({1234, 2}), false);
75 }
76 
TEST(DecodedFramesHistory,HandlesSkippedLayer)77 TEST(DecodedFramesHistory, HandlesSkippedLayer) {
78   DecodedFramesHistory history(kHistorySize);
79   history.InsertDecoded({1234, 0}, 0);
80   history.InsertDecoded({1234, 2}, 0);
81   history.InsertDecoded({1235, 0}, 0);
82   history.InsertDecoded({1235, 1}, 0);
83   EXPECT_EQ(history.WasDecoded({1234, 1}), false);
84   EXPECT_EQ(history.WasDecoded({1235, 1}), true);
85 }
86 
TEST(DecodedFramesHistory,HandlesBigJumpInPictureId)87 TEST(DecodedFramesHistory, HandlesBigJumpInPictureId) {
88   DecodedFramesHistory history(kHistorySize);
89   history.InsertDecoded({1234, 0}, 0);
90   history.InsertDecoded({1235, 0}, 0);
91   history.InsertDecoded({1236, 0}, 0);
92   history.InsertDecoded({1236 + kHistorySize / 2, 0}, 0);
93   EXPECT_EQ(history.WasDecoded({1234, 0}), true);
94   EXPECT_EQ(history.WasDecoded({1237, 0}), false);
95 }
96 
TEST(DecodedFramesHistory,ForgetsTooOldHistory)97 TEST(DecodedFramesHistory, ForgetsTooOldHistory) {
98   DecodedFramesHistory history(kHistorySize);
99   history.InsertDecoded({1234, 0}, 0);
100   history.InsertDecoded({1235, 0}, 0);
101   history.InsertDecoded({1236, 0}, 0);
102   history.InsertDecoded({1236 + kHistorySize * 2, 0}, 0);
103   EXPECT_EQ(history.WasDecoded({1234, 0}), false);
104   EXPECT_EQ(history.WasDecoded({1237, 0}), false);
105 }
106 
TEST(DecodedFramesHistory,ReturnsLastDecodedFrameId)107 TEST(DecodedFramesHistory, ReturnsLastDecodedFrameId) {
108   DecodedFramesHistory history(kHistorySize);
109   EXPECT_EQ(history.GetLastDecodedFrameId(), absl::nullopt);
110   history.InsertDecoded({1234, 0}, 0);
111   EXPECT_EQ(history.GetLastDecodedFrameId(), VideoLayerFrameId(1234, 0));
112   history.InsertDecoded({1235, 0}, 0);
113   EXPECT_EQ(history.GetLastDecodedFrameId(), VideoLayerFrameId(1235, 0));
114 }
115 
TEST(DecodedFramesHistory,ReturnsLastDecodedFrameTimestamp)116 TEST(DecodedFramesHistory, ReturnsLastDecodedFrameTimestamp) {
117   DecodedFramesHistory history(kHistorySize);
118   EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), absl::nullopt);
119   history.InsertDecoded({1234, 0}, 12345);
120   EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), 12345u);
121   history.InsertDecoded({1235, 0}, 12366);
122   EXPECT_EQ(history.GetLastDecodedFrameTimestamp(), 12366u);
123 }
124 
TEST(DecodedFramesHistory,NegativePictureIds)125 TEST(DecodedFramesHistory, NegativePictureIds) {
126   DecodedFramesHistory history(kHistorySize);
127   history.InsertDecoded({-1234, 0}, 12345);
128   history.InsertDecoded({-1233, 0}, 12366);
129   EXPECT_EQ(history.GetLastDecodedFrameId()->picture_id, -1233);
130 
131   history.InsertDecoded({-1, 0}, 12377);
132   history.InsertDecoded({0, 0}, 12388);
133   EXPECT_EQ(history.GetLastDecodedFrameId()->picture_id, 0);
134 
135   history.InsertDecoded({1, 0}, 12399);
136   EXPECT_EQ(history.GetLastDecodedFrameId()->picture_id, 1);
137 
138   EXPECT_EQ(history.WasDecoded({-1234, 0}), true);
139   EXPECT_EQ(history.WasDecoded({-1, 0}), true);
140   EXPECT_EQ(history.WasDecoded({0, 0}), true);
141   EXPECT_EQ(history.WasDecoded({1, 0}), true);
142 }
143 
144 }  // namespace
145 }  // namespace video_coding
146 }  // namespace webrtc
147