[FFmpeg-devel] [PATCH] Per-frame metadata
Stefano Sabatini
stefano.sabatini-lala at poste.it
Tue Apr 12 13:20:46 CEST 2011
On date Monday 2011-04-11 16:59:36 +0200, Nicolas George encoded:
> Hi.
>
> The attached series of patches introduce per-frame metadata, and in
> particular PNG zTXt and tEXt chunks decoding.
>
> I did not try to make it work for CC subtitles, as I do not know what
> exactly would be required, but I believe this is a first step in that
> direction too.
>
> Regards,
>
> --
> Nicolas George
> From c0557275f39dc7bc8049fa04cb0347e065147152 Mon Sep 17 00:00:00 2001
> From: Nicolas George <nicolas.george at normalesup.org>
> Date: Sun, 20 Mar 2011 19:39:20 +0100
> Subject: [PATCH 1/5] Introduce av_size_mult and av_realloc_f.
>
> av_size_mult helps checking for overflow when computing the size of a memory
> area.
>
> av_realloc_f helps avoiding memory-leaks in typical uses of realloc.
>
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
> libavutil/mem.c | 15 +++++++++++++++
> libavutil/mem.h | 25 +++++++++++++++++++++++++
> 2 files changed, 40 insertions(+), 0 deletions(-)
>
> diff --git a/libavutil/mem.c b/libavutil/mem.c
> index 7ffd6cb..26fb8c6 100644
> --- a/libavutil/mem.c
> +++ b/libavutil/mem.c
> @@ -136,6 +136,21 @@ void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size)
> #endif
> }
>
> +void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
> +{
> + size_t size;
> + void *r;
> +
> + if (av_size_mult(elsize, nelem, &size)) {
> + av_free(ptr);
> + return NULL;
> + }
> + r = av_realloc(ptr, size);
> + if (!r && size)
> + av_free(ptr);
> + return r;
> +}
> +
> void av_free(void *ptr)
> {
> #if CONFIG_MEMALIGN_HACK
> diff --git a/libavutil/mem.h b/libavutil/mem.h
> index 2bfbd0e..f661438 100644
> --- a/libavutil/mem.h
> +++ b/libavutil/mem.h
> @@ -95,6 +95,16 @@ void *av_malloc(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1);
> void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size) av_alloc_size(2);
>
> /**
> + * Allocate or reallocate a block of memory.
> + * This function does the same thing as av_realloc, except:
> + * - It takes two arguments and checks the result of the multiplication for
> + * integer overflow.
> + * - It frees the input block in case of failure, thus avoiding the memory
> + * leak with the classic "buf = realloc(buf); if (!buf) return -1;".
> + */
> +void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
> +
> +/**
> * Free a memory block which has been allocated with av_malloc(z)() or
> * av_realloc().
> * @param ptr Pointer to the memory block which should be freed.
> @@ -131,4 +141,19 @@ char *av_strdup(const char *s) av_malloc_attrib;
> */
> void av_freep(void *ptr);
>
> +/**
> + * Multiplies two size_t values checking for overflow.
Nit: multiply
> + * @return 0 if success, -1 if overflow.
-1 -> AVERROR(EINVAL)
> + */
> +static inline int av_size_mult(size_t a, size_t b, size_t *r)
> +{
> + size_t t = a * b;
> + /* Hack inspired from glibc: only try the division if nelem and elsize
> + * are both greater than sqrt(SIZE_MAX). */
> + if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
> + return -1;
ditto
> + *r = t;
> + return 0;
> +}
> +
> #endif /* AVUTIL_MEM_H */
> --
> 1.7.4.1
>
[...]
> From 74809f4f0e77b136bc5b0ea8f894b160928ed3df Mon Sep 17 00:00:00 2001
> From: Nicolas George <nicolas.george at normalesup.org>
> Date: Wed, 23 Mar 2011 19:56:25 +0100
> Subject: [PATCH 3/5] Move metadata API to libavcodec.
>
> The deprecated functions stay in libavformat until they are removed.
> To avoid problems with a double definition of AVMetadataConv, a preprocessor
> macro is defined; this will be removed after the major version bump.
>
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
Would it make sense to move metadata to libavutil rather than to
libavcodec?
For example you may need to display metadata from a lavfi filter.
[...]
--
FFmpeg = Fabulous and Fascinating Mythic Peaceless Elected Gorilla
More information about the ffmpeg-devel
mailing list