FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/qp_table.c
Date: 2025-06-23 20:06:14
Exec Total Coverage
Lines: 22 29 75.9%
Functions: 1 1 100.0%
Branches: 11 22 50.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdint.h>
20
21 #include "libavutil/frame.h"
22 #include "libavutil/mem.h"
23 #include "libavutil/video_enc_params.h"
24
25 #include "qp_table.h"
26
27 7 int ff_qp_table_extract(AVFrame *frame, int8_t **table, int *table_w, int *table_h,
28 enum AVVideoEncParamsType *qscale_type)
29 {
30 AVFrameSideData *sd;
31 AVVideoEncParams *par;
32 7 unsigned int mb_h = (frame->height + 15) / 16;
33 7 unsigned int mb_w = (frame->width + 15) / 16;
34 7 unsigned int nb_mb = mb_h * mb_w;
35 unsigned int block_idx;
36
37 7 *table = NULL;
38
39 7 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
40
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (!sd)
41 return 0;
42 7 par = (AVVideoEncParams *)sd->data;
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if ((par->type != AV_VIDEO_ENC_PARAMS_MPEG2 &&
44 par->type != AV_VIDEO_ENC_PARAMS_H264) ||
45
2/4
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
7 (par->nb_blocks != 0 && par->nb_blocks != nb_mb))
46 return AVERROR(ENOSYS);
47
48 7 *table = av_malloc(nb_mb);
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (!*table)
50 return AVERROR(ENOMEM);
51
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (table_w)
52 7 *table_w = mb_w;
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (table_h)
54 *table_h = mb_h;
55
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (qscale_type)
56 7 *qscale_type = par->type;
57
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if (par->nb_blocks == 0) {
59 memset(*table, par->qp, nb_mb);
60 return 0;
61 }
62
63
2/2
✓ Branch 0 taken 2772 times.
✓ Branch 1 taken 7 times.
2779 for (block_idx = 0; block_idx < nb_mb; block_idx++) {
64 2772 AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
65 2772 (*table)[block_idx] = par->qp + b->delta_qp;
66 }
67
68 7 return 0;
69 }
70
71