/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 | 94.3k | { |
55 | 94.3k | unsigned ox, oy, w, h, vw, vh; |
56 | 94.3k | w = vw = pic_width_in_luma_samples; |
57 | 94.3k | h = vh = pic_height_in_luma_samples; |
58 | | |
59 | 94.3k | if( chroma_format_idc > 3 ) |
60 | 0 | { |
61 | 0 | assert( chroma_format_idc <= 3 ); |
62 | 0 | return false; |
63 | 0 | } |
64 | | |
65 | 94.3k | static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} }; |
66 | | |
67 | 94.3k | ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0]; |
68 | 94.3k | oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1]; |
69 | | |
70 | 94.3k | vw -= (conf_win->left_offset + conf_win->right_offset) * |
71 | 94.3k | SubWidthHeight[chroma_format_idc][0]; |
72 | 94.3k | vh -= (conf_win->bottom_offset + conf_win->top_offset) * |
73 | 94.3k | SubWidthHeight[chroma_format_idc][1]; |
74 | | |
75 | 94.3k | if ( vw > w || vh > h ) |
76 | 7.18k | return false; |
77 | | |
78 | 87.2k | *p_ox = ox; *p_oy = oy; |
79 | 87.2k | *p_w = w; *p_h = h; |
80 | 87.2k | *p_vw = vw; *p_vh = vh; |
81 | 87.2k | return true; |
82 | 94.3k | } hevc_nal.c:h26x_get_picture_size Line | Count | Source | 54 | 94.3k | { | 55 | 94.3k | unsigned ox, oy, w, h, vw, vh; | 56 | 94.3k | w = vw = pic_width_in_luma_samples; | 57 | 94.3k | h = vh = pic_height_in_luma_samples; | 58 | | | 59 | 94.3k | if( chroma_format_idc > 3 ) | 60 | 0 | { | 61 | 0 | assert( chroma_format_idc <= 3 ); | 62 | 0 | return false; | 63 | 0 | } | 64 | | | 65 | 94.3k | static const uint8_t SubWidthHeight[4][2] = { {1, 1}, {2, 2}, {2, 1}, {1, 1} }; | 66 | | | 67 | 94.3k | ox = conf_win->left_offset * SubWidthHeight[chroma_format_idc][0]; | 68 | 94.3k | oy = conf_win->top_offset * SubWidthHeight[chroma_format_idc][1]; | 69 | | | 70 | 94.3k | vw -= (conf_win->left_offset + conf_win->right_offset) * | 71 | 94.3k | SubWidthHeight[chroma_format_idc][0]; | 72 | 94.3k | vh -= (conf_win->bottom_offset + conf_win->top_offset) * | 73 | 94.3k | SubWidthHeight[chroma_format_idc][1]; | 74 | | | 75 | 94.3k | if ( vw > w || vh > h ) | 76 | 7.18k | return false; | 77 | | | 78 | 87.2k | *p_ox = ox; *p_oy = oy; | 79 | 87.2k | *p_w = w; *p_h = h; | 80 | 87.2k | *p_vw = vw; *p_vh = vh; | 81 | | return true; | 82 | 94.3k | } |
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 | 117k | { |
95 | 117k | if( ar->aspect_ratio_idc != 255 ) |
96 | 83.1k | { |
97 | 83.1k | static const uint8_t ar_table[16][2] = |
98 | 83.1k | { |
99 | 83.1k | { 1, 1 }, |
100 | 83.1k | { 12, 11 }, |
101 | 83.1k | { 10, 11 }, |
102 | 83.1k | { 16, 11 }, |
103 | 83.1k | { 40, 33 }, |
104 | 83.1k | { 24, 11 }, |
105 | 83.1k | { 20, 11 }, |
106 | 83.1k | { 32, 11 }, |
107 | 83.1k | { 80, 33 }, |
108 | 83.1k | { 18, 11 }, |
109 | 83.1k | { 15, 11 }, |
110 | 83.1k | { 64, 33 }, |
111 | 83.1k | { 160, 99 }, |
112 | 83.1k | { 4, 3 }, |
113 | 83.1k | { 3, 2 }, |
114 | 83.1k | { 2, 1 }, |
115 | 83.1k | }; |
116 | 83.1k | if( ar->aspect_ratio_idc == 0 || |
117 | 41.4k | ar->aspect_ratio_idc >= 17 ) |
118 | 51.2k | return false; |
119 | 31.9k | *num = ar_table[ar->aspect_ratio_idc - 1][0]; |
120 | 31.9k | *den = ar_table[ar->aspect_ratio_idc - 1][1]; |
121 | 31.9k | } |
122 | 34.0k | else |
123 | 34.0k | { |
124 | 34.0k | *num = ar->sar_width; |
125 | 34.0k | *den = ar->sar_height; |
126 | 34.0k | } |
127 | 66.0k | return true; |
128 | 117k | } hevc_nal.c:h26x_get_aspect_ratio Line | Count | Source | 94 | 41.5k | { | 95 | 41.5k | if( ar->aspect_ratio_idc != 255 ) | 96 | 36.1k | { | 97 | 36.1k | static const uint8_t ar_table[16][2] = | 98 | 36.1k | { | 99 | 36.1k | { 1, 1 }, | 100 | 36.1k | { 12, 11 }, | 101 | 36.1k | { 10, 11 }, | 102 | 36.1k | { 16, 11 }, | 103 | 36.1k | { 40, 33 }, | 104 | 36.1k | { 24, 11 }, | 105 | 36.1k | { 20, 11 }, | 106 | 36.1k | { 32, 11 }, | 107 | 36.1k | { 80, 33 }, | 108 | 36.1k | { 18, 11 }, | 109 | 36.1k | { 15, 11 }, | 110 | 36.1k | { 64, 33 }, | 111 | 36.1k | { 160, 99 }, | 112 | 36.1k | { 4, 3 }, | 113 | 36.1k | { 3, 2 }, | 114 | 36.1k | { 2, 1 }, | 115 | 36.1k | }; | 116 | 36.1k | if( ar->aspect_ratio_idc == 0 || | 117 | 10.0k | ar->aspect_ratio_idc >= 17 ) | 118 | 35.5k | return false; | 119 | 594 | *num = ar_table[ar->aspect_ratio_idc - 1][0]; | 120 | 594 | *den = ar_table[ar->aspect_ratio_idc - 1][1]; | 121 | 594 | } | 122 | 5.34k | else | 123 | 5.34k | { | 124 | 5.34k | *num = ar->sar_width; | 125 | 5.34k | *den = ar->sar_height; | 126 | 5.34k | } | 127 | 5.94k | return true; | 128 | 41.5k | } |
mpeg4video.c:h26x_get_aspect_ratio Line | Count | Source | 94 | 75.7k | { | 95 | 75.7k | if( ar->aspect_ratio_idc != 255 ) | 96 | 47.0k | { | 97 | 47.0k | static const uint8_t ar_table[16][2] = | 98 | 47.0k | { | 99 | 47.0k | { 1, 1 }, | 100 | 47.0k | { 12, 11 }, | 101 | 47.0k | { 10, 11 }, | 102 | 47.0k | { 16, 11 }, | 103 | 47.0k | { 40, 33 }, | 104 | 47.0k | { 24, 11 }, | 105 | 47.0k | { 20, 11 }, | 106 | 47.0k | { 32, 11 }, | 107 | 47.0k | { 80, 33 }, | 108 | 47.0k | { 18, 11 }, | 109 | 47.0k | { 15, 11 }, | 110 | 47.0k | { 64, 33 }, | 111 | 47.0k | { 160, 99 }, | 112 | 47.0k | { 4, 3 }, | 113 | 47.0k | { 3, 2 }, | 114 | 47.0k | { 2, 1 }, | 115 | 47.0k | }; | 116 | 47.0k | if( ar->aspect_ratio_idc == 0 || | 117 | 31.3k | ar->aspect_ratio_idc >= 17 ) | 118 | 15.6k | return false; | 119 | 31.3k | *num = ar_table[ar->aspect_ratio_idc - 1][0]; | 120 | 31.3k | *den = ar_table[ar->aspect_ratio_idc - 1][1]; | 121 | 31.3k | } | 122 | 28.7k | else | 123 | 28.7k | { | 124 | 28.7k | *num = ar->sar_width; | 125 | 28.7k | *den = ar->sar_height; | 126 | 28.7k | } | 127 | 60.0k | return true; | 128 | 75.7k | } |
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 | 56.8k | { |
145 | 56.8k | *p_primaries = |
146 | 56.8k | iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries ); |
147 | 56.8k | *p_transfer = |
148 | 56.8k | iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics ); |
149 | 56.8k | *p_colorspace = |
150 | 56.8k | iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs ); |
151 | 56.8k | *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED; |
152 | | return true; |
153 | 56.8k | } hevc_nal.c:h26x_get_colorimetry Line | Count | Source | 144 | 43.8k | { | 145 | 43.8k | *p_primaries = | 146 | 43.8k | iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries ); | 147 | 43.8k | *p_transfer = | 148 | 43.8k | iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics ); | 149 | 43.8k | *p_colorspace = | 150 | 43.8k | iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs ); | 151 | 43.8k | *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED; | 152 | | return true; | 153 | 43.8k | } |
mpeg4video.c:h26x_get_colorimetry Line | Count | Source | 144 | 2.94k | { | 145 | 2.94k | *p_primaries = | 146 | 2.94k | iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries ); | 147 | 2.94k | *p_transfer = | 148 | 2.94k | iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics ); | 149 | 2.94k | *p_colorspace = | 150 | 2.94k | iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs ); | 151 | 2.94k | *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED; | 152 | | return true; | 153 | 2.94k | } |
mpegvideo.c:h26x_get_colorimetry Line | Count | Source | 144 | 10.0k | { | 145 | 10.0k | *p_primaries = | 146 | 10.0k | iso_23001_8_cp_to_vlc_primaries( colour->colour_primaries ); | 147 | 10.0k | *p_transfer = | 148 | 10.0k | iso_23001_8_tc_to_vlc_xfer( colour->transfer_characteristics ); | 149 | 10.0k | *p_colorspace = | 150 | 10.0k | iso_23001_8_mc_to_vlc_coeffs( colour->matrix_coeffs ); | 151 | 10.0k | *p_full_range = colour->full_range_flag ? COLOR_RANGE_FULL : COLOR_RANGE_LIMITED; | 152 | | return true; | 153 | 10.0k | } |
|
154 | | |
155 | | #endif |