diff mbox series

[FFmpeg-devel,7/9] avcodec/snow: Move decoder parts out of ff_snow_common_init_after_header

Message ID AS8P250MB0744CF57A383F9698414F90B8FFCA@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 00ba78cd6fb8fb7cbd20a36e840ddde3eda0dca0
Headers show
Series [FFmpeg-devel,1/9] avfilter/bwdif: Add proper BWDIFDSPContext | expand

Checks

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

Commit Message

Andreas Rheinhardt Sept. 25, 2023, 6:04 p.m. UTC
They are not common.

Furthermore, this file is pulled in when linking checkasm and
up until now, the calls to ff_get_buffer() and av_codec_is_decoder()
caused all of libavcodec to be pulled in as well. Besides being
bad size-wise this also has the downside that it pulls in
avpriv_(cga|vga16)_font from libavutil which are marked as
being imported from another library when building libavcodec
as a DLL; this breaks checkasm because it links both lavc and lavu
statically.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/snow.c    | 15 +--------------
 libavcodec/snowdec.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 09f2d60f47..90197976fb 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -21,7 +21,6 @@ 
 #include "libavutil/log.h"
 #include "libavutil/thread.h"
 #include "avcodec.h"
-#include "decode.h"
 #include "snow_dwt.h"
 #include "snow.h"
 #include "snowdata.h"
@@ -476,27 +475,15 @@  av_cold int ff_snow_common_init(AVCodecContext *avctx){
 int ff_snow_common_init_after_header(AVCodecContext *avctx) {
     SnowContext *s = avctx->priv_data;
     int plane_index, level, orientation;
-    int ret, emu_buf_size;
 
     if(!s->scratchbuf) {
-        if (av_codec_is_decoder(avctx->codec)) {
-            if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
-                                     AV_GET_BUFFER_FLAG_REF)) < 0)
-                return ret;
-        }
-
+        int emu_buf_size;
         emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
         if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf,      FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
             !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
             return AVERROR(ENOMEM);
     }
 
-    if (av_codec_is_decoder(avctx->codec) &&
-        s->mconly_picture->format != avctx->pix_fmt) {
-        av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     for(plane_index=0; plane_index < s->nb_planes; plane_index++){
         int w= s->avctx->width;
         int h= s->avctx->height;
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 489c09324e..e77dc8ce8a 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -455,6 +455,17 @@  static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
     s->current_picture->pict_type= AV_PICTURE_TYPE_I; //FIXME I vs. P
     if ((res = decode_header(s)) < 0)
         return res;
+
+    if (!s->mconly_picture->data[0]) {
+        res = ff_get_buffer(avctx, s->mconly_picture, AV_GET_BUFFER_FLAG_REF);
+        if (res < 0)
+            return res;
+    }
+    if (s->mconly_picture->format != avctx->pix_fmt) {
+        av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
+        return AVERROR_INVALIDDATA;
+    }
+
     if ((res=ff_snow_common_init_after_header(avctx)) < 0)
         return res;