[FFmpeg-devel] [PATCH] factorize stream info in av_find_stream_info

Michael Niedermayer michaelni
Tue Jun 16 20:27:06 CEST 2009


On Tue, Jun 16, 2009 at 01:04:06AM -0700, Baptiste Coudurier wrote:
Content-Description: ?
> Hi guys,
> 
> $subject, first patch factorize stream info in a struct, getting rid
> of MAX_STREAMS limit.
> 
> Second patch removes codec_info_nb_frames which appears useless.
> 
> -- 
> Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA    
> Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer                                  http://www.ffmpeg.org

>  utils.c |   86 +++++++++++++++++++++++++++++++++++++++-------------------------
>  1 file changed, 53 insertions(+), 33 deletions(-)
> 7b695df730779a268e6aa3c12e6ebadb4e51631e  factorize_stream_info.patch
> Index: libavformat/utils.c
> ===================================================================
> --- libavformat/utils.c	(revision 19202)
> +++ libavformat/utils.c	(working copy)
> @@ -2003,18 +2003,21 @@
>  int av_find_stream_info(AVFormatContext *ic)
>  {
>      int i, count, ret, read_size, j;
> +    int nb_streams = ic->nb_streams;
>      AVStream *st;
>      AVPacket pkt1, *pkt;
> -    int64_t last_dts[MAX_STREAMS];
> -    int64_t duration_gcd[MAX_STREAMS]={0};
> -    int duration_count[MAX_STREAMS]={0};
> -    double (*duration_error)[MAX_STD_TIMEBASES];
>      int64_t old_offset = url_ftell(ic->pb);
> -    int64_t codec_info_duration[MAX_STREAMS]={0};
> -    int codec_info_nb_frames[MAX_STREAMS]={0};
> +    struct {
> +        int64_t last_dts;
> +        int64_t duration_gcd;
> +        int64_t duration_count;
> +        int64_t duration;
> +        double duration_error[MAX_STD_TIMEBASES];
> +    } *stream_info = NULL, *new_stream_info;
>  
> -    duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
> -    if (!duration_error) return AVERROR(ENOMEM);

> +    stream_info = av_mallocz(nb_streams*sizeof(*stream_info));

can we be sure the multiply doesnt overflow?


[...]
> @@ -2052,7 +2055,8 @@
>                  break;
>              /* variable fps and no guess at the real fps */
>              if(   tb_unreliable(st->codec)
> -               && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO)
> +               && stream_info[st->index].duration_count<20 &&
> +                  st->codec->codec_type == CODEC_TYPE_VIDEO)
>                  break;
>              if(st->parser && st->parser->parser->split && !st->codec->extradata)
>                  break;

why is i changed to st->index ?


> @@ -2098,24 +2102,37 @@
>  
>          pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end);
>          if(av_dup_packet(pkt) < 0) {
> -            av_free(duration_error);
> +            av_free(stream_info);
>              return AVERROR(ENOMEM);
>          }
>  
>          read_size += pkt->size;
>  
>          st = ic->streams[pkt->stream_index];
> -        if(codec_info_nb_frames[st->index]>1) {
> -            if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration)
> -                break;
> -            codec_info_duration[st->index] += pkt->duration;
[...]
>          }
> -        if (pkt->duration != 0)
> -            codec_info_nb_frames[st->index]++;

this does not belong in the first patch

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090616/8735f4b6/attachment.pgp>



More information about the ffmpeg-devel mailing list