[FFmpeg-devel] [PATCH] better reporting of programs

Michael Niedermayer michaelni
Tue Oct 16 23:20:55 CEST 2007


On Sun, Oct 14, 2007 at 01:29:44PM +0200, Nico Sabbi wrote:
> Patch 1 adds to AVProgram an array of stream_ids associated to each 
> program, needed for patch 2 and for a forthcoming patch that
> in ffmpeg will leverage the knowledge of stream_id to select the 
> program to decode;
> Patch 2 does a complete reporting of programs and stream_ids
> when programs are present.

> Index: mpegts.c
> ===================================================================
> --- mpegts.c	(revisione 10581)
> +++ mpegts.c	(copia locale)
> @@ -597,6 +597,8 @@
>                      st = new_pes_av_stream(pes, 0);
>              }
>              add_pid_to_pmt(ts, h->id, pid);
> +            if(st)
> +                av_program_add_stream_id(ts->stream, h->id, st->id);

wouldnt it be better to use the index (like in AVFormatContext.streams[index])
or even a AVStream pointer
instead of AVStream.id ? it would be easier to find the AVStream with the
index/pointer, also finding the id from the index is a mere .streams[index].id
the other way around is slightly harder and less efficient


>              break;
>          default:
>              /* we ignore the other streams */
> Index: avformat.h
> ===================================================================
> --- avformat.h	(revisione 10579)
> +++ avformat.h	(copia locale)
> @@ -346,6 +346,7 @@
>  } AVStream;
>  
>  #define AV_PROGRAM_RUNNING 1
> +#define AV_MAX_STREAMS_PER_PROGRAM 64
>  
>  typedef struct AVProgram {
>      int            id;
> @@ -353,6 +354,8 @@
>      char           *name;          ///< Service name for DVB streams
>      int            flags;
>      enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
> +    int            stream_id[AV_MAX_STREAMS_PER_PROGRAM];
> +    int            nb_stream_ids;
>  } AVProgram;

by how much would the complexity increas if this where (re)alloc() instead
of fixed 64 ?

also the minor version should be bumped


[...]

> Index: utils.c
> ===================================================================
> --- utils.c	(revisione 10579)
> +++ utils.c	(copia locale)
> @@ -2488,6 +2508,32 @@
>  
>  /* "user interface" functions */
>  
> +static void dump_stream_format(AVFormatContext *ic, int i, int index, char *buf, int is_output)
> +{
> +    int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
> +    AVStream *st = ic->streams[i];
> +    int g = ff_gcd(st->time_base.num, st->time_base.den);
> +    avcodec_string(buf, sizeof(buf), st->codec, is_output);
> +    av_log(NULL, AV_LOG_INFO, "    Stream #%d.%d", index, i);
> +    /* the pid is an important information, so we display it */
> +    /* XXX: add a generic system */
> +    if (flags & AVFMT_SHOW_IDS)
> +        av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
> +    if (strlen(st->language) > 0)
> +        av_log(NULL, AV_LOG_INFO, "(%s)", st->language);
> +    av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g);
> +    av_log(NULL, AV_LOG_INFO, ": %s", buf);
> +    if(st->codec->codec_type == CODEC_TYPE_VIDEO){
> +        if(st->r_frame_rate.den && st->r_frame_rate.num)
> +            av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate));
> +/*      else if(st->time_base.den && st->time_base.num)
> +            av_log(NULL, AV_LOG_INFO, ", %5.2f fps(m)", 1/av_q2d(st->time_base));*/
> +        else
> +            av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base));
> +    }
> +    av_log(NULL, AV_LOG_INFO, "\n");
> +}
> +
>  void dump_format(AVFormatContext *ic,
>                   int index,
>                   const char *url,
> @@ -2532,35 +2578,24 @@
>          }
>          av_log(NULL, AV_LOG_INFO, "\n");
>      }
> -    for(i=0;i<ic->nb_streams;i++) {
> -        AVStream *st = ic->streams[i];
> -        int g= ff_gcd(st->time_base.num, st->time_base.den);
> -        avcodec_string(buf, sizeof(buf), st->codec, is_output);
> -        av_log(NULL, AV_LOG_INFO, "  Stream #%d.%d", index, i);
> -        /* the pid is an important information, so we display it */
> -        /* XXX: add a generic system */
> -        if (is_output)
> -            flags = ic->oformat->flags;
> -        else
> -            flags = ic->iformat->flags;
> -        if (flags & AVFMT_SHOW_IDS) {
> -            av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
> +    if(ic->nb_programs) {
> +        int j, k;
> +        for(j=0; j<ic->nb_programs; j++) {
> +        av_log(NULL, AV_LOG_INFO, "  Program %d", ic->programs[j]->id);
> +        if(ic->programs[j]->name)
> +            av_log(NULL, AV_LOG_INFO, " \"%s\"\n", ic->programs[j]->name);
> +            for(k=0; k<ic->programs[j]->nb_stream_ids; k++) {
> +                for(i=0; i<ic->nb_streams; i++) {
> +                    if(ic->streams[i]->id != ic->programs[j]->stream_id[k]) {
> +                        dump_stream_format(ic, i, index, buf, is_output);
> +                        break;
> +                    }
> +                }
> +            }
>          }
> -        if (strlen(st->language) > 0) {
> -            av_log(NULL, AV_LOG_INFO, "(%s)", st->language);
> -        }
> -        av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g);
> -        av_log(NULL, AV_LOG_INFO, ": %s", buf);
> -        if(st->codec->codec_type == CODEC_TYPE_VIDEO){
> -            if(st->r_frame_rate.den && st->r_frame_rate.num)
> -                av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate));
> -/*            else if(st->time_base.den && st->time_base.num)
> -                av_log(NULL, AV_LOG_INFO, ", %5.2f fps(m)", 1/av_q2d(st->time_base));*/
> -            else
> -                av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base));
> -        }
> -        av_log(NULL, AV_LOG_INFO, "\n");
> -    }
> +    } else
> +        for(i=0; i<ic->nb_streams; i++)
> +            dump_stream_format(ic, i, index, buf, is_output);
>  }

could you split the cosmetic code moving from the functional changes?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- 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/20071016/5e5612c0/attachment.pgp>



More information about the ffmpeg-devel mailing list