From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id DFFBD422EE for ; Sat, 30 Jul 2022 17:15:40 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 994F268BA4E; Sat, 30 Jul 2022 20:15:37 +0300 (EEST) Received: from out203-205-251-73.mail.qq.com (out203-205-251-73.mail.qq.com [203.205.251.73]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F213768B8B3 for ; Sat, 30 Jul 2022 20:15:29 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1659201326; bh=cfhbwayJFohz7oRiBPpyv7GtzJHPWipdt5M+4+M2dzk=; h=From:To:Cc:Subject:Date; b=Yuf1AbP+3vP7ed4w+tK51v9VuIlpxM8XVy8wzBO6OsL5ljupTurO/lQDFXzvKDc0x TUJyO2Zjoa/nz36RoMKPYJldkOF8CEfX09d4f9Pw0kavfLir25ds2RYc0Jr1dYVpLa hAFKVuugd+y3m5jpRB9BhY6BrRztQoNL1m5G9AtA= Received: from black.localdomain ([113.116.29.125]) by newxmesmtplogicsvrszc10.qq.com (NewEsmtp) with SMTP id 39003A85; Sun, 31 Jul 2022 01:14:16 +0800 X-QQ-mid: xmsmtpt1659201256t4f7iwmoj Message-ID: X-QQ-XMAILINFO: MmpliBmRb3iC44Bl089Sd+3W1nH6BkMOMpiER+ifCIcUiPMdFJAMLysOLqvwQ1 wRI1wipD0tmvfVYJET8KhdjlDorl0cFUMk1xMor+TNzFcrNlDAtYWYIf1cWsxTvjbq3Gj7C0taxx YBdP/KPiZ4va7YxWRywhlAFKLUhj/DJ8sNirew12b8MiRiFdnBNfbEH3A0VJldOk7BMWIqGbnj6h CMPlg06ZAIlM4ik936QDJgZcmM2nzjNa+NF/ulmOqdaheesNJxUGhR2u0XsCfi+cyrOWkfTE5WZZ HxMX5pk+X5DVjs1bfRjPM6a8Hz9Q5XnUOaIoeSfcjRlBwZ2u0HVHpVI2yyFhwqybV1aGgSe93nV4 dxoMglvfKRM6uwZDwqMZa3MkmPCyPGAnDmWhOqDeQuwbonitZaQIqqKuz6gpar/2E8b2oulYNk1M a0IN1mFir9671X2y8NJVZM2ARooLZo3wpOCyQkUIlzgNuNMKbCpXyLY1GlyZ834Osoqmo2ol+Xd7 UqFIKpcCX202dcG9EH4k3Ni2BLGQuq27dp416RCyf2Y4uCXOHMEXBPruQ/Z/BWX7mMdAd9R3SeNJ iV/X5+/hKORah4VJjk8ru6a7KI+MBdI5dkNEPNUTyHOmMY+6bIWv4AXfqWlfWzbpVe/TIEmn641U MIeZKGTDUUERfQCI6dfwJXsqfy7y86b6/FGXp+3RFds5sHD0PSNLocTy3SmmKohozlIQqM6TixGb RMKkNkwVhG+cwmBPnXmcucpZcgQGWzlYSBDxDQ19PCox0wjBrmJCVmjTBr1fUslZHk5yqJrseoo2 gsEhQ3PQ5FB+G2yPTuxo1jOWN6/cMkNqJVFfAYHbpnGxk1jw29OYeZzf2tTJdNhWrEu96pPdCk+f Rs+XPNEXhg+LJCBx04YBgdHc1S8iH1WuWyTdeXcjlEF5rv0W0NScLG42fXMD7Y81Qo9JhVzvsoDg dYg3/II+lhGH5qHQiFFpjHGNtflOEI From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jul 2022 01:14:11 +0800 X-OQ-MSGID: <20220730171412.600-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avformat/mov: fix frag_index.current out of sync X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Zhao Zhili frag_index.current is used by cenc_filter, and is updated inside mov_read_moof. It can out of sync regarding to mov_read_packet. Partly fix ticket #9807. --- libavformat/mov.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index a09a762d91..ce12a9e4f1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7095,6 +7095,31 @@ static int cenc_decrypt(MOVContext *c, MOVStreamContext *sc, AVEncryptionInfo *s } } +static MOVFragmentStreamInfo *get_frag_stream_info_from_pkt(MOVFragmentIndex *frag_index, AVPacket *pkt, int id) +{ + int current = frag_index->current; + + if (!frag_index->nb_items) + return NULL; + + // Check frag_index->current is the right one for pkt. It can out of sync. + if (current >= 0 && current < frag_index->nb_items) { + if (frag_index->item[current].moof_offset < pkt->pos && + (current + 1 == frag_index->nb_items || + frag_index->item[current + 1].moof_offset > pkt->pos)) + return get_frag_stream_info(frag_index, current, id); + } + + + for (int i = 0; i < frag_index->nb_items; i++) { + if (frag_index->item[i].moof_offset > pkt->pos) + break; + current = i; + } + frag_index->current = current; + return get_frag_stream_info(frag_index, current, id); +} + static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPacket *pkt, int current_index) { MOVFragmentStreamInfo *frag_stream_info; @@ -7102,7 +7127,7 @@ static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPa AVEncryptionInfo *encrypted_sample; int encrypted_index, ret; - frag_stream_info = get_frag_stream_info(&mov->frag_index, mov->frag_index.current, st->id); + frag_stream_info = get_frag_stream_info_from_pkt(&mov->frag_index, pkt, st->id); encrypted_index = current_index; encryption_index = NULL; if (frag_stream_info) { -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".