Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Sep 2011 19:35:18 +0000 (21:35 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 6 Sep 2011 19:35:18 +0000 (21:35 +0200)
* qatar/master:
  libx264: add 'cplxblur' private option
  libx264: add 'deblock' private option
  libx264: add 'b-bias' private option
  libx264: fix setting some options.
  libx264: remove useless assignment
  ac3dec: avoid pointless alloc and indirection for input_buffer
  mpeg12: cosmetics: reformat as K&R

Conflicts:
libavcodec/libx264.c
libavcodec/mpeg12.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/avcodec.h
libavcodec/libx264.c
libavcodec/mpeg12.c
libavcodec/options.c

Simple merge
@@@ -193,45 -186,12 +196,51 @@@ static av_cold int X264_close(AVCodecCo
      return 0;
  }
  
 +/**
 + * Detect default settings and use default profile to avoid libx264 failure.
 + */
 +static void check_default_settings(AVCodecContext *avctx)
 +{
 +    X264Context *x4 = avctx->priv_data;
 +
 +    int score = 0;
 +    score += x4->params.analyse.i_me_range == 0;
 +    score += x4->params.rc.i_qp_step == 3;
 +    score += x4->params.i_keyint_max == 12;
 +    score += x4->params.rc.i_qp_min == 2;
 +    score += x4->params.rc.i_qp_max == 31;
 +    score += x4->params.rc.f_qcompress == 0.5;
 +    score += fabs(x4->params.rc.f_ip_factor - 1.25) < 0.01;
 +    score += fabs(x4->params.rc.f_pb_factor - 1.25) < 0.01;
 +    score += x4->params.analyse.inter == 0 && x4->params.analyse.i_subpel_refine == 8;
 +    if (score >= 5) {
 +        av_log(avctx, AV_LOG_ERROR, "Default settings detected, using medium profile\n");
 +        x4->preset = av_strdup("medium");
 +        if (avctx->bit_rate == 200*1000)
 +            avctx->crf = 23;
 +    }
 +}
 +
 +#define OPT_STR(opt, param)                                                   \
 +    do {                                                                      \
 +        int ret;                                                              \
 +        if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \
 +            if(ret == X264_PARAM_BAD_NAME)                                    \
 +                av_log(avctx, AV_LOG_ERROR,                                   \
 +                        "bad option '%s': '%s'\n", opt, param);               \
 +            else                                                              \
 +                av_log(avctx, AV_LOG_ERROR,                                   \
 +                        "bad value for '%s': '%s'\n", opt, param);            \
 +            return -1;                                                        \
 +        }                                                                     \
 +    } while (0);
 +
