Revision 7a086a85 ffmpeg.c

View differences:

ffmpeg.c
563 563
{
564 564
    uint8_t *buftmp;
565 565
    int64_t audio_out_size, audio_buf_size;
566
    int64_t allocated_for_size= size;
566 567

  
567 568
    int size_out, frame_bytes, ret;
568 569
    AVCodecContext *enc= ost->st->codec;
......
571 572
    int isize= av_get_bits_per_sample_format(dec->sample_fmt)/8;
572 573
    const int coded_bps = av_get_bits_per_sample(enc->codec->id);
573 574

  
574
    audio_buf_size= (size + isize*dec->channels - 1) / (isize*dec->channels);
575
need_realloc:
576
    audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels);
575 577
    audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate;
576 578
    audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API
577 579
    audio_buf_size*= osize*enc->channels;
......
649 651
                    static uint8_t *input_tmp= NULL;
650 652
                    input_tmp= av_realloc(input_tmp, byte_delta + size);
651 653

  
652
                    if(byte_delta + size <= MAX_AUDIO_PACKET_SIZE)
653
                        ist->is_start=0;
654
                    else
655
                        byte_delta= MAX_AUDIO_PACKET_SIZE - size;
654
                    if(byte_delta > allocated_for_size - size){
655
                        allocated_for_size= byte_delta + (int64_t)size;
656
                        goto need_realloc;
657
                    }
658
                    ist->is_start=0;
656 659

  
657 660
                    memset(input_tmp, 0, byte_delta);
658 661
                    memcpy(input_tmp + byte_delta, buf, size);

Also available in: Unified diff