Coverage Report

Created: 2026-11-12 07:28

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
/* look at libavutil av_log2 ;) */
39
static inline
40
unsigned vlc_log2( unsigned int v )
41
42.2k
{
42
42.2k
    unsigned n = 0;
43
42.2k
    static const unsigned vlc_log2_table[16] =
44
42.2k
    {
45
42.2k
        0,0,1,1,2,2,2,2, 3,3,3,3,3,3,3,3
46
42.2k
    };
47
48
42.2k
    if( v&0xffff0000 )
49
0
    {
50
0
        v >>= 16;
51
0
        n += 16;
52
0
    }
53
42.2k
    if( v&0xff00 )
54
40.6k
    {
55
40.6k
        v >>= 8;
56
40.6k
        n += 8;
57
40.6k
    }
58
42.2k
    if( v&0xf0 )
59
39.6k
    {
60
39.6k
        v >>= 4;
61
39.6k
        n += 4;
62
39.6k
    }
63
42.2k
    n += vlc_log2_table[v];
64
65
42.2k
    return n;
66
42.2k
}
Unexecuted instantiation: hevc_nal.c:vlc_log2
mpeg4video.c:vlc_log2
Line
Count
Source
41
42.2k
{
42
42.2k
    unsigned n = 0;
43
42.2k
    static const unsigned vlc_log2_table[16] =
44
42.2k
    {
45
42.2k
        0,0,1,1,2,2,2,2, 3,3,3,3,3,3,3,3
46
42.2k
    };
47
48
42.2k
    if( v&0xffff0000 )
49
0
    {
50
0
        v >>= 16;
51
0
        n += 16;
52
0
    }
53
42.2k
    if( v&0xff00 )
54
40.6k
    {
55
40.6k
        v >>= 8;
56
40.6k
        n += 8;
57
40.6k
    }
58
42.2k
    if( v&0xf0 )
59
39.6k
    {
60
39.6k
        v >>= 4;
61
39.6k
        n += 4;
62
39.6k
    }
63
42.2k
    n += vlc_log2_table[v];
64
65
42.2k
    return n;
66
42.2k
}
Unexecuted instantiation: mpegvideo.c:vlc_log2
67
68
typedef struct
69
{
70
    nal_ue_t left_offset;
71
    nal_ue_t right_offset;
72
    nal_ue_t top_offset;
73
    nal_ue_t bottom_offset;
74
} h26x_conf_window_t;
75
76
static inline
77
bool h26x_get_picture_size( nal_u2_t chroma_format_idc,
78
                            nal_ue_t pic_width_in_luma_samples,
79
                            nal_ue_t pic_height_in_luma_samples,
80
                            const h26x_conf_window_t *conf_win,
81
                            unsigned *p_ox, unsigned *p_oy,
82
                            unsigned *p_w, unsigned *p_h,
83
                            unsigned *p_vw, unsigned *p_vh )
84
129k
{
85
129k
    unsigned ox, oy, w, h, vw, vh;
86
129k
    w = vw = pic_width_in_luma_samples;
87
129k
    h = vh = pic_height_in_luma_samples;
88
89
129k
    if( chroma_format_idc > 3 )
90
0
    {
91
0
        assert( chroma_format_idc <= 3 );
92
0
        return false;
93
0
    }
94
95
129k
    static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} };
96
97
129k
    ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0];
98
129k
    oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1];
99
100
129k
    vw -= (conf_win->left_offset +  conf_win->right_offset) *
101
129k
          SubWidthHeight[chroma_format_idc][0];
102
129k
    vh -= (conf_win->bottom_offset + conf_win->top_offset) *
103
129k
          SubWidthHeight[chroma_format_idc][1];
104
105
129k
    if ( vw > w || vh > h )
106
6.27k
        return false;
107
108
123k
    *p_ox = ox; *p_oy = oy;
109
123k
    *p_w = w; *p_h = h;
110
123k
    *p_vw = vw; *p_vh = vh;
111
123k
    return true;
