From patchwork Sat Feb 11 07:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40367 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:5494:b0:bf:7b3a:fd32 with SMTP id i20csp1975212pzk; Fri, 10 Feb 2023 23:45:03 -0800 (PST) X-Google-Smtp-Source: AK7set9q9/ovI70+OtCGlPzCgYNU66az1B4SMWyQxuN2Bwnz4mAH4bcOAguFhMy1GOEtZ8MnFSxs X-Received: by 2002:a17:906:da1b:b0:86d:7c2d:f65b with SMTP id fi27-20020a170906da1b00b0086d7c2df65bmr19443452ejb.27.1676101503618; Fri, 10 Feb 2023 23:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676101503; cv=none; d=google.com; s=arc-20160816; b=GycjO4JfNS7NhI+2yGzovffA6Pmk2ptxxYERrjxrCPX3b56HQ0kBkAeAnhDKfkqIAl o1zMe+LqsF7nAgBp6J4D4jSD85x3GWJoDmFsEBnH3bN6QlxApiPl+7lsRcqPJzfKSDAH B1ckqYkER0FW0i7jesyGdlQR5WLJwtyG5KrTHTZnw3LylgXEB7fQfvrbqT8tSrd5aQlt bzmp6LltgiUxTYnji/FVFxOfACBb22UToQFtLFgVAHKfttz9LdX6v+fTPz/60aOGM0sR JFkrC90JeFp1lLKdLfOLvv4Stkuwzy5Yt1q6njI++pcKTxC1Bstno/5kRxMor6VoGEHf 5BXA== 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=ZUFZ22Lzfq5K3wDfm6blW47OK9HCHdax0gpwAT2vWBw=; b=h6RZDp3UTMQholw9m7tmpFCplKpivCYmWPt/p1IOF5FUONS5gIwJuOjuHX2oF7zbph rxGR69b8kBMGplnETuNbyXHtc2HbnWUl7LoRtmyfsQGEE21hyp72Nv7b+fKe51mbig9A tO8h3B7nvoezb7hgiS3sUkXGOWcBO2IyNqfxwfkFpsxIclcmQo0xQsH9UHnMA7RKsd3/ sw1H0wPgx6wNo79buu8b2ZqwWGSBFuev0d3omaO5E8kNUyUPLs7bjcBWSYCLrev9dDhz W8xUXOR4TYUjHiRCyc67PZp8n2c40kP06SuVB07gUYoNGe/a/7WVXB/bvlG2/OQZmKFT 677g== 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 u23-20020a170906109700b0087bda7465bcsi8953493eju.844.2023.02.10.23.45.03; Fri, 10 Feb 2023 23:45:03 -0800 (PST) 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 2352968B611; Sat, 11 Feb 2023 09:44:36 +0200 (EET) 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 F046F68BD5F for ; Sat, 11 Feb 2023 09:44:27 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id AB04D2404EC for ; Sat, 11 Feb 2023 08:44:27 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id vBG0jsMMoKtB for ; Sat, 11 Feb 2023 08:44:26 +0100 (CET) Received: from libav.khirnov.net (unknown [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 E5454240591 for ; Sat, 11 Feb 2023 08:44:24 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9846A3A02ED for ; Sat, 11 Feb 2023 08:44:16 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Feb 2023 08:44:09 +0100 Message-Id: <20230211074412.29495-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230211074412.29495-1-anton@khirnov.net> References: <20230211074412.29495-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] fftools/ffmpeg_demux: add InputStream private data 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: yfbTULpSXrAL Move {min,max}_pts to it, which is not used outside of ffmpeg_demux. --- fftools/ffmpeg.h | 3 -- fftools/ffmpeg_demux.c | 63 ++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c657f55911..2d48a147b8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -377,9 +377,6 @@ typedef struct InputStream { int64_t filter_in_rescale_delta_last; - int64_t min_pts; /* pts with the smallest value in a current stream */ - int64_t max_pts; /* pts with the higher value in a current stream */ - // when forcing constant input framerate through -r, // this contains the pts that will be given to the next decoded frame int64_t cfr_next_pts; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 9f5d8fec24..b6b6b21271 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -52,6 +52,13 @@ static const char *const opt_name_display_rotations[] = {"display_rotati static const char *const opt_name_display_hflips[] = {"display_hflip", NULL}; static const char *const opt_name_display_vflips[] = {"display_vflip", NULL}; +typedef struct DemuxStream { + InputStream ist; + + int64_t min_pts; /* pts with the smallest value in a current stream */ + int64_t max_pts; /* pts with the higher value in a current stream */ +} DemuxStream; + typedef struct Demuxer { InputFile f; @@ -83,6 +90,11 @@ typedef struct DemuxMsg { int repeat_pict; } DemuxMsg; +static DemuxStream *ds_from_ist(InputStream *ist) +{ + return (DemuxStream*)ist; +} + static Demuxer *demuxer_from_ifile(InputFile *f) { return (Demuxer*)f; @@ -101,20 +113,20 @@ static void report_new_stream(Demuxer *d, const AVPacket *pkt) d->nb_streams_warn = pkt->stream_index + 1; } -static void ifile_duration_update(Demuxer *d, InputStream *ist, +static void ifile_duration_update(Demuxer *d, DemuxStream *ds, int64_t last_duration) { /* the total duration of the stream, max_pts - min_pts is * the duration of the stream without the last frame */ - if (ist->max_pts > ist->min_pts && - ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - last_duration) - last_duration += ist->max_pts - ist->min_pts; + if (ds->max_pts > ds->min_pts && + ds->max_pts - (uint64_t)ds->min_pts < INT64_MAX - last_duration) + last_duration += ds->max_pts - ds->min_pts; if (!d->duration || av_compare_ts(d->duration, d->time_base, - last_duration, ist->st->time_base) < 0) { + last_duration, ds->ist.st->time_base) < 0) { d->duration = last_duration; - d->time_base = ist->st->time_base; + d->time_base = ds->ist.st->time_base; } } @@ -122,7 +134,6 @@ static int seek_to_start(Demuxer *d) { InputFile *ifile = &d->f; AVFormatContext *is = ifile->ctx; - InputStream *ist; int ret; ret = avformat_seek_file(is, -1, INT64_MIN, is->start_time, is->start_time, 0); @@ -136,19 +147,21 @@ static int seek_to_start(Demuxer *d) int got_durations = 0; while (got_durations < ifile->audio_duration_queue_size) { + DemuxStream *ds; LastFrameDuration dur; ret = av_thread_message_queue_recv(ifile->audio_duration_queue, &dur, 0); if (ret < 0) return ret; got_durations++; - ist = ifile->streams[dur.stream_idx]; - ifile_duration_update(d, ist, dur.duration); + ds = ds_from_ist(ifile->streams[dur.stream_idx]); + ifile_duration_update(d, ds, dur.duration); } } else { for (int i = 0; i < ifile->nb_streams; i++) { int64_t duration = 0; - ist = ifile->streams[i]; + InputStream *ist = ifile->streams[i]; + DemuxStream *ds = ds_from_ist(ist); if (ist->framerate.num) { duration = av_rescale_q(1, av_inv_q(ist->framerate), ist->st->time_base); @@ -158,7 +171,7 @@ static int seek_to_start(Demuxer *d) duration = 1; } - ifile_duration_update(d, ist, duration); + ifile_duration_update(d, ds, duration); } } @@ -172,6 +185,7 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict) { InputFile *ifile = &d->f; InputStream *ist = ifile->streams[pkt->stream_index]; + DemuxStream *ds = ds_from_ist(ist); const int64_t start_time = ifile->start_time_effective; int64_t duration; @@ -216,8 +230,8 @@ static void ts_fixup(Demuxer *d, AVPacket *pkt, int *repeat_pict) 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); - ist->min_pts = FFMIN(pkt->pts, ist->min_pts); + ds->max_pts = FFMAX(pkt->pts, ds->max_pts); + ds->min_pts = FFMIN(pkt->pts, ds->min_pts); } if (pkt->dts != AV_NOPTS_VALUE) @@ -590,6 +604,18 @@ static void add_display_matrix_to_stream(const OptionsContext *o, vflip_set ? vflip : 0); } +static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st) +{ + InputFile *f = &d->f; + DemuxStream *ds = allocate_array_elem(&f->streams, sizeof(*ds), + &f->nb_streams); + + ds->ist.st = st; + ds->ist.file_index = f->index; + + return ds; +} + /* Add all the streams from the given input file to the demuxer */ static void add_input_streams(const OptionsContext *o, Demuxer *d) { @@ -600,6 +626,7 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) for (i = 0; i < ic->nb_streams; i++) { AVStream *st = ic->streams[i]; AVCodecParameters *par = st->codecpar; + DemuxStream *ds; InputStream *ist; char *framerate = NULL, *hwaccel_device = NULL; const char *hwaccel = NULL; @@ -611,15 +638,15 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ); - ist = ALLOC_ARRAY_ELEM(f->streams, f->nb_streams); - ist->st = st; - ist->file_index = f->index; + ds = demux_stream_alloc(d, st); + ist = &ds->ist; + ist->discard = 1; st->discard = AVDISCARD_ALL; ist->nb_samples = 0; ist->first_dts = AV_NOPTS_VALUE; - ist->min_pts = INT64_MAX; - ist->max_pts = INT64_MIN; + ds->min_pts = INT64_MAX; + ds->max_pts = INT64_MIN; ist->ts_scale = 1.0; MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);