blob: 0049ca7e1dbf634e1c6f86d5f642d350ff0fff90 [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 Eliasson1811c042018-09-07 12:35:23 +000040 packet.video_header.vp8().pictureId = 0x007F;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000041 FrameData frame_data;
42 frame_data.rtt_ms = 0;
43 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000044 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000045 // Always start with a key frame.
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000046 dec_state.Reset();
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000047 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000048 packet.frameType = kVideoFrameKey;
49 EXPECT_LE(0, frame_key.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000050 EXPECT_TRUE(dec_state.ContinuousFrame(&frame_key));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000051 dec_state.SetState(&frame);
52 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000053 packet.frameType = kVideoFrameDelta;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000054 // Use pictureId
johan0d1b2b62017-01-10 04:21:35 -080055 packet.is_first_packet_in_frame = false;
Philip Eliasson1811c042018-09-07 12:35:23 +000056 packet.video_header.vp8().pictureId = 0x0002;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000057 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000058 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
59 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +000060 packet.video_header.vp8().pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000061 packet.seqNum = 10;
62 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000063 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
64
65 // Use sequence numbers.
Philip Eliasson1811c042018-09-07 12:35:23 +000066 packet.video_header.vp8().pictureId = kNoPictureId;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000067 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000068 packet.seqNum = dec_state.sequence_num() - 1u;
69 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000070 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
71 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000072 packet.seqNum = dec_state.sequence_num() + 1u;
73 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000074 // Insert another packet to this frame
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000075 packet.seqNum++;
76 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000077 // Verify wrap.
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +000078 EXPECT_LE(dec_state.sequence_num(), 0xffff);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000079 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
80 dec_state.SetState(&frame);
81
82 // Insert packet with temporal info.
83 dec_state.Reset();
84 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +000085 packet.video_header.vp8().tl0PicIdx = 0;
86 packet.video_header.vp8().temporalIdx = 0;
87 packet.video_header.vp8().pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000088 packet.seqNum = 1;
89 packet.timestamp = 1;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000090 EXPECT_TRUE(dec_state.full_sync());
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000091 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000092 dec_state.SetState(&frame);
93 EXPECT_TRUE(dec_state.full_sync());
94 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000095 // 1 layer up - still good.
Philip Eliasson1811c042018-09-07 12:35:23 +000096 packet.video_header.vp8().tl0PicIdx = 0;
97 packet.video_header.vp8().temporalIdx = 1;
98 packet.video_header.vp8().pictureId = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000099 packet.seqNum = 2;
100 packet.timestamp = 2;
101 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000102 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
103 dec_state.SetState(&frame);
104 EXPECT_TRUE(dec_state.full_sync());
105 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000106 // Lost non-base layer packet => should update sync parameter.
Philip Eliasson1811c042018-09-07 12:35:23 +0000107 packet.video_header.vp8().tl0PicIdx = 0;
108 packet.video_header.vp8().temporalIdx = 3;
109 packet.video_header.vp8().pictureId = 3;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000110 packet.seqNum = 4;
111 packet.timestamp = 4;
112 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000113 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
114 // Now insert the next non-base layer (belonging to a next tl0PicId).
115 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +0000116 packet.video_header.vp8().tl0PicIdx = 1;
117 packet.video_header.vp8().temporalIdx = 2;
118 packet.video_header.vp8().pictureId = 4;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000119 packet.seqNum = 5;
120 packet.timestamp = 5;
121 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000122 // Checking continuity and not updating the state - this should not trigger
123 // an update of sync state.
124 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
125 EXPECT_TRUE(dec_state.full_sync());
126 // Next base layer (dropped interim non-base layers) - should update sync.
127 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +0000128 packet.video_header.vp8().tl0PicIdx = 1;
129 packet.video_header.vp8().temporalIdx = 0;
130 packet.video_header.vp8().pictureId = 5;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000131 packet.seqNum = 6;
132 packet.timestamp = 6;
133 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000134 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
135 dec_state.SetState(&frame);
136 EXPECT_FALSE(dec_state.full_sync());
137
138 // Check wrap for temporal layers.
139 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +0000140 packet.video_header.vp8().tl0PicIdx = 0x00FF;
141 packet.video_header.vp8().temporalIdx = 0;
142 packet.video_header.vp8().pictureId = 6;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000143 packet.seqNum = 7;
144 packet.timestamp = 7;
145 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000146 dec_state.SetState(&frame);
147 EXPECT_FALSE(dec_state.full_sync());
148 frame.Reset();
Philip Eliasson1811c042018-09-07 12:35:23 +0000149 packet.video_header.vp8().tl0PicIdx = 0x0000;
150 packet.video_header.vp8().temporalIdx = 0;
151 packet.video_header.vp8().pictureId = 7;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000152 packet.seqNum = 8;
153 packet.timestamp = 8;
154 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000155 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
156 // The current frame is not continuous
157 dec_state.SetState(&frame);
158 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000159}
160
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000161TEST(TestDecodingState, UpdateOldPacket) {
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000162 VCMDecodingState dec_state;
163 // Update only if zero size and newer than previous.
164 // Should only update if the timeStamp match.
165 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000166 VCMPacket packet;
167 packet.timestamp = 1;
168 packet.seqNum = 1;
169 packet.frameType = kVideoFrameDelta;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000170 FrameData frame_data;
171 frame_data.rtt_ms = 0;
172 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000173 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000174 dec_state.SetState(&frame);
175 EXPECT_EQ(dec_state.sequence_num(), 1);
176 // Insert an empty packet that does not belong to the same frame.
177 // => Sequence num should be the same.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000178 packet.timestamp = 2;
179 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000180 EXPECT_EQ(dec_state.sequence_num(), 1);
181 // Now insert empty packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000182 packet.timestamp = 1;
183 packet.seqNum = 2;
pbos22993e12015-10-19 02:39:06 -0700184 packet.frameType = kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000185 packet.sizeBytes = 0;
186 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000187 EXPECT_EQ(dec_state.sequence_num(), 2);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000188 // Now insert delta packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000189 packet.timestamp = 1;
190 packet.seqNum = 3;
191 packet.frameType = kVideoFrameDelta;
192 packet.sizeBytes = 1400;
193 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000194 EXPECT_EQ(dec_state.sequence_num(), 3);
195 // Insert a packet belonging to an older timestamp - should not update the
196 // sequence number.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000197 packet.timestamp = 0;
198 packet.seqNum = 4;
pbos22993e12015-10-19 02:39:06 -0700199 packet.frameType = kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000200 packet.sizeBytes = 0;
201 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000202 EXPECT_EQ(dec_state.sequence_num(), 3);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000203}
204
205TEST(TestDecodingState, MultiLayerBehavior) {
206 // Identify sync/non-sync when more than one layer.
207 VCMDecodingState dec_state;
208 // Identify packets belonging to old frames/packets.
209 // Set state for current frames.
210 // tl0PicIdx 0, temporal id 0.
211 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000212 VCMPacket packet;
213 packet.frameType = kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200214 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000215 packet.timestamp = 0;
216 packet.seqNum = 0;
Philip Eliasson1811c042018-09-07 12:35:23 +0000217 packet.video_header.vp8().tl0PicIdx = 0;
218 packet.video_header.vp8().temporalIdx = 0;
219 packet.video_header.vp8().pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000220 FrameData frame_data;
221 frame_data.rtt_ms = 0;
222 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000223 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000224 dec_state.SetState(&frame);
225 // tl0PicIdx 0, temporal id 1.
226 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000227 packet.timestamp = 1;
228 packet.seqNum = 1;
Philip Eliasson1811c042018-09-07 12:35:23 +0000229 packet.video_header.vp8().tl0PicIdx = 0;
230 packet.video_header.vp8().temporalIdx = 1;
231 packet.video_header.vp8().pictureId = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000232 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000233 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
234 dec_state.SetState(&frame);
235 EXPECT_TRUE(dec_state.full_sync());
236 // Lost tl0PicIdx 0, temporal id 2.
237 // Insert tl0PicIdx 0, temporal id 3.
238 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000239 packet.timestamp = 3;
240 packet.seqNum = 3;
Philip Eliasson1811c042018-09-07 12:35:23 +0000241 packet.video_header.vp8().tl0PicIdx = 0;
242 packet.video_header.vp8().temporalIdx = 3;
243 packet.video_header.vp8().pictureId = 3;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000244 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000245 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
246 dec_state.SetState(&frame);
247 EXPECT_FALSE(dec_state.full_sync());
248 // Insert next base layer
249 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000250 packet.timestamp = 4;
251 packet.seqNum = 4;
Philip Eliasson1811c042018-09-07 12:35:23 +0000252 packet.video_header.vp8().tl0PicIdx = 1;
253 packet.video_header.vp8().temporalIdx = 0;
254 packet.video_header.vp8().pictureId = 4;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000255 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000256 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
257 dec_state.SetState(&frame);
258 EXPECT_FALSE(dec_state.full_sync());
259 // Insert key frame - should update sync value.
260 // A key frame is always a base layer.
261 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000262 packet.frameType = kVideoFrameKey;
johan0d1b2b62017-01-10 04:21:35 -0800263 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000264 packet.timestamp = 5;
265 packet.seqNum = 5;
Philip Eliasson1811c042018-09-07 12:35:23 +0000266 packet.video_header.vp8().tl0PicIdx = 2;
267 packet.video_header.vp8().temporalIdx = 0;
268 packet.video_header.vp8().pictureId = 5;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000269 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000270 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
271 dec_state.SetState(&frame);
272 EXPECT_TRUE(dec_state.full_sync());
273 // After sync, a continuous PictureId is required
274 // (continuous base layer is not enough )
275 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000276 packet.frameType = kVideoFrameDelta;
277 packet.timestamp = 6;
278 packet.seqNum = 6;
Philip Eliasson1811c042018-09-07 12:35:23 +0000279 packet.video_header.vp8().tl0PicIdx = 3;
280 packet.video_header.vp8().temporalIdx = 0;
281 packet.video_header.vp8().pictureId = 6;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000282 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000283 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
284 EXPECT_TRUE(dec_state.full_sync());
285 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000286 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800287 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000288 packet.timestamp = 8;
289 packet.seqNum = 8;
Philip Eliasson1811c042018-09-07 12:35:23 +0000290 packet.video_header.vp8().tl0PicIdx = 4;
291 packet.video_header.vp8().temporalIdx = 0;
292 packet.video_header.vp8().pictureId = 8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000293 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000294 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
295 EXPECT_TRUE(dec_state.full_sync());
296 dec_state.SetState(&frame);
297 EXPECT_FALSE(dec_state.full_sync());
298
299 // Insert a non-ref frame - should update sync value.
300 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000301 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800302 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000303 packet.timestamp = 9;
304 packet.seqNum = 9;
Philip Eliasson1811c042018-09-07 12:35:23 +0000305 packet.video_header.vp8().tl0PicIdx = 4;
306 packet.video_header.vp8().temporalIdx = 2;
307 packet.video_header.vp8().pictureId = 9;
308 packet.video_header.vp8().layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000309 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000310 dec_state.SetState(&frame);
311 EXPECT_TRUE(dec_state.full_sync());
312
313 // The following test will verify the sync flag behavior after a loss.
314 // Create the following pattern:
315 // Update base layer, lose packet 1 (sync flag on, layer 2), insert packet 3
316 // (sync flag on, layer 2) check continuity and sync flag after inserting
317 // packet 2 (sync flag on, layer 1).
318 // Base layer.
319 frame.Reset();
320 dec_state.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000321 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800322 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000323 packet.markerBit = 1;
324 packet.timestamp = 0;
325 packet.seqNum = 0;
Philip Eliasson1811c042018-09-07 12:35:23 +0000326 packet.video_header.vp8().tl0PicIdx = 0;
327 packet.video_header.vp8().temporalIdx = 0;
328 packet.video_header.vp8().pictureId = 0;
329 packet.video_header.vp8().layerSync = false;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000330 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000331 dec_state.SetState(&frame);
332 EXPECT_TRUE(dec_state.full_sync());
333 // Layer 2 - 2 packets (insert one, lose one).
334 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000335 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800336 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000337 packet.markerBit = 0;
338 packet.timestamp = 1;
339 packet.seqNum = 1;
Philip Eliasson1811c042018-09-07 12:35:23 +0000340 packet.video_header.vp8().tl0PicIdx = 0;
341 packet.video_header.vp8().temporalIdx = 2;
342 packet.video_header.vp8().pictureId = 1;
343 packet.video_header.vp8().layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000344 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000345 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
346 // Layer 1
347 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000348 packet.frameType = kVideoFrameDelta;
johan0d1b2b62017-01-10 04:21:35 -0800349 packet.is_first_packet_in_frame = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000350 packet.markerBit = 1;
351 packet.timestamp = 2;
352 packet.seqNum = 3;
Philip Eliasson1811c042018-09-07 12:35:23 +0000353 packet.video_header.vp8().tl0PicIdx = 0;
354 packet.video_header.vp8().temporalIdx = 1;
355 packet.video_header.vp8().pictureId = 2;
356 packet.video_header.vp8().layerSync = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000357 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000358 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
359 EXPECT_TRUE(dec_state.full_sync());
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000360}
361
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000362TEST(TestDecodingState, DiscontinuousPicIdContinuousSeqNum) {
363 VCMDecodingState dec_state;
364 VCMFrameBuffer frame;
365 VCMPacket packet;
366 frame.Reset();
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000367 packet.frameType = kVideoFrameKey;
Niels Möller520ca4e2018-06-04 11:14:38 +0200368 packet.video_header.codec = kVideoCodecVP8;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000369 packet.timestamp = 0;
370 packet.seqNum = 0;
Philip Eliasson1811c042018-09-07 12:35:23 +0000371 packet.video_header.vp8().tl0PicIdx = 0;
372 packet.video_header.vp8().temporalIdx = 0;
373 packet.video_header.vp8().pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000374 FrameData frame_data;
375 frame_data.rtt_ms = 0;
376 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000377 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000378 dec_state.SetState(&frame);
379 EXPECT_TRUE(dec_state.full_sync());
380
381 // Continuous sequence number but discontinuous picture id. This implies a
382 // a loss and we have to fall back to only decoding the base layer.
383 frame.Reset();
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000384 packet.frameType = kVideoFrameDelta;
385 packet.timestamp += 3000;
386 ++packet.seqNum;
Philip Eliasson1811c042018-09-07 12:35:23 +0000387 packet.video_header.vp8().temporalIdx = 1;
388 packet.video_header.vp8().pictureId = 2;
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +0000389 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000390 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
391 dec_state.SetState(&frame);
392 EXPECT_FALSE(dec_state.full_sync());
393}
394
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000395TEST(TestDecodingState, OldInput) {
396 VCMDecodingState dec_state;
397 // Identify packets belonging to old frames/packets.
398 // Set state for current frames.
399 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000400 VCMPacket packet;
401 packet.timestamp = 10;
402 packet.seqNum = 1;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000403 FrameData frame_data;
404 frame_data.rtt_ms = 0;
405 frame_data.rolling_average_packets_per_frame = -1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000406 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000407 dec_state.SetState(&frame);
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000408 packet.timestamp = 9;
409 EXPECT_TRUE(dec_state.IsOldPacket(&packet));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000410 // Check for old frame
411 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000412 frame.InsertPacket(packet, 0, kNoErrors, frame_data);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000413 EXPECT_TRUE(dec_state.IsOldFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000414}
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000415
416TEST(TestDecodingState, PictureIdRepeat) {
417 VCMDecodingState dec_state;
418 VCMFrameBuffer frame;
419 VCMPacket packet;
420 packet.frameType = kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200421 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000422 packet.timestamp = 0;
423 packet.seqNum = 0;
Philip Eliasson1811c042018-09-07 12:35:23 +0000424 packet.video_header.vp8().tl0PicIdx = 0;
425 packet.video_header.vp8().temporalIdx = 0;
426 packet.video_header.vp8().pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000427 FrameData frame_data;
428 frame_data.rtt_ms = 0;
429 frame_data.rolling_average_packets_per_frame = -1;
430 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
431 dec_state.SetState(&frame);
432 // tl0PicIdx 0, temporal id 1.
433 frame.Reset();
434 ++packet.timestamp;
435 ++packet.seqNum;
Philip Eliasson1811c042018-09-07 12:35:23 +0000436 packet.video_header.vp8().temporalIdx++;
437 packet.video_header.vp8().pictureId++;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000438 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
439 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
440 frame.Reset();
441 // Testing only gap in tl0PicIdx when tl0PicIdx in continuous.
Philip Eliasson1811c042018-09-07 12:35:23 +0000442 packet.video_header.vp8().tl0PicIdx += 3;
443 packet.video_header.vp8().temporalIdx++;
444 packet.video_header.vp8().tl0PicIdx = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000445 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
446 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
447}
448
philipelcfc319b2015-11-10 07:17:23 -0800449TEST(TestDecodingState, FrameContinuityFlexibleModeKeyFrame) {
450 VCMDecodingState dec_state;
451 VCMFrameBuffer frame;
452 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800453 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800454 packet.timestamp = 1;
455 packet.seqNum = 0xffff;
456 uint8_t data[] = "I need a data pointer for this test!";
457 packet.sizeBytes = sizeof(data);
458 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200459 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800460
philipel29d88462018-08-08 14:26:00 +0200461 auto& vp9_hdr =
462 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800463 vp9_hdr.picture_id = 10;
464 vp9_hdr.flexible_mode = true;
465
466 FrameData frame_data;
467 frame_data.rtt_ms = 0;
468 frame_data.rolling_average_packets_per_frame = -1;
469
470 // Key frame as first frame
471 packet.frameType = kVideoFrameKey;
472 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
473 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
474 dec_state.SetState(&frame);
475
476 // Key frame again
477 vp9_hdr.picture_id = 11;
478 frame.Reset();
479 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
480 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
481 dec_state.SetState(&frame);
482
483 // Ref to 11, continuous
484 frame.Reset();
485 packet.frameType = kVideoFrameDelta;
486 vp9_hdr.picture_id = 12;
487 vp9_hdr.num_ref_pics = 1;
488 vp9_hdr.pid_diff[0] = 1;
489 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
490 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
491}
492
493TEST(TestDecodingState, FrameContinuityFlexibleModeOutOfOrderFrames) {
494 VCMDecodingState dec_state;
495 VCMFrameBuffer frame;
496 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800497 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800498 packet.timestamp = 1;
499 packet.seqNum = 0xffff;
500 uint8_t data[] = "I need a data pointer for this test!";
501 packet.sizeBytes = sizeof(data);
502 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200503 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800504
philipel29d88462018-08-08 14:26:00 +0200505 auto& vp9_hdr =
506 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800507 vp9_hdr.picture_id = 10;
508 vp9_hdr.flexible_mode = true;
509
510 FrameData frame_data;
511 frame_data.rtt_ms = 0;
512 frame_data.rolling_average_packets_per_frame = -1;
513
514 // Key frame as first frame
515 packet.frameType = kVideoFrameKey;
516 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
517 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
518 dec_state.SetState(&frame);
519
520 // Ref to 10, continuous
521 frame.Reset();
522 packet.frameType = kVideoFrameDelta;
523 vp9_hdr.picture_id = 15;
524 vp9_hdr.num_ref_pics = 1;
525 vp9_hdr.pid_diff[0] = 5;
526 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
527 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
528 dec_state.SetState(&frame);
529
530 // Out of order, last id 15, this id 12, ref to 10, continuous
531 frame.Reset();
532 vp9_hdr.picture_id = 12;
533 vp9_hdr.pid_diff[0] = 2;
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 // Ref 10, 12, 15, continuous
539 frame.Reset();
540 vp9_hdr.picture_id = 20;
541 vp9_hdr.num_ref_pics = 3;
542 vp9_hdr.pid_diff[0] = 10;
543 vp9_hdr.pid_diff[1] = 8;
544 vp9_hdr.pid_diff[2] = 5;
545 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
546 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
547}
548
549TEST(TestDecodingState, FrameContinuityFlexibleModeGeneral) {
550 VCMDecodingState dec_state;
551 VCMFrameBuffer frame;
552 VCMPacket packet;
johan0d1b2b62017-01-10 04:21:35 -0800553 packet.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800554 packet.timestamp = 1;
555 packet.seqNum = 0xffff;
556 uint8_t data[] = "I need a data pointer for this test!";
557 packet.sizeBytes = sizeof(data);
558 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200559 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800560
philipel29d88462018-08-08 14:26:00 +0200561 auto& vp9_hdr =
562 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800563 vp9_hdr.picture_id = 10;
564 vp9_hdr.flexible_mode = true;
565
566 FrameData frame_data;
567 frame_data.rtt_ms = 0;
568 frame_data.rolling_average_packets_per_frame = -1;
569
570 // Key frame as first frame
571 packet.frameType = kVideoFrameKey;
572 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
573 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
574
575 // Delta frame as first frame
576 frame.Reset();
577 packet.frameType = kVideoFrameDelta;
578 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
579 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
580
581 // Key frame then delta frame
582 frame.Reset();
583 packet.frameType = kVideoFrameKey;
584 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
585 dec_state.SetState(&frame);
586 frame.Reset();
587 packet.frameType = kVideoFrameDelta;
588 vp9_hdr.num_ref_pics = 1;
589 vp9_hdr.picture_id = 15;
590 vp9_hdr.pid_diff[0] = 5;
591 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
592 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
593 dec_state.SetState(&frame);
594
595 // Ref to 11, not continuous
596 frame.Reset();
597 vp9_hdr.picture_id = 16;
598 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
599 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
600
601 // Ref to 15, continuous
602 frame.Reset();
603 vp9_hdr.picture_id = 16;
604 vp9_hdr.pid_diff[0] = 1;
605 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
606 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
607 dec_state.SetState(&frame);
608
609 // Ref to 11 and 15, not continuous
610 frame.Reset();
611 vp9_hdr.picture_id = 20;
612 vp9_hdr.num_ref_pics = 2;
613 vp9_hdr.pid_diff[0] = 9;
614 vp9_hdr.pid_diff[1] = 5;
615 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
616 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
617
618 // Ref to 10, 15 and 16, continuous
619 frame.Reset();
620 vp9_hdr.picture_id = 22;
621 vp9_hdr.num_ref_pics = 3;
622 vp9_hdr.pid_diff[0] = 12;
623 vp9_hdr.pid_diff[1] = 7;
624 vp9_hdr.pid_diff[2] = 6;
625 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
626 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
627 dec_state.SetState(&frame);
628
629 // Key Frame, continuous
630 frame.Reset();
631 packet.frameType = kVideoFrameKey;
632 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 2;
633 vp9_hdr.num_ref_pics = 0;
634 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
635 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
636 dec_state.SetState(&frame);
637
638 // Frame at last index, ref to KF, continuous
639 frame.Reset();
640 packet.frameType = kVideoFrameDelta;
641 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 1;
642 vp9_hdr.num_ref_pics = 1;
643 vp9_hdr.pid_diff[0] = 1;
644 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
645 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
646 dec_state.SetState(&frame);
647
648 // Frame after wrapping buffer length, ref to last index, continuous
649 frame.Reset();
650 vp9_hdr.picture_id = 0;
651 vp9_hdr.num_ref_pics = 1;
652 vp9_hdr.pid_diff[0] = 1;
653 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
654 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
655 dec_state.SetState(&frame);
656
657 // Frame after wrapping start frame, ref to 0, continuous
658 frame.Reset();
659 vp9_hdr.picture_id = 20;
660 vp9_hdr.num_ref_pics = 1;
661 vp9_hdr.pid_diff[0] = 20;
662 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
663 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
664 dec_state.SetState(&frame);
665
666 // Frame after wrapping start frame, ref to 10, not continuous
667 frame.Reset();
668 vp9_hdr.picture_id = 23;
669 vp9_hdr.num_ref_pics = 1;
670 vp9_hdr.pid_diff[0] = 13;
671 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
672 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
673
674 // Key frame, continuous
675 frame.Reset();
676 packet.frameType = kVideoFrameKey;
677 vp9_hdr.picture_id = 25;
678 vp9_hdr.num_ref_pics = 0;
679 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
680 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
681 dec_state.SetState(&frame);
682
683 // Ref to KF, continuous
684 frame.Reset();
685 packet.frameType = kVideoFrameDelta;
686 vp9_hdr.picture_id = 26;
687 vp9_hdr.num_ref_pics = 1;
688 vp9_hdr.pid_diff[0] = 1;
689 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
690 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
691 dec_state.SetState(&frame);
692
693 // Ref to frame previous to KF, not continuous
694 frame.Reset();
695 vp9_hdr.picture_id = 30;
696 vp9_hdr.num_ref_pics = 1;
697 vp9_hdr.pid_diff[0] = 30;
698 EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data));
699 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
700}
701
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000702} // namespace webrtc