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 6AF6A48B7A for ; Mon, 4 Mar 2024 17:32:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8834B68D481; Mon, 4 Mar 2024 19:32:32 +0200 (EET) Received: from srv-infra-2.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4993268D444 for ; Mon, 4 Mar 2024 19:32:24 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-2.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 6CB074135F; Mon, 4 Mar 2024 17:32:23 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Mar 2024 18:32:17 +0100 Message-Id: <20240304173219.1877658-4-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240304173219.1877658-1-nicolas.gaullier@cji.paris> References: <20240304173219.1877658-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 3/5] avcodec/parser: fix fetch_timestamp in a scenario with unaligned packets 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: Nicolas Gaullier 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: Fix fetch_timestamp when the frame start is in a previous packet. Signed-off-by: Nicolas Gaullier --- libavcodec/parser.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/parser.c b/libavcodec/parser.c index 496ebbc231..3c22fdcc2f 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -102,7 +102,7 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy) s->dts = s->cur_frame_dts[i]; s->pts = s->cur_frame_pts[i]; s->pos = s->cur_frame_pos[i]; - s->offset = s->next_frame_offset - s->cur_frame_offset[i]; + s->offset = FFMAX( 0, s->next_frame_offset - s->cur_frame_offset[i]); } if (remove) s->cur_frame_offset[i] = INT64_MAX; @@ -158,11 +158,11 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, } if (s->fetch_timestamp) { - s->fetch_timestamp = 0; s->last_pts = s->pts; s->last_dts = s->dts; s->last_pos = s->pos; - ff_fetch_timestamp(s, 0, 0, 0); + ff_fetch_timestamp(s, FFMIN(s->fetch_timestamp, 0), 0, 0); + s->fetch_timestamp = 0; } /* WARNING: the returned index can be negative */ index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf, @@ -179,12 +179,13 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, /* update the file pointer */ if (*poutbuf_size) { + s->fetch_timestamp = index >= 0 || !s->frame_offset ? 1 : index; + /* fill the data for the current frame */ s->frame_offset = s->next_frame_offset; /* offset of the next frame */ s->next_frame_offset = s->cur_offset + index; - s->fetch_timestamp = 1; } else { /* Don't return a pointer to dummy_buf. */ *poutbuf = NULL; -- 2.30.2 _______________________________________________ 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".