From patchwork Tue Dec 21 18:43:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 32808 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5706123iog; Tue, 21 Dec 2021 10:43:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmWvCNyoW8i+LCu4+o5ZUksQoEwHM9/baMEXi92MORfsPjO9ZY0/IIkmuOvyWYdK2H32Dp X-Received: by 2002:a17:906:c111:: with SMTP id do17mr597889ejc.270.1640112233192; Tue, 21 Dec 2021 10:43:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640112233; cv=none; d=google.com; s=arc-20160816; b=081PxMm9DXwV/oXy/UKSlHZm1PjV2AFM6x9BLCrgKEeS/AC+j0C9sMdff0SfIVCUaZ 1IxFpWSmKinwyUF5qMnDuqY44HG9P5iOq+KV+od2tk43w6JPpSpQ0oxfuSd2doEcr8xP d52kbGZlLUyiT/A9P26ZZ8Sf9+KvPj2vcKvOvJMjHS5i9FwXdVZ5BSYHBAssZVGVEi3t wdZP5LehOthMW1VaD0v4K6JVD0eLVQXljfKmidIKnlo7sIyC31nLgEn4x4kZe3mUd9Cf 6Nk1Q6MqljDsjK5Xs+Npdy5pKnOp1hGSUDVylJxe3fkMtJKonTLBdbJyG9x+Ei6yLgOa WEng== 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 :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=giqyd+/WtbiUCOrf/FKlNzYuVDbjChTsWzSBQuSAOL8=; b=kIogclSrxsOU1v+2Kc4Xe7bR3+2vw1+j/JqPK6v/24meFFRpj35YuRiqgYQcAFiqSU 0skxBj8Lj1q/C3tlrrEporfpDmmjfHhKnNhLT6L9zNdvUNhPutk/+C0q1D9STB1ZoD8+ KAk2Bv5ezJclYYvD0+v7OeHgBo3eQhWyHYhuMo1rJV/n/HqPGSO4jGcEFeKO1gVc0CIY 5RpQri/HZ8Uwp67xYQc2AueJakVzs3IPZs0nyK2nzJHW8pcTWlwEjmZzOgv3f1jAC9kp Qm3Rl3pSmwd9MPVwjYtuMqy+pHA4LwCVFXRiBErVNMTyJadlCQnuiI3k+CaiwHRGbozy G8FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=T6sEf6Lt; 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=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hr6si4976408ejc.483.2021.12.21.10.43.52; Tue, 21 Dec 2021 10:43:53 -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; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=T6sEf6Lt; 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=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 83E5D68AEC3; Tue, 21 Dec 2021 20:43:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A150768A800 for ; Tue, 21 Dec 2021 20:43:44 +0200 (EET) Received: from w3.tutanota.de (unknown [192.168.1.164]) by w4.tutanota.de (Postfix) with ESMTP id 463B9106014E for ; Tue, 21 Dec 2021 18:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1640112224; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=VHnFfjRIgiA3Zd6QXKeHku+wUwrECoStikEe0dwEjaU=; b=T6sEf6LtoarUqviD9ofpvGBwcRiWrS0YGybXauFr3EF+6HoqtQGYx9A/Nhm69vEu Hks48CpWxKOd4Q4jZU6Ka6DQmPwLF7Q9AmpsRxBHujeLENqBrMZS5OVhSAesrvTe29d pS5gF7V5v3a+ZcOPGsrmciNmoJt9JVKcTCRqCdOpGYPqbsroJH//CNCkXpEmPRkI4fO oqp/ZDoUDuZGXskOzkkMaEkuLja/UxYXt1YoZV7tsEIgAA9TQDN0vKw5+61n9vvN+uA gB2hg9pkfbWH+eEQCsRTeloZ8vaWCHIdfL/DulwnpJQTvaKnaMppv4jOmFuk7hzCVnY c7JOu1q5Jg== Date: Tue, 21 Dec 2021 19:43:44 +0100 (CET) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] swscale: fix style issues and check malloc in ff_shuffle_filter_coefficients 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: gLXAXDFh6CXY Google's net worth for 2021:                       1 000 000 000 000 USD. Google's revenue for 2021:                           204 000 000 000 USD. Average annual salary for a Google engineer:                 135 000 USD. The greatest, most powerful beacon of capitalism on the planet sends a patch to an open-source project ran by volunteers. Said monument of wealth's revenue is dependent upon said project ran by volunteers. Issues per line of code: ~2.4. Guess which project's ran by volunteers who receive nothing from Google yet have to fix issues in patches meant to fix issues? Patch attached without snarky commit message. But I hope my point gets across. Subject: [PATCH] swscale: fix style issues and check malloc in ff_shuffle_filter_coefficients --- libswscale/swscale_internal.h | 2 +- libswscale/utils.c | 65 +++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 64aa0b9804..e834f2aa91 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -1106,5 +1106,5 @@ void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, #define MAX_LINES_AHEAD 4 //shuffle filter and filterPos for hyScale and hcScale filters in avx2 -void ff_shuffle_filter_coefficients(SwsContext *c, int* filterPos, int filterSize, int16_t *filter, int dstW); +int ff_shuffle_filter_coefficients(SwsContext *c, int* filterPos, int filterSize, int16_t *filter, int dstW); #endif /* SWSCALE_SWSCALE_INTERNAL_H */ diff --git a/libswscale/utils.c b/libswscale/utils.c index d4a72d3ce1..fbc1dc98ff 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -278,36 +278,40 @@ static const FormatEntry format_entries[] = { [AV_PIX_FMT_P416LE] = { 1, 0 }, }; -void ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, int filterSize, int16_t *filter, int dstW){ +int ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, + int filterSize, int16_t *filter, int dstW) +{ #if ARCH_X86_64 - int i, j, k, l; int cpu_flags = av_get_cpu_flags(); - if (EXTERNAL_AVX2_FAST(cpu_flags)){ - if ((c->srcBpc == 8) && (c->dstBpc <= 14)){ - if (dstW % 16 == 0){ - if (filter != NULL){ - for (i = 0; i < dstW; i += 8){ - FFSWAP(int, filterPos[i + 2], filterPos[i+4]); - FFSWAP(int, filterPos[i + 3], filterPos[i+5]); - } - if (filterSize > 4){ - int16_t *tmp2 = av_malloc(dstW * filterSize * 2); - memcpy(tmp2, filter, dstW * filterSize * 2); - for (i = 0; i < dstW; i += 16){//pixel - for (k = 0; k < filterSize / 4; ++k){//fcoeff - for (j = 0; j < 16; ++j){//inner pixel - for (l = 0; l < 4; ++l){//coeff - int from = i * filterSize + j * filterSize + k * 4 + l; - int to = (i) * filterSize + j * 4 + l + k * 64; - filter[to] = tmp2[from]; - } - } - } + + if (!EXTERNAL_AVX2_FAST(cpu_flags)) + return 0; + + if ((c->srcBpc == 8) && (c->dstBpc <= 14) && !(dstW % 16) && filter) { + for (int i = 0; i < dstW; i += 8) { + FFSWAP(int, filterPos[i + 2], filterPos[i+4]); + FFSWAP(int, filterPos[i + 3], filterPos[i+5]); + } + + if (filterSize > 4) { + int16_t *tmp2 = av_malloc(dstW * filterSize * 2); + if (!tmp2) + return AVERROR(ENOMEM); + + memcpy(tmp2, filter, dstW * filterSize * 2); + + for (int i = 0; i < dstW; i += 16) { //pixel + for (int k = 0; k < filterSize / 4; k++) { //fcoeff + for (int j = 0; j < 16; j++) { //inner pixel + for (int l = 0; l < 4; l++) { //coeff + int from = i * filterSize + j * filterSize + k * 4 + l; + int to = (i) * filterSize + j * 4 + l + k * 64; + filter[to] = tmp2[from]; } - av_free(tmp2); } } } + av_free(tmp2); } } #endif @@ -1836,7 +1840,12 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, get_local_pos(c, 0, 0, 0), get_local_pos(c, 0, 0, 0))) < 0) goto fail; - ff_shuffle_filter_coefficients(c, c->hLumFilterPos, c->hLumFilterSize, c->hLumFilter, dstW); + + if ((ret = ff_shuffle_filter_coefficients(c, c->hLumFilterPos, + c->hLumFilterSize, + c->hLumFilter, dstW))) + goto fail; + if ((ret = initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, c->chrSrcW, c->chrDstW, filterAlign, 1 << 14, @@ -1846,7 +1855,11 @@ av_cold int sws_init_context(SwsContext *c, SwsFilter *srcFilter, get_local_pos(c, c->chrSrcHSubSample, c->src_h_chr_pos, 0), get_local_pos(c, c->chrDstHSubSample, c->dst_h_chr_pos, 0))) < 0) goto fail; - ff_shuffle_filter_coefficients(c, c->hChrFilterPos, c->hChrFilterSize, c->hChrFilter, c->chrDstW); + + if ((ret = ff_shuffle_filter_coefficients(c, c->hChrFilterPos, + c->hChrFilterSize, + c->hChrFilter, c->chrDstW))) + goto fail; } } // initialize horizontal stuff