From patchwork Tue Jun 21 07:41:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 36371 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp2068018pzb; Tue, 21 Jun 2022 00:39:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tC03j+OCXr9T/svxHR1afxbu50Q1Ea/w+GxGKylPVP2JgUjkDvNxn7dmam35xbBrdtBzMx X-Received: by 2002:a17:906:7308:b0:710:dabe:d651 with SMTP id di8-20020a170906730800b00710dabed651mr24558783ejc.75.1655797163133; Tue, 21 Jun 2022 00:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655797163; cv=none; d=google.com; s=arc-20160816; b=T3OjTIYM5J9Xen9+iQq+HdJxc/o9GBOyjcIovoYqxmmatYebtPm5VGRP1wZC2yOuLR 8RHZ0b0jCdtOdj4zQQn3juLD35j5eFrbejBDXGNuR3jXfei4SnU/POa9AJ/DzYC8zRpQ L+h9aENYKfDkO9lVlpRjm1bkkSUSvTMLKAVX8LHUPYsyoQ2O1Pi1qxyGCI1OUCZZUPYG R+CadLautXccCSNIKBoZCGV2y2CYB8LjswVPWU6XrfasUs6fbXPrXg8Sk9TxOsnZdy+Z aMu8eTQqk+v+u261j0OvDZeTDDnO1bMSwfBiY7GExwoOSpoqSZrLSKAh9TzZAjL07DUz YOXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:mime-version:dkim-signature:delivered-to; bh=KU0NaevLWqz+hqSho8VmcF48nWaY1nRbKX79jDsXb/c=; b=dxwg7eucAf4WB7wThG4DtqMywNHIFF+zkpr6iqe+Okzi9kcrnAPfODvLT1PBw0WVsa fzjPu/SKk91BTECDVYS+09nTiytM/DEKubyvzRQCu3k8yCVs25xDyJhHv0P21+F/boiZ r2b39L/LOD3WDnL1L00uQq2hqt8Fh2dUUvS3S7+feQkIx0jMLd+2Oax4fD7AL7B6qmFr Nv3xUtHEVSnQK1sXxwYRSsyyFQE94V60Yp0TQeFs1AnsQPPe4NT4Ss3tbIbo7Ieugr+w cmypgWNNJ7elawxRRYW0Z9QQn00Y0avFvNIjHFE755feI4iCqXdeWGY10J0H+afZ8Xaf u0Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="WTFi/PY1"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d17-20020a17090648d100b00715777cb7cesi13919632ejt.417.2022.06.21.00.39.22; Tue, 21 Jun 2022 00:39:23 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b="WTFi/PY1"; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A421268B581; Tue, 21 Jun 2022 10:39:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A13D68B581 for ; Tue, 21 Jun 2022 10:39:13 +0300 (EEST) Received: by mail-yb1-f173.google.com with SMTP id i7so5365087ybe.11 for ; Tue, 21 Jun 2022 00:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=pFvBAsKoYKdSa4K1H4fiFl73sLcTytIvQ6buEO8yZA4=; b=WTFi/PY1hgYOjHT137jmFRNoER1QsRDUimLxG2vpI53uxD8p+ZY0+jsQL5Mc260yL3 HNv1zWzxTBp93PG0fIoTZB1hlDqD2BeaJRAO8hEeR/MAIhYmwTPiCC385vdH0AANbkiw zFf2O+Jq9FiyOjavzhGOaWe1l7pGqF50F8xpoJXS0oHmuSFQ+gB5n3XgUUt7PV2jpXR5 vt3vL2TdQMp+37qNQXV7Ty8Tyej1aKtu6ZDNlmLoojPbv4oTUU7scQ6TBqC7oSL7rEKM Jf0/ZPaV412hADeO7yYO2yihRnqQMfnUOFlZg8QNx+lnIsoD9QnF8zc3hye99RWdFGvG 6bBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=pFvBAsKoYKdSa4K1H4fiFl73sLcTytIvQ6buEO8yZA4=; b=JbQGlqzvaq2IwN5hTri3vb5hW9JntbvtVKYiAv5CSvcjSsI5ozzl6sOxHwP0N39EmK h6v7XM1lYVEK0wSrUSGHNzhczEk1LrSdgEPkF4p0jdNqQlIr6IQ2gn5BDFUvAS9D8kph SVQcDbBU22L2l6ECmNGKxG6vRSOKqKR77904BjAE/TA+SI/4JdNviEES+6u7BoNKKAvl iBd/XKHmJdOhGWcUe9M2/sKO1BwO9dt3nCB4AATJXEziudfIeAcU1w5KYv00ed6ex+lG jzbCJmLCMiDnyM/rru74LBJ2bb2mfe8uEGXTMN7yvqCz7WHxehpo5lyORpzkbZKuzeIG OsXQ== X-Gm-Message-State: AJIora9f+HSOx6yqRWf7T7yTa5FP91RgT5Q/yLqFD8vyeBag6Zbb5G7k 43PgK/UV1qARtvI3wUCu/0Fw3R59Un4ZI4rDcYI7pdSR0Dg= X-Received: by 2002:a25:4c3:0:b0:668:3954:7f5b with SMTP id 186-20020a2504c3000000b0066839547f5bmr30146807ybe.586.1655797151308; Tue, 21 Jun 2022 00:39:11 -0700 (PDT) MIME-Version: 1.0 From: Paul B Mahol Date: Tue, 21 Jun 2022 09:41:55 +0200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] [PATCH] avfilter: add 3D scope multimedia filter 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: 3xvNOJx8jwD3 Hello, Patch attached. From cef05f80e4a86fe0869b16bed9fe15ab2882b7a9 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Fri, 17 Jun 2022 18:27:19 +0200 Subject: [PATCH] avfilter: add 3D scope multimedia filter Signed-off-by: Paul B Mahol --- doc/filters.texi | 55 ++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/avf_a3dscope.c | 358 +++++++++++++++++++++++++++++++++++++ 4 files changed, 415 insertions(+) create mode 100644 libavfilter/avf_a3dscope.c diff --git a/doc/filters.texi b/doc/filters.texi index 5abab5de18..9ac6314489 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -26995,6 +26995,61 @@ tools. Below is a description of the currently available multimedia filters. +@section a3dscope + +Convert input audio to 3d scope video output. + +The filter accepts the following options: + +@table @option +@item rate, r +Set frame rate, expressed as number of frames per second. Default +value is "25". + +@item size, s +Specify the video size for the output. For the syntax of this option, check the +@ref{video size syntax,,"Video size" section in the ffmpeg-utils manual,ffmpeg-utils}. +Default value is @code{hd720}. + +@item fov +Set the camera field of view. Default is 90 degrees. +Allowed range is from 40 to 150. + +@item roll +Set the camera roll. + +@item pitch +Set the camera pitch. + +@item yaw +Set the camera yaw. + +@item xzoom +Set the camera zoom on X-axis. + +@item yzoom +Set the camera zoom on Y-axis. + +@item zzoom +Set the camera zoom on Z-axis. + +@item xpos +Set the camera position on X-axis. + +@item ypos +Set the camera position on Y-axis. + +@item zpos +Set the camera position on Z-axis. + +@item length +Set the length of displayed audio waves in number of frames. +@end table + +@subsection Commands + +Filter supports the some above options as @ref{commands}. + @section abitscope Convert input audio to a video output, displaying the audio bit scope. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 7ba1c8a861..15ae65336f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -573,6 +573,7 @@ OBJS-$(CONFIG_YUVTESTSRC_FILTER) += vsrc_testsrc.o OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o # multimedia filters +OBJS-$(CONFIG_A3DSCOPE_FILTER) += avf_a3dscope.o OBJS-$(CONFIG_ABITSCOPE_FILTER) += avf_abitscope.o OBJS-$(CONFIG_ADRAWGRAPH_FILTER) += f_drawgraph.o OBJS-$(CONFIG_AGRAPHMONITOR_FILTER) += f_graphmonitor.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index ec70feef11..d874eeb5b0 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -543,6 +543,7 @@ extern const AVFilter ff_vsrc_yuvtestsrc; extern const AVFilter ff_vsink_nullsink; /* multimedia filters */ +extern const AVFilter ff_avf_a3dscope; extern const AVFilter ff_avf_abitscope; extern const AVFilter ff_avf_adrawgraph; extern const AVFilter ff_avf_agraphmonitor; diff --git a/libavfilter/avf_a3dscope.c b/libavfilter/avf_a3dscope.c new file mode 100644 index 0000000000..e8b83a7a5e --- /dev/null +++ b/libavfilter/avf_a3dscope.c @@ -0,0 +1,358 @@ +/* + * Copyright (c) 2022 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/avassert.h" +#include "libavutil/channel_layout.h" +#include "libavutil/opt.h" +#include "libavutil/parseutils.h" +#include "avfilter.h" +#include "filters.h" +#include "formats.h" +#include "audio.h" +#include "video.h" +#include "internal.h" + +typedef struct Audio3dScopeContext { + const AVClass *class; + int w, h; + int size; + float fov; + float roll; + float pitch; + float yaw; + float zoom[3]; + float eye[3]; + + AVRational frame_rate; + int nb_samples; + + float view_matrix[4][4]; + float projection_matrix[4][4]; + + AVFrame *frames[60]; +} Audio3dScopeContext; + +#define OFFSET(x) offsetof(Audio3dScopeContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM + +static const AVOption a3dscope_options[] = { + { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS }, + { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS }, + { "size", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS }, + { "s", "set video size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str="hd720"}, 0, 0, FLAGS }, + { "fov", "set camera FoV", OFFSET(fov), AV_OPT_TYPE_FLOAT, {.dbl=90.f}, 40, 150, TFLAGS }, + { "roll", "set camera roll",OFFSET(roll), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180, 180, TFLAGS }, + { "pitch","set camera pitch",OFFSET(pitch), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180, 180, TFLAGS }, + { "yaw", "set camera yaw", OFFSET(yaw), AV_OPT_TYPE_FLOAT, {.dbl=0.f}, -180, 180, TFLAGS }, + { "xzoom","set camera zoom", OFFSET(zoom[0]),AV_OPT_TYPE_FLOAT, {.dbl=1.f}, 0.01, 10, TFLAGS }, + { "yzoom","set camera zoom", OFFSET(zoom[1]),AV_OPT_TYPE_FLOAT, {.dbl=1.f}, 0.01, 10, TFLAGS }, + { "zzoom","set camera zoom", OFFSET(zoom[2]),AV_OPT_TYPE_FLOAT, {.dbl=1.f}, 0.01, 10, TFLAGS }, + { "xpos", "set camera position", OFFSET(eye[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.f},-60.f, 60.f, TFLAGS }, + { "ypos", "set camera position", OFFSET(eye[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.f},-60.f, 60.f, TFLAGS }, + { "zpos", "set camera position", OFFSET(eye[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.f},-60.f, 60.f, TFLAGS }, + { "length","set length", OFFSET(size), AV_OPT_TYPE_INT, {.i64=15}, 1, 60, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(a3dscope); + +static int query_formats(AVFilterContext *ctx) +{ + AVFilterFormats *formats = NULL; + AVFilterChannelLayouts *layouts = NULL; + AVFilterLink *inlink = ctx->inputs[0]; + AVFilterLink *outlink = ctx->outputs[0]; + static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }; + static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE }; + int ret; + + formats = ff_make_format_list(sample_fmts); + if ((ret = ff_formats_ref (formats, &inlink->outcfg.formats )) < 0) + return ret; + + formats = ff_all_samplerates(); + if ((ret = ff_formats_ref(formats, &inlink->outcfg.samplerates)) < 0) + return ret; + + formats = ff_make_format_list(pix_fmts); + if ((ret = ff_formats_ref(formats, &outlink->incfg.formats)) < 0) + return ret; + + layouts = ff_all_channel_counts(); + if ((ret = ff_channel_layouts_ref(layouts, &inlink->outcfg.channel_layouts)) < 0) + return ret; + + return 0; +} + +static int config_input(AVFilterLink *inlink) +{ + AVFilterContext *ctx = inlink->dst; + Audio3dScopeContext *s = ctx->priv; + + s->nb_samples = FFMAX(1, av_rescale(inlink->sample_rate, s->frame_rate.den, s->frame_rate.num)); + + return 0; +} + +static int config_output(AVFilterLink *outlink) +{ + Audio3dScopeContext *s = outlink->src->priv; + + outlink->w = s->w; + outlink->h = s->h; + outlink->sample_aspect_ratio = (AVRational){1,1}; + outlink->frame_rate = s->frame_rate; + outlink->time_base = av_inv_q(outlink->frame_rate); + + return 0; +} + +static void projection_matrix(float fov, float a, float near, float far, + float matrix[4][4]) +{ + float f; + + memset(matrix, 0, sizeof(*matrix)); + + f = 1.0f / tanf(fov * 0.5f * M_PI / 180.f); + matrix[0][0] = f * a; + matrix[1][1] = f; + matrix[2][2] = -(far + near) / (far - near); + matrix[2][3] = -1.f; + matrix[3][2] = -(near * far) / (far - near); +} + +static inline void vmultiply(const float v[4], const float m[4][4], float d[4]) +{ + d[0] = v[0] * m[0][0] + v[1] * m[1][0] + v[2] * m[2][0] + v[3] * m[3][0]; + d[1] = v[0] * m[0][1] + v[1] * m[1][1] + v[2] * m[2][1] + v[3] * m[3][1]; + d[2] = v[0] * m[0][2] + v[1] * m[1][2] + v[2] * m[2][2] + v[3] * m[3][2]; + d[3] = v[0] * m[0][3] + v[1] * m[1][3] + v[2] * m[2][3] + v[3] * m[3][3]; +} + +static void mmultiply(const float m2[4][4], const float m1[4][4], float m[4][4]) +{ + vmultiply(m2[0], m1, m[0]); + vmultiply(m2[1], m1, m[1]); + vmultiply(m2[2], m1, m[2]); + vmultiply(m2[3], m1, m[3]); +} + +static float vdot(const float x[3], const float y[3]) +{ + return x[0] * y[0] + x[1] * y[1] + x[2] * y[2]; +} + +static void view_matrix(const float eye[3], + const float z[3], + const float roll, + const float pitch, + const float yaw, float m[4][4]) +{ + float cr = cosf(roll * M_PI / 180.f); + float sr = sinf(roll * M_PI / 180.f); + float cp = cosf(pitch * M_PI / 180.f); + float sp = sinf(pitch * M_PI / 180.f); + float cy = cosf(yaw * M_PI / 180.f); + float sy = sinf(yaw * M_PI / 180.f); + float t[4][4]; + float rx[4][4] = { + {z[0], 0.f, 0.f, 0.f }, + { 0.f, cy, -sy, 0.f }, + { 0.f, sy, cy, 0.f }, + { 0.f, 0.f, 0.f, 1.f }, + }; + + float ry[4][4] = { + { cp, 0.f, sp, 0.f }, + { 0.f,z[1], 0.f, 0.f }, + {-sp, 0.f, cp, 0.f }, + { 0.f, 0.f, 0.f, 1.f }, + }; + + float rz[4][4] = { + { cr, -sr, 0.f, 0.f }, + { sr, cr, 0.f, 0.f }, + { 0.f, 0.f,z[2], 0.f }, + { 0.f, 0.f, 0.f, 1.f }, + }; + + memset(m, 0, sizeof(*m)); + + mmultiply(rx, ry, t); + mmultiply(rz, t, m); + + m[3][0] = -vdot(m[0], eye); + m[3][1] = -vdot(m[1], eye); + m[3][2] = -vdot(m[2], eye); +} + +static void draw_dot(AVFrame *out, unsigned x, unsigned y, float z, + int r, int g, int b) +{ + const int linesize = out->linesize[0]; + uint8_t *dst; + + dst = out->data[0] + y * linesize + x * 4; + dst[0] = r * z; + dst[1] = g * z; + dst[2] = b * z; + dst[3] = 255 * z; +} + +static int filter_frame(AVFilterLink *inlink, AVFrame *in) +{ + AVFilterContext *ctx = inlink->dst; + AVFilterLink *outlink = ctx->outputs[0]; + Audio3dScopeContext *s = ctx->priv; + const float half_height = (s->h - 1) * 0.5f; + const float half_width = (s->w - 1) * 0.5f; + float matrix[4][4]; + const int w = s->w; + const int h = s->h; + AVFrame *out; + + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + av_frame_free(&in); + return AVERROR(ENOMEM); + } + + s->frames[0] = in; + + out->sample_aspect_ratio = (AVRational){1,1}; + for (int y = 0; y < outlink->h; y++) + memset(out->data[0] + y * out->linesize[0], 0, outlink->w * 4); + out->pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base); + + projection_matrix(s->fov, half_width / half_height, 0.1f, 1000000.f, s->projection_matrix); + view_matrix(s->eye, s->zoom, s->roll, s->pitch, s->yaw, s->view_matrix); + mmultiply(s->projection_matrix, s->view_matrix, matrix); + + for (int nb_frame = s->size - 1; nb_frame >= 0; nb_frame--) { + const float scale = 1.f / s->nb_samples; + AVFrame *frame = s->frames[nb_frame]; + float channels; + + if (!frame) + continue; + + channels = frame->ch_layout.nb_channels; + for (int ch = 0; ch < channels; ch++) { + const float *src = (float *)frame->extended_data[ch]; + const int r = 128.f + 127.f * sinf(ch / (channels - 1) * M_PI); + const int g = 128.f + 127.f * ch / (channels - 1); + const int b = 128.f + 127.f * cosf(ch / (channels - 1) * M_PI); + + for (int n = frame->nb_samples - 1, nn = s->nb_samples * nb_frame; n >= 0; n--, nn++) { + float v[4] = { src[n], ch - (channels - 1) * 0.5f, -0.1f + -nn * scale, 1.f }; + float d[4]; + int x, y; + + vmultiply(v, matrix, d); + + d[0] /= d[3]; + d[1] /= d[3]; + + x = d[0] * half_width + half_width; + y = d[1] * half_height + half_height; + + if (x >= w || y >= h || x < 0 || y < 0) + continue; + + draw_dot(out, x, y, av_clipf(1.f / d[3], 0.f, 1.f), + r, g, b); + } + } + } + + av_frame_free(&s->frames[59]); + memmove(&s->frames[1], &s->frames[0], 59 * sizeof(AVFrame *)); + s->frames[0] = NULL; + + return ff_filter_frame(outlink, out); +} + +static int activate(AVFilterContext *ctx) +{ + AVFilterLink *inlink = ctx->inputs[0]; + AVFilterLink *outlink = ctx->outputs[0]; + Audio3dScopeContext *s = ctx->priv; + AVFrame *in; + int ret; + + FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); + + ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in); + if (ret < 0) + return ret; + if (ret > 0) + return filter_frame(inlink, in); + + if (ff_inlink_queued_samples(inlink) >= s->nb_samples) { + ff_filter_set_ready(ctx, 10); + return 0; + } + + FF_FILTER_FORWARD_STATUS(inlink, outlink); + FF_FILTER_FORWARD_WANTED(outlink, inlink); + + return FFERROR_NOT_READY; +} + +static av_cold void uninit(AVFilterContext *ctx) +{ + Audio3dScopeContext *s = ctx->priv; + + for (int n = 0; n < 60; n++) + av_frame_free(&s->frames[n]); +} + +static const AVFilterPad audio3dscope_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .config_props = config_input, + }, +}; + +static const AVFilterPad audio3dscope_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, + }, +}; + +const AVFilter ff_avf_a3dscope = { + .name = "a3dscope", + .description = NULL_IF_CONFIG_SMALL("Convert input audio to 3d scope video output."), + .uninit = uninit, + .priv_size = sizeof(Audio3dScopeContext), + .activate = activate, + FILTER_INPUTS(audio3dscope_inputs), + FILTER_OUTPUTS(audio3dscope_outputs), + FILTER_QUERY_FUNC(query_formats), + .priv_class = &a3dscope_class, + .flags = AVFILTER_FLAG_SLICE_THREADS, + .process_command = ff_filter_process_command, +}; -- 2.36.1