From patchwork Wed Dec 22 03:25:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 32827 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp6022870iog; Tue, 21 Dec 2021 19:26:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBDuivrF9vV24A3o57Qordiov65nOGGLpdiTW2I1jdm8xz6PqWKkWDoxYg6DCBLc0r6+Cf X-Received: by 2002:a05:6402:34c6:: with SMTP id w6mr1148867edc.284.1640143614698; Tue, 21 Dec 2021 19:26:54 -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 oz35si402836ejc.527.2021.12.21.19.26.54; Tue, 21 Dec 2021 19:26:54 -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=Wx3dZ9Y3; 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 E0E5368B009; Wed, 22 Dec 2021 05:25:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074084.outbound.protection.outlook.com [40.92.74.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D44E68AFE9 for ; Wed, 22 Dec 2021 05:25:45 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i951RAtu1+tMNb1W9aCZ/lthmwNILaXDXihC/sQTquB0Vv8KieDYIdFYlpnOSsgkpDdIGnIHa1BZOzv6MDdZOvaXCCAL+WYT8dSoOX6LZ6qecrOUpZrlhfb7dnkbii0qCtfCVWD+5xL/3NrTKFC8a3GQmRtCbVQG0szuDjArCy45oVlZqZYsn5mdIRNi4hCBjcHXg6cl0NCGOySiUdIE71TQNnJG4v0K4+FXvlnTkPBfg4HN/0pyc4NcrKdWEAt3Oxdp1LUmE0kXVCUgKfVlJrkoSJtIQDTuUZjpw41VK4vkU+JbWs165++oMjC9lKANjVSKe4Xzx0rqe7unnsOOFg== 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=oDMh2zor5Fcu9XRd60hNmBs/MX6YVFGl/U8rksyzHPk=; b=a0926j0t7ARtfs82/tG2/AXjFfFyyEwTjGSf2AkeX4mpd11kkdVS9anHVOKKXBqWFXDiL86joaSl7zN+1EbpcpVW6e6N8tG7QQY2Vo4/spdVg+IjPddGs4W4PvQ5nYvPm57iUKvFNnPHQ4HEZws0ZidOHJyhR2FEE6rU0VI+sUeB8GUq/uQ78Cr+RSrxwcBsMQBP3rqNFBmKc86wWTXevVDcyzWTSB8weipInHd+uDJYBAte7EmV5jb8aUbonlJxTQC/S/dxT9yHttlLgzwQ/YpicGBs7y0OK/8wuR6qdpxT8+L3EbC/SMrlsZxzM2tYLnrTr+KYeA7PSNaqIoqssA== 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=oDMh2zor5Fcu9XRd60hNmBs/MX6YVFGl/U8rksyzHPk=; b=Wx3dZ9Y3gGBSLu6gZG5q9KnnoLd/p3NCzMHKGmLDC+h7t/yHKZDcGZCDGgiwOpZPsogf0x4ctvOdMzE7GF54SWCPDoKqryg3SbZTyrgvwWP8rWcauFhblJGxwlag62EyDoE2s6jVa4Qayrr3b/zxuPCkJ7vAgVWiT8ulyRiem2Epr2zAydIivjbcNKVYfLkVn94uescTfdY6SH8jIg7kJzVqhp6fSS8aOUAvD4DesRkjyTSU1QEjyNxpsmH83UzaK8ie+7ekCbIwTHXk1KYpDeFYWZt6Ej8OZHNKC2lsFRQroErojX2FsYyiR2CbagnZEBo0RGrhtl3rqr6gk6AGnA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4104.eurprd03.prod.outlook.com (2603:10a6:20b:18::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.15; Wed, 22 Dec 2021 03:25:34 +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.4801.022; Wed, 22 Dec 2021 03:25:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Dec 2021 04:25:10 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [5bdKWj0y78UeSPt6O671QzxDmWrGZ+Tj] X-ClientProxiedBy: AS9PR06CA0323.eurprd06.prod.outlook.com (2603:10a6:20b:45b::19) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211222032514.896794-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e73b9ca-c91a-4995-2d0b-08d9c4fab6de X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiR3EehW4kxQzdNcP2D/mG1JxNKlBGj85Tj6cqq0/J5m6dbGxhQEZbeT6r+uMWpbn9C4q91US1oxN26bURdmTflFWPqVjQAg5cYhdoIokD4Ntqt/MKS/tNtRfi6WVmXdiDbUm37er7R+41kJzcT6taP00q8ZHk5TdWc+lMaR5M3Pivd01t7WchQnn40gUsRUId2754FbDLsHnzCHZuvH6ywgr1jW6WnI912okTl3VbfiyciRwlfhzHdEuwqySPSdhRBpAa1H1QxPEDw5z8048oM7B5rQl3O00XW8XTXQCKcPHqVBcsrO87Yipdz+6xNhk1hqNG6vnBPRNX5R57fo6C5/iNh9pjeS7+ESHs53Bhwcz5chv/SL8oMuYcuDPi1oJcIuN5YysUuUdIkEITHuP0B47pGl18aFHQxMij6Qz9fG9diBtTiXonshbgsKjXvtQ+7O4t85dy+gdLxNh4z2Lo9TAl5+Yv79xZKqBa2VjsrZpWJ5dJi3vBFIIgKbVAs3f+NLwmK7Bi+r7XYvMqoHQHe0hRjY6zC1hFAJeu0unFXyt/CuCyyrR0OSzUQdzPF4QM+2gDSgpOp9El409cbM0nA+NjeCK7eVmivm2PK5TruZF10iaVwGP3BD9OKm1cT8KY0kM2GLMP2XEZC4BGdpJxKDYSbQxVgZ0E7ZaA1hL+uJKn4Vdh4igRpXUkvyt8gfVEn5lJ0+OPrBSbjawtZnW7dgDUtdMz7S5xQrK8FHkp+H3R1loMdBKRv8oAXTbsOygBk= X-MS-TrafficTypeDiagnostic: AM6PR03MB4104:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: llJp190liuMee0+G+ACnsvKOXcWyL4caNR27EMTf4IKe3GFmYLooyVRzHcNVCikkvxPg7/VXSrrEIBClbf9kzUvA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9lMSRsjNV67magF59sCfNCKHp1Ap05BTW+C41Ju7WHiaa2/aq1IspfVQCB2Fl9VBkJzcQvRY3VoVQpjRQhDlBnNa9yeR1qQ+T/AjEMY/3ZsY4YgJeQScT46TfbiPV3o1ZJ/Hc2sLhhz0iks8g+ZjjD3NvTjwiTYxn5ZCV4yYYxHyir2J7yLotjoOWRwFZd77z+UDOhVfIjRO8jKAMgETsjHK91T1GCftKuutyJ8qcsD3bVC5gsJQo6Wz4joPL876F091PTQTWEUQ4EGardUEOwfzjx/syqv96SY89wpius8w2iqgntp3B69/7X+pLshhDxjq2KLuVyDkPwiAwtpl/FhBYXLofP005dCSd8IDjrTX4daIU8onzk1G3hAyOZoC5tzHuRc5zov23sqok2Kws63fiJKfNUPXQU/O4j1OT4WG6qO3fQ4z85VuHojNFRX/DGbU+gZVC3b0mJtgTPyk0nQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e73b9ca-c91a-4995-2d0b-08d9c4fab6de X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2021 03:25:34.0392 (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: AM6PR03MB4104 Subject: [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header 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: FxHjpSULtwuP It is the structure that is actually used. Signed-off-by: Andreas Rheinhardt --- libavcodec/ljpegenc.c | 2 +- libavcodec/mjpegenc.c | 5 +++-- libavcodec/mjpegenc_common.c | 36 +++++++++++++++++------------------- libavcodec/mjpegenc_common.h | 3 +++ 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/libavcodec/ljpegenc.c b/libavcodec/ljpegenc.c index 968ba1fb60..ea00d5cf3c 100644 --- a/libavcodec/ljpegenc.c +++ b/libavcodec/ljpegenc.c @@ -238,7 +238,7 @@ static int ljpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt, init_put_bits(&pb, pkt->data, pkt->size); - ff_mjpeg_encode_picture_header(avctx, &pb, &s->scantable, + ff_mjpeg_encode_picture_header(avctx, &pb, NULL, &s->scantable, s->pred, s->matrix, s->matrix); header_bits = put_bits_count(&pb); diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index cafa0487c5..e74720dbab 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -76,8 +76,9 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], static void mjpeg_encode_picture_header(MpegEncContext *s) { - ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable, - 0, s->intra_matrix, s->chroma_intra_matrix); + ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->mjpeg_ctx, + &s->intra_scantable, 0, + s->intra_matrix, s->chroma_intra_matrix); s->esc_pos = put_bytes_count(&s->pb, 0); for (int i = 1; i < s->slice_context_count; i++) diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c index ed0e8c234d..70d5fddfd5 100644 --- a/libavcodec/mjpegenc_common.c +++ b/libavcodec/mjpegenc_common.c @@ -56,6 +56,7 @@ static int put_huffman_table(PutBitContext *p, int table_class, int table_id, } static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, + MJpegContext *m, ScanTable *intra_scantable, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64], @@ -63,17 +64,12 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, { int i, j, size; uint8_t *ptr; - MpegEncContext *s = NULL; - /* Since avctx->priv_data will point to LJpegEncContext in this case */ - if (avctx->codec_id != AV_CODEC_ID_LJPEG) - s = avctx->priv_data; - - if (avctx->codec_id != AV_CODEC_ID_LJPEG) { + if (m) { int matrix_count = 1 + !!memcmp(luma_intra_matrix, chroma_intra_matrix, sizeof(luma_intra_matrix[0]) * 64); - if (s && s->mjpeg_ctx->force_duplicated_matrix) + if (m->force_duplicated_matrix) matrix_count = 2; /* quant matrixes */ put_marker(p, DQT); @@ -110,16 +106,16 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p, // Only MJPEG can have a variable Huffman variable. All other // formats use the default Huffman table. - if (s && s->mjpeg_ctx->huffman == HUFFMAN_TABLE_OPTIMAL) { - size += put_huffman_table(p, 0, 0, s->mjpeg_ctx->bits_dc_luminance, - s->mjpeg_ctx->val_dc_luminance); - size += put_huffman_table(p, 0, 1, s->mjpeg_ctx->bits_dc_chrominance, - s->mjpeg_ctx->val_dc_chrominance); - - size += put_huffman_table(p, 1, 0, s->mjpeg_ctx->bits_ac_luminance, - s->mjpeg_ctx->val_ac_luminance); - size += put_huffman_table(p, 1, 1, s->mjpeg_ctx->bits_ac_chrominance, - s->mjpeg_ctx->val_ac_chrominance); + if (m && m->huffman == HUFFMAN_TABLE_OPTIMAL) { + size += put_huffman_table(p, 0, 0, m->bits_dc_luminance, + m->val_dc_luminance); + size += put_huffman_table(p, 0, 1, m->bits_dc_chrominance, + m->val_dc_chrominance); + + size += put_huffman_table(p, 1, 0, m->bits_ac_luminance, + m->val_ac_luminance); + size += put_huffman_table(p, 1, 1, m->bits_ac_chrominance, + m->val_ac_chrominance); } else { size += put_huffman_table(p, 0, 0, avpriv_mjpeg_bits_dc_luminance, avpriv_mjpeg_val_dc); @@ -218,11 +214,12 @@ void ff_mjpeg_init_hvsample(AVCodecContext *avctx, int hsample[4], int vsample[4 } void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, + MJpegContext *m, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64]) { - const int lossless = avctx->codec_id != AV_CODEC_ID_MJPEG && avctx->codec_id != AV_CODEC_ID_AMV; + const int lossless = !m; int hsample[4], vsample[4]; int components = 3 + (avctx->pix_fmt == AV_PIX_FMT_BGRA); int chroma_matrix = !!memcmp(luma_intra_matrix, @@ -239,7 +236,8 @@ void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, jpeg_put_comments(avctx, pb); - jpeg_table_header(avctx, pb, intra_scantable, luma_intra_matrix, chroma_intra_matrix, hsample); + jpeg_table_header(avctx, pb, m, intra_scantable, + luma_intra_matrix, chroma_intra_matrix, hsample); switch (avctx->codec_id) { case AV_CODEC_ID_MJPEG: put_marker(pb, SOF0 ); break; diff --git a/libavcodec/mjpegenc_common.h b/libavcodec/mjpegenc_common.h index 76c236d835..ac753bf153 100644 --- a/libavcodec/mjpegenc_common.h +++ b/libavcodec/mjpegenc_common.h @@ -27,7 +27,10 @@ #include "idctdsp.h" #include "put_bits.h" +struct MJpegContext; + void ff_mjpeg_encode_picture_header(AVCodecContext *avctx, PutBitContext *pb, + struct MJpegContext *m, ScanTable *intra_scantable, int pred, uint16_t luma_intra_matrix[64], uint16_t chroma_intra_matrix[64]);