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