From patchwork Sat Mar 25 19:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7a30:b0:df:834d:2c1a with SMTP id t48csp226172pzh; Sat, 25 Mar 2023 12:18:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YFDYXF64Jcmr/Rn67quSO3KOXbXwhZVTI46qeib+KwDw/b48zj+iQcWptt5IGfHFUL/+pd X-Received: by 2002:a17:906:7193:b0:931:7adf:547e with SMTP id h19-20020a170906719300b009317adf547emr7523016ejk.70.1679771897578; Sat, 25 Mar 2023 12:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679771897; cv=none; d=google.com; s=arc-20160816; b=dznk/ULuV7PRhZyp495GKpZqj0zyUvoeKqbKukj9eG44c2OP2+RMmRxldv7EXNlqtp fjbeKM7W23PEMcIl3sDUz3Dinrtp4PVZ4HcaFePge+hgr48EO1X7YIxtXXuHJ1kbGzx0 SVni0YUMGomp4bcCYPDMXwCpllpJqEWJ1MZmBVL4qrlj4A788nh7ZX5pau2PO9eRqtCV kRZ5HB7FOAtC+MtcerfieTMz0yWXmQtBQuwA6sdb5znW45S+HXEyUKujGwo4eUM98aoi 8W8sH/luJU+lxCsncBj9mhK5Uu7MpxIUxlGaDBt3WAfCGXLaGkmEZT50lJPV/dHh0ePL uxgQ== 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=2+hvJxsfAlX23/X+u5eLQrrft6H9KuFPbzsfTBM41zM=; b=j83Il2sSBjJnfJeeHWUchY3l+C7ejFYxhuyY7jsrF5JneJzt/GPPYqSdQ3nEpJLwec dIwI8rAaAyJ7E5Fwhtg8pqB7lSCXoTI+sFHZL9Qw3LhFmIgTadDoxfmpWuBkwWA5UnJ9 jsjnULv7wm3VzliBvVriBcCYShvJk1NEXoQwlX2XwN8kxiW/AKqlZaV8az9rZnLS4M/g nVl6m8ALoqaNiTfS3GI0jsLQZiJ4W2ubTL0APQuUE7gQwhF84NUw3V0T00oFJ5Pb/o/w uHKX6+uztTq1VZn55tWPOdi4D0NqYxN5+XqTBc9pRbP8prjgMU4yMQA6k2LRnQC/uQTI wtmg== 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 t18-20020a17090616d200b0093149d8926csi21927716ejd.335.2023.03.25.12.18.17; Sat, 25 Mar 2023 12:18:17 -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 689DB68CA1A; Sat, 25 Mar 2023 21:16:23 +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 900F068C9AB for ; Sat, 25 Mar 2023 21:16:07 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 53C702404EA 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 rITrd0o57OHk 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 E84C3240591 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 928A53A0567 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:12 +0100 Message-Id: <20230325191529.10578-6-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 06/23] fftools/sync_queue: make sure audio duration matches sample count 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: 9HqsboN2FIPY For audio AVFrames, nb_samples is typically more trustworthy than duration. Since sync queues look at durations, make sure they match the sample count. The last audio frame in the fate-shortest test is now gone. This is more correct, since it outlasts the last video frame. --- fftools/sync_queue.c | 15 ++++++++++++++- tests/ref/fate/shortest | 1 - 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c index 4204a821c1..5b98253a4a 100644 --- a/fftools/sync_queue.c +++ b/fftools/sync_queue.c @@ -116,6 +116,11 @@ static int64_t frame_ts(const SyncQueue *sq, SyncQueueFrame frame) frame.f->pts + frame.f->duration; } +static int frame_samples(const SyncQueue *sq, SyncQueueFrame frame) +{ + return (sq->type == SYNC_QUEUE_PACKETS) ? 0 : frame.f->nb_samples; +} + static int frame_null(const SyncQueue *sq, SyncQueueFrame frame) { return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL); @@ -293,7 +298,7 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) SyncQueueStream *st; SyncQueueFrame dst; int64_t ts; - int ret; + int ret, nb_samples; av_assert0(stream_idx < sq->nb_streams); st = &sq->streams[stream_idx]; @@ -313,6 +318,14 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame) frame_move(sq, dst, frame); + nb_samples = frame_samples(sq, dst); + // make sure frame duration is consistent with sample count + if (nb_samples) { + av_assert0(dst.f->sample_rate > 0); + dst.f->duration = av_rescale_q(nb_samples, (AVRational){ 1, dst.f->sample_rate }, + dst.f->time_base); + } + ts = frame_ts(sq, dst); ret = av_fifo_write(st->fifo, &dst, 1); diff --git a/tests/ref/fate/shortest b/tests/ref/fate/shortest index be93ff0da1..b5845508cf 100644 --- a/tests/ref/fate/shortest +++ b/tests/ref/fate/shortest @@ -115,4 +115,3 @@ 0, 48, 48, 1, 11212, 0xc61a3f0a, S=1, 8 1, 85760, 85760, 1536, 418, 0xae06ca91 0, 49, 49, 1, 1423, 0x45fba9e4, F=0x0, S=1, 8 -1, 87296, 87296, 1536, 418, 0x7bdcc3c7