Merge commit '072be3e8969f24113d599444be4d6a0ed04a6602'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 14 Dec 2012 14:00:28 +0000 (15:00 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 14 Dec 2012 14:17:51 +0000 (15:17 +0100)
* commit '072be3e8969f24113d599444be4d6a0ed04a6602':
  h264: set parameters from SPS whenever it changes
  asyncts: cosmetics: reindent

Conflicts:
libavcodec/h264.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_ps.c
libavfilter/af_asyncts.c

@@@ -2357,6 -2340,52 +2357,54 @@@ int ff_h264_get_profile(SPS *sps
      return profile;
  }
  
 -        if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {
+ static int h264_set_parameter_from_sps(H264Context *h)
+ {
+     MpegEncContext *s = &h->s;
+     if (s->flags & CODEC_FLAG_LOW_DELAY ||
+         (h->sps.bitstream_restriction_flag &&
+          !h->sps.num_reorder_frames)) {
+         if (s->avctx->has_b_frames > 1 || h->delayed_pic[0])
+             av_log(h->s.avctx, AV_LOG_WARNING, "Delayed frames seen. "
+                    "Reenabling low delay requires a codec flush.\n");
+         else
+             s->low_delay = 1;
+     }
+     if (s->avctx->has_b_frames < 2)
+         s->avctx->has_b_frames = !s->low_delay;
+     if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||
+         h->cur_chroma_format_idc      != h->sps.chroma_format_idc) {
+         if (s->avctx->codec &&
+             s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU &&
+             (h->sps.bit_depth_luma != 8 || h->sps.chroma_format_idc > 1)) {
+             av_log(s->avctx, AV_LOG_ERROR,
+                    "VDPAU decoding does not support video colorspace.\n");
+             return AVERROR_INVALIDDATA;
+         }
++        if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 14 &&
++            h->sps.bit_depth_luma != 11 && h->sps.bit_depth_luma != 13 &&
++                (h->sps.bit_depth_luma != 9 || !CHROMA422)) {
+             s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
+             h->cur_chroma_format_idc      = h->sps.chroma_format_idc;
+             h->pixel_shift                = h->sps.bit_depth_luma > 8;
+             ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma,
+                             h->sps.chroma_format_idc);
+             ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma,
+                               h->sps.chroma_format_idc);
+             s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;
+             ff_dsputil_init(&s->dsp, s->avctx);
+         } else {
+             av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n",
+                    h->sps.bit_depth_luma);
+             return AVERROR_INVALIDDATA;
+         }
+     }
+     return 0;
+ }
  /**
   * Decode a slice header.
   * This will also call ff_MPV_common_init() and frame_start() as needed.
@@@ -2373,7 -2402,7 +2421,7 @@@ static int decode_slice_header(H264Cont
      MpegEncContext *const s0 = &h0->s;
      unsigned int first_mb_in_slice;
      unsigned int pps_id;
-     int num_ref_idx_active_override_flag;
 -    int num_ref_idx_active_override_flag, max_refs, ret;
++    int num_ref_idx_active_override_flag, ret;
      unsigned int slice_type, tmp, i, j;
      int default_ref_list_done = 0;
      int last_pic_structure, last_pic_droppable;
                 h->pps.sps_id);
          return -1;
      }
-     h->sps = *h0->sps_buffers[h->pps.sps_id];
+     if (h->pps.sps_id != h->current_sps_id ||
+         h0->sps_buffers[h->pps.sps_id]->new) {
+         h0->sps_buffers[h->pps.sps_id]->new = 0;
+         h->current_sps_id = h->pps.sps_id;
+         h->sps            = *h0->sps_buffers[h->pps.sps_id];
 -
 -        if ((ret = h264_set_parameter_from_sps(h)) < 0)
 -            return ret;
+     }
  
      s->avctx->profile = ff_h264_get_profile(&h->sps);
      s->avctx->level   = h->sps.level_idc;
          s->avctx->sample_aspect_ratio = h->sps.sar;
          av_assert0(s->avctx->sample_aspect_ratio.den);
  
-         if (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU
-             && (h->sps.bit_depth_luma != 8 ||
-                 h->sps.chroma_format_idc > 1)) {
-             av_log(s->avctx, AV_LOG_ERROR,
-                    "VDPAU decoding does not support video "
-                    "colorspace\n");
-             return -1;
-         }
-         if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||
-             h->cur_chroma_format_idc != h->sps.chroma_format_idc) {
-             if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 14 && h->sps.bit_depth_luma != 11 && h->sps.bit_depth_luma != 13 &&
-                 (h->sps.bit_depth_luma != 9 || !CHROMA422)) {
-                 s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma;
-                 h->cur_chroma_format_idc = h->sps.chroma_format_idc;
-                 h->pixel_shift = h->sps.bit_depth_luma > 8;
-                 ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
-                 ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);
-                 s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;
-                 ff_dsputil_init(&s->dsp, s->avctx);
-             } else {
-                 av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d chroma_idc: %d\n",
-                        h->sps.bit_depth_luma, h->sps.chroma_format_idc);
-                 return -1;
-             }
-         }
++        if ((ret = h264_set_parameter_from_sps(h)) < 0)
++            return ret;
 +
          if (h->sps.video_signal_type_present_flag) {
 -            s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG
 +            s->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG
                                                        : AVCOL_RANGE_MPEG;
              if (h->sps.colour_description_present_flag) {
                  s->avctx->color_primaries = h->sps.color_primaries;
@@@ -4027,19 -3934,10 +4057,20 @@@ again
                      ff_h264_decode_seq_parameter_set(h);
                  }
  
 -                if (h264_set_parameter_from_sps(h) < 0) {
 -                    buf_index = -1;
 -                    goto end;
++
 +                if (s->flags & CODEC_FLAG_LOW_DELAY ||
 +                    (h->sps.bitstream_restriction_flag &&
 +                     !h->sps.num_reorder_frames)) {
 +                    if (s->avctx->has_b_frames > 1 || h->delayed_pic[0])
 +                        av_log(avctx, AV_LOG_WARNING, "Delayed frames seen "
 +                               "reenabling low delay requires a codec "
 +                               "flush.\n");
 +                        else
 +                            s->low_delay = 1;
                  }
 +
 +                if (avctx->has_b_frames < 2)
 +                    avctx->has_b_frames = !s->low_delay;
                  break;
              case NAL_PPS:
                  init_get_bits(&s->gb, ptr, bit_length);
Simple merge
@@@ -512,15 -456,16 +512,18 @@@ int ff_h264_decode_seq_parameter_set(H2
                 sps->vui_parameters_present_flag ? "VUI" : "",
                 csp[sps->chroma_format_idc],
                 sps->timing_info_present_flag ? sps->num_units_in_tick : 0,
 -               sps->timing_info_present_flag ? sps->time_scale : 0
 +               sps->timing_info_present_flag ? sps->time_scale : 0,
 +               sps->bit_depth_luma,
 +               h->sps.bitstream_restriction_flag ? sps->num_reorder_frames : -1
                 );
      }
+     sps->new = 1;
  
      av_free(h->sps_buffers[sps_id]);
-     h->sps_buffers[sps_id]= sps;
-     h->sps = *sps;
+     h->sps_buffers[sps_id] = sps;
+     h->sps                 = *sps;
+     h->current_sps_id      = sps_id;
      return 0;
  fail:
      av_free(sps);
Simple merge