[libav-devel] [PATCH] avio: simplify url_open_dyn_buf_internal by using avio_alloc_context()

Ronald S. Bultje rsbultje at gmail.com
Sun Apr 3 23:28:38 CEST 2011


Hi,

On Sun, Apr 3, 2011 at 2:00 PM, Anton Khirnov <anton at khirnov.net> wrote:
> ---
>  libavformat/aviobuf.c |   20 ++++++--------------
>  1 files changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 2e7ee15..18c8a05 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -1114,7 +1114,6 @@ static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
>  static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
>  {
>     DynBuffer *d;
> -    int ret;
>     unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
>
>     if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
> @@ -1122,23 +1121,16 @@ static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
>     d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
>     if (!d)
>         return AVERROR(ENOMEM);
> -    *s = av_mallocz(sizeof(AVIOContext));
> +    d->io_buffer_size = io_buffer_size;
> +    *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
> +                            max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
> +                            max_packet_size ? NULL : dyn_buf_seek);
>     if(!*s) {
>         av_free(d);
>         return AVERROR(ENOMEM);
>     }
> -    d->io_buffer_size = io_buffer_size;
> -    ret = ffio_init_context(*s, d->io_buffer, io_buffer_size,
> -                        1, d, NULL,
> -                        max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
> -                        max_packet_size ? NULL : dyn_buf_seek);
> -    if (ret == 0) {
> -        (*s)->max_packet_size = max_packet_size;
> -    } else {
> -        av_free(d);
> -        av_freep(s);
> -    }
> -    return ret;
> +    (*s)->max_packet_size = max_packet_size;
> +    return 0;
>  }
>
>  int url_open_dyn_buf(AVIOContext **s)
> --
> 1.7.4.1

OK.

Ronald


More information about the libav-devel mailing list