OSDN Git Service

Merge commit 'e2ceb17642f374a7df8f1f5d3d2b2446525bc7fb'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 30 Nov 2013 01:42:56 +0000 (02:42 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 30 Nov 2013 01:42:56 +0000 (02:42 +0100)
* commit 'e2ceb17642f374a7df8f1f5d3d2b2446525bc7fb':
  mpeg4videodec: move mpeg4-specific post-frame-decode code from h264dec to mpeg4videodec

Conflicts:
libavcodec/h263dec.c
libavcodec/mpeg4video.h
libavcodec/mpeg4videodec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/h263dec.c
libavcodec/mpeg4video.h
libavcodec/mpeg4videodec.c

@@@ -623,38 -608,6 +623,9 @@@ frame_end
  
      ff_MPV_frame_end(s);
  
-     /* divx 5.01+ bitstream reorder stuff */
-     /* Since this clobbers the input buffer and hwaccel codecs still need the
-      * data during hwaccel->end_frame we should not do this any earlier */
-     if (s->codec_id == AV_CODEC_ID_MPEG4 && s->divx_packed) {
-         int current_pos     = s->gb.buffer == s->bitstream_buffer ? 0 : (get_bits_count(&s->gb) >> 3);
-         int startcode_found = 0;
-         if (buf_size - current_pos > 7) {
-             int i;
-             for (i = current_pos; i < buf_size - 4; i++)
-                 if (buf[i]     == 0 &&
-                     buf[i + 1] == 0 &&
-                     buf[i + 2] == 1 &&
-                     buf[i + 3] == 0xB6) {
-                     startcode_found = !(buf[i + 4] & 0x40);
-                     break;
-                 }
-         }
-         if (startcode_found) {
-             av_fast_malloc(&s->bitstream_buffer,
-                            &s->allocated_bitstream_buffer_size,
-                            buf_size - current_pos +
-                            FF_INPUT_BUFFER_PADDING_SIZE);
-             if (!s->bitstream_buffer)
-                 return AVERROR(ENOMEM);
-             memcpy(s->bitstream_buffer, buf + current_pos,
-                    buf_size - current_pos);
-             s->bitstream_buffer_size = buf_size - current_pos;
-         }
-     }
++    if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
++        ff_mpeg4_frame_end(avctx, buf, buf_size);
 +
      if (!s->divx_packed && avctx->hwaccel)
          ff_thread_finish_setup(avctx);
  
@@@ -118,8 -118,7 +118,9 @@@ 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);
 +int ff_mpeg4_workaround_bugs(AVCodecContext *avctx);
