Changeset 2aa6ed9b67b83743c36baed75e1e6b56e91284dc

Show
Ignore:
Timestamp:
06/11/08 16:57:23 (3 months ago)
Author:
Rafaël Carré <rcarre@m2x.nl>
git-committer:
Rafaël Carré <rcarre@m2x.nl> 1213196243 +0200
git-parent:

[03ec97b0f1e272d2a247571415d9bc0e03d0add2]

git-author:
Rafaël Carré <rcarre@m2x.nl> 1213196243 +0200
Message:

FFmpeg encoder : be sure to use the minimum required buffer size

Use the correct type for the buffer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/codec/avcodec/encoder.c

    rf7d5f3e r2aa6ed9  
    107107     */ 
    108108    char *p_buffer; 
    109     char *p_buffer_out; 
     109    uint8_t *p_buffer_out; 
     110    size_t i_buffer_out; 
    110111 
    111112    /* 
     
    264265    p_enc->pf_encode_audio = EncodeAudio; 
    265266 
     267    p_sys->p_buffer = NULL; 
    266268    p_sys->p_buffer_out = NULL; 
    267     p_sys->p_buffer = NULL
     269    p_sys->i_buffer_out = 0
    268270 
    269271    p_sys->p_context = p_context = avcodec_alloc_context(); 
     
    459461                   i_aspect_den * (int64_t)p_context->width, 1 << 30 ); 
    460462 
    461         p_sys->p_buffer_out = malloc( p_context->height * p_context->width * 3 ); 
     463        p_sys->i_buffer_out = p_context->height * p_context->width * 3; 
     464        if( p_sys->i_buffer_out < FF_MIN_BUFFER_SIZE ) 
     465            p_sys->i_buffer_out = FF_MIN_BUFFER_SIZE; 
     466        p_sys->p_buffer_out = malloc( p_sys->i_buffer_out ); 
    462467 
    463468        p_enc->fmt_in.i_codec = VLC_FOURCC('I','4','2','0'); 
     
    687692    if( p_enc->fmt_in.i_cat == AUDIO_ES ) 
    688693    { 
    689         p_sys->p_buffer_out = malloc( 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE ); 
     694        p_sys->i_buffer_out = 2 * AVCODEC_MAX_AUDIO_FRAME_SIZE; 
     695        p_sys->p_buffer_out = malloc( p_sys->i_buffer_out ); 
    690696        p_sys->i_frame_size = p_context->frame_size * 2 * p_context->channels; 
    691697        p_sys->p_buffer = malloc( p_sys->i_frame_size ); 
     
    903909    /* End work-around */ 
    904910 
    905     i_out = avcodec_encode_video( p_sys->p_context, (uint8_t*)p_sys->p_buffer_out, 
    906                                   p_sys->p_context->height * p_sys->p_context->width * 3, &frame ); 
     911    i_out = avcodec_encode_video( p_sys->p_context, p_sys->p_buffer_out, 
     912                                  p_sys->i_buffer_out, &frame ); 
    907913 
    908914    if( i_out > 0 ) 
     
    10251031        } 
    10261032 
    1027         i_out = avcodec_encode_audio( p_sys->p_context, 
    1028                                       (uint8_t *)p_sys->p_buffer_out, 
    1029                                       2 * AVCODEC_MAX_AUDIO_FRAME_SIZE, 
    1030                                       p_samples ); 
     1033        i_out = avcodec_encode_audio( p_sys->p_context, p_sys->p_buffer_out, 
     1034                                      p_sys->i_buffer_out, p_samples ); 
    10311035 
    10321036#if 0