112
129k
}
hevc_nal.c:h26x_get_picture_size
Line
Count
Source
84
129k
{
85
129k
    unsigned ox, oy, w, h, vw, vh;
86
129k
    w = vw = pic_width_in_luma_samples;
87
129k
    h = vh = pic_height_in_luma_samples;
88
89
129k
    if( chroma_format_idc > 3 )
90
0
    {
91
0
        assert( chroma_format_idc <= 3 );
92
0
        return false;
93
0
    }
94
95
129k
    static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} };
96
97
129k
    ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0];
98
129k
    oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1];
99
100
129k
    vw -= (conf_win->left_offset +  conf_win->right_offset) *
101
129k
          SubWidthHeight[chroma_format_idc][0];
102
129k
    vh -= (conf_win->bottom_offset + conf_win->top_offset) *
103
129k
          SubWidthHeight[chroma_format_idc][1];
104
105
129k
    if ( vw > w || vh > h )
106
6.27k
        return false;
107
108
123k
    *p_ox = ox; *p_oy = oy;
109
123k
    *p_w = w; *p_h = h;
110
123k
    *p_vw = vw; *p_vh = vh;
111
    return true;
112
129k
}
Unexecuted instantiation: mpeg4video.c:h26x_get_picture_size
Unexecuted instantiation: mpegvideo.c:h26x_get_picture_size
113
114
typedef struct
115
{
116
    nal_u8_t aspect_ratio_idc;
117
    uint16_t sar_width;
118
    uint16_t sar_height;
119
} h26x_aspect_ratio_t;
120
121
static inline
122
bool h26x_get_aspect_ratio( const h26x_aspect_ratio_t *ar,
123
                            unsigned *num, unsigned *den )
