From patchwork Sat May 18 15:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48978 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp3503091pzb; Sat, 18 May 2024 08:26:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUhJdQ/79llBCu9aQ7PG4P3VbgRogEIHCZOfJ1mamuN4pe4U09W4QkF6mA0duFS18bz/ENg6iDBRy722V8Z/n7KiwDP2D4G3l78tg== X-Google-Smtp-Source: AGHT+IGhj9BjG4Sso/WT5tbDYwMflbRmYwFcavyIDzXGKAxwi/j7/PpEMLYvKChb7TszVetrz2sB X-Received: by 2002:a05:6402:2550:b0:575:9a9:7b5e with SMTP id 4fb4d7f45d1cf-57509a97bb4mr6602131a12.0.1716045963471; Sat, 18 May 2024 08:26:03 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5733c36d77fsi10847288a12.543.2024.05.18.08.26.03; Sat, 18 May 2024 08:26:03 -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=@outlook.com header.s=selector1 header.b=utC9Hs9p; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BFED668CF01; Sat, 18 May 2024 18:26:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05olkn2109.outbound.protection.outlook.com [40.92.90.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D7F068C1BA for ; Sat, 18 May 2024 18:25:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PeOpET4BxL6Ye1TfJ/Zl8AD+Do/CTiW50r7LxQNdTt+H+B6QPbzKW18JOyB5ojcxbIUzSNreuuocFKbDbnvOxDnZe6eOMuL9ZI7Xq15Aik23qKDF1pW1u+8A1xlbZogkK3H+ENThAonPzFuUQrhgjbdXUmxIhBZRRhyXzQDh3qJak5QJmGpQxJ1wYH6yZoZonPMBNkpydcBo+iHoMIFT2EthRmB+DaRMRfg2b436d+qyHWzETBhoS4LJxblCq2u0BrzLAd83/DD63OpVzp2GFdyfiwgmZOuXnU62rWI5hsUM6oCIORR4Zdui0u4y6zqK7hmELRuNweHb4R4unLbI6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Unn3GXcA6Qc4lZV1l3SUbkbFjn6eaAoKrzEb7+0uYRY=; b=L4R/nXaqEDenjDltoWGKl8SFTVUzZv48RNh4t/HAywoufWmt6pY6sV/OFfzO/njJFlERS4yjqRiPoZYhNO2LEjNyDs9HGvnO+LO39J+PhidurxxaKKCpKbGS5UiTOPUiWdBZc90kJ+Yb5Zw0MMHXbl1FBVoMeSFHpDNsT5J5vHlMW7OhMu5RN/NRSVjimR0q/F/jojowzCF64vH2KU6Q6Ap+WNaN1HD+2rHvx+2tQpSoFwZKYnILEWdX43LJDgwFdfjM8lTifuDFQapCCsylwxR0CBoXOMmf1HuaFqooX4jPPTKK//+lXnP7fLi5qH2RsNzI46SSwLvhcFQzxf50JQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Unn3GXcA6Qc4lZV1l3SUbkbFjn6eaAoKrzEb7+0uYRY=; b=utC9Hs9pHaLBNIFLiG2giAtMAuLDtG4VajN93m6hSMkgGHx+vf9L9nFLVPy6ULgzJhy/XxQUyCWCqDE1q1hm+Ogva7uP1T4wS+mQ49cJt5thKEGutkovbTxk+mrO7iA3zpypzh9oFaHdELWKxeLYuDLA/7KeruP/UwrqPREJjVw2ascesb367MGCXW4Hp4l1PlQfQAhFc7zONwDdP7YRvtb5qI2e51k8Zk8X/eqkhyx7uJGvzDfv5P+v1aIPERTVMWJ1khElimycyCk6nw4q5E4LE5AA4byebs2gnbIPlpDzWWSLMe+EVHOWZMjtamTzWMZHIqJoCeljy21zfok/zg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0064.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:23b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.34; Sat, 18 May 2024 15:25:52 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.7544.052; Sat, 18 May 2024 15:25:52 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 May 2024 17:25:43 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [NZzMGct8ZdQPg9CUgljb143XqqktA5mTBM/soxR3ZOk=] X-ClientProxiedBy: ZR0P278CA0013.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::23) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240518152544.932561-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0064:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c82dd28-7cdc-4ccc-9eaf-08dc774ecdd8 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: wNK1Y8cYho9FyPWU3F+xYKAOtEDBgKLIDfdjs4KwvnPnXJtW9UaK5JOnGoA91JHpcs7zjOdQe1Y7A1kAGfOs4AbIGfFe3rT5meB/O2Uq44/48q4G7K/08BA8N+Ux7e293iAJQcvd419AvPmH6NxsaYC6U5BvZnTN/nOzgRYGvaIqb21wxIejmq9egJAflfL2sAoqUQymm0RNuWziIPvNpVuaekNzqihRSFXA29BIrYj/fLS+Rn19WIcLWCdWKDQXPbHeN2tZIWEmx/1kOmshhXVel8lygA5mBsoAg2yInq03gogvz/mciEws9AKnUhMvqnQ5reOMJiZSGCehHyqHlmT48pjOfwNKSWw0iSic/axwlIoOlUyfJ12HSMycZcpgesh5UedGipM+4UM4+KBMbbeeOCLVtFhERzJXuT38rHStK2D+Zbf33OccZ0zpGPiGRUP/5/yhH/pH1hFyFajV/dD3SVj6MbDMBbXVODWVY5Xwg7lX1yy+ZgsDW/kKZT2KmELNhLMnbImK/AsbUEGkQVlXMuwokyes7FxCugLbTFwhR9pkh4wWFt2rzm+AO0uuHZ3QpnKLEaDeSVBJp63m2ZW0SGXueShD6VZPzHycV6nqTxA0UX136OhAW11vvrAH X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9sHK53tqWZdLl/5HUQMCY+Mel5qEcrTXb5+/ijR/BEyZG/t0QejrrQ2PfWETrbcB4NvVzvDJzyZqptvLX8lOMJBc1OzWxfrbAEm7RyYbQZCZkKvbbXzsiilG9/9M3Rbr230ETN0S09GG3li0Jysa2mOnBZZtkeoWU0aMpsuPWMNTtc3Kdh+jvfb8DG/MZNseTzpkTaC7RG7XTocIGsmpc7UfmM/jhnqBbklHBF0rgtWztfKJIGHZRzsZ/+Y4kPY6oU3mqFj/jU3nrqCJqmJV4IK6s0DMF1WWYiBDPZFI+EoO+OJZMwDG9R4orstgUX6KkFbxCWKgYLQN/NO1qCrSifCUf/dyDUn+JVwk7tMMEwJf2CYVjeRsfaTPVVsratHc3ZzdpvxCcjwGP56HhNp5nXXA9b2Lk7qe/D3OOjbTdmtTDHA/xZ0RvmsFZkLl1cR7FQ/q5L74cjJHzMksLeMxRXMa8Is0fEWK0iau81cFWB/niILu8tFMOiA2zjV0pc76DtoIPmDj2SIxGDYDXnMyd+FWJz3WdZSuIJvWLG7MM9ogzEsGJGR183E1j/9lr2WzZ34Wk8G/tIwqAwvKvgbJWz0/rRrUn5AODK036K7XK/hY8NfmS4IKWAwMHkK1k72iRq2AppDBOk98oSOidBw//VCUyF4JTpEXuX/gBuLBsIWrNexVipryEIzaZx/INX8be5ittD2gcsfZunZelGFzeKviXiYkCudHD6zLSkdKjmySpOyq1oQHtp8MhnPXvaDV0w/D+E7ZXIORRwAU+URY4Cl4xVbq6kRCyN0JzYSYfH98Qxt+pL7YKXx5tw4HI1UzDE+x5zZfeRHwKAFhFB1aZ/ynJwE6ODvX6lia1tpuk9T2dj98I7xUkuUptb3zt6o70dFPhnBy9NHM9vVwp0xhSnqnbbI3rHWzPy8FX3bIWoTTWoHoQxq4gdVvZWIEKrxKB7SvESiLgdi3ZzSNfM4GpVXCHrDJqc6IqXjWQaY0xy2ALoT6fIMIFwKCHsgUXvcjrHn2bAk9Kw2JVjuVwAjULSDASIQxCyw44yzWllRapUyPFtxyfWI8l/JDR3bFyYo7fLyHrYqxIeJTJdnB5QEzVsOJ0kvSEy6kqoTnFkrw2isfZueWjoaNObSlMCzydBK8jRBuREM8JXJnT9TXWaoB83/QEUd0mKV7Fh9YEsV0Lf9bRyGzUmN4mC3Zko0/Km5qwjAf5p7Jfo1f4vE/oniRMYn9VcsSVe45gmX11H/JYyINu3aP4PMtL02tYMETQbtLzj/H89A4SBk2iHnIos4BVA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c82dd28-7cdc-4ccc-9eaf-08dc774ecdd8 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 May 2024 15:25:52.6035 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2P250MB0064 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/vf_signalstats: Deduplicate <= 8 and > 8 bit code 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: KgNug0mH539T Signed-off-by: Andreas Rheinhardt --- libavfilter/vf_signalstats.c | 279 ++++++----------------------------- 1 file changed, 43 insertions(+), 236 deletions(-) diff --git a/libavfilter/vf_signalstats.c b/libavfilter/vf_signalstats.c index 960899596f..1bdc6a42ba 100644 --- a/libavfilter/vf_signalstats.c +++ b/libavfilter/vf_signalstats.c @@ -538,7 +538,7 @@ static unsigned compute_bit_depth(uint16_t mask) return av_popcount(mask); } -static int filter_frame8(AVFilterLink *link, AVFrame *in) +static int filter_frame(AVFilterLink *link, AVFrame *in) { AVFilterContext *ctx = link->dst; SignalstatsContext *s = ctx->priv; @@ -563,20 +563,17 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) int accy, accu, accv; int accsat, acchue = 0; int medhue, maxhue; - int toty = 0, totu = 0, totv = 0, totsat=0; - int tothue = 0; - int dify = 0, difu = 0, difv = 0; + int64_t toty = 0, totu = 0, totv = 0, totsat=0; + int64_t tothue = 0; + int64_t dify = 0, difu = 0, difv = 0; uint16_t masky = 0, masku = 0, maskv = 0; - int ret; + int filtot[FILT_NUMB] = {0}; AVFrame *prev; - + int ret; AVFrame *sat = s->frame_sat; AVFrame *hue = s->frame_hue; - const uint8_t *p_sat = sat->data[0]; - const uint8_t *p_hue = hue->data[0]; - const int lsz_sat = sat->linesize[0]; - const int lsz_hue = hue->linesize[0]; + const int hbd = s->depth > 8; ThreadDataHueSatMetrics td_huesat = { .src = in, .dst_sat = sat, @@ -602,38 +599,45 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) } } - ff_filter_execute(ctx, compute_sat_hue_metrics8, &td_huesat, + ff_filter_execute(ctx, hbd ? compute_sat_hue_metrics16 + : compute_sat_hue_metrics8, &td_huesat, NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx))); - // Calculate luma histogram and difference with previous frame or field. memset(s->histy, 0, s->maxsize * sizeof(*s->histy)); + memset(s->histu, 0, s->maxsize * sizeof(*s->histu)); + memset(s->histv, 0, s->maxsize * sizeof(*s->histv)); + memset(s->histsat, 0, s->maxsize * sizeof(*s->histsat)); + + if (hbd) { + const uint16_t *p_sat = (uint16_t *)sat->data[0]; + const uint16_t *p_hue = (uint16_t *)hue->data[0]; + const int lsz_sat = sat->linesize[0] / 2; + const int lsz_hue = hue->linesize[0] / 2; + // Calculate luma histogram and difference with previous frame or field. for (j = 0; j < link->h; j++) { for (i = 0; i < link->w; i++) { - const int yuv = in->data[0][w + i]; + const int yuv = AV_RN16(in->data[0] + w + i * 2); masky |= yuv; histy[yuv]++; - dify += abs(yuv - prev->data[0][pw + i]); + dify += abs(yuv - (int)AV_RN16(prev->data[0] + pw + i * 2)); } w += in->linesize[0]; pw += prev->linesize[0]; } // Calculate chroma histogram and difference with previous frame or field. - memset(s->histu, 0, s->maxsize * sizeof(*s->histu)); - memset(s->histv, 0, s->maxsize * sizeof(*s->histv)); - memset(s->histsat, 0, s->maxsize * sizeof(*s->histsat)); for (j = 0; j < s->chromah; j++) { for (i = 0; i < s->chromaw; i++) { - const int yuvu = in->data[1][cw+i]; - const int yuvv = in->data[2][cw+i]; + const int yuvu = AV_RN16(in->data[1] + cw + i * 2); + const int yuvv = AV_RN16(in->data[2] + cw + i * 2); masku |= yuvu; maskv |= yuvv; histu[yuvu]++; - difu += abs(yuvu - prev->data[1][cpw+i]); + difu += abs(yuvu - (int)AV_RN16(prev->data[1] + cpw + i * 2)); histv[yuvv]++; - difv += abs(yuvv - prev->data[2][cpw+i]); + difv += abs(yuvv - (int)AV_RN16(prev->data[2] + cpw + i * 2)); histsat[p_sat[i]]++; histhue[((int16_t*)p_hue)[i]]++; @@ -643,228 +647,36 @@ static int filter_frame8(AVFilterLink *link, AVFrame *in) p_sat += lsz_sat; p_hue += lsz_hue; } - - for (fil = 0; fil < FILT_NUMB; fil ++) { - if (s->filters & 1<outfilter == fil ? out : NULL, - }; - memset(s->jobs_rets, 0, s->nb_jobs * sizeof(*s->jobs_rets)); - ff_filter_execute(ctx, filters_def[fil].process8, - &td, s->jobs_rets, s->nb_jobs); - for (i = 0; i < s->nb_jobs; i++) - filtot[fil] += s->jobs_rets[i]; - } - } - - // find low / high based on histogram percentile - // these only need to be calculated once. - - lowp = lrint(s->fs * 10 / 100.); - highp = lrint(s->fs * 90 / 100.); - clowp = lrint(s->cfs * 10 / 100.); - chighp = lrint(s->cfs * 90 / 100.); - - accy = accu = accv = accsat = 0; - for (fil = 0; fil < s->maxsize; fil++) { - if (miny < 0 && histy[fil]) miny = fil; - if (minu < 0 && histu[fil]) minu = fil; - if (minv < 0 && histv[fil]) minv = fil; - if (minsat < 0 && histsat[fil]) minsat = fil; - - if (histy[fil]) maxy = fil; - if (histu[fil]) maxu = fil; - if (histv[fil]) maxv = fil; - if (histsat[fil]) maxsat = fil; - - toty += histy[fil] * fil; - totu += histu[fil] * fil; - totv += histv[fil] * fil; - totsat += histsat[fil] * fil; - - accy += histy[fil]; - accu += histu[fil]; - accv += histv[fil]; - accsat += histsat[fil]; - - if (lowy == -1 && accy >= lowp) lowy = fil; - if (lowu == -1 && accu >= clowp) lowu = fil; - if (lowv == -1 && accv >= clowp) lowv = fil; - if (lowsat == -1 && accsat >= clowp) lowsat = fil; - - if (highy == -1 && accy >= highp) highy = fil; - if (highu == -1 && accu >= chighp) highu = fil; - if (highv == -1 && accv >= chighp) highv = fil; - if (highsat == -1 && accsat >= chighp) highsat = fil; - } - - maxhue = histhue[0]; - medhue = -1; - for (fil = 0; fil < 360; fil++) { - tothue += histhue[fil] * fil; - acchue += histhue[fil]; - - if (medhue == -1 && acchue > s->cfs / 2) - medhue = fil; - if (histhue[fil] > maxhue) { - maxhue = histhue[fil]; - } - } - - av_frame_free(&s->frame_prev); - s->frame_prev = av_frame_clone(in); - -#define SET_META(key, fmt, val) do { \ - snprintf(metabuf, sizeof(metabuf), fmt, val); \ - av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \ -} while (0) - - av_dict_set_int(&out->metadata, "lavfi.signalstats.YMIN", miny, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.YLOW", lowy, 0); - SET_META("YAVG", "%g", 1.0 * toty / s->fs); - av_dict_set_int(&out->metadata, "lavfi.signalstats.YHIGH", highy, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.YMAX", maxy, 0); - - av_dict_set_int(&out->metadata, "lavfi.signalstats.UMIN", minu, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.ULOW", lowu, 0); - SET_META("UAVG", "%g", 1.0 * totu / s->cfs); - av_dict_set_int(&out->metadata, "lavfi.signalstats.UHIGH", highu, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.UMAX", maxu, 0); - - av_dict_set_int(&out->metadata, "lavfi.signalstats.VMIN", minv, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.VLOW", lowv, 0); - SET_META("VAVG", "%g", 1.0 * totv / s->cfs); - av_dict_set_int(&out->metadata, "lavfi.signalstats.VHIGH", highv, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.VMAX", maxv, 0); - - av_dict_set_int(&out->metadata, "lavfi.signalstats.SATMIN", minsat, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.SATLOW", lowsat, 0); - SET_META("SATAVG", "%g", 1.0 * totsat / s->cfs); - av_dict_set_int(&out->metadata, "lavfi.signalstats.SATHIGH", highsat, 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.SATMAX", maxsat, 0); - - av_dict_set_int(&out->metadata, "lavfi.signalstats.HUEMED", medhue, 0); - SET_META("HUEAVG", "%g", 1.0 * tothue / s->cfs); - - SET_META("YDIF", "%g", 1.0 * dify / s->fs); - SET_META("UDIF", "%g", 1.0 * difu / s->cfs); - SET_META("VDIF", "%g", 1.0 * difv / s->cfs); - - av_dict_set_int(&out->metadata, "lavfi.signalstats.YBITDEPTH", compute_bit_depth(masky), 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.UBITDEPTH", compute_bit_depth(masku), 0); - av_dict_set_int(&out->metadata, "lavfi.signalstats.VBITDEPTH", compute_bit_depth(maskv), 0); - - for (fil = 0; fil < FILT_NUMB; fil ++) { - if (s->filters & 1<fs); - snprintf(metaname, sizeof(metaname), "lavfi.signalstats.%s", filters_def[fil].name); - av_dict_set(&out->metadata, metaname, metabuf, 0); - } - } - - if (in != out) - av_frame_free(&in); - return ff_filter_frame(outlink, out); -} - -static int filter_frame16(AVFilterLink *link, AVFrame *in) -{ - AVFilterContext *ctx = link->dst; - SignalstatsContext *s = ctx->priv; - AVFilterLink *outlink = ctx->outputs[0]; - AVFrame *out = in; - int i, j; - int w = 0, cw = 0, // in - pw = 0, cpw = 0; // prev - int fil; - char metabuf[128]; - unsigned int *histy = s->histy, - *histu = s->histu, - *histv = s->histv, - histhue[360] = {0}, - *histsat = s->histsat; - int miny = -1, minu = -1, minv = -1; - int maxy = -1, maxu = -1, maxv = -1; - int lowy = -1, lowu = -1, lowv = -1; - int highy = -1, highu = -1, highv = -1; - int minsat = -1, maxsat = -1, lowsat = -1, highsat = -1; - int lowp, highp, clowp, chighp; - int accy, accu, accv; - int accsat, acchue = 0; - int medhue, maxhue; - int64_t toty = 0, totu = 0, totv = 0, totsat=0; - int64_t tothue = 0; - int64_t dify = 0, difu = 0, difv = 0; - uint16_t masky = 0, masku = 0, maskv = 0; - - int filtot[FILT_NUMB] = {0}; - AVFrame *prev; - int ret; - AVFrame *sat = s->frame_sat; - AVFrame *hue = s->frame_hue; - const uint16_t *p_sat = (uint16_t *)sat->data[0]; - const uint16_t *p_hue = (uint16_t *)hue->data[0]; - const int lsz_sat = sat->linesize[0] / 2; - const int lsz_hue = hue->linesize[0] / 2; - ThreadDataHueSatMetrics td_huesat = { - .src = in, - .dst_sat = sat, - .dst_hue = hue, - }; - - if (!s->frame_prev) - s->frame_prev = av_frame_clone(in); - - prev = s->frame_prev; - - if (s->outfilter != FILTER_NONE) { - out = av_frame_clone(in); - if (!out) { - av_frame_free(&in); - return AVERROR(ENOMEM); - } - ret = ff_inlink_make_frame_writable(link, &out); - if (ret < 0) { - av_frame_free(&out); - av_frame_free(&in); - return ret; - } - } - - ff_filter_execute(ctx, compute_sat_hue_metrics16, &td_huesat, - NULL, FFMIN(s->chromah, ff_filter_get_nb_threads(ctx))); - + } else { + const uint8_t *p_sat = sat->data[0]; + const uint8_t *p_hue = hue->data[0]; + const int lsz_sat = sat->linesize[0]; + const int lsz_hue = hue->linesize[0]; // Calculate luma histogram and difference with previous frame or field. - memset(s->histy, 0, s->maxsize * sizeof(*s->histy)); for (j = 0; j < link->h; j++) { for (i = 0; i < link->w; i++) { - const int yuv = AV_RN16(in->data[0] + w + i * 2); + const int yuv = in->data[0][w + i]; masky |= yuv; histy[yuv]++; - dify += abs(yuv - (int)AV_RN16(prev->data[0] + pw + i * 2)); + dify += abs(yuv - prev->data[0][pw + i]); } w += in->linesize[0]; pw += prev->linesize[0]; } // Calculate chroma histogram and difference with previous frame or field. - memset(s->histu, 0, s->maxsize * sizeof(*s->histu)); - memset(s->histv, 0, s->maxsize * sizeof(*s->histv)); - memset(s->histsat, 0, s->maxsize * sizeof(*s->histsat)); for (j = 0; j < s->chromah; j++) { for (i = 0; i < s->chromaw; i++) { - const int yuvu = AV_RN16(in->data[1] + cw + i * 2); - const int yuvv = AV_RN16(in->data[2] + cw + i * 2); + const int yuvu = in->data[1][cw+i]; + const int yuvv = in->data[2][cw+i]; masku |= yuvu; maskv |= yuvv; histu[yuvu]++; - difu += abs(yuvu - (int)AV_RN16(prev->data[1] + cpw + i * 2)); + difu += abs(yuvu - prev->data[1][cpw+i]); histv[yuvv]++; - difv += abs(yuvv - (int)AV_RN16(prev->data[2] + cpw + i * 2)); + difv += abs(yuvv - prev->data[2][cpw+i]); histsat[p_sat[i]]++; histhue[((int16_t*)p_hue)[i]]++; @@ -874,6 +686,7 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) p_sat += lsz_sat; p_hue += lsz_hue; } + } for (fil = 0; fil < FILT_NUMB; fil ++) { if (s->filters & 1<outfilter == fil ? out : NULL, }; memset(s->jobs_rets, 0, s->nb_jobs * sizeof(*s->jobs_rets)); - ff_filter_execute(ctx, filters_def[fil].process16, + ff_filter_execute(ctx, hbd ? filters_def[fil].process16 : filters_def[fil].process8, &td, s->jobs_rets, s->nb_jobs); for (i = 0; i < s->nb_jobs; i++) filtot[fil] += s->jobs_rets[i]; @@ -946,6 +759,11 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) av_frame_free(&s->frame_prev); s->frame_prev = av_frame_clone(in); +#define SET_META(key, fmt, val) do { \ + snprintf(metabuf, sizeof(metabuf), fmt, val); \ + av_dict_set(&out->metadata, "lavfi.signalstats." key, metabuf, 0); \ +} while (0) + av_dict_set_int(&out->metadata, "lavfi.signalstats.YMIN", miny, 0); av_dict_set_int(&out->metadata, "lavfi.signalstats.YLOW", lowy, 0); SET_META("YAVG", "%g", 1.0 * toty / s->fs); @@ -995,17 +813,6 @@ static int filter_frame16(AVFilterLink *link, AVFrame *in) return ff_filter_frame(outlink, out); } -static int filter_frame(AVFilterLink *link, AVFrame *in) -{ - AVFilterContext *ctx = link->dst; - SignalstatsContext *s = ctx->priv; - - if (s->depth > 8) - return filter_frame16(link, in); - else - return filter_frame8(link, in); -} - static const AVFilterPad signalstats_inputs[] = { { .name = "default",