Merge commit '48e139409556861c9e561ce34133891d8eecc3cf'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 29 Nov 2013 23:58:58 +0000 (00:58 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 30 Nov 2013 00:28:04 +0000 (01:28 +0100)
* commit '48e139409556861c9e561ce34133891d8eecc3cf':
  mpeg4videodec: move MpegEncContext.resync_marker into Mpeg4DecContext.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/mpeg4video.h
libavcodec/mpeg4videodec.c
libavcodec/mpegvideo.h
libavcodec/vaapi_mpeg4.c
libavcodec/vdpau.c
libavcodec/vdpau_internal.h
libavcodec/vdpau_mpeg4.c

diff --combined libavcodec/mpeg4video.h
@@@ -3,20 -3,20 +3,20 @@@
   * Copyright (c) 2000,2001 Fabrice Bellard
   * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -68,6 -68,8 +68,8 @@@ typedef struct Mpeg4DecContext 
      int vol_sprite_usage;
      // reversible vlc
      int rvlc;
+     ///< could this stream contain resync markers
+     int resync_marker;
  } Mpeg4DecContext;
  
  /* dc encoding for mpeg4 */
@@@ -116,7 -118,6 +118,7 @@@ int ff_mpeg4_decode_partitions(Mpeg4Dec
  int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
  int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
  void ff_mpeg4_init_direct_mv(MpegEncContext *s);
 +void ff_mpeg4videodec_static_init(void);
  
  /**
   *
@@@ -191,7 -192,7 +193,7 @@@ static inline int ff_mpeg4_pred_dc(Mpeg
      } else {
          level += pred;
          ret    = level;
 -        if (s->err_recognition & AV_EF_BITSTREAM) {
 +        if (s->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) {
              if (level < 0) {
                  av_log(s->avctx, AV_LOG_ERROR,
                         "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
@@@ -3,26 -3,23 +3,26 @@@
   * Copyright (c) 2000,2001 Fabrice Bellard
   * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
 +#define UNCHECKED_BITSTREAM_READER 1
 +
 +#include "libavutil/opt.h"
  #include "error_resilience.h"
  #include "internal.h"
  #include "mpegvideo.h"
@@@ -109,12 -106,12 +109,13 @@@ void ff_mpeg4_pred_ac(MpegEncContext *s
   * check if the next stuff is a resync marker or the end.
   * @return 0 if not
   */
--static inline int mpeg4_is_resync(MpegEncContext *s)
++static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
  {
++    MpegEncContext *s = &ctx->m;
      int bits_count = get_bits_count(&s->gb);
      int v          = show_bits(&s->gb, 16);
  
-     if (s->workaround_bugs & FF_BUG_NO_PADDING && !s->resync_marker)
 -    if (s->workaround_bugs & FF_BUG_NO_PADDING)
++    if (s->workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
          return 0;
  
      while (v <= 0xFF) {
          v  |= 0x7F >> (7 - (bits_count & 7));
  
          if (v == 0x7F)
 -            return 1;
 +            return s->mb_num;
      } else {
          if (v == ff_mpeg4_resync_prefix[bits_count & 7]) {
 -            int len;
 +            int len, mb_num;
 +            int mb_num_bits = av_log2(s->mb_num - 1) + 1;
              GetBitContext gb = s->gb;
  
              skip_bits(&s->gb, 1);
                  if (get_bits1(&s->gb))
                      break;
  
 +            mb_num = get_bits(&s->gb, mb_num_bits);
 +            if (!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits)
 +                mb_num= -1;
 +
              s->gb = gb;
  
              if (len >= ff_mpeg4_get_video_packet_prefix_length(s))
 -                return 1;
 +                return mb_num;
          }
      }
      return 0;
@@@ -372,17 -364,6 +373,17 @@@ static int mpeg4_decode_sprite_trajecto
      return 0;
  }
  
 +static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
 +    int len = FFMIN(ctx->time_increment_bits + 3, 15);
 +
 +    get_bits(gb, len);
 +    if (get_bits1(gb))
 +        get_bits(gb, len);
 +    check_marker(gb, "after new_pred");
 +
 +    return 0;
 +}
 +
  /**
   * Decode the next video packet.
   * @return <0 if something went wrong
@@@ -418,6 -399,19 +419,6 @@@ int ff_mpeg4_decode_video_packet_header
                 "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
          return -1;
      }
 -    if (s->pict_type == AV_PICTURE_TYPE_B) {
 -        int mb_x = 0, mb_y = 0;
 -
 -        while (s->next_picture.mbskip_table[s->mb_index2xy[mb_num]]) {
 -            if (!mb_x)
 -                ff_thread_await_progress(&s->next_picture_ptr->tf, mb_y++, 0);
 -            mb_num++;
 -            if (++mb_x == s->mb_width)
 -                mb_x = 0;
 -        }
 -        if (mb_num >= s->mb_num)
 -            return -1;  // slice contains just skipped MBs (already decoded)
 -    }
  
      s->mb_x = mb_num % s->mb_width;
      s->mb_y = mb_num / s->mb_width;
              }
          }
      }
 -    // FIXME new-pred stuff
 +    if (s->new_pred)
 +        decode_new_pred(ctx, &s->gb);
  
      return 0;
  }
@@@ -565,7 -558,7 +566,7 @@@ static inline int mpeg4_decode_dc(MpegE
  
          if (code > 8) {
              if (get_bits1(&s->gb) == 0) { /* marker */
 -                if (s->err_recognition & AV_EF_BITSTREAM) {
 +                if (s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
                      av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
                      return -1;
                  }
@@@ -933,8 -926,7 +934,8 @@@ int ff_mpeg4_decode_partitions(Mpeg4Dec
  static inline int mpeg4_decode_block(MpegEncContext *s, int16_t *block,
                                       int n, int coded, int intra, int rvlc)
  {
 -    int level, i, last, run, qmul, qadd, dc_pred_dir;
 +    int level, i, last, run, qmul, qadd;
 +    int av_uninit(dc_pred_dir);
      RLTable *rl;
      RL_VLC_ELEM *rl_vlc;
      const uint8_t *scan_table;
                                  SKIP_COUNTER(re, &s->gb, 1 + 12 + 1);
                              }
  
 +#if 0
 +                            if (s->error_recognition >= FF_ER_COMPLIANT) {
 +                                const int abs_level= FFABS(level);
 +                                if (abs_level<=MAX_LEVEL && run<=MAX_RUN) {
 +                                    const int run1= run - rl->max_run[last][abs_level] - 1;
 +                                    if (abs_level <= rl->max_level[last][run]) {
 +                                        av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
 +                                        return -1;
 +                                    }
 +                                    if (s->error_recognition > FF_ER_COMPLIANT) {
 +                                        if (abs_level <= rl->max_level[last][run]*2) {
 +                                            av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
 +                                            return -1;
 +                                        }
 +                                        if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
 +                                            av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
 +                                            return -1;
 +                                        }
 +                                    }
 +                                }
 +                            }
 +#endif
                              if (level > 0)
                                  level = level * qmul + qadd;
                              else
                                  level = level * qmul - qadd;
  
                              if ((unsigned)(level + 2048) > 4095) {
 -                                if (s->err_recognition & AV_EF_BITSTREAM) {
 +                                if (s->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
                                      if (level > 2560 || level < -2560) {
                                          av_log(s->avctx, AV_LOG_ERROR,
                                                 "|level| overflow in 3. esc, qp=%d\n",
@@@ -1268,12 -1238,12 +1269,12 @@@ static int mpeg4_decode_partitioned_mb(
  
      /* per-MB end of slice check */
      if (--s->mb_num_left <= 0) {
--        if (mpeg4_is_resync(s))
++        if (mpeg4_is_resync(ctx))
              return SLICE_END;
          else
              return SLICE_NOEND;
      } else {
--        if (mpeg4_is_resync(s)) {
++        if (mpeg4_is_resync(ctx)) {
              const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
              if (s->cbp_table[xy + delta])
                  return SLICE_END;
@@@ -1290,7 -1260,7 +1291,7 @@@ static int mpeg4_decode_mb(MpegEncConte
      static int8_t quant_tab[4] = { -1, -2, 1, 2 };
      const int xy = s->mb_x + s->mb_y * s->mb_stride;
  
 -    assert(s->h263_pred);
 +    av_assert2(s->h263_pred);
  
      if (s->pict_type == AV_PICTURE_TYPE_P ||
          s->pict_type == AV_PICTURE_TYPE_S) {
@@@ -1632,23 -1602,20 +1633,23 @@@ intra
  end:
      /* per-MB end of slice check */
      if (s->codec_id == AV_CODEC_ID_MPEG4) {
-         int next = mpeg4_is_resync(s);
 -        if (mpeg4_is_resync(s)) {
 -            const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
++        int 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 -1;
 +            } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
 +                return SLICE_END;
  
 -            if (s->pict_type == AV_PICTURE_TYPE_B &&
 -                s->next_picture.mbskip_table[xy + delta]) {
 +            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 (s->pict_type == AV_PICTURE_TYPE_B &&
 -                s->next_picture.mbskip_table[xy + delta])
 -                return SLICE_OK;
              return SLICE_END;
          }
      }
  static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb)
  {
      int hours, minutes, seconds;
 -    unsigned time_code = show_bits(gb, 18);
 -
 -    if (time_code & 0x40) {     /* marker_bit */
 -        hours   = time_code >> 13;
 -        minutes = time_code >> 7 & 0x3f;
 -        seconds = time_code & 0x3f;
 -        s->time_base = seconds + 60 * (minutes + 60 * hours);
 -        skip_bits(gb, 20);      /* time_code, closed_gov, broken_link */
 -    } else {
 -        av_log(s->avctx, AV_LOG_WARNING, "GOP header missing marker_bit\n");
 +
 +    if (!show_bits(gb, 23)) {
 +        av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n");
 +        return -1;
      }
  
 +    hours   = get_bits(gb, 5);
 +    minutes = get_bits(gb, 6);
 +    skip_bits1(gb);
 +    seconds = get_bits(gb, 6);
 +
 +    s->time_base = seconds + 60*(minutes + 60*hours);
 +
 +    skip_bits1(gb);
 +    skip_bits1(gb);
 +
      return 0;
  }
  
  static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
  {
 -    int profile_and_level_indication;
  
 -    profile_and_level_indication = get_bits(gb, 8);
 -
 -    s->avctx->profile = (profile_and_level_indication & 0xf0) >> 4;
 -    s->avctx->level   = (profile_and_level_indication & 0x0f);
 +    s->avctx->profile = get_bits(gb, 4);
 +    s->avctx->level   = get_bits(gb, 4);
  
      // for Simple profile, level 0
      if (s->avctx->profile == 0 && s->avctx->level == 8) {
@@@ -1772,11 -1738,11 +1773,11 @@@ static int decode_vol_header(Mpeg4DecCo
  
      if (ctx->shape != BIN_ONLY_SHAPE) {
          if (ctx->shape == RECT_SHAPE) {
 -            skip_bits1(gb);   /* marker */
 +            check_marker(gb, "before width");
              width = get_bits(gb, 13);
 -            skip_bits1(gb);   /* marker */
 +            check_marker(gb, "before height");
              height = get_bits(gb, 13);
 -            skip_bits1(gb);   /* marker */
 +            check_marker(gb, "after height");
              if (width && height &&  /* they should be non zero but who knows */
                  !(s->width && s->codec_tag == AV_RL32("MP4S"))) {
                  if (s->width && s->height &&
              if (s->quant_precision != 5)
                  av_log(s->avctx, AV_LOG_ERROR,
                         "quant precision %d\n", s->quant_precision);
 +            if (s->quant_precision<3 || s->quant_precision>9) {
 +                s->quant_precision = 5;
 +            }
          } else {
              s->quant_precision = 5;
          }
@@@ -1968,7 -1931,7 +1969,7 @@@ no_cplx_est
              s->cplx_estimation_trash_b = 0;
          }
  
-         s->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
+         ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
  
          s->data_partitioning = get_bits1(gb);
          if (s->data_partitioning)
          }
      }
  
 +    if (s->avctx->debug&FF_DEBUG_PICT_INFO) {
 +        av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d,  %s%s%s%s\n",
 +               s->avctx->time_base.num, s->avctx->time_base.den,
 +               ctx->time_increment_bits,
 +               s->quant_precision,
 +               s->progressive_sequence,
 +               s->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "",
 +               s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : ""
 +        );
 +    }
 +
      return 0;
  }
  
@@@ -2063,9 -2015,8 +2064,9 @@@ static int decode_user_data(MpegEncCont
          s->divx_build   = build;
          s->divx_packed  = e == 3 && last == 'p';
          if (s->divx_packed && !s->showed_packed_warning) {
 -            av_log(s->avctx, AV_LOG_WARNING,
 -                   "Invalid and inefficient vfw-avi packed B frames detected\n");
 +            av_log(s->avctx, AV_LOG_INFO, "Video uses a non-standard and "
 +                   "wasteful way to store B-frames ('packed B-frames'). "
 +                   "Consider using a tool like VirtualDub or avidemux to fix it.\n");
              s->showed_packed_warning = 1;
          }
      }
@@@ -2098,7 -2049,6 +2099,7 @@@ static int decode_vop_header(Mpeg4DecCo
  {
      MpegEncContext *s = &ctx->m;
      int time_incr, time_increment;
 +    int64_t pts;
  
      s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I;        /* pict type: I = 0 , P = 1 */
      if (s->pict_type == AV_PICTURE_TYPE_B && s->low_delay &&
  
          av_log(s->avctx, AV_LOG_ERROR,
                 "my guess is %d bits ;)\n", ctx->time_increment_bits);
 +        if (s->avctx->time_base.den && 4*s->avctx->time_base.den < 1<<ctx->time_increment_bits) {
 +            s->avctx->time_base.den = 1<<ctx->time_increment_bits;
 +        }
      }
  
      if (IS_3IV1)
          }
      }
  
 +    if (s->avctx->time_base.num)
 +        pts = ROUNDED_DIV(s->time, s->avctx->time_base.num);
 +    else
 +        pts = AV_NOPTS_VALUE;
 +    if (s->avctx->debug&FF_DEBUG_PTS)
 +        av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n",
 +               pts);
 +
      check_marker(gb, "before vop_coded");
  
      /* vop coded */
              av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
          return FRAME_SKIPPED;
      }
 +    if (s->new_pred)
 +        decode_new_pred(ctx, gb);
 +
      if (ctx->shape != BIN_ONLY_SHAPE &&
                      (s->pict_type == AV_PICTURE_TYPE_P ||
                       (s->pict_type == AV_PICTURE_TYPE_S &&
          if (s->pict_type == AV_PICTURE_TYPE_B)
              skip_bits_long(gb, s->cplx_estimation_trash_b);
  
 +        if (get_bits_left(gb) < 3) {
 +            av_log(s->avctx, AV_LOG_ERROR, "Header truncated\n");
 +            return -1;
 +        }
          s->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)];
          if (!s->progressive_sequence) {
              s->top_field_first = get_bits1(gb);
              if (s->f_code == 0) {
                  av_log(s->avctx, AV_LOG_ERROR,
                         "Error, header damaged or not MPEG4 header (f_code=0)\n");
 +                s->f_code = 1;
                  return -1;  // makes no sense to continue, as there is nothing left from the image then
              }
          } else
  
          if (s->pict_type == AV_PICTURE_TYPE_B) {
              s->b_code = get_bits(gb, 3);
 +            if (s->b_code == 0) {
 +                av_log(s->avctx, AV_LOG_ERROR,
 +                       "Error, header damaged or not MPEG4 header (b_code=0)\n");
 +                s->b_code=1;
 +                return -1; // makes no sense to continue, as the MV decoding will break very quickly
 +            }
          } else
              s->b_code = 1;
  
          if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
              av_log(s->avctx, AV_LOG_DEBUG,
 -                   "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n",
 +                   "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n",
                     s->qscale, s->f_code, s->b_code,
                     s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
 -                   gb->size_in_bits, s->progressive_sequence, s->alternate_scan,
 +                   gb->size_in_bits,s->progressive_sequence, s->alternate_scan,
                     s->top_field_first, s->quarter_sample ? "q" : "h",
-                    s->data_partitioning, s->resync_marker,
+                    s->data_partitioning, ctx->resync_marker,
                     s->num_sprite_warping_points, s->sprite_warping_accuracy,
                     1 - s->no_rounding, s->vo_type,
                     s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold,
                     s->cplx_estimation_trash_i, s->cplx_estimation_trash_p,
 -                   s->cplx_estimation_trash_b);
 +                   s->cplx_estimation_trash_b,
 +                   s->time,
 +                   time_increment
 +                  );
          }
  
          if (!s->scalability) {
@@@ -2386,8 -2308,8 +2387,8 @@@ int ff_mpeg4_decode_picture_header(Mpeg
      for (;;) {
          if (get_bits_count(gb) >= gb->size_in_bits) {
              if (gb->size_in_bits == 8 &&
 -                (s->divx_version >= 0 || s->xvid_build >= 0)) {
 -                av_log(s->avctx, AV_LOG_WARNING, "frame skip %d\n", gb->size_in_bits);
 +                (s->divx_version >= 0 || s->xvid_build >= 0) || s->codec_tag == AV_RL32("QMP4")) {
 +                av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits);
                  return FRAME_SKIPPED;  // divx bug
              } else
                  return -1;  // end of stream
      return decode_vop_header(ctx, gb);
  }
  
 +av_cold void ff_mpeg4videodec_static_init(void) {
 +    static int done = 0;
 +
 +    if (!done) {
 +        ff_init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
 +        ff_init_rl(&ff_rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]);
 +        ff_init_rl(&ff_rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]);
 +        INIT_VLC_RL(ff_mpeg4_rl_intra, 554);
 +        INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
 +        INIT_VLC_RL(ff_rvlc_rl_intra, 1072);
 +        INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
 +                        &ff_mpeg4_DCtab_lum[0][1], 2, 1,
 +                        &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
 +        INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
 +                        &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
 +                        &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
 +        INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
 +                        &ff_sprite_trajectory_tab[0][1], 4, 2,
 +                        &ff_sprite_trajectory_tab[0][0], 4, 2, 128);
 +        INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
 +                        &ff_mb_type_b_tab[0][1], 2, 1,
 +                        &ff_mb_type_b_tab[0][0], 2, 1, 16);
 +        done = 1;
 +    }
 +}
 +
  static int mpeg4_update_thread_context(AVCodecContext *dst,
                                         const AVCodecContext *src)
  {
  
      s->shape               = s1->shape;
      s->time_increment_bits = s1->time_increment_bits;
 +    s->vol_sprite_usage    = s1->vol_sprite_usage;
 +    s->rvlc                = s1->rvlc;
  
      return 0;
  }
@@@ -2534,6 -2428,7 +2535,6 @@@ static av_cold int decode_init(AVCodecC
      Mpeg4DecContext *ctx = avctx->priv_data;
      MpegEncContext *s = &ctx->m;
      int ret;
 -    static int done = 0;
  
      s->divx_version =
      s->divx_build   =
      if ((ret = ff_h263_decode_init(avctx)) < 0)
          return ret;
  
 -    if (!done) {
 -        done = 1;
 -
 -        ff_init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
 -        ff_init_rl(&ff_rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]);
 -        ff_init_rl(&ff_rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]);
 -        INIT_VLC_RL(ff_mpeg4_rl_intra, 554);
 -        INIT_VLC_RL(ff_rvlc_rl_inter, 1072);
 -        INIT_VLC_RL(ff_rvlc_rl_intra, 1072);
 -        INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */,
 -                        &ff_mpeg4_DCtab_lum[0][1], 2, 1,
 -                        &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
 -        INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */,
 -                        &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
 -                        &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
 -        INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
 -                        &ff_sprite_trajectory_tab[0][1], 4, 2,
 -                        &ff_sprite_trajectory_tab[0][0], 4, 2, 128);
 -        INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
 -                        &ff_mb_type_b_tab[0][1], 2, 1,
 -                        &ff_mb_type_b_tab[0][0], 2, 1, 16);
 -    }
 +    ff_mpeg4videodec_static_init();
  
      s->h263_pred = 1;
 -    s->low_delay = 0; /* default, might be overriden in the vol header during header parsing */
 +    s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
      s->decode_mb = mpeg4_decode_mb;
      ctx->time_increment_bits = 4; /* default value for broken headers */
  
@@@ -2573,27 -2489,6 +2574,27 @@@ static const AVProfile mpeg4_video_prof
      { FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE, "Advanced Scalable Texture Profile" },
      { FF_PROFILE_MPEG4_SIMPLE_STUDIO,             "Simple Studio Profile" },
      { FF_PROFILE_MPEG4_ADVANCED_SIMPLE,           "Advanced Simple Profile" },
 +    { FF_PROFILE_UNKNOWN },
 +};
 +
 +static const AVOption mpeg4_options[] = {
 +    {"quarter_sample", "1/4 subpel MC", offsetof(MpegEncContext, quarter_sample), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, 0},
 +    {"divx_packed", "divx style packed b frames", offsetof(MpegEncContext, divx_packed), FF_OPT_TYPE_INT, {.i64 = 0}, 0, 1, 0},
 +    {NULL}
 +};
 +
 +static const AVClass mpeg4_class = {
 +    "MPEG4 Video Decoder",
 +    av_default_item_name,
 +    mpeg4_options,
 +    LIBAVUTIL_VERSION_INT,
 +};
 +
 +static const AVClass mpeg4_vdpau_class = {
 +    "MPEG4 Video VDPAU Decoder",
 +    av_default_item_name,
 +    mpeg4_options,
 +    LIBAVUTIL_VERSION_INT,
  };
  
  AVCodec ff_mpeg4_decoder = {
                               CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
                               CODEC_CAP_FRAME_THREADS,
      .flush                 = ff_mpeg_flush,
 +    .max_lowres            = 3,
      .pix_fmts              = ff_h263_hwaccel_pixfmt_list_420,
      .profiles              = NULL_IF_CONFIG_SMALL(mpeg4_video_profiles),
      .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg4_update_thread_context),
 +    .priv_class = &mpeg4_class,
 +};
 +
 +
 +#if CONFIG_MPEG4_VDPAU_DECODER
 +AVCodec ff_mpeg4_vdpau_decoder = {
 +    .name           = "mpeg4_vdpau",
 +    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"),
 +    .type           = AVMEDIA_TYPE_VIDEO,
 +    .id             = AV_CODEC_ID_MPEG4,
 +    .priv_data_size = sizeof(MpegEncContext),
 +    .init           = decode_init,
 +    .close          = ff_h263_decode_end,
 +    .decode         = ff_h263_decode_frame,
 +    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
 +                      CODEC_CAP_HWACCEL_VDPAU,
 +    .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_VDPAU_MPEG4,
 +                                                  AV_PIX_FMT_NONE },
 +    .priv_class     = &mpeg4_vdpau_class,
  };
 +#endif
diff --combined libavcodec/mpegvideo.h
@@@ -3,20 -3,20 +3,20 @@@
   * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
   * Copyright (c) 2002-2004 Michael Niedermayer
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -32,7 -32,6 +32,7 @@@
  #include "dsputil.h"
  #include "error_resilience.h"
  #include "get_bits.h"
 +#include "h264chroma.h"
  #include "h263dsp.h"
  #include "hpeldsp.h"
  #include "put_bits.h"
@@@ -44,7 -43,6 +44,7 @@@
  #include "videodsp.h"
  
  #include "libavutil/opt.h"
 +#include "libavutil/timecode.h"
  
  #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded
  
@@@ -58,13 -56,14 +58,13 @@@ enum OutputFormat 
  #define MPEG_BUF_SIZE (16 * 1024)
  
  #define QMAT_SHIFT_MMX 16
 -#define QMAT_SHIFT 22
 +#define QMAT_SHIFT 21
  
  #define MAX_FCODE 7
 -#define MAX_MV 2048
 +#define MAX_MV 4096
  
 -#define MAX_THREADS 16
 -
 -#define MAX_PICTURE_COUNT 32
 +#define MAX_THREADS 32
 +#define MAX_PICTURE_COUNT 36
  
  #define MAX_B_FRAMES 16
  
@@@ -146,9 -145,6 +146,9 @@@ typedef struct Picture
      AVBufferRef *mc_mb_var_buf;
      uint16_t *mc_mb_var;        ///< Table for motion compensated MB variances
  
 +    int alloc_mb_width;         ///< mb_width used to allocate tables
 +    int alloc_mb_height;        ///< mb_height used to allocate tables
 +
      AVBufferRef *mb_mean_buf;
      uint8_t *mb_mean;           ///< Table for MB luminance
  
      int pic_id;                 /**< h264 pic_num (short -> no wrap version of pic_num,
                                       pic_num & max_pic_num; long -> long_pic_num) */
      int long_ref;               ///< 1->long term reference 0->short term reference
 -    int ref_poc[2][2][32];      ///< h264 POCs of the frames used as reference (FIXME need per slice)
 +    int ref_poc[2][2][32];      ///< h264 POCs of the frames/fields used as reference (FIXME need per slice)
      int ref_count[2][2];        ///< number of entries in ref_poc              (FIXME need per slice)
      int mbaff;                  ///< h264 1 -> MBAFF frame 0-> not MBAFF
      int field_picture;          ///< whether or not the picture was encoded in separate fields
      int mb_var_sum;             ///< sum of MB variance for current frame
      int mc_mb_var_sum;          ///< motion compensated MB variance for current frame
  
 -    int b_frame_score;          /* */
 +    int b_frame_score;
      int needs_realloc;          ///< Picture needs to be reallocated (eg due to a frame size change)
  
      int reference;
      int shared;
      int recovered;              ///< Picture at IDR or recovery point + recovery count
 +
 +    int crop;
 +    int crop_left;
 +    int crop_top;
  } Picture;
  
  /**
@@@ -385,7 -377,7 +385,7 @@@ typedef struct MpegEncContext 
      uint8_t *coded_block_base;
      uint8_t *coded_block;          ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
      int16_t (*ac_val_base)[16];
 -    int16_t (*ac_val[3])[16];      ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous
 +    int16_t (*ac_val[3])[16];      ///< used for mpeg4 AC prediction, all 3 arrays must be continuous
      int mb_skipped;                ///< MUST BE SET only during DECODING
      uint8_t *mbskip_table;        /**< used to avoid copy if macroblock skipped (for black regions for example)
                                     and used for b-frame encoding & decoding (contains skip table of next P Frame) */
      int *lambda_table;
      int adaptive_quant;         ///< use adaptive quantization
      int dquant;                 ///< qscale difference to prev qscale
 +    int closed_gop;             ///< MPEG1/2 GOP is closed
      int pict_type;              ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
 +    int vbv_delay;
      int last_pict_type; //FIXME removes
      int last_non_b_pict_type;   ///< used for mpeg4 gmc b-frames & ratecontrol
      int droppable;
      int frame_rate_index;
 +    AVRational mpeg2_frame_rate_ext;
      int last_lambda_for[5];     ///< last lambda for a specific pict type
      int skipdct;                ///< skip dct and code zero residual
  
      int h263_long_vectors;      ///< use horrible h263v1 long vector mode
  
      DSPContext dsp;             ///< pointers for accelerated dsp functions
 +    H264ChromaContext h264chroma;
      HpelDSPContext hdsp;
      VideoDSPContext vdsp;
      H263DSPContext h263dsp;
      uint8_t *luma_dc_vlc_length;
  #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level))
  
 -    int coded_score[8];
 +    int coded_score[12];
  
      /** precomputed matrix (combine qscale and DCT renorm) */
      int (*q_intra_matrix)[64];
 +    int (*q_chroma_intra_matrix)[64];
      int (*q_inter_matrix)[64];
      /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/
      uint16_t (*q_intra_matrix16)[2][64];
 +    uint16_t (*q_chroma_intra_matrix16)[2][64];
      uint16_t (*q_inter_matrix16)[2][64];
  
      /* noise reduction */
      /* bit rate control */
      int64_t total_bits;
      int frame_bits;                ///< bits used for the current frame
 +    int stuffing_bits;             ///< bits used for stuffing
      int next_lambda;               ///< next lambda used for retrying to encode a frame
      RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
  
      int prev_mb_info, last_mb_info;
      uint8_t *mb_info_ptr;
      int mb_info_size;
 +    int ehc_mode;
  
      /* H.263+ specific */
      int umvplus;                    ///< == H263+ && unrestricted_mv
      int low_latency_sprite;
      int data_partitioning;           ///< data partitioning flag from header
      int partitioned_frame;           ///< is current frame partitioned
-     int resync_marker;               ///< could this stream contain resync markers
      int low_delay;                   ///< no reordering needed / has no b-frames
      int vo_type;
      int vol_control_parameters;      ///< does the stream contain the low_delay flag, used to workaround buggy encoders
      struct MJpegContext *mjpeg_ctx;
      int mjpeg_vsample[3];       ///< vertical sampling factors, default = {2, 1, 1}
      int mjpeg_hsample[3];       ///< horizontal sampling factors, default = {2, 1, 1}
 +    int esc_pos;
  
      /* MSMPEG4 specific */
      int mv_table_index;
      /* RTP specific */
      int rtp_mode;
  
 +    char *tc_opt_str;        ///< timecode option string
 +    AVTimecode tc;           ///< timecode context
 +
      uint8_t *ptr_lastgob;
 +    int swap_uv;             //vcr2 codec is an MPEG-2 variant with U and V swapped
      int16_t (*pblocks[12])[64];
  
      int16_t (*block)[64]; ///< points to one of the following blocks
 -    int16_t (*blocks)[8][64]; // for HQ mode we need to keep the best block
 +    int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
      int (*decode_mb)(struct MpegEncContext *s, int16_t block[6][64]); // used by some codecs to avoid a switch()
  #define SLICE_OK         0
  #define SLICE_ERROR     -1
@@@ -829,10 -807,9 +828,10 @@@ void ff_MPV_frame_end(MpegEncContext *s
  int ff_MPV_encode_init(AVCodecContext *avctx);
  int ff_MPV_encode_end(AVCodecContext *avctx);
  int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
 -                          const AVFrame *frame, int *got_packet);
 -void ff_MPV_encode_init_x86(MpegEncContext *s);
 +                          AVFrame *frame, int *got_packet);
 +void ff_dct_encode_init_x86(MpegEncContext *s);
  void ff_MPV_common_init_x86(MpegEncContext *s);
 +void ff_MPV_common_init_axp(MpegEncContext *s);
  void ff_MPV_common_init_arm(MpegEncContext *s);
  void ff_MPV_common_init_bfin(MpegEncContext *s);
  void ff_MPV_common_init_ppc(MpegEncContext *s);
@@@ -843,14 -820,7 +842,14 @@@ void ff_draw_horiz_band(AVCodecContext 
                          int v_edge_pos, int h_edge_pos);
  void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h);
  void ff_mpeg_flush(AVCodecContext *avctx);
 -void ff_print_debug_info(MpegEncContext *s, Picture *p);
 +
 +void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict);
 +void ff_print_debug_info2(AVCodecContext *avctx, Picture *p, AVFrame *pict, uint8_t *mbskip_table,
 +                         int *low_delay,
 +                         int mb_width, int mb_height, int mb_stride, int quarter_sample);
 +
 +int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type);
 +
  void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
  void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
  int ff_find_unused_picture(MpegEncContext *s, int shared);
