Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c
@ 2022-10-12 18:03 Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only Andreas Rheinhardt
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:03 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It is the only codec for which mcsel is ever set.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4videodec.c    | 168 ++++++++++++++++++++++++++++++++++
 libavcodec/mpeg4videodec.h    |   3 +
 libavcodec/mpegvideo_motion.c | 166 +--------------------------------
 3 files changed, 174 insertions(+), 163 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 4dbf37afe5..58a8ac9027 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -72,6 +72,174 @@ static const int mb_type_b_map[4] = {
     MB_TYPE_L0      | MB_TYPE_16x16,
 };
 
+static void gmc1_motion(MpegEncContext *s,
+                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                        uint8_t *const *ref_picture)
+{
+    const uint8_t *ptr;
+    int src_x, src_y, motion_x, motion_y;
+    ptrdiff_t offset, linesize, uvlinesize;
+    int emu = 0;
+
+    motion_x   = s->sprite_offset[0][0];
+    motion_y   = s->sprite_offset[0][1];
+    src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
+    src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
+    motion_x *= 1 << (3 - s->sprite_warping_accuracy);
+    motion_y *= 1 << (3 - s->sprite_warping_accuracy);
+    src_x      = av_clip(src_x, -16, s->width);
+    if (src_x == s->width)
+        motion_x = 0;
+    src_y = av_clip(src_y, -16, s->height);
+    if (src_y == s->height)
+        motion_y = 0;
+
+    linesize   = s->linesize;
+    uvlinesize = s->uvlinesize;
+
+    ptr = ref_picture[0] + src_y * linesize + src_x;
+
+    if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
+        (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
+        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
+                                 linesize, linesize,
+                                 17, 17,
+                                 src_x, src_y,
+                                 s->h_edge_pos, s->v_edge_pos);
+        ptr = s->sc.edge_emu_buffer;
+    }
+
+    if ((motion_x | motion_y) & 7) {
+        s->mdsp.gmc1(dest_y, ptr, linesize, 16,
+                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+        s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
+                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+    } else {
+        int dxy;
+
+        dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
+        if (s->no_rounding) {
+            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
+        } else {
+            s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
+        }
+    }
+
+    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
+        return;
+
+    motion_x   = s->sprite_offset[1][0];
+    motion_y   = s->sprite_offset[1][1];
+    src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
+    src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
+    motion_x  *= 1 << (3 - s->sprite_warping_accuracy);
+    motion_y  *= 1 << (3 - s->sprite_warping_accuracy);
+    src_x      = av_clip(src_x, -8, s->width >> 1);
+    if (src_x == s->width >> 1)
+        motion_x = 0;
+    src_y = av_clip(src_y, -8, s->height >> 1);
+    if (src_y == s->height >> 1)
+        motion_y = 0;
+
+    offset = (src_y * uvlinesize) + src_x;
+    ptr    = ref_picture[1] + offset;
+    if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
+        (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
+        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
+                                 uvlinesize, uvlinesize,
+                                 9, 9,
+                                 src_x, src_y,
+                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+        ptr = s->sc.edge_emu_buffer;
+        emu = 1;
+    }
+    s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
+                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+
+    ptr = ref_picture[2] + offset;
+    if (emu) {
+        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
+                                 uvlinesize, uvlinesize,
+                                 9, 9,
+                                 src_x, src_y,
+                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
+        ptr = s->sc.edge_emu_buffer;
+    }
+    s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
+                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+}
+
+static void gmc_motion(MpegEncContext *s,
+                       uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                       uint8_t *const *ref_picture)
+{
+    const uint8_t *ptr;
+    int linesize, uvlinesize;
+    const int a = s->sprite_warping_accuracy;
+    int ox, oy;
+
+    linesize   = s->linesize;
+    uvlinesize = s->uvlinesize;
+
+    ptr = ref_picture[0];
+
+    ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
+         s->sprite_delta[0][1] * s->mb_y * 16;
+    oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
+         s->sprite_delta[1][1] * s->mb_y * 16;
+
+    s->mdsp.gmc(dest_y, ptr, linesize, 16,
+                ox, oy,
+                s->sprite_delta[0][0], s->sprite_delta[0][1],
+                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                s->h_edge_pos, s->v_edge_pos);
+    s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
+                ox + s->sprite_delta[0][0] * 8,
+                oy + s->sprite_delta[1][0] * 8,
+                s->sprite_delta[0][0], s->sprite_delta[0][1],
+                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                s->h_edge_pos, s->v_edge_pos);
+
+    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
+        return;
+
+    ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
+         s->sprite_delta[0][1] * s->mb_y * 8;
+    oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
+         s->sprite_delta[1][1] * s->mb_y * 8;
+
+    ptr = ref_picture[1];
+    s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
+                ox, oy,
+                s->sprite_delta[0][0], s->sprite_delta[0][1],
+                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
+
+    ptr = ref_picture[2];
+    s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
+                ox, oy,
+                s->sprite_delta[0][0], s->sprite_delta[0][1],
+                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
+}
+
+void ff_mpeg4_mcsel_motion(MpegEncContext *s,
+                           uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                           uint8_t *const *ref_picture)
+{
+    if (s->real_sprite_warping_points == 1) {
+        gmc1_motion(s, dest_y, dest_cb, dest_cr,
+                    ref_picture);
+    } else {
+        gmc_motion(s, dest_y, dest_cb, dest_cr,
+                    ref_picture);
+    }
+}
+
 void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
                             uint8_t *dest_cr, int block_size, int uvlinesize,
                             int dct_linesize, int dct_offset)
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 65d846aed0..8d1e121b67 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -87,6 +87,9 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
 void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
                             uint8_t *dest_cr, int block_size, int uvlinesize,
                             int dct_linesize, int dct_offset);
+void ff_mpeg4_mcsel_motion(MpegEncContext *s,
+                           uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+                           uint8_t *const *ref_picture);
 int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx);
 int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
 int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx);
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index fe3bfc4454..8922f5b1a5 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -31,164 +31,10 @@
 #include "h261.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
+#include "mpeg4videodec.h"
 #include "qpeldsp.h"
 #include "wmv2.h"
 
