Mercurial > libavcodec.hg
comparison oggvorbis.c @ 2716:040b965f2cd0 libavcodec
accept old extradata format
author | mru |
---|---|
date | Thu, 19 May 2005 11:45:10 +0000 |
parents | 0975710cf7f4 |
children | c553a407b1b6 |
comparison
equal
deleted
inserted
replaced
2715:e36446161876 | 2716:040b965f2cd0 |
---|---|
178 oggvorbis_encode_frame, | 178 oggvorbis_encode_frame, |
179 oggvorbis_encode_close, | 179 oggvorbis_encode_close, |
180 .capabilities= CODEC_CAP_DELAY, | 180 .capabilities= CODEC_CAP_DELAY, |
181 } ; | 181 } ; |
182 | 182 |
183 | |
184 static int oggvorbis_decode_init(AVCodecContext *avccontext) { | 183 static int oggvorbis_decode_init(AVCodecContext *avccontext) { |
185 OggVorbisContext *context = avccontext->priv_data ; | 184 OggVorbisContext *context = avccontext->priv_data ; |
186 uint8_t *p= avccontext->extradata; | 185 uint8_t *p= avccontext->extradata; |
187 int i, hsizes[3]; | 186 int i, hsizes[3]; |
188 unsigned char *headers[3], *extradata = avccontext->extradata; | 187 unsigned char *headers[3], *extradata = avccontext->extradata; |
189 unsigned int offset; | |
190 | 188 |
191 vorbis_info_init(&context->vi) ; | 189 vorbis_info_init(&context->vi) ; |
192 vorbis_comment_init(&context->vc) ; | 190 vorbis_comment_init(&context->vc) ; |
193 | 191 |
194 if(! avccontext->extradata_size || ! p) { | 192 if(! avccontext->extradata_size || ! p) { |
195 av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n"); | 193 av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n"); |
196 return -1; | 194 return -1; |
197 } | 195 } |
198 if(*p != 2) { | 196 |
197 if(p[0] == 0 && p[1] == 30) { | |
198 for(i = 0; i < 3; i++){ | |
199 hsizes[i] = *p++ << 8; | |
200 hsizes[i] += *p++; | |
201 headers[i] = p; | |
202 p += hsizes[i]; | |
203 } | |
204 } else if(*p == 2) { | |
205 unsigned int offset = 1; | |
206 p++; | |
207 for(i=0; i<2; i++) { | |
208 hsizes[i] = 0; | |
209 while((*p == 0xFF) && (offset < avccontext->extradata_size)) { | |
210 hsizes[i] += 0xFF; | |
211 offset++; | |
212 p++; | |
213 } | |
214 if(offset >= avccontext->extradata_size - 1) { | |
215 av_log(avccontext, AV_LOG_ERROR, | |
216 "vorbis header sizes damaged\n"); | |
217 return -1; | |
218 } | |
219 hsizes[i] += *p; | |
220 offset++; | |
221 p++; | |
222 } | |
223 hsizes[2] = avccontext->extradata_size - hsizes[0]-hsizes[1]-offset; | |
224 #if 0 | |
225 av_log(avccontext, AV_LOG_DEBUG, | |
226 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n", | |
227 hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size); | |
228 #endif | |
229 headers[0] = extradata + offset; | |
230 headers[1] = extradata + offset + hsizes[0]; | |
231 headers[2] = extradata + offset + hsizes[0] + hsizes[1]; | |
232 } else { | |
199 av_log(avccontext, AV_LOG_ERROR, | 233 av_log(avccontext, AV_LOG_ERROR, |
200 "vorbis initial header len is wrong: %d\n", *p); | 234 "vorbis initial header len is wrong: %d\n", *p); |
201 return -1; | 235 return -1; |
202 } | 236 } |
203 offset = 1; | |
204 p++; | |
205 for(i=0; i<2; i++) { | |
206 hsizes[i] = 0; | |
207 while((*p == 0xFF) && (offset < avccontext->extradata_size)) { | |
208 hsizes[i] += 0xFF; | |
209 offset++; | |
210 p++; | |
211 } | |
212 if(offset >= avccontext->extradata_size - 1) { | |
213 av_log(avccontext, AV_LOG_ERROR, "vorbis header sizes damaged\n"); | |
214 return -1; | |
215 } | |
216 hsizes[i] += *p; | |
217 offset++; | |
218 p++; | |
219 } | |
220 hsizes[2] = avccontext->extradata_size - hsizes[0] - hsizes[1] - offset; | |
221 #if 0 | |
222 av_log(avccontext, AV_LOG_DEBUG, | |
223 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n", | |
224 hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size); | |
225 #endif | |
226 headers[0] = extradata + offset; | |
227 headers[1] = extradata + offset + hsizes[0]; | |
228 headers[2] = extradata + offset + hsizes[0] + hsizes[1]; | |
229 | 237 |
230 for(i=0; i<3; i++){ | 238 for(i=0; i<3; i++){ |
231 context->op.b_o_s= i==0; | 239 context->op.b_o_s= i==0; |
232 context->op.bytes = hsizes[i]; | 240 context->op.bytes = hsizes[i]; |
233 context->op.packet = headers[i]; | 241 context->op.packet = headers[i]; |
234 if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ | 242 if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ |
235 av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1); | 243 av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1); |
236 return -1; | 244 return -1; |
237 } | 245 } |
238 } | 246 } |
247 | |
239 avccontext->channels = context->vi.channels; | 248 avccontext->channels = context->vi.channels; |
240 avccontext->sample_rate = context->vi.rate; | 249 avccontext->sample_rate = context->vi.rate; |
241 avccontext->time_base= (AVRational){1, avccontext->sample_rate}; | 250 avccontext->time_base= (AVRational){1, avccontext->sample_rate}; |
242 | 251 |
243 vorbis_synthesis_init(&context->vd, &context->vi); | 252 vorbis_synthesis_init(&context->vd, &context->vi); |