From patchwork Thu Apr 29 23:56:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27518 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp2015735pxb; Thu, 29 Apr 2021 16:59:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh4cbLVfa9wXznwH1NAsYihLUeCUUTLS36/VR6xA3G+Mv98pQKSSDOGEOYCrTkGXCmdZn3 X-Received: by 2002:a50:ee88:: with SMTP id f8mr2521357edr.176.1619740799032; Thu, 29 Apr 2021 16:59:59 -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 dy11si90306edb.47.2021.04.29.16.59.58; Thu, 29 Apr 2021 16:59:59 -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=sg6p4IRu; 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 6E6A368A2F4; Fri, 30 Apr 2021 02:59:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-DB8-obe.outbound.protection.outlook.com (mail-db8eur06olkn2064.outbound.protection.outlook.com [40.92.51.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D87768A0E7 for ; Fri, 30 Apr 2021 02:59:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e3z1v+gF9eI66k81KM3tIcl08Urq1GtPQAcHuvSYypOaeHots+6FhKmC+zVOvwmDpizLhpzVoVBC7kTNzmBCcMln24ga3TVIw30QCd51I7LU61Nu50OnvkV3Iuiu7xuTBoU0kWbea37AJtOfiRZ/PWr2EMXNRVvWSfmFb2EaS9ZT1Oh78okY9eDLEXb5VcK3KrPsUUzHLu/dkHSkdyZK3lIoWjrPtnNRH4qKx6IT7H2Ep00Y81O0HgJys7mQ3dQ088kr9sGtnZ8VAUymtzZaFqIQULcfjf/Axw02tK6o9Iy9f/OVvETwS/I96+C57EcOP02GJsH2IvZ3KXZpv6Q2lw== 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-SenderADCheck; bh=o5g+VrBHlLskhK4m7FMSYvb28SfVnDikzD/RGR2xenE=; b=OBY1wRvXLAW9qUdy9mB1wpHP7+O+i8ylgJDCmUCrs0hZ7nz0dKAyPYC/EC4qx6ck2VMUgP+R0aTtpssjMc9B4k+ZWckL6y25yiNLcdnsnbNnn+PUYujOVg9BwBBAVkkrpjQ93BugZjWSg5IkPsvDuCS2E1G8JseUySE4tVa0M4hhmfqzQ6XrSVVVaYrl1DYVF6EA7VH64Cd/vKI7hrtBhGLgy1gGmcvSEZY0oq/smZCn5+6JkEom3YJmDEm7vjaVLlTMOg1KVmfp4cna+qVnqVkJdH0A+NUxwZyqNEIE8zx48WkPUP51Ws5DIVymA8D8ZIMFXdkgrx5fzoKPW5kGBw== 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=o5g+VrBHlLskhK4m7FMSYvb28SfVnDikzD/RGR2xenE=; b=sg6p4IRudcOg5eEO9Ol60WOmgXfoEDoMetw8PPthgYMNAjf76NSFceySqoK2vcRnTD9Dd3qaBml8IWwJeXB2SP/HvRhJrKm9NjAT1Qqa3GCbUk9aGeTj8q4j5uRfEF96RebDpbGLhMC6hlfpbmIBQG3LxqpE14giyzAPtckfK3MIUAn7N65i3M4dAHgzdt+aoWYlzDZizaGlrq+crs/9rV+7PFP1VCyiJv2iILpgQzQau87fAUPG6NCfkHwAFpfJ8zUpsvbBOks2vYFFlxHAu/1g0MMyX4KS/Ne7YH+nDTlrjBZ7iYav5YHboLhOlF4cQLXQpT32p04bRmd9pCOwmQ== Received: from AM7EUR06FT005.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::42) by AM7EUR06HT005.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::390) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27; Thu, 29 Apr 2021 23:59:12 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::4c) by AM7EUR06FT005.mail.protection.outlook.com (2a01:111:e400:fc36::397) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Thu, 29 Apr 2021 23:59:12 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:95AE43D53313AD656B8ACA3365924F450F8ED33F918563F648D731EAADB9AE45; UpperCasedChecksum:2E19A607ABE0CB95D9C5191300BE8F6D0CFFF007B0B79B8D2E7855E0FE1AF94B; SizeAsReceived:7611; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4065.027; Thu, 29 Apr 2021 23:59:12 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Apr 2021 01:56:47 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [LMqUTPkDoYRCRrhijloYeOw8rUBxA3M7] X-ClientProxiedBy: ZR0P278CA0088.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::21) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210429235717.2067041-15-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.193.248.86) by ZR0P278CA0088.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Thu, 29 Apr 2021 23:59:12 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 8732145a-97bd-4a2b-f874-08d90b6ac998 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnJqnaHo6w7XTEhYoMxTOUdiV/cvqPi1sITop5PsqPFqeg3i6sSnQc/V694WYln2h7EOK5he6qVgvVOLXqmZohgXemGikRVE/0ktZDjCb4gjtUgOiRjATa4iOOrDZU/w33jjAfZnoHZdG5Ek0TFgLOvHc2iXBiDbR/TugPfsNsw6Hf5HMpB6WEFeR5c92B75N7pJ0xwWE6Du8N04Z6khqI+IbXMSnVtGwSMBrbZnHH8Q27+32HXJz0NgUM2wonmQy9GTbbv3JlQJhqJt29dk+QtUnMxnrggNuRRZT97MFnbTF9Prm7/TGzqUi1jgIy1os1wkDmTlKvUdaLgdQgjUiPobZ7jbxgr+p+dmfNkP2oX76vVdbl8THPpM/NbrKvSg27heXsrV8yIVUjQk7CJiNq7RK1V0XgE7u9eGPgnOfg9bgs04P3P7vhxIZAUHeeZBMaJrO7Y9MGf3J17RgQm1siOfRrt0cC26QNvJDtHJLgxRNsgTL5GUxP7gq4UN5Prr2wHl8Pacebcqu3gFt7ap58hd72775G/Fl4yU/ve668C2Ea4WR91jLf4F/L62RLFDYYP//7Qx/m04t7lO30FA/TclrkwaAeRezdJISkatDjvdmz5AJ/QpBScfQhUOcy0LbvDMrpKstbpagDkW87zinq2mBKA+v7JrIjb7/XvuhxuXP93eVSn4F6Dj5dn+qfKxTy0J9rx8+CKjXX4hk7V/gKBbLoio+F2NWiXm9UrSHk+9PXiB/UM0AK0EF6ZeF1uhQ= X-MS-TrafficTypeDiagnostic: AM7EUR06HT005: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A45HUZHDdfn2+Zc2HEfmFJdMSLoniG/NRQjMfQs1Rwyb0V6lIANIv/hOAjPaYAEkpemSViuW6caO6gVahw/Dnm5qjL94zLa+uGR8CxShFbMnllSvHcCmqtyPCGABEbelmsdpdwpShA6xgnDz3wlGbN8oS1CqcaqDenVWnApg6y4Mn7aD/WwoZsPM75C+EfWCpPPFhAfCCayMZ7APBz3odtQBpgMer48X/k2wIHagzSDP4jtmo+3ZzyHdwi5okCm78NNUUnlKyVr61VNuxjtEyvTYjRS93wkwJ9vw55HX5eTAQpSfrIlZE7Lj4G7QvKjxvP4vVkTLQlxLLQ6sMuJLd4S+sufVpTt+6bSkO07oCipQqdhGl6uFHsJAhkGvF4tKboJspvam+hxq47/9jKsrxA== X-MS-Exchange-AntiSpam-MessageData: oS3m+/jyfByunrScZczcOZ+oaV9XbSQD/dAPRO+aHiSwCd/h04pMaN9joTLljgsZGc17HRXYc7VMC2dd722wLLxaBtvEYxfZRgSB7HY1L0DsLgsC2t30UC+7ioqH7RaCaVZePEnMKpViT+nVDbQNsw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8732145a-97bd-4a2b-f874-08d90b6ac998 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2021 23:59:12.7899 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT005.eop-eur06.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7EUR06HT005 Subject: [FFmpeg-devel] [PATCH 16/46] avcodec/dpxenc: Avoid copying packet data, allow user-supplied buffers 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: 5vuMgIn0bfAr When the packet size is known in advance like here, one can avoid an intermediate buffer for the packet data; this also makes it easy to allow user-supplied buffers. Only one thing needed to be changed: One can no longer use a pointer to uint16_t for the destination buffer because its alignment is unknown. Signed-off-by: Andreas Rheinhardt --- libavcodec/dpxenc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libavcodec/dpxenc.c b/libavcodec/dpxenc.c index 615623bf94..1213ea71c3 100644 --- a/libavcodec/dpxenc.c +++ b/libavcodec/dpxenc.c @@ -23,6 +23,7 @@ #include "libavutil/intreadwrite.h" #include "libavutil/imgutils.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" typedef struct DPXContext { @@ -142,7 +143,7 @@ static void encode_gbrp10(AVCodecContext *avctx, const AVFrame *pic, uint8_t *ds } } -static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint16_t *dst) +static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint8_t *dst) { DPXContext *s = avctx->priv_data; const uint16_t *src[3] = {(uint16_t*)pic->data[0], @@ -163,11 +164,11 @@ static void encode_gbrp12(AVCodecContext *avctx, const AVFrame *pic, uint16_t *d value[2] = AV_RL16(src[1] + x) << 4; value[0] = AV_RL16(src[2] + x) << 4; } - for (i = 0; i < 3; i++) - write16(dst++, value[i]); + for (i = 0; i < 3; i++, dst += 2) + write16(dst, value[i]); } - for (i = 0; i < pad; i++) - *dst++ = 0; + for (i = 0; i < pad; i++, dst += 2) + AV_WN16(dst, 0); for (i = 0; i < 3; i++) src[i] += pic->linesize[i]/2; } @@ -196,7 +197,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, need_align = size - len; size *= avctx->height; } - if ((ret = ff_alloc_packet2(avctx, pkt, size + HEADER_SIZE, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, size + HEADER_SIZE, 0)) < 0) return ret; buf = pkt->data; @@ -259,7 +260,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, encode_rgb48_10bit(avctx, frame, buf + HEADER_SIZE); break; case 12: - encode_gbrp12(avctx, frame, (uint16_t*)(buf + HEADER_SIZE)); + encode_gbrp12(avctx, frame, buf + HEADER_SIZE); break; default: av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component); @@ -281,6 +282,7 @@ const AVCodec ff_dpx_encoder = { .long_name = NULL_IF_CONFIG_SMALL("DPX (Digital Picture Exchange) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_DPX, + .capabilities = AV_CODEC_CAP_DR1, .priv_data_size = sizeof(DPXContext), .init = encode_init, .encode2 = encode_frame,