[FFmpeg-devel] [PATCH 2/3] avformat/mpegts: cache PID discard values

Michael Niedermayer michael at niedermayer.cc
Fri Jan 25 10:56:48 EET 2019


On Thu, Jan 24, 2019 at 09:38:00PM +0100, Marton Balint wrote:
> discard_pid can be quite expensive, so let's cache it and recalculate it on
> every packet start.
> 
> ffmpeg -y -i samples/MPEG-VOB/sdtv/RAI.ts -c copy -map 0:v:0 -map 0:a:0 -f mpegts /dev/null
> 
> Before:
>    1685 decicycles in handle_packet,  523483 runs,    805 skips
> 
> After:
>     883 decicycles in handle_packet,  523505 runs,    783 skips
> 
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
>  libavformat/mpegts.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 300db110d4..b04fd7b4f4 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -91,6 +91,7 @@ struct MpegTSFilter {
>      int es_id;
>      int last_cc; /* last cc code (-1 if first packet) */
>      int64_t last_pcr;
> +    int discard;
>      enum MpegTSFilterType type;
>      union {
>          MpegTSPESFilter pes_filter;
> @@ -2474,8 +2475,6 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
>      int64_t pos;
>  
>      pid = AV_RB16(packet + 1) & 0x1fff;
> -    if (pid && discard_pid(ts, pid))
> -        return 0;
>      is_start = packet[1] & 0x40;
>      tss = ts->pids[pid];
>      if (ts->auto_guess && !tss && is_start) {
> @@ -2484,6 +2483,10 @@ static int handle_packet(MpegTSContext *ts, const uint8_t *packet)
>      }
>      if (!tss)
>          return 0;
> +    if (is_start)
> +        tss->discard = discard_pid(ts, pid);
> +    if (tss->discard)
> +        return 0;

this is moving the discard check over the auto_guess /add_pes_stream()
have you checked or know that this is ok ?
its not immedeatly obviouls (to me) why this would have no side effects

thx

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

It is dangerous to be right in matters on which the established authorities
are wrong. -- 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/20190125/dadba33c/attachment.sig>


More information about the ffmpeg-devel mailing list