@@@ -864,7 -834,6 +863,7 @@@ void ff_set_qscale(MpegEncContext * s, 
  void ff_mpeg_er_frame_start(MpegEncContext *s);
  
  int ff_dct_common_init(MpegEncContext *s);
 +int ff_dct_encode_init(MpegEncContext *s);
  void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64],
                         const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra);
  int ff_dct_quantize_c(MpegEncContext *s, int16_t *block, int n, int qscale, int *overflow);
@@@ -893,7 -862,7 +892,7 @@@ extern const enum AVPixelFormat ff_pixf
  void ff_block_permute(int16_t *block, uint8_t *permutation, const uint8_t *scantable, int last);
  
  static inline void ff_update_block_index(MpegEncContext *s){
 -    const int block_size = 8;
 +    const int block_size= 8 >> s->avctx->lowres;
  
      s->block_index[0]+=2;
      s->block_index[1]+=2;
@@@ -985,5 -954,4 +984,5 @@@ void ff_wmv2_encode_mb(MpegEncContext 
  int ff_mpeg_ref_picture(MpegEncContext *s, Picture *dst, Picture *src);
  void ff_mpeg_unref_picture(MpegEncContext *s, Picture *picture);
  
 +
  #endif /* AVCODEC_MPEGVIDEO_H */
diff --combined libavcodec/vaapi_mpeg4.c
@@@ -3,20 -3,20 +3,20 @@@
   *
   * Copyright (C) 2008-2009 Splitted-Desktop Systems
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
@@@ -72,7 -72,7 +72,7 @@@ static int vaapi_mpeg4_start_frame(AVCo
      pic_param->vol_fields.bits.quarter_sample           = s->quarter_sample;
      pic_param->vol_fields.bits.data_partitioned         = s->data_partitioning;
      pic_param->vol_fields.bits.reversible_vlc           = ctx->rvlc;
-     pic_param->vol_fields.bits.resync_marker_disable    = !s->resync_marker;
+     pic_param->vol_fields.bits.resync_marker_disable    = !ctx->resync_marker;
      pic_param->no_of_sprite_warping_points              = s->num_sprite_warping_points;
      for (i = 0; i < s->num_sprite_warping_points && i < 3; i++) {
          pic_param->sprite_trajectory_du[i]              = s->sprite_traj[i][0];
@@@ -124,14 -124,25 +124,14 @@@ static int vaapi_mpeg4_decode_slice(AVC
  
      av_dlog(avctx, "vaapi_mpeg4_decode_slice(): buffer %p, size %d\n", buffer, size);
  
 -    /* video_plane_with_short_video_header() contains all GOBs
 -     * in-order, and this is what VA API (Intel backend) expects: only
 -     * a single slice param. So fake macroblock_number for Libav so
 -     * that we don't call vaapi_mpeg4_decode_slice() again
 -     */
 -    if (avctx->codec->id == AV_CODEC_ID_H263)
 -        size = s->gb.buffer_end - buffer;
 -
      /* Fill in VASliceParameterBufferMPEG4 */
      slice_param = (VASliceParameterBufferMPEG4 *)ff_vaapi_alloc_slice(avctx->hwaccel_context, buffer, size);
      if (!slice_param)
          return -1;
      slice_param->macroblock_offset      = get_bits_count(&s->gb) % 8;
 -    slice_param->macroblock_number      = s->mb_y * s->mb_width + s->mb_x;
 +    slice_param->macroblock_number      = 0;
      slice_param->quant_scale            = s->qscale;
  
 -    if (avctx->codec->id == AV_CODEC_ID_H263)
 -        s->mb_y = s->mb_height;
 -
      return 0;
  }
  
diff --combined libavcodec/vdpau.c
@@@ -4,20 -4,20 +4,20 @@@
   *
   * Copyright (c) 2008 NVIDIA
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
   * @{
   */
  
 +AVVDPAUContext *av_alloc_vdpaucontext(void)
 +{
 +    return av_vdpau_alloc_context();
 +}
 +
 +MAKE_ACCESSORS(AVVDPAUContext, vdpau_hwaccel, AVVDPAU_Render2, render2)
 +
  int ff_vdpau_common_start_frame(Picture *pic,
                                  av_unused const uint8_t *buffer,
                                  av_unused uint32_t size)
      CONFIG_VC1_VDPAU_HWACCEL   || CONFIG_WMV3_VDPAU_HWACCEL
  int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
  {
 +    int res = 0;
      AVVDPAUContext *hwctx = avctx->hwaccel_context;
      MpegEncContext *s = avctx->priv_data;
      Picture *pic = s->current_picture_ptr;
      struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
      VdpVideoSurface surf = ff_vdpau_get_surface_id(pic);
  
 +    if (!hwctx->render) {
 +        res = hwctx->render2(avctx, &pic->f, (void *)&pic_ctx->info,
 +                             pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
 +    } else
      hwctx->render(hwctx->decoder, surf, (void *)&pic_ctx->info,
                    pic_ctx->bitstream_buffers_used, pic_ctx->bitstream_buffers);
  
      ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
      av_freep(&pic_ctx->bitstream_buffers);
  
 -    return 0;
 +    return res;
  }
  #endif
  
@@@ -102,342 -90,6 +102,343 @@@ int ff_vdpau_add_buffer(Picture *pic, c
      return 0;
  }
  
-     render->info.vc1.syncmarker         = v->s.resync_marker;
 +/* Obsolete non-hwaccel VDPAU support below... */
 +
 +void ff_vdpau_h264_set_reference_frames(H264Context *h)
 +{
 +    struct vdpau_render_state *render, *render_ref;
 +    VdpReferenceFrameH264 *rf, *rf2;
 +    Picture *pic;
 +    int i, list, pic_frame_idx;
 +
 +    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
 +    assert(render);
 +
 +    rf = &render->info.h264.referenceFrames[0];
 +#define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames)
 +
 +    for (list = 0; list < 2; ++list) {
 +        Picture **lp = list ? h->long_ref : h->short_ref;
 +        int ls = list ? 16 : h->short_ref_count;
 +
 +        for (i = 0; i < ls; ++i) {
 +            pic = lp[i];
 +            if (!pic || !pic->reference)
 +                continue;
 +            pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num;
 +
 +            render_ref = (struct vdpau_render_state *)pic->f.data[0];
 +            assert(render_ref);
 +
 +            rf2 = &render->info.h264.referenceFrames[0];
 +            while (rf2 != rf) {
 +                if (
 +                    (rf2->surface == render_ref->surface)
 +                    && (rf2->is_long_term == pic->long_ref)
 +                    && (rf2->frame_idx == pic_frame_idx)
 +                )
 +                    break;
 +                ++rf2;
 +            }
 +            if (rf2 != rf) {
 +                rf2->top_is_reference    |= (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
 +                rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
 +                continue;
 +            }
 +
 +            if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT])
 +                continue;
 +
 +            rf->surface             = render_ref->surface;
 +            rf->is_long_term        = pic->long_ref;
 +            rf->top_is_reference    = (pic->reference & PICT_TOP_FIELD)    ? VDP_TRUE : VDP_FALSE;
 +            rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE;
 +            rf->field_order_cnt[0]  = pic->field_poc[0];
 +            rf->field_order_cnt[1]  = pic->field_poc[1];
 +            rf->frame_idx           = pic_frame_idx;
 +
 +            ++rf;
 +        }
 +    }
 +
 +    for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
 +        rf->surface             = VDP_INVALID_HANDLE;
 +        rf->is_long_term        = 0;
 +        rf->top_is_reference    = 0;
 +        rf->bottom_is_reference = 0;
 +        rf->field_order_cnt[0]  = 0;
 +        rf->field_order_cnt[1]  = 0;
 +        rf->frame_idx           = 0;
 +    }
 +}
 +
 +void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf, int buf_size)
 +{
 +    struct vdpau_render_state *render = (struct vdpau_render_state*)data;
 +    assert(render);
 +
 +    render->bitstream_buffers= av_fast_realloc(
 +        render->bitstream_buffers,
 +        &render->bitstream_buffers_allocated,
 +        sizeof(*render->bitstream_buffers)*(render->bitstream_buffers_used + 1)
 +    );
 +
 +    render->bitstream_buffers[render->bitstream_buffers_used].struct_version  = VDP_BITSTREAM_BUFFER_VERSION;
 +    render->bitstream_buffers[render->bitstream_buffers_used].bitstream       = buf;
 +    render->bitstream_buffers[render->bitstream_buffers_used].bitstream_bytes = buf_size;
 +    render->bitstream_buffers_used++;
 +}
 +
 +#if CONFIG_H264_VDPAU_DECODER
 +void ff_vdpau_h264_picture_start(H264Context *h)
 +{
 +    struct vdpau_render_state *render;
 +    int i;
 +
 +    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
 +    assert(render);
 +
 +    for (i = 0; i < 2; ++i) {
 +        int foc = h->cur_pic_ptr->field_poc[i];
 +        if (foc == INT_MAX)
 +            foc = 0;
 +        render->info.h264.field_order_cnt[i] = foc;
 +    }
 +
 +    render->info.h264.frame_num = h->frame_num;
 +}
 +
 +void ff_vdpau_h264_picture_complete(H264Context *h)
 +{
 +    struct vdpau_render_state *render;
 +
 +    render = (struct vdpau_render_state *)h->cur_pic_ptr->f.data[0];
 +    assert(render);
 +
 +    render->info.h264.slice_count = h->slice_num;
 +    if (render->info.h264.slice_count < 1)
 +        return;
 +
 +    render->info.h264.is_reference                           = (h->cur_pic_ptr->reference & 3) ? VDP_TRUE : VDP_FALSE;
 +    render->info.h264.field_pic_flag                         = h->picture_structure != PICT_FRAME;
 +    render->info.h264.bottom_field_flag                      = h->picture_structure == PICT_BOTTOM_FIELD;
 +    render->info.h264.num_ref_frames                         = h->sps.ref_frame_count;
 +    render->info.h264.mb_adaptive_frame_field_flag           = h->sps.mb_aff && !render->info.h264.field_pic_flag;
 +    render->info.h264.constrained_intra_pred_flag            = h->pps.constrained_intra_pred;
 +    render->info.h264.weighted_pred_flag                     = h->pps.weighted_pred;
 +    render->info.h264.weighted_bipred_idc                    = h->pps.weighted_bipred_idc;
 +    render->info.h264.frame_mbs_only_flag                    = h->sps.frame_mbs_only_flag;
 +    render->info.h264.transform_8x8_mode_flag                = h->pps.transform_8x8_mode;
 +    render->info.h264.chroma_qp_index_offset                 = h->pps.chroma_qp_index_offset[0];
 +    render->info.h264.second_chroma_qp_index_offset          = h->pps.chroma_qp_index_offset[1];
 +    render->info.h264.pic_init_qp_minus26                    = h->pps.init_qp - 26;
 +    render->info.h264.num_ref_idx_l0_active_minus1           = h->pps.ref_count[0] - 1;
 +    render->info.h264.num_ref_idx_l1_active_minus1           = h->pps.ref_count[1] - 1;
 +    render->info.h264.log2_max_frame_num_minus4              = h->sps.log2_max_frame_num - 4;
 +    render->info.h264.pic_order_cnt_type                     = h->sps.poc_type;
 +    render->info.h264.log2_max_pic_order_cnt_lsb_minus4      = h->sps.poc_type ? 0 : h->sps.log2_max_poc_lsb - 4;
 +    render->info.h264.delta_pic_order_always_zero_flag       = h->sps.delta_pic_order_always_zero_flag;
 +    render->info.h264.direct_8x8_inference_flag              = h->sps.direct_8x8_inference_flag;
 +    render->info.h264.entropy_coding_mode_flag               = h->pps.cabac;
 +    render->info.h264.pic_order_present_flag                 = h->pps.pic_order_present;
 +    render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present;
 +    render->info.h264.redundant_pic_cnt_present_flag         = h->pps.redundant_pic_cnt_present;
 +    memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4));
 +    memcpy(render->info.h264.scaling_lists_8x8[0], h->pps.scaling_matrix8[0], sizeof(render->info.h264.scaling_lists_8x8[0]));
 +    memcpy(render->info.h264.scaling_lists_8x8[1], h->pps.scaling_matrix8[3], sizeof(render->info.h264.scaling_lists_8x8[0]));
 +
 +    ff_h264_draw_horiz_band(h, 0, h->avctx->height);
 +    render->bitstream_buffers_used = 0;
 +}
 +#endif /* CONFIG_H264_VDPAU_DECODER */
 +
 +#if CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER
 +void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
 +                                    int buf_size, int slice_count)
 +{
 +    struct vdpau_render_state *render, *last, *next;
 +    int i;
 +
 +    if (!s->current_picture_ptr) return;
 +
 +    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
 +    assert(render);
 +
 +    /* fill VdpPictureInfoMPEG1Or2 struct */
 +    render->info.mpeg.picture_structure          = s->picture_structure;
 +    render->info.mpeg.picture_coding_type        = s->pict_type;
 +    render->info.mpeg.intra_dc_precision         = s->intra_dc_precision;
 +    render->info.mpeg.frame_pred_frame_dct       = s->frame_pred_frame_dct;
 +    render->info.mpeg.concealment_motion_vectors = s->concealment_motion_vectors;
 +    render->info.mpeg.intra_vlc_format           = s->intra_vlc_format;
 +    render->info.mpeg.alternate_scan             = s->alternate_scan;
 +    render->info.mpeg.q_scale_type               = s->q_scale_type;
 +    render->info.mpeg.top_field_first            = s->top_field_first;
 +    render->info.mpeg.full_pel_forward_vector    = s->full_pel[0]; // MPEG-1 only.  Set 0 for MPEG-2
 +    render->info.mpeg.full_pel_backward_vector   = s->full_pel[1]; // MPEG-1 only.  Set 0 for MPEG-2
 +    render->info.mpeg.f_code[0][0]               = s->mpeg_f_code[0][0]; // For MPEG-1 fill both horiz. & vert.
 +    render->info.mpeg.f_code[0][1]               = s->mpeg_f_code[0][1];
 +    render->info.mpeg.f_code[1][0]               = s->mpeg_f_code[1][0];
 +    render->info.mpeg.f_code[1][1]               = s->mpeg_f_code[1][1];
 +    for (i = 0; i < 64; ++i) {
 +        render->info.mpeg.intra_quantizer_matrix[i]     = s->intra_matrix[i];
 +        render->info.mpeg.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
 +    }
 +
 +    render->info.mpeg.forward_reference          = VDP_INVALID_HANDLE;
 +    render->info.mpeg.backward_reference         = VDP_INVALID_HANDLE;
 +
 +    switch(s->pict_type){
 +    case  AV_PICTURE_TYPE_B:
 +        next = (struct vdpau_render_state *)s->next_picture.f.data[0];
 +        assert(next);
 +        render->info.mpeg.backward_reference     = next->surface;
 +        // no return here, going to set forward prediction
 +    case  AV_PICTURE_TYPE_P:
 +        last = (struct vdpau_render_state *)s->last_picture.f.data[0];
 +        if (!last) // FIXME: Does this test make sense?
 +            last = render; // predict second field from the first
 +        render->info.mpeg.forward_reference      = last->surface;
 +    }
 +
 +    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 +
 +    render->info.mpeg.slice_count                = slice_count;
 +
 +    if (slice_count)
 +        ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
 +    render->bitstream_buffers_used               = 0;
 +}
 +#endif /* CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER */
 +
 +#if CONFIG_VC1_VDPAU_DECODER
 +void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
 +                                 int buf_size)
 +{
 +    VC1Context *v = s->avctx->priv_data;
 +    struct vdpau_render_state *render, *last, *next;
 +
 +    render = (struct vdpau_render_state *)s->current_picture.f.data[0];
 +    assert(render);
 +
 +    /*  fill LvPictureInfoVC1 struct */
 +    render->info.vc1.frame_coding_mode  = v->fcm ? v->fcm + 1 : 0;
 +    render->info.vc1.postprocflag       = v->postprocflag;
 +    render->info.vc1.pulldown           = v->broadcast;
 +    render->info.vc1.interlace          = v->interlace;
 +    render->info.vc1.tfcntrflag         = v->tfcntrflag;
 +    render->info.vc1.finterpflag        = v->finterpflag;
 +    render->info.vc1.psf                = v->psf;
 +    render->info.vc1.dquant             = v->dquant;
 +    render->info.vc1.panscan_flag       = v->panscanflag;
 +    render->info.vc1.refdist_flag       = v->refdist_flag;
 +    render->info.vc1.quantizer          = v->quantizer_mode;
 +    render->info.vc1.extended_mv        = v->extended_mv;
 +    render->info.vc1.extended_dmv       = v->extended_dmv;
 +    render->info.vc1.overlap            = v->overlap;
 +    render->info.vc1.vstransform        = v->vstransform;
 +    render->info.vc1.loopfilter         = v->s.loop_filter;
 +    render->info.vc1.fastuvmc           = v->fastuvmc;
 +    render->info.vc1.range_mapy_flag    = v->range_mapy_flag;
 +    render->info.vc1.range_mapy         = v->range_mapy;
 +    render->info.vc1.range_mapuv_flag   = v->range_mapuv_flag;
 +    render->info.vc1.range_mapuv        = v->range_mapuv;
 +    /* Specific to simple/main profile only */
 +    render->info.vc1.multires           = v->multires;
- void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
++    render->info.vc1.syncmarker         = v->resync_marker;
 +    render->info.vc1.rangered           = v->rangered | (v->rangeredfrm << 1);
 +    render->info.vc1.maxbframes         = v->s.max_b_frames;
 +
 +    render->info.vc1.deblockEnable      = v->postprocflag & 1;
 +    render->info.vc1.pquant             = v->pq;
 +
 +    render->info.vc1.forward_reference  = VDP_INVALID_HANDLE;
 +    render->info.vc1.backward_reference = VDP_INVALID_HANDLE;
 +
 +    if (v->bi_type)
 +        render->info.vc1.picture_type = 4;
 +    else
 +        render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3;
 +
 +    switch(s->pict_type){
 +    case  AV_PICTURE_TYPE_B:
 +        next = (struct vdpau_render_state *)s->next_picture.f.data[0];
 +        assert(next);
 +        render->info.vc1.backward_reference = next->surface;
 +        // no break here, going to set forward prediction
 +    case  AV_PICTURE_TYPE_P:
 +        last = (struct vdpau_render_state *)s->last_picture.f.data[0];
 +        if (!last) // FIXME: Does this test make sense?
 +            last = render; // predict second field from the first
 +        render->info.vc1.forward_reference = last->surface;
 +    }
 +
 +    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 +
 +    render->info.vc1.slice_count          = 1;
 +
 +    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
 +    render->bitstream_buffers_used        = 0;
 +}
 +#endif /* (CONFIG_VC1_VDPAU_DECODER */
 +
 +#if CONFIG_MPEG4_VDPAU_DECODER
