diff mbox series

[FFmpeg-devel,2/5] avcodec/mjpegdec: Move special SMVJPEG-code to SMVJPEG-only function

Message ID GV1P250MB0737C7E6218C857B346EFC518F1A9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit b640cda95d82cec76d4e8441b2ce119415c213e7
Headers show
Series [FFmpeg-devel,1/5] avcodec/mjpegdec: Restrict AVID MJPEG to non-SMVJPEG | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 7, 2022, 7:02 p.m. UTC
This automatically avoids runtime checks for whether
the decoder is SMVJPEG.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mjpegdec.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 28e2839072..b88d2ab889 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2422,9 +2422,6 @@  int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
 
     s->force_pal8 = 0;
 
-    if (avctx->codec_id == AV_CODEC_ID_SMVJPEG && s->smv_next_frame > 0)
-        return smv_process_frame(avctx, frame);
-
     av_dict_free(&s->exif_metadata);
     av_freep(&s->stereo3d);
     s->adobe_transform = -1;
@@ -2921,13 +2918,6 @@  the_end:
     av_dict_copy(&frame->metadata, s->exif_metadata, 0);
     av_dict_free(&s->exif_metadata);
 
-    if (avctx->codec_id == AV_CODEC_ID_SMVJPEG) {
-        ret = smv_process_frame(avctx, frame);
-        if (ret < 0) {
-            av_frame_unref(frame);
-            return ret;
-        }
-    }
     if (avctx->codec_id != AV_CODEC_ID_SMVJPEG &&
         (avctx->codec_tag == MKTAG('A', 'V', 'R', 'n') ||
          avctx->codec_tag == MKTAG('A', 'V', 'D', 'J')) &&
@@ -3060,6 +3050,21 @@  const FFCodec ff_thp_decoder = {
 #endif
 
 #if CONFIG_SMVJPEG_DECODER
+static int smvjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame)
+{
+    MJpegDecodeContext *s = avctx->priv_data;
+    int ret;
+
+    if (s->smv_next_frame > 0)
+        return smv_process_frame(avctx, frame);
+
+    ret = ff_mjpeg_receive_frame(avctx, frame);
+    if (ret < 0)
+        return ret;
+
+    return smv_process_frame(avctx, frame);
+}
+
 const FFCodec ff_smvjpeg_decoder = {
     .p.name         = "smvjpeg",
     CODEC_LONG_NAME("SMV JPEG"),
@@ -3068,7 +3073,7 @@  const FFCodec ff_smvjpeg_decoder = {
     .priv_data_size = sizeof(MJpegDecodeContext),
     .init           = ff_mjpeg_decode_init,
     .close          = ff_mjpeg_decode_end,
-    FF_CODEC_RECEIVE_FRAME_CB(ff_mjpeg_receive_frame),
+    FF_CODEC_RECEIVE_FRAME_CB(smvjpeg_receive_frame),
     .flush          = decode_flush,
     .p.capabilities = AV_CODEC_CAP_DR1,
     .caps_internal  = FF_CODEC_CAP_EXPORTS_CROPPING |