+ int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
  
  /**
   *
          s->low_delay = 1;
      s->avctx->has_b_frames = !s->low_delay;
  
 -    if (s->xvid_build == -1 && s->divx_version == -1 && s->lavc_build == -1) {
 -        if (s->stream_codec_tag == AV_RL32("XVID") ||
 -            s->codec_tag        == AV_RL32("XVID") ||
 -            s->codec_tag        == AV_RL32("XVIX") ||
 -            s->codec_tag        == AV_RL32("RMP4") ||
 -            s->codec_tag        == AV_RL32("ZMP4") ||
 -            s->codec_tag        == AV_RL32("SIPP"))
 -            s->xvid_build = 0;
 -    }
 -
 -    if (s->xvid_build == -1 && s->divx_version == -1 && s->lavc_build == -1)
 -        if (s->codec_tag == AV_RL32("DIVX") && s->vo_type == 0 &&
 -            s->vol_control_parameters == 0)
 -            s->divx_version = 400;  // divx 4
 -
 -    if (s->xvid_build >= 0 && s->divx_version >= 0) {
 -        s->divx_version =
 -        s->divx_build   = -1;
 -    }
 -
 -    if (s->workaround_bugs & FF_BUG_AUTODETECT) {
 -        if (s->codec_tag == AV_RL32("XVIX"))
 -            s->workaround_bugs |= FF_BUG_XVID_ILACE;
 -
 -        if (s->codec_tag == AV_RL32("UMP4"))
 -            s->workaround_bugs |= FF_BUG_UMP4;
 -
 -        if (s->divx_version >= 500 && s->divx_build < 1814)
 -            s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
 -
 -        if (s->divx_version > 502 && s->divx_build < 1814)
 -            s->workaround_bugs |= FF_BUG_QPEL_CHROMA2;
 -
 -        if (s->xvid_build <= 3U)
 -            s->padding_bug_score = 256 * 256 * 256 * 64;
 -
 -        if (s->xvid_build <= 1U)
 -            s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
 -
 -        if (s->xvid_build <= 12U)
 -            s->workaround_bugs |= FF_BUG_EDGE;
 -
 -        if (s->xvid_build <= 32U)
 -            s->workaround_bugs |= FF_BUG_DC_CLIP;
 -
 -        if (s->lavc_build < 4653U)
 -            s->workaround_bugs |= FF_BUG_STD_QPEL;
 -
 -        if (s->lavc_build < 4655U)
 -            s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
 -
 -        if (s->lavc_build < 4670U)
 -            s->workaround_bugs |= FF_BUG_EDGE;
 -
 -        if (s->lavc_build <= 4712U)
 -            s->workaround_bugs |= FF_BUG_DC_CLIP;
 -
 -        if (s->divx_version >= 0)
 -            s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
 -
 -        if (s->divx_version == 501 && s->divx_build == 20020416)
 -            s->padding_bug_score = 256 * 256 * 256 * 64;
 -
 -        if (s->divx_version < 500U)
 -            s->workaround_bugs |= FF_BUG_EDGE;
 +    return decode_vop_header(ctx, gb);
 +}
  
 -        if (s->divx_version >= 0)
 -            s->workaround_bugs |= FF_BUG_HPEL_CHROMA;
 -    }
 +av_cold void ff_mpeg4videodec_static_init(void) {
 +    static int done = 0;
  
 -#if HAVE_MMX
 -    if (s->codec_id == AV_CODEC_ID_MPEG4 && s->xvid_build >= 0 &&
 -        s->avctx->idct_algo == FF_IDCT_AUTO &&
 -        (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) {
 -        s->avctx->idct_algo = FF_IDCT_XVIDMMX;
 -        ff_dct_common_init(s);
 -        s->picture_number = 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;
      }
 -#endif
 -
 -    if (s->avctx->debug & FF_DEBUG_BUGS)
 -        av_log(s->avctx, AV_LOG_DEBUG,
 -               "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
 -               s->workaround_bugs, s->lavc_build, s->xvid_build,
 -               s->divx_version, s->divx_build, s->divx_packed ? "p" : "");
 -
 -    return decode_vop_header(ctx, gb);
  }
  
 -    /* divx 5.01+ bistream reorder stuff */
+ int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
+ {
+     Mpeg4DecContext *ctx = avctx->priv_data;
+     MpegEncContext    *s = &ctx->m;
 -        int current_pos     = get_bits_count(&s->gb) >> 3;
++    /* divx 5.01+ bitstream reorder stuff */
++    /* Since this clobbers the input buffer and hwaccel codecs still need the
++     * data during hwaccel->end_frame we should not do this any earlier */
+     if (s->divx_packed) {
 -        if (buf_size - current_pos > 5) {
++        int current_pos     = s->gb.buffer == s->bitstream_buffer ? 0 : (get_bits_count(&s->gb) >> 3);
+         int startcode_found = 0;
 -            for (i = current_pos; i < buf_size - 3; i++)
++        if (buf_size - current_pos > 7) {
++
+             int i;
 -                    startcode_found = 1;
++            for (i = current_pos; i < buf_size - 4; i++)
++
+                 if (buf[i]     == 0 &&
+                     buf[i + 1] == 0 &&
+                     buf[i + 2] == 1 &&
+                     buf[i + 3] == 0xB6) {
 -        if (s->gb.buffer == s->bitstream_buffer && buf_size > 7 &&
 -            s->xvid_build >= 0) {       // xvid style
 -            startcode_found = 1;
 -            current_pos     = 0;
 -        }
++                    startcode_found = !(buf[i + 4] & 0x40);
+                     break;
+                 }
+         }
+         if (startcode_found) {
+             av_fast_malloc(&s->bitstream_buffer,
+                            &s->allocated_bitstream_buffer_size,
+                            buf_size - current_pos +
+                            FF_INPUT_BUFFER_PADDING_SIZE);
+             if (!s->bitstream_buffer)
+                 return AVERROR(ENOMEM);
+             memcpy(s->bitstream_buffer, buf + current_pos,
+                    buf_size - current_pos);
+             s->bitstream_buffer_size = buf_size - current_pos;
+         }
+     }
+     return 0;
+ }
  static int mpeg4_update_thread_context(AVCodecContext *dst,
                                         const AVCodecContext *src)
  {