From patchwork Sat Dec 11 18:40:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32325 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a0c:cdc3:0:0:0:0:0 with SMTP id a3csp5358632qvn; Sat, 11 Dec 2021 10:41:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJznNRVwS2sb9x4cg7qgRFeKw8XhVkcOs+K1y1ZUZEOQqbxMnFgwW5/gnCvkffDWiucgIi5V X-Received: by 2002:a17:906:3ce9:: with SMTP id d9mr32081392ejh.172.1639248091022; Sat, 11 Dec 2021 10:41:31 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qa42si10702330ejc.545.2021.12.11.10.41.30; Sat, 11 Dec 2021 10:41:31 -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=@outlook.com header.s=selector1 header.b=MLrLlZJ9; 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 606D268AF52; Sat, 11 Dec 2021 20:40:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2064.outbound.protection.outlook.com [40.92.89.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EEE4168AE9B for ; Sat, 11 Dec 2021 20:40:53 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LFz83Ps0RvWWXug4qbuwDed/P5Wk7Cv2aATlySyLWTYyjeEth+1q8Mma6BKUe+Dj37nMTkm/1n2NCRVK0qFpFlwC9xyw1rfnONwHL4gDXDjAELYfjilv2htRb2fHxtM78oRFlfHTZLUAXrEZSsmCJGl82f7nFNX+w113CyESUhDxElneXJZBSZOwAFrFdKmJ0715jBxg33aizKP3BNu7WWQ+aLGHTwG9W/9VIu86nzFsKeQx0zX0oF1mXhXgcYj2R0dKtFG5jpxXa8R4c4RLHvPVWfcrph8JW/JTPOPxntbxgi6BlcP6ca/S0TKkR+fJvWaraXoyjUsFEz6gKc6Evg== 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=HcBEX+7iOO/BqMmAUTdOhBJbI+buogtgnB5PrFRhXD8=; b=B79Q4JkrpY+j/PvzFN0kSyOwTbNzM1YIjwcQ+csk0F/hG9kM+XsepWbrO94BqDD2lbJWf15zkaaqgCwEvubDzE7LmyFfv577GgOBXgfWyWbICIwo2I+K/yaIxLqdx071HSuaRVlfl2hoOM8ptJN/ikF7KGwrFlsZz/J8Lv9GGCff6HdZegdC8X8f318LVNNYQjVcCqN7hrs1Ix9viw1dW8B+wA1nT+Nyn5j2/HQYuXfMC4xmlOFcLu2uelHe0LZE5It9lg9t1dUxIoU91rFLrNDOvS9/m12KUZP4RnRUC6l1YNEtA8HQzHeEhUBGN7l9HoCgy1GLitDaUMEcmru96A== 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=HcBEX+7iOO/BqMmAUTdOhBJbI+buogtgnB5PrFRhXD8=; b=MLrLlZJ9l6hep7+CbhhcBsdfR0Gbl7GrREpET3tmzALYgEiNoXBxceDufcnizPIXCNhnFQA9nT5ER3wlQNkMUmXN0dt5xMv7vqlnzWuIRiEs55Xny/NjcUGVyzE/0nJenfrQQZ0MF/1eS5g573ftg15ZjB2TJi8BWB/zDMgUphjXtGNyaQXzxwc/iZZrt5EgWiAKq+4dni9IaZ1uSq7C8tx3jhJF/JATx+dfVKHtBDpBP15veH0QVsWBVP3MGZDXhj/eh8wIygVTMpF9bF/7QX4skelLhxtcpf6MaR/2OApwuykJDdl4ZIlPTMnRpuGoFXFpTjwOaUPox1XwsYGcPA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6450.eurprd03.prod.outlook.com (2603:10a6:20b:1b2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.22; Sat, 11 Dec 2021 18:40:52 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f0dc:92f5:6bc2:45ca%6]) with mapi id 15.20.4778.017; Sat, 11 Dec 2021 18:40:52 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 11 Dec 2021 19:40:20 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [bbP31ea6nrPaw0qZlQ4100KEN0r4F4YU] X-ClientProxiedBy: AM4P190CA0008.EURP190.PROD.OUTLOOK.COM (2603:10a6:200:56::18) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211211184025.1430779-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7969810d-f8d0-415c-a74f-08d9bcd5c218 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiS9msLST/hR/FDB3IPfXlmiUj7970baJZv3UI31fPKxikKy3SoGp/U1jryXAQ/ARBhbbBI7sJPYjykrVniVjOWqcb/Me5vAu77/82Udpj23870v0J16wmQ2W8nZwlfa/ZUCWiwZvpMnEJN39s3vB80h1lH45GTGL6SkdnhGXN/fEDbfe7f1RReOS5ZMArZ08ChBBXKYXUO5s7MdPFVKJPS3gzNkCSVZwau6HBNfwXXmdd2dBl7hyJLfgET5aM2+AqU6d1Db6LXHC+cT5RAYMGQ9WXdSsbeyUmLsLWzhMEEwpJmki7cyPQazZRBxpQ32CirRBtys/InQPQBgBJpwMytTo/XO1ul6M/CY/wvKQu6ZFSIB8H8T/TfPMcPmXymr4jxyk4EfYc5WbzOVZiwUcrDFHbUrkj8wlWLB4EkFzxt3zv0izseOZldqql5SHMtyPLnimR/o1I51py6W9tm42Sj4RjeMVnBQypHNcmmdsZET4rooHru0vA76VjVw5yMq/+82cjpZq2xtliucJropC5ze5lO7ar3a7UmXsfnpqu0aAlNpDVZLvJAGRazQk8yULqRg9ykGrOnaCmZs7hDarn+ARn9mARWtqh+pxA+v3jMX6hnO7YHGqlEhNeo7ToSDz430NGYXNkqUu0Im0a7JybhcI2qccWtCGOWJwsFURR7+/6viJVazb2LdPi9Mt0fNxcwvWtRTEAPVKDlwE4ffXfB2lT/XnbCltwLqLWYXL5dpa9OxaDBx5lm7pits8saX4jg= X-MS-TrafficTypeDiagnostic: AM7PR03MB6450:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WHgIKKZ80rQFMoK8BSdKfIvByU/QafmGmAhCdL9sxTE7yNV11SKnR/1ysKkDoxzZnQUMA63tWsmSxWylaepfe1Bjlfj0LHylhun5KjGglQ4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BOJ83jZdyTabRJGgKxharac4vwiBIJEEb+aveRmfcSr+S7f0mbHQXAzF9DQFZR0ikNseyN6a+b6ZWZr2Qx2pma/56OMleu4Bhm2dFzJVBZOq89NIeJoxbn0y0l2spR5AG4+rY+Qs0Vhs8u0QrMu+fKEmiQYFDSIpUZz4461VPHcWlhjOKNVwPrsCnCE7INZRQUrbXebVXfRUdN9WEZzTDSk6b275qBwaJWtju/mY2p11/qyk8R4Ms7hnK/mXwReRbYqdBXnPG0wpTt5mlzAwDlQaP3Fo08u6jLV/DIfoxPNGNWKc7SEwzJv968Zy4fIrEkWgPAFqRZlQJP1l4jAVjtwaupwaW8pyMpa+9uUhRjlm9fwHQJxFxujcuguqih5chtQ5to+Nllyzx+xGO7VMHAnVhKqPZERy+lqcbpAISzkecT3DalctzASFL/dvUdURkg7Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7969810d-f8d0-415c-a74f-08d9bcd5c218 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 18:40:52.2118 (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: AM7PR03MB6450 Subject: [FFmpeg-devel] [PATCH 07/12] avcodec/pgssubdec: Use dedicated pointer for accesses 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: rzRVTuXHubIC Content-Length: 6546 Improves readability and decreases codesize. Signed-off-by: Andreas Rheinhardt --- libavcodec/pgssubdec.c | 66 ++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c index d2824f5bbf..8a200aa01b 100644 --- a/libavcodec/pgssubdec.c +++ b/libavcodec/pgssubdec.c @@ -443,6 +443,7 @@ static int parse_presentation_segment(AVCodecContext *avctx, for (i = 0; i < ctx->presentation.object_count; i++) { + PGSSubObjectRef *const object = &ctx->presentation.objects[i]; if (buf_end - buf < 8) { av_log(avctx, AV_LOG_ERROR, "Insufficent space for object\n"); @@ -450,32 +451,29 @@ static int parse_presentation_segment(AVCodecContext *avctx, return AVERROR_INVALIDDATA; } - ctx->presentation.objects[i].id = bytestream_get_be16(&buf); - ctx->presentation.objects[i].window_id = bytestream_get_byte(&buf); - ctx->presentation.objects[i].composition_flag = bytestream_get_byte(&buf); + object->id = bytestream_get_be16(&buf); + object->window_id = bytestream_get_byte(&buf); + object->composition_flag = bytestream_get_byte(&buf); - ctx->presentation.objects[i].x = bytestream_get_be16(&buf); - ctx->presentation.objects[i].y = bytestream_get_be16(&buf); + object->x = bytestream_get_be16(&buf); + object->y = bytestream_get_be16(&buf); // If cropping - if (ctx->presentation.objects[i].composition_flag & 0x80) { - ctx->presentation.objects[i].crop_x = bytestream_get_be16(&buf); - ctx->presentation.objects[i].crop_y = bytestream_get_be16(&buf); - ctx->presentation.objects[i].crop_w = bytestream_get_be16(&buf); - ctx->presentation.objects[i].crop_h = bytestream_get_be16(&buf); + if (object->composition_flag & 0x80) { + object->crop_x = bytestream_get_be16(&buf); + object->crop_y = bytestream_get_be16(&buf); + object->crop_w = bytestream_get_be16(&buf); + object->crop_h = bytestream_get_be16(&buf); } ff_dlog(avctx, "Subtitle Placement x=%d, y=%d\n", - ctx->presentation.objects[i].x, ctx->presentation.objects[i].y); + object->x, object->y); - if (ctx->presentation.objects[i].x > avctx->width || - ctx->presentation.objects[i].y > avctx->height) { + if (object->x > avctx->width || object->y > avctx->height) { av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n", - ctx->presentation.objects[i].x, - ctx->presentation.objects[i].y, + object->x, object->y, avctx->width, avctx->height); - ctx->presentation.objects[i].x = 0; - ctx->presentation.objects[i].y = 0; + object->y = object->x = 0; if (avctx->err_recognition & AV_EF_EXPLODE) { return AVERROR_INVALIDDATA; } @@ -531,13 +529,13 @@ static int display_end_segment(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } for (i = 0; i < ctx->presentation.object_count; i++) { + AVSubtitleRect *const rect = av_mallocz(sizeof(*rect)); PGSSubObject *object; - sub->rects[i] = av_mallocz(sizeof(*sub->rects[0])); - if (!sub->rects[i]) + if (!rect) return AVERROR(ENOMEM); - sub->num_rects++; - sub->rects[i]->type = SUBTITLE_BITMAP; + sub->rects[sub->num_rects++] = rect; + rect->type = SUBTITLE_BITMAP; /* Process bitmap */ object = find_object(ctx->presentation.objects[i].id, &ctx->objects); @@ -551,16 +549,16 @@ static int display_end_segment(AVCodecContext *avctx, void *data, continue; } if (ctx->presentation.objects[i].composition_flag & 0x40) - sub->rects[i]->flags |= AV_SUBTITLE_FLAG_FORCED; + rect->flags |= AV_SUBTITLE_FLAG_FORCED; - sub->rects[i]->x = ctx->presentation.objects[i].x; - sub->rects[i]->y = ctx->presentation.objects[i].y; + rect->x = ctx->presentation.objects[i].x; + rect->y = ctx->presentation.objects[i].y; if (object->rle) { - sub->rects[i]->w = object->w; - sub->rects[i]->h = object->h; + rect->w = object->w; + rect->h = object->h; - sub->rects[i]->linesize[0] = object->w; + rect->linesize[0] = object->w; if (object->rle_remaining_len) { av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n", @@ -568,25 +566,25 @@ static int display_end_segment(AVCodecContext *avctx, void *data, if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } - ret = decode_rle(avctx, sub->rects[i], object->rle, object->rle_data_len); + ret = decode_rle(avctx, rect, object->rle, object->rle_data_len); if (ret < 0) { if ((avctx->err_recognition & AV_EF_EXPLODE) || ret == AVERROR(ENOMEM)) { return ret; } - sub->rects[i]->w = 0; - sub->rects[i]->h = 0; + rect->w = 0; + rect->h = 0; continue; } } /* Allocate memory for colors */ - sub->rects[i]->nb_colors = 256; - sub->rects[i]->data[1] = av_mallocz(AVPALETTE_SIZE); - if (!sub->rects[i]->data[1]) + rect->nb_colors = 256; + rect->data[1] = av_mallocz(AVPALETTE_SIZE); + if (!rect->data[1]) return AVERROR(ENOMEM); if (!ctx->forced_subs_only || ctx->presentation.objects[i].composition_flag & 0x40) - memcpy(sub->rects[i]->data[1], palette->clut, sub->rects[i]->nb_colors * sizeof(uint32_t)); + memcpy(rect->data[1], palette->clut, rect->nb_colors * sizeof(uint32_t)); } return 1; }