[FFmpeg-devel] [PATCH 3/6] libavformat: Add a function for freeing an AVFormatContext

Reinhard Tartler siretart
Thu Feb 3 13:44:53 CET 2011


On Thu, Feb 03, 2011 at 13:10:14 (CET), Martin Storsj? wrote:

> This function is useful for freeing data structures allocated by
> muxers, which currently have to be freed manually by the caller.
> ---
>  libavformat/avformat.h |    6 ++++++
>  libavformat/utils.c    |   11 ++++++++---
>  2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index f9f9be5..1cbe274 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1230,6 +1230,12 @@ void av_close_input_stream(AVFormatContext *s);
>  void av_close_input_file(AVFormatContext *s);
>  
>  /**
> + * Free an AVFormatContext and all its streams.
> + * @param s context to free
> + */
> +void av_free_context(AVFormatContext *s);
> +
> +/**
>   * Add a new stream to a media file.
>   *
>   * Can only be called in the read_header() function. If the flag
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 4f51c26..2d0dea5 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2541,12 +2541,17 @@ int av_read_pause(AVFormatContext *s)
>  
>  void av_close_input_stream(AVFormatContext *s)
>  {
> -    int i;
> -    AVStream *st;
> -
>      flush_packet_queue(s);
>      if (s->iformat->read_close)
>          s->iformat->read_close(s);
> +    av_free_context(s);
> +}
> +
> +void av_free_context(AVFormatContext *s)
> +{
> +    int i;
> +    AVStream *st;
> +
>      for(i=0;i<s->nb_streams;i++) {
>          /* free all data in a stream component */
>          st = s->streams[i];

Patch misses doc/APIchanges update and minor bump.

-- 
Gruesse/greetings,
Reinhard Tartler, KeyID 945348A4




More information about the ffmpeg-devel mailing list