FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h2645_vui.c
Date: 2026-08-11 17:55:23
Exec Total Coverage
Lines: 43 47 91.5%
Functions: 1 1 100.0%
Branches: 27 36 75.0%

Line Branch Exec Source
1 /*
2 * Common H.264/HEVC VUI Parameter decoding
3 *
4 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5 * Copyright (C) 2012 - 2013 Guillaume Martres
6 * Copyright (C) 2012 - 2013 Mickael Raulet
7 * Copyright (C) 2012 - 2013 Gildas Cocherel
8 * Copyright (C) 2013 Vittorio Giovara
9 *
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27 #include "libavutil/log.h"
28 #include "libavutil/pixdesc.h"
29
30 #include "get_bits.h"
31 #include "golomb.h"
32 #include "h2645data.h"
33 #include "h2645_vui.h"
34
35 #define EXTENDED_SAR 255
36
37 1445 void ff_h2645_decode_common_vui_params(GetBitContext *gb, H2645VUI *vui, void *logctx)
38 {
39 1445 av_log(logctx, AV_LOG_DEBUG, "Decoding VUI\n");
40
41 1445 vui->aspect_ratio_info_present_flag = get_bits1(gb);
42
2/2
✓ Branch 0 taken 699 times.
✓ Branch 1 taken 746 times.
1445 if (vui->aspect_ratio_info_present_flag) {
43 699 vui->aspect_ratio_idc = get_bits(gb, 8);
44
2/2
✓ Branch 0 taken 646 times.
✓ Branch 1 taken 53 times.
699 if (vui->aspect_ratio_idc < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect))
45 646 vui->sar = ff_h2645_pixel_aspect[vui->aspect_ratio_idc];
46
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
53 else if (vui->aspect_ratio_idc == EXTENDED_SAR) {
47 53 vui->sar.num = get_bits(gb, 16);
48 53 vui->sar.den = get_bits(gb, 16);
49
2/4
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53 times.
53 if (!vui->sar.num || !vui->sar.den) {
50 av_log(logctx, AV_LOG_WARNING,
51 "Invalid SAR %d/%d in bitstream, treating as unspecified.\n",
52 vui->sar.num, vui->sar.den);
53 vui->sar = (AVRational){ 0, 1 };
54 }
55 } else
56 av_log(logctx, AV_LOG_WARNING,
57 "Unknown SAR index: %u.\n", vui->aspect_ratio_idc);
58 } else
59 746 vui->sar = (AVRational){ 0, 1 };
60
61 1445 vui->overscan_info_present_flag = get_bits1(gb);
62
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 1367 times.
1445 if (vui->overscan_info_present_flag)
63 78 vui->overscan_appropriate_flag = get_bits1(gb);
64
65 1445 vui->video_signal_type_present_flag = get_bits1(gb);
66
2/2
✓ Branch 0 taken 329 times.
✓ Branch 1 taken 1116 times.
1445 if (vui->video_signal_type_present_flag) {
67 329 vui->video_format = get_bits(gb, 3);
68 329 vui->video_full_range_flag = get_bits1(gb);
69 329 vui->colour_description_present_flag = get_bits1(gb);
70
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 33 times.
329 if (vui->colour_description_present_flag) {
71 296 vui->colour_primaries = get_bits(gb, 8);
72 296 vui->transfer_characteristics = get_bits(gb, 8);
73 296 vui->matrix_coeffs = get_bits(gb, 8);
74
75 // Set invalid values to "unspecified"
76
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 2 times.
296 if (vui->colour_primaries == AVCOL_PRI_RESERVED0 ||
77
2/4
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 294 times.
588 vui->colour_primaries == AVCOL_PRI_RESERVED ||
78 294 !av_color_primaries_name(vui->colour_primaries))
79 2 vui->colour_primaries = AVCOL_PRI_UNSPECIFIED;
80
2/2
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 2 times.
296 if (vui->transfer_characteristics == AVCOL_TRC_RESERVED0 ||
81
2/4
✓ Branch 0 taken 294 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 294 times.
588 vui->transfer_characteristics == AVCOL_TRC_RESERVED ||
82 294 !av_color_transfer_name(vui->transfer_characteristics))
83 2 vui->transfer_characteristics = AVCOL_TRC_UNSPECIFIED;
84
3/4
✓ Branch 0 taken 294 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 294 times.
590 if (vui->matrix_coeffs == AVCOL_SPC_RESERVED ||
85 294 !av_color_space_name(vui->matrix_coeffs))
86 2 vui->matrix_coeffs = AVCOL_SPC_UNSPECIFIED;
87 }
88 }
89
90 1445 vui->chroma_loc_info_present_flag = get_bits1(gb);
91
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 1271 times.
1445 if (vui->chroma_loc_info_present_flag) {
92 174 vui->chroma_sample_loc_type_top_field = get_ue_golomb_31(gb);
93 174 vui->chroma_sample_loc_type_bottom_field = get_ue_golomb_31(gb);
94
1/2
✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
174 if (vui->chroma_sample_loc_type_top_field <= 5U)
95 174 vui->chroma_location = vui->chroma_sample_loc_type_top_field + 1;
96 else
97 vui->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
98 } else
99 1271 vui->chroma_location = AVCHROMA_LOC_LEFT;
100 1445 }
101