diff mbox

[FFmpeg-devel,2/2] avcodec/mpeg4videodec: Workaround interlaced mpeg4 edge MC bug

Message ID 20161112113135.20799-2-michael@niedermayer.cc
State Accepted
Headers show

Commit Message

Michael Niedermayer Nov. 12, 2016, 11:31 a.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/avcodec.h          | 1 +
 libavcodec/mpeg4videodec.c    | 5 +++++
 libavcodec/mpegvideo.c        | 2 ++
 libavcodec/mpegvideo_motion.c | 4 ++++
 libavcodec/options_table.h    | 1 +
 5 files changed, 13 insertions(+)

Comments

Carl Eugen Hoyos Nov. 12, 2016, 12:34 p.m. UTC | #1
2016-11-12 12:31 GMT+01:00 Michael Niedermayer <michael@niedermayer.cc>:

> +        if ((ctx->lavc_build&0xFF) >= 100) {

(Do we guarantee that MICRO <= 255?)

> +            if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752550)

Sorry, I meant this patch, not 1/2:
Please mention the relevant change (60ab6e24?) in the commit message.

Thank you, Carl Eugen
Moritz Barsnick Nov. 12, 2016, 12:50 p.m. UTC | #2
On Sat, Nov 12, 2016 at 13:34:02 +0100, Carl Eugen Hoyos wrote:
> > +        if ((ctx->lavc_build&0xFF) >= 100) {
> (Do we guarantee that MICRO <= 255?)

Most of the version macros in libavutil/version.h will not behave as
expected if not, as they assume 8 bits. So, yes, that's an implicit
requirement.

Moritz
Michael Niedermayer Nov. 17, 2016, 11:21 a.m. UTC | #3
On Sat, Nov 12, 2016 at 12:31:35PM +0100, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/avcodec.h          | 1 +
>  libavcodec/mpeg4videodec.c    | 5 +++++
>  libavcodec/mpegvideo.c        | 2 ++
>  libavcodec/mpegvideo_motion.c | 4 ++++
>  libavcodec/options_table.h    | 1 +
>  5 files changed, 13 insertions(+)

applied

[...]
diff mbox

Patch

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 211112f..e5e7f42 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2878,6 +2878,7 @@  typedef struct AVCodecContext {
 #define FF_BUG_DC_CLIP          4096
 #define FF_BUG_MS               8192 ///< Work around various bugs in Microsoft's broken decoders.
 #define FF_BUG_TRUNCATED       16384
+#define FF_BUG_IEDGE           32768
 
     /**
      * strictly follow the standard (MPEG-4, ...).
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 3adf28d..cdd0dd4 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2195,6 +2195,11 @@  int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
         if (ctx->lavc_build <= 4712U)
             s->workaround_bugs |= FF_BUG_DC_CLIP;
 
+        if ((ctx->lavc_build&0xFF) >= 100) {
+            if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752550)
+                s->workaround_bugs |= FF_BUG_IEDGE;
+        }
+
         if (ctx->divx_version >= 0)
             s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
         if (ctx->divx_version == 501 && ctx->divx_build == 20020416)
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 59be078..e5424cb 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -2117,6 +2117,8 @@  static av_always_inline void mpeg_motion_lowres(MpegEncContext *s,
         if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
             uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize;
             uint8_t *vbuf =ubuf + 10 * s->uvlinesize;
+            if (s->workaround_bugs & FF_BUG_IEDGE)
+                vbuf -= s->uvlinesize;
             s->vdsp.emulated_edge_mc(ubuf,  ptr_cb,
                                      uvlinesize >> field_based, uvlinesize >> field_based,
                                      9, 9 + field_based,
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index b97a6cb..a310bd4 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -327,6 +327,8 @@  void mpeg_motion_internal(MpegEncContext *s,
         if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
             uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize;
             uint8_t *vbuf = ubuf + 10 * s->uvlinesize;
+            if (s->workaround_bugs & FF_BUG_IEDGE)
+                vbuf -= s->uvlinesize;
             uvsrc_y = (unsigned)uvsrc_y << field_based;
             s->vdsp.emulated_edge_mc(ubuf, ptr_cb,
                                      s->uvlinesize, s->uvlinesize,
@@ -550,6 +552,8 @@  static inline void qpel_motion(MpegEncContext *s,
         if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
             uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize;
             uint8_t *vbuf = ubuf + 10 * s->uvlinesize;
+            if (s->workaround_bugs & FF_BUG_IEDGE)
+                vbuf -= s->uvlinesize;
             s->vdsp.emulated_edge_mc(ubuf, ptr_cb,
                                      s->uvlinesize, s->uvlinesize,
                                      9, 9 + field_based,
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4323ae9..b65acea 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -163,6 +163,7 @@  static const AVOption avcodec_options[] = {
 {"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"},
 {"ms", "work around various bugs in Microsoft's broken decoders", 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"},
 {"trunc", "truncated frames", 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"},
+{"iedge", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_BUG_IEDGE }, INT_MIN, INT_MAX, V|D, "bug"},
 {"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
 {"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},
 {"strict", "strictly conform to all the things in the spec no matter what the consequences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, A|V|D|E, "strict"},