blob: 1ecb9b22e2b25ea9e54edd9afada7bdbb1b0c028 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/decoding_state.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012#include "modules/rtp_rtcp/source/rtp_video_header.h"
13#include "modules/video_coding/codecs/interface/common_constants.h"
14#include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
15#include "modules/video_coding/codecs/vp9/include/vp9_globals.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/video_coding/frame_buffer.h"
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "modules/video_coding/include/video_coding.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/video_coding/packet.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "modules/video_coding/session_info.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "test/gtest.h"
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000021
22namespace webrtc {
23
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000024TEST(TestDecodingState, Sanity) {
25 VCMDecodingState dec_state;
26 dec_state.Reset();
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000027 EXPECT_TRUE(dec_state.in_initial_state());
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000028 EXPECT_TRUE(dec_state.full_sync());
29}
30
31TEST(TestDecodingState, FrameContinuity) {
32 VCMDecodingState dec_state;
33 // Check that makes decision based on correct method.
andrew@webrtc.orgdf9c0e52013-04-24 02:13:18 +000034 VCMFrameBuffer frame;
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000035 VCMFrameBuffer frame_key;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000036 VCMPacket packet;
Niels Möllerd5e02f02019-02-20 13:12:21 +010037 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000038 packet.timestamp = 1;
39 packet.seqNum = 0xffff;
Niels Möllerabbc50e2019-04-24 09:41:16 +020040 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +020041 packet.video_header.codec = kVideoCodecVP8;
Philip Eliassond52a1a62018-09-07 13:03:55 +000042 auto& vp8_header =
43 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
44 vp8_header.pictureId = 0x007F;
agalusza@google.comd818dcb2013-07-29 21:48:11 +000045 FrameData frame_data;
46 frame_data.rtt_ms = 0;
47 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +010048 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000049 // Always start with a key frame.
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000050 dec_state.Reset();
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000051 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
Niels Möllerabbc50e2019-04-24 09:41:16 +020052 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller375b3462019-01-10 15:35:56 +010053 EXPECT_LE(0, frame_key.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org8392cd92013-04-25 21:30:50 +000054 EXPECT_TRUE(dec_state.ContinuousFrame(&frame_key));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000055 dec_state.SetState(&frame);
56 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +020057 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000058 // Use pictureId
Niels Möllerd5e02f02019-02-20 13:12:21 +010059 packet.video_header.is_first_packet_in_frame = false;
Philip Eliassond52a1a62018-09-07 13:03:55 +000060 vp8_header.pictureId = 0x0002;
Niels Möller375b3462019-01-10 15:35:56 +010061 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000062 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
63 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +000064 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000065 packet.seqNum = 10;
Niels Möller375b3462019-01-10 15:35:56 +010066 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000067 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
68
69 // Use sequence numbers.
Philip Eliassond52a1a62018-09-07 13:03:55 +000070 vp8_header.pictureId = kNoPictureId;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000071 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000072 packet.seqNum = dec_state.sequence_num() - 1u;
Niels Möller375b3462019-01-10 15:35:56 +010073 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000074 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
75 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000076 packet.seqNum = dec_state.sequence_num() + 1u;
Niels Möller375b3462019-01-10 15:35:56 +010077 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000078 // Insert another packet to this frame
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000079 packet.seqNum++;
Niels Möller375b3462019-01-10 15:35:56 +010080 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000081 // Verify wrap.
mikhal@webrtc.orgf31a47a2013-08-26 17:10:11 +000082 EXPECT_LE(dec_state.sequence_num(), 0xffff);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000083 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
84 dec_state.SetState(&frame);
85
86 // Insert packet with temporal info.
87 dec_state.Reset();
88 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +000089 vp8_header.tl0PicIdx = 0;
90 vp8_header.temporalIdx = 0;
91 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +000092 packet.seqNum = 1;
93 packet.timestamp = 1;
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000094 EXPECT_TRUE(dec_state.full_sync());
Niels Möller375b3462019-01-10 15:35:56 +010095 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000096 dec_state.SetState(&frame);
97 EXPECT_TRUE(dec_state.full_sync());
98 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +000099 // 1 layer up - still good.
Philip Eliassond52a1a62018-09-07 13:03:55 +0000100 vp8_header.tl0PicIdx = 0;
101 vp8_header.temporalIdx = 1;
102 vp8_header.pictureId = 1;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000103 packet.seqNum = 2;
104 packet.timestamp = 2;
Niels Möller375b3462019-01-10 15:35:56 +0100105 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000106 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
107 dec_state.SetState(&frame);
108 EXPECT_TRUE(dec_state.full_sync());
109 frame.Reset();
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000110 // Lost non-base layer packet => should update sync parameter.
Philip Eliassond52a1a62018-09-07 13:03:55 +0000111 vp8_header.tl0PicIdx = 0;
112 vp8_header.temporalIdx = 3;
113 vp8_header.pictureId = 3;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000114 packet.seqNum = 4;
115 packet.timestamp = 4;
Niels Möller375b3462019-01-10 15:35:56 +0100116 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000117 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
118 // Now insert the next non-base layer (belonging to a next tl0PicId).
119 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000120 vp8_header.tl0PicIdx = 1;
121 vp8_header.temporalIdx = 2;
122 vp8_header.pictureId = 4;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000123 packet.seqNum = 5;
124 packet.timestamp = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100125 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000126 // Checking continuity and not updating the state - this should not trigger
127 // an update of sync state.
128 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
129 EXPECT_TRUE(dec_state.full_sync());
130 // Next base layer (dropped interim non-base layers) - should update sync.
131 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000132 vp8_header.tl0PicIdx = 1;
133 vp8_header.temporalIdx = 0;
134 vp8_header.pictureId = 5;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000135 packet.seqNum = 6;
136 packet.timestamp = 6;
Niels Möller375b3462019-01-10 15:35:56 +0100137 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000138 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
139 dec_state.SetState(&frame);
140 EXPECT_FALSE(dec_state.full_sync());
141
142 // Check wrap for temporal layers.
143 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000144 vp8_header.tl0PicIdx = 0x00FF;
145 vp8_header.temporalIdx = 0;
146 vp8_header.pictureId = 6;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000147 packet.seqNum = 7;
148 packet.timestamp = 7;
Niels Möller375b3462019-01-10 15:35:56 +0100149 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000150 dec_state.SetState(&frame);
151 EXPECT_FALSE(dec_state.full_sync());
152 frame.Reset();
Philip Eliassond52a1a62018-09-07 13:03:55 +0000153 vp8_header.tl0PicIdx = 0x0000;
154 vp8_header.temporalIdx = 0;
155 vp8_header.pictureId = 7;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000156 packet.seqNum = 8;
157 packet.timestamp = 8;
Niels Möller375b3462019-01-10 15:35:56 +0100158 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000159 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
160 // The current frame is not continuous
161 dec_state.SetState(&frame);
162 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000163}
164
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000165TEST(TestDecodingState, UpdateOldPacket) {
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000166 VCMDecodingState dec_state;
167 // Update only if zero size and newer than previous.
168 // Should only update if the timeStamp match.
169 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000170 VCMPacket packet;
171 packet.timestamp = 1;
172 packet.seqNum = 1;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200173 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000174 FrameData frame_data;
175 frame_data.rtt_ms = 0;
176 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +0100177 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000178 dec_state.SetState(&frame);
179 EXPECT_EQ(dec_state.sequence_num(), 1);
180 // Insert an empty packet that does not belong to the same frame.
181 // => Sequence num should be the same.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000182 packet.timestamp = 2;
183 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000184 EXPECT_EQ(dec_state.sequence_num(), 1);
185 // Now insert empty packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000186 packet.timestamp = 1;
187 packet.seqNum = 2;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200188 packet.video_header.frame_type = VideoFrameType::kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000189 packet.sizeBytes = 0;
190 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000191 EXPECT_EQ(dec_state.sequence_num(), 2);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000192 // Now insert delta packet belonging to the same frame.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000193 packet.timestamp = 1;
194 packet.seqNum = 3;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200195 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000196 packet.sizeBytes = 1400;
197 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000198 EXPECT_EQ(dec_state.sequence_num(), 3);
199 // Insert a packet belonging to an older timestamp - should not update the
200 // sequence number.
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000201 packet.timestamp = 0;
202 packet.seqNum = 4;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200203 packet.video_header.frame_type = VideoFrameType::kEmptyFrame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000204 packet.sizeBytes = 0;
205 dec_state.UpdateOldPacket(&packet);
mikhal@webrtc.org77c425b2012-01-03 20:35:25 +0000206 EXPECT_EQ(dec_state.sequence_num(), 3);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000207}
208
209TEST(TestDecodingState, MultiLayerBehavior) {
210 // Identify sync/non-sync when more than one layer.
211 VCMDecodingState dec_state;
212 // Identify packets belonging to old frames/packets.
213 // Set state for current frames.
214 // tl0PicIdx 0, temporal id 0.
215 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000216 VCMPacket packet;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200217 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200218 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000219 packet.timestamp = 0;
220 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000221 auto& vp8_header =
222 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
223 vp8_header.tl0PicIdx = 0;
224 vp8_header.temporalIdx = 0;
225 vp8_header.pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000226 FrameData frame_data;
227 frame_data.rtt_ms = 0;
228 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +0100229 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000230 dec_state.SetState(&frame);
231 // tl0PicIdx 0, temporal id 1.
232 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000233 packet.timestamp = 1;
234 packet.seqNum = 1;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000235 vp8_header.tl0PicIdx = 0;
236 vp8_header.temporalIdx = 1;
237 vp8_header.pictureId = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100238 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000239 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
240 dec_state.SetState(&frame);
241 EXPECT_TRUE(dec_state.full_sync());
242 // Lost tl0PicIdx 0, temporal id 2.
243 // Insert tl0PicIdx 0, temporal id 3.
244 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000245 packet.timestamp = 3;
246 packet.seqNum = 3;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000247 vp8_header.tl0PicIdx = 0;
248 vp8_header.temporalIdx = 3;
249 vp8_header.pictureId = 3;
Niels Möller375b3462019-01-10 15:35:56 +0100250 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000251 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
252 dec_state.SetState(&frame);
253 EXPECT_FALSE(dec_state.full_sync());
254 // Insert next base layer
255 frame.Reset();
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000256 packet.timestamp = 4;
257 packet.seqNum = 4;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000258 vp8_header.tl0PicIdx = 1;
259 vp8_header.temporalIdx = 0;
260 vp8_header.pictureId = 4;
Niels Möller375b3462019-01-10 15:35:56 +0100261 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000262 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
263 dec_state.SetState(&frame);
264 EXPECT_FALSE(dec_state.full_sync());
265 // Insert key frame - should update sync value.
266 // A key frame is always a base layer.
267 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200268 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100269 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000270 packet.timestamp = 5;
271 packet.seqNum = 5;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000272 vp8_header.tl0PicIdx = 2;
273 vp8_header.temporalIdx = 0;
274 vp8_header.pictureId = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100275 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000276 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
277 dec_state.SetState(&frame);
278 EXPECT_TRUE(dec_state.full_sync());
279 // After sync, a continuous PictureId is required
280 // (continuous base layer is not enough )
281 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200282 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000283 packet.timestamp = 6;
284 packet.seqNum = 6;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000285 vp8_header.tl0PicIdx = 3;
286 vp8_header.temporalIdx = 0;
287 vp8_header.pictureId = 6;
Niels Möller375b3462019-01-10 15:35:56 +0100288 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000289 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
290 EXPECT_TRUE(dec_state.full_sync());
291 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200292 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100293 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000294 packet.timestamp = 8;
295 packet.seqNum = 8;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000296 vp8_header.tl0PicIdx = 4;
297 vp8_header.temporalIdx = 0;
298 vp8_header.pictureId = 8;
Niels Möller375b3462019-01-10 15:35:56 +0100299 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000300 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
301 EXPECT_TRUE(dec_state.full_sync());
302 dec_state.SetState(&frame);
303 EXPECT_FALSE(dec_state.full_sync());
304
305 // Insert a non-ref frame - should update sync value.
306 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200307 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100308 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000309 packet.timestamp = 9;
310 packet.seqNum = 9;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000311 vp8_header.tl0PicIdx = 4;
312 vp8_header.temporalIdx = 2;
313 vp8_header.pictureId = 9;
314 vp8_header.layerSync = true;
Niels Möller375b3462019-01-10 15:35:56 +0100315 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000316 dec_state.SetState(&frame);
317 EXPECT_TRUE(dec_state.full_sync());
318
319 // The following test will verify the sync flag behavior after a loss.
320 // Create the following pattern:
321 // Update base layer, lose packet 1 (sync flag on, layer 2), insert packet 3
322 // (sync flag on, layer 2) check continuity and sync flag after inserting
323 // packet 2 (sync flag on, layer 1).
324 // Base layer.
325 frame.Reset();
326 dec_state.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200327 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100328 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000329 packet.markerBit = 1;
330 packet.timestamp = 0;
331 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000332 vp8_header.tl0PicIdx = 0;
333 vp8_header.temporalIdx = 0;
334 vp8_header.pictureId = 0;
335 vp8_header.layerSync = false;
Niels Möller375b3462019-01-10 15:35:56 +0100336 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000337 dec_state.SetState(&frame);
338 EXPECT_TRUE(dec_state.full_sync());
339 // Layer 2 - 2 packets (insert one, lose one).
340 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200341 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100342 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000343 packet.markerBit = 0;
344 packet.timestamp = 1;
345 packet.seqNum = 1;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000346 vp8_header.tl0PicIdx = 0;
347 vp8_header.temporalIdx = 2;
348 vp8_header.pictureId = 1;
349 vp8_header.layerSync = true;
Niels Möller375b3462019-01-10 15:35:56 +0100350 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000351 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
352 // Layer 1
353 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200354 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100355 packet.video_header.is_first_packet_in_frame = true;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000356 packet.markerBit = 1;
357 packet.timestamp = 2;
358 packet.seqNum = 3;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000359 vp8_header.tl0PicIdx = 0;
360 vp8_header.temporalIdx = 1;
361 vp8_header.pictureId = 2;
362 vp8_header.layerSync = true;
Niels Möller375b3462019-01-10 15:35:56 +0100363 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000364 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
365 EXPECT_TRUE(dec_state.full_sync());
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000366}
367
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000368TEST(TestDecodingState, DiscontinuousPicIdContinuousSeqNum) {
369 VCMDecodingState dec_state;
370 VCMFrameBuffer frame;
371 VCMPacket packet;
372 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200373 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller520ca4e2018-06-04 11:14:38 +0200374 packet.video_header.codec = kVideoCodecVP8;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000375 packet.timestamp = 0;
376 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000377 auto& vp8_header =
378 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
379 vp8_header.tl0PicIdx = 0;
380 vp8_header.temporalIdx = 0;
381 vp8_header.pictureId = 0;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000382 FrameData frame_data;
383 frame_data.rtt_ms = 0;
384 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +0100385 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000386 dec_state.SetState(&frame);
387 EXPECT_TRUE(dec_state.full_sync());
388
389 // Continuous sequence number but discontinuous picture id. This implies a
390 // a loss and we have to fall back to only decoding the base layer.
391 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200392 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000393 packet.timestamp += 3000;
394 ++packet.seqNum;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000395 vp8_header.temporalIdx = 1;
396 vp8_header.pictureId = 2;
Niels Möller375b3462019-01-10 15:35:56 +0100397 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
stefan@webrtc.orge72e9ee2012-09-19 11:08:05 +0000398 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
399 dec_state.SetState(&frame);
400 EXPECT_FALSE(dec_state.full_sync());
401}
402
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000403TEST(TestDecodingState, OldInput) {
404 VCMDecodingState dec_state;
405 // Identify packets belonging to old frames/packets.
406 // Set state for current frames.
407 VCMFrameBuffer frame;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000408 VCMPacket packet;
409 packet.timestamp = 10;
410 packet.seqNum = 1;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000411 FrameData frame_data;
412 frame_data.rtt_ms = 0;
413 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +0100414 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000415 dec_state.SetState(&frame);
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000416 packet.timestamp = 9;
417 EXPECT_TRUE(dec_state.IsOldPacket(&packet));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000418 // Check for old frame
419 frame.Reset();
Niels Möller375b3462019-01-10 15:35:56 +0100420 frame.InsertPacket(packet, 0, frame_data);
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000421 EXPECT_TRUE(dec_state.IsOldFrame(&frame));
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000422}
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000423
424TEST(TestDecodingState, PictureIdRepeat) {
425 VCMDecodingState dec_state;
426 VCMFrameBuffer frame;
427 VCMPacket packet;
Niels Möllerabbc50e2019-04-24 09:41:16 +0200428 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möller520ca4e2018-06-04 11:14:38 +0200429 packet.video_header.codec = kVideoCodecVP8;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000430 packet.timestamp = 0;
431 packet.seqNum = 0;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000432 auto& vp8_header =
433 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>();
434 vp8_header.tl0PicIdx = 0;
435 vp8_header.temporalIdx = 0;
436 vp8_header.pictureId = 0;
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000437 FrameData frame_data;
438 frame_data.rtt_ms = 0;
439 frame_data.rolling_average_packets_per_frame = -1;
Niels Möller375b3462019-01-10 15:35:56 +0100440 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000441 dec_state.SetState(&frame);
442 // tl0PicIdx 0, temporal id 1.
443 frame.Reset();
444 ++packet.timestamp;
445 ++packet.seqNum;
Philip Eliassond52a1a62018-09-07 13:03:55 +0000446 vp8_header.temporalIdx++;
447 vp8_header.pictureId++;
Niels Möller375b3462019-01-10 15:35:56 +0100448 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000449 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
450 frame.Reset();
451 // Testing only gap in tl0PicIdx when tl0PicIdx in continuous.
Philip Eliassond52a1a62018-09-07 13:03:55 +0000452 vp8_header.tl0PicIdx += 3;
453 vp8_header.temporalIdx++;
454 vp8_header.tl0PicIdx = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100455 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
mikhal@webrtc.org0aeb22e2013-10-28 22:26:14 +0000456 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
457}
458
philipelcfc319b2015-11-10 07:17:23 -0800459TEST(TestDecodingState, FrameContinuityFlexibleModeKeyFrame) {
460 VCMDecodingState dec_state;
461 VCMFrameBuffer frame;
462 VCMPacket packet;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100463 packet.video_header.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800464 packet.timestamp = 1;
465 packet.seqNum = 0xffff;
466 uint8_t data[] = "I need a data pointer for this test!";
467 packet.sizeBytes = sizeof(data);
468 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200469 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800470
philipel29d88462018-08-08 14:26:00 +0200471 auto& vp9_hdr =
472 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800473 vp9_hdr.picture_id = 10;
474 vp9_hdr.flexible_mode = true;
475
476 FrameData frame_data;
477 frame_data.rtt_ms = 0;
478 frame_data.rolling_average_packets_per_frame = -1;
479
480 // Key frame as first frame
Niels Möllerabbc50e2019-04-24 09:41:16 +0200481 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller375b3462019-01-10 15:35:56 +0100482 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800483 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
484 dec_state.SetState(&frame);
485
486 // Key frame again
487 vp9_hdr.picture_id = 11;
488 frame.Reset();
Niels Möller375b3462019-01-10 15:35:56 +0100489 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800490 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
491 dec_state.SetState(&frame);
492
493 // Ref to 11, continuous
494 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200495 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
philipelcfc319b2015-11-10 07:17:23 -0800496 vp9_hdr.picture_id = 12;
497 vp9_hdr.num_ref_pics = 1;
498 vp9_hdr.pid_diff[0] = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100499 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800500 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
501}
502
503TEST(TestDecodingState, FrameContinuityFlexibleModeOutOfOrderFrames) {
504 VCMDecodingState dec_state;
505 VCMFrameBuffer frame;
506 VCMPacket packet;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100507 packet.video_header.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800508 packet.timestamp = 1;
509 packet.seqNum = 0xffff;
510 uint8_t data[] = "I need a data pointer for this test!";
511 packet.sizeBytes = sizeof(data);
512 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200513 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800514
philipel29d88462018-08-08 14:26:00 +0200515 auto& vp9_hdr =
516 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800517 vp9_hdr.picture_id = 10;
518 vp9_hdr.flexible_mode = true;
519
520 FrameData frame_data;
521 frame_data.rtt_ms = 0;
522 frame_data.rolling_average_packets_per_frame = -1;
523
524 // Key frame as first frame
Niels Möllerabbc50e2019-04-24 09:41:16 +0200525 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller375b3462019-01-10 15:35:56 +0100526 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800527 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
528 dec_state.SetState(&frame);
529
530 // Ref to 10, continuous
531 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200532 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
philipelcfc319b2015-11-10 07:17:23 -0800533 vp9_hdr.picture_id = 15;
534 vp9_hdr.num_ref_pics = 1;
535 vp9_hdr.pid_diff[0] = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100536 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800537 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
538 dec_state.SetState(&frame);
539
540 // Out of order, last id 15, this id 12, ref to 10, continuous
541 frame.Reset();
542 vp9_hdr.picture_id = 12;
543 vp9_hdr.pid_diff[0] = 2;
Niels Möller375b3462019-01-10 15:35:56 +0100544 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800545 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
546 dec_state.SetState(&frame);
547
548 // Ref 10, 12, 15, continuous
549 frame.Reset();
550 vp9_hdr.picture_id = 20;
551 vp9_hdr.num_ref_pics = 3;
552 vp9_hdr.pid_diff[0] = 10;
553 vp9_hdr.pid_diff[1] = 8;
554 vp9_hdr.pid_diff[2] = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100555 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800556 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
557}
558
559TEST(TestDecodingState, FrameContinuityFlexibleModeGeneral) {
560 VCMDecodingState dec_state;
561 VCMFrameBuffer frame;
562 VCMPacket packet;
Niels Möllerd5e02f02019-02-20 13:12:21 +0100563 packet.video_header.is_first_packet_in_frame = true;
philipelcfc319b2015-11-10 07:17:23 -0800564 packet.timestamp = 1;
565 packet.seqNum = 0xffff;
566 uint8_t data[] = "I need a data pointer for this test!";
567 packet.sizeBytes = sizeof(data);
568 packet.dataPtr = data;
Niels Möller520ca4e2018-06-04 11:14:38 +0200569 packet.video_header.codec = kVideoCodecVP9;
philipelcfc319b2015-11-10 07:17:23 -0800570
philipel29d88462018-08-08 14:26:00 +0200571 auto& vp9_hdr =
572 packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>();
philipelcfc319b2015-11-10 07:17:23 -0800573 vp9_hdr.picture_id = 10;
574 vp9_hdr.flexible_mode = true;
575
576 FrameData frame_data;
577 frame_data.rtt_ms = 0;
578 frame_data.rolling_average_packets_per_frame = -1;
579
580 // Key frame as first frame
Niels Möllerabbc50e2019-04-24 09:41:16 +0200581 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller375b3462019-01-10 15:35:56 +0100582 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800583 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
584
585 // Delta frame as first frame
586 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200587 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
Niels Möller375b3462019-01-10 15:35:56 +0100588 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800589 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
590
591 // Key frame then delta frame
592 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200593 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
Niels Möller375b3462019-01-10 15:35:56 +0100594 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800595 dec_state.SetState(&frame);
596 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200597 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
philipelcfc319b2015-11-10 07:17:23 -0800598 vp9_hdr.num_ref_pics = 1;
599 vp9_hdr.picture_id = 15;
600 vp9_hdr.pid_diff[0] = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100601 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800602 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
603 dec_state.SetState(&frame);
604
605 // Ref to 11, not continuous
606 frame.Reset();
607 vp9_hdr.picture_id = 16;
Niels Möller375b3462019-01-10 15:35:56 +0100608 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800609 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
610
611 // Ref to 15, continuous
612 frame.Reset();
613 vp9_hdr.picture_id = 16;
614 vp9_hdr.pid_diff[0] = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100615 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800616 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
617 dec_state.SetState(&frame);
618
619 // Ref to 11 and 15, not continuous
620 frame.Reset();
621 vp9_hdr.picture_id = 20;
622 vp9_hdr.num_ref_pics = 2;
623 vp9_hdr.pid_diff[0] = 9;
624 vp9_hdr.pid_diff[1] = 5;
Niels Möller375b3462019-01-10 15:35:56 +0100625 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800626 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
627
628 // Ref to 10, 15 and 16, continuous
629 frame.Reset();
630 vp9_hdr.picture_id = 22;
631 vp9_hdr.num_ref_pics = 3;
632 vp9_hdr.pid_diff[0] = 12;
633 vp9_hdr.pid_diff[1] = 7;
634 vp9_hdr.pid_diff[2] = 6;
Niels Möller375b3462019-01-10 15:35:56 +0100635 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800636 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
637 dec_state.SetState(&frame);
638
639 // Key Frame, continuous
640 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200641 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
philipelcfc319b2015-11-10 07:17:23 -0800642 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 2;
643 vp9_hdr.num_ref_pics = 0;
Niels Möller375b3462019-01-10 15:35:56 +0100644 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800645 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
646 dec_state.SetState(&frame);
647
648 // Frame at last index, ref to KF, continuous
649 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200650 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
philipelcfc319b2015-11-10 07:17:23 -0800651 vp9_hdr.picture_id = VCMDecodingState::kFrameDecodedLength - 1;
652 vp9_hdr.num_ref_pics = 1;
653 vp9_hdr.pid_diff[0] = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100654 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800655 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
656 dec_state.SetState(&frame);
657
658 // Frame after wrapping buffer length, ref to last index, continuous
659 frame.Reset();
660 vp9_hdr.picture_id = 0;
661 vp9_hdr.num_ref_pics = 1;
662 vp9_hdr.pid_diff[0] = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100663 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800664 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
665 dec_state.SetState(&frame);
666
667 // Frame after wrapping start frame, ref to 0, continuous
668 frame.Reset();
669 vp9_hdr.picture_id = 20;
670 vp9_hdr.num_ref_pics = 1;
671 vp9_hdr.pid_diff[0] = 20;
Niels Möller375b3462019-01-10 15:35:56 +0100672 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800673 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
674 dec_state.SetState(&frame);
675
676 // Frame after wrapping start frame, ref to 10, not continuous
677 frame.Reset();
678 vp9_hdr.picture_id = 23;
679 vp9_hdr.num_ref_pics = 1;
680 vp9_hdr.pid_diff[0] = 13;
Niels Möller375b3462019-01-10 15:35:56 +0100681 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800682 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
683
684 // Key frame, continuous
685 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200686 packet.video_header.frame_type = VideoFrameType::kVideoFrameKey;
philipelcfc319b2015-11-10 07:17:23 -0800687 vp9_hdr.picture_id = 25;
688 vp9_hdr.num_ref_pics = 0;
Niels Möller375b3462019-01-10 15:35:56 +0100689 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800690 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
691 dec_state.SetState(&frame);
692
693 // Ref to KF, continuous
694 frame.Reset();
Niels Möllerabbc50e2019-04-24 09:41:16 +0200695 packet.video_header.frame_type = VideoFrameType::kVideoFrameDelta;
philipelcfc319b2015-11-10 07:17:23 -0800696 vp9_hdr.picture_id = 26;
697 vp9_hdr.num_ref_pics = 1;
698 vp9_hdr.pid_diff[0] = 1;
Niels Möller375b3462019-01-10 15:35:56 +0100699 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800700 EXPECT_TRUE(dec_state.ContinuousFrame(&frame));
701 dec_state.SetState(&frame);
702
703 // Ref to frame previous to KF, not continuous
704 frame.Reset();
705 vp9_hdr.picture_id = 30;
706 vp9_hdr.num_ref_pics = 1;
707 vp9_hdr.pid_diff[0] = 30;
Niels Möller375b3462019-01-10 15:35:56 +0100708 EXPECT_LE(0, frame.InsertPacket(packet, 0, frame_data));
philipelcfc319b2015-11-10 07:17:23 -0800709 EXPECT_FALSE(dec_state.ContinuousFrame(&frame));
710}
711
mikhal@webrtc.org62665b82011-12-29 18:09:58 +0000712} // namespace webrtc