[FFmpeg-devel] [PATCH 1/1] mpegts: stop analyzing when pmt for all programs have been found

Andrey Utkin andrey.krieger.utkin at gmail.com
Sat Dec 14 13:51:51 CET 2013


2013/12/14 Joakim Plate <elupus at ecce.se>:
> This disable NOHEADER after finding PMT for all programs to

disables

> avoid find_stream_info always exhausting probe size for mpegts
>
> This is very problematically for live streams since read speed

I'd suggest "important" instead of "problematically". Although this
explanation is a bit trivial, if you like my suggestion you could make
it more concise, just saying that avformat_find_stream_info on MPEG TS
would complete faster.

> will be limited. rtsp, udp and any protocol streaming a live
> mpegts will have dramatically faster startup time.
> ---
>  libavformat/mpegts.c | 54 +++++++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 45 insertions(+), 9 deletions(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index d67c63a..51f4267 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -90,6 +90,9 @@ struct Program {
>      unsigned int id; //program id/service id
>      unsigned int nb_pids;
>      unsigned int pids[MAX_PIDS_PER_PROGRAM];
> +
> +    /** have we found pmt for this program */
> +    int pmt;

As you set it to just 0 or 1, i'd suggest name "pmt_found".

> @@ -1912,6 +1933,21 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
>                                     p, p_end - p, 0);
>              }
>          }
> +
> +        // stop find_stream_info from waiting for more streams
> +        // when all programs have received a PMT
> +        if( ts->stream->ctx_flags & AVFMTCTX_NOHEADER) {
> +            int i;
> +            for(i=0; i<ts->nb_prg; i++) {
> +                if (ts->prg[i].pmt == 0)
> +                    break;
> +            }
> +            if (ts->nb_prg > 0 && i == ts->nb_prg) {
> +                av_log(ts->stream, AV_LOG_DEBUG, "All programs have pmt, headers found\n");
> +                ts->stream->ctx_flags &= ~AVFMTCTX_NOHEADER;
> +            }
> +        }
> +

I know that major developers of FFmpeg like concise code, but i
personally would prefer explicit "found" flag variable instead of
using final value of "i" to determine result. Just my houmble opinion.


Thanks for your efforts, this enhancement is interesting. BTW, does
the modified procedure take its place _after_ the amount of data
required by "probesize" and "analyzeduration" options is fetched?

-- 
Andrey Utkin


More information about the ffmpeg-devel mailing list