+ #define PARSE_X264_OPT(name, var)\
+     if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\
+         av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\
+         return AVERROR(EINVAL);\
+     }
  static av_cold int X264_init(AVCodecContext *avctx)
  {
      X264Context *x4 = avctx->priv_data;
@@@ -1,11 -1,11 +1,11 @@@
  /*
   * MPEG-1/2 decoder
-  * Copyright (c) 2000,2001 Fabrice Bellard
+  * Copyright (c) 2000, 2001 Fabrice Bellard
   * Copyright (c) 2002-2004 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.
@@@ -448,15 -440,11 +440,15 @@@ static int mpeg_decode_mb(MpegEncContex
                  }
                  break;
              case MT_DMV:
 +                if(s->progressive_sequence){
 +                    av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
 +                    return -1;
 +                }
                  s->mv_type = MV_TYPE_DMV;
-                 for(i=0;i<2;i++) {
+                 for (i = 0; i < 2; i++) {
                      if (USES_LIST(mb_type, i)) {
                          int dmx, dmy, mx, my, m;
-                         const int my_shift= s->picture_structure == PICT_FRAME;
+                         const int my_shift = s->picture_structure == PICT_FRAME;
  
                          mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
                                                  s->last_mv[i][0][0]);
@@@ -1217,41 -1193,8 +1197,42 @@@ static void quant_matrix_rebuild(uint16
      }
  }
  
- static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){
 +static const enum PixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
 +#if CONFIG_MPEG_XVMC_DECODER
 +    PIX_FMT_XVMC_MPEG2_IDCT,
 +    PIX_FMT_XVMC_MPEG2_MC,
 +#endif
 +#if CONFIG_MPEG1_VDPAU_HWACCEL
 +    PIX_FMT_VDPAU_MPEG1,
 +#endif
 +    PIX_FMT_YUV420P,
 +    PIX_FMT_NONE
 +};
 +
 +static const enum PixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
 +#if CONFIG_MPEG_XVMC_DECODER
 +    PIX_FMT_XVMC_MPEG2_IDCT,
 +    PIX_FMT_XVMC_MPEG2_MC,
 +#endif
 +#if CONFIG_MPEG2_VDPAU_HWACCEL
 +    PIX_FMT_VDPAU_MPEG2,
 +#endif
 +#if CONFIG_MPEG2_DXVA2_HWACCEL
 +    PIX_FMT_DXVA2_VLD,
 +#endif
 +#if CONFIG_MPEG2_VAAPI_HWACCEL
 +    PIX_FMT_VAAPI_VLD,
 +#endif
 +    PIX_FMT_YUV420P,
 +    PIX_FMT_NONE
 +};
 +
 +static inline int uses_vdpau(AVCodecContext *avctx) {
 +    return avctx->pix_fmt == PIX_FMT_VDPAU_MPEG1 || avctx->pix_fmt == PIX_FMT_VDPAU_MPEG2;
 +}
 +
+ static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
+ {
      Mpeg1Context *s1 = avctx->priv_data;
      MpegEncContext *s = &s1->mpeg_enc_ctx;
  
@@@ -1369,10 -1304,11 +1343,10 @@@ static int mpeg_decode_postinit(AVCodec
  
          avctx->pix_fmt = mpeg_get_pixelformat(avctx);
          avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
-         //until then pix_fmt may be changed right after codec init
-         ifavctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
+         // until then pix_fmt may be changed right after codec init
+         if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT ||
 -            avctx->hwaccel                            ||
 -            s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
 +            avctx->hwaccel )
-             if( avctx->idct_algo == FF_IDCT_AUTO )
+             if (avctx->idct_algo == FF_IDCT_AUTO)
                  avctx->idct_algo = FF_IDCT_SIMPLE;
  
          /* Quantization matrices may need reordering
@@@ -1597,30 -1534,31 +1572,30 @@@ static void mpeg_decode_picture_coding_
          av_log(s->avctx, AV_LOG_ERROR, "interlaced frame in progressive sequence, ignoring\n");
      }
  
-     if(s->picture_structure==0 || (s->progressive_frame && s->picture_structure!=PICT_FRAME)){
+     if (s->picture_structure == 0 || (s->progressive_frame && s->picture_structure != PICT_FRAME)) {
          av_log(s->avctx, AV_LOG_ERROR, "picture_structure %d invalid, ignoring\n", s->picture_structure);
-         s->picture_structure= PICT_FRAME;
+         s->picture_structure = PICT_FRAME;
      }
  
-     if(s->progressive_sequence && !s->frame_pred_frame_dct){
+     if (s->progressive_sequence && !s->frame_pred_frame_dct) {
          av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n");
 -        s->frame_pred_frame_dct = 1;
      }
  
-     if(s->picture_structure == PICT_FRAME){
-         s->first_field=0;
-         s->v_edge_pos= 16*s->mb_height;
-     }else{
+     if (s->picture_structure == PICT_FRAME) {
+         s->first_field = 0;
+         s->v_edge_pos  = 16 * s->mb_height;
+     } else {
          s->first_field ^= 1;
-         s->v_edge_pos=  8*s->mb_height;
-         memset(s->mbskip_table, 0, s->mb_stride*s->mb_height);
+         s->v_edge_pos   = 8 * s->mb_height;
+         memset(s->mbskip_table, 0, s->mb_stride * s->mb_height);
      }
  
-     if(s->alternate_scan){
-         ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable  , ff_alternate_vertical_scan);
-         ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable  , ff_alternate_vertical_scan);
-     }else{
-         ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable  , ff_zigzag_direct);
-         ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable  , ff_zigzag_direct);
+     if (s->alternate_scan) {
+         ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
+         ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
+     } else {
+         ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
+         ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
      }
  
      /* composite display not parsed */
@@@ -2116,8 -2058,9 +2095,8 @@@ static int vcr2_init_sequence(AVCodecCo
      avctx->pix_fmt = mpeg_get_pixelformat(avctx);
      avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
  
 -    if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
 -        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
 +    if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel )
-         if( avctx->idct_algo == FF_IDCT_AUTO )
+         if (avctx->idct_algo == FF_IDCT_AUTO)
              avctx->idct_algo = FF_IDCT_SIMPLE;
  
      if (MPV_common_init(s) < 0)
@@@ -2321,20 -2267,19 +2303,20 @@@ static int decode_chunks(AVCodecContex
      const uint8_t *buf_ptr = buf;
      const uint8_t *buf_end = buf + buf_size;
      int ret, input_size;
-     int last_code= 0;
+     int last_code = 0;
  
-     for(;;) {
+     for (;;) {
          /* find next start code */
          uint32_t start_code = -1;
-         buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
-         if (start_code > 0x1ff){
-             if(s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT){
-                 if(HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)){
+         buf_ptr = ff_find_start_code(buf_ptr, buf_end, &start_code);
+         if (start_code > 0x1ff) {
+             if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) {
+                 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
                      int i;
 +                    av_assert0(avctx->thread_count > 1);
  
                      avctx->execute(avctx, slice_decode_thread,  &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
-                     for(i=0; i<s->slice_count; i++)
+                     for (i = 0; i < s->slice_count; i++)
                          s2->error_count += s2->thread_context[i]->error_count;
                  }
  
                      break;
                  }
  
-                 if(HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)){
+                 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
 -                    int threshold= (s2->mb_height * s->slice_count + avctx->thread_count / 2) / avctx->thread_count;
 +                    int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
 +                    av_assert0(avctx->thread_count > 1);
-                     if(threshold <= mb_y){
-                         MpegEncContext *thread_context= s2->thread_context[s->slice_count];
+                     if (threshold <= mb_y) {
+                         MpegEncContext *thread_context = s2->thread_context[s->slice_count];
  
-                         thread_context->start_mb_y= mb_y;
-                         thread_context->end_mb_y  = s2->mb_height;
-                         if(s->slice_count){
-                             s2->thread_context[s->slice_count-1]->end_mb_y= mb_y;
+                         thread_context->start_mb_y = mb_y;
+                         thread_context->end_mb_y   = s2->mb_height;
+                         if (s->slice_count) {
+                             s2->thread_context[s->slice_count-1]->end_mb_y = mb_y;
                              ff_update_duplicate_context(thread_context, s2);
                          }
                          init_get_bits(&thread_context->gb, buf_ptr, input_size*8);
@@@ -392,13 -392,15 +392,15 @@@ static const AVOption options[]=
  {"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E},
  {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E},
  #if FF_API_X264_GLOBAL_OPTS
 -{"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E},
 +{"crf", "enables constant quality mode, and selects the quality (x264/VP8)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 63, V|E},
  {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E},
  #endif
 -{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E},
 -{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
 +{"keyint_min", "minimum interval between IDR-frames", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E},
 +{"refs", "reference frames to consider for motion compensation", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E},
  {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+ #if FF_API_X264_GLOBAL_OPTS
  {"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E},
+ #endif
  {"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
  {"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), FF_OPT_TYPE_INT, {.dbl = 2 }, INT_MIN, INT_MAX, V|E},
  #if FF_API_X264_GLOBAL_OPTS