124
171k
{
125
171k
    if( ar->aspect_ratio_idc != 255 )
126
146k
    {
127
146k
        static const uint8_t ar_table[16][2] =
128
146k
            {
129
146k
             {    1,      1 },
130
146k
             {   12,     11 },
131
146k
             {   10,     11 },
132
146k
             {   16,     11 },
133
146k
             {   40,     33 },
134
146k
             {   24,     11 },
135
146k
             {   20,     11 },
136
146k
             {   32,     11 },
137
146k
             {   80,     33 },
138
146k
             {   18,     11 },
139
146k
             {   15,     11 },
140
146k
             {   64,     33 },
141
146k
             {  160,     99 },
142
146k
             {    4,      3 },
143
146k
             {    3,      2 },
144
146k
             {    2,      1 },
145
146k
             };
146
146k
        if( ar->aspect_ratio_idc == 0 ||
147
103k
            ar->aspect_ratio_idc >= 17 )
148
55.7k
            return false;
149
90.3k
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
150
90.3k
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
151
90.3k
    }
152
25.6k
    else
153
25.6k
    {
154
25.6k
        *num = ar->sar_width;
155
25.6k
        *den = ar->sar_height;
156
25.6k
    }
157
115k
    return true;
158
171k
}
hevc_nal.c:h26x_get_aspect_ratio
Line
Count
Source
124
39.3k
{
125
39.3k
    if( ar->aspect_ratio_idc != 255 )
126
27.3k
    {
127
27.3k
        static const uint8_t ar_table[16][2] =
128
27.3k
            {
129
27.3k
             {    1,      1 },
130
27.3k
             {   12,     11 },
131
27.3k
             {   10,     11 },
132
27.3k
             {   16,     11 },
133
27.3k
             {   40,     33 },
134
27.3k
             {   24,     11 },
135
27.3k
             {   20,     11 },
136
27.3k
             {   32,     11 },
137
27.3k
             {   80,     33 },
138
27.3k
             {   18,     11 },
139
27.3k
             {   15,     11 },
140
27.3k
             {   64,     33 },
141
27.3k
             {  160,     99 },
142
27.3k
             {    4,      3 },
143
27.3k
             {    3,      2 },
144
27.3k
             {    2,      1 },
145
27.3k
             };
146
27.3k
        if( ar->aspect_ratio_idc == 0 ||
147
13.6k
            ar->aspect_ratio_idc >= 17 )
148
27.0k
            return false;
149
363
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
150
363
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
151
363
    }
152
11.9k
    else
153
11.9k
    {
154
11.9k
        *num = ar->sar_width;
155
11.9k
        *den = ar->sar_height;
156
11.9k
    }
157
12.3k
    return true;
158
39.3k
}
mpeg4video.c:h26x_get_aspect_ratio
Line
Count
Source
124
132k
{
125
132k
    if( ar->aspect_ratio_idc != 255 )
126
118k
    {
127
118k
        static const uint8_t ar_table[16][2] =
128
118k
            {
129
118k
             {    1,      1 },
130
118k
             {   12,     11 },
131
118k
             {   10,     11 },
132
118k
             {   16,     11 },
133
118k
             {   40,     33 },
134
118k
             {   24,     11 },
135
118k
             {   20,     11 },
136
118k
             {   32,     11 },
137
118k
             {   80,     33 },
138
118k
             {   18,     11 },
139
118k
             {   15,     11 },
140
118k
             {   64,     33 },
141
118k
             {  160,     99 },
142
118k
             {    4,      3 },
143
118k
             {    3,      2 },
144
118k
             {    2,      1 },
145
118k
             };
146
118k
        if( ar->aspect_ratio_idc == 0 ||
147
89.9k
            ar->aspect_ratio_idc >= 17 )
148
28.6k
            return false;
149
89.9k
        *num = ar_table[ar->aspect_ratio_idc - 1][0];
150
89.9k
        *den = ar_table[ar->aspect_ratio_idc - 1][1];
151
89.9k
    }
152
13.6k
    else
153
13.6k
    {
154
13.6k
        *num = ar->sar_width;
155
13.6k
        *den = ar->sar_height;
156
13.6k
    }
157
103k
    return true;
158
132k
}
Unexecuted instantiation: mpegvideo.c:h26x_get_aspect_ratio
159
160
typedef struct
161
{
162
    nal_u8_t colour_primaries;
163
    nal_u8_t transfer_characteristics;
164
    nal_u8_t matrix_coeffs;
165
    nal_u1_t full_range_flag;
166
} h26x_colour_description_t;
167
168
static inline
169
bool h26x_get_colorimetry( const h26x_colour_description_t *colour,
170
                           video_color_primaries_t *p_primaries,
171
                           video_transfer_func_t *p_transfer,
172
                           video_color_space_t *p_colorspace,
173
                           video_color_range_t *p_full_range )
174
75.7k
{
175
75.7k
    *p_primaries =
176
75.7k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
177
75.7k
    *p_transfer =
178
75.7k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
179
75.7k
    *p_colorspace =
180
75.7k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
181
75.7k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
182
    return true;
183
75.7k
}
hevc_nal.c:h26x_get_colorimetry
Line
Count
Source
174
50.1k
{
175
50.1k
    *p_primaries =
176
50.1k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
177
50.1k
    *p_transfer =
178
50.1k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
179
50.1k
    *p_colorspace =
180
50.1k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
181
50.1k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
182
    return true;
183
50.1k
}
mpeg4video.c:h26x_get_colorimetry
Line
Count
Source
174
4.87k
{
175
4.87k
    *p_primaries =
176
4.87k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
177
4.87k
    *p_transfer =
178
4.87k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
179
4.87k
    *p_colorspace =
180
4.87k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
181
4.87k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
182
    return true;
183
4.87k
}
mpegvideo.c:h26x_get_colorimetry
Line
Count
Source
174
20.6k
{
175
20.6k
    *p_primaries =
176
20.6k
        iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries );
177
20.6k
    *p_transfer =
178
20.6k
        iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics );
179
20.6k
    *p_colorspace =
180
20.6k
        iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs );
181
20.6k
    *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED;
182
    return true;
183
20.6k
}
184
185
#endif