From patchwork Sun Oct 2 00:06:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38510 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp527769pzh; Sat, 1 Oct 2022 17:08:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Z/CCR1Mh2hTqwLtrt+0epApOTHg1MyrJiT9bW2CGRMtcT+Swl8QmmKkI6IEjpfFOGdFC5 X-Received: by 2002:a05:6402:181:b0:456:692f:d0b3 with SMTP id r1-20020a056402018100b00456692fd0b3mr13017930edv.190.1664669320986; Sat, 01 Oct 2022 17:08:40 -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 b20-20020aa7c6d4000000b00457563c4196si4137873eds.595.2022.10.01.17.08.39; Sat, 01 Oct 2022 17:08:40 -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=g23L5md9; 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 01F4768BB98; Sun, 2 Oct 2022 03:08:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-oln040092066075.outbound.protection.outlook.com [40.92.66.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D664A68BB70 for ; Sun, 2 Oct 2022 03:08:27 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O2MP1HOLgSzrEScD5ZqiZMYIBQW3qKnX5RAcc+HPrGJbOFbwjuq+6YZpxUoxcWBjlXPTH3A7XFVFbUPtB9MkcfjKhirw4gVENT5Y3T3YIFpCRZUyl8zV8pOYfO/4T3EwvRpIXnXJGc69WL7fzWEmfgfjlixJIYha2Z2+CgRCEFt7vnUNHPekBPwlr9xHfXQ7NXJyFW09ITymNbXiH/ZkfW96LODObI5bnjK2Dm7PZm5R3wtaPNIfl6uY6HdZGAThmK492Cozv2XC+13lEleEeOb545XmB1mBUdYYb4Pta4mKIirC+m1D4A8PW3kYbTyYLRoz83E5H5Ef8DXOZVlbuA== 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=NuzLzpqFIghcLXYAhhaxz/AmlkY6Hi3r3T+Hciqrzlc=; b=Y5wjBrkRy4zXO2eAYT2+Qf+MqIA0bhMfAVop3+ZLcqSHL7SyZWctdg8nAEDIAylxE0qtwbiKIcai4TPabYf6wa33vrqhR4Ijq2FjzsaW6g0PF60143hVQd4UMlAwKjnze3UHRvtIPxKKY6Te29FeXYPTkYJdIAkGQjYFORaczQ4ku1KdRiT1e/awV2q9Csy810wxtdGnMzO7Rak+vCD2zX0X4yiZiIPg1v0qRwiVRmJ/HKaxqPdBg49XwwV+CMELRwXIDSim5PGRgPHTZ6yaIex8UfRXo/oSy7J6oDSysFATE6M2tHzx2XGc+EVaK6xn1Q/CGC5ZN1++3TeKEW3gvg== 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=NuzLzpqFIghcLXYAhhaxz/AmlkY6Hi3r3T+Hciqrzlc=; b=g23L5md9yQnN6vQcFNgJhW0o0w5Us+nSOcJCjJX6UQyGzgXX3iXpeh/HxPC8aCCk2/a+b9cAg59Q4IUMLGG50aIdxEG3/52WIT0W4rSlENtmdU9zw+5Sx5IljSIVkt6/uWuKzGd1z7V4up24eVrtHXte1gkl9iJdJyBTdN4tXWWnE8VqnRDui2begoMR9rC5nU5tu8Hk5TyScDKs6/6pudxrDxJLKAi3ypSySbWjwMgDHbAXQhqat2GpOjJvWE3pRKT6IT41ex/M+KMrQy9MlhoWxdGXtjHHdAWchhx/zCGIQrA2eirrn4c7LVTG31b2Djs/BIlKwxu0V8M+uAlBSw== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by GV2P250MB0997.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:d7::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.23; Sun, 2 Oct 2022 00:08:26 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5676.023; Sun, 2 Oct 2022 00:08:26 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 2 Oct 2022 02:06:16 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [kN91erTpNcjpU6rOblEYzQLTSnqBRYkoUrHkFQt/1Fk=] X-ClientProxiedBy: ZR2P278CA0010.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:50::14) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20221002000617.469194-12-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|GV2P250MB0997:EE_ X-MS-Office365-Filtering-Correlation-Id: fb2efb0c-de57-46d3-c193-08daa40a3a5a X-MS-Exchange-SLBlob-MailProps: ZILSnhm0P3nPH8ePuXi+6dv+20UuINthAy18GYZ7tfFad5/EgzgU65Xgmlrj17X/6eFQ7WmjtoW+SMl/hwUQ0VDakvxzk03RIYThd8yorqeS2Tgx+/iwlZmg60fQDXxP9H0hNAuDbnsdoyLM8JgYaCoivVurSFFpoyzVCS6w0Y/sKGUmf2VJi5Bne1GzoZjmIMuWB/qcN599Ibcn0AOAz/NzPyLfNA5UzmU2jP8je/Z+6RV470xJ+Yqfdie19F2AYQElZZ4NnmGHdcHfd6ptZq3dPQySHB176TgSo7dxNVAddV8Z8kJvj+xZBbbWcoVCZKpoMUGyfCG9FqiAXGvpHlZEyUyK7lP1DF8PMUv7iUb4vpVAO1II34VCaZPjn3GwH4Q3XwH7pV5hmqbYn6MwVY2gGORZGSxE+r7GBMwV181Y2Af3gnfgssRlbHCErZigJLTmJaEdAFk5L9xiq2I6+EOKpNm7V8qRzXrAtjNHr8RoISFeNeFTjWm/2tyekC9u9K5g8kAh4IeE2uPCEFY/s5chFRAJfuV1xlKRjnUzVqS+Lv9Kq/04YEvDC83SvCvWbRN+WaIuRbJ7l8HZkmuXpggfTKS07Try1er8T4+zGUTQ+Xi4gZqDZyBLMx+J81xZni06B0pEgQsWP6gX8sR9Sz8DpKWt7KM8BbpWKr/BOnXe9X5pWh/xzluIWsjcqm0QPL67GQGWeNV2fAmf7Q0yzr7Pcy6WD1IRUekFWPozsbKGqK8Yi3ctjOnHTq8YAkBMLrQ5uFMftUT1PuC81oei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MS-Exchange-CrossTenant-Network-Message-Id: fb2efb0c-de57-46d3-c193-08daa40a3a5a X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2022 00:08:26.4032 (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: GV2P250MB0997 Subject: [FFmpeg-devel] [PATCH 13/14] avcodec/huffyuv: Split HYuvContext into decoder and encoder context 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: Ns5KYm1yhOFR While the share of elements used by both is quite big, the amount of code shared between the decoders and encoders is negligible. Therefore one can easily split the context if one wants to. The reasons for doing so are that the non-shared elements are non-negligible: The stats array which is only used by the encoder takes 524288B of 868904B (on x64); similarly, pix_bgr_map which is only used by the decoder takes 16KiB. Furthermore, using a shared context also entails inclusions of unneeded headers like put_bits.h for the decoder and get_bits.h for the encoder (and all of these and much more for huffyuv.c). Signed-off-by: Andreas Rheinhardt --- libavcodec/huffyuv.c | 19 +++++----- libavcodec/huffyuv.h | 68 ++++++++--------------------------- libavcodec/huffyuvdec.c | 80 ++++++++++++++++++++++++++++++----------- libavcodec/huffyuvdsp.c | 1 + libavcodec/huffyuvdsp.h | 13 ------- libavcodec/huffyuvenc.c | 73 +++++++++++++++++++++++++++---------- 6 files changed, 139 insertions(+), 115 deletions(-) diff --git a/libavcodec/huffyuv.c b/libavcodec/huffyuv.c index 23a2bb2537..bbe4b952b0 100644 --- a/libavcodec/huffyuv.c +++ b/libavcodec/huffyuv.c @@ -30,10 +30,11 @@ #include +#include "libavutil/attributes.h" +#include "libavutil/error.h" +#include "libavutil/log.h" #include "libavutil/mem.h" -#include "avcodec.h" -#include "bswapdsp.h" #include "huffyuv.h" int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int n) @@ -55,25 +56,25 @@ int ff_huffyuv_generate_bits_table(uint32_t *dst, const uint8_t *len_table, int return 0; } -av_cold int ff_huffyuv_alloc_temp(HYuvContext *s, int width) +av_cold int ff_huffyuv_alloc_temp(uint8_t *temp[3], uint16_t *temp16[3], int width) { int i; for (i=0; i<3; i++) { - s->temp[i] = av_malloc(4 * width + 16); - if (!s->temp[i]) + temp[i] = av_malloc(4 * width + 16); + if (!temp[i]) return AVERROR(ENOMEM); - s->temp16[i] = (uint16_t*)s->temp[i]; + temp16[i] = (uint16_t*)temp[i]; } return 0; } -av_cold void ff_huffyuv_common_end(HYuvContext *s) +av_cold void ff_huffyuv_common_end(uint8_t *temp[3], uint16_t *temp16[3]) { int i; for(i = 0; i < 3; i++) { - av_freep(&s->temp[i]); - s->temp16[i] = NULL; + av_freep(&temp[i]); + temp16[i] = NULL; } } diff --git a/libavcodec/huffyuv.h b/libavcodec/huffyuv.h index 823a091809..6cc48bf57d 100644 --- a/libavcodec/huffyuv.h +++ b/libavcodec/huffyuv.h @@ -31,16 +31,19 @@ #include -#include "avcodec.h" -#include "bswapdsp.h" -#include "get_bits.h" -#include "huffyuvdsp.h" -#include "huffyuvencdsp.h" -#include "put_bits.h" -#include "lossless_videodsp.h" -#include "lossless_videoencdsp.h" - -#define VLC_BITS 12 +#include "config.h" + +#if HAVE_BIGENDIAN +#define B 3 +#define G 2 +#define R 1 +#define A 0 +#else +#define B 0 +#define G 1 +#define R 2 +#define A 3 +#endif #define MAX_BITS 16 #define MAX_N (1<priv_data; + HYuvDecContext *s = avctx->priv_data; int i; - ff_huffyuv_common_end(s); + ff_huffyuv_common_end(s->temp, s->temp16); av_freep(&s->bitstream_buffer); for (i = 0; i < 8; i++) @@ -293,7 +331,7 @@ static av_cold int decode_end(AVCodecContext *avctx) static av_cold int decode_init(AVCodecContext *avctx) { - HYuvContext *s = avctx->priv_data; + HYuvDecContext *s = avctx->priv_data; int ret; ret = av_image_check_size(avctx->width, avctx->height, 0, avctx); @@ -559,7 +597,7 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - if ((ret = ff_huffyuv_alloc_temp(s, avctx->width)) < 0) + if ((ret = ff_huffyuv_alloc_temp(s->temp, s->temp16, avctx->width)) < 0) return ret; return 0; @@ -618,7 +656,7 @@ static av_cold int decode_init(AVCodecContext *avctx) GET_VLC_DUAL(dst0, dst1, re, &s->gb, s->vlc[4+plane1].table, \ s->vlc[0].table, s->vlc[plane1].table, VLC_BITS, 3, OP8bits) -static void decode_422_bitstream(HYuvContext *s, int count) +static void decode_422_bitstream(HYuvDecContext *s, int count) { int i, icount; OPEN_READER(re, &s->gb); @@ -662,7 +700,7 @@ static void decode_422_bitstream(HYuvContext *s, int count) dst1 = get_vlc2(&s->gb, s->vlc[plane].table, VLC_BITS, 3)<<2;\ dst1 += get_bits(&s->gb, 2);\ } -static void decode_plane_bitstream(HYuvContext *s, int width, int plane) +static void decode_plane_bitstream(HYuvDecContext *s, int width, int plane) { int i, count = width/2; @@ -723,7 +761,7 @@ static void decode_plane_bitstream(HYuvContext *s, int width, int plane) } } -static void decode_gray_bitstream(HYuvContext *s, int count) +static void decode_gray_bitstream(HYuvDecContext *s, int count) { int i; OPEN_READER(re, &s->gb); @@ -741,7 +779,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count) CLOSE_READER(re, &s->gb); } -static av_always_inline void decode_bgr_1(HYuvContext *s, int count, +static av_always_inline void decode_bgr_1(HYuvDecContext *s, int count, int decorrelate, int alpha) { int i; @@ -799,7 +837,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count, CLOSE_READER(re, &s->gb); } -static void decode_bgr_bitstream(HYuvContext *s, int count) +static void decode_bgr_bitstream(HYuvDecContext *s, int count) { if (s->decorrelate) { if (s->bitstream_bpp == 24) @@ -814,7 +852,7 @@ static void decode_bgr_bitstream(HYuvContext *s, int count) } } -static void draw_slice(HYuvContext *s, AVCodecContext *avctx, AVFrame *frame, int y) +static void draw_slice(HYuvDecContext *s, AVCodecContext *avctx, AVFrame *frame, int y) { int h, cy, i; int offset[AV_NUM_DATA_POINTERS]; @@ -842,7 +880,7 @@ static void draw_slice(HYuvContext *s, AVCodecContext *avctx, AVFrame *frame, in s->last_slice_end = y + h; } -static int left_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, int w, int acc) +static int left_prediction(HYuvDecContext *s, uint8_t *dst, const uint8_t *src, int w, int acc) { if (s->bps <= 8) { return s->llviddsp.add_left_pred(dst, src, w, acc); @@ -851,7 +889,7 @@ static int left_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, int } } -static void add_bytes(HYuvContext *s, uint8_t *dst, uint8_t *src, int w) +static void add_bytes(HYuvDecContext *s, uint8_t *dst, uint8_t *src, int w) { if (s->bps <= 8) { s->llviddsp.add_bytes(dst, src, w); @@ -860,7 +898,7 @@ static void add_bytes(HYuvContext *s, uint8_t *dst, uint8_t *src, int w) } } -static void add_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src, const uint8_t *diff, int w, int *left, int *left_top) +static void add_median_prediction(HYuvDecContext *s, uint8_t *dst, const uint8_t *src, const uint8_t *diff, int w, int *left, int *left_top) { if (s->bps <= 8) { s->llviddsp.add_median_pred(dst, src, diff, w, left, left_top); @@ -872,7 +910,7 @@ static void add_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *s static int decode_slice(AVCodecContext *avctx, AVFrame *p, int height, int buf_size, int y_offset, int table_size) { - HYuvContext *s = avctx->priv_data; + HYuvDecContext *s = avctx->priv_data; int fake_ystride, fake_ustride, fake_vstride; const int width = avctx->width; const int width2 = avctx->width >> 1; @@ -1185,7 +1223,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p, { const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - HYuvContext *s = avctx->priv_data; + HYuvDecContext *s = avctx->priv_data; const int width = avctx->width; const int height = avctx->height; int slice, table_size = 0, ret, nb_slices; @@ -1268,7 +1306,7 @@ const FFCodec ff_huffyuv_decoder = { CODEC_LONG_NAME("Huffyuv / HuffYUV"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_HUFFYUV, - .priv_data_size = sizeof(HYuvContext), + .priv_data_size = sizeof(HYuvDecContext), .init = decode_init, .close = decode_end, FF_CODEC_DECODE_CB(decode_frame), @@ -1283,7 +1321,7 @@ const FFCodec ff_ffvhuff_decoder = { CODEC_LONG_NAME("Huffyuv FFmpeg variant"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_FFVHUFF, - .priv_data_size = sizeof(HYuvContext), + .priv_data_size = sizeof(HYuvDecContext), .init = decode_init, .close = decode_end, FF_CODEC_DECODE_CB(decode_frame), @@ -1299,7 +1337,7 @@ const FFCodec ff_hymt_decoder = { CODEC_LONG_NAME("HuffYUV MT"), .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_HYMT, - .priv_data_size = sizeof(HYuvContext), + .priv_data_size = sizeof(HYuvDecContext), .init = decode_init, .close = decode_end, FF_CODEC_DECODE_CB(decode_frame), diff --git a/libavcodec/huffyuvdsp.c b/libavcodec/huffyuvdsp.c index 10723b2fca..fb98836cc4 100644 --- a/libavcodec/huffyuvdsp.c +++ b/libavcodec/huffyuvdsp.c @@ -21,6 +21,7 @@ #include "config.h" #include "libavutil/attributes.h" #include "mathops.h" +#include "huffyuv.h" #include "huffyuvdsp.h" // 0x00010001 or 0x0001000100010001 or whatever, depending on the cpu's native arithmetic size diff --git a/libavcodec/huffyuvdsp.h b/libavcodec/huffyuvdsp.h index e5f5b05466..90e50b5429 100644 --- a/libavcodec/huffyuvdsp.h +++ b/libavcodec/huffyuvdsp.h @@ -21,19 +21,6 @@ #include #include "libavutil/pixfmt.h" -#include "config.h" - -#if HAVE_BIGENDIAN -#define B 3 -#define G 2 -#define R 1 -#define A 0 -#else -#define B 0 -#define G 1 -#define R 2 -#define A 3 -#endif typedef struct HuffYUVDSPContext { void (*add_int16)(uint16_t *dst/*align 16*/, const uint16_t *src/*align 16*/, diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index 5293d32d2b..17d2490dc3 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -31,6 +31,7 @@ #include "config_components.h" #include "avcodec.h" +#include "bswapdsp.h" #include "codec_internal.h" #include "encode.h" #include "huffyuv.h" @@ -41,7 +42,39 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" -static inline void diff_bytes(HYuvContext *s, uint8_t *dst, +typedef struct HYuvEncContext { + AVClass *class; + AVCodecContext *avctx; + PutBitContext pb; + Predictor predictor; + int interlaced; + int decorrelate; + int bitstream_bpp; + int version; + int bps; + int n; // 1<bps <= 8) { @@ -51,7 +84,7 @@ static inline void diff_bytes(HYuvContext *s, uint8_t *dst, } } -static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, +static inline int sub_left_prediction(HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int left) { int i; @@ -82,7 +115,7 @@ static inline int sub_left_prediction(HYuvContext *s, uint8_t *dst, } } -static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, +static inline void sub_left_prediction_bgr32(HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha) @@ -118,7 +151,7 @@ static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, *alpha = src[(w - 1) * 4 + A]; } -static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst, +static inline void sub_left_prediction_rgb24(HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue) { @@ -146,7 +179,9 @@ static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst, *blue = src[(w - 1) * 3 + 2]; } -static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top) +static void sub_median_prediction(HYuvEncContext *s, uint8_t *dst, + const uint8_t *src1, const uint8_t *src2, + int w, int *left, int *left_top) { if (s->bps <= 8) { s->llvidencdsp.sub_median_pred(dst, src1, src2, w , left, left_top); @@ -155,7 +190,7 @@ static void sub_median_prediction(HYuvContext *s, uint8_t *dst, const uint8_t *s } } -static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf) +static int store_table(HYuvEncContext *s, const uint8_t *len, uint8_t *buf) { int i; int index = 0; @@ -180,7 +215,7 @@ static int store_table(HYuvContext *s, const uint8_t *len, uint8_t *buf) return index; } -static int store_huffman_tables(HYuvContext *s, uint8_t *buf) +static int store_huffman_tables(HYuvEncContext *s, uint8_t *buf) { int i, ret; int size = 0; @@ -204,7 +239,7 @@ static int store_huffman_tables(HYuvContext *s, uint8_t *buf) static av_cold int encode_init(AVCodecContext *avctx) { - HYuvContext *s = avctx->priv_data; + HYuvEncContext *s = avctx->priv_data; int i, j; int ret; const AVPixFmtDescriptor *desc; @@ -393,7 +428,7 @@ static av_cold int encode_init(AVCodecContext *avctx) s->stats[i][j]= 0; } - ret = ff_huffyuv_alloc_temp(s, avctx->width); + ret = ff_huffyuv_alloc_temp(s->temp, s->temp16, avctx->width); if (ret < 0) return ret; @@ -401,7 +436,7 @@ static av_cold int encode_init(AVCodecContext *avctx) return 0; } -static int encode_422_bitstream(HYuvContext *s, int offset, int count) +static int encode_422_bitstream(HYuvEncContext *s, int offset, int count) { int i; const uint8_t *y = s->temp[0] + offset; @@ -456,7 +491,7 @@ static int encode_422_bitstream(HYuvContext *s, int offset, int count) return 0; } -static int encode_plane_bitstream(HYuvContext *s, int width, int plane) +static int encode_plane_bitstream(HYuvEncContext *s, int width, int plane) { int i, count = width/2; @@ -618,7 +653,7 @@ static int encode_plane_bitstream(HYuvContext *s, int width, int plane) return 0; } -static int encode_gray_bitstream(HYuvContext *s, int count) +static int encode_gray_bitstream(HYuvEncContext *s, int count) { int i; @@ -663,7 +698,7 @@ static int encode_gray_bitstream(HYuvContext *s, int count) return 0; } -static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes) +static inline int encode_bgra_bitstream(HYuvEncContext *s, int count, int planes) { int i; @@ -716,7 +751,7 @@ static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes) static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { - HYuvContext *s = avctx->priv_data; + HYuvEncContext *s = avctx->priv_data; const int width = avctx->width; const int width2 = avctx->width >> 1; const int height = avctx->height; @@ -996,16 +1031,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, static av_cold int encode_end(AVCodecContext *avctx) { - HYuvContext *s = avctx->priv_data; + HYuvEncContext *s = avctx->priv_data; - ff_huffyuv_common_end(s); + ff_huffyuv_common_end(s->temp, s->temp16); av_freep(&avctx->stats_out); return 0; } -#define OFFSET(x) offsetof(HYuvContext, x) +#define OFFSET(x) offsetof(HYuvEncContext, x) #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM #define COMMON_OPTIONS \ @@ -1048,7 +1083,7 @@ const FFCodec ff_huffyuv_encoder = { .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_HUFFYUV, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, - .priv_data_size = sizeof(HYuvContext), + .priv_data_size = sizeof(HYuvEncContext), .init = encode_init, FF_CODEC_ENCODE_CB(encode_frame), .close = encode_end, @@ -1067,7 +1102,7 @@ const FFCodec ff_ffvhuff_encoder = { .p.type = AVMEDIA_TYPE_VIDEO, .p.id = AV_CODEC_ID_FFVHUFF, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, - .priv_data_size = sizeof(HYuvContext), + .priv_data_size = sizeof(HYuvEncContext), .init = encode_init, FF_CODEC_ENCODE_CB(encode_frame), .close = encode_end,