| 1 | /******************************************************************** |
| 2 | * * |
| 3 | * THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. * |
| 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
| 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
| 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
| 7 | * * |
| 8 | * THE libopusfile SOURCE CODE IS (C) COPYRIGHT 2012-2020 * |
| 9 | * by the Xiph.Org Foundation and contributors https://xiph.org/ * |
| 10 | * * |
| 11 | ********************************************************************/ |
| 12 | //#ifdef HAVE_CONFIG_H |
| 13 | #include "opus__config.h"cxx . . $ `<file>/external/opusfile/opus/opus__config.h`/ |
| 14 | //#endif |
| 15 | |
| 16 | #include "opusfile_internal.h"cxx . . $ `<file>/external/opusfile/opusfile_internal.h`/ |
| 17 | #include <limits.h> |
| 18 | #include <string.h> |
| 19 | |
| 20 | static unsigned op_parse_uint16lecxx . . $ op_parse_uint16le(ca1608e2c87725e2).(const unsigned char *_data){ |
| 21 | return _data[0]|_data[1]<<8; |
| 22 | } |
| 23 | |
| 24 | static int op_parse_int16lecxx . . $ op_parse_int16le(b84ccf4e0bb14b06).(const unsigned char *_data){ |
| 25 | int ret; |
| 26 | ret=_data[0]|_data[1]<<8; |
| 27 | return (ret^0x8000)-0x8000; |
| 28 | } |
| 29 | |
| 30 | static opus_uint32cxx . . $ opus_uint32# op_parse_uint32lecxx . . $ op_parse_uint32le(ca1608e2c87725e2).(const unsigned char *_data){ |
| 31 | return _data[0]|(opus_uint32cxx . . $ opus_uint32#)_data[1]<<8| |
| 32 | (opus_uint32cxx . . $ opus_uint32#)_data[2]<<16|(opus_uint32cxx . . $ opus_uint32#)_data[3]<<24; |
| 33 | } |
| 34 | |
| 35 | static opus_uint32cxx . . $ opus_uint32# op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(const unsigned char *_data){ |
| 36 | return _data[3]|(opus_uint32cxx . . $ opus_uint32#)_data[2]<<8| |
| 37 | (opus_uint32cxx . . $ opus_uint32#)_data[1]<<16|(opus_uint32cxx . . $ opus_uint32#)_data[0]<<24; |
| 38 | } |
| 39 | |
| 40 | int opus_head_parsecxx . . $ opus_head_parse(ab9670a7fbf2322e).(OpusHeadcxx . . $ OpusHead# *_head,const unsigned char *_data,size_t _len){ |
| 41 | OpusHeadcxx . . $ OpusHead# head; |
| 42 | if(_len<8)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 43 | if(memcmp(_data,"OpusHead",8)!=0)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 44 | if(_len<9)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 45 | head.versioncxx . . $ OpusHead#version.=_data[8]; |
| 46 | if(head.versioncxx . . $ OpusHead#version.>15)return OP_EVERSIONcxx . . $ `external/opusfile/opusfile.h:188:9`!; |
| 47 | if(_len<19)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 48 | head.channel_countcxx . . $ OpusHead#channel_count.=_data[9]; |
| 49 | head.pre_skipcxx . . $ OpusHead#pre_skip.=op_parse_uint16lecxx . . $ op_parse_uint16le(ca1608e2c87725e2).(_data+10); |
| 50 | head.input_sample_ratecxx . . $ OpusHead#input_sample_rate.=op_parse_uint32lecxx . . $ op_parse_uint32le(ca1608e2c87725e2).(_data+12); |
| 51 | head.output_gaincxx . . $ OpusHead#output_gain.=op_parse_int16lecxx . . $ op_parse_int16le(b84ccf4e0bb14b06).(_data+16); |
| 52 | head.mapping_familycxx . . $ OpusHead#mapping_family.=_data[18]; |
| 53 | if(head.mapping_familycxx . . $ OpusHead#mapping_family.==0){ |
| 54 | if(head.channel_countcxx . . $ OpusHead#channel_count.<1||head.channel_countcxx . . $ OpusHead#channel_count.>2)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 55 | if(head.versioncxx . . $ OpusHead#version.<=1&&_len>19)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 56 | head.stream_countcxx . . $ OpusHead#stream_count.=1; |
| 57 | head.coupled_countcxx . . $ OpusHead#coupled_count.=head.channel_countcxx . . $ OpusHead#channel_count.-1; |
| 58 | if(_head!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 59 | _head->mappingcxx . . $ OpusHead#mapping.[0]=0; |
| 60 | _head->mappingcxx . . $ OpusHead#mapping.[1]=1; |
| 61 | } |
| 62 | } |
| 63 | else if(head.mapping_familycxx . . $ OpusHead#mapping_family.==1){ |
| 64 | size_t size; |
| 65 | int ci; |
| 66 | if(head.channel_countcxx . . $ OpusHead#channel_count.<1||head.channel_countcxx . . $ OpusHead#channel_count.>8)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 67 | size=21+head.channel_countcxx . . $ OpusHead#channel_count.; |
| 68 | if(_len<size||head.versioncxx . . $ OpusHead#version.<=1&&_len>size)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 69 | head.stream_countcxx . . $ OpusHead#stream_count.=_data[19]; |
| 70 | if(head.stream_countcxx . . $ OpusHead#stream_count.<1)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 71 | head.coupled_countcxx . . $ OpusHead#coupled_count.=_data[20]; |
| 72 | if(head.coupled_countcxx . . $ OpusHead#coupled_count.>head.stream_countcxx . . $ OpusHead#stream_count.)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 73 | for(ci=0;ci<head.channel_countcxx . . $ OpusHead#channel_count.;ci++){ |
| 74 | if(_data[21+ci]>=head.stream_countcxx . . $ OpusHead#stream_count.+head.coupled_countcxx . . $ OpusHead#coupled_count. |
| 75 | &&_data[21+ci]!=255){ |
| 76 | return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 77 | } |
| 78 | } |
| 79 | if(_head!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)memcpy(_head->mappingcxx . . $ OpusHead#mapping.,_data+21,head.channel_countcxx . . $ OpusHead#channel_count.); |
| 80 | } |
| 81 | /*General purpose players should not attempt to play back content with |
| 82 | channel mapping family 255.*/ |
| 83 | else if(head.mapping_familycxx . . $ OpusHead#mapping_family.==255)return OP_EIMPLcxx . . $ `external/opusfile/opusfile.h:176:9`!; |
| 84 | /*No other channel mapping families are currently defined.*/ |
| 85 | else return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 86 | if(_head!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)memcpy(_head,&head,head.mappingcxx . . $ OpusHead#mapping.-(unsigned char *)&head); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | void opus_tags_initcxx . . $ opus_tags_init(ef9d647e5ade63ca).(OpusTagscxx . . $ OpusTags# *_tags){ |
| 91 | memset(_tags,0,sizeof(*_tags)); |
| 92 | } |
| 93 | |
| 94 | void opus_tags_clearcxx . . $ opus_tags_clear(ef9d647e5ade63ca).(OpusTagscxx . . $ OpusTags# *_tags){ |
| 95 | int ncomments; |
| 96 | int ci; |
| 97 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 98 | if(_tags->user_commentscxx . . $ OpusTags#user_comments.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)ncomments++; |
| 99 | else{ |
| 100 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(ncomments==0); |
| 101 | } |
| 102 | for(ci=ncomments;ci-->0;)Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_tags->user_comments[ci]); |
| 103 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_tags->user_comments); |
| 104 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_tags->comment_lengths); |
| 105 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_tags->vendor); |
| 106 | } |
| 107 | |
| 108 | /*Ensure there's room for up to _ncomments comments.*/ |
| 109 | static int op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(OpusTagscxx . . $ OpusTags# *_tags,size_t _ncomments){ |
| 110 | char **user_comments; |
| 111 | int *comment_lengths; |
| 112 | int cur_ncomments; |
| 113 | size_t size; |
| 114 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(_ncomments>=(size_t)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 115 | size=sizeof(*_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.)*(_ncomments+1); |
| 116 | if(size/sizeof(*_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.)!=_ncomments+1)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 117 | cur_ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 118 | /*We only support growing. |
| 119 | Trimming requires cleaning up the allocated strings in the old space, and |
| 120 | is best handled separately if it's ever needed.*/ |
| 121 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(_ncomments>=(size_t)cur_ncomments); |
| 122 | comment_lengths=(int *)Melder_realloccxx . . $ Melder_realloc(d42fd80046fa8ace).(_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.,size); |
| 123 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(comment_lengths==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 124 | if(_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 125 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(cur_ncomments==0); |
| 126 | comment_lengths[cur_ncomments]=0; |
| 127 | } |
| 128 | comment_lengths[_ncomments]=comment_lengths[cur_ncomments]; |
| 129 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.=comment_lengths; |
| 130 | size=sizeof(*_tags->user_commentscxx . . $ OpusTags#user_comments.)*(_ncomments+1); |
| 131 | if(size/sizeof(*_tags->user_commentscxx . . $ OpusTags#user_comments.)!=_ncomments+1)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 132 | user_comments=(char **)Melder_realloccxx . . $ Melder_realloc(d42fd80046fa8ace).(_tags->user_commentscxx . . $ OpusTags#user_comments.,size); |
| 133 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(user_comments==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 134 | if(_tags->user_commentscxx . . $ OpusTags#user_comments.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 135 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(cur_ncomments==0); |
| 136 | user_comments[cur_ncomments]=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 137 | } |
| 138 | user_comments[_ncomments]=user_comments[cur_ncomments]; |
| 139 | _tags->user_commentscxx . . $ OpusTags#user_comments.=user_comments; |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /*Duplicate a (possibly non-NUL terminated) string with a known length.*/ |
| 144 | static char *op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).(const char *_s,size_t _len){ |
| 145 | size_t size; |
| 146 | char *ret; |
| 147 | size=sizeof(*ret)*(_len+1); |
| 148 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(size<_len))return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 149 | ret=(char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(size); |
| 150 | if(OP_LIKELYcxx . . $ `external/opusfile/opusfile_internal.h:67:11`!(ret!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)){ |
| 151 | ret=(char *)memcpy(ret,_s,sizeof(*ret)*_len); |
| 152 | ret[_len]='\0'; |
| 153 | } |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | /*The actual implementation of opus_tags_parse(). |
| 158 | Unlike the public API, this function requires _tags to already be |
| 159 | initialized, modifies its contents before success is guaranteed, and assumes |
| 160 | the caller will clear it on error.*/ |
| 161 | static int opus_tags_parse_implcxx . . $ opus_tags_parse_impl(d263ff345f2cc50e).(OpusTagscxx . . $ OpusTags# *_tags, |
| 162 | const unsigned char *_data,size_t _len){ |
| 163 | opus_uint32cxx . . $ opus_uint32# count; |
| 164 | size_t len; |
| 165 | int ncomments; |
| 166 | int ci; |
| 167 | len=_len; |
| 168 | if(len<8)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 169 | if(memcmp(_data,"OpusTags",8)!=0)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 170 | if(len<16)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 171 | _data+=8; |
| 172 | len-=8; |
| 173 | count=op_parse_uint32lecxx . . $ op_parse_uint32le(ca1608e2c87725e2).(_data); |
| 174 | _data+=4; |
| 175 | len-=4; |
| 176 | if(count>len)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 177 | if(_tags!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 178 | _tags->vendorcxx . . $ OpusTags#vendor.=op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).((char *)_data,count); |
| 179 | if(_tags->vendorcxx . . $ OpusTags#vendor.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 180 | } |
| 181 | _data+=count; |
| 182 | len-=count; |
| 183 | if(len<4)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 184 | count=op_parse_uint32lecxx . . $ op_parse_uint32le(ca1608e2c87725e2).(_data); |
| 185 | _data+=4; |
| 186 | len-=4; |
| 187 | /*Check to make sure there's minimally sufficient data left in the packet.*/ |
| 188 | if(count>len>>2)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 189 | /*Check for overflow (the API limits this to an int).*/ |
| 190 | if(count>(opus_uint32cxx . . $ opus_uint32#)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!-1)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 191 | if(_tags!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 192 | int ret; |
| 193 | ret=op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(_tags,count); |
| 194 | if(ret<0)return ret; |
| 195 | } |
| 196 | ncomments=(int)count; |
| 197 | for(ci=0;ci<ncomments;ci++){ |
| 198 | /*Check to make sure there's minimally sufficient data left in the packet.*/ |
| 199 | if((size_t)(ncomments-ci)>len>>2)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 200 | count=op_parse_uint32lecxx . . $ op_parse_uint32le(ca1608e2c87725e2).(_data); |
| 201 | _data+=4; |
| 202 | len-=4; |
| 203 | if(count>len)return OP_EBADHEADERcxx . . $ `external/opusfile/opusfile.h:186:9`!; |
| 204 | /*Check for overflow (the API limits this to an int).*/ |
| 205 | if(count>(opus_uint32cxx . . $ opus_uint32#)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 206 | if(_tags!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 207 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ci]=op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).((char *)_data,count); |
| 208 | if(_tags->user_commentscxx . . $ OpusTags#user_comments.[ci]==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 209 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ci]=(int)count; |
| 210 | _tags->commentscxx . . $ OpusTags#comments.=ci+1; |
| 211 | /*Needed by opus_tags_clear() if we fail before parsing the (optional) |
| 212 | binary metadata.*/ |
| 213 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ci+1]=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 214 | } |
| 215 | _data+=count; |
| 216 | len-=count; |
| 217 | } |
| 218 | if(len>0&&(_data[0]&1)){ |
| 219 | if(len>(opus_uint32cxx . . $ opus_uint32#)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 220 | if(_tags!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 221 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments]=(char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(len); |
| 222 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(_tags->user_comments[ncomments]==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 223 | memcpy(_tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments],_data,len); |
| 224 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]=(int)len; |
| 225 | } |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | int opus_tags_parsecxx . . $ opus_tags_parse(d263ff345f2cc50e).(OpusTagscxx . . $ OpusTags# *_tags,const unsigned char *_data,size_t _len){ |
| 231 | if(_tags!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 232 | OpusTagscxx . . $ OpusTags# tags; |
| 233 | int ret; |
| 234 | opus_tags_initcxx . . $ opus_tags_init(ef9d647e5ade63ca).(&tags); |
| 235 | ret=opus_tags_parse_implcxx . . $ opus_tags_parse_impl(d263ff345f2cc50e).(&tags,_data,_len); |
| 236 | if(ret<0)opus_tags_clearcxx . . $ opus_tags_clear(ef9d647e5ade63ca).(&tags); |
| 237 | else *_tags=cxx . . $ OpusTags#`operator=`(dc971e84081b4107).*&tags; |
| 238 | return ret; |
| 239 | } |
| 240 | else return opus_tags_parse_implcxx . . $ opus_tags_parse_impl(d263ff345f2cc50e).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,_data,_len); |
| 241 | } |
| 242 | |
| 243 | /*The actual implementation of opus_tags_copy(). |
| 244 | Unlike the public API, this function requires _dst to already be |
| 245 | initialized, modifies its contents before success is guaranteed, and assumes |
| 246 | the caller will clear it on error.*/ |
| 247 | static int opus_tags_copy_implcxx . . $ opus_tags_copy_impl(c80de6561c42ec3f).(OpusTagscxx . . $ OpusTags# *_dst,const OpusTagscxx . . $ OpusTags# *_src){ |
| 248 | char *vendor; |
| 249 | int ncomments; |
| 250 | int ret; |
| 251 | int ci; |
| 252 | vendor=_src->vendorcxx . . $ OpusTags#vendor.; |
| 253 | _dst->vendorcxx . . $ OpusTags#vendor.=op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).(vendor,strlen(vendor)); |
| 254 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(_dst->vendor==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 255 | ncomments=_src->commentscxx . . $ OpusTags#comments.; |
| 256 | ret=op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(_dst,ncomments); |
| 257 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(ret<0))return ret; |
| 258 | for(ci=0;ci<ncomments;ci++){ |
| 259 | int len; |
| 260 | len=_src->comment_lengthscxx . . $ OpusTags#comment_lengths.[ci]; |
| 261 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(len>=0); |
| 262 | _dst->user_commentscxx . . $ OpusTags#user_comments.[ci]=op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).(_src->user_commentscxx . . $ OpusTags#user_comments.[ci],len); |
| 263 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(_dst->user_comments[ci]==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 264 | _dst->comment_lengthscxx . . $ OpusTags#comment_lengths.[ci]=len; |
| 265 | _dst->commentscxx . . $ OpusTags#comments.=ci+1; |
| 266 | } |
| 267 | if(_src->comment_lengthscxx . . $ OpusTags#comment_lengths.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!){ |
| 268 | int len; |
| 269 | len=_src->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]; |
| 270 | if(len>0){ |
| 271 | _dst->user_commentscxx . . $ OpusTags#user_comments.[ncomments]=(char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(len); |
| 272 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(_dst->user_comments[ncomments]==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 273 | memcpy(_dst->user_commentscxx . . $ OpusTags#user_comments.[ncomments],_src->user_commentscxx . . $ OpusTags#user_comments.[ncomments],len); |
| 274 | _dst->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]=len; |
| 275 | } |
| 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | int opus_tags_copycxx . . $ opus_tags_copy(c80de6561c42ec3f).(OpusTagscxx . . $ OpusTags# *_dst,const OpusTagscxx . . $ OpusTags# *_src){ |
| 281 | OpusTagscxx . . $ OpusTags# dst; |
| 282 | int ret; |
| 283 | opus_tags_initcxx . . $ opus_tags_init(ef9d647e5ade63ca).(&dst); |
| 284 | ret=opus_tags_copy_implcxx . . $ opus_tags_copy_impl(c80de6561c42ec3f).(&dst,_src); |
| 285 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(ret<0))opus_tags_clearcxx . . $ opus_tags_clear(ef9d647e5ade63ca).(&dst); |
| 286 | else *_dst=cxx . . $ OpusTags#`operator=`(dc971e84081b4107).*&dst; |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | int opus_tags_addcxx . . $ opus_tags_add(e075705ac333c44d).(OpusTagscxx . . $ OpusTags# *_tags,const char *_tag,const char *_value){ |
| 291 | char *comment; |
| 292 | size_t tag_len; |
| 293 | size_t value_len; |
| 294 | int ncomments; |
| 295 | int ret; |
| 296 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 297 | ret=op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(_tags,ncomments+1); |
| 298 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(ret<0))return ret; |
| 299 | tag_len=strlen(_tag); |
| 300 | value_len=strlen(_value); |
| 301 | /*+2 for '=' and '\0'.*/ |
| 302 | if(tag_len+value_len<tag_len)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 303 | if(tag_len+value_len>(size_t)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!-2)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 304 | comment=(char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*comment)*(tag_len+value_len+2)); |
| 305 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(comment==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 306 | memcpy(comment,_tag,sizeof(*comment)*tag_len); |
| 307 | comment[tag_len]='='; |
| 308 | memcpy(comment+tag_len+1,_value,sizeof(*comment)*(value_len+1)); |
| 309 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments]=comment; |
| 310 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]=(int)(tag_len+value_len+1); |
| 311 | _tags->commentscxx . . $ OpusTags#comments.=ncomments+1; |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | int opus_tags_add_commentcxx . . $ opus_tags_add_comment(4aadadb9f74bb079).(OpusTagscxx . . $ OpusTags# *_tags,const char *_comment){ |
| 316 | char *comment; |
| 317 | int comment_len; |
| 318 | int ncomments; |
| 319 | int ret; |
| 320 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 321 | ret=op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(_tags,ncomments+1); |
| 322 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(ret<0))return ret; |
| 323 | comment_len=(int)strlen(_comment); |
| 324 | comment=op_strdup_with_lencxx . . $ op_strdup_with_len(eabdfdef77619b3d).(_comment,comment_len); |
| 325 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(comment==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 326 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments]=comment; |
| 327 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]=comment_len; |
| 328 | _tags->commentscxx . . $ OpusTags#comments.=ncomments+1; |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | int opus_tags_set_binary_suffixcxx . . $ opus_tags_set_binary_suffix(a12c34be9d6a6c6c).(OpusTagscxx . . $ OpusTags# *_tags, |
| 333 | const unsigned char *_data,int _len){ |
| 334 | unsigned char *binary_suffix_data; |
| 335 | int ncomments; |
| 336 | int ret; |
| 337 | if(_len<0||_len>0&&(_data==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!||!(_data[0]&1)))return OP_EINVALcxx . . $ `external/opusfile/opusfile.h:178:9`!; |
| 338 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 339 | ret=op_tags_ensure_capacitycxx . . $ op_tags_ensure_capacity(57aabce69496360e).(_tags,ncomments); |
| 340 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(ret<0))return ret; |
| 341 | binary_suffix_data= |
| 342 | (unsigned char *)Melder_realloccxx . . $ Melder_realloc(d42fd80046fa8ace).(_tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments],_len); |
| 343 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(binary_suffix_data==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!))return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 344 | memcpy(binary_suffix_data,_data,_len); |
| 345 | _tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments]=(char *)binary_suffix_data; |
| 346 | _tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]=_len; |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | int opus_tagcomparecxx . . $ opus_tagcompare(5ae29d726ae57f88).(const char *_tag_name,const char *_comment){ |
| 351 | size_t tag_len; |
| 352 | tag_len=strlen(_tag_name); |
| 353 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(tag_len>(size_t)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!))return -1; |
| 354 | return opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).(_tag_name,(int)tag_len,_comment); |
| 355 | } |
| 356 | |
| 357 | int opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).(const char *_tag_name,int _tag_len,const char *_comment){ |
| 358 | int ret; |
| 359 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(_tag_len>=0); |
| 360 | ret=op_strncasecmpcxx . . $ op_strncasecmp(f0be30763a490cce).(_tag_name,_comment,_tag_len); |
| 361 | return ret?ret:'='-_comment[_tag_len]; |
| 362 | } |
| 363 | |
| 364 | const char *opus_tags_querycxx . . $ opus_tags_query(2ec59d1c09bf381f).(const OpusTagscxx . . $ OpusTags# *_tags,const char *_tag,int _count){ |
| 365 | char **user_comments; |
| 366 | size_t tag_len; |
| 367 | int found; |
| 368 | int ncomments; |
| 369 | int ci; |
| 370 | tag_len=strlen(_tag); |
| 371 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(tag_len>(size_t)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!))return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 372 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 373 | user_comments=_tags->user_commentscxx . . $ OpusTags#user_comments.; |
| 374 | found=0; |
| 375 | for(ci=0;ci<ncomments;ci++){ |
| 376 | if(!opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).(_tag,(int)tag_len,user_comments[ci])){ |
| 377 | /*We return a pointer to the data, not a copy.*/ |
| 378 | if(_count==found++)return user_comments[ci]+tag_len+1; |
| 379 | } |
| 380 | } |
| 381 | /*Didn't find anything.*/ |
| 382 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 383 | } |
| 384 | |
| 385 | int opus_tags_query_countcxx . . $ opus_tags_query_count(e4c80bfdc7e63db8).(const OpusTagscxx . . $ OpusTags# *_tags,const char *_tag){ |
| 386 | char **user_comments; |
| 387 | size_t tag_len; |
| 388 | int found; |
| 389 | int ncomments; |
| 390 | int ci; |
| 391 | tag_len=strlen(_tag); |
| 392 | if(OP_UNLIKELYcxx . . $ `external/opusfile/opusfile_internal.h:68:11`!(tag_len>(size_t)INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!))return 0; |
| 393 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 394 | user_comments=_tags->user_commentscxx . . $ OpusTags#user_comments.; |
| 395 | found=0; |
| 396 | for(ci=0;ci<ncomments;ci++){ |
| 397 | if(!opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).(_tag,(int)tag_len,user_comments[ci]))found++; |
| 398 | } |
| 399 | return found; |
| 400 | } |
| 401 | |
| 402 | const unsigned char *opus_tags_get_binary_suffixcxx . . $ opus_tags_get_binary_suffix(83ca6531d2e9a9cb).(const OpusTagscxx . . $ OpusTags# *_tags, |
| 403 | int *_len){ |
| 404 | int ncomments; |
| 405 | int len; |
| 406 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 407 | len=_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!?0:_tags->comment_lengthscxx . . $ OpusTags#comment_lengths.[ncomments]; |
| 408 | *_len=len; |
| 409 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(len==0||_tags->user_comments!=NULL); |
| 410 | return len>0?(const unsigned char *)_tags->user_commentscxx . . $ OpusTags#user_comments.[ncomments]:NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 411 | } |
| 412 | |
| 413 | static int opus_tags_get_gaincxx . . $ opus_tags_get_gain(26db7f0e661a6439).(const OpusTagscxx . . $ OpusTags# *_tags,int *_gain_q8, |
| 414 | const char *_tag_name,size_t _tag_len){ |
| 415 | char **comments; |
| 416 | int ncomments; |
| 417 | int ci; |
| 418 | comments=_tags->user_commentscxx . . $ OpusTags#user_comments.; |
| 419 | ncomments=_tags->commentscxx . . $ OpusTags#comments.; |
| 420 | /*Look for the first valid tag with the name _tag_name and use that.*/ |
| 421 | for(ci=0;ci<ncomments;ci++){ |
| 422 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(_tag_len<=(size_t)INT_MAX); |
| 423 | if(opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).(_tag_name,(int)_tag_len,comments[ci])==0){ |
| 424 | char *p; |
| 425 | opus_int32cxx . . $ opus_int32# gain_q8; |
| 426 | int negative; |
| 427 | p=comments[ci]+_tag_len+1; |
| 428 | negative=0; |
| 429 | if(*p=='-'){ |
| 430 | negative=-1; |
| 431 | p++; |
| 432 | } |
| 433 | else if(*p=='+')p++; |
| 434 | gain_q8=0; |
| 435 | while(*p>='0'&&*p<='9'){ |
| 436 | gain_q8=10*gain_q8+*p-'0'; |
| 437 | if(gain_q8>32767-negative)break; |
| 438 | p++; |
| 439 | } |
| 440 | /*This didn't look like a signed 16-bit decimal integer. |
| 441 | Not a valid gain tag.*/ |
| 442 | if(*p!='\0')continue; |
| 443 | *_gain_q8=(int)(gain_q8+negative^negative); |
| 444 | return 0; |
| 445 | } |
| 446 | } |
| 447 | return OP_FALSEcxx . . $ `external/opusfile/opusfile.h:161:9`!; |
| 448 | } |
| 449 | |
| 450 | int opus_tags_get_album_gaincxx . . $ opus_tags_get_album_gain(772c5e6ffff50f56).(const OpusTagscxx . . $ OpusTags# *_tags,int *_gain_q8){ |
| 451 | return opus_tags_get_gaincxx . . $ opus_tags_get_gain(26db7f0e661a6439).(_tags,_gain_q8,"R128_ALBUM_GAIN",15); |
| 452 | } |
| 453 | |
| 454 | int opus_tags_get_track_gaincxx . . $ opus_tags_get_track_gain(772c5e6ffff50f56).(const OpusTagscxx . . $ OpusTags# *_tags,int *_gain_q8){ |
| 455 | return opus_tags_get_gaincxx . . $ opus_tags_get_gain(26db7f0e661a6439).(_tags,_gain_q8,"R128_TRACK_GAIN",15); |
| 456 | } |
| 457 | |
| 458 | static int op_is_jpegcxx . . $ op_is_jpeg(22502bda773498f8).(const unsigned char *_buf,size_t _buf_sz){ |
| 459 | return _buf_sz>=3&&memcmp(_buf,"\xFF\xD8\xFF",3)==0; |
| 460 | } |
| 461 | |
| 462 | /*Tries to extract the width, height, bits per pixel, and palette size of a |
| 463 | JPEG. |
| 464 | On failure, simply leaves its outputs unmodified.*/ |
| 465 | static void op_extract_jpeg_paramscxx . . $ op_extract_jpeg_params(24bcfede25d11c7d).(const unsigned char *_buf,size_t _buf_sz, |
| 466 | opus_uint32cxx . . $ opus_uint32# *_width,opus_uint32cxx . . $ opus_uint32# *_height, |
| 467 | opus_uint32cxx . . $ opus_uint32# *_depth,opus_uint32cxx . . $ opus_uint32# *_colors,int *_has_palette){ |
| 468 | if(op_is_jpegcxx . . $ op_is_jpeg(22502bda773498f8).(_buf,_buf_sz)){ |
| 469 | size_t offs; |
| 470 | offs=2; |
| 471 | for(;;){ |
| 472 | size_t segment_len; |
| 473 | int marker; |
| 474 | while(offs<_buf_sz&&_buf[offs]!=0xFF)offs++; |
| 475 | while(offs<_buf_sz&&_buf[offs]==0xFF)offs++; |
| 476 | marker=_buf[offs]; |
| 477 | offs++; |
| 478 | /*If we hit EOI* (end of image), or another SOI* (start of image), |
| 479 | or SOS (start of scan), then stop now.*/ |
| 480 | if(offs>=_buf_sz||(marker>=0xD8&&marker<=0xDA))break; |
| 481 | /*RST* (restart markers): skip (no segment length).*/ |
| 482 | else if(marker>=0xD0&&marker<=0xD7)continue; |
| 483 | /*Read the length of the marker segment.*/ |
| 484 | if(_buf_sz-offs<2)break; |
| 485 | segment_len=_buf[offs]<<8|_buf[offs+1]; |
| 486 | if(segment_len<2||_buf_sz-offs<segment_len)break; |
| 487 | if(marker==0xC0||(marker>0xC0&&marker<0xD0&&(marker&3)!=0)){ |
| 488 | /*Found a SOFn (start of frame) marker segment:*/ |
| 489 | if(segment_len>=8){ |
| 490 | *_height=_buf[offs+3]<<8|_buf[offs+4]; |
| 491 | *_width=_buf[offs+5]<<8|_buf[offs+6]; |
| 492 | *_depth=_buf[offs+2]*_buf[offs+7]; |
| 493 | *_colors=0; |
| 494 | *_has_palette=0; |
| 495 | } |
| 496 | break; |
| 497 | } |
| 498 | /*Other markers: skip the whole marker segment.*/ |
| 499 | offs+=segment_len; |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static int op_is_pngcxx . . $ op_is_png(22502bda773498f8).(const unsigned char *_buf,size_t _buf_sz){ |
| 505 | return _buf_sz>=8&&memcmp(_buf,"\x89PNG\x0D\x0A\x1A\x0A",8)==0; |
| 506 | } |
| 507 | |
| 508 | /*Tries to extract the width, height, bits per pixel, and palette size of a |
| 509 | PNG. |
| 510 | On failure, simply leaves its outputs unmodified.*/ |
| 511 | static void op_extract_png_paramscxx . . $ op_extract_png_params(24bcfede25d11c7d).(const unsigned char *_buf,size_t _buf_sz, |
| 512 | opus_uint32cxx . . $ opus_uint32# *_width,opus_uint32cxx . . $ opus_uint32# *_height, |
| 513 | opus_uint32cxx . . $ opus_uint32# *_depth,opus_uint32cxx . . $ opus_uint32# *_colors,int *_has_palette){ |
| 514 | if(op_is_pngcxx . . $ op_is_png(22502bda773498f8).(_buf,_buf_sz)){ |
| 515 | size_t offs; |
| 516 | offs=8; |
| 517 | while(_buf_sz-offs>=12){ |
| 518 | ogg_uint32_tcxx . . $ ogg_uint32_t# chunk_len; |
| 519 | chunk_len=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+offs); |
| 520 | if(chunk_len>_buf_sz-(offs+12))break; |
| 521 | else if(chunk_len==13&&memcmp(_buf+offs+4,"IHDR",4)==0){ |
| 522 | int color_type; |
| 523 | *_width=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+offs+8); |
| 524 | *_height=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+offs+12); |
| 525 | color_type=_buf[offs+17]; |
| 526 | if(color_type==3){ |
| 527 | *_depth=24; |
| 528 | *_has_palette=1; |
| 529 | } |
| 530 | else{ |
| 531 | int sample_depth; |
| 532 | sample_depth=_buf[offs+16]; |
| 533 | if(color_type==0)*_depth=sample_depth; |
| 534 | else if(color_type==2)*_depth=sample_depth*3; |
| 535 | else if(color_type==4)*_depth=sample_depth*2; |
| 536 | else if(color_type==6)*_depth=sample_depth*4; |
| 537 | *_colors=0; |
| 538 | *_has_palette=0; |
| 539 | break; |
| 540 | } |
| 541 | } |
| 542 | else if(*_has_palette>0&&memcmp(_buf+offs+4,"PLTE",4)==0){ |
| 543 | *_colors=chunk_len/3; |
| 544 | break; |
| 545 | } |
| 546 | offs+=12+chunk_len; |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | static int op_is_gifcxx . . $ op_is_gif(22502bda773498f8).(const unsigned char *_buf,size_t _buf_sz){ |
| 552 | return _buf_sz>=6&&(memcmp(_buf,"GIF87a",6)==0||memcmp(_buf,"GIF89a",6)==0); |
| 553 | } |
| 554 | |
| 555 | /*Tries to extract the width, height, bits per pixel, and palette size of a |
| 556 | GIF. |
| 557 | On failure, simply leaves its outputs unmodified.*/ |
| 558 | static void op_extract_gif_paramscxx . . $ op_extract_gif_params(24bcfede25d11c7d).(const unsigned char *_buf,size_t _buf_sz, |
| 559 | opus_uint32cxx . . $ opus_uint32# *_width,opus_uint32cxx . . $ opus_uint32# *_height, |
| 560 | opus_uint32cxx . . $ opus_uint32# *_depth,opus_uint32cxx . . $ opus_uint32# *_colors,int *_has_palette){ |
| 561 | if(op_is_gifcxx . . $ op_is_gif(22502bda773498f8).(_buf,_buf_sz)&&_buf_sz>=14){ |
| 562 | *_width=_buf[6]|_buf[7]<<8; |
| 563 | *_height=_buf[8]|_buf[9]<<8; |
| 564 | /*libFLAC hard-codes the depth to 24.*/ |
| 565 | *_depth=24; |
| 566 | *_colors=1<<((_buf[10]&7)+1); |
| 567 | *_has_palette=1; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | /*The actual implementation of opus_picture_tag_parse(). |
| 572 | Unlike the public API, this function requires _pic to already be |
| 573 | initialized, modifies its contents before success is guaranteed, and assumes |
| 574 | the caller will clear it on error.*/ |
| 575 | static int opus_picture_tag_parse_implcxx . . $ opus_picture_tag_parse_impl(e123a46d9957eea4).(OpusPictureTagcxx . . $ OpusPictureTag# *_pic,const char *_tag, |
| 576 | unsigned char *_buf,size_t _buf_sz,size_t _base64_sz){ |
| 577 | opus_int32cxx . . $ opus_int32# picture_type; |
| 578 | opus_uint32cxx . . $ opus_uint32# mime_type_length; |
| 579 | char *mime_type; |
| 580 | opus_uint32cxx . . $ opus_uint32# description_length; |
| 581 | char *description; |
| 582 | opus_uint32cxx . . $ opus_uint32# width; |
| 583 | opus_uint32cxx . . $ opus_uint32# height; |
| 584 | opus_uint32cxx . . $ opus_uint32# depth; |
| 585 | opus_uint32cxx . . $ opus_uint32# colors; |
| 586 | opus_uint32cxx . . $ opus_uint32# data_length; |
| 587 | opus_uint32cxx . . $ opus_uint32# file_width; |
| 588 | opus_uint32cxx . . $ opus_uint32# file_height; |
| 589 | opus_uint32cxx . . $ opus_uint32# file_depth; |
| 590 | opus_uint32cxx . . $ opus_uint32# file_colors; |
| 591 | int format; |
| 592 | int has_palette; |
| 593 | int colors_set; |
| 594 | size_t i; |
| 595 | /*Decode the BASE64 data.*/ |
| 596 | OP_ASSERTcxx . . $ `external/opusfile/opusfile_internal.h:91:11`!(_base64_sz>=11); |
| 597 | for(i=0;i<_base64_sz;i++){ |
| 598 | opus_uint32cxx . . $ opus_uint32# value; |
| 599 | int j; |
| 600 | value=0; |
| 601 | for(j=0;j<4;j++){ |
| 602 | unsigned c; |
| 603 | unsigned d; |
| 604 | c=(unsigned char)_tag[4*i+j]; |
| 605 | if(c=='+')d=62; |
| 606 | else if(c=='/')d=63; |
| 607 | else if(c>='0'&&c<='9')d=52+c-'0'; |
| 608 | else if(c>='a'&&c<='z')d=26+c-'a'; |
| 609 | else if(c>='A'&&c<='Z')d=c-'A'; |
| 610 | else if(c=='='&&3*i+j>_buf_sz)d=0; |
| 611 | else return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 612 | value=value<<6|d; |
| 613 | } |
| 614 | _buf[3*i]=(unsigned char)(value>>16); |
| 615 | if(3*i+1<_buf_sz){ |
| 616 | _buf[3*i+1]=(unsigned char)(value>>8); |
| 617 | if(3*i+2<_buf_sz)_buf[3*i+2]=(unsigned char)value; |
| 618 | } |
| 619 | } |
| 620 | i=0; |
| 621 | picture_type=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 622 | i+=4; |
| 623 | /*Extract the MIME type.*/ |
| 624 | mime_type_length=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 625 | i+=4; |
| 626 | if(mime_type_length>_buf_sz-32)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 627 | mime_type=(char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*_pic->mime_typecxx . . $ OpusPictureTag#mime_type.)*(mime_type_length+1)); |
| 628 | if(mime_type==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 629 | memcpy(mime_type,_buf+i,sizeof(*mime_type)*mime_type_length); |
| 630 | mime_type[mime_type_length]='\0'; |
| 631 | _pic->mime_typecxx . . $ OpusPictureTag#mime_type.=mime_type; |
| 632 | i+=mime_type_length; |
| 633 | /*Extract the description string.*/ |
| 634 | description_length=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 635 | i+=4; |
| 636 | if(description_length>_buf_sz-mime_type_length-32)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 637 | description= |
| 638 | (char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*_pic->mime_typecxx . . $ OpusPictureTag#mime_type.)*(description_length+1)); |
| 639 | if(description==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 640 | memcpy(description,_buf+i,sizeof(*description)*description_length); |
| 641 | description[description_length]='\0'; |
| 642 | _pic->descriptioncxx . . $ OpusPictureTag#description.=description; |
| 643 | i+=description_length; |
| 644 | /*Extract the remaining fields.*/ |
| 645 | width=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 646 | i+=4; |
| 647 | height=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 648 | i+=4; |
| 649 | depth=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 650 | i+=4; |
| 651 | colors=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 652 | i+=4; |
| 653 | /*If one of these is set, they all must be, but colors==0 is a valid value.*/ |
| 654 | colors_set=width!=0||height!=0||depth!=0||colors!=0; |
| 655 | if((width==0||height==0||depth==0)&&colors_set)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 656 | data_length=op_parse_uint32becxx . . $ op_parse_uint32be(ca1608e2c87725e2).(_buf+i); |
| 657 | i+=4; |
| 658 | if(data_length>_buf_sz-i)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 659 | /*Trim extraneous data so we don't copy it below.*/ |
| 660 | _buf_sz=i+data_length; |
| 661 | /*Attempt to determine the image format.*/ |
| 662 | format=OP_PIC_FORMAT_UNKNOWNcxx . . $ `external/opusfile/opusfile.h:319:9`!; |
| 663 | if(mime_type_length==3&&strcmp(mime_type,"-->")==0){ |
| 664 | format=OP_PIC_FORMAT_URLcxx . . $ `external/opusfile/opusfile.h:321:9`!; |
| 665 | /*Picture type 1 must be a 32x32 PNG.*/ |
| 666 | if(picture_type==1&&(width!=0||height!=0)&&(width!=32||height!=32)){ |
| 667 | return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 668 | } |
| 669 | /*Append a terminating NUL for the convenience of our callers.*/ |
| 670 | _buf[_buf_sz++]='\0'; |
| 671 | } |
| 672 | else{ |
| 673 | if(mime_type_length==10 |
| 674 | &&op_strncasecmpcxx . . $ op_strncasecmp(f0be30763a490cce).(mime_type,"image/jpeg",mime_type_length)==0){ |
| 675 | if(op_is_jpegcxx . . $ op_is_jpeg(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_JPEGcxx . . $ `external/opusfile/opusfile.h:323:9`!; |
| 676 | } |
| 677 | else if(mime_type_length==9 |
| 678 | &&op_strncasecmpcxx . . $ op_strncasecmp(f0be30763a490cce).(mime_type,"image/png",mime_type_length)==0){ |
| 679 | if(op_is_pngcxx . . $ op_is_png(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_PNGcxx . . $ `external/opusfile/opusfile.h:325:9`!; |
| 680 | } |
| 681 | else if(mime_type_length==9 |
| 682 | &&op_strncasecmpcxx . . $ op_strncasecmp(f0be30763a490cce).(mime_type,"image/gif",mime_type_length)==0){ |
| 683 | if(op_is_gifcxx . . $ op_is_gif(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_GIFcxx . . $ `external/opusfile/opusfile.h:327:9`!; |
| 684 | } |
| 685 | else if(mime_type_length==0||(mime_type_length==6 |
| 686 | &&op_strncasecmpcxx . . $ op_strncasecmp(f0be30763a490cce).(mime_type,"image/",mime_type_length)==0)){ |
| 687 | if(op_is_jpegcxx . . $ op_is_jpeg(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_JPEGcxx . . $ `external/opusfile/opusfile.h:323:9`!; |
| 688 | else if(op_is_pngcxx . . $ op_is_png(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_PNGcxx . . $ `external/opusfile/opusfile.h:325:9`!; |
| 689 | else if(op_is_gifcxx . . $ op_is_gif(22502bda773498f8).(_buf+i,data_length))format=OP_PIC_FORMAT_GIFcxx . . $ `external/opusfile/opusfile.h:327:9`!; |
| 690 | } |
| 691 | file_width=file_height=file_depth=file_colors=0; |
| 692 | has_palette=-1; |
| 693 | switch(format){ |
| 694 | case OP_PIC_FORMAT_JPEGcxx . . $ `external/opusfile/opusfile.h:323:9`!:{ |
| 695 | op_extract_jpeg_paramscxx . . $ op_extract_jpeg_params(24bcfede25d11c7d).(_buf+i,data_length, |
| 696 | &file_width,&file_height,&file_depth,&file_colors,&has_palette); |
| 697 | }break; |
| 698 | case OP_PIC_FORMAT_PNGcxx . . $ `external/opusfile/opusfile.h:325:9`!:{ |
| 699 | op_extract_png_paramscxx . . $ op_extract_png_params(24bcfede25d11c7d).(_buf+i,data_length, |
| 700 | &file_width,&file_height,&file_depth,&file_colors,&has_palette); |
| 701 | }break; |
| 702 | case OP_PIC_FORMAT_GIFcxx . . $ `external/opusfile/opusfile.h:327:9`!:{ |
| 703 | op_extract_gif_paramscxx . . $ op_extract_gif_params(24bcfede25d11c7d).(_buf+i,data_length, |
| 704 | &file_width,&file_height,&file_depth,&file_colors,&has_palette); |
| 705 | }break; |
| 706 | } |
| 707 | if(has_palette>=0){ |
| 708 | /*If we successfully extracted these parameters from the image, override |
| 709 | any declared values.*/ |
| 710 | width=file_width; |
| 711 | height=file_height; |
| 712 | depth=file_depth; |
| 713 | colors=file_colors; |
| 714 | } |
| 715 | /*Picture type 1 must be a 32x32 PNG.*/ |
| 716 | if(picture_type==1&&(format!=OP_PIC_FORMAT_PNGcxx . . $ `external/opusfile/opusfile.h:325:9`!||width!=32||height!=32)){ |
| 717 | return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 718 | } |
| 719 | } |
| 720 | /*Adjust _buf_sz instead of using data_length to capture the terminating NUL |
| 721 | for URLs.*/ |
| 722 | _buf_sz-=i; |
| 723 | memmove(_buf,_buf+i,sizeof(*_buf)*_buf_sz); |
| 724 | _buf=(unsigned char *)Melder_realloccxx . . $ Melder_realloc(d42fd80046fa8ace).(_buf,_buf_sz); |
| 725 | if(_buf_sz>0&&_buf==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 726 | _pic->typecxx . . $ OpusPictureTag#type.=picture_type; |
| 727 | _pic->widthcxx . . $ OpusPictureTag#width.=width; |
| 728 | _pic->heightcxx . . $ OpusPictureTag#height.=height; |
| 729 | _pic->depthcxx . . $ OpusPictureTag#depth.=depth; |
| 730 | _pic->colorscxx . . $ OpusPictureTag#colors.=colors; |
| 731 | _pic->data_lengthcxx . . $ OpusPictureTag#data_length.=data_length; |
| 732 | _pic->datacxx . . $ OpusPictureTag#data.=_buf; |
| 733 | _pic->formatcxx . . $ OpusPictureTag#format.=format; |
| 734 | return 0; |
| 735 | } |
| 736 | |
| 737 | int opus_picture_tag_parsecxx . . $ opus_picture_tag_parse(2005a5775e53c484).(OpusPictureTagcxx . . $ OpusPictureTag# *_pic,const char *_tag){ |
| 738 | OpusPictureTagcxx . . $ OpusPictureTag# pic; |
| 739 | unsigned char *buf; |
| 740 | size_t base64_sz; |
| 741 | size_t buf_sz; |
| 742 | size_t tag_length; |
| 743 | int ret; |
| 744 | if(opus_tagncomparecxx . . $ opus_tagncompare(c7241514171e2942).("METADATA_BLOCK_PICTURE",22,_tag)==0)_tag+=23; |
| 745 | /*Figure out how much BASE64-encoded data we have.*/ |
| 746 | tag_length=strlen(_tag); |
| 747 | if(tag_length&3)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 748 | base64_sz=tag_length>>2; |
| 749 | buf_sz=3*base64_sz; |
| 750 | if(buf_sz<32)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 751 | if(_tag[tag_length-1]=='=')buf_sz--; |
| 752 | if(_tag[tag_length-2]=='=')buf_sz--; |
| 753 | if(buf_sz<32)return OP_ENOTFORMATcxx . . $ `external/opusfile/opusfile.h:183:9`!; |
| 754 | /*Allocate an extra byte to allow appending a terminating NUL to URL data.*/ |
| 755 | buf=(unsigned char *)_Melder_malloccxx . . $ _Melder_malloc(1de1fe46563a6a2a).(sizeof(*buf)*(buf_sz+1)); |
| 756 | if(buf==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)return OP_EFAULTcxx . . $ `external/opusfile/opusfile.h:173:9`!; |
| 757 | opus_picture_tag_initcxx . . $ opus_picture_tag_init(133f07de582ffe9e).(&pic); |
| 758 | ret=opus_picture_tag_parse_implcxx . . $ opus_picture_tag_parse_impl(e123a46d9957eea4).(&pic,_tag,buf,buf_sz,base64_sz); |
| 759 | if(ret<0){ |
| 760 | opus_picture_tag_clearcxx . . $ opus_picture_tag_clear(133f07de582ffe9e).(&pic); |
| 761 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(buf); |
| 762 | } |
| 763 | else *_pic=cxx . . $ OpusPictureTag#`operator=`(dc447e2c41a7e2d0).*&pic; |
| 764 | return ret; |
| 765 | } |
| 766 | |
| 767 | void opus_picture_tag_initcxx . . $ opus_picture_tag_init(133f07de582ffe9e).(OpusPictureTagcxx . . $ OpusPictureTag# *_pic){ |
| 768 | memset(_pic,0,sizeof(*_pic)); |
| 769 | } |
| 770 | |
| 771 | void opus_picture_tag_clearcxx . . $ opus_picture_tag_clear(133f07de582ffe9e).(OpusPictureTagcxx . . $ OpusPictureTag# *_pic){ |
| 772 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_pic->description); |
| 773 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_pic->mime_type); |
| 774 | Melder_freecxx . . $ `melder/melder_alloc.h:38:9`!(_pic->data); |
| 775 | } |