-     render->info.mpeg4.resync_marker_disable             = !s->resync_marker;
++void ff_vdpau_mpeg4_decode_picture(Mpeg4DecContext *ctx, const uint8_t *buf,
 +                                   int buf_size)
 +{
++    MpegEncContext *s = &ctx->m;
 +    struct vdpau_render_state *render, *last, *next;
 +    int i;
 +
 +    if (!s->current_picture_ptr) return;
 +
 +    render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0];
 +    assert(render);
 +
 +    /* fill VdpPictureInfoMPEG4Part2 struct */
 +    render->info.mpeg4.trd[0]                            = s->pp_time;
 +    render->info.mpeg4.trb[0]                            = s->pb_time;
 +    render->info.mpeg4.trd[1]                            = s->pp_field_time >> 1;
 +    render->info.mpeg4.trb[1]                            = s->pb_field_time >> 1;
 +    render->info.mpeg4.vop_time_increment_resolution     = s->avctx->time_base.den;
 +    render->info.mpeg4.vop_coding_type                   = 0;
 +    render->info.mpeg4.vop_fcode_forward                 = s->f_code;
 +    render->info.mpeg4.vop_fcode_backward                = s->b_code;
++    render->info.mpeg4.resync_marker_disable             = !ctx->resync_marker;
 +    render->info.mpeg4.interlaced                        = !s->progressive_sequence;
 +    render->info.mpeg4.quant_type                        = s->mpeg_quant;
 +    render->info.mpeg4.quarter_sample                    = s->quarter_sample;
 +    render->info.mpeg4.short_video_header                = s->avctx->codec->id == AV_CODEC_ID_H263;
 +    render->info.mpeg4.rounding_control                  = s->no_rounding;
 +    render->info.mpeg4.alternate_vertical_scan_flag      = s->alternate_scan;
 +    render->info.mpeg4.top_field_first                   = s->top_field_first;
 +    for (i = 0; i < 64; ++i) {
 +        render->info.mpeg4.intra_quantizer_matrix[i]     = s->intra_matrix[i];
 +        render->info.mpeg4.non_intra_quantizer_matrix[i] = s->inter_matrix[i];
 +    }
 +    render->info.mpeg4.forward_reference                 = VDP_INVALID_HANDLE;
 +    render->info.mpeg4.backward_reference                = VDP_INVALID_HANDLE;
 +
 +    switch (s->pict_type) {
 +    case AV_PICTURE_TYPE_B:
 +        next = (struct vdpau_render_state *)s->next_picture.f.data[0];
 +        assert(next);
 +        render->info.mpeg4.backward_reference     = next->surface;
 +        render->info.mpeg4.vop_coding_type        = 2;
 +        // no break here, going to set forward prediction
 +    case AV_PICTURE_TYPE_P:
 +        last = (struct vdpau_render_state *)s->last_picture.f.data[0];
 +        assert(last);
 +        render->info.mpeg4.forward_reference      = last->surface;
 +    }
 +
 +    ff_vdpau_add_data_chunk(s->current_picture_ptr->f.data[0], buf, buf_size);
 +
 +    ff_mpeg_draw_horiz_band(s, 0, s->avctx->height);
 +    render->bitstream_buffers_used = 0;
 +}
 +#endif /* CONFIG_MPEG4_VDPAU_DECODER */
 +
  int av_vdpau_get_profile(AVCodecContext *avctx, VdpDecoderProfile *profile)
  {
  #define PROFILE(prof)       \
@@@ -4,34 -4,30 +4,35 @@@
   *
   * Copyright (C) 2008 NVIDIA
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #ifndef AVCODEC_VDPAU_INTERNAL_H
  #define AVCODEC_VDPAU_INTERNAL_H
  
 +#include "config.h"
  #include <stdint.h>
 +#if CONFIG_VDPAU
  #include <vdpau/vdpau.h>
 +#endif
 +#include "h264.h"
  
  #include "avcodec.h"
++#include "mpeg4video.h"
  #include "mpegvideo.h"
  #include "version.h"
  
@@@ -41,7 -37,6 +42,7 @@@ static inline uintptr_t ff_vdpau_get_su
      return (uintptr_t)pic->f.data[3];
  }
  
 +#if CONFIG_VDPAU
  #if !FF_API_BUFS_VDPAU
  union AVVDPAUPictureInfo {
      VdpPictureInfoH264        h264;
@@@ -74,28 -69,10 +75,28 @@@ struct vdpau_picture_context 
       */
      VdpBitstreamBuffer *bitstream_buffers;
  };
 +#endif
  
  int ff_vdpau_common_start_frame(Picture *pic,
                                  const uint8_t *buffer, uint32_t size);
  int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx);
  int ff_vdpau_add_buffer(Picture *pic, const uint8_t *buf, uint32_t buf_size);
  
