From patchwork Wed Jan 26 21:34:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33870 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1882696iov; Wed, 26 Jan 2022 13:36:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZBrJ4Ljz+ylR6rCxrHAl8S0uuDfnaADOwX3DBK7jXxpHaIa5Pft/0tX7Xu23NbeReUiEI X-Received: by 2002:a17:907:7d94:: with SMTP id oz20mr572842ejc.340.1643232972061; Wed, 26 Jan 2022 13:36:12 -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 f14si224730edd.197.2022.01.26.13.36.11; Wed, 26 Jan 2022 13:36:12 -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=HOvN1iEz; 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 BBA4868B169; Wed, 26 Jan 2022 23:35:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-oln040092071048.outbound.protection.outlook.com [40.92.71.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56FFC68AF21 for ; Wed, 26 Jan 2022 23:35:17 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BL5vbNfxMFwm0nFd+9SuxEVgmfsAiifFXd608zH2w4K3evPQf4Fr0eO1yrl2OHA4aSdF8yZYsdZP2NZnq4y7OSb0Oe+SSI2kzZrkfTaBbfwfMzD8L6XiUZ1FqIdumj2U8mwiOg7YetUWofcQGanOGp2EzyKpKax0fS9lbiUi+2thEGGUFz7Q4s6sVARB6LTl6DFdYnewtm1nsqN49+56lLqnZxsjp4G5pN0sSa+RPzrVIkHhkvmQPd6XTGOiVDVWjU7AxwfGSlaKhphts4faARvmdzTrcn87x+bANquS6ZmMXrT+xDuz4qCIp06TjrNirjInah0btWFgZcKTOMzTkg== 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=NFq/fMNlTte1k/HjFWuQF9Of8X3eIfvcEnpKBYgUqsA=; b=bTx7GrIAT5TaBLdRrDt0ChjlA5FzqWwJjPtADDhtXHBHBjYo8Uef0+tv04v1rA4NQ10WzV9tODQlci4y14KUYgx1KXUSHNrJ7qEgWKUQ0ovE80a1PMXwdvMBxIFs091D7bWy7WFyrQEqntEiV0PPy3LxtOoH7YMteA+ORSg2CnNMZO3lYOxSxbvQnXxNCNQhHXqjJAUKbsF+sr3KcFCBKmiqr84x+/kdI7h7/dQUoCPSZ4hrhlw33MHDC+EMEZ5r9Gt9NE+gTd1G+UjXMHs/nWH07ubCUD3+uDnP66LhorFI3kWtiRji9hRUG/wNa4fj1RvwWWYedRj53OdxMs5/lw== 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=NFq/fMNlTte1k/HjFWuQF9Of8X3eIfvcEnpKBYgUqsA=; b=HOvN1iEzmQnbsgcf2VgMf+On5Sf8FmX9enLmrUE90HsxQFr9ZxrvUoj8CclkGhY5beASdPpDgYmamKXnMvcKP5avG+jK6yvA63Ja+4xycncmIVCpBzCja5HNbBGzD3Fu/IlcnMXZ8M8hZomslDPPvWDcZkPRrs0qWT4OKjUI7KujjY/higXqjbGBwFhIPYcur6wcfsTRgjkcv5qV7uor0LXm93ewYPIgawe+x6kyFTmohpDhuRPzONTNHvj3loIX7KXn/6BaeDPkK7pHulkKN2WxSuVVVbVIUzH96RmEcCuP/pzmtrOk5C49XoRkvdOt69b4RKdU56aToLMh0/qN7w== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by DBAPR03MB6406.eurprd03.prod.outlook.com (2603:10a6:10:190::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Wed, 26 Jan 2022 21:35:14 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%4]) with mapi id 15.20.4930.017; Wed, 26 Jan 2022 21:35:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 26 Jan 2022 22:34:46 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [bu/RPaO3BtrsAZavSKMwiNSM3gCjUutW] X-ClientProxiedBy: AM3PR03CA0066.eurprd03.prod.outlook.com (2603:10a6:207:5::24) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220126213451.1887291-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f4cc803f-74b1-4e09-b5f8-08d9e113bcdd X-MS-TrafficTypeDiagnostic: DBAPR03MB6406:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RGeCmZmWBRK9Sl/2SRbqqizspcKv92NxkZSlUjvC35FKDnfLXyvgQ/ZDx3FOSS4tClA+7C0YJMYgZqj7WL2DvUyESKrBjQqvgn6ylEYwFvKqkSiQ9+ZoiAS/A15dQZG/9Ksrp7D0oPXIbxY6oo6tRW6+jY5jBspNxtPWRHwmhgSC2dHNthc3Ru86nw/UAZlgKj2nvIjfbQ/NLbkloM4wpAZgMWSfGiU2YiNOXnWJ8hazGous+IPy4uNthDiREy0SrVel6eoGRR5bzE6EDNIbIopZrM77zHbeRjgb5EQuUYiIiZZlwPFREtP7WDVT9HpXiNiBZuNdDENtpbPzvJBAzIpvD/COOzeijuzdjhuwEE1p+Lp7jHGNbn/ANRD+dx7vaYw3QIVXY3nKrJiMX3cxTYEEzCepT0Xe+zbFePVv7qERkt3n2krRUndwLAKKbd5p+285a7K+NVoZk68ND7DF9FixCMNyWjq2Yn89i+LQ1Fxp6ceC2KnaO+8XT9RlLTo7I+2rcw7qNbR5LtjUKlAecRiY+recWRlROs4yvgkP4dKgsh7OlF8XJGrr9Ay9LcFf X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v/dSYRUVuqg1OZSnsbJPPhhP1D0S3Qd2ErMCuH4+Z5RLAxvNsDbiv7lJMyixQbaDlF1ESmlrktYz6ce+aijGWDoqzY5SzzgVopEOcwdTKMuptmej2dNu8uvEVYuAn/uskGzmE6/E6wtNst0taZ8xvgtJdomGITNB80XPbqP5tTAaQLC7LZWZ+LjX7ia+R/N4GKwvXiGTvVsu/hkDvaVnZe6jlfeM9DMyGRPXnf+G6JvMTIocz7O6Adp4Sjjok0hj74xZ+oHHApE+OVK8Y/zIkSnEuwAPK4LxduxgSObbH8zBzSyVp4KOFQi0l1A+P4SxRFf6hIruchEXt8I4gjI6kbduAPq8IztbIaOYEJThRiKAvYbJHrerM960YVukxeoZXH1czq8UEDPad6Dom3dooj5jlIyqgkDQ10OWp9fqbPHxivoALATWCW8By7A159ZIXPHhRiT+mI8eObTaXvbdBd3+6Rj8zq4wgcrx+LLhojX01ohUDVVMNR09fIcPrwxZow3acFcnKLoqVDqvi9TzydbZzHkbtHiDIPqp+U1si7YSh7V+rAhWsO0srGVNyU/jO0f5ndD+ntyENZLKEUFvF00mcBkC57/oEPqgxl1VLQY/ljio373EDhH4iV8sdzZ3iB7IlSROUWEjn3OydnpAHpCcl+BJt4lFVB3x+dhW8QGgaK1Ym2tOwienXEC2ykFj7XXadg675sg7FwjW/77GFDUWup8XY5aB7pWLcd2Qdf2t8zccDY7gWy4MFU63suEyUTsQ5H/9IwQOD73JT8moBLYN7/gpj0rhyPYBFw6ujSF2dTjKku1NwzedhpuMTGZmL3YQnRIxf6fFW4LBrjLdp8y3UtoaWGE0TZhIkt0+d8qUaLs2nf+on1rWY5Uw7X0OcZxGEOHAMcJiulw2fWLp73IYOmkOq3Q2Qe9aEE2X3BKMxvIyZx7fBF7z0zELnTw9Bs4u8nGSS7K3vFnrWeN6mg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f4cc803f-74b1-4e09-b5f8-08d9e113bcdd X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2022 21:35:13.9861 (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: DBAPR03MB6406 Subject: [FFmpeg-devel] [PATCH 28/33] avcodec/mpegvideo: Move MPEG-4 Simple Studio Profile fields to mpeg4video 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: eGxCeiaXiRFQ This is possible now that dealing with the Simple Studio Profile has been moved to mpeg4videodec.c. It also allows to avoid allocations, because one can simply put the required buffers on the context (if one made these buffers part of MpegEncContext, the memory would be wasted for every codec other than MPEG-4). Signed-off-by: Andreas Rheinhardt --- libavcodec/mpeg4video.h | 5 +++++ libavcodec/mpeg4videodec.c | 44 ++++++++++++++++++++------------------ libavcodec/mpegvideo.c | 13 ----------- libavcodec/mpegvideo.h | 4 ---- 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h index 08beb7f29f..9fc79b1a22 100644 --- a/libavcodec/mpeg4video.h +++ b/libavcodec/mpeg4video.h @@ -117,6 +117,11 @@ typedef struct Mpeg4DecContext { int cplx_estimation_trash_b; int rgb; + + int32_t block32[12][64]; + // 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan + int dpcm_direction; + int16_t dpcm_macroblock[3][256]; } Mpeg4DecContext; diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index fb43ad2d17..b8118ff2d2 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -71,32 +71,33 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb uint8_t *dest_cr, int block_size, int uvlinesize, int dct_linesize, int dct_offset) { + Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; const int act_block_size = block_size * 2; - if (s->dpcm_direction == 0) { - s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)(*s->block32)[0]); - s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)(*s->block32)[1]); - s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)(*s->block32)[2]); - s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)(*s->block32)[3]); + if (ctx->dpcm_direction == 0) { + s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)ctx->block32[0]); + s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)ctx->block32[1]); + s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)ctx->block32[2]); + s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)ctx->block32[3]); dct_linesize = uvlinesize << s->interlaced_dct; dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; - s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)(*s->block32)[4]); - s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)(*s->block32)[5]); - s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)(*s->block32)[6]); - s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)(*s->block32)[7]); + s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)ctx->block32[4]); + s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)ctx->block32[5]); + s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)ctx->block32[6]); + s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)ctx->block32[7]); if (!s->chroma_x_shift){ //Chroma444 - s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)(*s->block32)[8]); - s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)(*s->block32)[9]); - s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[10]); - s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[11]); + s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)ctx->block32[8]); + s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)ctx->block32[9]); + s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)ctx->block32[10]); + s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)ctx->block32[11]); } - } else if(s->dpcm_direction == 1) { + } else if (ctx->dpcm_direction == 1) { uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr}; int linesize[3] = {dct_linesize, uvlinesize, uvlinesize}; for (int i = 0; i < 3; i++) { - const uint16_t *src = (*s->dpcm_macroblock)[i]; + const uint16_t *src = ctx->dpcm_macroblock[i]; int vsub = i ? s->chroma_y_shift : 0; int hsub = i ? s->chroma_x_shift : 0; int lowres = s->avctx->lowres; @@ -111,9 +112,9 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb } else { uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr}; int linesize[3] = {dct_linesize, uvlinesize, uvlinesize}; - av_assert2(s->dpcm_direction == -1); + av_assert2(ctx->dpcm_direction == -1); for (int i = 0; i < 3; i++) { - const uint16_t *src = (*s->dpcm_macroblock)[i]; + const uint16_t *src = ctx->dpcm_macroblock[i]; int vsub = i ? s->chroma_y_shift : 0; int hsub = i ? s->chroma_x_shift : 0; int lowres = s->avctx->lowres; @@ -2078,9 +2079,10 @@ static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[25 static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64]) { + Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s; int i; - s->dpcm_direction = 0; + ctx->dpcm_direction = 0; /* StudioMacroblock */ /* Assumes I-VOP */ @@ -2094,15 +2096,15 @@ static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64]) } for (i = 0; i < mpeg4_block_count[s->chroma_format]; i++) { - if (mpeg4_decode_studio_block(s, (*s->block32)[i], i) < 0) + if (mpeg4_decode_studio_block(s, ctx->block32[i], i) < 0) return AVERROR_INVALIDDATA; } } else { /* DPCM */ check_marker(s->avctx, &s->gb, "DPCM block start"); - s->dpcm_direction = get_bits1(&s->gb) ? -1 : 1; + ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1; for (i = 0; i < 3; i++) { - if (mpeg4_decode_dpcm_macroblock(s, (*s->dpcm_macroblock)[i], i) < 0) + if (mpeg4_decode_dpcm_macroblock(s, ctx->dpcm_macroblock[i], i) < 0) return AVERROR_INVALIDDATA; } } diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index a231ee52b7..3b889e0791 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -378,11 +378,6 @@ static int init_duplicate_context(MpegEncContext *s) } if (s->out_format == FMT_H263) { - if (!(s->block32 = av_mallocz(sizeof(*s->block32))) || - !(s->dpcm_macroblock = av_mallocz(sizeof(*s->dpcm_macroblock)))) - return AVERROR(ENOMEM); - s->dpcm_direction = 0; - /* ac values */ if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size)) return AVERROR(ENOMEM); @@ -434,8 +429,6 @@ static void free_duplicate_context(MpegEncContext *s) av_freep(&s->me.map); av_freep(&s->me.score_map); av_freep(&s->blocks); - av_freep(&s->block32); - av_freep(&s->dpcm_macroblock); av_freep(&s->ac_val_base); s->block = NULL; } @@ -462,9 +455,6 @@ static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src) COPY(me.score_map); COPY(blocks); COPY(block); - COPY(block32); - COPY(dpcm_macroblock); - COPY(dpcm_direction); COPY(start_mb_y); COPY(end_mb_y); COPY(me.map_generation); @@ -678,10 +668,7 @@ static void clear_context(MpegEncContext *s) s->dct_error_sum = NULL; s->block = NULL; s->blocks = NULL; - s->block32 = NULL; memset(s->pblocks, 0, sizeof(s->pblocks)); - s->dpcm_direction = 0; - s->dpcm_macroblock = NULL; s->ac_val_base = NULL; s->ac_val[0] = s->ac_val[1] = diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 0b76a460c9..325f62e01f 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -479,10 +479,6 @@ typedef struct MpegEncContext { int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch() - int32_t (*block32)[12][64]; - int dpcm_direction; // 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan - int16_t (*dpcm_macroblock)[3][256]; - #define SLICE_OK 0 #define SLICE_ERROR -1 #define SLICE_END -2 ///