From patchwork Tue Jan 11 20:45:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33235 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4047665iog; Tue, 11 Jan 2022 12:47:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJy30kYl3H7RykHnTwf1aY8DJk01rdAkehHF7MSpaQLRTOVFsUjcBDWOeOYfGaOvzrk37Rr0 X-Received: by 2002:a05:6402:42d4:: with SMTP id i20mr6070647edc.52.1641934058165; Tue, 11 Jan 2022 12:47:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934058; cv=none; d=google.com; s=arc-20160816; b=fLJjJwaaFH7Q0JtayTU2oQW72kvLBnTOKuz13cbCIvJERKURrzN/5Itfts0oyuzgDu CLXspq5EWOs9iLpJCcpYa/XRUkqfeVp7Jjw6QiwXkDZRJgxadUJ6BD1cEDMgNtCwEXoM oSjROK5CHf4CjSYFWQBwFt8xGEIud9oELkOvlqDvCK1JmRF+eNsZgGcpdD7tSJnXZ5I1 BseirhxZFbkt5NtZvvu/0uq1rS/QOluAFcIWYJR1lvQ7R7sF1hCGrjjW4JmarVRxO0o7 NRnF1Q46EfWOFWJugHkfSMyw8JXDcc4CAGyseSk+VWYFVmqJ59JZwTLiAc/SS8sCUnZH zquw== 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=4/jla7SYRH7FijlDa/cM1iMB1E63m28enyOlgr+iaIU=; b=uhdVVngoJMZVxiMiIuDFQ88I0rINhrKZ0N+Afd1DoJbgGqRGh3Iy/HNs5WAt4fncM7 1aLnbXFtK2UZoHSzcdj9I7zYIUIlRCVlDnMrbXoY8hl/8zmpWDJ3CMNxl2d1SB+J3XM+ VnicBbFx0hg1Ysq9AvGL7TUvN3S03WmfTluY5udsc/oJ1jbZSnxPG5ySb+ucCgsxBn60 +sYMGlWihwRsIYcyEWGQArmFhDGA1yAX/WeJXRDgbmEbLZ0peG5jsNtwuVJIVon0ky3Y 3M4OymjfaNM7zXYMcCAUkOdfNbr7pjnugyYxqyPpkNiyH6+AoGCvU0LRKKCC8KgYtG8X Z8wQ== 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 y5si4379954edc.129.2022.01.11.12.47.37; Tue, 11 Jan 2022 12:47:38 -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 1225D68AB96; Tue, 11 Jan 2022 22:47:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (unknown [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1BFC68AB96 for ; Tue, 11 Jan 2022 22:47:26 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 54E7C240699 for ; Tue, 11 Jan 2022 21:47:26 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Fq5Q0K7f0ojm for ; Tue, 11 Jan 2022 21:47:25 +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 222E224017E for ; Tue, 11 Jan 2022 21:47:25 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id EC5463A0743; Tue, 11 Jan 2022 21:47:24 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:45:39 +0100 Message-Id: <20220111204610.14262-4-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> References: <20220111204610.14262-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/35] lavu/fifo: add new functions for determinining reading/writing size 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: VZ8FUDTrQA7o Consistently use size_t for sizes. The new names should also be more clear - e.g. current av_fifo_size() could be misinterpreted as meaning the allocated size. --- doc/APIchanges | 2 +- libavutil/fifo.c | 16 +++++++++++++--- libavutil/fifo.h | 10 ++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 5646cf2278..9400c5147a 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -18,7 +18,7 @@ API changes, most recent first: Add av_fifo_alloc2(), which allows setting a FIFO element size. Operations on FIFOs created with this function on these elements rather than bytes. - Add av_fifo_elem_size(). + Add av_fifo_elem_size(), av_fifo_can_read(), av_fifo_can_write(). 2022-01-xx - xxxxxxxxxx - lavu fifo.h Access to all AVFifoBuffer members is deprecated. The struct will diff --git a/libavutil/fifo.c b/libavutil/fifo.c index fc7c93470f..8cde2c20e1 100644 --- a/libavutil/fifo.c +++ b/libavutil/fifo.c @@ -126,7 +126,7 @@ size_t av_fifo_elem_size(const AVFifoBuffer *f) return fb->elem_size; } -int av_fifo_size(const AVFifoBuffer *f) +size_t av_fifo_can_read(const AVFifoBuffer *f) { const FifoBuffer *fb = (const FifoBuffer*)f; if (fb->offset_w <= fb->offset_r && !fb->is_empty) @@ -134,10 +134,20 @@ int av_fifo_size(const AVFifoBuffer *f) return fb->offset_w - fb->offset_r; } -int av_fifo_space(const AVFifoBuffer *f) +size_t av_fifo_can_write(const AVFifoBuffer *f) { const FifoBuffer *fb = (const FifoBuffer*)f; - return fb->nb_elems - av_fifo_size(f); + return fb->nb_elems - av_fifo_can_read(f); +} + +int av_fifo_size(const AVFifoBuffer *f) +{ + return av_fifo_can_read(f); +} + +int av_fifo_space(const AVFifoBuffer *f) +{ + return av_fifo_can_write(f); } int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) diff --git a/libavutil/fifo.h b/libavutil/fifo.h index 22362c0239..9e78082b3b 100644 --- a/libavutil/fifo.h +++ b/libavutil/fifo.h @@ -119,6 +119,16 @@ int av_fifo_size(const AVFifoBuffer *f); */ int av_fifo_space(const AVFifoBuffer *f); +/** + * @return number of elements available for reading from the given FIFO. + */ +size_t av_fifo_can_read(const AVFifoBuffer *f); + +/** + * @return number of elements that can be written into the given FIFO. + */ +size_t av_fifo_can_write(const AVFifoBuffer *f); + /** * Feed data at specific position from an AVFifoBuffer to a user-supplied callback. * Similar as av_fifo_gereric_read but without discarding data.