summaryrefslogtreecommitdiff
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-10-14 05:39:59 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-10-20 07:29:03 +0200
commit6fe4e8fab47089ff095d994a2a2b986cff0a50d4 (patch)
tree22d3f1365f31df626cc234049e4c1c77505373b4 /libavcodec/mpegvideo_enc.c
parent9ca312d8abd0d5d9364346392959f0a6d2061219 (diff)
downloadffmpeg-6fe4e8fab47089ff095d994a2a2b986cff0a50d4.tar.gz
avcodec/mpegvideo: Split ff_mpv_reconstruct_mb() into de/encoder part
This has the advantage of not having to check for whether a given MpegEncContext is actually a decoder or an encoder context at runtime. To do so, mpv_reconstruct_mb_internal() is moved into a new template file that is included by both mpegvideo_enc.c and mpegvideo_dec.c; the decoder-only code (mainly lowres) are also moved to mpegvideo_dec.c. The is_encoder checks are changed to #if IS_ENCODER in order to avoid having to include headers for decoder-only functions in mpegvideo_enc.c. This approach also has the advantage that it is easy to adapt mpv_reconstruct_mb_internal() to using different structures for decoders and encoders (e.g. the check for whether a macroblock should be processed for the encoder or not uses MpegEncContext elements that make no sense for decoders and should not be part of their context). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 2cbb856866..ce363a585d 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1017,6 +1017,26 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
return 0;
}
+#define IS_ENCODER 1
+#include "mpv_reconstruct_mb_template.c"
+
+static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
+{
+ if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
+ /* print DCT coefficients */
+ av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
+ for (int i = 0; i < 6; i++) {
+ for (int j = 0; j < 64; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "%5d",
+ block[i][s->idsp.idct_permutation[j]]);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+
+ mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12);
+}
+
static int get_sae(const uint8_t *src, int ref, int stride)
{
int x,y;
@@ -2577,7 +2597,7 @@ static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegE
}
if(s->avctx->mb_decision == FF_MB_DECISION_RD){
- ff_mpv_reconstruct_mb(s, s->block);
+ mpv_reconstruct_mb(s, s->block);
score *= s->lambda2;
score += sse_mb(s) << FF_LAMBDA_SHIFT;
@@ -3287,7 +3307,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
if(s->avctx->mb_decision == FF_MB_DECISION_BITS)
- ff_mpv_reconstruct_mb(s, s->block);
+ mpv_reconstruct_mb(s, s->block);
} else {
int motion_x = 0, motion_y = 0;
s->mv_type=MV_TYPE_16X16;
@@ -3406,7 +3426,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B)
ff_h263_update_motion_val(s);
- ff_mpv_reconstruct_mb(s, s->block);
+ mpv_reconstruct_mb(s, s->block);
}
/* clean the MV table in IPS frames for direct mode in B-frames */