FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/tests/video_enc_params.c
Date: 2026-07-16 17:05:34
Exec Total Coverage
Lines: 54 59 91.5%
Functions: 1 1 100.0%
Branches: 15 24 62.5%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdint.h>
20 #include <stdio.h>
21
22 #include "libavutil/frame.h"
23 #include "libavutil/mem.h"
24 #include "libavutil/video_enc_params.h"
25
26 1 int main(void)
27 {
28 AVVideoEncParams *par;
29 AVVideoBlockParams *block;
30 AVFrame *frame;
31 size_t size;
32
33 static const struct {
34 enum AVVideoEncParamsType type;
35 const char *name;
36 } types[] = {
37 { AV_VIDEO_ENC_PARAMS_VP9, "VP9" },
38 { AV_VIDEO_ENC_PARAMS_H264, "H264" },
39 { AV_VIDEO_ENC_PARAMS_MPEG2, "MPEG2" },
40 };
41
42 /* av_video_enc_params_alloc - each type with blocks */
43 1 printf("Testing av_video_enc_params_alloc()\n");
44
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; i++) {
45 3 par = av_video_enc_params_alloc(types[i].type, 4, &size);
46
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (par) {
47 3 printf("%s: OK, type=%d, nb_blocks=%u, size>0=%s\n",
48 3 types[i].name, par->type, par->nb_blocks,
49
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 size > 0 ? "yes" : "no");
50 3 av_free(par);
51 } else {
52 printf("%s: FAIL\n", types[i].name);
53 }
54 }
55
56 /* zero blocks */
57 1 par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_VP9, 0, &size);
58
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (par) {
59 1 printf("zero blocks: OK, nb_blocks=%u\n", par->nb_blocks);
60 1 av_free(par);
61 } else {
62 printf("zero blocks: FAIL\n");
63 }
64
65 /* alloc without size */
66 1 par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_H264, 1, NULL);
67
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 printf("alloc (no size): %s\n", par ? "OK" : "FAIL");
68 1 av_free(par);
69
70 /* av_video_enc_params_block - write and read back */
71 1 printf("\nTesting av_video_enc_params_block()\n");
72 1 par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_H264, 3, NULL);
73
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (par) {
74 1 par->qp = 26;
75 1 par->delta_qp[0][0] = -2;
76 1 par->delta_qp[0][1] = -1;
77 1 printf("frame qp=%d, delta_qp[0]={%d,%d}\n",
78 par->qp, par->delta_qp[0][0], par->delta_qp[0][1]);
79
80
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; i++) {
81 3 block = av_video_enc_params_block(par, i);
82 3 if ((uint8_t *)block != (uint8_t *)par + par->blocks_offset +
83
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 (size_t)i * par->block_size)
84 printf("block %d: pointer inconsistent with blocks_offset/block_size\n", i);
85 3 block->src_x = i * 16;
86 3 block->src_y = i * 16;
87 3 block->w = 16;
88 3 block->h = 16;
89 3 block->delta_qp = i - 1;
90 }
91
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 for (int i = 0; i < 3; i++) {
92 3 block = av_video_enc_params_block(par, i);
93 3 printf("block %d: src=(%d,%d) size=%dx%d delta_qp=%d\n",
94 i, block->src_x, block->src_y,
95 block->w, block->h, block->delta_qp);
96 }
97 1 av_free(par);
98 }
99
100 /* av_video_enc_params_create_side_data */
101 1 printf("\nTesting av_video_enc_params_create_side_data()\n");
102 1 frame = av_frame_alloc();
103
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (frame) {
104 1 par = av_video_enc_params_create_side_data(frame,
105 AV_VIDEO_ENC_PARAMS_VP9, 2);
106
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (par) {
107 1 printf("side_data: OK, type=%d, nb_blocks=%u\n",
108 1 par->type, par->nb_blocks);
109 1 block = av_video_enc_params_block(par, 0);
110 1 block->delta_qp = 5;
111 1 block = av_video_enc_params_block(par, 0);
112 1 printf("side_data block 0: delta_qp=%d\n", block->delta_qp);
113 } else {
114 printf("side_data: FAIL\n");
115 }
116 1 av_frame_free(&frame);
117 }
118
119 /* NONE type */
120 1 printf("\nTesting NONE type\n");
121 1 par = av_video_enc_params_alloc(AV_VIDEO_ENC_PARAMS_NONE, 0, &size);
122
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (par) {
123 1 printf("NONE: OK, type=%d\n", par->type);
124 1 av_free(par);
125 } else {
126 printf("NONE: FAIL\n");
127 }
128
129 1 return 0;
130 }
131