]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/mss2.c
nvenc: Allow different const qps for I, P and B frames
[ffmpeg] / libavcodec / mss2.c
index 6f9391f870a1a538c61419f477f7a48383687a83..6fcadb16c9c45d800ef9b1af4720a101ec1e6090 100644 (file)
 #include "libavutil/avassert.h"
 #include "error_resilience.h"
 #include "internal.h"
-#include "msmpeg4data.h"
+#include "mpeg_er.h"
+#include "msmpeg4.h"
+#include "qpeldsp.h"
 #include "vc1.h"
+#include "wmv2data.h"
 #include "mss12.h"
 #include "mss2dsp.h"
 
@@ -37,6 +40,7 @@ typedef struct MSS2Context {
     AVFrame       *last_pic;
     MSS12Context   c;
     MSS2DSPContext dsp;
+    QpelDSPContext qdsp;
     SliceContext   sc[2];
 } MSS2Context;
 
@@ -170,7 +174,7 @@ static int decode_pal_v2(MSS12Context *ctx, const uint8_t *buf, int buf_size)
     return 1 + ncol * 3;
 }
 
-static int decode_555(GetByteContext *gB, uint16_t *dst, int stride,
+static int decode_555(GetByteContext *gB, uint16_t *dst, ptrdiff_t stride,
                       int keyframe, int w, int h)
 {
     int last_symbol = 0, repeat = 0, prev_avail = 0;
@@ -228,8 +232,8 @@ static int decode_555(GetByteContext *gB, uint16_t *dst, int stride,
     return 0;
 }
 
-static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, int pal_stride,
-                      uint8_t *rgb_dst, int rgb_stride, uint32_t *pal,
+static int decode_rle(GetBitContext *gb, uint8_t *pal_dst, ptrdiff_t pal_stride,
+                      uint8_t *rgb_dst, ptrdiff_t rgb_stride, uint32_t *pal,
                       int keyframe, int kf_slipt, int slice, int w, int h)
 {
     uint8_t bits[270] = { 0 };
@@ -393,8 +397,8 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
 
     avctx->pix_fmt = AV_PIX_FMT_YUV420P;
 
-    if ((ret = ff_MPV_frame_start(s, avctx)) < 0) {
-        av_log(v->s.avctx, AV_LOG_ERROR, "ff_MPV_frame_start error\n");
+    if ((ret = ff_mpv_frame_start(s, avctx)) < 0) {
+        av_log(v->s.avctx, AV_LOG_ERROR, "ff_mpv_frame_start error\n");
         avctx->pix_fmt = AV_PIX_FMT_RGB24;
         return ret;
     }
@@ -412,9 +416,15 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
 
     ff_vc1_decode_blocks(v);
 
-    ff_er_frame_end(&s->er);
+    if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
+        ff_er_frame_end(&s->er);
+    } else {
+        av_log(v->s.avctx, AV_LOG_WARNING,
+               "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
+               v->end_mb_x, s->end_mb_y, s->mb_width, s->mb_height);
+    }
 
-    ff_MPV_frame_end(s);
+    ff_mpv_frame_end(s);
 
     f = s->current_picture.f;
 
@@ -472,9 +482,6 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
     Rectangle wmv9rects[MAX_WMV9_RECTANGLES], *r;
     int used_rects = 0, i, implicit_rect = 0, av_uninit(wmv9_mask);
 
-    av_assert0(FF_INPUT_BUFFER_PADDING_SIZE >=
-               ARITH2_PADDING + (MIN_CACHE_BITS + 7) / 8);
-
     init_get_bits(&gb, buf, buf_size * 8);
 
     if (keyframe = get_bits1(&gb))
@@ -787,8 +794,8 @@ static av_cold int wmv9_init(AVCodecContext *avctx)
         return ret;
 
     /* error concealment */
-    v->s.me.qpel_put = v->s.dsp.put_qpel_pixels_tab;
-    v->s.me.qpel_avg = v->s.dsp.avg_qpel_pixels_tab;
+    v->s.me.qpel_put = v->s.qdsp.put_qpel_pixels_tab;
+    v->s.me.qpel_avg = v->s.qdsp.avg_qpel_pixels_tab;
 
     return 0;
 }
@@ -827,6 +834,7 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx)
         return ret;
     }
     ff_mss2dsp_init(&ctx->dsp);
+    ff_qpeldsp_init(&ctx->qdsp);
 
     avctx->pix_fmt = c->free_colours == 127 ? AV_PIX_FMT_RGB555
                                             : AV_PIX_FMT_RGB24;
@@ -849,5 +857,5 @@ AVCodec ff_mss2_decoder = {
     .init           = mss2_decode_init,
     .close          = mss2_decode_end,
     .decode         = mss2_decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1,
 };