From patchwork Tue Jan 11 20:46:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33261 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4050318iog; Tue, 11 Jan 2022 12:52:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJxw/7G9i0pop+sx/3iwRcCZI0SGdv1BRZsRvE+zTzD+aAwIW7+rSuouCxzZNulFOWqyM8AP X-Received: by 2002:a17:906:9f01:: with SMTP id fy1mr4953281ejc.475.1641934338894; Tue, 11 Jan 2022 12:52:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934338; cv=none; d=google.com; s=arc-20160816; b=lIEVhVJE1vRtxra/Ih/NS/e/S5B6HfENaNxPglM0k4ZvOSIk+MFGRHDwjHgIpkvswT kN60YcWcLlAQOaCB7r/P62K7b6BS8/zNWCFNKau3aHX9W1FBEtvxUNnoT5gSKfioV0K0 0yeuCG8JizCCLXuM0+dMkuoaOb5KX1oXaCHCy1gebuP74eGFRMuGzGlaJJKC14XBKxt9 oiR9aeXeWEnc9Q+lEc9lXtGyKWKv9JKGPw+IelGQK2LvKic8QDmJizoZiSjp+Qi/lwbL jhguA8l//6GM4/B+fICkN9ZczQ0D8hH3IsPoriWb6y/g2zC5w7EVMrjiH4StgeXltrFG 0zfQ== 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=kPBQCrtAYdhAHYegWzcmMe0/DIdNg8vgmqRKMx6MFKY=; b=KKSzR8phancSmJ6DWv7swnRagvgcauRbI2cEuGnQCJQf68m7G3wsPUvuGJR+gEEnXN N4JudJ3YRdsOm+gq/mv+ov2BGqpf/IERUvfzBRhrbvRdTMBdJR/IdH9I4CYpaUzPvLiz 2I6ZDZHTxBI7zQcfMUxzyIyjUR+unPp41DySPRFcAxF3kxdCCRUYmkaS8EsLfNkIRxP/ 7KvmMNNYi7VwzzxvXrwfbutBClmAhpeRMBItaHvO1JpehJ+gH5ltKwJta2yhlE2RUADP xj1i/WuPnguOchyRGoUH1YRiNOoXrnzHywMFbZct5NrU7nmnyW8UAdgRA3xeW0QweU1n o3mQ== 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 nd41si5591969ejc.477.2022.01.11.12.52.18; Tue, 11 Jan 2022 12:52:18 -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 7C4BD68B000; Tue, 11 Jan 2022 22:48:00 +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 1D1B868AF41 for ; Tue, 11 Jan 2022 22:47:39 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 8915B24017C for ; Tue, 11 Jan 2022 21:47:38 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xxHd5lrQb33Y for ; Tue, 11 Jan 2022 21:47:37 +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 53037240692 for ; Tue, 11 Jan 2022 21:47:26 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 5B92F3A0743; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:46:03 +0100 Message-Id: <20220111204610.14262-28-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 28/35] lavd/jack: switch to the 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: ZSuda/envEk0 --- libavdevice/jack.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/libavdevice/jack.c b/libavdevice/jack.c index 0d5465e407..eb75cc9dc6 100644 --- a/libavdevice/jack.c +++ b/libavdevice/jack.c @@ -81,13 +81,14 @@ static int process_callback(jack_nframes_t nframes, void *arg) self->buffer_size); /* Check if an empty packet is available, and if there's enough space to send it back once filled */ - if ((av_fifo_size(self->new_pkts) < sizeof(pkt)) || (av_fifo_space(self->filled_pkts) < sizeof(pkt))) { + if (!av_fifo_can_read(self->new_pkts) || + !av_fifo_can_write(self->filled_pkts)) { self->pkt_xrun = 1; return 0; } /* Retrieve empty (but allocated) packet */ - av_fifo_generic_read(self->new_pkts, &pkt, sizeof(pkt), NULL); + av_fifo_read(self->new_pkts, &pkt, 1); pkt_data = (float *) pkt.data; latency = 0; @@ -106,7 +107,7 @@ static int process_callback(jack_nframes_t nframes, void *arg) pkt.pts = (cycle_time - (double) latency / (self->nports * self->sample_rate)) * 1000000.0; /* Send the now filled packet back, and increase packet counter */ - av_fifo_generic_write(self->filled_pkts, &pkt, sizeof(pkt), NULL); + av_fifo_write(self->filled_pkts, &pkt, 1); sem_post(&self->packet_count); return 0; @@ -134,12 +135,12 @@ static int supply_new_packets(JackData *self, AVFormatContext *context) /* Supply the process callback with new empty packets, by filling the new * packets FIFO buffer with as many packets as possible. process_callback() * can't do this by itself, because it can't allocate memory in realtime. */ - while (av_fifo_space(self->new_pkts) >= sizeof(pkt)) { + while (av_fifo_can_write(self->new_pkts)) { if ((test = av_new_packet(&pkt, pkt_size)) < 0) { av_log(context, AV_LOG_ERROR, "Could not create packet of size %d\n", pkt_size); return test; } - av_fifo_generic_write(self->new_pkts, &pkt, sizeof(pkt), NULL); + av_fifo_write(self->new_pkts, &pkt, 1); } return 0; } @@ -193,9 +194,9 @@ static int start_jack(AVFormatContext *context) } /* Create FIFO buffers */ - self->filled_pkts = av_fifo_alloc_array(FIFO_PACKETS_NUM, sizeof(AVPacket)); + self->filled_pkts = av_fifo_alloc2(FIFO_PACKETS_NUM, sizeof(AVPacket), 0); /* New packets FIFO with one extra packet for safety against underruns */ - self->new_pkts = av_fifo_alloc_array((FIFO_PACKETS_NUM + 1), sizeof(AVPacket)); + self->new_pkts = av_fifo_alloc2((FIFO_PACKETS_NUM + 1), sizeof(AVPacket), 0); if (!self->new_pkts) { jack_client_close(self->client); return AVERROR(ENOMEM); @@ -212,8 +213,8 @@ static int start_jack(AVFormatContext *context) static void free_pkt_fifo(AVFifoBuffer **fifo) { AVPacket pkt; - while (av_fifo_size(*fifo)) { - av_fifo_generic_read(*fifo, &pkt, sizeof(pkt), NULL); + while (av_fifo_can_read(*fifo)) { + av_fifo_read(*fifo, &pkt, 1); av_packet_unref(&pkt); } av_fifo_freep(fifo); @@ -313,7 +314,7 @@ static int audio_read_packet(AVFormatContext *context, AVPacket *pkt) } /* Retrieve the packet filled with audio data by process_callback() */ - av_fifo_generic_read(self->filled_pkts, pkt, sizeof(*pkt), NULL); + av_fifo_read(self->filled_pkts, pkt, 1); if ((test = supply_new_packets(self, context))) return test;