-static void gmc1_motion(MpegEncContext *s,
-                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
-                        uint8_t *const *ref_picture)
-{
-    const uint8_t *ptr;
-    int src_x, src_y, motion_x, motion_y;
-    ptrdiff_t offset, linesize, uvlinesize;
-    int emu = 0;
-
-    motion_x   = s->sprite_offset[0][0];
-    motion_y   = s->sprite_offset[0][1];
-    src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
-    src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
-    motion_x *= 1 << (3 - s->sprite_warping_accuracy);
-    motion_y *= 1 << (3 - s->sprite_warping_accuracy);
-    src_x      = av_clip(src_x, -16, s->width);
-    if (src_x == s->width)
-        motion_x = 0;
-    src_y = av_clip(src_y, -16, s->height);
-    if (src_y == s->height)
-        motion_y = 0;
-
-    linesize   = s->linesize;
-    uvlinesize = s->uvlinesize;
-
-    ptr = ref_picture[0] + src_y * linesize + src_x;
-
-    if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
-        (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
-        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
-                                 linesize, linesize,
-                                 17, 17,
-                                 src_x, src_y,
-                                 s->h_edge_pos, s->v_edge_pos);
-        ptr = s->sc.edge_emu_buffer;
-    }
-
-    if ((motion_x | motion_y) & 7) {
-        s->mdsp.gmc1(dest_y, ptr, linesize, 16,
-                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
-        s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
-                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
-    } else {
-        int dxy;
-
-        dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
-        if (s->no_rounding) {
-            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
-        } else {
-            s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
-        }
-    }
-
-    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
-        return;
-
-    motion_x   = s->sprite_offset[1][0];
-    motion_y   = s->sprite_offset[1][1];
-    src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
-    src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
-    motion_x  *= 1 << (3 - s->sprite_warping_accuracy);
-    motion_y  *= 1 << (3 - s->sprite_warping_accuracy);
-    src_x      = av_clip(src_x, -8, s->width >> 1);
-    if (src_x == s->width >> 1)
-        motion_x = 0;
-    src_y = av_clip(src_y, -8, s->height >> 1);
-    if (src_y == s->height >> 1)
-        motion_y = 0;
-
-    offset = (src_y * uvlinesize) + src_x;
-    ptr    = ref_picture[1] + offset;
-    if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
-        (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
-        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
-                                 uvlinesize, uvlinesize,
-                                 9, 9,
-                                 src_x, src_y,
-                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
-        ptr = s->sc.edge_emu_buffer;
-        emu = 1;
-    }
-    s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
-                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
-
-    ptr = ref_picture[2] + offset;
-    if (emu) {
-        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
-                                 uvlinesize, uvlinesize,
-                                 9, 9,
-                                 src_x, src_y,
-                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
-        ptr = s->sc.edge_emu_buffer;
-    }
-    s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
-                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
-}
-
-static void gmc_motion(MpegEncContext *s,
-                       uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
-                       uint8_t *const *ref_picture)
-{
-    const uint8_t *ptr;
-    int linesize, uvlinesize;
-    const int a = s->sprite_warping_accuracy;
-    int ox, oy;
-
-    linesize   = s->linesize;
-    uvlinesize = s->uvlinesize;
-
-    ptr = ref_picture[0];
-
-    ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
-         s->sprite_delta[0][1] * s->mb_y * 16;
-    oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
-         s->sprite_delta[1][1] * s->mb_y * 16;
-
-    s->mdsp.gmc(dest_y, ptr, linesize, 16,
-                ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                s->h_edge_pos, s->v_edge_pos);
-    s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
-                ox + s->sprite_delta[0][0] * 8,
-                oy + s->sprite_delta[1][0] * 8,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                s->h_edge_pos, s->v_edge_pos);
-
-    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
-        return;
-
-    ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
-         s->sprite_delta[0][1] * s->mb_y * 8;
-    oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
-         s->sprite_delta[1][1] * s->mb_y * 8;
-
-    ptr = ref_picture[1];
-    s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
-                ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
-
-    ptr = ref_picture[2];
-    s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
-                ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
-}
-
 static inline int hpel_motion(MpegEncContext *s,
                               uint8_t *dest, uint8_t *src,
                               int src_x, int src_y,
@@ -849,14 +695,8 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s,
 
     switch (s->mv_type) {
     case MV_TYPE_16X16:
-        if (!is_mpeg12 && s->mcsel) {
-            if (s->real_sprite_warping_points == 1) {
-                gmc1_motion(s, dest_y, dest_cb, dest_cr,
-                            ref_picture);
-            } else {
-                gmc_motion(s, dest_y, dest_cb, dest_cr,
-                           ref_picture);
-            }
+        if (CONFIG_MPEG4_DECODER && !is_mpeg12 && s->mcsel) {
+            ff_mpeg4_mcsel_motion(s, dest_y, dest_cb, dest_cr, ref_picture);
         } else if (!is_mpeg12 && s->quarter_sample) {
             qpel_motion(s, dest_y, dest_cb, dest_cr,
                         0, 0, 0,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
@ 2022-10-12 18:06 ` Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContext Andreas Rheinhardt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It is only used by gmc/gmc1 which is only used by the MPEG-4
decoder, so move it to Mpeg4DecContext and rename it
to Mpeg4VideoDSP. Also compile it iff the MPEG-4 decoder is compiled.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/Makefile                           |  4 +-
 libavcodec/mpeg4videodec.c                    | 58 ++++++++++---------
 libavcodec/mpeg4videodec.h                    |  3 +
 .../{mpegvideodsp.c => mpeg4videodsp.c}       |  8 +--
 .../{mpegvideodsp.h => mpeg4videodsp.h}       | 16 ++---
 libavcodec/mpegvideo.c                        |  1 -
 libavcodec/mpegvideo.h                        |  2 -
 libavcodec/ppc/Makefile                       |  4 +-
 .../ppc/{mpegvideodsp.c => mpeg4videodsp.c}   |  4 +-
 libavcodec/x86/Makefile                       |  5 +-
 .../x86/{mpegvideodsp.c => mpeg4videodsp.c}   |  4 +-
 11 files changed, 57 insertions(+), 52 deletions(-)
 rename libavcodec/{mpegvideodsp.c => mpeg4videodsp.c} (96%)
 rename libavcodec/{mpegvideodsp.h => mpeg4videodsp.h} (81%)
 rename libavcodec/ppc/{mpegvideodsp.c => mpeg4videodsp.c} (98%)
 rename libavcodec/x86/{mpegvideodsp.c => mpeg4videodsp.c} (98%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 37b63cadc2..2df7479721 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -132,7 +132,7 @@ OBJS-$(CONFIG_MPEGAUDIODSP)            += mpegaudiodsp.o                \
                                           mpegaudiodsp_float.o
 OBJS-$(CONFIG_MPEGAUDIOHEADER)         += mpegaudiodecheader.o mpegaudiotabs.o
 OBJS-$(CONFIG_MPEG4AUDIO)              += mpeg4audio.o mpeg4audio_sample_rates.o
-OBJS-$(CONFIG_MPEGVIDEO)               += mpegvideo.o mpegvideodsp.o rl.o \
+OBJS-$(CONFIG_MPEGVIDEO)               += mpegvideo.o rl.o \
                                           mpegvideo_motion.o \
                                           mpegvideodata.o mpegpicture.o  \
                                           to_upper4.o
@@ -523,7 +523,7 @@ OBJS-$(CONFIG_MPEG2_CUVID_DECODER)     += cuviddec.o
 OBJS-$(CONFIG_MPEG2_MEDIACODEC_DECODER) += mediacodecdec.o
 OBJS-$(CONFIG_MPEG2_VAAPI_ENCODER)     += vaapi_encode_mpeg2.o
 OBJS-$(CONFIG_MPEG2_V4L2M2M_DECODER)   += v4l2_m2m_dec.o
-OBJS-$(CONFIG_MPEG4_DECODER)           += xvididct.o
+OBJS-$(CONFIG_MPEG4_DECODER)           += mpeg4videodsp.o xvididct.o
 OBJS-$(CONFIG_MPEG4_ENCODER)           += mpeg4videoenc.o
 OBJS-$(CONFIG_MPEG4_CUVID_DECODER)     += cuviddec.o
 OBJS-$(CONFIG_MPEG4_MEDIACODEC_DECODER) += mediacodecdec.o
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 58a8ac9027..1638664e00 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -72,7 +72,7 @@ static const int mb_type_b_map[4] = {
     MB_TYPE_L0      | MB_TYPE_16x16,
 };
 
-static void gmc1_motion(MpegEncContext *s,
+static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
                         uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
                         uint8_t *const *ref_picture)
 {
@@ -110,10 +110,10 @@ static void gmc1_motion(MpegEncContext *s,
     }
 
     if ((motion_x | motion_y) & 7) {
-        s->mdsp.gmc1(dest_y, ptr, linesize, 16,
-                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
-        s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
-                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+        ctx->mdsp.gmc1(dest_y, ptr, linesize, 16,
+                       motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+        ctx->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
+                       motion_x & 15, motion_y & 15, 128 - s->no_rounding);
     } else {
         int dxy;
 
@@ -153,8 +153,8 @@ static void gmc1_motion(MpegEncContext *s,
         ptr = s->sc.edge_emu_buffer;
         emu = 1;
     }
-    s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
-                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+    ctx->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
+                   motion_x & 15, motion_y & 15, 128 - s->no_rounding);
 
     ptr = ref_picture[2] + offset;
     if (emu) {
@@ -165,11 +165,11 @@ static void gmc1_motion(MpegEncContext *s,
                                  s->h_edge_pos >> 1, s->v_edge_pos >> 1);
         ptr = s->sc.edge_emu_buffer;
     }
-    s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
-                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
+    ctx->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
+                   motion_x & 15, motion_y & 15, 128 - s->no_rounding);
 }
 
-static void gmc_motion(MpegEncContext *s,
+static void gmc_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
                        uint8_t *const *ref_picture)
 {
@@ -188,13 +188,13 @@ static void gmc_motion(MpegEncContext *s,
     oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
          s->sprite_delta[1][1] * s->mb_y * 16;
 
-    s->mdsp.gmc(dest_y, ptr, linesize, 16,
-                ox, oy,
+    ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
+                  ox, oy,
                 s->sprite_delta[0][0], s->sprite_delta[0][1],
                 s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                s->h_edge_pos, s->v_edge_pos);
-    s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
+                  a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                  s->h_edge_pos, s->v_edge_pos);
+    ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
                 ox + s->sprite_delta[0][0] * 8,
                 oy + s->sprite_delta[1][0] * 8,
                 s->sprite_delta[0][0], s->sprite_delta[0][1],
@@ -211,31 +211,33 @@ static void gmc_motion(MpegEncContext *s,
          s->sprite_delta[1][1] * s->mb_y * 8;
 
     ptr = ref_picture[1];
-    s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
-                ox, oy,
+    ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
+                  ox, oy,
                 s->sprite_delta[0][0], s->sprite_delta[0][1],
                 s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
+                  a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                  (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
 
     ptr = ref_picture[2];
-    s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
-                ox, oy,
+    ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
+                  ox, oy,
                 s->sprite_delta[0][0], s->sprite_delta[0][1],
                 s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
+                  a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                  (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
 }
 
 void ff_mpeg4_mcsel_motion(MpegEncContext *s,
                            uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
                            uint8_t *const *ref_picture)
 {
+    const Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+
     if (s->real_sprite_warping_points == 1) {
-        gmc1_motion(s, dest_y, dest_cb, dest_cr,
+        gmc1_motion(s, ctx, dest_y, dest_cb, dest_cr,
                     ref_picture);
     } else {
-        gmc_motion(s, dest_y, dest_cb, dest_cr,
+        gmc_motion(s, ctx, dest_y, dest_cb, dest_cr,
                     ref_picture);
     }
 }
@@ -3684,6 +3686,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
     return 0;
 }
 
+#if CONFIG_MPEG4_DECODER
 #if HAVE_THREADS
 static int mpeg4_update_thread_context(AVCodecContext *dst,
                                        const AVCodecContext *src)
@@ -3726,7 +3729,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
     memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
     memcpy(s->sprite_traj,  s1->sprite_traj,  sizeof(s1->sprite_traj));
 
-    if (CONFIG_MPEG4_DECODER && !init && s1->xvid_build >= 0)
+    if (!init && s1->xvid_build >= 0)
         ff_xvid_idct_init(&s->m.idsp, dst);
 
     return 0;
@@ -3814,6 +3817,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
 
+    ff_mpeg4videodsp_init(&ctx->mdsp);
+
     ff_thread_once(&init_static_once, mpeg4_init_static);
 
     return 0;
@@ -3873,3 +3878,4 @@ const FFCodec ff_mpeg4_decoder = {
                                NULL
                            },
 };
+#endif /* CONFIG_MPEG4_DECODER */
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 8d1e121b67..302c5c38da 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -27,6 +27,7 @@
 
 #include "get_bits.h"
 #include "mpegvideo.h"
+#include "mpeg4videodsp.h"
 
 
 typedef struct Mpeg4DecContext {
@@ -76,6 +77,8 @@ typedef struct Mpeg4DecContext {
 
     int rgb;
 
+    Mpeg4VideoDSPContext mdsp;
+
     int32_t block32[12][64];
     // 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan
     int dpcm_direction;
diff --git a/libavcodec/mpegvideodsp.c b/libavcodec/mpeg4videodsp.c
similarity index 96%
rename from libavcodec/mpegvideodsp.c
rename to libavcodec/mpeg4videodsp.c
index 05893d0e01..1c5661a076 100644
--- a/libavcodec/mpegvideodsp.c
+++ b/libavcodec/mpeg4videodsp.c
@@ -19,7 +19,7 @@
 #include "config.h"
 #include "libavutil/attributes.h"
 #include "libavutil/common.h"
-#include "mpegvideodsp.h"
+#include "mpeg4videodsp.h"
 
 static void gmc1_c(uint8_t *dst, const uint8_t *src, int stride, int h,
                    int x16, int y16, int rounder)
@@ -107,14 +107,14 @@ void ff_gmc_c(uint8_t *dst, const uint8_t *src, int stride, int h, int ox, int o
     }
 }
 
-av_cold void ff_mpegvideodsp_init(MpegVideoDSPContext *c)
+av_cold void ff_mpeg4videodsp_init(Mpeg4VideoDSPContext *c)
 {
     c->gmc1 = gmc1_c;
     c->gmc  = ff_gmc_c;
 
 #if ARCH_PPC
-    ff_mpegvideodsp_init_ppc(c);
+    ff_mpeg4videodsp_init_ppc(c);
 #elif ARCH_X86
-    ff_mpegvideodsp_init_x86(c);
+    ff_mpeg4videodsp_init_x86(c);
 #endif
 }
diff --git a/libavcodec/mpegvideodsp.h b/libavcodec/mpeg4videodsp.h
similarity index 81%
rename from libavcodec/mpegvideodsp.h
rename to libavcodec/mpeg4videodsp.h
index 69e6053c68..e1ccb71ce9 100644
--- a/libavcodec/mpegvideodsp.h
+++ b/libavcodec/mpeg4videodsp.h
@@ -16,8 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef AVCODEC_MPEGVIDEODSP_H
-#define AVCODEC_MPEGVIDEODSP_H
+#ifndef AVCODEC_MPEG4VIDEODSP_H
+#define AVCODEC_MPEG4VIDEODSP_H
 
 #include <stdint.h>
 
@@ -25,7 +25,7 @@ void ff_gmc_c(uint8_t *dst, const uint8_t *src, int stride, int h, int ox, int o
               int dxx, int dxy, int dyx, int dyy, int shift, int r,
               int width, int height);
 
-typedef struct MpegVideoDSPContext {
+typedef struct Mpeg4VideoDSPContext {
     /**
      * translational global motion compensation.
      */
@@ -38,10 +38,10 @@ typedef struct MpegVideoDSPContext {
                 int stride, int h, int ox, int oy,
                 int dxx, int dxy, int dyx, int dyy,
                 int shift, int r, int width, int height);
-} MpegVideoDSPContext;
+} Mpeg4VideoDSPContext;
 
-void ff_mpegvideodsp_init(MpegVideoDSPContext *c);
-void ff_mpegvideodsp_init_ppc(MpegVideoDSPContext *c);
-void ff_mpegvideodsp_init_x86(MpegVideoDSPContext *c);
+void ff_mpeg4videodsp_init(Mpeg4VideoDSPContext *c);
+void ff_mpeg4videodsp_init_ppc(Mpeg4VideoDSPContext *c);
+void ff_mpeg4videodsp_init_x86(Mpeg4VideoDSPContext *c);
 
-#endif /* AVCODEC_MPEGVIDEODSP_H */
+#endif /* AVCODEC_MPEG4VIDEODSP_H */
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 5095149eaa..b9fa6dc2d1 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -284,7 +284,6 @@ static av_cold int dct_init(MpegEncContext *s)
     ff_blockdsp_init(&s->bdsp);
     ff_h264chroma_init(&s->h264chroma, 8); //for lowres
     ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
-    ff_mpegvideodsp_init(&s->mdsp);
     ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
 
     if (s->avctx->debug & FF_DEBUG_NOMC) {
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 1ddf8034aa..007d681a09 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -40,7 +40,6 @@
 #include "me_cmp.h"
 #include "motion_est.h"
 #include "mpegpicture.h"
-#include "mpegvideodsp.h"
 #include "mpegvideoencdsp.h"
 #include "pixblockdsp.h"
 #include "put_bits.h"
@@ -209,7 +208,6 @@ typedef struct MpegEncContext {
     HpelDSPContext hdsp;
     IDCTDSPContext idsp;
     MECmpContext mecc;
-    MpegVideoDSPContext mdsp;
     MpegvideoEncDSPContext mpvencdsp;
     PixblockDSPContext pdsp;
     QpelDSPContext qdsp;
diff --git a/libavcodec/ppc/Makefile b/libavcodec/ppc/Makefile
index 03e5b42d33..bc13d8a0ce 100644
--- a/libavcodec/ppc/Makefile
+++ b/libavcodec/ppc/Makefile
@@ -14,8 +14,7 @@ OBJS-$(CONFIG_IDCTDSP)                 += ppc/idctdsp.o
 OBJS-$(CONFIG_LLVIDDSP)                += ppc/lossless_videodsp_altivec.o
 OBJS-$(CONFIG_ME_CMP)                  += ppc/me_cmp.o
 OBJS-$(CONFIG_MPEGAUDIODSP)            += ppc/mpegaudiodsp_altivec.o
-OBJS-$(CONFIG_MPEGVIDEO)               += ppc/mpegvideo_altivec.o      \
-                                          ppc/mpegvideodsp.o
+OBJS-$(CONFIG_MPEGVIDEO)               += ppc/mpegvideo_altivec.o
 OBJS-$(CONFIG_MPEGVIDEOENC)            += ppc/mpegvideoencdsp.o
 OBJS-$(CONFIG_PIXBLOCKDSP)             += ppc/pixblockdsp.o
 OBJS-$(CONFIG_VC1DSP)                  += ppc/vc1dsp_altivec.o
@@ -26,6 +25,7 @@ OBJS-$(CONFIG_VP8DSP)                  += ppc/vp8dsp_altivec.o
 # decoders/encoders
 OBJS-$(CONFIG_HEVC_DECODER)            += ppc/hevcdsp.o
 OBJS-$(CONFIG_LLAUDDSP)                += ppc/lossless_audiodsp_altivec.o
+OBJS-$(CONFIG_MPEG4_DECODER)           += ppc/mpeg4videodsp.o
 OBJS-$(CONFIG_SVQ1_ENCODER)            += ppc/svq1enc_altivec.o
 OBJS-$(CONFIG_VORBIS_DECODER)          += ppc/vorbisdsp_altivec.o
 OBJS-$(CONFIG_VP7_DECODER)             += ppc/vp8dsp_altivec.o
diff --git a/libavcodec/ppc/mpegvideodsp.c b/libavcodec/ppc/mpeg4videodsp.c
similarity index 98%
rename from libavcodec/ppc/mpegvideodsp.c
rename to libavcodec/ppc/mpeg4videodsp.c
index 3e99e089ea..8b30af4258 100644
--- a/libavcodec/ppc/mpegvideodsp.c
+++ b/libavcodec/ppc/mpeg4videodsp.c
@@ -26,7 +26,7 @@
 #include "libavutil/ppc/cpu.h"
 #include "libavutil/ppc/util_altivec.h"
 
-#include "libavcodec/mpegvideodsp.h"
+#include "libavcodec/mpeg4videodsp.h"
 
 #if HAVE_ALTIVEC
 /* AltiVec-enhanced gmc1. ATM this code assumes stride is a multiple of 8
@@ -128,7 +128,7 @@ static void gmc1_altivec(uint8_t *dst /* align 8 */, const uint8_t *src /* align
 }
 #endif /* HAVE_ALTIVEC */
 
-av_cold void ff_mpegvideodsp_init_ppc(MpegVideoDSPContext *c)
+av_cold void ff_mpeg4videodsp_init_ppc(Mpeg4VideoDSPContext *c)
 {
 #if HAVE_ALTIVEC
     if (!PPC_ALTIVEC(av_get_cpu_flags()))
diff --git a/libavcodec/x86/Makefile b/libavcodec/x86/Makefile
index e1120b7e15..ec6adcd8b0 100644
--- a/libavcodec/x86/Makefile
+++ b/libavcodec/x86/Makefile
@@ -27,8 +27,7 @@ OBJS-$(CONFIG_LPC)                     += x86/lpc_init.o
 OBJS-$(CONFIG_MDCT15)                  += x86/mdct15_init.o
 OBJS-$(CONFIG_ME_CMP)                  += x86/me_cmp_init.o
 OBJS-$(CONFIG_MPEGAUDIODSP)            += x86/mpegaudiodsp.o
-OBJS-$(CONFIG_MPEGVIDEO)               += x86/mpegvideo.o              \
-                                          x86/mpegvideodsp.o
+OBJS-$(CONFIG_MPEGVIDEO)               += x86/mpegvideo.o
 OBJS-$(CONFIG_MPEGVIDEOENC)            += x86/mpegvideoenc.o           \
                                           x86/mpegvideoencdsp_init.o
 OBJS-$(CONFIG_PIXBLOCKDSP)             += x86/pixblockdsp_init.o
@@ -62,7 +61,7 @@ OBJS-$(CONFIG_HEVC_DECODER)            += x86/hevcdsp_init.o
 OBJS-$(CONFIG_JPEG2000_DECODER)        += x86/jpeg2000dsp_init.o
 OBJS-$(CONFIG_LSCR_DECODER)            += x86/pngdsp_init.o
 OBJS-$(CONFIG_MLP_DECODER)             += x86/mlpdsp_init.o
-OBJS-$(CONFIG_MPEG4_DECODER)           += x86/xvididct_init.o
+OBJS-$(CONFIG_MPEG4_DECODER)           += x86/mpeg4videodsp.o x86/xvididct_init.o
 OBJS-$(CONFIG_PNG_DECODER)             += x86/pngdsp_init.o
 OBJS-$(CONFIG_PRORES_DECODER)          += x86/proresdsp_init.o
 OBJS-$(CONFIG_PRORES_LGPL_DECODER)     += x86/proresdsp_init.o
diff --git a/libavcodec/x86/mpegvideodsp.c b/libavcodec/x86/mpeg4videodsp.c
similarity index 98%
rename from libavcodec/x86/mpegvideodsp.c
rename to libavcodec/x86/mpeg4videodsp.c
index ea1d941fba..6a1c6c5064 100644
--- a/libavcodec/x86/mpegvideodsp.c
+++ b/libavcodec/x86/mpeg4videodsp.c
@@ -20,7 +20,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/cpu.h"
 #include "libavutil/x86/cpu.h"
-#include "libavcodec/mpegvideodsp.h"
+#include "libavcodec/mpeg4videodsp.h"
 #include "libavcodec/videodsp.h"
 
 #if HAVE_INLINE_ASM
@@ -150,7 +150,7 @@ static void gmc_mmx(uint8_t *dst, const uint8_t *src,
 
 #endif /* HAVE_INLINE_ASM */
 
-av_cold void ff_mpegvideodsp_init_x86(MpegVideoDSPContext *c)
+av_cold void ff_mpeg4videodsp_init_x86(Mpeg4VideoDSPContext *c)
 {
 #if HAVE_INLINE_ASM
     int cpu_flags = av_get_cpu_flags();
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContext
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only Andreas Rheinhardt
@ 2022-10-12 18:06 ` Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 4/6] avcodec/mpeg4videodec: Sync sprite_warping_accuracy between threads Andreas Rheinhardt
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Only used there.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4videodec.c | 106 ++++++++++++++++++-------------------
 libavcodec/mpeg4videodec.h |   4 ++
 libavcodec/mpegvideo.h     |   4 --
 libavcodec/vaapi_mpeg4.c   |   2 +-
 4 files changed, 58 insertions(+), 58 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 1638664e00..dcf970af5a 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -81,12 +81,12 @@ static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
     ptrdiff_t offset, linesize, uvlinesize;
     int emu = 0;
 
-    motion_x   = s->sprite_offset[0][0];
-    motion_y   = s->sprite_offset[0][1];
-    src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
-    src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
-    motion_x *= 1 << (3 - s->sprite_warping_accuracy);
-    motion_y *= 1 << (3 - s->sprite_warping_accuracy);
+    motion_x   = ctx->sprite_offset[0][0];
+    motion_y   = ctx->sprite_offset[0][1];
+    src_x      = s->mb_x * 16 + (motion_x >> (ctx->sprite_warping_accuracy + 1));
+    src_y      = s->mb_y * 16 + (motion_y >> (ctx->sprite_warping_accuracy + 1));
+    motion_x *= 1 << (3 - ctx->sprite_warping_accuracy);
+    motion_y *= 1 << (3 - ctx->sprite_warping_accuracy);
     src_x      = av_clip(src_x, -16, s->width);
     if (src_x == s->width)
         motion_x = 0;
@@ -128,12 +128,12 @@ static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
     if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
         return;
 
-    motion_x   = s->sprite_offset[1][0];
-    motion_y   = s->sprite_offset[1][1];
-    src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
-    src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
-    motion_x  *= 1 << (3 - s->sprite_warping_accuracy);
-    motion_y  *= 1 << (3 - s->sprite_warping_accuracy);
+    motion_x   = ctx->sprite_offset[1][0];
+    motion_y   = ctx->sprite_offset[1][1];
+    src_x      = s->mb_x * 8 + (motion_x >> (ctx->sprite_warping_accuracy + 1));
+    src_y      = s->mb_y * 8 + (motion_y >> (ctx->sprite_warping_accuracy + 1));
+    motion_x  *= 1 << (3 - ctx->sprite_warping_accuracy);
+    motion_y  *= 1 << (3 - ctx->sprite_warping_accuracy);
     src_x      = av_clip(src_x, -8, s->width >> 1);
     if (src_x == s->width >> 1)
         motion_x = 0;
@@ -175,7 +175,7 @@ static void gmc_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
 {
     const uint8_t *ptr;
     int linesize, uvlinesize;
-    const int a = s->sprite_warping_accuracy;
+    const int a = ctx->sprite_warping_accuracy;
     int ox, oy;
 
     linesize   = s->linesize;
@@ -183,46 +183,46 @@ static void gmc_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
 
     ptr = ref_picture[0];
 
-    ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
-         s->sprite_delta[0][1] * s->mb_y * 16;
-    oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
-         s->sprite_delta[1][1] * s->mb_y * 16;
+    ox = ctx->sprite_offset[0][0] + ctx->sprite_delta[0][0] * s->mb_x * 16 +
+         ctx->sprite_delta[0][1] * s->mb_y * 16;
+    oy = ctx->sprite_offset[0][1] + ctx->sprite_delta[1][0] * s->mb_x * 16 +
+         ctx->sprite_delta[1][1] * s->mb_y * 16;
 
     ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
                   ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                  ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
+                  ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
                   a + 1, (1 << (2 * a + 1)) - s->no_rounding,
                   s->h_edge_pos, s->v_edge_pos);
     ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
-                ox + s->sprite_delta[0][0] * 8,
-                oy + s->sprite_delta[1][0] * 8,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
-                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
-                s->h_edge_pos, s->v_edge_pos);
+                  ox + ctx->sprite_delta[0][0] * 8,
+                  oy + ctx->sprite_delta[1][0] * 8,
+                  ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
+                  ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
+                  a + 1, (1 << (2 * a + 1)) - s->no_rounding,
+                  s->h_edge_pos, s->v_edge_pos);
 
     if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
         return;
 
-    ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
-         s->sprite_delta[0][1] * s->mb_y * 8;
-    oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
-         s->sprite_delta[1][1] * s->mb_y * 8;
+    ox = ctx->sprite_offset[1][0] + ctx->sprite_delta[0][0] * s->mb_x * 8 +
+         ctx->sprite_delta[0][1] * s->mb_y * 8;
+    oy = ctx->sprite_offset[1][1] + ctx->sprite_delta[1][0] * s->mb_x * 8 +
+         ctx->sprite_delta[1][1] * s->mb_y * 8;
 
     ptr = ref_picture[1];
     ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
                   ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                  ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
+                  ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
                   a + 1, (1 << (2 * a + 1)) - s->no_rounding,
                   (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
 
     ptr = ref_picture[2];
     ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
                   ox, oy,
-                s->sprite_delta[0][0], s->sprite_delta[0][1],
-                s->sprite_delta[1][0], s->sprite_delta[1][1],
+                  ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
+                  ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
                   a + 1, (1 << (2 * a + 1)) - s->no_rounding,
                   (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
 }
@@ -233,7 +233,7 @@ void ff_mpeg4_mcsel_motion(MpegEncContext *s,
 {
     const Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
 
-    if (s->real_sprite_warping_points == 1) {
+    if (ctx->real_sprite_warping_points == 1) {
         gmc1_motion(s, ctx, dest_y, dest_cb, dest_cr,
                     ref_picture);
     } else {
@@ -418,8 +418,8 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
 static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
 {
     MpegEncContext *s = &ctx->m;
-    int a     = 2 << s->sprite_warping_accuracy;
-    int rho   = 3  - s->sprite_warping_accuracy;
+    int a     = 2 << ctx->sprite_warping_accuracy;
+    int rho   = 3  - ctx->sprite_warping_accuracy;
     int r     = 16 / a;
     int alpha = 1;
     int beta  = 0;
@@ -607,7 +607,7 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
         sprite_delta[1][1] = a;
         ctx->sprite_shift[0] = 0;
         ctx->sprite_shift[1] = 0;
-        s->real_sprite_warping_points = 1;
+        ctx->real_sprite_warping_points = 1;
     } else {
         int shift_y = 16 - ctx->sprite_shift[0];
         int shift_c = 16 - ctx->sprite_shift[1];
@@ -653,18 +653,18 @@ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *g
                 goto overflow;
             }
         }
-        s->real_sprite_warping_points = ctx->num_sprite_warping_points;
+        ctx->real_sprite_warping_points = ctx->num_sprite_warping_points;
     }
 
     for (i = 0; i < 4; i++) {
-        s->sprite_offset[i&1][i>>1] = sprite_offset[i&1][i>>1];
-        s->sprite_delta [i&1][i>>1] = sprite_delta [i&1][i>>1];
+        ctx->sprite_offset[i&1][i>>1] = sprite_offset[i&1][i>>1];
+        ctx->sprite_delta [i&1][i>>1] = sprite_delta [i&1][i>>1];
     }
 
     return 0;
 overflow:
-    memset(s->sprite_offset, 0, sizeof(s->sprite_offset));
-    memset(s->sprite_delta, 0, sizeof(s->sprite_delta));
+    memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
+    memset(ctx->sprite_delta,  0, sizeof(ctx->sprite_delta));
     return AVERROR_PATCHWELCOME;
 }
 
@@ -832,25 +832,25 @@ static inline int get_amv(Mpeg4DecContext *ctx, int n)
     MpegEncContext *s = &ctx->m;
     int x, y, mb_v, sum, dx, dy, shift;
     int len     = 1 << (s->f_code + 4);
-    const int a = s->sprite_warping_accuracy;
+    const int a = ctx->sprite_warping_accuracy;
 
     if (s->workaround_bugs & FF_BUG_AMV)
         len >>= s->quarter_sample;
 
-    if (s->real_sprite_warping_points == 1) {
+    if (ctx->real_sprite_warping_points == 1) {
         if (ctx->divx_version == 500 && ctx->divx_build == 413 && a >= s->quarter_sample)
-            sum = s->sprite_offset[0][n] / (1 << (a - s->quarter_sample));
+            sum = ctx->sprite_offset[0][n] / (1 << (a - s->quarter_sample));
         else
-            sum = RSHIFT(s->sprite_offset[0][n] * (1 << s->quarter_sample), a);
+            sum = RSHIFT(ctx->sprite_offset[0][n] * (1 << s->quarter_sample), a);
     } else {
-        dx    = s->sprite_delta[n][0];
-        dy    = s->sprite_delta[n][1];
+        dx    = ctx->sprite_delta[n][0];
+        dy    = ctx->sprite_delta[n][1];
         shift = ctx->sprite_shift[0];
         if (n)
             dy -= 1 << (shift + a + 1);
         else
             dx -= 1 << (shift + a + 1);
-        mb_v = s->sprite_offset[0][n] + dx * s->mb_x * 16U + dy * s->mb_y * 16U;
+        mb_v = ctx->sprite_offset[0][n] + dx * s->mb_x * 16U + dy * s->mb_y * 16U;
 
         sum = 0;
         for (y = 0; y < 16; y++) {
@@ -2698,7 +2698,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
                 ctx->num_sprite_warping_points = 0;
                 return AVERROR_INVALIDDATA;
             }
-            s->sprite_warping_accuracy  = get_bits(gb, 2);
+            ctx->sprite_warping_accuracy  = get_bits(gb, 2);
             ctx->sprite_brightness_change = get_bits1(gb);
             if (ctx->vol_sprite_usage == STATIC_SPRITE)
                 skip_bits1(gb); // low_latency_sprite
@@ -3286,8 +3286,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
             if (ctx->vol_sprite_usage == STATIC_SPRITE)
                 av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
         } else {
-            memset(s->sprite_offset, 0, sizeof(s->sprite_offset));
-            memset(s->sprite_delta, 0, sizeof(s->sprite_delta));
+            memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
+            memset(ctx->sprite_delta,  0, sizeof(ctx->sprite_delta));
         }
     }
 
@@ -3329,7 +3329,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
                    gb->size_in_bits,s->progressive_sequence, s->alternate_scan,
                    s->top_field_first, s->quarter_sample ? 'q' : 'h',
                    s->data_partitioning, ctx->resync_marker,
-                   ctx->num_sprite_warping_points, s->sprite_warping_accuracy,
+                   ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy,
                    1 - s->no_rounding, ctx->vo_type,
                    ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold,
                    ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p,
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 302c5c38da..c0e6ec6592 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -38,7 +38,11 @@ typedef struct Mpeg4DecContext {
     int shape;
     int vol_sprite_usage;
     int sprite_brightness_change;
+    int sprite_warping_accuracy;
     int num_sprite_warping_points;
+    int real_sprite_warping_points;
+    int sprite_offset[2][2];         ///< sprite offset[isChroma][isMVY]
+    int sprite_delta[2][2];          ///< sprite_delta [isY][isMVY]
     /// sprite trajectory points
     uint16_t sprite_traj[4][2];
     /// sprite shift [isChroma]
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 007d681a09..925e61138d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -376,13 +376,9 @@ typedef struct MpegEncContext {
     uint16_t pb_time;               ///< time distance between the last b and p,s,i frame
     uint16_t pp_field_time;
     uint16_t pb_field_time;         ///< like above, just for interlaced
-    int real_sprite_warping_points;
-    int sprite_offset[2][2];         ///< sprite offset[isChroma][isMVY]
-    int sprite_delta[2][2];          ///< sprite_delta [isY][isMVY]
     int mcsel;
     int quant_precision;
     int quarter_sample;              ///< 1->qpel, 0->half pel ME/MC
-    int sprite_warping_accuracy;
     int data_partitioning;           ///< data partitioning flag from header
     int partitioned_frame;           ///< is current frame partitioned
     int low_delay;                   ///< no reordering needed / has no B-frames
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index ca3f3b22f6..4e74e0382b 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -66,7 +66,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_
             .interlaced                   = !s->progressive_sequence,
             .obmc_disable                 = 1,
             .sprite_enable                = ctx->vol_sprite_usage,
-            .sprite_warping_accuracy      = s->sprite_warping_accuracy,
+            .sprite_warping_accuracy      = ctx->sprite_warping_accuracy,
             .quant_type                   = s->mpeg_quant,
             .quarter_sample               = s->quarter_sample,
             .data_partitioned             = s->data_partitioning,
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 4/6] avcodec/mpeg4videodec: Sync sprite_warping_accuracy between threads
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContext Andreas Rheinhardt
@ 2022-10-12 18:06 ` Andreas Rheinhardt
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks Andreas Rheinhardt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

It is set in the vol header and is therefore a sequence and
not only a picture property.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4videodec.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index dcf970af5a..aeb0d003ec 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3705,6 +3705,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
     s->shape                     = s1->shape;
     s->vol_sprite_usage          = s1->vol_sprite_usage;
     s->sprite_brightness_change  = s1->sprite_brightness_change;
+    s->sprite_warping_accuracy   = s1->sprite_warping_accuracy;
     s->num_sprite_warping_points = s1->num_sprite_warping_points;
     s->m.data_partitioning       = s1->m.data_partitioning;
     s->rvlc                      = s1->rvlc;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
                   ` (2 preceding siblings ...)
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 4/6] avcodec/mpeg4videodec: Sync sprite_warping_accuracy between threads Andreas Rheinhardt
@ 2022-10-12 18:06 ` Andreas Rheinhardt
  2022-10-13 21:05   ` Michael Niedermayer
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 6/6] avcodec/mpeg4videodec: Reindent after the previous commit Andreas Rheinhardt
  2022-10-19 12:24 ` [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
  5 siblings, 1 reply; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

codec_id is always AV_CODEC_ID_MPEG4 in this file.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4videodec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index aeb0d003ec..b4e2c09706 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1648,6 +1648,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
     int16_t *mot_val;
     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
     const int xy = s->mb_x + s->mb_y * s->mb_stride;
+    int next;
 
     av_assert2(s ==  (void*)ctx);
     av_assert2(s->h263_pred);
@@ -1999,8 +2000,7 @@ intra:
 
 end:
     /* per-MB end of slice check */
-    if (s->codec_id == AV_CODEC_ID_MPEG4) {
-        int next = mpeg4_is_resync(ctx);
+    next = mpeg4_is_resync(ctx);
         if (next) {
             if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
                 return AVERROR_INVALIDDATA;
@@ -2019,7 +2019,6 @@ end:
 
             return SLICE_END;
         }
-    }
 
     return SLICE_OK;
 }
@@ -3084,7 +3083,6 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
                ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
 
     if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
-        s->codec_id == AV_CODEC_ID_MPEG4 &&
         avctx->idct_algo == FF_IDCT_AUTO) {
         avctx->idct_algo = FF_IDCT_XVID;
         ff_mpv_idct_init(s);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH 6/6] avcodec/mpeg4videodec: Reindent after the previous commit
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
                   ` (3 preceding siblings ...)
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks Andreas Rheinhardt
@ 2022-10-12 18:06 ` Andreas Rheinhardt
  2022-10-19 12:24 ` [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
  5 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-12 18:06 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4videodec.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index b4e2c09706..c4f268c534 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2001,25 +2001,25 @@ intra:
 end:
     /* per-MB end of slice check */
     next = mpeg4_is_resync(ctx);
-        if (next) {
-            if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
-                return AVERROR_INVALIDDATA;
-            } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
-                return SLICE_END;
-
-            if (s->pict_type == AV_PICTURE_TYPE_B) {
-                const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
-                ff_thread_await_progress(&s->next_picture_ptr->tf,
-                                         (s->mb_x + delta >= s->mb_width)
-                                         ? FFMIN(s->mb_y + 1, s->mb_height - 1)
-                                         : s->mb_y, 0);
-                if (s->next_picture.mbskip_table[xy + delta])
-                    return SLICE_OK;
-            }
-
+    if (next) {
+        if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
+            return AVERROR_INVALIDDATA;
+        } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
             return SLICE_END;
+
+        if (s->pict_type == AV_PICTURE_TYPE_B) {
+            const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
+            ff_thread_await_progress(&s->next_picture_ptr->tf,
+                                        (s->mb_x + delta >= s->mb_width)
+                                        ? FFMIN(s->mb_y + 1, s->mb_height - 1)
+                                        : s->mb_y, 0);
+            if (s->next_picture.mbskip_table[xy + delta])
+                return SLICE_OK;
         }
 
+        return SLICE_END;
+    }
+
     return SLICE_OK;
 }
 
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks Andreas Rheinhardt
@ 2022-10-13 21:05   ` Michael Niedermayer
  2022-10-13 21:23     ` Andreas Rheinhardt
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Niedermayer @ 2022-10-13 21:05 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 815 bytes --]

Hi

On Wed, Oct 12, 2022 at 08:06:22PM +0200, Andreas Rheinhardt wrote:
> codec_id is always AV_CODEC_ID_MPEG4 in this file.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mpeg4videodec.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
[...]
> @@ -3084,7 +3083,6 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
>                 ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
>  
>      if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
> -        s->codec_id == AV_CODEC_ID_MPEG4 &&

should the CONFIG_MPEG4_DECODER check be removed too ?

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks
  2022-10-13 21:05   ` Michael Niedermayer
@ 2022-10-13 21:23     ` Andreas Rheinhardt
  2022-10-13 22:22       ` Michael Niedermayer
  0 siblings, 1 reply; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-13 21:23 UTC (permalink / raw)
  To: ffmpeg-devel

Michael Niedermayer:
> Hi
> 
> On Wed, Oct 12, 2022 at 08:06:22PM +0200, Andreas Rheinhardt wrote:
>> codec_id is always AV_CODEC_ID_MPEG4 in this file.
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavcodec/mpeg4videodec.c | 6 ++----
>>  1 file changed, 2 insertions(+), 4 deletions(-)
> [...]
>> @@ -3084,7 +3083,6 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
>>                 ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
>>  
>>      if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
>> -        s->codec_id == AV_CODEC_ID_MPEG4 &&
> 
> should the CONFIG_MPEG4_DECODER check be removed too ?
> 

This file is also compiled if the MPEG-4 parser or the H.263 decoder is
enabled (hence if any of the H.263 decoder family is enabled); the
former is probably done because of ff_mpeg4_pred_ac() which is used by
msmpeg4dec.c (this is the only exception to what I wrote in the commit
message; will amend it). The latter could be solved by moving the code
common to mpeg4-decoder and parser out into a file of its own, say
mpeg4_parse.c. I pondered doing that; would you have any objections to
it? It would allow to cut down on the crazy list of requirements of the
mpeg4 parser.
Anyway, given that both the MPEG-4 parser as well as the H.263 decoder
already require mpegvideodec, one could remove this CONFIG_MPEG4_DECODER
without causing linking failures, but doing so would cause a tiny bit
more code to be included in case the MPEG-4 decoder is disabled (in
fact, ff_mpeg4_workaround_bugs() is completely unnecessary in this
case). So removing it has a tiny disadvantage now and I intend to deal
with this whole issue later anyway, so I don't intend to do it now
(unless you insist).

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks
  2022-10-13 21:23     ` Andreas Rheinhardt
@ 2022-10-13 22:22       ` Michael Niedermayer
  2022-10-18 23:13         ` [FFmpeg-devel] [PATCH v2 " Andreas Rheinhardt
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Niedermayer @ 2022-10-13 22:22 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1919 bytes --]

On Thu, Oct 13, 2022 at 11:23:33PM +0200, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Hi
> > 
> > On Wed, Oct 12, 2022 at 08:06:22PM +0200, Andreas Rheinhardt wrote:
> >> codec_id is always AV_CODEC_ID_MPEG4 in this file.
> >>
> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> >> ---
> >>  libavcodec/mpeg4videodec.c | 6 ++----
> >>  1 file changed, 2 insertions(+), 4 deletions(-)
> > [...]
> >> @@ -3084,7 +3083,6 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
> >>                 ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
> >>  
> >>      if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
> >> -        s->codec_id == AV_CODEC_ID_MPEG4 &&
> > 
> > should the CONFIG_MPEG4_DECODER check be removed too ?
> > 
> 
> This file is also compiled if the MPEG-4 parser or the H.263 decoder is
> enabled (hence if any of the H.263 decoder family is enabled); the
> former is probably done because of ff_mpeg4_pred_ac() which is used by
> msmpeg4dec.c (this is the only exception to what I wrote in the commit
> message; will amend it). The latter could be solved by moving the code
> common to mpeg4-decoder and parser out into a file of its own, say
> mpeg4_parse.c. I pondered doing that; would you have any objections to
> it? It would allow to cut down on the crazy list of requirements of the
> mpeg4 parser.

really, you are doing this factorization, you decide which way it makes
most sense.
Id just say something if i see something that "feels" wrong
here it was just me seeing te compile time check and you saying its always
AV_CODEC_ID_MPEG4.
Maybe you could word the commit messsage more verbosely 

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [FFmpeg-devel] [PATCH v2 5/6] avcodec/mpeg4videodec: Remove always-true checks
  2022-10-13 22:22       ` Michael Niedermayer
@ 2022-10-18 23:13         ` Andreas Rheinhardt
  0 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-18 23:13 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

codec_id is always AV_CODEC_ID_MPEG4 for mpeg4_decode_mb(),
as the MPEG-4 decoder is the only decoder for which
ff_mpeg4_decode_picture_header() as well as decode_init()
are ever called and these are the only places where
the decode_mb function pointer is ever set to mpeg4_decode_mb().
ff_mpeg4_workaround_bugs() is also only called for the MPEG-4
decoder (the caller checks the codec id).

(ff_mpeg4_decode_picture_header() is also called for the MPEG-4
parser, but it never uses the decode_mb function pointer.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
I hope this commit message is detailed enough now.

 libavcodec/mpeg4videodec.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index aeb0d003ec..b4e2c09706 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1648,6 +1648,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
     int16_t *mot_val;
     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
     const int xy = s->mb_x + s->mb_y * s->mb_stride;
+    int next;
 
     av_assert2(s ==  (void*)ctx);
     av_assert2(s->h263_pred);
@@ -1999,8 +2000,7 @@ intra:
 
 end:
     /* per-MB end of slice check */
-    if (s->codec_id == AV_CODEC_ID_MPEG4) {
-        int next = mpeg4_is_resync(ctx);
+    next = mpeg4_is_resync(ctx);
         if (next) {
             if        (s->mb_x + s->mb_y*s->mb_width + 1 >  next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
                 return AVERROR_INVALIDDATA;
@@ -2019,7 +2019,6 @@ end:
 
             return SLICE_END;
         }
-    }
 
     return SLICE_OK;
 }
@@ -3084,7 +3083,6 @@ int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
                ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
 
     if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
-        s->codec_id == AV_CODEC_ID_MPEG4 &&
         avctx->idct_algo == FF_IDCT_AUTO) {
         avctx->idct_algo = FF_IDCT_XVID;
         ff_mpv_idct_init(s);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c
  2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
                   ` (4 preceding siblings ...)
  2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 6/6] avcodec/mpeg4videodec: Reindent after the previous commit Andreas Rheinhardt
@ 2022-10-19 12:24 ` Andreas Rheinhardt
  5 siblings, 0 replies; 11+ messages in thread
From: Andreas Rheinhardt @ 2022-10-19 12:24 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> It is the only codec for which mcsel is ever set.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/mpeg4videodec.c    | 168 ++++++++++++++++++++++++++++++++++
>  libavcodec/mpeg4videodec.h    |   3 +
>  libavcodec/mpegvideo_motion.c | 166 +--------------------------------
>  3 files changed, 174 insertions(+), 163 deletions(-)
> 
> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> index 4dbf37afe5..58a8ac9027 100644
> --- a/libavcodec/mpeg4videodec.c
> +++ b/libavcodec/mpeg4videodec.c
> @@ -72,6 +72,174 @@ static const int mb_type_b_map[4] = {
>      MB_TYPE_L0      | MB_TYPE_16x16,
>  };
>  
> +static void gmc1_motion(MpegEncContext *s,
> +                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> +                        uint8_t *const *ref_picture)
> +{
> +    const uint8_t *ptr;
> +    int src_x, src_y, motion_x, motion_y;
> +    ptrdiff_t offset, linesize, uvlinesize;
> +    int emu = 0;
> +
> +    motion_x   = s->sprite_offset[0][0];
> +    motion_y   = s->sprite_offset[0][1];
> +    src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
> +    src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
> +    motion_x *= 1 << (3 - s->sprite_warping_accuracy);
> +    motion_y *= 1 << (3 - s->sprite_warping_accuracy);
> +    src_x      = av_clip(src_x, -16, s->width);
> +    if (src_x == s->width)
> +        motion_x = 0;
> +    src_y = av_clip(src_y, -16, s->height);
> +    if (src_y == s->height)
> +        motion_y = 0;
> +
> +    linesize   = s->linesize;
> +    uvlinesize = s->uvlinesize;
> +
> +    ptr = ref_picture[0] + src_y * linesize + src_x;
> +
> +    if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
> +        (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
> +        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> +                                 linesize, linesize,
> +                                 17, 17,
> +                                 src_x, src_y,
> +                                 s->h_edge_pos, s->v_edge_pos);
> +        ptr = s->sc.edge_emu_buffer;
> +    }
> +
> +    if ((motion_x | motion_y) & 7) {
> +        s->mdsp.gmc1(dest_y, ptr, linesize, 16,
> +                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> +        s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
> +                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> +    } else {
> +        int dxy;
> +
> +        dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
> +        if (s->no_rounding) {
> +            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
> +        } else {
> +            s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
> +        }
> +    }
> +
> +    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
> +        return;
> +
> +    motion_x   = s->sprite_offset[1][0];
> +    motion_y   = s->sprite_offset[1][1];
> +    src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
> +    src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
> +    motion_x  *= 1 << (3 - s->sprite_warping_accuracy);
> +    motion_y  *= 1 << (3 - s->sprite_warping_accuracy);
> +    src_x      = av_clip(src_x, -8, s->width >> 1);
> +    if (src_x == s->width >> 1)
> +        motion_x = 0;
> +    src_y = av_clip(src_y, -8, s->height >> 1);
> +    if (src_y == s->height >> 1)
> +        motion_y = 0;
> +
> +    offset = (src_y * uvlinesize) + src_x;
> +    ptr    = ref_picture[1] + offset;
> +    if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
> +        (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
> +        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> +                                 uvlinesize, uvlinesize,
> +                                 9, 9,
> +                                 src_x, src_y,
> +                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
> +        ptr = s->sc.edge_emu_buffer;
> +        emu = 1;
> +    }
> +    s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
> +                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> +
> +    ptr = ref_picture[2] + offset;
> +    if (emu) {
> +        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> +                                 uvlinesize, uvlinesize,
> +                                 9, 9,
> +                                 src_x, src_y,
> +                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
> +        ptr = s->sc.edge_emu_buffer;
> +    }
> +    s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
> +                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> +}
> +
> +static void gmc_motion(MpegEncContext *s,
> +                       uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> +                       uint8_t *const *ref_picture)
> +{
> +    const uint8_t *ptr;
> +    int linesize, uvlinesize;
> +    const int a = s->sprite_warping_accuracy;
> +    int ox, oy;
> +
> +    linesize   = s->linesize;
> +    uvlinesize = s->uvlinesize;
> +
> +    ptr = ref_picture[0];
> +
> +    ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
> +         s->sprite_delta[0][1] * s->mb_y * 16;
> +    oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
> +         s->sprite_delta[1][1] * s->mb_y * 16;
> +
> +    s->mdsp.gmc(dest_y, ptr, linesize, 16,
> +                ox, oy,
> +                s->sprite_delta[0][0], s->sprite_delta[0][1],
> +                s->sprite_delta[1][0], s->sprite_delta[1][1],
> +                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> +                s->h_edge_pos, s->v_edge_pos);
> +    s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
> +                ox + s->sprite_delta[0][0] * 8,
> +                oy + s->sprite_delta[1][0] * 8,
> +                s->sprite_delta[0][0], s->sprite_delta[0][1],
> +                s->sprite_delta[1][0], s->sprite_delta[1][1],
> +                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> +                s->h_edge_pos, s->v_edge_pos);
> +
> +    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
> +        return;
> +
> +    ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
> +         s->sprite_delta[0][1] * s->mb_y * 8;
> +    oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
> +         s->sprite_delta[1][1] * s->mb_y * 8;
> +
> +    ptr = ref_picture[1];
> +    s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
> +                ox, oy,
> +                s->sprite_delta[0][0], s->sprite_delta[0][1],
> +                s->sprite_delta[1][0], s->sprite_delta[1][1],
> +                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> +                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
> +
> +    ptr = ref_picture[2];
> +    s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
> +                ox, oy,
> +                s->sprite_delta[0][0], s->sprite_delta[0][1],
> +                s->sprite_delta[1][0], s->sprite_delta[1][1],
> +                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> +                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
> +}
> +
> +void ff_mpeg4_mcsel_motion(MpegEncContext *s,
> +                           uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> +                           uint8_t *const *ref_picture)
> +{
> +    if (s->real_sprite_warping_points == 1) {
> +        gmc1_motion(s, dest_y, dest_cb, dest_cr,
> +                    ref_picture);
> +    } else {
> +        gmc_motion(s, dest_y, dest_cb, dest_cr,
> +                    ref_picture);
> +    }
> +}
> +
>  void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
>                              uint8_t *dest_cr, int block_size, int uvlinesize,
>                              int dct_linesize, int dct_offset)
> diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
> index 65d846aed0..8d1e121b67 100644
> --- a/libavcodec/mpeg4videodec.h
> +++ b/libavcodec/mpeg4videodec.h
> @@ -87,6 +87,9 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
>  void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
>                              uint8_t *dest_cr, int block_size, int uvlinesize,
>                              int dct_linesize, int dct_offset);
> +void ff_mpeg4_mcsel_motion(MpegEncContext *s,
> +                           uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> +                           uint8_t *const *ref_picture);
>  int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx);
>  int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
>  int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx);
> diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
> index fe3bfc4454..8922f5b1a5 100644
> --- a/libavcodec/mpegvideo_motion.c
> +++ b/libavcodec/mpegvideo_motion.c
> @@ -31,164 +31,10 @@
>  #include "h261.h"
>  #include "mpegutils.h"
>  #include "mpegvideo.h"
> +#include "mpeg4videodec.h"
>  #include "qpeldsp.h"
>  #include "wmv2.h"
>  
> -static void gmc1_motion(MpegEncContext *s,
> -                        uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> -                        uint8_t *const *ref_picture)
> -{
> -    const uint8_t *ptr;
> -    int src_x, src_y, motion_x, motion_y;
> -    ptrdiff_t offset, linesize, uvlinesize;
> -    int emu = 0;
> -
> -    motion_x   = s->sprite_offset[0][0];
> -    motion_y   = s->sprite_offset[0][1];
> -    src_x      = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy + 1));
> -    src_y      = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy + 1));
> -    motion_x *= 1 << (3 - s->sprite_warping_accuracy);
> -    motion_y *= 1 << (3 - s->sprite_warping_accuracy);
> -    src_x      = av_clip(src_x, -16, s->width);
> -    if (src_x == s->width)
> -        motion_x = 0;
> -    src_y = av_clip(src_y, -16, s->height);
> -    if (src_y == s->height)
> -        motion_y = 0;
> -
> -    linesize   = s->linesize;
> -    uvlinesize = s->uvlinesize;
> -
> -    ptr = ref_picture[0] + src_y * linesize + src_x;
> -
> -    if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
> -        (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
> -        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> -                                 linesize, linesize,
> -                                 17, 17,
> -                                 src_x, src_y,
> -                                 s->h_edge_pos, s->v_edge_pos);
> -        ptr = s->sc.edge_emu_buffer;
> -    }
> -
> -    if ((motion_x | motion_y) & 7) {
> -        s->mdsp.gmc1(dest_y, ptr, linesize, 16,
> -                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> -        s->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
> -                     motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> -    } else {
> -        int dxy;
> -
> -        dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
> -        if (s->no_rounding) {
> -            s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
> -        } else {
> -            s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
> -        }
> -    }
> -
> -    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
> -        return;
> -
> -    motion_x   = s->sprite_offset[1][0];
> -    motion_y   = s->sprite_offset[1][1];
> -    src_x      = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy + 1));
> -    src_y      = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy + 1));
> -    motion_x  *= 1 << (3 - s->sprite_warping_accuracy);
> -    motion_y  *= 1 << (3 - s->sprite_warping_accuracy);
> -    src_x      = av_clip(src_x, -8, s->width >> 1);
> -    if (src_x == s->width >> 1)
> -        motion_x = 0;
> -    src_y = av_clip(src_y, -8, s->height >> 1);
> -    if (src_y == s->height >> 1)
> -        motion_y = 0;
> -
> -    offset = (src_y * uvlinesize) + src_x;
> -    ptr    = ref_picture[1] + offset;
> -    if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
> -        (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
> -        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> -                                 uvlinesize, uvlinesize,
> -                                 9, 9,
> -                                 src_x, src_y,
> -                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
> -        ptr = s->sc.edge_emu_buffer;
> -        emu = 1;
> -    }
> -    s->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
> -                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> -
> -    ptr = ref_picture[2] + offset;
> -    if (emu) {
> -        s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
> -                                 uvlinesize, uvlinesize,
> -                                 9, 9,
> -                                 src_x, src_y,
> -                                 s->h_edge_pos >> 1, s->v_edge_pos >> 1);
> -        ptr = s->sc.edge_emu_buffer;
> -    }
> -    s->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
> -                 motion_x & 15, motion_y & 15, 128 - s->no_rounding);
> -}
> -
> -static void gmc_motion(MpegEncContext *s,
> -                       uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
> -                       uint8_t *const *ref_picture)
> -{
> -    const uint8_t *ptr;
> -    int linesize, uvlinesize;
> -    const int a = s->sprite_warping_accuracy;
> -    int ox, oy;
> -
> -    linesize   = s->linesize;
> -    uvlinesize = s->uvlinesize;
> -
> -    ptr = ref_picture[0];
> -
> -    ox = s->sprite_offset[0][0] + s->sprite_delta[0][0] * s->mb_x * 16 +
> -         s->sprite_delta[0][1] * s->mb_y * 16;
> -    oy = s->sprite_offset[0][1] + s->sprite_delta[1][0] * s->mb_x * 16 +
> -         s->sprite_delta[1][1] * s->mb_y * 16;
> -
> -    s->mdsp.gmc(dest_y, ptr, linesize, 16,
> -                ox, oy,
> -                s->sprite_delta[0][0], s->sprite_delta[0][1],
> -                s->sprite_delta[1][0], s->sprite_delta[1][1],
> -                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> -                s->h_edge_pos, s->v_edge_pos);
> -    s->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
> -                ox + s->sprite_delta[0][0] * 8,
> -                oy + s->sprite_delta[1][0] * 8,
> -                s->sprite_delta[0][0], s->sprite_delta[0][1],
> -                s->sprite_delta[1][0], s->sprite_delta[1][1],
> -                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> -                s->h_edge_pos, s->v_edge_pos);
> -
> -    if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
> -        return;
> -
> -    ox = s->sprite_offset[1][0] + s->sprite_delta[0][0] * s->mb_x * 8 +
> -         s->sprite_delta[0][1] * s->mb_y * 8;
> -    oy = s->sprite_offset[1][1] + s->sprite_delta[1][0] * s->mb_x * 8 +
> -         s->sprite_delta[1][1] * s->mb_y * 8;
> -
> -    ptr = ref_picture[1];
> -    s->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
> -                ox, oy,
> -                s->sprite_delta[0][0], s->sprite_delta[0][1],
> -                s->sprite_delta[1][0], s->sprite_delta[1][1],
> -                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> -                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
> -
> -    ptr = ref_picture[2];
> -    s->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
> -                ox, oy,
> -                s->sprite_delta[0][0], s->sprite_delta[0][1],
> -                s->sprite_delta[1][0], s->sprite_delta[1][1],
> -                a + 1, (1 << (2 * a + 1)) - s->no_rounding,
> -                (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
> -}
> -
>  static inline int hpel_motion(MpegEncContext *s,
>                                uint8_t *dest, uint8_t *src,
>                                int src_x, int src_y,
> @@ -849,14 +695,8 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s,
>  
>      switch (s->mv_type) {
>      case MV_TYPE_16X16:
> -        if (!is_mpeg12 && s->mcsel) {
> -            if (s->real_sprite_warping_points == 1) {
> -                gmc1_motion(s, dest_y, dest_cb, dest_cr,
> -                            ref_picture);
> -            } else {
> -                gmc_motion(s, dest_y, dest_cb, dest_cr,
> -                           ref_picture);
> -            }
> +        if (CONFIG_MPEG4_DECODER && !is_mpeg12 && s->mcsel) {
> +            ff_mpeg4_mcsel_motion(s, dest_y, dest_cb, dest_cr, ref_picture);
>          } else if (!is_mpeg12 && s->quarter_sample) {
>              qpel_motion(s, dest_y, dest_cb, dest_cr,
>                          0, 0, 0,

Will apply this patchset tomorrow unless there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-10-19 12:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 18:03 [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt
2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 2/6] avcodec/mpegvideodsp: Make MpegVideoDSP MPEG-4 only Andreas Rheinhardt
2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 3/6] avcodec/mpegvideo: Move sprite-related fields to Mpeg4DecContext Andreas Rheinhardt
2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 4/6] avcodec/mpeg4videodec: Sync sprite_warping_accuracy between threads Andreas Rheinhardt
2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 5/6] avcodec/mpeg4videodec: Remove always-true checks Andreas Rheinhardt
2022-10-13 21:05   ` Michael Niedermayer
2022-10-13 21:23     ` Andreas Rheinhardt
2022-10-13 22:22       ` Michael Niedermayer
2022-10-18 23:13         ` [FFmpeg-devel] [PATCH v2 " Andreas Rheinhardt
2022-10-12 18:06 ` [FFmpeg-devel] [PATCH 6/6] avcodec/mpeg4videodec: Reindent after the previous commit Andreas Rheinhardt
2022-10-19 12:24 ` [FFmpeg-devel] [PATCH 1/6] avcodec/mpegvideo_motion: Move mspel/gmc motion to mpeg4videodec.c Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git