[FFmpeg-devel] [PATCH] support for flvtool2 "keyframes based" generated index in FLV format decoder

Anton Khirnov anton
Wed Feb 16 20:52:14 CET 2011


First of all, could you please get rid of tabs and use git-formatted
patches?

> Index: libavformat/flvdec.c
> ===================================================================
> --- libavformat/flvdec.c	(revision 26402)
> +++ libavformat/flvdec.c	(working copy)
> @@ -30,6 +30,10 @@
>  #include "avformat.h"
>  #include "flv.h"
>  
> +#define METADATA_KEYFRAMES_TAG "keyframes"
> +#define METADATA_KEYFRAMES_TIMESTAMP_TAG "times"
> +#define METADATA_KEYFRAMES_BYTEOFFSET_TAG "filepositions"
> +
>  typedef struct {
>      int wrong_dts; ///< wrong dts due to negative cts
>  } FLVContext;
> @@ -124,6 +128,97 @@
>      return length;
>  }
>  
> +static int parse_keyframes_index(AVFormatContext *s, ByteIOContext *ioc, AVStream *vstream, int64_t max_pos) {
> +    unsigned int arraylen = 0, timeslen = 0, fileposlen = 0, i;
> +    double num_val;
> +    char str_val[256];
> +    int64_t *times = NULL;
> +    int64_t *filepositions = NULL;
> +
> +    while (url_ftell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
> +        int64_t* current_array;
> +
> +        // Expect array object in context
> +        if (get_byte(ioc) != AMF_DATA_TYPE_ARRAY) {
> +            av_freep(&times);
> +            av_freep(&filepositions);
> +            return -1;
> +	}
> +
> +        arraylen = get_be32(ioc);
> +        /*
> +         * Expect only 'times' or 'filepositions' sub-arrays in other case refuse to use such metadata
> +         * for indexing
> +         */
> +        if (!strcmp(METADATA_KEYFRAMES_TIMESTAMP_TAG, str_val)) {
> +            times = av_mallocz(sizeof(*times) * arraylen);

This will leak memory if the index contains more than one array of each
type. Change to realloc maybe?

-- 
Anton Khirnov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20110216/a1371635/attachment.pgp>



More information about the ffmpeg-devel mailing list