From patchwork Tue May 19 19:06:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 19777 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 456E144B4AE for ; Tue, 19 May 2020 22:07:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2C705688395; Tue, 19 May 2020 22:07:09 +0300 (EEST) 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 0548D6881A0 for ; Tue, 19 May 2020 22:07:02 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id DD0EFE3F04; Tue, 19 May 2020 21:07:01 +0200 (CEST) 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 PZlYzxXH8C_Z; Tue, 19 May 2020 21:07:00 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3E19AE3EFC; Tue, 19 May 2020 21:07:00 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 May 2020 21:06:59 +0200 Message-Id: <20200519190659.11906-1-cus@passwd.hu> X-Mailer: git-send-email 2.26.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mpegts: fix resync logic stuck in 192 bytes 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" pos47_full is not updated for every packet, and for unseekable inputs the resync logic might simply skip some 0x47 sync bytes. In order to detect these let's check for modulo instead of exact value. Also skip unrecognized sync byte distances instead of considering them as a failure of detection. It only delays the detection of the new packet size. Also note that AVIO only buffers a single packet (for UDP/mpegts, that usually means 1316 bytes), so among every ten consecutive 188-byte MPEGTS packets there will always be a seek failure, and that caused the old code to not find the 188 byte pattern across 10 consecutive packets. Signed-off-by: Marton Balint --- libavformat/mpegts.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index a065c61c40..f2b2c05d86 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -2846,12 +2846,14 @@ static void reanalyze(MpegTSContext *ts) { if (pos < 0) return; pos -= ts->pos47_full; - if (pos == TS_PACKET_SIZE) { + if (pos % TS_PACKET_SIZE == 0) { ts->size_stat[0] ++; - } else if (pos == TS_DVHS_PACKET_SIZE) { + } if (pos % TS_DVHS_PACKET_SIZE == 0) { ts->size_stat[1] ++; - } else if (pos == TS_FEC_PACKET_SIZE) { + } if (pos % TS_FEC_PACKET_SIZE == 0) { ts->size_stat[2] ++; + } else { + return; } ts->size_stat_count ++;