| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Test for HEVC mp4toannexb bitstream filter parameter set deduplication | ||
| 3 | * | ||
| 4 | * Copyright (c) 2026 FFmpeg developers | ||
| 5 | * | ||
| 6 | * This file is part of FFmpeg. | ||
| 7 | * | ||
| 8 | * FFmpeg is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with FFmpeg; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | |||
| 26 | #include "libavutil/error.h" | ||
| 27 | #include "libavutil/intreadwrite.h" | ||
| 28 | #include "libavutil/macros.h" | ||
| 29 | #include "libavutil/mem.h" | ||
| 30 | #include "libavcodec/avcodec.h" | ||
| 31 | #include "libavcodec/bsf.h" | ||
| 32 | #include "libavcodec/packet.h" | ||
| 33 | |||
| 34 | /* Valid 64x64 HEVC parameter sets and slice from x265 */ | ||
| 35 | static const uint8_t vps_bytes[] = { | ||
| 36 | 0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x03, 0x70, | ||
| 37 | 0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03, | ||
| 38 | 0x00, 0x00, 0x03, 0x00, 0x1e, 0x95, 0x94, 0x09 | ||
| 39 | }; | ||
| 40 | |||
| 41 | static const uint8_t sps_bytes[] = { | ||
| 42 | 0x42, 0x01, 0x01, 0x03, 0x70, 0x00, 0x00, 0x03, | ||
| 43 | 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, | ||
| 44 | 0x00, 0x1e, 0xa0, 0x20, 0x81, 0x05, 0x96, 0x56, | ||
| 45 | 0x54, 0xa4, 0xc2, 0xe0, 0x10, 0x00, 0x00, 0x3e, | ||
| 46 | 0x80, 0x00, 0x00, 0x3e, 0x80, 0x80 | ||
| 47 | }; | ||
| 48 | |||
| 49 | /* SPS 1 differs only in sps_seq_parameter_set_id: ue(v) 1 becomes 010. | ||
| 50 | * Repacked trailing bits and reinserted emulation-prevention bytes. */ | ||
| 51 | static const uint8_t sps1_bytes[] = { | ||
| 52 | 0x42, 0x01, 0x01, 0x03, 0x70, 0x00, 0x00, 0x03, | ||
| 53 | 0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, | ||
| 54 | 0x00, 0x1e, 0x48, 0x08, 0x20, 0x41, 0x65, 0x95, | ||
| 55 | 0x95, 0x29, 0x30, 0xb8, 0x04, 0x00, 0x00, 0x0f, | ||
| 56 | 0xa0, 0x00, 0x00, 0x0f, 0xa0, 0x20 | ||
| 57 | }; | ||
| 58 | |||
| 59 | /* PPS with pps_pic_parameter_set_id = 0 */ | ||
| 60 | static const uint8_t pps0_bytes[] = { | ||
| 61 | 0x44, 0x01, 0xc0, 0x73, 0xc0, 0x89 | ||
| 62 | }; | ||
| 63 | |||
| 64 | /* PPS with pps_pic_parameter_set_id = 1 */ | ||
| 65 | static const uint8_t pps1_bytes[] = { | ||
| 66 | 0x44, 0x01, 0x50, 0x1c, 0xf0, 0x22, 0x40 | ||
| 67 | }; | ||
| 68 | |||
| 69 | /* Prefix SEI (filler payload type 3 to verify SEI NAL retention and ordering) */ | ||
| 70 | static const uint8_t prefix_sei_bytes[] = { | ||
| 71 | 0x4e, 0x01, 0x03, 0x01, 0xff, 0x80 | ||
| 72 | }; | ||
| 73 | |||
| 74 | /* Valid 2-byte Prefix SEI header for cap-testing */ | ||
| 75 | static const uint8_t dummy_sei_bytes[] = { | ||
| 76 | 0x4e, 0x01 | ||
| 77 | }; | ||
| 78 | |||
| 79 | /* Valid IDR slice referencing PPS 0 */ | ||
| 80 | static const uint8_t idr_slice_bytes[] = { | ||
| 81 | 0x28, 0x01, 0xac, 0x4e, 0xd7, 0x1f, 0xff, 0xf5, | ||
| 82 | 0xde, 0x9c, 0xaf, 0xea, 0xf8 | ||
| 83 | }; | ||
| 84 | |||
| 85 | static const uint8_t hvcc_header[22] = { | ||
| 86 | 1, /* configurationVersion = 1 */ | ||
| 87 | 0x01, /* general_profile_space / tier / profile_idc */ | ||
| 88 | 0x60, 0, 0, 0, /* general_profile_compatibility_flags */ | ||
| 89 | 0x90, 0, 0, 0, 0, 0, /* general_constraint_indicator_flags */ | ||
| 90 | 0x5d, /* general_level_idc */ | ||
| 91 | 0xf0, 0x00, /* min_spatial_segmentation_idc (1111 0000) */ | ||
| 92 | 0xfc, /* parallelismType */ | ||
| 93 | 0xfd, /* chroma_format_idc (3 = 4:2:0) */ | ||
| 94 | 0xf8, /* bit_depth_luma_minus8 */ | ||
| 95 | 0xf8, /* bit_depth_chroma_minus8 */ | ||
| 96 | 0x00, 0x00, /* avgFrameRate */ | ||
| 97 | 0x03 /* lengthSizeMinusOne = 3 (4-byte length prefix) */ | ||
| 98 | }; | ||
| 99 | |||
| 100 | typedef struct HVCCNALDesc { | ||
| 101 | int type; | ||
| 102 | const uint8_t *data; | ||
| 103 | size_t size; | ||
| 104 | int count; | ||
| 105 | } HVCCNALDesc; | ||
| 106 | |||
| 107 | 10 | static void print_packet_hex(const char *label, const AVPacket *pkt) | |
| 108 | { | ||
| 109 | 10 | printf("%s: size %d, hex: ", label, pkt->size); | |
| 110 |
2/2✓ Branch 0 taken 1597 times.
✓ Branch 1 taken 10 times.
|
1607 | for (int i = 0; i < pkt->size; i++) |
| 111 | 1597 | printf("%02x", pkt->data[i]); | |
| 112 | 10 | printf("\n"); | |
| 113 | 10 | } | |
| 114 | |||
| 115 | /* Helper to build a HEVCDecoderConfigurationRecord (hvcC) from array descriptors */ | ||
| 116 | 4 | static uint8_t *build_hvcc(size_t *hvcc_size, const HVCCNALDesc *arrays, int nb_arrays) | |
| 117 | { | ||
| 118 | 4 | size_t total = sizeof(hvcc_header) + 1; | |
| 119 | uint8_t *buf, *p; | ||
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 4 times.
|
15 | for (int i = 0; i < nb_arrays; i++) |
| 122 | 11 | total += 3 + (size_t)arrays[i].count * (2 + arrays[i].size); | |
| 123 | |||
| 124 | 4 | buf = av_mallocz(total + AV_INPUT_BUFFER_PADDING_SIZE); | |
| 125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!buf) |
| 126 | ✗ | return NULL; | |
| 127 | |||
| 128 | 4 | p = buf; | |
| 129 | 4 | memcpy(p, hvcc_header, sizeof(hvcc_header)); | |
| 130 | 4 | p += sizeof(hvcc_header); | |
| 131 | 4 | *p++ = nb_arrays; | |
| 132 | |||
| 133 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 4 times.
|
15 | for (int i = 0; i < nb_arrays; i++) { |
| 134 | 11 | int cnt = arrays[i].count; | |
| 135 | 11 | size_t len = arrays[i].size; | |
| 136 | |||
| 137 | 11 | *p++ = arrays[i].type & 0x3f; | |
| 138 | 11 | *p++ = (cnt >> 8) & 0xff; | |
| 139 | 11 | *p++ = cnt & 0xff; | |
| 140 |
2/2✓ Branch 0 taken 2060 times.
✓ Branch 1 taken 11 times.
|
2071 | for (int j = 0; j < cnt; j++) { |
| 141 | 2060 | *p++ = (len >> 8) & 0xff; | |
| 142 | 2060 | *p++ = len & 0xff; | |
| 143 |
1/2✓ Branch 0 taken 2060 times.
✗ Branch 1 not taken.
|
2060 | if (arrays[i].data) |
| 144 | 2060 | memcpy(p, arrays[i].data, len); | |
| 145 | else | ||
| 146 | ✗ | memset(p, 0x80, len); | |
| 147 | 2060 | p += len; | |
| 148 | } | ||
| 149 | } | ||
| 150 | |||
| 151 | 4 | *hvcc_size = p - buf; | |
| 152 | 4 | return buf; | |
| 153 | } | ||
| 154 | |||
| 155 | /* Helper to build a packet with 4-byte length-prefixed NALUs */ | ||
| 156 | 10 | static int build_packet(AVPacket *pkt, | |
| 157 | const uint8_t *nalus[], const size_t lens[], int count) | ||
| 158 | { | ||
| 159 | 10 | size_t total = 0; | |
| 160 | uint8_t *p; | ||
| 161 | int ret; | ||
| 162 | |||
| 163 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 10 times.
|
78 | for (int i = 0; i < count; i++) |
| 164 | 68 | total += 4 + lens[i]; | |
| 165 | |||
| 166 | 10 | ret = av_new_packet(pkt, total); | |
| 167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) |
| 168 | ✗ | return ret; | |
| 169 | |||
| 170 | 10 | p = pkt->data; | |
| 171 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 10 times.
|
78 | for (int i = 0; i < count; i++) { |
| 172 | 68 | AV_WB32(p, lens[i]); | |
| 173 | 68 | memcpy(p + 4, nalus[i], lens[i]); | |
| 174 | 68 | p += 4 + lens[i]; | |
| 175 | } | ||
| 176 | |||
| 177 | 10 | return 0; | |
| 178 | } | ||
| 179 | |||
| 180 | 10 | static int decode_packet(const AVPacket *pkt) | |
| 181 | { | ||
| 182 | 10 | const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_HEVC); | |
| 183 | 10 | AVCodecContext *dec_ctx = NULL; | |
| 184 | 10 | AVFrame *frame = NULL; | |
| 185 | 10 | AVPacket *dec_pkt = NULL; | |
| 186 | 10 | int ret = 0, got_frame = 0; | |
| 187 | |||
| 188 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!codec) { |
| 189 | ✗ | fprintf(stderr, "HEVC decoder not found\n"); | |
| 190 | ✗ | return AVERROR_DECODER_NOT_FOUND; | |
| 191 | } | ||
| 192 | |||
| 193 | 10 | dec_ctx = avcodec_alloc_context3(codec); | |
| 194 | 10 | frame = av_frame_alloc(); | |
| 195 | 10 | dec_pkt = av_packet_alloc(); | |
| 196 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
|
10 | if (!dec_ctx || !frame || !dec_pkt) { |
| 197 | ✗ | ret = AVERROR(ENOMEM); | |
| 198 | ✗ | goto end; | |
| 199 | } | ||
| 200 | |||
| 201 | 10 | ret = avcodec_open2(dec_ctx, codec, NULL); | |
| 202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) |
| 203 | ✗ | goto end; | |
| 204 | |||
| 205 | 10 | ret = av_packet_ref(dec_pkt, pkt); | |
| 206 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) |
| 207 | ✗ | goto end; | |
| 208 | |||
| 209 | 10 | ret = avcodec_send_packet(dec_ctx, dec_pkt); | |
| 210 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (ret < 0) |
| 211 | ✗ | goto end; | |
| 212 | |||
| 213 | while (1) { | ||
| 214 | 10 | ret = avcodec_receive_frame(dec_ctx, frame); | |
| 215 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10 | if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) |
| 216 | break; | ||
| 217 | ✗ | if (ret < 0) | |
| 218 | ✗ | goto end; | |
| 219 | ✗ | got_frame++; | |
| 220 | } | ||
| 221 | |||
| 222 | 10 | ret = avcodec_send_packet(dec_ctx, NULL); | |
| 223 |
1/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
10 | if (ret < 0 && ret != AVERROR_EOF) |
| 224 | ✗ | goto end; | |
| 225 | |||
| 226 | while (1) { | ||
| 227 | 20 | ret = avcodec_receive_frame(dec_ctx, frame); | |
| 228 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (ret == AVERROR_EOF) |
| 229 | 10 | break; | |
| 230 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) |
| 231 | ✗ | goto end; | |
| 232 | 10 | got_frame++; | |
| 233 | } | ||
| 234 | |||
| 235 | 10 | printf("Decoded frames: %d\n", got_frame); | |
| 236 | 10 | ret = 0; | |
| 237 | |||
| 238 | 10 | end: | |
| 239 | 10 | av_packet_free(&dec_pkt); | |
| 240 | 10 | av_frame_free(&frame); | |
| 241 | 10 | avcodec_free_context(&dec_ctx); | |
| 242 | 10 | return ret; | |
| 243 | } | ||
| 244 | |||
| 245 | 11 | static int run_test_case(const char *case_name, | |
| 246 | const uint8_t *hvcc, size_t hvcc_size, | ||
| 247 | AVPacket *in_pkt, int init_only, | ||
| 248 | int check_decode) | ||
| 249 | { | ||
| 250 | const AVBitStreamFilter *bsf; | ||
| 251 | 11 | AVBSFContext *ctx = NULL; | |
| 252 | 11 | AVPacket *out_pkt = NULL; | |
| 253 | 11 | int ret = 0; | |
| 254 | |||
| 255 | 11 | printf("=== Test: %s ===\n", case_name); | |
| 256 | |||
| 257 | 11 | bsf = av_bsf_get_by_name("hevc_mp4toannexb"); | |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (!bsf) { |
| 259 | ✗ | fprintf(stderr, "Bitstream filter hevc_mp4toannexb not found\n"); | |
| 260 | ✗ | return -1; | |
| 261 | } | ||
| 262 | |||
| 263 | 11 | ret = av_bsf_alloc(bsf, &ctx); | |
| 264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (ret < 0) |
| 265 | ✗ | return ret; | |
| 266 | |||
| 267 | 11 | ctx->par_in->codec_type = AVMEDIA_TYPE_VIDEO; | |
| 268 | 11 | ctx->par_in->codec_id = AV_CODEC_ID_HEVC; | |
| 269 | 11 | ctx->par_in->extradata = av_memdup(hvcc, hvcc_size + AV_INPUT_BUFFER_PADDING_SIZE); | |
| 270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (!ctx->par_in->extradata) { |
| 271 | ✗ | ret = AVERROR(ENOMEM); | |
| 272 | ✗ | goto end; | |
| 273 | } | ||
| 274 | 11 | ctx->par_in->extradata_size = hvcc_size; | |
| 275 | |||
| 276 | 11 | ret = av_bsf_init(ctx); | |
| 277 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | if (init_only) { |
| 278 | 1 | printf("av_bsf_init: %d\n", ret); | |
| 279 | 1 | ret = 0; | |
| 280 | 1 | goto end; | |
| 281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | } else if (ret < 0) { |
| 282 | char errbuf[AV_ERROR_MAX_STRING_SIZE]; | ||
| 283 | ✗ | av_strerror(ret, errbuf, sizeof(errbuf)); | |
| 284 | ✗ | fprintf(stderr, "av_bsf_init failed: %s\n", errbuf); | |
| 285 | ✗ | goto end; | |
| 286 | } | ||
| 287 | |||
| 288 | 10 | out_pkt = av_packet_alloc(); | |
| 289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (!out_pkt) { |
| 290 | ✗ | ret = AVERROR(ENOMEM); | |
| 291 | ✗ | goto end; | |
| 292 | } | ||
| 293 | |||
| 294 | 10 | ret = av_bsf_send_packet(ctx, in_pkt); | |
| 295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) { |
| 296 | ✗ | fprintf(stderr, "av_bsf_send_packet failed: %d\n", ret); | |
| 297 | ✗ | goto end; | |
| 298 | } | ||
| 299 | |||
| 300 | 10 | ret = av_bsf_receive_packet(ctx, out_pkt); | |
| 301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) { |
| 302 | ✗ | fprintf(stderr, "av_bsf_receive_packet failed: %d\n", ret); | |
| 303 | ✗ | goto end; | |
| 304 | } | ||
| 305 | |||
| 306 | 10 | print_packet_hex("Output", out_pkt); | |
| 307 | |||
| 308 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | if (check_decode) { |
| 309 | 10 | ret = decode_packet(out_pkt); | |
| 310 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) { |
| 311 | ✗ | fprintf(stderr, "%s: decoding output packet failed\n", case_name); | |
| 312 | ✗ | goto end; | |
| 313 | } | ||
| 314 | /* The decoder prints the actual frame count for FATE. */ | ||
| 315 | } | ||
| 316 | |||
| 317 | 10 | ret = 0; | |
| 318 | |||
| 319 | 11 | end: | |
| 320 | 11 | av_packet_free(&out_pkt); | |
| 321 | 11 | av_bsf_free(&ctx); | |
| 322 | 11 | return ret; | |
| 323 | } | ||
| 324 | |||
| 325 | 1 | int main(void) | |
| 326 | { | ||
| 327 | 1 | uint8_t *hvcc_std = NULL, *hvcc_sei = NULL, *hvcc_dup = NULL, *hvcc_limit = NULL; | |
| 328 | 1 | size_t sz_std = 0, sz_sei = 0, sz_dup = 0, sz_limit = 0; | |
| 329 | 1 | AVPacket *pkt = av_packet_alloc(); | |
| 330 | 1 | int ret = 0, err; | |
| 331 | |||
| 332 | 1 | const HVCCNALDesc std_arrays[] = { | |
| 333 | { 32, vps_bytes, sizeof(vps_bytes), 1 }, | ||
| 334 | { 33, sps_bytes, sizeof(sps_bytes), 1 }, | ||
| 335 | { 34, pps0_bytes, sizeof(pps0_bytes), 1 }, | ||
| 336 | }; | ||
| 337 | 1 | const HVCCNALDesc sei_arrays[] = { | |
| 338 | { 39, prefix_sei_bytes, sizeof(prefix_sei_bytes), 1 }, | ||
| 339 | { 32, vps_bytes, sizeof(vps_bytes), 1 }, | ||
| 340 | { 33, sps_bytes, sizeof(sps_bytes), 1 }, | ||
| 341 | { 34, pps0_bytes, sizeof(pps0_bytes), 1 }, | ||
| 342 | }; | ||
| 343 | 1 | const HVCCNALDesc dup_arrays[] = { | |
| 344 | { 32, vps_bytes, sizeof(vps_bytes), 1 }, | ||
| 345 | { 33, sps_bytes, sizeof(sps_bytes), 2 }, | ||
| 346 | { 34, pps0_bytes, sizeof(pps0_bytes), 1 }, | ||
| 347 | }; | ||
| 348 | 1 | const HVCCNALDesc limit_arrays[] = { | |
| 349 | { 39, dummy_sei_bytes, sizeof(dummy_sei_bytes), 2049 }, | ||
| 350 | }; | ||
| 351 | |||
| 352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!pkt) |
| 353 | ✗ | return 1; | |
| 354 | |||
| 355 | 1 | hvcc_std = build_hvcc(&sz_std, std_arrays, FF_ARRAY_ELEMS(std_arrays)); | |
| 356 | 1 | hvcc_sei = build_hvcc(&sz_sei, sei_arrays, FF_ARRAY_ELEMS(sei_arrays)); | |
| 357 | 1 | hvcc_dup = build_hvcc(&sz_dup, dup_arrays, FF_ARRAY_ELEMS(dup_arrays)); | |
| 358 | 1 | hvcc_limit = build_hvcc(&sz_limit, limit_arrays, FF_ARRAY_ELEMS(limit_arrays)); | |
| 359 | |||
| 360 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
|
1 | if (!hvcc_std || !hvcc_sei || !hvcc_dup || !hvcc_limit) { |
| 361 | ✗ | ret = 1; | |
| 362 | ✗ | goto cleanup; | |
| 363 | } | ||
| 364 | |||
| 365 | /* Case 1: Standard insertion (extradata has VPS, SPS, PPS 0; packet only has IDR slice) */ | ||
| 366 | { | ||
| 367 | 1 | const uint8_t *nalus[] = { idr_slice_bytes }; | |
| 368 | 1 | const size_t lens[] = { sizeof(idr_slice_bytes) }; | |
| 369 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 370 | ✗ | ret = 1; | |
| 371 | ✗ | goto cleanup; | |
| 372 | } | ||
| 373 | 1 | err = run_test_case("Case 1 (Standard Insertion)", hvcc_std, sz_std, pkt, 0, 1); | |
| 374 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 375 | ✗ | ret = 1; | |
| 376 | 1 | av_packet_unref(pkt); | |
| 377 | } | ||
| 378 | |||
| 379 | /* Case 2: Exact payload deduplication (extradata has VPS, SPS, PPS 0; packet has identical in-band VPS, SPS, PPS 0 + IDR slice) */ | ||
| 380 | { | ||
| 381 | 1 | const uint8_t *nalus[] = { vps_bytes, sps_bytes, pps0_bytes, idr_slice_bytes }; | |
| 382 | 1 | const size_t lens[] = { sizeof(vps_bytes), sizeof(sps_bytes), sizeof(pps0_bytes), sizeof(idr_slice_bytes) }; | |
| 383 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 384 | ✗ | ret = 1; | |
| 385 | ✗ | goto cleanup; | |
| 386 | } | ||
| 387 | 1 | err = run_test_case("Case 2 (Exact Payload Deduplication)", hvcc_std, sz_std, pkt, 0, 1); | |
| 388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 389 | ✗ | ret = 1; | |
| 390 | 1 | av_packet_unref(pkt); | |
| 391 | } | ||
| 392 | |||
| 393 | /* Case 3: Reviewer Fairy counterexample (extradata has VPS, SPS, PPS 0; packet has in-band VPS, SPS, PPS 1 + IDR slice) */ | ||
| 394 | { | ||
| 395 | 1 | const uint8_t *nalus[] = { vps_bytes, sps_bytes, pps1_bytes, idr_slice_bytes }; | |
| 396 | 1 | const size_t lens[] = { sizeof(vps_bytes), sizeof(sps_bytes), sizeof(pps1_bytes), sizeof(idr_slice_bytes) }; | |
| 397 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 398 | ✗ | ret = 1; | |
| 399 | ✗ | goto cleanup; | |
| 400 | } | ||
| 401 | 1 | err = run_test_case("Case 3 (Fairy Counterexample - Retain PPS 0)", hvcc_std, sz_std, pkt, 0, 1); | |
| 402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 403 | ✗ | ret = 1; | |
| 404 | 1 | av_packet_unref(pkt); | |
| 405 | } | ||
| 406 | |||
| 407 | /* Case 4: Filler SEI preservation (extradata has Prefix SEI, VPS, SPS, PPS 0; packet has identical VPS, SPS, PPS 0 + IDR slice) */ | ||
| 408 | { | ||
| 409 | 1 | const uint8_t *nalus[] = { vps_bytes, sps_bytes, pps0_bytes, idr_slice_bytes }; | |
| 410 | 1 | const size_t lens[] = { sizeof(vps_bytes), sizeof(sps_bytes), sizeof(pps0_bytes), sizeof(idr_slice_bytes) }; | |
| 411 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 412 | ✗ | ret = 1; | |
| 413 | ✗ | goto cleanup; | |
| 414 | } | ||
| 415 | 1 | err = run_test_case("Case 4 (Filler SEI Preservation)", hvcc_sei, sz_sei, pkt, 0, 1); | |
| 416 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 417 | ✗ | ret = 1; | |
| 418 | 1 | av_packet_unref(pkt); | |
| 419 | } | ||
| 420 | |||
| 421 | /* Case 5: Many nonmatching in-band PPS copies before a matching PPS */ | ||
| 422 | { | ||
| 423 | const uint8_t *nalus[36]; | ||
| 424 | size_t lens[36]; | ||
| 425 | 1 | int count = 0; | |
| 426 | |||
| 427 | 1 | nalus[count] = vps_bytes; | |
| 428 | 1 | lens[count++] = sizeof(vps_bytes); | |
| 429 | |||
| 430 | 1 | nalus[count] = sps_bytes; | |
| 431 | 1 | lens[count++] = sizeof(sps_bytes); | |
| 432 | |||
| 433 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1 times.
|
33 | for (int k = 0; k < 32; k++) { |
| 434 | 32 | nalus[count] = pps1_bytes; | |
| 435 | 32 | lens[count++] = sizeof(pps1_bytes); | |
| 436 | } | ||
| 437 | |||
| 438 | 1 | nalus[count] = pps0_bytes; | |
| 439 | 1 | lens[count++] = sizeof(pps0_bytes); | |
| 440 | |||
| 441 | 1 | nalus[count] = idr_slice_bytes; | |
| 442 | 1 | lens[count++] = sizeof(idr_slice_bytes); | |
| 443 | |||
| 444 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, count) < 0) { |
| 445 | ✗ | ret = 1; | |
| 446 | ✗ | goto cleanup; | |
| 447 | } | ||
| 448 | 1 | err = run_test_case("Case 5 (Many Nonmatching In-band PPS Copies)", hvcc_std, sz_std, pkt, 0, 1); | |
| 449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 450 | ✗ | ret = 1; | |
| 451 | 1 | av_packet_unref(pkt); | |
| 452 | } | ||
| 453 | |||
| 454 | /* Case 6: In-band parameter set suppresses duplicate extradata entries | ||
| 455 | * (extradata has 1xVPS, 2xSPS, 1xPPS 0; packet has 1xVPS, 1xSPS, 1xPPS 0 + IDR slice). | ||
| 456 | * Verifies that matching in-band parameter sets suppress all identical | ||
| 457 | * extradata copies, leaving only the in-band entry. | ||
| 458 | */ | ||
| 459 | { | ||
| 460 | 1 | const uint8_t *nalus[] = { vps_bytes, sps_bytes, pps0_bytes, idr_slice_bytes }; | |
| 461 | 1 | const size_t lens[] = { sizeof(vps_bytes), sizeof(sps_bytes), sizeof(pps0_bytes), sizeof(idr_slice_bytes) }; | |
| 462 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 463 | ✗ | ret = 1; | |
| 464 | ✗ | goto cleanup; | |
| 465 | } | ||
| 466 | 1 | err = run_test_case("Case 6 (Duplicate Extradata PS Suppressed By In-Band Match)", | |
| 467 | hvcc_dup, sz_dup, pkt, 0, 1); | ||
| 468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 469 | ✗ | ret = 1; | |
| 470 | 1 | av_packet_unref(pkt); | |
| 471 | } | ||
| 472 | |||
| 473 | /* Case 7: Exceeds MAX_EXTRADATA_NALS limit rejection (hvcC carries >2048 NALUs) */ | ||
| 474 | 1 | err = run_test_case("Case 7 (Exceeds MAX_EXTRADATA_NALS Limit Rejection)", | |
| 475 | hvcc_limit, sz_limit, NULL, 1, 0); | ||
| 476 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 477 | ✗ | ret = 1; | |
| 478 | |||
| 479 | /* Case 8: Leading Prefix SEI before matching in-band VPS and SPS | ||
| 480 | * (extradata has VPS, SPS, PPS 0; packet has Prefix SEI, matching VPS, matching SPS + IDR slice). | ||
| 481 | * Verifies that extradata PPS 0 is not prematurely emitted before matching VPS/SPS. | ||
| 482 | */ | ||
| 483 | { | ||
| 484 | 1 | const uint8_t *nalus[] = { prefix_sei_bytes, vps_bytes, sps_bytes, idr_slice_bytes }; | |
| 485 | 1 | const size_t lens[] = { sizeof(prefix_sei_bytes), sizeof(vps_bytes), sizeof(sps_bytes), sizeof(idr_slice_bytes) }; | |
| 486 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 487 | ✗ | ret = 1; | |
| 488 | ✗ | goto cleanup; | |
| 489 | } | ||
| 490 | 1 | err = run_test_case("Case 8 (Leading Prefix SEI Before Matching VPS/SPS)", | |
| 491 | hvcc_std, sz_std, pkt, 0, 1); | ||
| 492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 493 | ✗ | ret = 1; | |
| 494 | 1 | av_packet_unref(pkt); | |
| 495 | } | ||
| 496 | |||
| 497 | /* Case 9: In-band PPS before SPS reordering | ||
| 498 | * (extradata has VPS, SPS, PPS 0; packet has in-band PPS 0, matching SPS + IDR slice). | ||
| 499 | * Verifies that out-of-order in-band SPS does not suppress extradata SPS needed by earlier PPS. | ||
| 500 | */ | ||
| 501 | { | ||
| 502 | 1 | const uint8_t *nalus[] = { pps0_bytes, sps_bytes, idr_slice_bytes }; | |
| 503 | 1 | const size_t lens[] = { sizeof(pps0_bytes), sizeof(sps_bytes), sizeof(idr_slice_bytes) }; | |
| 504 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 505 | ✗ | ret = 1; | |
| 506 | ✗ | goto cleanup; | |
| 507 | } | ||
| 508 | 1 | err = run_test_case("Case 9 (In-band PPS Before SPS Reordering)", | |
| 509 | hvcc_std, sz_std, pkt, 0, 1); | ||
| 510 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 511 | ✗ | ret = 1; | |
| 512 | 1 | av_packet_unref(pkt); | |
| 513 | } | ||
| 514 | |||
| 515 | /* Case 10: Leading Prefix SEI with only VPS matched | ||
| 516 | * (extradata has VPS 0, SPS 0, PPS 0; packet has Prefix SEI, matching VPS 0 + IDR slice). | ||
| 517 | * Verifies that extradata SPS 0 and PPS 0 are not prematurely emitted before | ||
| 518 | * in-band VPS 0 due to the Prefix SEI barrier, ensuring valid decoding topology. | ||
| 519 | */ | ||
| 520 | { | ||
| 521 | 1 | const uint8_t *nalus[] = { prefix_sei_bytes, vps_bytes, idr_slice_bytes }; | |
| 522 | 1 | const size_t lens[] = { sizeof(prefix_sei_bytes), sizeof(vps_bytes), sizeof(idr_slice_bytes) }; | |
| 523 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 524 | ✗ | ret = 1; | |
| 525 | ✗ | goto cleanup; | |
| 526 | } | ||
| 527 | 1 | err = run_test_case("Case 10 (Leading Prefix SEI With Matching VPS Only)", | |
| 528 | hvcc_std, sz_std, pkt, 0, 1); | ||
| 529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 530 | ✗ | ret = 1; | |
| 531 | 1 | av_packet_unref(pkt); | |
| 532 | } | ||
| 533 | |||
| 534 | /* Case 11: Multiple SPS IDs across Prefix SEI | ||
| 535 | * (extradata has VPS 0, SPS 0, PPS 0; packet has matching VPS 0, in-band SPS 1, | ||
| 536 | * Prefix SEI, matching SPS 0 + IDR slice). | ||
| 537 | * Verifies that seeing SPS 1 before Prefix SEI does not prematurely emit extradata PPS 0 | ||
| 538 | * which depends on SPS 0 that appears after the SEI. | ||
| 539 | */ | ||
| 540 | { | ||
| 541 | 1 | const uint8_t *nalus[] = { vps_bytes, sps1_bytes, prefix_sei_bytes, sps_bytes, idr_slice_bytes }; | |
| 542 | 1 | const size_t lens[] = { sizeof(vps_bytes), sizeof(sps1_bytes), sizeof(prefix_sei_bytes), | |
| 543 | sizeof(sps_bytes), sizeof(idr_slice_bytes) }; | ||
| 544 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (build_packet(pkt, nalus, lens, FF_ARRAY_ELEMS(nalus)) < 0) { |
| 545 | ✗ | ret = 1; | |
| 546 | ✗ | goto cleanup; | |
| 547 | } | ||
| 548 | 1 | err = run_test_case("Case 11 (Multiple SPS IDs Across Prefix SEI)", | |
| 549 | hvcc_std, sz_std, pkt, 0, 1); | ||
| 550 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
| 551 | ✗ | ret = 1; | |
| 552 | 1 | av_packet_unref(pkt); | |
| 553 | } | ||
| 554 | |||
| 555 | 1 | cleanup: | |
| 556 | 1 | av_freep(&hvcc_std); | |
| 557 | 1 | av_freep(&hvcc_sei); | |
| 558 | 1 | av_freep(&hvcc_dup); | |
| 559 | 1 | av_freep(&hvcc_limit); | |
| 560 | 1 | av_packet_free(&pkt); | |
| 561 | 1 | return ret; | |
| 562 | } | ||
| 563 |