[FFmpeg-devel] [PATCH] Deprecate av_fifo_realloc() in favour of a safer av_fifo_realloc2()

Stefano Sabatini stefano.sabatini-lala
Wed Aug 13 22:11:37 CEST 2008


On date Monday 2008-08-11 17:14:50 +0200, Stefano Sabatini encoded:
> On date Monday 2008-08-11 14:14:28 +0100, M?ns Rullg?rd encoded:
> > 
> > Stefano Sabatini wrote:
> > > If there are no objections then I'll apply it on Wednesday (then I'll
> > > provide further patches to fix the deprecation warnings).
> > 
> > IMO, deprecation attributes should only be added when the old functions
> > are no longer used internally.
> 
> Fine with me, so the plan is:
> 1) define the new function
> 2) make the codebase use the new functions
> 3) deprecate the old av_fifo_realloc() and put it under #if VERSION < ...
> 
> Patches for points 1 and 2 attached.
[...]
> Index: libavutil/fifo.h
> ===================================================================
> --- libavutil/fifo.h	(revision 14692)
> +++ libavutil/fifo.h	(working copy)
> @@ -97,10 +97,19 @@
>   * Resizes an AVFifoBuffer.
>   * @param *f AVFifoBuffer to resize
>   * @param size new AVFifoBuffer size in bytes
> + * @see av_fifo_realloc2()
>   */
>  void av_fifo_realloc(AVFifoBuffer *f, unsigned int size);
>  
>  /**
> + * Resizes an AVFifoBuffer.
> + * @param *f AVFifoBuffer to resize
> + * @param size new AVFifoBuffer size in bytes
> + * @return <0 for failure >=0 otherwise
> + */
> +int av_fifo_realloc2(AVFifoBuffer *f, unsigned int size);
> +
> +/**
>   * Reads and discards the specified amount of data from an AVFifoBuffer.
>   * @param *f AVFifoBuffer to read from
>   * @param size amount of data to read in bytes
> Index: libavutil/fifo.c
> ===================================================================
> --- libavutil/fifo.c	(revision 14692)
> +++ libavutil/fifo.c	(working copy)
> @@ -55,18 +55,24 @@
>   * Resizes a FIFO.
>   */
>  void av_fifo_realloc(AVFifoBuffer *f, unsigned int new_size) {
> +    av_fifo_realloc2(f, new_size);
> +}
> +
> +int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) {
>      unsigned int old_size= f->end - f->buffer;
>  
>      if(old_size <= new_size){
>          int len= av_fifo_size(f);
>          AVFifoBuffer f2;
>  
> -        av_fifo_init(&f2, new_size);
> +        if (av_fifo_init(&f2, new_size) < 0)
> +            return -1;
>          av_fifo_read(f, f2.buffer, len);
>          f2.wptr += len;
>          av_free(f->buffer);
>          *f= f2;
>      }
> +    return 0;
>  }
>  
>  void av_fifo_write(AVFifoBuffer *f, const uint8_t *buf, int size)

> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 14692)
> +++ ffmpeg.c	(working copy)
> @@ -641,7 +641,10 @@
>      /* now encode as many frames as possible */
>      if (enc->frame_size > 1) {
>          /* output resampled raw samples */
> -        av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out);
> +        if (av_fifo_realloc2(&ost->fifo, av_fifo_size(&ost->fifo) + size_out) < 0) {
> +            fprintf(stderr, "av_fifo_realloc2() failed\n");
> +            av_exit(1);
> +        }
>          av_fifo_generic_write(&ost->fifo, buftmp, size_out, NULL);
>  
>          frame_bytes = enc->frame_size * 2 * enc->channels;
> Index: libavformat/mpegenc.c
> ===================================================================
> --- libavformat/mpegenc.c	(revision 14692)
> +++ libavformat/mpegenc.c	(working copy)
> @@ -1170,7 +1170,8 @@
>          stream->predecode_packet= pkt_desc;
>      stream->next_packet= &pkt_desc->next;
>  
> -    av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size);
> +    if (av_fifo_realloc2(&stream->fifo, av_fifo_size(&stream->fifo) + size) < 0)
> +        return -1;
>  
>      if (s->is_dvd){
>          if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)

Ping?
-- 
FFmpeg = Free and Furious Magical Portable Extended Guide




More information about the ffmpeg-devel mailing list