tests/fate/libavutil: add FATE test for video_enc_params

Unit test covering av_video_enc_params_alloc,
av_video_enc_params_block, and
av_video_enc_params_create_side_data.

Tests allocation for all three codec types (VP9, H264, MPEG2) and
the NONE type, with 0 and 4 blocks, with and without size output.
Verifies block getter indexing by writing and reading back
coordinates, dimensions, and delta_qp values. Tests frame-level qp
and delta_qp fields, and side data creation with frame attachment.

Coverage for libavutil/video_enc_params.c: 0.00% -> 86.21%
(remaining uncovered lines are OOM error paths)

Signed-off-by: marcos ashton <marcosashiglesias@gmail.com>
This commit is contained in:
marcos ashton
2026-03-25 23:11:10 +00:00
parent c8ec660d78
commit 878eabdfef
4 changed files with 154 additions and 0 deletions

View File

@@ -308,6 +308,7 @@ TESTPROGS = adler32 \
twofish \
utf8 \
uuid \
video_enc_params \
xtea \
tea \

View File

@@ -0,0 +1,130 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <stdio.h>
#include "libavutil/frame.h"
#include "libavutil/mem.h"
#include "libavutil/video_enc_params.h"
int main(void)
{
AVVideoEncParams *par;
AVVideoBlockParams *block;
AVFrame *frame;
size_t size;
static const struct {
enum AVVideoEncParamsType type;
const char *name;
} types[] = {
{ AV_VIDEO_ENC_PARAMS_VP9, "VP9" },
{ AV_VIDEO_ENC_PARAMS_H264, "H264" },
{ AV_VIDEO_ENC_PARAMS_MPEG2, "MPEG2" },
};
/* av_video_enc_params_alloc - each type with blocks */
printf("Testing av_video_enc_params_alloc()\n");
for (int i = 0; i < 3; i++) {
par = av_video_enc_params_alloc(types[i].type, 4, &size);
if (par) {
printf("%s: OK, type=%d, nb_blocks=%u, size>0=%s\n",
types[i].name, par->type, par->nb_blocks,
size > 0 ? "yes" : "no");
av_free(par);
} else {
printf("%s: FAIL\n", types[i].name);
}
}
/* zero blocks */
par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_VP9, 0, &size);
if (par) {
printf("zero blocks: OK, nb_blocks=%u\n", par->nb_blocks);
av_free(par);
} else {
printf("zero blocks: FAIL\n");
}
/* alloc without size */
par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_H264, 1, NULL);
printf("alloc (no size): %s\n", par ? "OK" : "FAIL");
av_free(par);
/* av_video_enc_params_block - write and read back */
printf("\nTesting av_video_enc_params_block()\n");
par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_H264, 3, NULL);
if (par) {
par->qp = 26;
par->delta_qp[0][0] = -2;
par->delta_qp[0][1] = -1;
printf("frame qp=%d, delta_qp[0]={%d,%d}\n",
par->qp, par->delta_qp[0][0], par->delta_qp[0][1]);
for (int i = 0; i < 3; i++) {
block = av_video_enc_params_block(par, i);
if ((uint8_t *)block != (uint8_t *)par + par->blocks_offset +
(size_t)i * par->block_size)
printf("block %d: pointer inconsistent with blocks_offset/block_size\n", i);
block->src_x = i * 16;
block->src_y = i * 16;
block->w = 16;
block->h = 16;
block->delta_qp = i - 1;
}
for (int i = 0; i < 3; i++) {
block = av_video_enc_params_block(par, i);
printf("block %d: src=(%d,%d) size=%dx%d delta_qp=%d\n",
i, block->src_x, block->src_y,
block->w, block->h, block->delta_qp);
}
av_free(par);
}
/* av_video_enc_params_create_side_data */
printf("\nTesting av_video_enc_params_create_side_data()\n");
frame = av_frame_alloc();
if (frame) {
par = av_video_enc_params_create_side_data(frame,
AV_VIDEO_ENC_PARAMS_VP9, 2);
if (par) {
printf("side_data: OK, type=%d, nb_blocks=%u\n",
par->type, par->nb_blocks);
block = av_video_enc_params_block(par, 0);
block->delta_qp = 5;
block = av_video_enc_params_block(par, 0);
printf("side_data block 0: delta_qp=%d\n", block->delta_qp);
} else {
printf("side_data: FAIL\n");
}
av_frame_free(&frame);
}
/* NONE type */
printf("\nTesting NONE type\n");
par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_NONE, 0, &size);
if (par) {
printf("NONE: OK, type=%d\n", par->type);
av_free(par);
} else {
printf("NONE: FAIL\n");
}
return 0;
}

View File

@@ -195,6 +195,10 @@ fate-uuid: libavutil/tests/uuid$(EXESUF)
fate-uuid: CMD = run libavutil/tests/uuid$(EXESUF)
fate-uuid: CMP = null
FATE_LIBAVUTIL += fate-video_enc_params
fate-video_enc_params: libavutil/tests/video_enc_params$(EXESUF)
fate-video_enc_params: CMD = run libavutil/tests/video_enc_params$(EXESUF)
FATE_LIBAVUTIL += fate-file
fate-file: libavutil/tests/file$(EXESUF)
fate-file: CMD = run libavutil/tests/file$(EXESUF) $(SRC_PATH)/libavutil/tests/file.c

View File

@@ -0,0 +1,19 @@
Testing av_video_enc_params_alloc()
VP9: OK, type=0, nb_blocks=4, size>0=yes
H264: OK, type=1, nb_blocks=4, size>0=yes
MPEG2: OK, type=2, nb_blocks=4, size>0=yes
zero blocks: OK, nb_blocks=0
alloc (no size): OK
Testing av_video_enc_params_block()
frame qp=26, delta_qp[0]={-2,-1}
block 0: src=(0,0) size=16x16 delta_qp=-1
block 1: src=(16,16) size=16x16 delta_qp=0
block 2: src=(32,32) size=16x16 delta_qp=1
Testing av_video_enc_params_create_side_data()
side_data: OK, type=0, nb_blocks=2
side_data block 0: delta_qp=5
Testing NONE type
NONE: OK, type=-1