From patchwork Tue Oct 18 12:36:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 38794 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4a86:b0:9d:28a3:170e with SMTP id fn6csp2083636pzb; Tue, 18 Oct 2022 05:40:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6rb+obiH0iFGUbx3d/MKjW4EIMPXgJED/6dzBfsSckWQE3yD7xSO6Yy5kva5RoXxS1JSla X-Received: by 2002:a17:907:b0b:b0:78d:8877:9f9e with SMTP id h11-20020a1709070b0b00b0078d88779f9emr2207804ejl.693.1666096855751; Tue, 18 Oct 2022 05:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666096855; cv=none; d=google.com; s=arc-20160816; b=OyI5AyEzVLJWoN28XkwrW+aHtY9IyYPnYXsrumP9jngTcaeg5wHUvqWqBcYtsFe+Mc FFvXZdir7fUic+wDg1t9+ZGq9DBaSLLcoDY1J04p4JPKLOP7fqQ/6rfo5NbN4D1zUv+0 2AuS2JT3AV9bANkp65t3GvRqO1O9YvU/IRI2aRmY8DND+1vuRI4OOXCwCUQULUlo65Ih iUUz7biKHcFvZpfjS9Ju6sQW9vD6EqeDV4qHfaBn9sL/3FrmKdG4NbhB7FxS6SnQwLMX HiRxElaFQCDZk9Y3qD5TVsUhaZuKnXokPdInERHOg0ralPV6kmKlMXnR8z/+UFVI5eBo aLnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=xnHUP/hr7AonnUcNcyCWEyoEukiNhboN7Pt2nb4EYNo=; b=YdrB7pdJTUO+s4QmMf0dxDT37aVIcg0kv9UtEVYl7W0fwgyV6CzIaAIP4SZx2ufasz Xv2ntQwucRhETGpCFVHdVzfxN6UoyM2P9VgLO7+442LQctkaq3Z20G3sgjw67M3dj4TS 1qterp83TWd2I6twG8gAgJEnELJZYJTvMjgi7bs/HqaH3a61lFWZwUCiIDlfZ/5UvBXe Sbn+dpCnLjiLYQw4o2Jrbp/NmJ3HHjnr3AFxoB8VLCGBEjI9Y13Ejmg1k3PR2SqAMaTi avRY/SG9Fk2oPZM1PIUoxWgvBkgLX5SAq9ilJYJ8iti6MlE/oI0f/tSddU9mIsdEpIep aGoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s15-20020a05640217cf00b00458d63dee39si10103330edy.472.2022.10.18.05.40.55; Tue, 18 Oct 2022 05:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1398368BDCC; Tue, 18 Oct 2022 15:38:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E91A468BD3C for ; Tue, 18 Oct 2022 15:38:22 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 69D592404F5 for ; Tue, 18 Oct 2022 14:38:22 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 6lQ_cE7gmTt3 for ; Tue, 18 Oct 2022 14:38:20 +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 D699E2406D0 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B5B723A1767 for ; Tue, 18 Oct 2022 14:38:13 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Oct 2022 14:36:48 +0200 Message-Id: <20221018123701.25002-7-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221018123701.25002-1-anton@khirnov.net> References: <20221018123701.25002-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/20] fftools/ffmpeg: move duration/time_base from InputFile to Demuxer 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: LuSdnpO0ZkYn They are private to the demuxer and do not need to be visible outside of it. --- fftools/ffmpeg.h | 3 --- fftools/ffmpeg_demux.c | 30 ++++++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 8c3effdb05..2f635c779d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -434,9 +434,6 @@ typedef struct InputFile { int eof_reached; /* true if eof reached */ int eagain; /* true if last read attempt returned EAGAIN */ int ist_index; /* index of first stream in input_streams */ - int64_t duration; /* actual duration of the longest stream in a file - at the moment when looping happens */ - AVRational time_base; /* time base of the duration */ int64_t input_ts_offset; int input_sync_ref; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 90868de7aa..fe1b3bd8b7 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -50,6 +50,11 @@ typedef struct Demuxer { /* number of times input stream should be looped */ int loop; + /* actual duration of the longest stream in a file at the moment when + * looping happens */ + int64_t duration; + /* time base of the duration */ + AVRational time_base; AVThreadMessageQueue *in_thread_queue; int thread_queue_size; @@ -84,7 +89,7 @@ static void report_new_stream(InputFile *file, const AVPacket *pkt) file->nb_streams_warn = pkt->stream_index + 1; } -static void ifile_duration_update(InputFile *f, InputStream *ist, +static void ifile_duration_update(Demuxer *d, InputStream *ist, int64_t last_duration) { /* the total duration of the stream, max_pts - min_pts is @@ -93,11 +98,11 @@ static void ifile_duration_update(InputFile *f, InputStream *ist, ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration) last_duration += ist->max_pts - ist->min_pts; - if (!f->duration || - av_compare_ts(f->duration, f->time_base, + if (!d->duration || + av_compare_ts(d->duration, d->time_base, last_duration, ist->st->time_base) < 0) { - f->duration = last_duration; - f->time_base = ist->st->time_base; + d->duration = last_duration; + d->time_base = ist->st->time_base; } } @@ -126,7 +131,7 @@ static int seek_to_start(Demuxer *d) got_durations++; ist = input_streams[ifile->ist_index + dur.stream_idx]; - ifile_duration_update(ifile, ist, dur.duration); + ifile_duration_update(d, ist, dur.duration); } } else { for (int i = 0; i < ifile->nb_streams; i++) { @@ -141,7 +146,7 @@ static int seek_to_start(Demuxer *d) duration = 1; } - ifile_duration_update(ifile, ist, duration); + ifile_duration_update(d, ist, duration); } } @@ -151,8 +156,9 @@ static int seek_to_start(Demuxer *d) return ret; } -static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) +static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict) { + InputFile *ifile = &d->f; InputStream *ist = input_streams[ifile->ist_index + pkt->stream_index]; const int64_t start_time = ifile->ctx->start_time; int64_t duration; @@ -195,7 +201,7 @@ static void ts_fixup(InputFile *ifile, AVPacket *pkt, int *repeat_pict) if (pkt->dts != AV_NOPTS_VALUE) pkt->dts *= ist->ts_scale; - duration = av_rescale_q(ifile->duration, ifile->time_base, ist->st->time_base); + duration = av_rescale_q(d->duration, d->time_base, ist->st->time_base); if (pkt->pts != AV_NOPTS_VALUE) { pkt->pts += duration; ist->max_pts = FFMAX(pkt->pts, ist->max_pts); @@ -274,7 +280,7 @@ static void *input_thread(void *arg) } } - ts_fixup(f, pkt, &msg.repeat_pict); + ts_fixup(d, pkt, &msg.repeat_pict); msg.pkt = av_packet_alloc(); if (!msg.pkt) { @@ -960,8 +966,8 @@ int ifile_open(OptionsContext *o, const char *filename) f->rate_emu = o->rate_emu; f->accurate_seek = o->accurate_seek; d->loop = o->loop; - f->duration = 0; - f->time_base = (AVRational){ 1, 1 }; + d->duration = 0; + d->time_base = (AVRational){ 1, 1 }; f->readrate = o->readrate ? o->readrate : 0.0; if (f->readrate < 0.0f) {