diff mbox series

[FFmpeg-devel,v2,26/71] avcodec/h263: Move encoder-only part out of ff_h263_update_motion_val()

Message ID GV1P250MB0737038B81E1E4992F16C95D8FE02@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,v2,01/71] avcodec/ratecontrol: Fix double free on error | expand

Commit Message

Andreas Rheinhardt May 11, 2024, 8:50 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h263.c          |  9 ---------
 libavcodec/h263enc.h       |  2 +-
 libavcodec/ituh263enc.c    | 14 ++++++++++++++
 libavcodec/mpegvideo_enc.c |  4 ++--
 4 files changed, 17 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index b30ffaf878..3edf810bcc 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -91,15 +91,6 @@  void ff_h263_update_motion_val(MpegEncContext * s){
         s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x;
         s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y;
     }
-
-    if(s->encoding){ //FIXME encoding MUST be cleaned up
-        if (s->mv_type == MV_TYPE_8X8)
-            s->current_picture.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8;
-        else if(s->mb_intra)
-            s->current_picture.mb_type[mb_xy] = MB_TYPE_INTRA;
-        else
-            s->current_picture.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16;
-    }
 }
 
 void ff_h263_loop_filter(MpegEncContext * s){
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index e45475686e..cd5ded1593 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -36,7 +36,7 @@  void ff_init_qscale_tab(MpegEncContext *s);
 void ff_clean_h263_qscales(MpegEncContext *s);
 
 void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code);
-
+void ff_h263_update_mb(MpegEncContext *s);
 
 static inline int h263_get_motion_length(int val, int f_code)
 {
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 4741ada853..87689e5f5b 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -688,6 +688,20 @@  void ff_h263_encode_mb(MpegEncContext * s,
     }
 }
 
+void ff_h263_update_mb(MpegEncContext *s)
+{
+    const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
+
+    if (s->mv_type == MV_TYPE_8X8)
+        s->current_picture.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8;
+    else if(s->mb_intra)
+        s->current_picture.mb_type[mb_xy] = MB_TYPE_INTRA;
+    else
+        s->current_picture.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16;
+
+    ff_h263_update_motion_val(s);
+}
+
 void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
 {
     int range, bit_size, sign, code, bits;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 4121cc034f..1798a25ed9 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3314,7 +3314,7 @@  static int encode_thread(AVCodecContext *c, void *arg){
 
                 if (CONFIG_H263_ENCODER &&
                     s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B)
-                    ff_h263_update_motion_val(s);
+                    ff_h263_update_mb(s);
 
                 if(next_block==0){ //FIXME 16 vs linesize16
                     s->hdsp.put_pixels_tab[0][0](s->dest[0], s->sc.rd_scratchpad                     , s->linesize  ,16);
@@ -3440,7 +3440,7 @@  static int encode_thread(AVCodecContext *c, void *arg){
 
                 if (CONFIG_H263_ENCODER &&
                     s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B)
-                    ff_h263_update_motion_val(s);
+                    ff_h263_update_mb(s);
 
                 mpv_reconstruct_mb(s, s->block);
             }