From patchwork Tue Feb 1 13:06:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33981 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp601167iov; Tue, 1 Feb 2022 05:08:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/eyeadj4ijAUSyiI3Bsv1ExJ757mf1WRb9cF3me4k0TqXEudKcexVLWvjGNObP5/rdAf1 X-Received: by 2002:aa7:da44:: with SMTP id w4mr24949353eds.146.1643720909932; Tue, 01 Feb 2022 05:08:29 -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 dn8si9108402ejc.1000.2022.02.01.05.08.29; Tue, 01 Feb 2022 05:08:29 -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=dHrhQoWu; 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 BFFC068B2D1; Tue, 1 Feb 2022 15:07:39 +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-db8eur05olkn2063.outbound.protection.outlook.com [40.92.89.63]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D308068B2A8 for ; Tue, 1 Feb 2022 15:07:36 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJPScLGoKzovGBRnYTTS3pckQwl59/rg/dNRLqB+gd8X1d8mClwPOI0FVpsX0WvwsFwxNcNxSMnWnwTzV0Ez7FKEn27feBcPP5IJ+8LVeeENe+ly8Ps5tATiAESNemM0Gp/T9gr1s8vmlcd8NCZNnaD1vQusyFrv3zR6n5fwgRqXrZoXD7c+JrOHMs8k+IEm6x/tDbQgqq4Y+PWnVy4DOfZ3cag8B75mNK474IJ1tMPBLKB4tzuC5/P/kkREgF8K4L/JHDV0ke7D7K+3UYpjQ2jZzVozhV2zq3q+dJHrzZWkiSqDRrunycjq+pFxns/KC7VLF9T5+hvXbBOOpC5w/w== 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=e5RcdzWXrLSzX913ql4rGxTnzdBVcWgeF8FZ5CLLymw=; b=S5t/LNUO4VY4lGpq0nqadClSrE+FVrHgESfjZubdaedFWlOW7xlVwidU/FiRALVunuPcChwup3r/Z1cxqT3ySULuBGR0AkGy7PQAPSH7oKJAcO7ec4csV2KJYOqsb/J7/yPf29crg5nc2PrUCkAs8cU6Tv0uXxc6gc6rwP7gIgRA9xKlEYQwuiKRB+n9a3YercAW4tLFVohVgldxxfaf56+wB+pQu4TKSzDib/yIR5kBRnuZSWwuKh7z2WHYV0ZppYDmVAGasojbp1J9x8Qg9bb5EIhEj4KiwNJFI9EbAOWe1iJ5FV10EUrh4AP6/5tnQAOyq3O8xAsdN7Y3CCU5sQ== 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=e5RcdzWXrLSzX913ql4rGxTnzdBVcWgeF8FZ5CLLymw=; b=dHrhQoWunLaKQDdGiaPWyYMD1FuMXcB0yH/J9I0CsksgTIwpzEw12K8e4EXgfW8uYhDLSZxWB1uq3nFhIdY1pNvyd/sFpUXC1VjnQtbEBZgoe4RR5OdVHUbkSBhWha4rmjphs8U/Y2lc82Siid0CryivYRUl2t2cByvpEuHQtosWO5d3z8tB6szKoj+w8rVCCLyyqa9i1rpZwYawGU0T6NaIq9q9fIhDcgxkfU1MkDvuGuZjTP7DC8heOXIN8A2eFhEUsBRL12GdbTeYBS7wn39A1smOMlLX1p9u5QjqUW5uE/VYyOJO2S/8h8nxeYs+bJgX7tTcaTE1VEPnoeypng== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by DB6PR03MB3046.eurprd03.prod.outlook.com (2603:10a6:6:34::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21; Tue, 1 Feb 2022 13:07:26 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4951.011; Tue, 1 Feb 2022 13:07:26 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:03 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [kPAXmCKsPxWt7ETUM+uPkE5sTJ4xiF0i] X-ClientProxiedBy: AM6P195CA0092.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220201130706.1420875-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcd1ca3e-a1ed-4714-975d-08d9e583cb1c X-MS-TrafficTypeDiagnostic: DB6PR03MB3046:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uVOtdER3uoGIs4a0SaBUBaJfoE3ZpogkZ4n8y430uVAaXuR1hlMagOWNIbou2TzN1quqFJQk76gPRX6jOXRFYnVhA0pCeSGkwbW4gEOb0a6QHrGmHB8SPZOTrx+i9QQYFWAGAedzXUcfJUgws6ghkoeoGHqep0HWeYnQr3aBf135LMl/rB+mAMjxEl9eL3EChSXgplpsWrtHWgtK4X7WLv8brRyzli1ai5Pw3bnwP1/YRa2Tcile8TeM2eRfUgiu1ZLUYIESeaNZwP18/+FTJKFGuClVt7ljTh3/TqC5YsDs22vuxP/notGMyI3gWpTT+ZanhEC2q5sN7N1cbPOHFfWdA09KdWgzttAzE2TKu1LgdPQIMdW7pOW5JJ0lQI2yRgwdUAUYWkfcQiD9QBcfSi09dHSvX7uaulCo2aGD4RUqkOoH09fc14jYJ7J2YaBik3ZeSB6a3c0Oi7x8FGxzxyNNKD9V+KQ/NTuO4LEWsKmZ+F+WdIG9cN7dwYMmWodw9i6xnw/CzXvfLjbQK3lbRThc7HjbaB0o6BqfdjHcYMusHsfNr6qOvrzjJ+U7qE8j X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vM9J6aHCulQ45/HT3QVDQiEXDL15QJaHrYS6iq5MThAm5nldhHv7yGhKr7rMZ9TgBOAX/LUXckm7VgJ1rftW2iDy/KaUBrmWC0QBejMd7r2GqaMhhMEprZNFkmF+f4iez2GW1gPwV+7iQ5O+apS4QGs8H9yCzBVCpEbm5K7KAMHycYANEGa6YgIW/UaHGEAIyMUVrWF6VaXeIbM9TQjvbOhq1Il/H34ZwnaXR6IBFrLy67Lj0wQ0jJ1A8DWtHzhRjj5BwX0O/ni5UFbGxTlC6CT7TkvtIDcP43vfrwklIN6c42RCRCp/p+8gPFWNL5DICZbmTWIIdAoYTFGBOK4WrO1lfX+kK3ZnJhwPXTB6ZvIRWgWgxCns3lk6DlHadpsDXR7Zw2xmCHXeSks8D34upv46oO7qU+oKKNfh+xd4ltVQtZWY6LLF61A+Vj7wLfMLQVI+lZUpt93E1bTidDfVbZ0xu+4YCwJaZ3M86rhWbVb9qbGUWPer807ZTaa3hQCJysEZJN8P1vH8uBENBHgDdkTz1xEvJPReOArtPH/MhHaqtzW5JyUZM01Fs8WMUuVCjB9Zueqs5aL/corthsZY3GkWOkP+FnIjnMpG9mqy0zPHtbuANvzM0SYtRLcnbb9mX3YEQkzlNS9d7K7PI7U01XcrlbcDe8GD27/I5cJgmBmnkq3a+k9FLl7wvpYT6qtkQF8BhY6KjtVw+R2qfv/JCyOYaRt7xbxM0i/5ivYlIyfpfyVTm9XXqAaprTEG0vUpRDQTgbmYih5VM42uGoV4j4vKU/KrS2RFjYS/DzsU6N9kMBLqT9QZaMF56kY2JWGFxFulCCT4BPCGvotk1+igyVWy61G7dTEOFmE/MD7vCnukipkqrmadCuceWtcbXXfGBV+8Gt7NX9NcGYw+3sO3eGkZdKm7X1GLn0Ieyiay3amDQZ5Dd0KcvEVWvk1G5AJHeUUXGL/eQcBT359OmRy4rA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcd1ca3e-a1ed-4714-975d-08d9e583cb1c X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 13:07:26.1854 (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: DB6PR03MB3046 Subject: [FFmpeg-devel] [PATCH v2 06/69] avcodec/h261: Separate decode and encode contexts 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: R5Yz1oc228Eu Signed-off-by: Andreas Rheinhardt --- libavcodec/h261.c | 2 +- libavcodec/h261.h | 8 ------ libavcodec/h261dec.c | 59 +++++++++++++++++++++++++++----------------- libavcodec/h261enc.c | 54 +++++++++++++++++++++++++--------------- 4 files changed, 72 insertions(+), 51 deletions(-) diff --git a/libavcodec/h261.c b/libavcodec/h261.c index 1290c040cd..7dfaee7dc4 100644 --- a/libavcodec/h261.c +++ b/libavcodec/h261.c @@ -60,7 +60,7 @@ static void h261_loop_filter(uint8_t *src, int stride) void ff_h261_loop_filter(MpegEncContext *s) { - H261Context *h = (H261Context *)s; + H261Context *const h = s->private_ctx; const int linesize = s->linesize; const int uvlinesize = s->uvlinesize; uint8_t *dest_y = s->dest[0]; diff --git a/libavcodec/h261.h b/libavcodec/h261.h index 25728a295d..ff1903e508 100644 --- a/libavcodec/h261.h +++ b/libavcodec/h261.h @@ -35,15 +35,7 @@ * H261Context */ typedef struct H261Context { - MpegEncContext s; - - int current_mba; - int mba_diff; int mtype; - int current_mv_x; - int current_mv_y; - int gob_number; - int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read } H261Context; #define MB_TYPE_H261_FIL 0x800000 diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 2fd8d94df1..17f1067b15 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -47,6 +47,19 @@ static VLC h261_mtype_vlc; static VLC h261_mv_vlc; static VLC h261_cbp_vlc; +typedef struct H261DecContext { + MpegEncContext s; + + H261Context common; + + int current_mba; + int mba_diff; + int current_mv_x; + int current_mv_y; + int gob_number; + int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read +} H261DecContext; + static av_cold void h261_decode_init_static(void) { INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35, @@ -67,9 +80,10 @@ static av_cold void h261_decode_init_static(void) static av_cold int h261_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; - H261Context *h = avctx->priv_data; + H261DecContext *const h = avctx->priv_data; MpegEncContext *const s = &h->s; + s->private_ctx = &h->common; // set defaults ff_mpv_decode_init(s, avctx); @@ -89,7 +103,7 @@ static av_cold int h261_decode_init(AVCodecContext *avctx) * Decode the group of blocks header or slice header. * @return <0 if an error occurred */ -static int h261_decode_gob_header(H261Context *h) +static int h261_decode_gob_header(H261DecContext *h) { unsigned int val; MpegEncContext *const s = &h->s; @@ -143,7 +157,7 @@ static int h261_decode_gob_header(H261Context *h) * Decode the group of blocks / video packet header. * @return <0 if no resync found */ -static int h261_resync(H261Context *h) +static int h261_resync(H261DecContext *h) { MpegEncContext *const s = &h->s; int left, ret; @@ -184,7 +198,7 @@ static int h261_resync(H261Context *h) * Decode skipped macroblocks. * @return 0 */ -static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2) +static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) { MpegEncContext *const s = &h->s; int i; @@ -209,7 +223,7 @@ static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2) s->mv[0][0][0] = 0; s->mv[0][0][1] = 0; s->mb_skipped = 1; - h->mtype &= ~MB_TYPE_H261_FIL; + h->common.mtype &= ~MB_TYPE_H261_FIL; if (s->current_picture.motion_val[0]) { int b_stride = 2*s->mb_width + 1; @@ -254,7 +268,7 @@ static int decode_mv_component(GetBitContext *gb, int v) * Decode a macroblock. * @return <0 if an error occurred */ -static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded) +static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded) { MpegEncContext *const s = &h->s; int level, i, j, run; @@ -346,9 +360,10 @@ static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded) return 0; } -static int h261_decode_mb(H261Context *h) +static int h261_decode_mb(H261DecContext *h) { MpegEncContext *const s = &h->s; + H261Context *const com = &h->common; int i, cbp, xy; cbp = 63; @@ -386,23 +401,23 @@ static int h261_decode_mb(H261Context *h) ff_update_block_index(s); // Read mtype - h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); - if (h->mtype < 0) { + com->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); + if (com->mtype < 0) { av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n", - h->mtype); + com->mtype); return SLICE_ERROR; } - av_assert0(h->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map)); - h->mtype = ff_h261_mtype_map[h->mtype]; + av_assert0(com->mtype < FF_ARRAY_ELEMS(ff_h261_mtype_map)); + com->mtype = ff_h261_mtype_map[com->mtype]; // Read mquant - if (IS_QUANT(h->mtype)) + if (IS_QUANT(com->mtype)) ff_set_qscale(s, get_bits(&s->gb, 5)); - s->mb_intra = IS_INTRA4x4(h->mtype); + s->mb_intra = IS_INTRA4x4(com->mtype); // Read mv - if (IS_16X16(h->mtype)) { + if (IS_16X16(com->mtype)) { /* Motion vector data is included for all MC macroblocks. MVD is * obtained from the macroblock vector by subtracting the vector * of the preceding macroblock. For this calculation the vector @@ -425,7 +440,7 @@ static int h261_decode_mb(H261Context *h) } // Read cbp - if (HAS_CBP(h->mtype)) + if (HAS_CBP(com->mtype)) cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 1) + 1; if (s->mb_intra) { @@ -449,7 +464,7 @@ static int h261_decode_mb(H261Context *h) intra: /* decode each block */ - if (s->mb_intra || HAS_CBP(h->mtype)) { + if (s->mb_intra || HAS_CBP(com->mtype)) { s->bdsp.clear_blocks(s->block[0]); for (i = 0; i < 6; i++) { if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0) @@ -470,7 +485,7 @@ intra: * Decode the H.261 picture header. * @return <0 if no startcode found */ -static int h261_decode_picture_header(H261Context *h) +static int h261_decode_picture_header(H261DecContext *h) { MpegEncContext *const s = &h->s; int format, i; @@ -534,7 +549,7 @@ static int h261_decode_picture_header(H261Context *h) return 0; } -static int h261_decode_gob(H261Context *h) +static int h261_decode_gob(H261DecContext *h) { MpegEncContext *const s = &h->s; @@ -580,9 +595,9 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size) static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { + H261DecContext *const h = avctx->priv_data; const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; - H261Context *h = avctx->priv_data; MpegEncContext *s = &h->s; int ret; AVFrame *pict = data; @@ -657,7 +672,7 @@ retry: static av_cold int h261_decode_end(AVCodecContext *avctx) { - H261Context *h = avctx->priv_data; + H261DecContext *const h = avctx->priv_data; MpegEncContext *s = &h->s; ff_mpv_common_end(s); @@ -669,7 +684,7 @@ const AVCodec ff_h261_decoder = { .long_name = NULL_IF_CONFIG_SMALL("H.261"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H261, - .priv_data_size = sizeof(H261Context), + .priv_data_size = sizeof(H261DecContext), .init = h261_decode_init, .close = h261_decode_end, .decode = h261_decode_frame, diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index af65c1f3b1..13fe5bbfb2 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -37,6 +37,14 @@ static uint8_t uni_h261_rl_len [64*64*2*2]; #define UNI_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) +typedef struct H261EncContext { + MpegEncContext s; + + H261Context common; + + int gob_number; +} H261EncContext; + int ff_h261_get_picture_format(int width, int height) { // QCIF @@ -52,7 +60,7 @@ int ff_h261_get_picture_format(int width, int height) void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number) { - H261Context *h = (H261Context *)s; + H261EncContext *const h = (H261EncContext *)s; int format, temp_ref; align_put_bits(&s->pb); @@ -90,7 +98,7 @@ void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number) */ static void h261_encode_gob_header(MpegEncContext *s, int mb_line) { - H261Context *h = (H261Context *)s; + H261EncContext *const h = (H261EncContext *)s; if (ff_h261_get_picture_format(s->width, s->height) == 0) { h->gob_number += 2; // QCIF } else { @@ -132,7 +140,7 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) } } -static void h261_encode_motion(H261Context *h, int val) +static void h261_encode_motion(H261EncContext *h, int val) { MpegEncContext *const s = &h->s; int sign, code; @@ -166,7 +174,7 @@ static inline int get_cbp(MpegEncContext *s, int16_t block[6][64]) * @param block the 8x8 block * @param n block index (0-3 are luma, 4-5 are chroma) */ -static void h261_encode_block(H261Context *h, int16_t *block, int n) +static void h261_encode_block(H261EncContext *h, int16_t *block, int n) { MpegEncContext *const s = &h->s; int level, run, i, j, last_index, last_non_zero, sign, slevel, code; @@ -237,12 +245,15 @@ static void h261_encode_block(H261Context *h, int16_t *block, int n) void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y) { - H261Context *h = (H261Context *)s; + /* The following is only allowed because this encoder + * does not use slice threading. */ + H261EncContext *const h = (H261EncContext *)s; + H261Context *const com = &h->common; int mvd, mv_diff_x, mv_diff_y, i, cbp; cbp = 63; // avoid warning mvd = 0; - h->mtype = 0; + com->mtype = 0; if (!s->mb_intra) { /* compute cbp */ @@ -270,34 +281,34 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], /* calculate MTYPE */ if (!s->mb_intra) { - h->mtype++; + com->mtype++; if (mvd || s->loop_filter) - h->mtype += 3; + com->mtype += 3; if (s->loop_filter) - h->mtype += 3; + com->mtype += 3; if (cbp) - h->mtype++; - av_assert1(h->mtype > 1); + com->mtype++; + av_assert1(com->mtype > 1); } if (s->dquant && cbp) { - h->mtype++; + com->mtype++; } else s->qscale -= s->dquant; put_bits(&s->pb, - ff_h261_mtype_bits[h->mtype], - ff_h261_mtype_code[h->mtype]); + ff_h261_mtype_bits[com->mtype], + ff_h261_mtype_code[com->mtype]); - h->mtype = ff_h261_mtype_map[h->mtype]; + com->mtype = ff_h261_mtype_map[com->mtype]; - if (IS_QUANT(h->mtype)) { + if (IS_QUANT(com->mtype)) { ff_set_qscale(s, s->qscale + s->dquant); put_bits(&s->pb, 5, s->qscale); } - if (IS_16X16(h->mtype)) { + if (IS_16X16(com->mtype)) { mv_diff_x = (motion_x >> 1) - s->last_mv[0][0][0]; mv_diff_y = (motion_y >> 1) - s->last_mv[0][0][1]; s->last_mv[0][0][0] = (motion_x >> 1); @@ -306,7 +317,7 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], h261_encode_motion(h, mv_diff_y); } - if (HAS_CBP(h->mtype)) { + if (HAS_CBP(com->mtype)) { av_assert1(cbp > 0); put_bits(&s->pb, ff_h261_cbp_tab[cbp - 1][1], @@ -316,7 +327,7 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], /* encode each block */ h261_encode_block(h, block[i], i); - if (!IS_16X16(h->mtype)) { + if (!IS_16X16(com->mtype)) { s->last_mv[0][0][0] = 0; s->last_mv[0][0][1] = 0; } @@ -371,8 +382,11 @@ static av_cold void h261_encode_init_static(void) av_cold void ff_h261_encode_init(MpegEncContext *s) { + H261EncContext *const h = (H261EncContext*)s; static AVOnce init_static_once = AV_ONCE_INIT; + s->private_ctx = &h->common; + s->min_qcoeff = -127; s->max_qcoeff = 127; s->y_dc_scale_table = @@ -390,7 +404,7 @@ const AVCodec ff_h261_encoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H261, .priv_class = &ff_mpv_enc_class, - .priv_data_size = sizeof(H261Context), + .priv_data_size = sizeof(H261EncContext), .init = ff_mpv_encode_init, .encode2 = ff_mpv_encode_picture, .close = ff_mpv_encode_end,