FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/qp_table.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 25 28 89.3%
Functions: 1 1 100.0%
Branches: 15 20 75.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 47 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 47 unsigned int mb_h = (frame->height + 15) / 16;
33 47 unsigned int mb_w = (frame->width + 15) / 16;
34 47 unsigned int nb_mb = mb_h * mb_w;
35 unsigned int block_idx;
36
37 47 *table = NULL;
38
39 47 sd = av_frame_get_side_data(frame, AV_FRAME_DATA_VIDEO_ENC_PARAMS);
40
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 27 times.
47 if (!sd)
41 20 return 0;
42 27 par = (AVVideoEncParams*)sd->data;
43
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (par->type != AV_VIDEO_ENC_PARAMS_MPEG2 ||
44
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
27 (par->nb_blocks != 0 && par->nb_blocks != nb_mb))
45 return AVERROR(ENOSYS);
46
47 27 *table = av_malloc(nb_mb);
48
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (!*table)
49 return AVERROR(ENOMEM);
50
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (table_w)
51 27 *table_w = mb_w;
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (table_h)
53 *table_h = mb_h;
54
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 20 times.
27 if (qscale_type)
55 7 *qscale_type = par->type;
56
57
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 22 times.
27 if (par->nb_blocks == 0) {
58 5 memset(*table, par->qp, nb_mb);
59 5 return 0;
60 }
61
62
2/2
✓ Branch 0 taken 8712 times.
✓ Branch 1 taken 22 times.
8734 for (block_idx = 0; block_idx < nb_mb; block_idx++) {
63 8712 AVVideoBlockParams *b = av_video_enc_params_block(par, block_idx);
64 8712 (*table)[block_idx] = par->qp + b->delta_qp;
65 }
66
67 22 return 0;
68 }
69
70