diff mbox series

[FFmpeg-devel,05/14] avcodec/mjpegenc: Add wrapper for ff_mjpeg_encode_picture_header()

Message ID AM7PR03MB6660394FC811A850F8BA89958F7D9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 410af1caa34838ab36ceeab83f82b0ef8df823ba
Headers show
Series [FFmpeg-devel,01/14] avcodec/mjpegenc: Use custom close function directly | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 22, 2021, 3:25 a.m. UTC
This factors the translation from MpegEncContext out
and will enable further optimizations in the next commits.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegenc.c      | 16 ++++++++++++++--
 libavcodec/mjpegenc.h      |  1 +
 libavcodec/mpegvideo_enc.c |  5 +----
 3 files changed, 16 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c
index 8b51058f5d..b682036f87 100644
--- a/libavcodec/mjpegenc.c
+++ b/libavcodec/mjpegenc.c
@@ -74,6 +74,19 @@  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,
+                                   s->pred, s->intra_matrix, s->chroma_intra_matrix);
+}
+
+void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
+{
+    /* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
+    if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
+        mjpeg_encode_picture_header(s);
+}
+
 #if CONFIG_MJPEG_ENCODER
 /**
  * Encodes and outputs the entire frame in the JPEG format.
@@ -213,8 +226,7 @@  int ff_mjpeg_encode_stuffing(MpegEncContext *s)
         s->intra_chroma_ac_vlc_length      =
         s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;
 
-        ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
-                                       s->pred, s->intra_matrix, s->chroma_intra_matrix);
+        mjpeg_encode_picture_header(s);
         mjpeg_encode_picture_frame(s);
     }
 #endif
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h
index bc9b017e7a..555677e69a 100644
--- a/libavcodec/mjpegenc.h
+++ b/libavcodec/mjpegenc.h
@@ -105,6 +105,7 @@  static inline void put_marker(PutBitContext *p, enum JpegMarker code)
 }
 
 int  ff_mjpeg_encode_init(MpegEncContext *s);
+void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s);
 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
 int  ff_mjpeg_encode_stuffing(MpegEncContext *s);
 
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 23e8a41a86..9807e491e5 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3702,10 +3702,7 @@  static int encode_picture(MpegEncContext *s, int picture_number)
     switch(s->out_format) {
 #if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER
     case FMT_MJPEG:
-        /* s->huffman == HUFFMAN_TABLE_OPTIMAL can only be true for MJPEG. */
-        if (!CONFIG_MJPEG_ENCODER || s->huffman != HUFFMAN_TABLE_OPTIMAL)
-            ff_mjpeg_encode_picture_header(s->avctx, &s->pb, &s->intra_scantable,
-                                           s->pred, s->intra_matrix, s->chroma_intra_matrix);
+        ff_mjpeg_amv_encode_picture_header(s);
         break;
 #endif
     case FMT_SPEEDHQ: