[FFmpeg-devel] [PATCH] avformat/mpegts.c: reduce buffering during initialization

Michael Niedermayer michael at niedermayer.cc
Wed Mar 6 02:25:10 EET 2019


On Mon, Mar 04, 2019 at 10:21:01PM -0500, andriy.gelman at gmail.com wrote:
> From: Andriy Gelman <andriy.gelman at gmail.com>
> 
> Reduces buffering during estimation of mpegts raw_packet_size
> parameter. Instead of buffering a fixed 8192 bytes, calculate
> probe scores on a smaller buffer. Increase buffer size until
> probe score is greater than minimum value.
> ---
>  libavformat/mpegts.c | 82 +++++++++++++++++++++++++++++++-------------
>  1 file changed, 59 insertions(+), 23 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index b04fd7b4f4..a7b33eae69 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -53,6 +53,10 @@
>          (prev_dividend) = (dividend);                                          \
>      } while (0)
>  
> +#define MAX_RAW_PACKET_PROBE 8192
> +#define PROBE_PACKET_STEP 512
> +#define RAW_PACKET_MIN_SCORE 10
> +
>  enum MpegTSFilterType {
>      MPEGTS_PES,
>      MPEGTS_SECTION,
> @@ -591,28 +595,64 @@ static int analyze(const uint8_t *buf, int size, int packet_size,
>      return best_score - FFMAX(stat_all - 10*best_score, 0)/10;
>  }
>  
> -/* autodetect fec presence. Must have at least 1024 bytes  */
> -static int get_packet_size(const uint8_t *buf, int size)
> +/* autodetect fec presence */
> +static int get_packet_size(AVIOContext* pb)
>  {
>      int score, fec_score, dvhs_score;
> +    int pd_packet_size = TS_PACKET_SIZE;
> +    int best_score = 0;
> +    int ret;
>  
> -    if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
> -        return AVERROR_INVALIDDATA;
> +    AVProbeData pd = { 0 };
> +    while (best_score < RAW_PACKET_MIN_SCORE &&
> +            pd.buf_size + PROBE_PACKET_STEP <= MAX_RAW_PACKET_PROBE) {

the end condition is not robust
if you have scores 100 and 101, 101 is better but the difference is too small
to stop the loop without risk that the other moght be better later

the use of AVProbeData does not seem to help this code in any way


> +
> +        /*create extra space for next packet*/
> +        uint8_t *new_buf = av_realloc(pd.buf, pd.buf_size + PROBE_PACKET_STEP);

the previous code needed no dynamic allocation. Changing that is not needed
and would e a seperate issue and require an explanation why.

overall this patch looks like it changes alot more than whats needed
to run the code with less data in an initial iteration

thx

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

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190306/fb7d207f/attachment.sig>


More information about the ffmpeg-devel mailing list