mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #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.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 22 | TEST(TestDecodingState, Sanity) { |
| 23 | VCMDecodingState dec_state; |
| 24 | dec_state.Reset(); |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 25 | EXPECT_TRUE(dec_state.in_initial_state()); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 26 | EXPECT_TRUE(dec_state.full_sync()); |
| 27 | } |
| 28 | |
| 29 | TEST(TestDecodingState, FrameContinuity) { |
| 30 | VCMDecodingState dec_state; |
| 31 | // Check that makes decision based on correct method. |
andrew@webrtc.org | df9c0e5 | 2013-04-24 02:13:18 +0000 | [diff] [blame] | 32 | VCMFrameBuffer frame; |
mikhal@webrtc.org | 8392cd9 | 2013-04-25 21:30:50 +0000 | [diff] [blame] | 33 | VCMFrameBuffer frame_key; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 34 | VCMPacket packet; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 35 | packet.is_first_packet_in_frame = true; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 36 | packet.timestamp = 1; |
| 37 | packet.seqNum = 0xffff; |
| 38 | packet.frameType = kVideoFrameDelta; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 39 | packet.video_header.codec = kVideoCodecVP8; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 40 | auto& vp8_header = |
| 41 | packet.video_header.video_type_header.emplace<RTPVideoHeaderVP8>(); |
| 42 | vp8_header.pictureId = 0x007F; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 43 | FrameData frame_data; |
| 44 | frame_data.rtt_ms = 0; |
| 45 | frame_data.rolling_average_packets_per_frame = -1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 46 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 8392cd9 | 2013-04-25 21:30:50 +0000 | [diff] [blame] | 47 | // Always start with a key frame. |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 48 | dec_state.Reset(); |
mikhal@webrtc.org | 8392cd9 | 2013-04-25 21:30:50 +0000 | [diff] [blame] | 49 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 50 | packet.frameType = kVideoFrameKey; |
| 51 | EXPECT_LE(0, frame_key.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 8392cd9 | 2013-04-25 21:30:50 +0000 | [diff] [blame] | 52 | EXPECT_TRUE(dec_state.ContinuousFrame(&frame_key)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 53 | dec_state.SetState(&frame); |
| 54 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 55 | packet.frameType = kVideoFrameDelta; |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 56 | // Use pictureId |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 57 | packet.is_first_packet_in_frame = false; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 58 | vp8_header.pictureId = 0x0002; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 59 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 60 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 61 | frame.Reset(); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 62 | vp8_header.pictureId = 0; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 63 | packet.seqNum = 10; |
| 64 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 65 | EXPECT_TRUE(dec_state.ContinuousFrame(&frame)); |
| 66 | |
| 67 | // Use sequence numbers. |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 68 | vp8_header.pictureId = kNoPictureId; |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 69 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 70 | packet.seqNum = dec_state.sequence_num() - 1u; |
| 71 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 72 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 73 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 74 | packet.seqNum = dec_state.sequence_num() + 1u; |
| 75 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 76 | // Insert another packet to this frame |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 77 | packet.seqNum++; |
| 78 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 79 | // Verify wrap. |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 80 | EXPECT_LE(dec_state.sequence_num(), 0xffff); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 81 | 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 Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 87 | vp8_header.tl0PicIdx = 0; |
| 88 | vp8_header.temporalIdx = 0; |
| 89 | vp8_header.pictureId = 0; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 90 | packet.seqNum = 1; |
| 91 | packet.timestamp = 1; |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 92 | EXPECT_TRUE(dec_state.full_sync()); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 93 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 94 | dec_state.SetState(&frame); |
| 95 | EXPECT_TRUE(dec_state.full_sync()); |
| 96 | frame.Reset(); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 97 | // 1 layer up - still good. |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 98 | vp8_header.tl0PicIdx = 0; |
| 99 | vp8_header.temporalIdx = 1; |
| 100 | vp8_header.pictureId = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 101 | packet.seqNum = 2; |
| 102 | packet.timestamp = 2; |
| 103 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 104 | EXPECT_TRUE(dec_state.ContinuousFrame(&frame)); |
| 105 | dec_state.SetState(&frame); |
| 106 | EXPECT_TRUE(dec_state.full_sync()); |
| 107 | frame.Reset(); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 108 | // Lost non-base layer packet => should update sync parameter. |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 109 | vp8_header.tl0PicIdx = 0; |
| 110 | vp8_header.temporalIdx = 3; |
| 111 | vp8_header.pictureId = 3; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 112 | packet.seqNum = 4; |
| 113 | packet.timestamp = 4; |
| 114 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 115 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 116 | // Now insert the next non-base layer (belonging to a next tl0PicId). |
| 117 | frame.Reset(); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 118 | vp8_header.tl0PicIdx = 1; |
| 119 | vp8_header.temporalIdx = 2; |
| 120 | vp8_header.pictureId = 4; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 121 | packet.seqNum = 5; |
| 122 | packet.timestamp = 5; |
| 123 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 124 | // 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 Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 130 | vp8_header.tl0PicIdx = 1; |
| 131 | vp8_header.temporalIdx = 0; |
| 132 | vp8_header.pictureId = 5; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 133 | packet.seqNum = 6; |
| 134 | packet.timestamp = 6; |
| 135 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 136 | 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 Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 142 | vp8_header.tl0PicIdx = 0x00FF; |
| 143 | vp8_header.temporalIdx = 0; |
| 144 | vp8_header.pictureId = 6; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 145 | packet.seqNum = 7; |
| 146 | packet.timestamp = 7; |
| 147 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 148 | dec_state.SetState(&frame); |
| 149 | EXPECT_FALSE(dec_state.full_sync()); |
| 150 | frame.Reset(); |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 151 | vp8_header.tl0PicIdx = 0x0000; |
| 152 | vp8_header.temporalIdx = 0; |
| 153 | vp8_header.pictureId = 7; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 154 | packet.seqNum = 8; |
| 155 | packet.timestamp = 8; |
| 156 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 157 | 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.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 161 | } |
| 162 | |
mikhal@webrtc.org | 77c425b | 2012-01-03 20:35:25 +0000 | [diff] [blame] | 163 | TEST(TestDecodingState, UpdateOldPacket) { |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 164 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 168 | VCMPacket packet; |
| 169 | packet.timestamp = 1; |
| 170 | packet.seqNum = 1; |
| 171 | packet.frameType = kVideoFrameDelta; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 172 | FrameData frame_data; |
| 173 | frame_data.rtt_ms = 0; |
| 174 | frame_data.rolling_average_packets_per_frame = -1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 175 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 176 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 180 | packet.timestamp = 2; |
| 181 | dec_state.UpdateOldPacket(&packet); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 182 | EXPECT_EQ(dec_state.sequence_num(), 1); |
| 183 | // Now insert empty packet belonging to the same frame. |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 184 | packet.timestamp = 1; |
| 185 | packet.seqNum = 2; |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 186 | packet.frameType = kEmptyFrame; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 187 | packet.sizeBytes = 0; |
| 188 | dec_state.UpdateOldPacket(&packet); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 189 | EXPECT_EQ(dec_state.sequence_num(), 2); |
mikhal@webrtc.org | 77c425b | 2012-01-03 20:35:25 +0000 | [diff] [blame] | 190 | // Now insert delta packet belonging to the same frame. |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 191 | packet.timestamp = 1; |
| 192 | packet.seqNum = 3; |
| 193 | packet.frameType = kVideoFrameDelta; |
| 194 | packet.sizeBytes = 1400; |
| 195 | dec_state.UpdateOldPacket(&packet); |
mikhal@webrtc.org | 77c425b | 2012-01-03 20:35:25 +0000 | [diff] [blame] | 196 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 199 | packet.timestamp = 0; |
| 200 | packet.seqNum = 4; |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 201 | packet.frameType = kEmptyFrame; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 202 | packet.sizeBytes = 0; |
| 203 | dec_state.UpdateOldPacket(&packet); |
mikhal@webrtc.org | 77c425b | 2012-01-03 20:35:25 +0000 | [diff] [blame] | 204 | EXPECT_EQ(dec_state.sequence_num(), 3); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | TEST(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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 214 | VCMPacket packet; |
| 215 | packet.frameType = kVideoFrameDelta; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 216 | packet.video_header.codec = kVideoCodecVP8; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 217 | packet.timestamp = 0; |
| 218 | packet.seqNum = 0; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 219 | 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.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 224 | FrameData frame_data; |
| 225 | frame_data.rtt_ms = 0; |
| 226 | frame_data.rolling_average_packets_per_frame = -1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 227 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 228 | dec_state.SetState(&frame); |
| 229 | // tl0PicIdx 0, temporal id 1. |
| 230 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 231 | packet.timestamp = 1; |
| 232 | packet.seqNum = 1; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 233 | vp8_header.tl0PicIdx = 0; |
| 234 | vp8_header.temporalIdx = 1; |
| 235 | vp8_header.pictureId = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 236 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 237 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 243 | packet.timestamp = 3; |
| 244 | packet.seqNum = 3; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 245 | vp8_header.tl0PicIdx = 0; |
| 246 | vp8_header.temporalIdx = 3; |
| 247 | vp8_header.pictureId = 3; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 248 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 249 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 254 | packet.timestamp = 4; |
| 255 | packet.seqNum = 4; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 256 | vp8_header.tl0PicIdx = 1; |
| 257 | vp8_header.temporalIdx = 0; |
| 258 | vp8_header.pictureId = 4; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 259 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 260 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 266 | packet.frameType = kVideoFrameKey; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 267 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 268 | packet.timestamp = 5; |
| 269 | packet.seqNum = 5; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 270 | vp8_header.tl0PicIdx = 2; |
| 271 | vp8_header.temporalIdx = 0; |
| 272 | vp8_header.pictureId = 5; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 273 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 274 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 280 | packet.frameType = kVideoFrameDelta; |
| 281 | packet.timestamp = 6; |
| 282 | packet.seqNum = 6; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 283 | vp8_header.tl0PicIdx = 3; |
| 284 | vp8_header.temporalIdx = 0; |
| 285 | vp8_header.pictureId = 6; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 286 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 287 | EXPECT_TRUE(dec_state.ContinuousFrame(&frame)); |
| 288 | EXPECT_TRUE(dec_state.full_sync()); |
| 289 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 290 | packet.frameType = kVideoFrameDelta; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 291 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 292 | packet.timestamp = 8; |
| 293 | packet.seqNum = 8; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 294 | vp8_header.tl0PicIdx = 4; |
| 295 | vp8_header.temporalIdx = 0; |
| 296 | vp8_header.pictureId = 8; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 297 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 298 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 305 | packet.frameType = kVideoFrameDelta; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 306 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 307 | packet.timestamp = 9; |
| 308 | packet.seqNum = 9; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 309 | vp8_header.tl0PicIdx = 4; |
| 310 | vp8_header.temporalIdx = 2; |
| 311 | vp8_header.pictureId = 9; |
| 312 | vp8_header.layerSync = true; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 313 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 314 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 325 | packet.frameType = kVideoFrameDelta; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 326 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 327 | packet.markerBit = 1; |
| 328 | packet.timestamp = 0; |
| 329 | packet.seqNum = 0; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 330 | vp8_header.tl0PicIdx = 0; |
| 331 | vp8_header.temporalIdx = 0; |
| 332 | vp8_header.pictureId = 0; |
| 333 | vp8_header.layerSync = false; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 334 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 335 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 339 | packet.frameType = kVideoFrameDelta; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 340 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 341 | packet.markerBit = 0; |
| 342 | packet.timestamp = 1; |
| 343 | packet.seqNum = 1; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 344 | vp8_header.tl0PicIdx = 0; |
| 345 | vp8_header.temporalIdx = 2; |
| 346 | vp8_header.pictureId = 1; |
| 347 | vp8_header.layerSync = true; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 348 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 349 | EXPECT_TRUE(dec_state.ContinuousFrame(&frame)); |
| 350 | // Layer 1 |
| 351 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 352 | packet.frameType = kVideoFrameDelta; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 353 | packet.is_first_packet_in_frame = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 354 | packet.markerBit = 1; |
| 355 | packet.timestamp = 2; |
| 356 | packet.seqNum = 3; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 357 | vp8_header.tl0PicIdx = 0; |
| 358 | vp8_header.temporalIdx = 1; |
| 359 | vp8_header.pictureId = 2; |
| 360 | vp8_header.layerSync = true; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 361 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 362 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 363 | EXPECT_TRUE(dec_state.full_sync()); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 364 | } |
| 365 | |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 366 | TEST(TestDecodingState, DiscontinuousPicIdContinuousSeqNum) { |
| 367 | VCMDecodingState dec_state; |
| 368 | VCMFrameBuffer frame; |
| 369 | VCMPacket packet; |
| 370 | frame.Reset(); |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 371 | packet.frameType = kVideoFrameKey; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 372 | packet.video_header.codec = kVideoCodecVP8; |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 373 | packet.timestamp = 0; |
| 374 | packet.seqNum = 0; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 375 | 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.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 380 | FrameData frame_data; |
| 381 | frame_data.rtt_ms = 0; |
| 382 | frame_data.rolling_average_packets_per_frame = -1; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 383 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 384 | 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.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 390 | packet.frameType = kVideoFrameDelta; |
| 391 | packet.timestamp += 3000; |
| 392 | ++packet.seqNum; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 393 | vp8_header.temporalIdx = 1; |
| 394 | vp8_header.pictureId = 2; |
mikhal@webrtc.org | f31a47a | 2013-08-26 17:10:11 +0000 | [diff] [blame] | 395 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
stefan@webrtc.org | e72e9ee | 2012-09-19 11:08:05 +0000 | [diff] [blame] | 396 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 397 | dec_state.SetState(&frame); |
| 398 | EXPECT_FALSE(dec_state.full_sync()); |
| 399 | } |
| 400 | |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 401 | TEST(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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 406 | VCMPacket packet; |
| 407 | packet.timestamp = 10; |
| 408 | packet.seqNum = 1; |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 409 | FrameData frame_data; |
| 410 | frame_data.rtt_ms = 0; |
| 411 | frame_data.rolling_average_packets_per_frame = -1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 412 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 413 | dec_state.SetState(&frame); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 414 | packet.timestamp = 9; |
| 415 | EXPECT_TRUE(dec_state.IsOldPacket(&packet)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 416 | // Check for old frame |
| 417 | frame.Reset(); |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 418 | frame.InsertPacket(packet, 0, kNoErrors, frame_data); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 419 | EXPECT_TRUE(dec_state.IsOldFrame(&frame)); |
mikhal@webrtc.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 420 | } |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 421 | |
| 422 | TEST(TestDecodingState, PictureIdRepeat) { |
| 423 | VCMDecodingState dec_state; |
| 424 | VCMFrameBuffer frame; |
| 425 | VCMPacket packet; |
| 426 | packet.frameType = kVideoFrameDelta; |
Niels Möller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 427 | packet.video_header.codec = kVideoCodecVP8; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 428 | packet.timestamp = 0; |
| 429 | packet.seqNum = 0; |
Philip Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 430 | 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.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 435 | 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 Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 444 | vp8_header.temporalIdx++; |
| 445 | vp8_header.pictureId++; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 446 | 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 Eliasson | d52a1a6 | 2018-09-07 13:03:55 +0000 | [diff] [blame^] | 450 | vp8_header.tl0PicIdx += 3; |
| 451 | vp8_header.temporalIdx++; |
| 452 | vp8_header.tl0PicIdx = 1; |
mikhal@webrtc.org | 0aeb22e | 2013-10-28 22:26:14 +0000 | [diff] [blame] | 453 | EXPECT_LE(0, frame.InsertPacket(packet, 0, kNoErrors, frame_data)); |
| 454 | EXPECT_FALSE(dec_state.ContinuousFrame(&frame)); |
| 455 | } |
| 456 | |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 457 | TEST(TestDecodingState, FrameContinuityFlexibleModeKeyFrame) { |
| 458 | VCMDecodingState dec_state; |
| 459 | VCMFrameBuffer frame; |
| 460 | VCMPacket packet; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 461 | packet.is_first_packet_in_frame = true; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 462 | 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öller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 467 | packet.video_header.codec = kVideoCodecVP9; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 468 | |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 469 | auto& vp9_hdr = |
| 470 | packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>(); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 471 | 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 | |
| 501 | TEST(TestDecodingState, FrameContinuityFlexibleModeOutOfOrderFrames) { |
| 502 | VCMDecodingState dec_state; |
| 503 | VCMFrameBuffer frame; |
| 504 | VCMPacket packet; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 505 | packet.is_first_packet_in_frame = true; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 506 | 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öller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 511 | packet.video_header.codec = kVideoCodecVP9; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 512 | |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 513 | auto& vp9_hdr = |
| 514 | packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>(); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 515 | 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 | |
| 557 | TEST(TestDecodingState, FrameContinuityFlexibleModeGeneral) { |
| 558 | VCMDecodingState dec_state; |
| 559 | VCMFrameBuffer frame; |
| 560 | VCMPacket packet; |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 561 | packet.is_first_packet_in_frame = true; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 562 | 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öller | 520ca4e | 2018-06-04 11:14:38 +0200 | [diff] [blame] | 567 | packet.video_header.codec = kVideoCodecVP9; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 568 | |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 569 | auto& vp9_hdr = |
| 570 | packet.video_header.video_type_header.emplace<RTPVideoHeaderVP9>(); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 571 | 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.org | 62665b8 | 2011-12-29 18:09:58 +0000 | [diff] [blame] | 710 | } // namespace webrtc |