diff mbox series

[FFmpeg-devel,27/33] avcodec/mpegvideo: Move handling Simple Studio Profile to mpeg4videodec

Message ID AM7PR03MB6660523FEBA06750286C3BC58F209@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 85ac29ad1cbb1ab2e1294a7e8a30db20df7c0b86
Headers show
Series [FFmpeg-devel,01/21] avcodec/h263: Remove declaration for inexistent function | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 26, 2022, 9:34 p.m. UTC
This is its only user.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/mpeg4video.h    |  4 +++
 libavcodec/mpeg4videodec.c | 62 +++++++++++++++++++++++++++++++++++
 libavcodec/mpegvideo.c     | 66 +++-----------------------------------
 3 files changed, 71 insertions(+), 61 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index fd6b6f2863..08beb7f29f 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -119,6 +119,10 @@  typedef struct Mpeg4DecContext {
     int rgb;
 } Mpeg4DecContext;
 
+
+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_encode_mb(MpegEncContext *s,
                         int16_t block[6][64],
                         int motion_x, int motion_y);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index bdd320b1df..fb43ad2d17 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -67,6 +67,68 @@  static const int mb_type_b_map[4] = {
     MB_TYPE_L0      | MB_TYPE_16x16,
 };
 
+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)
+{
+    const int act_block_size = block_size * 2;
+
+    if (s->dpcm_direction == 0) {
+        s->idsp.idct_put(dest_y,                               dct_linesize, (int16_t*)(*s->block32)[0]);
+        s->idsp.idct_put(dest_y              + act_block_size, dct_linesize, (int16_t*)(*s->block32)[1]);
+        s->idsp.idct_put(dest_y + dct_offset,                  dct_linesize, (int16_t*)(*s->block32)[2]);
+        s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)(*s->block32)[3]);
+
+        dct_linesize = uvlinesize << s->interlaced_dct;
+        dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
+
+        s->idsp.idct_put(dest_cb,              dct_linesize, (int16_t*)(*s->block32)[4]);
+        s->idsp.idct_put(dest_cr,              dct_linesize, (int16_t*)(*s->block32)[5]);
+        s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)(*s->block32)[6]);
+        s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)(*s->block32)[7]);
+        if (!s->chroma_x_shift){ //Chroma444
+            s->idsp.idct_put(dest_cb + act_block_size,              dct_linesize, (int16_t*)(*s->block32)[8]);
+            s->idsp.idct_put(dest_cr + act_block_size,              dct_linesize, (int16_t*)(*s->block32)[9]);
+            s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[10]);
+            s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[11]);
+        }
+    } else if(s->dpcm_direction == 1) {
+        uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
+        int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
+        for (int i = 0; i < 3; i++) {
+            const uint16_t *src = (*s->dpcm_macroblock)[i];
+            int vsub = i ? s->chroma_y_shift : 0;
+            int hsub = i ? s->chroma_x_shift : 0;
+            int lowres = s->avctx->lowres;
+            int step = 1 << lowres;
+            for (int h = 0; h < (16 >> (vsub + lowres)); h++){
+                for (int w = 0, idx = 0; w < (16 >> (hsub + lowres)); w++, idx += step)
+                    dest_pcm[i][w] = src[idx];
+                dest_pcm[i] += linesize[i] / 2;
+                src         += (16 >> hsub) * step;
+            }
+        }
+    } else {
+        uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
+        int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
+        av_assert2(s->dpcm_direction == -1);
+        for (int i = 0; i < 3; i++) {
+            const uint16_t *src = (*s->dpcm_macroblock)[i];
+            int vsub = i ? s->chroma_y_shift : 0;
+            int hsub = i ? s->chroma_x_shift : 0;
+            int lowres = s->avctx->lowres;
+            int step = 1 << lowres;
+            dest_pcm[i] += (linesize[i] / 2) * ((16 >> vsub) - 1);
+            for (int h = (16 >> (vsub + lowres)) - 1; h >= 0; h--){
+                for (int w = (16 >> (hsub + lowres)) - 1, idx = 0; w >= 0; w--, idx += step)
+                    dest_pcm[i][w] = src[idx];
+                src += step * (16 >> hsub);
+                dest_pcm[i] -= linesize[i] / 2;
+            }
+        }
+    }
+}
+
 /**
  * Predict the ac.
  * @param n block index (0-3 are luma, 4-5 are chroma)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 40494fe115..a231ee52b7 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -40,6 +40,7 @@ 
 #include "mpeg_er.h"
 #include "mpegutils.h"
 #include "mpegvideo.h"
+#include "mpeg4video.h"
 #include "mpegvideodata.h"
 #include "qpeldsp.h"
 #include "thread.h"
@@ -1602,67 +1603,10 @@  void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
         } else {
             /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
                TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
-            if (!is_mpeg12 && s->avctx->bits_per_raw_sample > 8) {
-                const int act_block_size = block_size * 2;
-
-                if(s->dpcm_direction == 0) {
-                    s->idsp.idct_put(dest_y,                           dct_linesize, (int16_t*)(*s->block32)[0]);
-                    s->idsp.idct_put(dest_y              + act_block_size, dct_linesize, (int16_t*)(*s->block32)[1]);
-                    s->idsp.idct_put(dest_y + dct_offset,              dct_linesize, (int16_t*)(*s->block32)[2]);
-                    s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)(*s->block32)[3]);
-
-                    dct_linesize = uvlinesize << s->interlaced_dct;
-                    dct_offset   = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
-
-                    s->idsp.idct_put(dest_cb,              dct_linesize, (int16_t*)(*s->block32)[4]);
-                    s->idsp.idct_put(dest_cr,              dct_linesize, (int16_t*)(*s->block32)[5]);
-                    s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)(*s->block32)[6]);
-                    s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)(*s->block32)[7]);
-                    if(!s->chroma_x_shift){//Chroma444
-                        s->idsp.idct_put(dest_cb + act_block_size,              dct_linesize, (int16_t*)(*s->block32)[8]);
-                        s->idsp.idct_put(dest_cr + act_block_size,              dct_linesize, (int16_t*)(*s->block32)[9]);
-                        s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[10]);
-                        s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[11]);
-                    }
-                } else if(s->dpcm_direction == 1) {
-                    int i, w, h;
-                    uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
-                    int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
-                    for(i = 0; i < 3; i++) {
-                        const int16_t *src = (*s->dpcm_macroblock)[i];
-                        int idx = 0;
-                        int vsub = i ? s->chroma_y_shift : 0;
-                        int hsub = i ? s->chroma_x_shift : 0;
-                        int lowres = lowres_flag ? s->avctx->lowres : 0;
-                        int step = 1 << lowres;
-                        for (h = 0; h < (16 >> (vsub + lowres)); h++){
-                            for (w = 0, idx = 0; w < (16 >> (hsub + lowres)); w++, idx += step)
-                                dest_pcm[i][w] = src[idx];
-                            dest_pcm[i] += linesize[i] / 2;
-                            src         += (16 >> hsub) * step;
-                        }
-                    }
-                } else {
-                    int i, w, h;
-                    uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
-                    int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
-                    av_assert2(s->dpcm_direction == -1);
-                    for(i = 0; i < 3; i++) {
-                        const int16_t *src = (*s->dpcm_macroblock)[i];
-                        int idx = 0;
-                        int vsub = i ? s->chroma_y_shift : 0;
-                        int hsub = i ? s->chroma_x_shift : 0;
-                        int lowres = lowres_flag ? s->avctx->lowres : 0;
-                        int step = 1 << lowres;
-                        dest_pcm[i] += (linesize[i] / 2) * ((16 >> vsub) - 1);
-                        for (h = (16 >> (vsub + lowres)) - 1; h >= 0; h--){
-                            for (w = (16 >> (hsub + lowres)) - 1, idx = 0; w >= 0; w--, idx += step)
-                                dest_pcm[i][w] = src[idx];
-                            src += step * (16 >> hsub);
-                            dest_pcm[i] -= linesize[i] / 2;
-                        }
-                    }
-                }
+            if (!is_mpeg12 && CONFIG_MPEG4_DECODER && /* s->codec_id == AV_CODEC_ID_MPEG4 && */
+                s->avctx->bits_per_raw_sample > 8) {
+                ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
+                                       uvlinesize, dct_linesize, dct_offset);
             }
             /* dct only in intra block */
             else if (IS_ENCODER(s) || !IS_MPEG12(s)) {