From patchwork Tue Jan 11 20:46:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33268 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4052216iog; Tue, 11 Jan 2022 12:55:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBGSuStOhjGPPttPtjV+dx0W4f9/lh8a9TFyFuOoXzE8pjjkpKSsmBe7G+pptz3kwa08nB X-Received: by 2002:a17:906:9b08:: with SMTP id eo8mr5288217ejc.234.1641934533293; Tue, 11 Jan 2022 12:55:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934533; cv=none; d=google.com; s=arc-20160816; b=uvw4blcK7aJ75dh89OkFMLs56tPow2Nd/AzGF9SasFoOJgl3xVnlBX0xnY7IKMfBkk 421+KWhu9OZkvC9ZL2GbbFfq0KQQet+pS+drSMzIfT4pZ5GvFLdi5yCwprzM3FbQMUkT CUbhhGRuDEBGmgqHPH0p4BBJ5ok8JrdKscx0RknMPMLBKtNQ3e3cjAu4+RU24d3+pJDr 2OOqYm3WkgrLvs8ENsDNiVSZFtrufIlwMjqfhtAFssjXbqO7OSbeP40mmDer4snk88Pm F6p9SYlGMQSWp9JlRDeFFNqfkXjqV7SICk34xAV76+7FKLZdINOGAiOgfPre/agZMsuH jXYQ== 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=rjKiZGvKdNBT8I8owybYMOdqy82+HiafgKEGWgLBNOQ=; b=fhGe+CEFft2JdelSssuLLt9jqcuMtUDjwfxgorsoya1rSscT5vcq7kXZ9ffDafrpXj cfXonUW87YMjo7L8TA64dWWokoHtN6TpFKQywSR0pcOA6DfMgZcAgterbKklPt8hw9kt AuRcuBWUZF5haLIM5Q7ISMcK/TSuVG9wTj3i7DAYO5drdmn/UT7lZP+q/fSmDCECeUYo 6zsqD65p/rs8wwDh6il/xyo85pv7xxfHUh6XICUvZ4l1yj4lI+3diG4elcUwvVUt8g6r duyQ0GXhFQg2QQ8MD/xq6xQ77oazwtixAxILkj0Z8wo5yDtTWJBOCCg8pvXLAo3vUdr9 Ejww== 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 oz43si68983ejc.708.2022.01.11.12.55.32; Tue, 11 Jan 2022 12:55:33 -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 BC0B068AFB7; Tue, 11 Jan 2022 22:54:57 +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 1910268AF3A for ; Tue, 11 Jan 2022 22:54:49 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 920BF240179 for ; Tue, 11 Jan 2022 21:54:48 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id g-kKQfSHe1ts for ; Tue, 11 Jan 2022 21:54:48 +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 CC00C2404FE for ; Tue, 11 Jan 2022 21:54:46 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 70AF53A0746; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:46:08 +0100 Message-Id: <20220111204610.14262-33-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 33/35] lavfi/vf_deshake_opencl: 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: Jfcyi5RuE19b --- libavfilter/vf_deshake_opencl.c | 80 ++++++++++----------------------- 1 file changed, 24 insertions(+), 56 deletions(-) diff --git a/libavfilter/vf_deshake_opencl.c b/libavfilter/vf_deshake_opencl.c index 9c761ba5ad..c8ad1d2a4a 100644 --- a/libavfilter/vf_deshake_opencl.c +++ b/libavfilter/vf_deshake_opencl.c @@ -156,14 +156,8 @@ static void free_debug_matches(AbsoluteFrameMotion *afm) { return; } - while (av_fifo_size(afm->debug_matches) > 0) { - av_fifo_generic_read( - afm->debug_matches, - &dm, - sizeof(DebugMatches), - NULL - ); - + while (av_fifo_can_read(afm->debug_matches)) { + av_fifo_read(afm->debug_matches, &dm, 1); av_freep(&dm.matches); } @@ -863,7 +857,7 @@ static void ringbuf_float_at( } else { // This expression represents the last valid index in the buffer, // which we use repeatedly at the end of the video. - clip_end = deshake_ctx->smooth_window - (av_fifo_space(values) / sizeof(float)) - 1; + clip_end = deshake_ctx->smooth_window - av_fifo_can_write(values) - 1; } if (deshake_ctx->abs_motion.data_start_offset != -1) { @@ -881,13 +875,7 @@ static void ringbuf_float_at( clip_end ); - av_fifo_generic_peek_at( - values, - val, - offset_clipped * sizeof(float), - sizeof(float), - NULL - ); + av_fifo_peek(values, val, 1, offset_clipped); } // Returns smoothed current frame value of the given buffer of floats based on the @@ -1188,10 +1176,8 @@ static int deshake_opencl_init(AVFilterContext *avctx) } for (int i = 0; i < RingbufCount; i++) { - ctx->abs_motion.ringbuffers[i] = av_fifo_alloc_array( - ctx->smooth_window, - sizeof(float) - ); + ctx->abs_motion.ringbuffers[i] = av_fifo_alloc2(ctx->smooth_window, + sizeof(float), 0); if (!ctx->abs_motion.ringbuffers[i]) { err = AVERROR(ENOMEM); @@ -1200,9 +1186,9 @@ static int deshake_opencl_init(AVFilterContext *avctx) } if (ctx->debug_on) { - ctx->abs_motion.debug_matches = av_fifo_alloc_array( + ctx->abs_motion.debug_matches = av_fifo_alloc2( ctx->smooth_window / 2, - sizeof(DebugMatches) + sizeof(DebugMatches), 0 ); if (!ctx->abs_motion.debug_matches) { @@ -1424,12 +1410,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) const float luma_h_over_chroma_h = ((float)input_frame->height / (float)chroma_height); if (deshake_ctx->debug_on) { - av_fifo_generic_read( + av_fifo_read( deshake_ctx->abs_motion.debug_matches, - &debug_matches, - sizeof(DebugMatches), - NULL - ); + &debug_matches, 1); } if (input_frame->pkt_duration) { @@ -1441,13 +1424,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *input_frame) // Get the absolute transform data for this frame for (int i = 0; i < RingbufCount; i++) { - av_fifo_generic_peek_at( - deshake_ctx->abs_motion.ringbuffers[i], - &old_vals[i], - deshake_ctx->abs_motion.curr_frame_offset * sizeof(float), - sizeof(float), - NULL - ); + av_fifo_peek(deshake_ctx->abs_motion.ringbuffers[i], + &old_vals[i], 1, + deshake_ctx->abs_motion.curr_frame_offset); } if (deshake_ctx->tripod_mode) { @@ -1842,7 +1821,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) { sizeof(cl_mem), &deshake_ctx->brief_pattern} ); - if (av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) { + if (!av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX])) { // This is the first frame we've been given to queue, meaning there is // no previous frame to match descriptors to @@ -1892,7 +1871,7 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) // old data (and just treat them all as part of the new values) if (deshake_ctx->abs_motion.data_end_offset == -1) { deshake_ctx->abs_motion.data_end_offset = - av_fifo_size(deshake_ctx->abs_motion.ringbuffers[RingbufX]) / sizeof(float) - 1; + av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[RingbufX]) - 1; } goto no_motion_data; @@ -1934,13 +1913,10 @@ static int queue_frame(AVFilterLink *link, AVFrame *input_frame) // Get the absolute transform data for the previous frame for (int i = 0; i < RingbufCount; i++) { - av_fifo_generic_peek_at( + av_fifo_peek( deshake_ctx->abs_motion.ringbuffers[i], - &prev_vals[i], - av_fifo_size(deshake_ctx->abs_motion.ringbuffers[i]) - sizeof(float), - sizeof(float), - NULL - ); + &prev_vals[i], 1, + av_fifo_can_read(deshake_ctx->abs_motion.ringbuffers[i]) - 1); } new_vals[RingbufX] = prev_vals[RingbufX] + relative.translation.s[0]; @@ -2011,21 +1987,13 @@ end: } debug_matches.num_matches = num_vectors; - av_fifo_generic_write( + av_fifo_write( deshake_ctx->abs_motion.debug_matches, - &debug_matches, - sizeof(DebugMatches), - NULL - ); + &debug_matches, 1); } for (int i = 0; i < RingbufCount; i++) { - av_fifo_generic_write( - deshake_ctx->abs_motion.ringbuffers[i], - &new_vals[i], - sizeof(float), - NULL - ); + av_fifo_write(deshake_ctx->abs_motion.ringbuffers[i], &new_vals[i], 1); } return ff_framequeue_add(&deshake_ctx->fq, input_frame); @@ -2063,9 +2031,9 @@ static int activate(AVFilterContext *ctx) // If there is no more space in the ringbuffers, remove the oldest // values to make room for the new ones - if (av_fifo_space(deshake_ctx->abs_motion.ringbuffers[RingbufX]) == 0) { + if (!av_fifo_can_write(deshake_ctx->abs_motion.ringbuffers[RingbufX])) { for (int i = 0; i < RingbufCount; i++) { - av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float)); + av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1); } } ret = queue_frame(inlink, frame); @@ -2092,7 +2060,7 @@ static int activate(AVFilterContext *ctx) // Finish processing the rest of the frames in the queue. while(ff_framequeue_queued_frames(&deshake_ctx->fq) != 0) { for (int i = 0; i < RingbufCount; i++) { - av_fifo_drain(deshake_ctx->abs_motion.ringbuffers[i], sizeof(float)); + av_fifo_drain2(deshake_ctx->abs_motion.ringbuffers[i], 1); } ret = filter_frame(inlink, ff_framequeue_take(&deshake_ctx->fq));