diff mbox series

[FFmpeg-devel,4/6] avcodec/mpegvideo_enc: Move H.261 size check to h261enc.c

Message ID GV1P250MB0737931694FD9CF02113B2448F589@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit d74ca6fdb4255ef8009355ebf6acbd0629047009
Headers show
Series [FFmpeg-devel,1/6] fate/vcodec: Add speedhq tests | expand

Checks

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

Commit Message

Andreas Rheinhardt Oct. 2, 2022, 9:18 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h261enc.c       | 11 ++++++++++-
 libavcodec/h261enc.h       |  2 +-
 libavcodec/mpegvideo_enc.c | 11 +++--------
 3 files changed, 14 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index b868827160..7aa548c39d 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -382,11 +382,18 @@  static av_cold void h261_encode_init_static(void)
     init_uni_h261_rl_tab(&ff_h261_rl_tcoeff, uni_h261_rl_len);
 }
 
-av_cold void ff_h261_encode_init(MpegEncContext *s)
+av_cold int ff_h261_encode_init(MpegEncContext *s)
 {
     H261EncContext *const h = (H261EncContext*)s;
     static AVOnce init_static_once = AV_ONCE_INIT;
 
+    if (ff_h261_get_picture_format(s->width, s->height) < 0) {
+        av_log(s->avctx, AV_LOG_ERROR,
+                "The specified picture size of %dx%d is not valid for the "
+                "H.261 codec.\nValid sizes are 176x144, 352x288\n",
+                s->width, s->height);
+        return AVERROR(EINVAL);
+    }
     s->private_ctx = &h->common;
 
     s->min_qcoeff       = -127;
@@ -398,6 +405,8 @@  av_cold void ff_h261_encode_init(MpegEncContext *s)
     s->intra_ac_vlc_length      = s->inter_ac_vlc_length      = uni_h261_rl_len;
     s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = uni_h261_rl_len + 128*64;
     ff_thread_once(&init_static_once, h261_encode_init_static);
+
+    return 0;
 }
 
 const FFCodec ff_h261_encoder = {
diff --git a/libavcodec/h261enc.h b/libavcodec/h261enc.h
index 0a01858be5..088cd9f4e0 100644
--- a/libavcodec/h261enc.h
+++ b/libavcodec/h261enc.h
@@ -35,6 +35,6 @@  void ff_h261_reorder_mb_index(MpegEncContext *s);
 void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64],
                        int motion_x, int motion_y);
 void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number);
-void ff_h261_encode_init(MpegEncContext *s);
+int ff_h261_encode_init(MpegEncContext *s);
 
 #endif
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index e7e2e60a9a..8d74f9e978 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -682,14 +682,9 @@  av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
     case AV_CODEC_ID_H261:
         if (!CONFIG_H261_ENCODER)
             return AVERROR_ENCODER_NOT_FOUND;
-        if (ff_h261_get_picture_format(s->width, s->height) < 0) {
-            av_log(avctx, AV_LOG_ERROR,
-                   "The specified picture size of %dx%d is not valid for the "
-                   "H.261 codec.\nValid sizes are 176x144, 352x288\n",
-                    s->width, s->height);
-            return AVERROR(EINVAL);
-        }
-        ff_h261_encode_init(s);
+        ret = ff_h261_encode_init(s);
+        if (ret < 0)
+            return ret;
         s->out_format = FMT_H261;
         avctx->delay  = 0;
         s->low_delay  = 1;