avformat/mpegts: cache PID discard values

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✌️0 -map 0🅰️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@passwd.hu>
This commit is contained in:
Marton Balint 2019-01-23 01:28:26 +01:00
parent 1eb6bfbc1f
commit 56c58b99d0
1 changed files with 5 additions and 2 deletions

View File

@ -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;
ts->current_pid = pid;
afc = (packet[3] >> 4) & 3;