Coverage Report

Created: 2026-08-13 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/h26x_nal_common.h
Line
Count
Source
1
/*****************************************************************************
2
 * h26x_nal_common.h: h26x shared code
3
 *****************************************************************************
4
 * Copyright © 2010-2024 VideoLabs, VideoLAN and VLC Authors
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#ifndef H26X_NAL_COMMON_H
21
# define H26X_NAL_COMMON_H
22
23
#include <assert.h>
24
#include <vlc_common.h>
25
#include "iso_color_tables.h"
26
27
typedef uint8_t  nal_u1_t;
28
typedef uint8_t  nal_u2_t;
29
typedef uint8_t  nal_u3_t;
30
typedef uint8_t  nal_u4_t;
31
typedef uint8_t  nal_u5_t;
32
typedef uint8_t  nal_u6_t;
33
typedef uint8_t  nal_u7_t;
34
typedef uint8_t  nal_u8_t;
35
typedef int32_t  nal_se_t;
36
typedef uint32_t nal_ue_t;
37
38
typedef struct
39
{
40
    nal_ue_t left_offset;
41
    nal_ue_t right_offset;
42
    nal_ue_t top_offset;
43
    nal_ue_t bottom_offset;
44
} h26x_conf_window_t;
45
46
static inline
47
bool h26x_get_picture_size( nal_u2_t chroma_format_idc,
48
                            nal_ue_t pic_width_in_luma_samples,
49
                            nal_ue_t pic_height_in_luma_samples,
50
                            const h26x_conf_window_t *conf_win,
51
                            unsigned *p_ox, unsigned *p_oy,
52
                            unsigned *p_w, unsigned *p_h,
53
                            unsigned *p_vw, unsigned *p_vh )
54
14.6k
{
55
14.6k
    unsigned ox, oy, w, h, vw, vh;
56
14.6k
    w = vw = pic_width_in_luma_samples;
57
14.6k
    h = vh = pic_height_in_luma_samples;
58
59
14.6k
    if( chroma_format_idc > 3 )
60
0
    {
61
0
        assert( chroma_format_idc <= 3 );
62
0
        return false;
63
0
    }
64
65
14.6k
    static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} };
66
67
14.6k
    ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0];
68
14.6k
    oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1];
69
70
14.6k
    vw -= (conf_win->left_offset +  conf_win->right_offset) *
71
14.6k
          SubWidthHeight[chroma_format_idc][0];
72
14.6k
    vh -= (conf_win->bottom_offset + conf_win->top_offset) *
73
14.6k
          SubWidthHeight[chroma_format_idc][1];
74
75
14.6k
    if ( vw > w || vh > h )
76
6.13k
        return false;
77
78
8.54k
    *p_ox = ox; *p_oy = oy;
79
8.54k
    *p_w = w; *p_h = h;
80
8.54k
    *p_vw = vw; *p_vh = vh;
81
8.54k
    return true;
82
14.6k
}
hevc_nal.c:h26x_get_picture_size
Line
Count
Source
54
14.6k
{
55
14.6k
    unsigned ox, oy, w, h, vw, vh;
56
14.6k
    w = vw = pic_width_in_luma_samples;
57
14.6k
    h = vh = pic_height_in_luma_samples;
58
59
14.6k
    if( chroma_format_idc > 3 )
60
0
    {
61
0
        assert( chroma_format_idc <= 3 );
62
0
        return false;
63
0
    }
64
65
14.6k
    static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} };
66
67
14.6k
    ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0];
68
14.6k
    oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1];
69
70
14.6k
    vw -= (conf_win->left_offset +  conf_win->right_offset) *
71
14.6k
          SubWidthHeight[chroma_format_idc][0];
72
14.6k
    vh -= (conf_win->bottom_offset + conf_win->top_offset) *
73
14.6k
          SubWidthHeight[chroma_format_idc][1];
74
75
14.6k
    if ( vw > w || vh > h )
76
6.13k
        return false;
77
78
8.54k
    *p_ox = ox; *p_oy = oy;
79
8.54k
    *p_w = w; *p_h = h;
80
8.54k
    *p_vw = vw; *p_vh = vh;
81
    return true;
82
14.6k
}
Unexecuted instantiation: mpeg4video.c:h26x_get_picture_size
Unexecuted instantiation: mpegvideo.c:h26x_get_picture_size
83
84
typedef struct
85
{
86
    nal_u8_t aspect_ratio_idc;
87
    uint16_t sar_width;
88
    uint16_t sar_height;
89
} h26x_aspect_ratio_t;
90
91
static inline
92
bool h26x_get_aspect_ratio( const h26x_aspect_ratio_t *ar,
93
                            unsigned *num, unsigned *den )
94
141k
{
95
141k
    if( ar->aspect_ratio_idc != 255 )
96
108k
    {
97
108k
        static const uint8_t ar_table[16][2] =
98
108k
            {
99
108k
             {    1,      1 },
100
108k
             {   12,     11 },
101
108k
             {   10,     11 },
102
108k
             {   16,     11 },
103
108k
             {   40,     33 },
104
108k
             {   24,     11 },
105
108k
             {   20,     11 },
106
108k
             {   32,     11 },
107
108k
             {   80,     33 },
108
108k
             {   18,     11 },
109
108k
             {   15,     11 },
110
108k
             {   64,     33 },
111
108k
             {  160,     99 },
112
108k
             {    4,      3 },
113
108k
             {    3,      2 },
114
108k
             {    2,      1 },
115
108k
             };
116
108k
        if( ar->aspect_ratio_idc == 0 ||
117
75.6k
            ar->aspect_ratio_idc >= 17 )
118
36.8k
            return false;
119
71.8k
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
120
71.8k
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
121
71.8k
    }
122
32.8k
    else
123
32.8k
    {
124
32.8k
        *num = ar->sar_width;
125
32.8k
        *den = ar->sar_height;
126
32.8k
    }
127
104k
    return true;
128
141k
}
hevc_nal.c:h26x_get_aspect_ratio
Line
Count
Source
94
7.51k
{
95
7.51k
    if( ar->aspect_ratio_idc != 255 )
96
6.36k
    {
97
6.36k
        static const uint8_t ar_table[16][2] =
98
6.36k
            {
99
6.36k
             {    1,      1 },
100
6.36k
             {   12,     11 },
101
6.36k
             {   10,     11 },
102
6.36k
             {   16,     11 },
103
6.36k
             {   40,     33 },
104
6.36k
             {   24,     11 },
105
6.36k
             {   20,     11 },
106
6.36k
             {   32,     11 },
107
6.36k
             {   80,     33 },
108
6.36k
             {   18,     11 },
109
6.36k
             {   15,     11 },
110
6.36k
             {   64,     33 },
111
6.36k
             {  160,     99 },
112
6.36k
             {    4,      3 },
113
6.36k
             {    3,      2 },
114
6.36k
             {    2,      1 },
115
6.36k
             };
116
6.36k
        if( ar->aspect_ratio_idc == 0 ||
117
3.90k
            ar->aspect_ratio_idc >= 17 )
118
6.28k
            return false;
119
84
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
120
84
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
121
84
    }
122
1.15k
    else
123
1.15k
    {
124
1.15k
        *num = ar->sar_width;
125
1.15k
        *den = ar->sar_height;
126
1.15k
    }
127
1.23k
    return true;
128
7.51k
}
mpeg4video.c:h26x_get_aspect_ratio
Line
Count
Source
94
133k
{
95
133k
    if( ar->aspect_ratio_idc != 255 )
96
102k
    {
97
102k
        static const uint8_t ar_table[16][2] =
98
102k
            {
99
102k
             {    1,      1 },
100
102k
             {   12,     11 },
101
102k
             {   10,     11 },
102
102k
             {   16,     11 },
103
102k
             {   40,     33 },
104
102k
             {   24,     11 },
105
102k
             {   20,     11 },
106
102k
             {   32,     11 },
107
102k
             {   80,     33 },
108
102k
             {   18,     11 },
109
102k
             {   15,     11 },
110
102k
             {   64,     33 },
111
102k
             {  160,     99 },
112
102k
             {    4,      3 },
113
102k
             {    3,      2 },
114
102k
             {    2,      1 },
115
102k
             };
116
102k
        if( ar->aspect_ratio_idc == 0 ||
117
71.7k
            ar->aspect_ratio_idc >= 17 )
118
30.5k
            return false;
119
71.7k
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
120
71.7k
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
121
71.7k
    }
122
31.6k
    else
123
31.6k
    {
124
31.6k
        *num = ar->sar_width;
125
31.6k
        *den = ar->sar_height;
126
31.6k
    }
127
103k
    return true;
128
133k
}
Unexecuted instantiation: mpegvideo.c:h26x_get_aspect_ratio
129
130
typedef struct
131
{
132
    nal_u8_t colour_primaries;
133
    nal_u8_t transfer_characteristics;
134
    nal_u8_t matrix_coeffs;
135
    nal_u1_t full_range_flag;
136
} h26x_colour_description_t;
137
138
static inline
139
bool h26x_get_colorimetry( const h26x_colour_description_t *colour,
140
                           video_color_primaries_t *p_primaries,
141
                           video_transfer_func_t *p_transfer,
142
                           video_color_space_t *p_colorspace,
143
                           video_color_range_t *p_full_range )
144
33.1k
{
145
33.1k
    *p_primaries =
146
33.1k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
147
33.1k
    *p_transfer =
148
33.1k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
149
33.1k
    *p_colorspace =
150
33.1k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
151
33.1k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
152
    return true;
153
33.1k
}
hevc_nal.c:h26x_get_colorimetry
Line
Count
Source
144
11.1k
{
145
11.1k
    *p_primaries =
146
11.1k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
147
11.1k
    *p_transfer =
148
11.1k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
149
11.1k
    *p_colorspace =
150
11.1k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
151
11.1k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
152
    return true;
153
11.1k
}
mpeg4video.c:h26x_get_colorimetry
Line
Count
Source
144
2.89k
{
145
2.89k
    *p_primaries =
146
2.89k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
147
2.89k
    *p_transfer =
148
2.89k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
149
2.89k
    *p_colorspace =
150
2.89k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
151
2.89k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
152
    return true;
153
2.89k
}
mpegvideo.c:h26x_get_colorimetry
Line
Count
Source
144
19.1k
{
145
19.1k
    *p_primaries =
146
19.1k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
147
19.1k
    *p_transfer =
148
19.1k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
149
19.1k
    *p_colorspace =
150
19.1k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
151
19.1k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
152
    return true;
153
19.1k
}
154
155
#endif