From patchwork Sat Mar 25 19:15: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: 40823 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp225541pzh; Sat, 25 Mar 2023 12:16:48 -0700 (PDT) X-Google-Smtp-Source: AKy350bAY/B2FS7e84Es8A9bS0jnQTlW/3jObleMlcz6kS4wcPaLYV8WTbQGW1vIcB0dSx6/CA0s X-Received: by 2002:a17:906:4ed4:b0:878:61d8:d7c2 with SMTP id i20-20020a1709064ed400b0087861d8d7c2mr7446975ejv.39.1679771808728; Sat, 25 Mar 2023 12:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679771808; cv=none; d=google.com; s=arc-20160816; b=bwpDdepPGXuIAgKa5tTJRjq/VbhbFpD1Hy/qIvInpEiN6J/bbdTVMGCaeV8PHrLyyA rICTj3peEyPyiEwKcbovqlhdPob4thhl30aRylRBAt4kRMSnowvih1iMEvKho1UUSm3H gLtqWK/Jnpfp9n6jxfr3xQbh1b7IjRawCsZVIJu6pqAGxLwUvVcOUEudcYYxII0MSKAI DFmJ/QYUhqdYyUeot7/4DOaSHum0Q8k6X5FiRZ4Kbq9YgJ1nkcQRzmDZt5vzDw7mUptP T+6m2ymW6+SIuBRC/f1daoYFFQpaNz0skbPwu++ODtrDgi3e2IHkvyFS3BIeYNla/E4H U5+w== 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=fiQrI/UMlyUH+C2ApHN3APuoNbEODjnrszYeeCbq8n4=; b=jpfj3al2jLEiNMKZX6b5kmlWYhk+oVV4dN9l3I7ccDydW8S1fPUtBHdbQ1ny1qUTbR AuSWvGIq/qFmENitSs7Ej7HK0YYU/MxXvFyT8EN/mlOUC1Eb3dib08vUnDF58m6iaoNv vvB6BY4pTfhL0+V6lF4n97KVIt29Z2/TTWOoNE5w7CGvDzwIDydGeqlnoMm9T+zQVL5t QOkqnkRgT4E5DflLZrMaSg0mKelPgyOEJ74T5eJ06yPWI45jhiv/NFeIAfmlQda4uehY t2gjvBj71KR2wY5hQd2oyQdmAiqEz+ia6JDXQAB/Qy1y1XPhGTS04Jeq4lYWZcdRlurX 7IRA== 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 h22-20020a1709062dd600b0092800a29047si21856786eji.253.2023.03.25.12.16.48; Sat, 25 Mar 2023 12:16:48 -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 5C7C768C9B4; Sat, 25 Mar 2023 21:16:13 +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 72C6068C810 for ; Sat, 25 Mar 2023 21:16:03 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 282AB2404F5 for ; Sat, 25 Mar 2023 20:16:03 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id N5NwJgCIfoM1 for ; Sat, 25 Mar 2023 20:16:02 +0100 (CET) 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 D80112404EA for ; Sat, 25 Mar 2023 20:16:00 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 717433A03E5 for ; Sat, 25 Mar 2023 20:15:54 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Mar 2023 20:15:09 +0100 Message-Id: <20230325191529.10578-3-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230325191529.10578-1-anton@khirnov.net> References: <20230325191529.10578-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/23] fftools/sync_queue: use timebase from input frames/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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: shc0sk/T3M/v They are always properly set now. Avoid a separate timebase-setting call, which duplicates the knowledge of the timebase being used. --- fftools/ffmpeg.c | 3 --- fftools/ffmpeg_mux.c | 3 --- fftools/sync_queue.c | 39 ++++++++++++++++++++++----------------- fftools/sync_queue.h | 6 ------ 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index abda713ddb..3a205a3b01 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3194,9 +3194,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) if (ost->bitexact) enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT; - if (ost->sq_idx_encode >= 0) - sq_set_tb(of->sq_encode, ost->sq_idx_encode, enc_ctx->time_base); - ost->mux_timebase = enc_ctx->time_base; return 0; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index cf58051949..1937bc2aa7 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -586,9 +586,6 @@ int of_stream_init(OutputFile *of, OutputStream *ost) MuxStream *ms = ms_from_ost(ost); int ret; - if (ost->sq_idx_mux >= 0) - sq_set_tb(mux->sq_mux, ost->sq_idx_mux, ost->mux_timebase); - /* initialize bitstream filters for the output stream * needs to be done here, because the codec id for streamcopy is not * known until now */ diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c index c2b23ee4f5..7c348af300 100644 --- a/fftools/sync_queue.c +++ b/fftools/sync_queue.c @@ -84,6 +84,26 @@ static int frame_null(const SyncQueue *sq, SyncQueueFrame frame) return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL); } +static void tb_update(const SyncQueue *sq, SyncQueueStream *st, + const SyncQueueFrame frame) +{ + AVRational tb = (sq->type == SYNC_QUEUE_PACKETS) ? + frame.p->time_base : frame.f->time_base; + + av_assert0(tb.num > 0 && tb.den > 0); + + if (tb.num == st->tb.num && tb.den == st->tb.den) + return; + + // timebase should not change after the first frame + av_assert0(!av_fifo_can_read(st->fifo)); + + if (st->head_ts != AV_NOPTS_VALUE) + st->head_ts = av_rescale_q(st->head_ts, st->tb, tb); + + st->tb = tb; +} + static void finish_stream(SyncQueue *sq, unsigned int stream_idx) { SyncQueueStream *st = &sq->streams[stream_idx]; @@ -241,8 +261,6 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) av_assert0(stream_idx < sq->nb_streams); st = &sq->streams[stream_idx]; - av_assert0(st->tb.num > 0 && st->tb.den > 0); - if (frame_null(sq, frame)) { finish_stream(sq, stream_idx); return 0; @@ -250,6 +268,8 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) if (st->finished) return AVERROR_EOF; + tb_update(sq, st, frame); + ret = objpool_get(sq->pool, (void**)&dst); if (ret < 0) return ret; @@ -375,21 +395,6 @@ int sq_add_stream(SyncQueue *sq, int limiting) return sq->nb_streams++; } -void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb) -{ - SyncQueueStream *st; - - av_assert0(stream_idx < sq->nb_streams); - st = &sq->streams[stream_idx]; - - av_assert0(!av_fifo_can_read(st->fifo)); - - if (st->head_ts != AV_NOPTS_VALUE) - st->head_ts = av_rescale_q(st->head_ts, st->tb, tb); - - st->tb = tb; -} - void sq_limit_frames(SyncQueue *sq, unsigned int stream_idx, uint64_t frames) { SyncQueueStream *st; diff --git a/fftools/sync_queue.h b/fftools/sync_queue.h index 3f823ff0d9..17d282c38c 100644 --- a/fftools/sync_queue.h +++ b/fftools/sync_queue.h @@ -59,12 +59,6 @@ void sq_free(SyncQueue **sq); */ int sq_add_stream(SyncQueue *sq, int limiting); -/** - * Set the timebase for the stream with index stream_idx. Should be called - * before sending any frames for this stream. - */ -void sq_set_tb(SyncQueue *sq, unsigned int stream_idx, AVRational tb); - /** * Limit the number of output frames for stream with index stream_idx * to max_frames.