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 B027E46141 for ; Mon, 8 May 2023 09:20:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0E1F868C1E4; Mon, 8 May 2023 12:18:23 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C2FCB68C144 for ; Mon, 8 May 2023 12:18:03 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 155952405EC for ; Mon, 8 May 2023 11:18:01 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id rRrYHKfc5cDp for ; Mon, 8 May 2023 11:18:00 +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 32E9C2404F8 for ; Mon, 8 May 2023 11:17:57 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id F08FB3A1251 for ; Mon, 8 May 2023 11:17:56 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 May 2023 11:17:21 +0200 Message-Id: <20230508091738.20813-5-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508091738.20813-1-anton@khirnov.net> References: <20230508091738.20813-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/22] fftools/ffmpeg: attach InputStream.dts to demuxed packets when needed 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: This way computing it and using it for streamcopy does not need to happen in sync. Will be useful in following commits, where updating InputStream.dts will be moved to the demuxing thread. --- fftools/ffmpeg.c | 22 ++++++++++++++++++++-- fftools/ffmpeg.h | 7 +++++++ fftools/ffmpeg_demux.c | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ca6ff780c3..2a39d767cd 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1368,6 +1368,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo { InputFile *f = input_files[ist->file_index]; const AVCodecParameters *par = ist->par; + int64_t dts_est = AV_NOPTS_VALUE; int ret = 0; int repeating = 0; int eof_reached = 0; @@ -1463,6 +1464,11 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (!pkt && !ist->decoding_needed) eof_reached = 1; + if (pkt && pkt->opaque_ref) { + DemuxPktData *pd = (DemuxPktData*)pkt->opaque_ref->data; + dts_est = pd->dts_est; + } + duration_exceeded = 0; if (f->recording_time != INT64_MAX) { int64_t start_time = 0; @@ -1470,7 +1476,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo start_time += f->start_time != AV_NOPTS_VALUE ? f->start_time : 0; start_time += start_at_zero ? 0 : f->start_time_effective; } - if (ist->dts >= f->recording_time + start_time) + if (dts_est >= f->recording_time + start_time) duration_exceeded = 1; } @@ -1484,7 +1490,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo continue; } - of_streamcopy(ost, pkt, ist->dts); + of_streamcopy(ost, pkt, dts_est); } return !eof_reached; @@ -1900,6 +1906,18 @@ static void ist_dts_update(InputStream *ist, AVPacket *pkt) } break; } + + av_assert0(!pkt->opaque_ref); + if (ist->streamcopy_needed) { + DemuxPktData *pd; + + pkt->opaque_ref = av_buffer_allocz(sizeof(*pd)); + if (!pkt->opaque_ref) + report_and_exit(AVERROR(ENOMEM)); + pd = (DemuxPktData*)pkt->opaque_ref->data; + + pd->dts_est = ist->dts; + } } /* diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b0319f0ed0..8a5d5b13c8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -95,6 +95,12 @@ typedef struct { } AudioChannelMap; #endif +typedef struct DemuxPktData { + // estimated dts in AV_TIME_BASE_Q, + // to be used when real dts is missing + int64_t dts_est; +} DemuxPktData; + typedef struct OptionsContext { OptionGroup *g; @@ -337,6 +343,7 @@ typedef struct InputStream { int discard; /* true if stream data should be discarded */ int user_set_discard; int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */ + int streamcopy_needed; #define DECODING_FOR_OST 1 #define DECODING_FOR_FILTER 2 // should attach FrameData as opaque_ref after decoding diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index b16a20a87b..eda838f84c 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -584,6 +584,7 @@ static void ist_use(InputStream *ist, int decoding_needed) ist->discard = 0; ist->st->discard = ist->user_set_discard; ist->decoding_needed |= decoding_needed; + ist->streamcopy_needed |= !decoding_needed; if (decoding_needed && !avcodec_is_open(ist->dec_ctx)) { int ret = dec_open(ist); -- 2.39.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".