Revision 1574eff3

View differences:

libavcodec/vmdav.c
506 506
    const uint8_t *buf = avpkt->data;
507 507
    int buf_size = avpkt->size;
508 508
    VmdAudioContext *s = avctx->priv_data;
509
    int block_type;
509
    int block_type, silent_chunks;
510 510
    unsigned char *output_samples = (unsigned char *)data;
511 511

  
512 512
    if (buf_size < 16) {
......
523 523
    buf      += 16;
524 524
    buf_size -= 16;
525 525

  
526
    if (block_type == BLOCK_TYPE_AUDIO) {
527
        /* the chunk contains audio */
528
        *data_size = vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);
529
    } else if (block_type == BLOCK_TYPE_INITIAL) {
530
        /* initial chunk, may contain audio and silence */
526
    silent_chunks = 0;
527
    if (block_type == BLOCK_TYPE_INITIAL) {
531 528
        uint32_t flags = AV_RB32(buf);
532
        int silent_chunks = av_popcount(flags);
529
        silent_chunks  = av_popcount(flags);
533 530
        buf      += 4;
534 531
        buf_size -= 4;
535
        if(*data_size < (s->block_align*silent_chunks + buf_size) * 2)
536
            return -1;
537
        *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);
538 532
    } else if (block_type == BLOCK_TYPE_SILENCE) {
539
        /* silent chunk */
540
        *data_size = vmdaudio_loadsound(s, output_samples, buf, 1, 0);
533
        silent_chunks = 1;
534
        buf_size = 0; // should already be zero but set it just to be sure
541 535
    }
542 536

  
537
    /* ensure output buffer is large enough */
538
    if (*data_size < (s->block_align*silent_chunks + buf_size) * 2)
539
        return -1;
540

  
541
    *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);
542

  
543 543
    return avpkt->size;
544 544
}
545 545

  

Also available in: Unified diff