From patchwork Tue Jan 11 20:46:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33264 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4050569iog; Tue, 11 Jan 2022 12:52:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvM8LmIvYFO2ixtd3MytPI44Asd4VRviehCvoeqIJq2v/4YfqAU6JOWY3uqDoVXzV1Xen8 X-Received: by 2002:a17:907:8a04:: with SMTP id sc4mr4961848ejc.392.1641934362534; Tue, 11 Jan 2022 12:52:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934362; cv=none; d=google.com; s=arc-20160816; b=QgbQLTacRPgK560Jl7jA60EocFfykDvtC5cgAb+FBh2tDJHiJTBneZhKmEzjc+M+hf L8kSFhYKuLxU0/8uvr+R4i4JJIoSq99tpPGUU7YLxLTT5YN5hNrn0bd3qqrTdoqeNwRx Sl5h+5JmGKCxaDhXcJxkOawgJgzQ7g4v8GOY5eGF7gfoVlLu9G2jSK7Np0SfrpdGyXKB l6VWqKOH72cO2OJmIRLmjLARW48vtMRYkhspY2OYETAUX59y0SoaM+1C4oSz266PQVNb sRl1UOqv2tPnAk0K1tNUu6WH/dQL0Me9fSfpceZ0A6Ar1YhB6sDjFws6IyjAtkJzld93 ztJg== 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=aqGeV573mS6AnxzkseysO0DW3T9Pux1L3h+go5MEhZE=; b=q1Er/QWBMpBTZ/onRZ9XMrywPL6b6roy5v1V1Fxc1unmNu3caShljIMXKh+thRGPGZ OF83iCS6mYBZm4XP9Tm1IGWtyXkrrjMtc9XaUtNw/YCHhiHecAuWoPQ512cd7OLlr2QT N/j2BRyoRmE4HyW6ZrOk0QG5IkiYOIofIqnXfew+/g0caO+DgF+HQIYDKIrAV+m36rrM hfnhg0v9/87OTxaRFOBZanTZkNFbec8wQzyDmODwC0DAydHDv9lY4/dH6WrzW6jtSDvl 0kuGIoWOOki3QipZN9QAx6ONYyTSPsGZProt4HiwTn4iwjlwqutdPAEo8mjToOH0R48r S0OQ== 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 jg39si2759580ejc.437.2022.01.11.12.52.42; Tue, 11 Jan 2022 12:52:42 -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 8571A68AF54; Tue, 11 Jan 2022 22:48:02 +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 3428468AF3A for ; Tue, 11 Jan 2022 22:47:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A09CC24017C for ; Tue, 11 Jan 2022 21:47:40 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id g4XNMMwSQvMV for ; Tue, 11 Jan 2022 21:47:38 +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 8770624017E for ; Tue, 11 Jan 2022 21:47:26 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 641B43A0E05; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:46:05 +0100 Message-Id: <20220111204610.14262-30-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 30/35] lavu/audio_fifo: switch to new FIFO API 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: 5Z2MV6Afe++1 --- libavutil/audio_fifo.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/libavutil/audio_fifo.c b/libavutil/audio_fifo.c index 243efc39e4..1ab0c9bcdc 100644 --- a/libavutil/audio_fifo.c +++ b/libavutil/audio_fifo.c @@ -80,7 +80,7 @@ AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, goto error; for (i = 0; i < af->nb_buffers; i++) { - af->buf[i] = av_fifo_alloc(buf_size); + af->buf[i] = av_fifo_alloc2(buf_size, 1, 0); if (!af->buf[i]) goto error; } @@ -95,15 +95,19 @@ error: int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples) { + const size_t cur_size = av_fifo_can_read (af->buf[0]) + + av_fifo_can_write(af->buf[0]); int i, ret, buf_size; if ((ret = av_samples_get_buffer_size(&buf_size, af->channels, nb_samples, af->sample_fmt, 1)) < 0) return ret; - for (i = 0; i < af->nb_buffers; i++) { - if ((ret = av_fifo_realloc2(af->buf[i], buf_size)) < 0) - return ret; + if (buf_size > cur_size) { + for (i = 0; i < af->nb_buffers; i++) { + if ((ret = av_fifo_grow2(af->buf[i], buf_size - cur_size)) < 0) + return ret; + } } af->allocated_samples = nb_samples; return 0; @@ -126,8 +130,8 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples) size = nb_samples * af->sample_size; for (i = 0; i < af->nb_buffers; i++) { - ret = av_fifo_generic_write(af->buf[i], data[i], size, NULL); - if (ret != size) + ret = av_fifo_write(af->buf[i], data[i], size); + if (ret < 0) return AVERROR_BUG; } af->nb_samples += nb_samples; @@ -137,21 +141,7 @@ int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples) int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples) { - int i, ret, size; - - if (nb_samples < 0) - return AVERROR(EINVAL); - nb_samples = FFMIN(nb_samples, af->nb_samples); - if (!nb_samples) - return 0; - - size = nb_samples * af->sample_size; - for (i = 0; i < af->nb_buffers; i++) { - if ((ret = av_fifo_generic_peek(af->buf[i], data[i], size, NULL)) < 0) - return AVERROR_BUG; - } - - return nb_samples; + return av_audio_fifo_peek_at(af, data, nb_samples, 0); } int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offset) @@ -171,7 +161,7 @@ int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offs offset *= af->sample_size; size = nb_samples * af->sample_size; for (i = 0; i < af->nb_buffers; i++) { - if ((ret = av_fifo_generic_peek_at(af->buf[i], data[i], offset, size, NULL)) < 0) + if ((ret = av_fifo_peek(af->buf[i], data[i], size, offset)) < 0) return AVERROR_BUG; } @@ -190,7 +180,7 @@ int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples) size = nb_samples * af->sample_size; for (i = 0; i < af->nb_buffers; i++) { - if (av_fifo_generic_read(af->buf[i], data[i], size, NULL) < 0) + if (av_fifo_read(af->buf[i], data[i], size) < 0) return AVERROR_BUG; } af->nb_samples -= nb_samples; @@ -209,7 +199,7 @@ int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples) if (nb_samples) { size = nb_samples * af->sample_size; for (i = 0; i < af->nb_buffers; i++) - av_fifo_drain(af->buf[i], size); + av_fifo_drain2(af->buf[i], size); af->nb_samples -= nb_samples; } return 0;