- void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf,
 +
 +void ff_vdpau_add_data_chunk(uint8_t *data, const uint8_t *buf,
 +                             int buf_size);
 +
 +void ff_vdpau_mpeg_picture_complete(MpegEncContext *s, const uint8_t *buf,
 +                                    int buf_size, int slice_count);
 +
 +void ff_vdpau_h264_picture_start(H264Context *h);
 +void ff_vdpau_h264_set_reference_frames(H264Context *h);
 +void ff_vdpau_h264_picture_complete(H264Context *h);
 +
 +void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf,
 +                                 int buf_size);
 +
++void ff_vdpau_mpeg4_decode_picture(Mpeg4DecContext *s, const uint8_t *buf,
 +                                   int buf_size);
 +
  #endif /* AVCODEC_VDPAU_INTERNAL_H */
diff --combined libavcodec/vdpau_mpeg4.c
@@@ -4,33 -4,35 +4,35 @@@
   * Copyright (c) 2008 NVIDIA
   * Copyright (c) 2013 RĂ©mi Denis-Courmont
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * FFmpeg is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * FFmpeg is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
 - * License along with Libav; if not, write to the Free Software Foundation,
 + * License along with FFmpeg; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  #include <vdpau/vdpau.h>
  
  #include "avcodec.h"
+ #include "mpeg4video.h"
  #include "vdpau.h"
  #include "vdpau_internal.h"
  
  static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
                                     const uint8_t *buffer, uint32_t size)
  {
-     MpegEncContext * const s = avctx->priv_data;
+     Mpeg4DecContext *ctx = avctx->priv_data;
+     MpegEncContext * const s = &ctx->m;
      Picture *pic             = s->current_picture_ptr;
      struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
      VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
@@@ -62,7 -64,7 +64,7 @@@
      info->vop_time_increment_resolution     = s->avctx->time_base.den;
      info->vop_fcode_forward                 = s->f_code;
      info->vop_fcode_backward                = s->b_code;
-     info->resync_marker_disable             = !s->resync_marker;
+     info->resync_marker_disable             = !ctx->resync_marker;
      info->interlaced                        = !s->progressive_sequence;
      info->quant_type                        = s->mpeg_quant;
      info->quarter_sample                    = s->quarter_sample;