/src/vvdec/source/Lib/CommonLib/SEI_internal.cpp
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | #include "SEI_internal.h" |
43 | | #include "vvdec/sei.h" |
44 | | #include <stdlib.h> |
45 | | #include "CommonDef.h" |
46 | | |
47 | | namespace vvdec |
48 | | { |
49 | | |
50 | | const char *SEI_internal::getSEIMessageString( vvdecSEIPayloadType payloadType) |
51 | 0 | { |
52 | 0 | switch (payloadType) |
53 | 0 | { |
54 | 0 | case VVDEC_BUFFERING_PERIOD: return "Buffering period"; |
55 | 0 | case VVDEC_PICTURE_TIMING: return "Picture timing"; |
56 | 0 | case VVDEC_FILLER_PAYLOAD: return "Filler payload"; // not currently decoded |
57 | 0 | case VVDEC_USER_DATA_REGISTERED_ITU_T_T35: return "User data registered"; // not currently decoded |
58 | 0 | case VVDEC_USER_DATA_UNREGISTERED: return "User data unregistered"; |
59 | 0 | case VVDEC_FILM_GRAIN_CHARACTERISTICS: return "Film grain characteristics"; // not currently decoded |
60 | 0 | case VVDEC_FRAME_PACKING: return "Frame packing arrangement"; |
61 | 0 | case VVDEC_PARAMETER_SETS_INCLUSION_INDICATION: return "Parameter sets inclusion indication"; |
62 | 0 | case VVDEC_DECODING_UNIT_INFO: return "Decoding unit information"; |
63 | 0 | case VVDEC_SCALABLE_NESTING: return "Scalable nesting"; |
64 | 0 | case VVDEC_DECODED_PICTURE_HASH: return "Decoded picture hash"; |
65 | 0 | case VVDEC_DEPENDENT_RAP_INDICATION: return "Dependent RAP indication"; |
66 | 0 | case VVDEC_MASTERING_DISPLAY_COLOUR_VOLUME: return "Mastering display colour volume"; |
67 | 0 | case VVDEC_ALTERNATIVE_TRANSFER_CHARACTERISTICS: return "Alternative transfer characteristics"; |
68 | 0 | case VVDEC_CONTENT_LIGHT_LEVEL_INFO: return "Content light level information"; |
69 | 0 | case VVDEC_AMBIENT_VIEWING_ENVIRONMENT: return "Ambient viewing environment"; |
70 | 0 | case VVDEC_CONTENT_COLOUR_VOLUME: return "Content colour volume"; |
71 | 0 | case VVDEC_EQUIRECTANGULAR_PROJECTION: return "Equirectangular projection"; |
72 | 0 | case VVDEC_SPHERE_ROTATION: return "Sphere rotation"; |
73 | 0 | case VVDEC_REGION_WISE_PACKING: return "Region wise packing information"; |
74 | 0 | case VVDEC_OMNI_VIEWPORT: return "Omni viewport"; |
75 | 0 | case VVDEC_GENERALIZED_CUBEMAP_PROJECTION: return "Generalized cubemap projection"; |
76 | 0 | case VVDEC_FRAME_FIELD_INFO: return "Frame field info"; |
77 | 0 | case VVDEC_SAMPLE_ASPECT_RATIO_INFO: return "Sample aspect ratio information"; |
78 | 0 | case VVDEC_SUBPICTURE_LEVEL_INFO: return "Subpicture level information"; |
79 | 0 | default: return "Unknown"; |
80 | 0 | } |
81 | 0 | } |
82 | | |
83 | | seiMessages SEI_internal::getSeisByType(const seiMessages &seiList, vvdecSEIPayloadType seiType) |
84 | 0 | { |
85 | 0 | seiMessages result; |
86 | |
|
87 | 0 | for( auto& s : seiList ) |
88 | 0 | { |
89 | 0 | if ( s->payloadType == seiType) |
90 | 0 | { |
91 | 0 | result.push_back(s); |
92 | 0 | } |
93 | 0 | } |
94 | 0 | return result; |
95 | 0 | } |
96 | | |
97 | | seiMessages SEI_internal::extractSeisByType(seiMessages &seiList, vvdecSEIPayloadType seiType) |
98 | 0 | { |
99 | 0 | seiMessages result; |
100 | 0 | seiMessages::iterator it=seiList.begin(); |
101 | 0 | while ( it!=seiList.end() ) |
102 | 0 | { |
103 | 0 | if ((*it)->payloadType == seiType) |
104 | 0 | { |
105 | 0 | result.push_back(*it); |
106 | 0 | it = seiList.erase(it); |
107 | 0 | } |
108 | 0 | else |
109 | 0 | { |
110 | 0 | it++; |
111 | 0 | } |
112 | 0 | } |
113 | 0 | return result; |
114 | 0 | } |
115 | | |
116 | | void SEI_internal::deleteSEIs ( seiMessages &seiList) |
117 | 0 | { |
118 | 0 | for( auto &sei : seiList ) |
119 | 0 | { |
120 | 0 | if( sei ) |
121 | 0 | { |
122 | 0 | if( sei->payloadType == VVDEC_SCALABLE_NESTING ) |
123 | 0 | { |
124 | 0 | const vvdecSEIScalableNesting* nestingSei = ( vvdecSEIScalableNesting* ) sei->payload; |
125 | |
|
126 | 0 | if( !nestingSei->snSubpicFlag ) |
127 | 0 | { |
128 | 0 | continue; |
129 | 0 | } |
130 | | |
131 | 0 | for( int i = 0; i < nestingSei->snNumSEIs; ++i ) |
132 | 0 | { |
133 | 0 | auto& nestedSei = nestingSei->nestedSEIs[i]; |
134 | |
|
135 | 0 | if( nestedSei->payload ) |
136 | 0 | free( nestedSei->payload ); |
137 | 0 | delete nestedSei; |
138 | 0 | } |
139 | 0 | } |
140 | | |
141 | 0 | if( sei->payload ) |
142 | 0 | free( sei->payload ); |
143 | 0 | delete sei ; |
144 | 0 | } |
145 | 0 | } |
146 | 0 | seiList.clear(); |
147 | 0 | } |
148 | | |
149 | | vvdecSEI* SEI_internal::allocSEI( vvdecSEIPayloadType payloadType ) |
150 | 0 | { |
151 | 0 | vvdecSEI* sei = new vvdecSEI; |
152 | |
|
153 | 0 | if( sei ) |
154 | 0 | { |
155 | 0 | sei->payload = NULL; |
156 | 0 | sei->payloadType = (vvdecSEIPayloadType)payloadType; |
157 | 0 | sei->size = 0; |
158 | 0 | } |
159 | 0 | else |
160 | 0 | { |
161 | 0 | CHECK_FATAL( !sei, "sei memory allocation error" ); |
162 | 0 | return nullptr; |
163 | 0 | } |
164 | | |
165 | 0 | if( 0 != allocSEIPayload( sei )) |
166 | 0 | { |
167 | 0 | CHECK_FATAL( !sei, "sei payload allocation error" ); |
168 | 0 | delete sei ; |
169 | 0 | return nullptr; |
170 | 0 | } |
171 | | |
172 | 0 | return sei; |
173 | 0 | } |
174 | | |
175 | | |
176 | | int SEI_internal::allocSEIPayload( vvdecSEI* sei, int userDefSize ) |
177 | 0 | { |
178 | 0 | if( NULL == sei ){ return -1; } |
179 | 0 | int size = userDefSize>0 ? userDefSize : getPayloadSize( sei->payloadType ); |
180 | 0 | if( size <= 0 ){ return -1;} |
181 | | |
182 | 0 | sei->payload = malloc( size ); |
183 | 0 | if( sei->payload ) |
184 | 0 | { |
185 | 0 | sei->size = size; |
186 | 0 | memset( sei->payload, 0, size ); |
187 | 0 | } |
188 | |
|
189 | 0 | return 0; |
190 | 0 | } |
191 | | |
192 | | int SEI_internal::getPayloadSize(vvdecSEIPayloadType payloadType) |
193 | 0 | { |
194 | 0 | switch (payloadType) |
195 | 0 | { |
196 | 0 | case VVDEC_BUFFERING_PERIOD: return sizeof( vvdecSEIBufferingPeriod ); |
197 | 0 | case VVDEC_PICTURE_TIMING: return sizeof( vvdecSEIPictureTiming ); |
198 | 0 | case VVDEC_FILLER_PAYLOAD: return 0; |
199 | 0 | case VVDEC_USER_DATA_REGISTERED_ITU_T_T35: return sizeof( vvdecSEIUserDataRegistered ); // not currently decoded |
200 | 0 | case VVDEC_USER_DATA_UNREGISTERED: return sizeof( vvdecSEIUserDataUnregistered ); |
201 | 0 | case VVDEC_FILM_GRAIN_CHARACTERISTICS: return sizeof( vvdecSEIFilmGrainCharacteristics ); |
202 | 0 | case VVDEC_FRAME_PACKING: return sizeof( vvdecSEIFramePacking ); |
203 | 0 | case VVDEC_PARAMETER_SETS_INCLUSION_INDICATION: return sizeof( vvdecSEIParameterSetsInclusionIndication ); |
204 | 0 | case VVDEC_DECODING_UNIT_INFO: return sizeof( vvdecSEIDecodingUnitInfo ); |
205 | 0 | case VVDEC_SCALABLE_NESTING: return sizeof( vvdecSEIScalableNesting ); |
206 | 0 | case VVDEC_DECODED_PICTURE_HASH: return sizeof( vvdecSEIDecodedPictureHash ); |
207 | 0 | case VVDEC_DEPENDENT_RAP_INDICATION: return sizeof( vvdecSEIDependentRapIndication ); |
208 | 0 | case VVDEC_MASTERING_DISPLAY_COLOUR_VOLUME: return sizeof( vvdecSEIMasteringDisplayColourVolume ); |
209 | 0 | case VVDEC_ALTERNATIVE_TRANSFER_CHARACTERISTICS: return sizeof( vvdecSEIAlternativeTransferCharacteristics ); |
210 | 0 | case VVDEC_CONTENT_LIGHT_LEVEL_INFO: return sizeof( vvdecSEIContentLightLevelInfo ); |
211 | 0 | case VVDEC_AMBIENT_VIEWING_ENVIRONMENT: return sizeof( vvdecSEIAmbientViewingEnvironment ); |
212 | 0 | case VVDEC_CONTENT_COLOUR_VOLUME: return sizeof( vvdecSEIContentColourVolume ); |
213 | 0 | case VVDEC_EQUIRECTANGULAR_PROJECTION: return sizeof( vvdecSEIEquirectangularProjection ); |
214 | 0 | case VVDEC_SPHERE_ROTATION: return sizeof( vvdecSEISphereRotation ); |
215 | 0 | case VVDEC_REGION_WISE_PACKING: return sizeof( vvdecSEIRegionWisePacking ); |
216 | 0 | case VVDEC_OMNI_VIEWPORT: return sizeof( vvdecSEIOmniViewport ); |
217 | 0 | case VVDEC_GENERALIZED_CUBEMAP_PROJECTION: return sizeof( vvdecSEIGeneralizedCubemapProjection ); |
218 | 0 | case VVDEC_FRAME_FIELD_INFO: return sizeof( vvdecSEIFrameFieldInfo ); |
219 | 0 | case VVDEC_SAMPLE_ASPECT_RATIO_INFO: return sizeof( vvdecSEISampleAspectRatioInfo ); |
220 | 0 | case VVDEC_SUBPICTURE_LEVEL_INFO: return sizeof( vvdecSEISubpictureLevelInfo ); |
221 | 0 | default: return -1; |
222 | 0 | } |
223 | | |
224 | 0 | return -1; |
225 | 0 | } |
226 | | |
227 | | } |