Revision aa236250 libavcodec/vmdav.c

View differences:

libavcodec/vmdav.c
511 511
    int block_type;
512 512
    unsigned char *output_samples = (unsigned char *)data;
513 513

  
514
    /* point to the start of the encoded data */
515
    const unsigned char *p = buf + 16;
516

  
517 514
    if (buf_size < 16) {
518 515
        av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");
519 516
        *data_size = 0;
......
525 522
        av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type);
526 523
        return AVERROR(EINVAL);
527 524
    }
525
    buf      += 16;
526
    buf_size -= 16;
528 527

  
529 528
    if (block_type == BLOCK_TYPE_AUDIO) {
530 529
        /* the chunk contains audio */
531
        *data_size = vmdaudio_loadsound(s, output_samples, p, 0, buf_size - 16);
530
        *data_size = vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);
532 531
    } else if (block_type == BLOCK_TYPE_INITIAL) {
533 532
        /* initial chunk, may contain audio and silence */
534
        uint32_t flags = AV_RB32(p);
533
        uint32_t flags = AV_RB32(buf);
535 534
        int raw_block_size = s->block_align *
536 535
                             (av_get_bits_per_sample_fmt(avctx->sample_fmt) / 8);
537 536
        int silent_chunks = av_popcount(flags);
538
        if(*data_size < (s->block_align*silent_chunks + buf_size - 20) * 2)
537
        buf      += 4;
538
        buf_size -= 4;
539
        if(*data_size < (s->block_align*silent_chunks + buf_size) * 2)
539 540
            return -1;
540 541
        *data_size = 0;
541 542
        memset(output_samples, 0, raw_block_size * silent_chunks);
542 543
        output_samples += raw_block_size * silent_chunks;
543 544
        *data_size = raw_block_size * silent_chunks;
544
        *data_size += vmdaudio_loadsound(s, output_samples, p + 4, 0, buf_size - 20);
545
        *data_size += vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);
545 546
    } else if (block_type == BLOCK_TYPE_SILENCE) {
546 547
        /* silent chunk */
547
        *data_size = vmdaudio_loadsound(s, output_samples, p, 1, s->block_align);
548
        *data_size = vmdaudio_loadsound(s, output_samples, buf, 1, s->block_align);
548 549
    }
549 550

  
550
    return buf_size;
551
    return avpkt->size;
551 552
}
552 553

  
553 554

  

Also available in: Unified diff