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 1FBE443BE3 for ; Mon, 22 Aug 2022 11:15:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BE36368B9DC; Mon, 22 Aug 2022 14:15:44 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3A38168B98D for ; Mon, 22 Aug 2022 14:15:38 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B8F5E240D0E for ; Mon, 22 Aug 2022 13:15:37 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id hhNHHKFr3ToV for ; Mon, 22 Aug 2022 13:15:36 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 88F5C240D03 for ; Mon, 22 Aug 2022 13:15:36 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 4C5B63A1E7C; Mon, 22 Aug 2022 13:15:26 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Aug 2022 12:47:59 +0200 Message-Id: <20220822104759.20314-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: stop accessing av_stream_get_parser() from the main thread 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 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: It races with the demuxing thread. Instead, send the information along with the demuxed packets. Ideally, the code should stop using the stream-internal parsing completely, but that requires considerably more effort. Fixes races, e.g. in: - fate-h264-brokensps-2580 - fate-h264-extradata-reload - fate-iv8-demux - fate-m4v-cfr - fate-m4v --- fftools/ffmpeg.c | 8 ++++++-- fftools/ffmpeg.h | 6 ++++++ fftools/ffmpeg_demux.c | 16 ++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ef7177fc33..ff74534ad0 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2452,7 +2452,9 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (pkt && pkt->duration) { duration_dts = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); } else if(ist->dec_ctx->framerate.num != 0 && ist->dec_ctx->framerate.den != 0) { - int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict+1 : ist->dec_ctx->ticks_per_frame; + int ticks = ist->last_pkt_repeat_pict >= 0 ? + ist->last_pkt_repeat_pict + 1 : + ist->dec_ctx->ticks_per_frame; duration_dts = ((int64_t)AV_TIME_BASE * ist->dec_ctx->framerate.den * ticks) / ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame; @@ -2555,7 +2557,9 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } else if (pkt->duration) { ist->next_dts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); } else if(ist->dec_ctx->framerate.num != 0) { - int ticks= av_stream_get_parser(ist->st) ? av_stream_get_parser(ist->st)->repeat_pict + 1 : ist->dec_ctx->ticks_per_frame; + int ticks = ist->last_pkt_repeat_pict >= 0 ? + ist->last_pkt_repeat_pict + 1 : + ist->dec_ctx->ticks_per_frame; ist->next_dts += ((int64_t)AV_TIME_BASE * ist->dec_ctx->framerate.den * ticks) / ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 921e579c32..27ef92654c 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -348,6 +348,12 @@ typedef struct InputStream { int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units) int wrap_correction_done; + // the value of AVCodecParserContext.repeat_pict from the AVStream parser + // for the last packet returned from ifile_get_packet() + // -1 if unknown + // FIXME: this is a hack, the avstream parser should not be used + int last_pkt_repeat_pict; + int64_t filter_in_rescale_delta_last; int64_t min_pts; /* pts with the smallest value in a current stream */ diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 6dfb5bb35b..6e89f5999a 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -32,6 +32,9 @@ typedef struct DemuxMsg { AVPacket *pkt; int looping; + + // repeat_pict from the demuxer-internal parser + int repeat_pict; } DemuxMsg; static void report_new_stream(InputFile *file, const AVPacket *pkt) @@ -114,7 +117,7 @@ static int seek_to_start(InputFile *ifile) return ret; } -static void ts_fixup(InputFile *ifile, AVPacket *pkt) +static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) { InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index]; const int64_t start_time = ifile->ctx->start_time; @@ -167,6 +170,11 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt) if (pkt->dts != AV_NOPTS_VALUE) pkt->dts += duration; + + *repeat_pict = -1; + if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + av_stream_get_parser(ist->st)) + *repeat_pict = av_stream_get_parser(ist->st)->repeat_pict; } static void *input_thread(void *arg) @@ -231,7 +239,7 @@ static void *input_thread(void *arg) } } - ts_fixup(f, pkt); + ts_fixup(f, pkt, &msg.repeat_pict); msg.pkt = av_packet_alloc(); if (!msg.pkt) { @@ -352,6 +360,7 @@ int init_input_threads(void) int ifile_get_packet(InputFile *f, AVPacket **pkt) { + InputStream *ist; DemuxMsg msg; int ret; @@ -382,6 +391,9 @@ int ifile_get_packet(InputFile *f, AVPacket **pkt) if (msg.looping) return 1; + ist = input_streams[f->ist_index + msg.pkt->stream_index]; + ist->last_pkt_repeat_pict = msg.repeat_pict; + *pkt = msg.pkt; return 0; } -- 2.35.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".