blob: 82c6f1202bae752e9ddb342a6416126c042002ff [file] [log] [blame]
mikhal@webrtc.org62665b82011-12-29 18:09:58 +00001/*
2 * Copyright (c) 2011 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 <string.h>
12
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "modules/include/module_common_types.h"
14#include "modules/video_coding/decoding_state.h"
15#include "modules/video_coding/frame_buffer.h"
16#include "modules/video_coding/jitter_buffer_common.h"
17#include "modules/video_coding/packet.h"
18#include "test/gtest.h"
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000019
20namespace webrtc {
21
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000022TEST(TestDecodingState, Sanity) {
23 VCMDecodingState dec_state;
24 dec_state.Reset();
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000025 EXPECT_TRUE(dec_state.in_initial_state());
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000026 EXPECT_TRUE(dec_state.full_sync());
27}
28
29TEST(TestDecodingState, FrameContinuity) {
30 VCMDecodingState dec_state;
31 // Check that makes decision based on correct method.
andrew@webrtc.orgdf9c0e52013-04-24 02:13:18 +000032 VCMFrameBuffer frame;
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000033 VCMFrameBuffer frame_key;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000034 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -080035 packet.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000036 packet.timestamp = 1;
37 packet.seqNum = 0xffff;
38 packet.frameType = kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +020039 packet.video_header.codec = kVideoCodecVP8;
Philip Eliassond52a1a62018-09-07 13:03:55 +000040 auto& vp8_header =
41 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
42 vp8_header.pictureId = 0x007F;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000043 FrameData frame_data;
44 frame_data.rtt_ms = 0;
45 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000046 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000047 // Always start with a key frame.
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000048 dec_state.Reset();
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000049 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000050 packet.frameType = kVideoFrameKey;
51 EXPECT_LE(0, frame_key.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000052 EXPECT_TRUE(dec_state.ContinuousFrame(&frame_key));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000053 dec_state.SetState(&frame);
54 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000055 packet.frameType = kVideoFrameDelta;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000056 // Use pictureId
johan0d1b2b62017-01-10 04:21:35 -080057 packet.is_first_packet_in_frame = false;
Philip Eliassond52a1a62018-09-07 13:03:55 +000058 vp8_header.pictureId = 0x0002;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000059 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000060 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
61 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +000062 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000063 packet.seqNum = 10;
64 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000065 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
66
67 // Use sequence numbers.
Philip Eliassond52a1a62018-09-07 13:03:55 +000068 vp8_header.pictureId = kNoPictureId;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000069 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000070 packet.seqNum = dec_state.sequence_num() - 1u;
71 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000072 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
73 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000074 packet.seqNum = dec_state.sequence_num() + 1u;
75 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000076 // Insert another packet to this frame
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000077 packet.seqNum++;
78 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000079 // Verify wrap.
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +000080 EXPECT_LE(dec_state.sequence_num(), 0xffff);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000081 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
82 dec_state.SetState(&frame);
83
84 // Insert packet with temporal info.
85 dec_state.Reset();
86 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +000087 vp8_header.tl0PicIdx = 0;
88 vp8_header.temporalIdx = 0;
89 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000090 packet.seqNum = 1;
91 packet.timestamp = 1;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000092 EXPECT_TRUE(dec_state.full_sync());
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000093 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000094 dec_state.SetState(&frame);
95 EXPECT_TRUE(dec_state.full_sync());
96 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000097 // 1 layer up - still good.
Philip Eliassond52a1a62018-09-07 13:03:55 +000098 vp8_header.tl0PicIdx = 0;
99 vp8_header.temporalIdx = 1;
100 vp8_header.pictureId = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000101 packet.seqNum = 2;
102 packet.timestamp = 2;
103 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000104 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
105 dec_state.SetState(&frame);
106 EXPECT_TRUE(dec_state.full_sync());
107 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000108 // Lost non-base layer packet => should update sync parameter.
Philip Eliassond52a1a62018-09-07 13:03:55 +0000109 vp8_header.tl0PicIdx = 0;
110 vp8_header.temporalIdx = 3;
111 vp8_header.pictureId = 3;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000112 packet.seqNum = 4;
113 packet.timestamp = 4;
114 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000115 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
116 // Now insert the next non-base layer (belonging to a next tl0PicId).
117 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000118 vp8_header.tl0PicIdx = 1;
119 vp8_header.temporalIdx = 2;
120 vp8_header.pictureId = 4;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000121 packet.seqNum = 5;
122 packet.timestamp = 5;
123 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000124 // Checking continuity and not updating the state - this should not trigger
125 // an update of sync state.
126 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
127 EXPECT_TRUE(dec_state.full_sync());
128 // Next base layer (dropped interim non-base layers) - should update sync.
129 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000130 vp8_header.tl0PicIdx = 1;
131 vp8_header.temporalIdx = 0;
132 vp8_header.pictureId = 5;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000133 packet.seqNum = 6;
134 packet.timestamp = 6;
135 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000136 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
137 dec_state.SetState(&frame);
138 EXPECT_FALSE(dec_state.full_sync());
139
140 // Check wrap for temporal layers.
141 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000142 vp8_header.tl0PicIdx = 0x00FF;
143 vp8_header.temporalIdx = 0;
144 vp8_header.pictureId = 6;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000145 packet.seqNum = 7;
146 packet.timestamp = 7;
147 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000148 dec_state.SetState(&frame);
149 EXPECT_FALSE(dec_state.full_sync());
150 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000151 vp8_header.tl0PicIdx = 0x0000;
152 vp8_header.temporalIdx = 0;
153 vp8_header.pictureId = 7;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000154 packet.seqNum = 8;
155 packet.timestamp = 8;
156 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000157 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
158 // The current frame is not continuous
159 dec_state.SetState(&frame);
160 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000161}
162
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000163TEST(TestDecodingState, UpdateOldPacket) {
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000164 VCMDecodingState dec_state;
165 // Update only if zero size and newer than previous.
166 // Should only update if the timeStamp match.
167 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000168 VCMPacket packet;
169 packet.timestamp = 1;
170 packet.seqNum = 1;
171 packet.frameType = kVideoFrameDelta;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000172 FrameData frame_data;
173 frame_data.rtt_ms = 0;
174 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000175 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000176 dec_state.SetState(&frame);
177 EXPECT_EQ(dec_state.sequence_num(), 1);
178 // Insert an empty packet that does not belong to the same frame.
179 // => Sequence num should be the same.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000180 packet.timestamp = 2;
181 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000182 EXPECT_EQ(dec_state.sequence_num(), 1);
183 // Now insert empty packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000184 packet.timestamp = 1;
185 packet.seqNum = 2;
pbos22993e12015-10-19 02:39:06 -0700186 packet.frameType = kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000187 packet.sizeBytes = 0;
188 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000189 EXPECT_EQ(dec_state.sequence_num(), 2);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000190 // Now insert delta packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000191 packet.timestamp = 1;
192 packet.seqNum = 3;
193 packet.frameType = kVideoFrameDelta;
194 packet.sizeBytes = 1400;
195 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000196 EXPECT_EQ(dec_state.sequence_num(), 3);
197 // Insert a packet belonging to an older timestamp - should not update the
198 // sequence number.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000199 packet.timestamp = 0;
200 packet.seqNum = 4;
pbos22993e12015-10-19 02:39:06 -0700201 packet.frameType = kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000202 packet.sizeBytes = 0;
203 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000204 EXPECT_EQ(dec_state.sequence_num(), 3);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000205}
206
207TEST(TestDecodingState, MultiLayerBehavior) {
208 // Identify sync/non-sync when more than one layer.
209 VCMDecodingState dec_state;
210 // Identify packets belonging to old frames/packets.
211 // Set state for current frames.
212 // tl0PicIdx 0, temporal id 0.
213 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000214 VCMPacket packet;
215 packet.frameType = kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200216 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000217 packet.timestamp = 0;
218 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000219 auto& vp8_header =
220 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
221 vp8_header.tl0PicIdx = 0;
222 vp8_header.temporalIdx = 0;
223 vp8_header.pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000224 FrameData frame_data;
225 frame_data.rtt_ms = 0;
226 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000227 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000228 dec_state.SetState(&frame);
229 // tl0PicIdx 0, temporal id 1.
230 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000231 packet.timestamp = 1;
232 packet.seqNum = 1;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000233 vp8_header.tl0PicIdx = 0;
234 vp8_header.temporalIdx = 1;
235 vp8_header.pictureId = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000236 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000237 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
238 dec_state.SetState(&frame);
239 EXPECT_TRUE(dec_state.full_sync());
240 // Lost tl0PicIdx 0, temporal id 2.
241 // Insert tl0PicIdx 0, temporal id 3.
242 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000243 packet.timestamp = 3;
244 packet.seqNum = 3;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000245 vp8_header.tl0PicIdx = 0;
246 vp8_header.temporalIdx = 3;
247 vp8_header.pictureId = 3;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000248 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000249 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
250 dec_state.SetState(&frame);
251 EXPECT_FALSE(dec_state.full_sync());
252 // Insert next base layer
253 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000254 packet.timestamp = 4;
255 packet.seqNum = 4;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000256 vp8_header.tl0PicIdx = 1;
257 vp8_header.temporalIdx = 0;
258 vp8_header.pictureId = 4;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000259 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000260 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
261 dec_state.SetState(&frame);
262 EXPECT_FALSE(dec_state.full_sync());
263 // Insert key frame - should update sync value.
264 // A key frame is always a base layer.
265 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000266 packet.frameType = kVideoFrameKey;
johan0d1b2b62017-01-10 04:21:35 -0800267 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000268 packet.timestamp = 5;
269 packet.seqNum = 5;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000270 vp8_header.tl0PicIdx = 2;
271 vp8_header.temporalIdx = 0;
272 vp8_header.pictureId = 5;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000273 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000274 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
275 dec_state.SetState(&frame);
276 EXPECT_TRUE(dec_state.full_sync());
277 // After sync, a continuous PictureId is required
278 // (continuous base layer is not enough )
279 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000280 packet.frameType = kVideoFrameDelta;
281 packet.timestamp = 6;
282 packet.seqNum = 6;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000283 vp8_header.tl0PicIdx = 3;
284 vp8_header.temporalIdx = 0;
285 vp8_header.pictureId = 6;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000286 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000287 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
288 EXPECT_TRUE(dec_state.full_sync());
289 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000290 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800291 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000292 packet.timestamp = 8;
293 packet.seqNum = 8;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000294 vp8_header.tl0PicIdx = 4;
295 vp8_header.temporalIdx = 0;
296 vp8_header.pictureId = 8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000297 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000298 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
299 EXPECT_TRUE(dec_state.full_sync());
300 dec_state.SetState(&frame);
301 EXPECT_FALSE(dec_state.full_sync());
302
303 // Insert a non-ref frame - should update sync value.
304 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000305 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800306 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000307 packet.timestamp = 9;
308 packet.seqNum = 9;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000309 vp8_header.tl0PicIdx = 4;
310 vp8_header.temporalIdx = 2;
311 vp8_header.pictureId = 9;
312 vp8_header.layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000313 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000314 dec_state.SetState(&frame);
315 EXPECT_TRUE(dec_state.full_sync());
316
317 // The following test will verify the sync flag behavior after a loss.
318 // Create the following pattern:
319 // Update base layer, lose packet 1 (sync flag on, layer 2), insert packet 3
320 // (sync flag on, layer 2) check continuity and sync flag after inserting
321 // packet 2 (sync flag on, layer 1).
322 // Base layer.
323 frame.Reset();
324 dec_state.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000325 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800326 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000327 packet.markerBit = 1;
328 packet.timestamp = 0;
329 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000330 vp8_header.tl0PicIdx = 0;
331 vp8_header.temporalIdx = 0;
332 vp8_header.pictureId = 0;
333 vp8_header.layerSync = false;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000334 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000335 dec_state.SetState(&frame);
336 EXPECT_TRUE(dec_state.full_sync());
337 // Layer 2 - 2 packets (insert one, lose one).
338 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000339 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800340 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000341 packet.markerBit = 0;
342 packet.timestamp = 1;
343 packet.seqNum = 1;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000344 vp8_header.tl0PicIdx = 0;
345 vp8_header.temporalIdx = 2;
346 vp8_header.pictureId = 1;
347 vp8_header.layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000348 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000349 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
350 // Layer 1
351 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000352 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800353 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000354 packet.markerBit = 1;
355 packet.timestamp = 2;
356 packet.seqNum = 3;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000357 vp8_header.tl0PicIdx = 0;
358 vp8_header.temporalIdx = 1;
359 vp8_header.pictureId = 2;
360 vp8_header.layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000361 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000362 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
363 EXPECT_TRUE(dec_state.full_sync());
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000364}
365
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000366TEST(TestDecodingState, DiscontinuousPicIdContinuousSeqNum) {
367 VCMDecodingState dec_state;
368 VCMFrameBuffer frame;
369 VCMPacket packet;
370 frame.Reset();
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000371 packet.frameType = kVideoFrameKey;
Niels Möller520ca4e2018-06-04 11:14:38 +0200372 packet.video_header.codec = kVideoCodecVP8;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000373 packet.timestamp = 0;
374 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000375 auto& vp8_header =
376 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
377 vp8_header.tl0PicIdx = 0;
378 vp8_header.temporalIdx = 0;
379 vp8_header.pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000380 FrameData frame_data;
381 frame_data.rtt_ms = 0;
382 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000383 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000384 dec_state.SetState(&frame);
385 EXPECT_TRUE(dec_state.full_sync());
386
387 // Continuous sequence number but discontinuous picture id. This implies a
388 // a loss and we have to fall back to only decoding the base layer.
389 frame.Reset();
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000390 packet.frameType = kVideoFrameDelta;
391 packet.timestamp += 3000;
392 ++packet.seqNum;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000393 vp8_header.temporalIdx = 1;
394 vp8_header.pictureId = 2;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000395 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000396 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
397 dec_state.SetState(&frame);
398 EXPECT_FALSE(dec_state.full_sync());
399}
400
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000401TEST(TestDecodingState, OldInput) {
402 VCMDecodingState dec_state;
403 // Identify packets belonging to old frames/packets.
404 // Set state for current frames.
405 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000406 VCMPacket packet;
407 packet.timestamp = 10;
408 packet.seqNum = 1;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000409 FrameData frame_data;
410 frame_data.rtt_ms = 0;
411 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000412 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000413 dec_state.SetState(&frame);
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000414 packet.timestamp = 9;
415 EXPECT_TRUE(dec_state.IsOldPacket(&packet));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000416 // Check for old frame
417 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000418 frame.InsertPacket(packet, 0, kNoErrors, frame_data);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000419 EXPECT_TRUE(dec_state.IsOldFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000420}
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000421
422TEST(TestDecodingState, PictureIdRepeat) {
423 VCMDecodingState dec_state;
424 VCMFrameBuffer frame;
425 VCMPacket packet;
426 packet.frameType = kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200427 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000428 packet.timestamp = 0;
429 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000430 auto& vp8_header =
431 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
432 vp8_header.tl0PicIdx = 0;
433 vp8_header.temporalIdx = 0;
434 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000435 FrameData frame_data;
436 frame_data.rtt_ms = 0;
437 frame_data.rolling_average_packets_per_frame = -1;
438 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
439 dec_state.SetState(&frame);
440 // tl0PicIdx 0, temporal id 1.
441 frame.Reset();
442 ++packet.timestamp;
443 ++packet.seqNum;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000444 vp8_header.temporalIdx++;
445 vp8_header.pictureId++;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000446 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
447 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
448 frame.Reset();
449 // Testing only gap in tl0PicIdx when tl0PicIdx in continuous.
Philip Eliassond52a1a62018-09-07 13:03:55 +0000450 vp8_header.tl0PicIdx += 3;
451 vp8_header.temporalIdx++;
452 vp8_header.tl0PicIdx = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000453 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
454 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
455}
456
philipelcfc319b2015-11-10 07:17:23 -0800457TEST(TestDecodingState, FrameContinuityFlexibleModeKeyFrame) {
458 VCMDecodingState dec_state;
459 VCMFrameBuffer frame;
460 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800461 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800462 packet.timestamp = 1;
463 packet.seqNum = 0xffff;
464 uint8_t data[] = "I need a data pointer for this test!";
465 packet.sizeBytes = sizeof(data);
466 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200467 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800468
philipel29d88462018-08-08 14:26:00 +0200469 auto& vp9_hdr =
470 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800471 vp9_hdr.picture_id = 10;
472 vp9_hdr.flexible_mode = true;
473
474 FrameData frame_data;
475 frame_data.rtt_ms = 0;
476 frame_data.rolling_average_packets_per_frame = -1;
477
478 // Key frame as first frame
479 packet.frameType = kVideoFrameKey;
480 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
481 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
482 dec_state.SetState(&frame);
483
484 // Key frame again
485 vp9_hdr.picture_id = 11;
486 frame.Reset();
487 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
488 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
489 dec_state.SetState(&frame);
490
491 // Ref to 11, continuous
492 frame.Reset();
493 packet.frameType = kVideoFrameDelta;
494 vp9_hdr.picture_id = 12;
495 vp9_hdr.num_ref_pics = 1;
496 vp9_hdr.pid_diff[0] = 1;
497 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
498 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
499}
500
501TEST(TestDecodingState, FrameContinuityFlexibleModeOutOfOrderFrames) {
502 VCMDecodingState dec_state;
503 VCMFrameBuffer frame;
504 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800505 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800506 packet.timestamp = 1;
507 packet.seqNum = 0xffff;
508 uint8_t data[] = "I need a data pointer for this test!";
509 packet.sizeBytes = sizeof(data);
510 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200511 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800512
philipel29d88462018-08-08 14:26:00 +0200513 auto& vp9_hdr =
514 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800515 vp9_hdr.picture_id = 10;
516 vp9_hdr.flexible_mode = true;
517
518 FrameData frame_data;
519 frame_data.rtt_ms = 0;
520 frame_data.rolling_average_packets_per_frame = -1;
521
522 // Key frame as first frame
523 packet.frameType = kVideoFrameKey;
524 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
525 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
526 dec_state.SetState(&frame);
527
528 // Ref to 10, continuous
529 frame.Reset();
530 packet.frameType = kVideoFrameDelta;
531 vp9_hdr.picture_id = 15;
532 vp9_hdr.num_ref_pics = 1;
533 vp9_hdr.pid_diff[0] = 5;
534 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
535 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
536 dec_state.SetState(&frame);
537
538 // Out of order, last id 15, this id 12, ref to 10, continuous
539 frame.Reset();
540 vp9_hdr.picture_id = 12;
541 vp9_hdr.pid_diff[0] = 2;
542 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
543 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
544 dec_state.SetState(&frame);
545
546 // Ref 10, 12, 15, continuous
547 frame.Reset();
548 vp9_hdr.picture_id = 20;
549 vp9_hdr.num_ref_pics = 3;
550 vp9_hdr.pid_diff[0] = 10;
551 vp9_hdr.pid_diff[1] = 8;
552 vp9_hdr.pid_diff[2] = 5;
553 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
554 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
555}
556
557TEST(TestDecodingState, FrameContinuityFlexibleModeGeneral) {
558 VCMDecodingState dec_state;
559 VCMFrameBuffer frame;
560 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800561 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800562 packet.timestamp = 1;
563 packet.seqNum = 0xffff;
564 uint8_t data[] = "I need a data pointer for this test!";
565 packet.sizeBytes = sizeof(data);
566 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200567 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800568
philipel29d88462018-08-08 14:26:00 +0200569 auto& vp9_hdr =
570 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800571 vp9_hdr.picture_id = 10;
572 vp9_hdr.flexible_mode = true;
573
574 FrameData frame_data;
575 frame_data.rtt_ms = 0;
576 frame_data.rolling_average_packets_per_frame = -1;
577
578 // Key frame as first frame
579 packet.frameType = kVideoFrameKey;
580 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
581 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
582
583 // Delta frame as first frame
584 frame.Reset();
585 packet.frameType = kVideoFrameDelta;
586 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
587 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
588
589 // Key frame then delta frame
590 frame.Reset();
591 packet.frameType = kVideoFrameKey;
592 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
593 dec_state.SetState(&frame);
594 frame.Reset();
595 packet.frameType = kVideoFrameDelta;
596 vp9_hdr.num_ref_pics = 1;
597 vp9_hdr.picture_id = 15;
598 vp9_hdr.pid_diff[0] = 5;
599 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
600 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
601 dec_state.SetState(&frame);
602
603 // Ref to 11, not continuous
604 frame.Reset();
605 vp9_hdr.picture_id = 16;
606 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
607 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
608
609 // Ref to 15, continuous
610 frame.Reset();
611 vp9_hdr.picture_id = 16;
612 vp9_hdr.pid_diff[0] = 1;
613 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
614 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
615 dec_state.SetState(&frame);
616
617 // Ref to 11 and 15, not continuous
618 frame.Reset();
619 vp9_hdr.picture_id = 20;
620 vp9_hdr.num_ref_pics = 2;
621 vp9_hdr.pid_diff[0] = 9;
622 vp9_hdr.pid_diff[1] = 5;
623 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
624 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
625
626 // Ref to 10, 15 and 16, continuous
627 frame.Reset();
628 vp9_hdr.picture_id = 22;
629 vp9_hdr.num_ref_pics = 3;
630 vp9_hdr.pid_diff[0] = 12;
631 vp9_hdr.pid_diff[1] = 7;
632 vp9_hdr.pid_diff[2] = 6;
633 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
634 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
635 dec_state.SetState(&frame);
636
637 // Key Frame, continuous
638 frame.Reset();
639 packet.frameType = kVideoFrameKey;
640 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 2;
641 vp9_hdr.num_ref_pics = 0;
642 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
643 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
644 dec_state.SetState(&frame);
645
646 // Frame at last index, ref to KF, continuous
647 frame.Reset();
648 packet.frameType = kVideoFrameDelta;
649 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 1;
650 vp9_hdr.num_ref_pics = 1;
651 vp9_hdr.pid_diff[0] = 1;
652 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
653 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
654 dec_state.SetState(&frame);
655
656 // Frame after wrapping buffer length, ref to last index, continuous
657 frame.Reset();
658 vp9_hdr.picture_id = 0;
659 vp9_hdr.num_ref_pics = 1;
660 vp9_hdr.pid_diff[0] = 1;
661 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
662 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
663 dec_state.SetState(&frame);
664
665 // Frame after wrapping start frame, ref to 0, continuous
666 frame.Reset();
667 vp9_hdr.picture_id = 20;
668 vp9_hdr.num_ref_pics = 1;
669 vp9_hdr.pid_diff[0] = 20;
670 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
671 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
672 dec_state.SetState(&frame);
673
674 // Frame after wrapping start frame, ref to 10, not continuous
675 frame.Reset();
676 vp9_hdr.picture_id = 23;
677 vp9_hdr.num_ref_pics = 1;
678 vp9_hdr.pid_diff[0] = 13;
679 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
680 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
681
682 // Key frame, continuous
683 frame.Reset();
684 packet.frameType = kVideoFrameKey;
685 vp9_hdr.picture_id = 25;
686 vp9_hdr.num_ref_pics = 0;
687 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
688 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
689 dec_state.SetState(&frame);
690
691 // Ref to KF, continuous
692 frame.Reset();
693 packet.frameType = kVideoFrameDelta;
694 vp9_hdr.picture_id = 26;
695 vp9_hdr.num_ref_pics = 1;
696 vp9_hdr.pid_diff[0] = 1;
697 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
698 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
699 dec_state.SetState(&frame);
700
701 // Ref to frame previous to KF, not continuous
702 frame.Reset();
703 vp9_hdr.picture_id = 30;
704 vp9_hdr.num_ref_pics = 1;
705 vp9_hdr.pid_diff[0] = 30;
706 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
707 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
708}
709
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000710} // namespace webrtc