Merge commit '7d8482640058d66867602a6f58446c9342d9d146'
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 31 Dec 2012 12:26:12 +0000 (13:26 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Mon, 31 Dec 2012 12:38:01 +0000 (13:38 +0100)
* commit '7d8482640058d66867602a6f58446c9342d9d146':
  cavs: deMpegEncContextize

Note, the bugfixes have all been in FFmpeg previously, this just switches away
from MpegEncContext

Conflicts:
libavcodec/cavs.c
libavcodec/cavsdec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/cavs.c
libavcodec/cavs.h
libavcodec/cavsdec.c

@@@ -668,9 -667,7 +667,7 @@@ int ff_cavs_next_mb(AVSContext *h) 
   *
   ****************************************************************************/
  
 -void ff_cavs_init_pic(AVSContext *h) {
 +int ff_cavs_init_pic(AVSContext *h) {
-     MpegEncContext *s = &h->s;
-     int ret;
      int i;
  
      /* clear some predictors */
      h->luma_scan[3] = 8*h->l_stride+8;
      h->mbx = h->mby = h->mbidx = 0;
      h->flags = 0;
-     if (!s->edge_emu_buffer &&
-         (ret = ff_mpv_frame_size_alloc(s, h->picture.f.linesize[0])) < 0) {
-         av_log(s->avctx, AV_LOG_ERROR,
-                "get_buffer() failed to allocate context scratch buffers.\n");
-         return ret;
-     }
 +
 +    return 0;
  }
  
  /*****************************************************************************
Simple merge
@@@ -601,9 -601,9 +603,9 @@@ static inline int decode_residual_inter
      int block;
  
      /* get coded block pattern */
-     int cbp = get_ue_golomb(&h->s.gb);
+     int cbp = get_ue_golomb(&h->gb);
 -    if (cbp > 63) {
 +    if (cbp > 63U) {
-         av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n");
+         av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp\n");
          return -1;
      }
      h->cbp = cbp_tab[cbp][1];
@@@ -673,8 -673,8 +675,8 @@@ static int decode_mb_i(AVSContext *h, i
      /* get coded block pattern */
      if (h->pic_type == AV_PICTURE_TYPE_I)
          cbp_code = get_ue_golomb(gb);
 -    if (cbp_code > 63) {
 +    if (cbp_code > 63U) {
-         av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n");
+         av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
          return -1;
      }
      h->cbp = cbp_tab[cbp_code][0];
@@@ -832,11 -832,7 +834,11 @@@ static int decode_mb_b(AVSContext *h, e
          }
          break;
      default:
 -        assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8));
 +        if (mb_type <= B_SYM_16X16) {
-             av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
++            av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
 +            return AVERROR_INVALIDDATA;
 +        }
 +        av_assert2(mb_type < B_8X8);
          flags = ff_cavs_partition_flags[mb_type];
          if (mb_type & 1) { /* 16x8 macroblock types */
              if (flags & FWD0)
  static inline int decode_slice_header(AVSContext *h, GetBitContext *gb)
  {
      if (h->stc > 0xAF)
-         av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
+         av_log(h->avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
 +
 +    if (h->stc >= h->mb_height)
 +        return -1;
 +
      h->mby   = h->stc;
      h->mbidx = h->mby * h->mb_width;
  
@@@ -938,23 -928,14 +940,15 @@@ static inline int check_for_slice(AVSCo
  
  static int decode_pic(AVSContext *h)
  {
-     MpegEncContext *s = &h->s;
      int skip_count    = -1;
 +    int ret;
      enum cavs_mb mb_type;
  
-     if (!s->context_initialized) {
-         if (ff_MPV_common_init(s) < 0)
-             return -1;
-         ff_init_scantable_permutation(s->dsp.idct_permutation,
-                                       h->cdsp.idct_perm);
-         ff_init_scantable(s->dsp.idct_permutation, &h->scantable, ff_zigzag_direct);
-     }
-     skip_bits(&s->gb, 16);//bbv_dwlay
+     skip_bits(&h->gb, 16);//bbv_dwlay
      if (h->stc == PIC_PB_START_CODE) {
-         h->pic_type = get_bits(&s->gb, 2) + AV_PICTURE_TYPE_I;
+         h->pic_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
          if (h->pic_type > AV_PICTURE_TYPE_B) {
-             av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n");
+             av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
              return -1;
          }
          /* make sure we have the reference frames we need */
              return -1;
      } else {
          h->pic_type = AV_PICTURE_TYPE_I;
-         if (get_bits1(&s->gb))
-             skip_bits(&s->gb, 24);//time_code
+         if (get_bits1(&h->gb))
+             skip_bits(&h->gb, 24);//time_code
          /* old sample clips were all progressive and no low_delay,
             bump stream revision if detected otherwise */
-         if (s->low_delay || !(show_bits(&s->gb, 9) & 1))
+         if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
              h->stream_revision = 1;
          /* similarly test top_field_first and repeat_first_field */
-         else if (show_bits(&s->gb, 11) & 3)
+         else if (show_bits(&h->gb, 11) & 3)
              h->stream_revision = 1;
          if (h->stream_revision > 0)
-             skip_bits(&s->gb, 1); //marker_bit
+             skip_bits(&h->gb, 1); //marker_bit
      }
      /* release last B frame */
-     if (h->picture.f.data[0])
-         s->avctx->release_buffer(s->avctx, &h->picture.f);
+     if (h->cur.f->data[0])
+         h->avctx->release_buffer(h->avctx, h->cur.f);
  
-     if ((ret = ff_get_buffer(s->avctx, &h->picture.f)) < 0)
 -    ff_get_buffer(h->avctx, h->cur.f);
++    if ((ret = ff_get_buffer(h->avctx, h->cur.f)) < 0)
 +        return ret;
+     if (!h->edge_emu_buffer) {
+         int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
+         h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
+         if (!h->edge_emu_buffer)
+             return AVERROR(ENOMEM);
+     }
 -    ff_cavs_init_pic(h);
 +    if ((ret = ff_cavs_init_pic(h)) < 0)
 +        return ret;
-     h->picture.poc = get_bits(&s->gb, 8) * 2;
+     h->cur.poc = get_bits(&h->gb, 8) * 2;
  
      /* get temporal distances and MV scaling factors */
      if (h->pic_type != AV_PICTURE_TYPE_B) {
@@@ -1089,38 -1075,33 +1090,37 @@@ static int decode_seq_header(AVSContex
      int frame_rate_code;
      int width, height;
  
-     h->profile = get_bits(&s->gb, 8);
-     h->level   = get_bits(&s->gb, 8);
-     skip_bits1(&s->gb); //progressive sequence
+     h->profile = get_bits(&h->gb, 8);
+     h->level   = get_bits(&h->gb, 8);
+     skip_bits1(&h->gb); //progressive sequence
  
-     width  = get_bits(&s->gb, 14);
-     height = get_bits(&s->gb, 14);
-     if ((s->width || s->height) && (s->width != width || s->height != height)) {
-         av_log_missing_feature(s, "Width/height changing in CAVS", 0);
+     width  = get_bits(&h->gb, 14);
+     height = get_bits(&h->gb, 14);
+     if ((h->width || h->height) && (h->width != width || h->height != height)) {
+         av_log_missing_feature(h->avctx, "Width/height changing in CAVS", 0);
          return AVERROR_PATCHWELCOME;
      }
-         av_log(s, AV_LOG_ERROR, "Dimensions invalid\n");
 +    if (width <= 0 || height <= 0) {
-     s->width  = width;
-     s->height = height;
-     skip_bits(&s->gb, 2); //chroma format
-     skip_bits(&s->gb, 3); //sample_precision
-     h->aspect_ratio = get_bits(&s->gb, 4);
-     frame_rate_code = get_bits(&s->gb, 4);
-     skip_bits(&s->gb, 18); //bit_rate_lower
-     skip_bits1(&s->gb);    //marker_bit
-     skip_bits(&s->gb, 12); //bit_rate_upper
-     s->low_delay =  get_bits1(&s->gb);
-     h->mb_width  = (s->width  + 15) >> 4;
-     h->mb_height = (s->height + 15) >> 4;
-     h->s.avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_code].num;
-     h->s.avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_code].den;
-     h->s.avctx->width  = s->width;
-     h->s.avctx->height = s->height;
++        av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
 +        return AVERROR_INVALIDDATA;
 +    }
+     h->width  = width;
+     h->height = height;
+     skip_bits(&h->gb, 2); //chroma format
+     skip_bits(&h->gb, 3); //sample_precision
+     h->aspect_ratio = get_bits(&h->gb, 4);
+     frame_rate_code = get_bits(&h->gb, 4);
+     skip_bits(&h->gb, 18); //bit_rate_lower
+     skip_bits1(&h->gb);    //marker_bit
+     skip_bits(&h->gb, 12); //bit_rate_upper
+     h->low_delay =  get_bits1(&h->gb);
+     h->mb_width  = (h->width  + 15) >> 4;
+     h->mb_height = (h->height + 15) >> 4;
+     h->avctx->time_base.den = ff_mpeg12_frame_rate_tab[frame_rate_code].num;
+     h->avctx->time_base.num = ff_mpeg12_frame_rate_tab[frame_rate_code].den;
+     h->avctx->width  = h->width;
+     h->avctx->height = h->height;
      if (!h->top_qp)
          ff_cavs_init_top_lines(h);
      return 0;
@@@ -1180,9 -1160,7 +1179,9 @@@ static int cavs_decode_frame(AVCodecCon
              *got_frame = 0;
              if (!h->got_keyframe)
                  break;
-             init_get_bits(&s->gb, buf_ptr, input_size);
 +            if(!h->top_qp)
 +                break;
+             init_get_bits(&h->gb, buf_ptr, input_size);
              h->stc = stc;
              if (decode_pic(h))
                  break;