Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 08/14] avcodec/mpegvideo: Move MJPEG/AMV-only fields to MJpegContext
Date: Wed, 22 Dec 2021 04:25:08 +0100
Message-ID: <AM7PR03MB66607D44C5D72BE27F05731A8F7D9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB66606013F665BF849CE7CAD68F7D9@AM7PR03MB6660.eurprd03.prod.outlook.com>

This is possible now that MJpegContext is allocated jointly
with MpegEncContext as part of the AVCodecContext's private data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegenc.c        | 18 ++++++++++--------
 libavcodec/mjpegenc.h        |  3 +++
 libavcodec/mjpegenc_common.c |  4 ++--
 libavcodec/mpegvideo.h       |  8 +++++---
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index c1b759f7a8..9b5acde58d 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -86,8 +86,10 @@ static void mjpeg_encode_picture_header(MpegEncContext *s)
 
 void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
 {
+    MJPEGEncContext *const m = (MJPEGEncContext*)s;
+    av_assert2(s->mjpeg_ctx == &m->mjpeg);
     /* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
-    if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
+    if (!CONFIG_MJPEG_ENCODER || m->mjpeg.huffman != HUFFMAN_TABLE_OPTIMAL)
         mjpeg_encode_picture_header(s);
 }
 
@@ -211,13 +213,13 @@ static void mjpeg_build_optimal_huffman(MJpegContext *m)
  */
 int ff_mjpeg_encode_stuffing(MpegEncContext *s)
 {
+    MJpegContext *const m = s->mjpeg_ctx;
     PutBitContext *pbc = &s->pb;
     int mb_y = s->mb_y - !s->mb_x;
     int ret;
 
 #if CONFIG_MJPEG_ENCODER
-    if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {
-        MJpegContext *m = s->mjpeg_ctx;
+    if (m->huffman == HUFFMAN_TABLE_OPTIMAL) {
 
         mjpeg_build_optimal_huffman(m);
 
@@ -293,7 +295,7 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
     av_assert0(s->slice_context_count == 1);
 
     if (s->codec_id == AV_CODEC_ID_AMV || (s->avctx->active_thread_type & FF_THREAD_SLICE))
-        s->huffman = 0;
+        m->huffman = HUFFMAN_TABLE_DEFAULT;
 
     if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
         // Used to produce garbage with MJPEG.
@@ -346,7 +348,7 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
     // Buffers start out empty.
     m->huff_ncode = 0;
 
-    if(s->huffman == HUFFMAN_TABLE_OPTIMAL)
+    if (m->huffman == HUFFMAN_TABLE_OPTIMAL)
         return alloc_huffman(s);
 
     return 0;
@@ -514,7 +516,7 @@ static void encode_block(MpegEncContext *s, int16_t *block, int n)
 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
 {
     int i;
-    if (s->huffman == HUFFMAN_TABLE_OPTIMAL) {
+    if (s->mjpeg_ctx->huffman == HUFFMAN_TABLE_OPTIMAL) {
         if (s->chroma_format == CHROMA_444) {
             record_block(s, block[0], 0);
             record_block(s, block[2], 2);
@@ -614,11 +616,11 @@ static int amv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
 }
 #endif
 
-#define OFFSET(x) offsetof(MpegEncContext, x)
+#define OFFSET(x) offsetof(MJPEGEncContext, mjpeg.x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
 FF_MPV_COMMON_OPTS
-{ "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" },
+{ "pred", "Prediction method", FF_MPV_OFFSET(pred), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 3, VE, "pred" },
     { "left",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "pred" },
     { "plane",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, INT_MIN, INT_MAX, VE, "pred" },
     { "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "pred" },
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
index 555677e69a..a593b67e96 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -57,6 +57,9 @@ typedef struct MJpegHuffmanCode {
  * Holds JPEG frame data and Huffman table data.
  */
 typedef struct MJpegContext {
+    int huffman;
+    /* Force duplication of mjpeg matrices, useful for rtp streaming */
+    int force_duplicated_matrix;
     //FIXME use array [3] instead of lumi / chroma, for easier addressing
     uint8_t huff_size_dc_luminance[12];     ///< DC luminance Huffman table size.
     uint16_t huff_code_dc_luminance[12];    ///< DC luminance Huffman table codes.
diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index b9df32ad15..0303e65790 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -73,7 +73,7 @@ static void jpeg_table_header(AVCodecContext *avctx, PutBitContext *p,
         int matrix_count = 1 + !!memcmp(luma_intra_matrix,
                                         chroma_intra_matrix,
                                         sizeof(luma_intra_matrix[0]) * 64);
-        if (s && s->force_duplicated_matrix)
+        if (s && s->mjpeg_ctx->force_duplicated_matrix)
             matrix_count = 2;
         /* quant matrixes */
         put_marker(p, DQT);
@@ -110,7 +110,7 @@ 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->huffman == HUFFMAN_TABLE_OPTIMAL) {
+    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,
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 879b019ffc..5a3486d74c 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -290,7 +290,6 @@ typedef struct MpegEncContext {
     uint16_t chroma_intra_matrix[64];
     uint16_t inter_matrix[64];
     uint16_t chroma_inter_matrix[64];
-    int force_duplicated_matrix; ///< Force duplication of mjpeg matrices, useful for rtp streaming
 
     int intra_quant_bias;    ///< bias for the quantizer
     int inter_quant_bias;    ///< bias for the quantizer
@@ -414,7 +413,6 @@ typedef struct MpegEncContext {
     struct MJpegContext *mjpeg_ctx;
     int esc_pos;
     int pred;
-    int huffman;
 
     /* MSMPEG4 specific */
     int mv_table_index;
@@ -575,6 +573,10 @@ typedef struct MpegEncContext {
     int noise_reduction;
 
     int intra_penalty;
+
+#if FF_API_MPEGVIDEO_OPTS
+    int dummy;               ///< used as target for deprecated options
+#endif
 } MpegEncContext;
 
 /* mpegvideo_enc common options */
@@ -664,7 +666,7 @@ FF_MPV_OPT_CMP_FUNC, \
 #define FF_MPV_DEPRECATED_A53_CC_OPT \
     { "a53cc",      "Deprecated, does nothing", FF_MPV_OFFSET(a53_cc),     AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
 #define FF_MPV_DEPRECATED_MATRIX_OPT \
-   { "force_duplicated_matrix", "Deprecated, does nothing", FF_MPV_OFFSET(force_duplicated_matrix), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
+   { "force_duplicated_matrix", "Deprecated, does nothing", FF_MPV_OFFSET(dummy), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED },
 #define FF_MPV_DEPRECATED_BFRAME_OPTS \
    { "b_strategy",    "Deprecated, does nothing", FF_MPV_OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, { .i64 =  0 }, 0, 2, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
    { "b_sensitivity", "Deprecated, does nothing", FF_MPV_OFFSET(b_sensitivity),    AV_OPT_TYPE_INT, { .i64 = 40 }, 1, INT_MAX, FF_MPV_OPT_FLAGS | AV_OPT_FLAG_DEPRECATED }, \
-- 
2.32.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2021-12-22  3:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22  3:19 [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 02/14] avcodec/mjpegenc: Avoid allocation of MJpegContext Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 03/14] avcodec/mpegvideo_enc: Move MJPEG init checks to mjpegenc.c Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 04/14] avcodec/mpegvideo_enc: Remove redundant checks for multithreading Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header() Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 06/14] avcodec/mjpegenc_common: Move code for MJPEG/AMV to mjpegenc Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 07/14] avcodec/mjpegenc_common: Fix intendation Andreas Rheinhardt
2021-12-22  3:25 ` Andreas Rheinhardt [this message]
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 09/14] avcodec/mjpegenc: Deprecate unused prediction type Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 10/14] avcodec/mjpegenc_common: Pass MJpegContext for writing picture header Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 11/14] avcodec/mjpegenc_common: Don't call function unnecessarily Andreas Rheinhardt
2021-12-22  3:25 ` [FFmpeg-devel] [PATCH 12/14] avcodec/mjpegenc_common: Use AVCodecContext.codec_id directly Andreas Rheinhardt
2021-12-22  3:30 ` [FFmpeg-devel] [PATCH 13/14] avcodec/mpegvideo: Remove unnecessary headers Andreas Rheinhardt
2021-12-22  3:30 ` [FFmpeg-devel] [PATCH 14/14] avcodec/mpegvideo_enc: Remove impossible branch Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 15/30] avcodec/speedhqenc: Inline constants Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 16/30] avcodec/mpegvideo_enc: Move updating mb_info to its only user Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 17/30] avcodec/mpeg12enc: Simplify check for A53 closed captions Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 18/30] avcodec/mpeg12enc: Add custom context, move mpeg2_frame_rate_ext to it Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 19/30] avcodec/mpeg12enc: Move options-related fields to MPEG12EncContext Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 20/30] avcodec/mpegvideo_enc: Don't merge decoder-only fields Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 21/30] avcodec/mpeg12dec: Use %c to write single char Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 22/30] avcodec/mpegvideo: Don't duplicate identical code Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 23/30] avcodec/mpegvideo: Avoid needlessly calling function Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 24/30] avcodec/wmv2: Move ff_wmv2_add_mb() to the wmv2dec Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 25/30] avcodec/mpegvideo_motion: Don't duplicate identical code Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 26/30] avcodec/mpegvideo: Don't check for > 8 bit MPEG-1/2 Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 27/30] avcodec/mpegvideo: Partially check for being encoder at compile-time Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 28/30] avcodec/mpegvideo: Try to perform check for MPEG-1/2 " Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 29/30] avcodec/mpegvideo: Remove always-true branch Andreas Rheinhardt
2021-12-23  9:13 ` [FFmpeg-devel] [PATCH 30/30] avcodec/mpegvideo: Check for no_rounding at compile-time if possible Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 31/36] avcodec/mpegvideo: Don't initialize error resilience context for encoder Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 32/36] avcodec/mpegvideo: Remove always-false check Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 33/36] avcodec/mpegvideo: Move decoding-only code into a new file Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 34/36] configure: Add new mpegvideodec CONFIG_EXTRA Andreas Rheinhardt
2021-12-25  6:09   ` [FFmpeg-devel] [PATCH v2 34/35] " Andreas Rheinhardt
2021-12-25  6:09   ` [FFmpeg-devel] [PATCH v2 35/35] configure: Remove mpegvideo dependency on me_cmp Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 35/36] avcodec/mpegvideo_enc: Improve inlining of chroma_format Andreas Rheinhardt
2021-12-24  3:23 ` [FFmpeg-devel] [PATCH 36/36] avcodec/mpegvideo_enc: Remove dead code at compile time Andreas Rheinhardt
2021-12-24 17:17   ` Michael Niedermayer
2021-12-24 18:30     ` Andreas Rheinhardt
2021-12-24 18:36       ` Michael Niedermayer
2021-12-25  6:06 ` [FFmpeg-devel] [PATCH 37/39] avcodec/mpeg12enc: Also inline chroma subsampling Andreas Rheinhardt
2021-12-25  6:06 ` [FFmpeg-devel] [PATCH 38/39] avcodec/mpeg12enc: Partially inline whether codec is MPEG-1 Andreas Rheinhardt
2021-12-25  6:06 ` [FFmpeg-devel] [PATCH 39/39] avcodec/mpeg12enc: Inline constants Andreas Rheinhardt
2021-12-31 10:03 ` [FFmpeg-devel] [PATCH 01/14] avcodec/mjpegenc: Use custom close function directly Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM7PR03MB66607D44C5D72BE27F05731A8F7D9@AM7PR03MB6660.eurprd03.prod.outlook.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git