From patchwork Thu Jan 24 20:38:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 11862 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7984844D2A8 for ; Thu, 24 Jan 2019 22:38:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9FD1568AD94; Thu, 24 Jan 2019 22:37:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1411E68AD77 for ; Thu, 24 Jan 2019 22:37:52 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 386D0E1346; Thu, 24 Jan 2019 21:38:10 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p2z3HiajRhzB; Thu, 24 Jan 2019 21:38:09 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DBCD2E166C; Thu, 24 Jan 2019 21:38:08 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Jan 2019 21:38:00 +0100 Message-Id: <20190124203801.18484-2-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190124203801.18484-1-cus@passwd.hu> References: <20190124203801.18484-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/3] avformat/mpegts: cache PID discard values X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 --- 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; ts->current_pid = pid; afc = (packet[3] >> 4) & 3;