... | ... |
@@ -273,6 +273,73 @@ static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_siz |
273 | 273 |
} |
274 | 274 |
} |
275 | 275 |
|
276 |
+static int read_header(ShortenContext *s) |
|
277 |
+{ |
|
278 |
+ int i; |
|
279 |
+ int maxnlpc = 0; |
|
280 |
+ /* shorten signature */ |
|
281 |
+ if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { |
|
282 |
+ av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); |
|
283 |
+ return -1; |
|
284 |
+ } |
|
285 |
+ |
|
286 |
+ s->lpcqoffset = 0; |
|
287 |
+ s->blocksize = DEFAULT_BLOCK_SIZE; |
|
288 |
+ s->channels = 1; |
|
289 |
+ s->nmean = -1; |
|
290 |
+ s->version = get_bits(&s->gb, 8); |
|
291 |
+ s->internal_ftype = get_uint(s, TYPESIZE); |
|
292 |
+ |
|
293 |
+ s->channels = get_uint(s, CHANSIZE); |
|
294 |
+ if (s->channels > MAX_CHANNELS) { |
|
295 |
+ av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); |
|
296 |
+ return -1; |
|
297 |
+ } |
|
298 |
+ |
|
299 |
+ /* get blocksize if version > 0 */ |
|
300 |
+ if (s->version > 0) { |
|
301 |
+ int skip_bytes; |
|
302 |
+ s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); |
|
303 |
+ maxnlpc = get_uint(s, LPCQSIZE); |
|
304 |
+ s->nmean = get_uint(s, 0); |
|
305 |
+ |
|
306 |
+ skip_bytes = get_uint(s, NSKIPSIZE); |
|
307 |
+ for (i=0; i<skip_bytes; i++) { |
|
308 |
+ skip_bits(&s->gb, 8); |
|
309 |
+ } |
|
310 |
+ } |
|
311 |
+ s->nwrap = FFMAX(NWRAP, maxnlpc); |
|
312 |
+ |
|
313 |
+ if (allocate_buffers(s)) |
|
314 |
+ return -1; |
|
315 |
+ |
|
316 |
+ init_offset(s); |
|
317 |
+ |
|
318 |
+ if (s->version > 1) |
|
319 |
+ s->lpcqoffset = V2LPCQOFFSET; |
|
320 |
+ |
|
321 |
+ if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { |
|
322 |
+ av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); |
|
323 |
+ return -1; |
|
324 |
+ } |
|
325 |
+ |
|
326 |
+ s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
|
327 |
+ if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { |
|
328 |
+ av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); |
|
329 |
+ return -1; |
|
330 |
+ } |
|
331 |
+ |
|
332 |
+ for (i=0; i<s->header_size; i++) |
|
333 |
+ s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
|
334 |
+ |
|
335 |
+ if (decode_wave_header(s->avctx, s->header, s->header_size) < 0) |
|
336 |
+ return -1; |
|
337 |
+ |
|
338 |
+ s->cur_chan = 0; |
|
339 |
+ s->bitshift = 0; |
|
340 |
+ |
|
341 |
+ return 0; |
|
342 |
+} |
|
276 | 343 |
|
277 | 344 |
static int shorten_decode_frame(AVCodecContext *avctx, |
278 | 345 |
void *data, int *data_size, |
... | ... |
@@ -311,67 +378,9 @@ static int shorten_decode_frame(AVCodecContext *avctx, |
311 | 311 |
skip_bits(&s->gb, s->bitindex); |
312 | 312 |
if (!s->blocksize) |
313 | 313 |
{ |
314 |
- int maxnlpc = 0; |
|
315 |
- /* shorten signature */ |
|
316 |
- if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { |
|
317 |
- av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); |
|
318 |
- return -1; |
|
319 |
- } |
|
320 |
- |
|
321 |
- s->lpcqoffset = 0; |
|
322 |
- s->blocksize = DEFAULT_BLOCK_SIZE; |
|
323 |
- s->channels = 1; |
|
324 |
- s->nmean = -1; |
|
325 |
- s->version = get_bits(&s->gb, 8); |
|
326 |
- s->internal_ftype = get_uint(s, TYPESIZE); |
|
327 |
- |
|
328 |
- s->channels = get_uint(s, CHANSIZE); |
|
329 |
- if (s->channels > MAX_CHANNELS) { |
|
330 |
- av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); |
|
331 |
- return -1; |
|
332 |
- } |
|
333 |
- |
|
334 |
- /* get blocksize if version > 0 */ |
|
335 |
- if (s->version > 0) { |
|
336 |
- int skip_bytes; |
|
337 |
- s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); |
|
338 |
- maxnlpc = get_uint(s, LPCQSIZE); |
|
339 |
- s->nmean = get_uint(s, 0); |
|
340 |
- |
|
341 |
- skip_bytes = get_uint(s, NSKIPSIZE); |
|
342 |
- for (i=0; i<skip_bytes; i++) { |
|
343 |
- skip_bits(&s->gb, 8); |
|
344 |
- } |
|
345 |
- } |
|
346 |
- s->nwrap = FFMAX(NWRAP, maxnlpc); |
|
347 |
- |
|
348 |
- if (allocate_buffers(s)) |
|
349 |
- return -1; |
|
350 |
- |
|
351 |
- init_offset(s); |
|
352 |
- |
|
353 |
- if (s->version > 1) |
|
354 |
- s->lpcqoffset = V2LPCQOFFSET; |
|
355 |
- |
|
356 |
- if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { |
|
357 |
- av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); |
|
358 |
- return -1; |
|
359 |
- } |
|
360 |
- |
|
361 |
- s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); |
|
362 |
- if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { |
|
363 |
- av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); |
|
364 |
- return -1; |
|
365 |
- } |
|
366 |
- |
|
367 |
- for (i=0; i<s->header_size; i++) |
|
368 |
- s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); |
|
369 |
- |
|
370 |
- if (decode_wave_header(avctx, s->header, s->header_size) < 0) |
|
371 |
- return -1; |
|
372 |
- |
|
373 |
- s->cur_chan = 0; |
|
374 |
- s->bitshift = 0; |
|
314 |
+ int ret; |
|
315 |
+ if ((ret = read_header(s)) < 0) |
|
316 |
+ return ret; |
|
375 | 317 |
} |
376 | 318 |
else |
377 | 319 |
{ |