Merge commit '72da8d9bb24d1b1bf74c2f1108650c0da0054d2e'
authorClément Bœsch <u@pkh.me>
Sun, 19 Jun 2016 10:43:21 +0000 (12:43 +0200)
committerClément Bœsch <u@pkh.me>
Sun, 19 Jun 2016 10:50:24 +0000 (12:50 +0200)
* commit '72da8d9bb24d1b1bf74c2f1108650c0da0054d2e':
  h264_parser: remove the remaining dependencies on the h264 decoder

Merged-by: Clément Bœsch <u@pkh.me>
1  2 
configure
libavcodec/Makefile
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_parse.c
libavcodec/h264_parse.h
libavcodec/h264_parser.c

diff --cc configure
+++ b/configure
@@@ -2689,18 -2190,12 +2689,18 @@@ mpeg2_qsv_encoder_select="qsvenc
  nvenc_h264_encoder_deps="nvenc"
  nvenc_hevc_encoder_deps="nvenc"
  
 +vc1_cuvid_decoder_deps="cuda cuvid CUVIDVC1PICPARAMS"
 +vc1_cuvid_decoder_select="vc1_cuvid_hwaccel"
 +vp8_cuvid_decoder_deps="cuda cuvid CUVIDVP9PICPARAMS"
 +vp8_cuvid_decoder_select="vp8_cuvid_hwaccel"
 +vp9_cuvid_decoder_deps="cuda cuvid CUVIDVP9PICPARAMS"
 +vp9_cuvid_decoder_select="vp9_cuvid_hwaccel"
 +
  # parsers
- h264_parser_select="h264_decoder"
+ h264_parser_select="golomb h264dsp"
  hevc_parser_select="golomb"
  mpegvideo_parser_select="mpegvideo"
 -mpeg4video_parser_select="error_resilience h263dsp mpegvideo qpeldsp"
 +mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
  vc1_parser_select="vc1dsp"
  
  # bitstream_filters
Simple merge
@@@ -782,38 -753,6 +782,10 @@@ static void flush_dpb(AVCodecContext *a
      h->context_initialized = 0;
  }
  
- /**
-  * Compute profile from profile_idc and constraint_set?_flags.
-  *
-  * @param sps SPS
-  *
-  * @return profile as defined by FF_PROFILE_H264_*
-  */
- int ff_h264_get_profile(const SPS *sps)
- {
-     int profile = sps->profile_idc;
-     switch (sps->profile_idc) {
-     case FF_PROFILE_H264_BASELINE:
-         // constraint_set1_flag set to 1
-         profile |= (sps->constraint_set_flags & 1 << 1) ? FF_PROFILE_H264_CONSTRAINED : 0;
-         break;
-     case FF_PROFILE_H264_HIGH_10:
-     case FF_PROFILE_H264_HIGH_422:
-     case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
-         // constraint_set3_flag set to 1
-         profile |= (sps->constraint_set_flags & 1 << 3) ? FF_PROFILE_H264_INTRA : 0;
-         break;
-     }
-     return profile;
- }
 +#if FF_API_CAP_VDPAU
 +static const uint8_t start_code[] = { 0x00, 0x00, 0x01 };
 +#endif
 +
  static int get_last_needed_nal(H264Context *h)
  {
      int nals_needed = 0;
@@@ -705,14 -661,9 +705,9 @@@ extern const uint16_t ff_h264_mb_sizes[
   * Decode SPS
   */
  int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
 -                                     H264ParamSets *ps);
 +                                     H264ParamSets *ps, int ignore_truncation);
  
  /**
-  * compute profile from sps
-  */
- int ff_h264_get_profile(const SPS *sps);
- /**
   * Decode PPS
   */
  int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
@@@ -466,5 -447,32 +466,32 @@@ int ff_h264_decode_extradata(const uint
          if (ret < 0)
              return ret;
      }
 -    return 0;
 +    return size;
  }
+ /**
+  * Compute profile from profile_idc and constraint_set?_flags.
+  *
+  * @param sps SPS
+  *
+  * @return profile as defined by FF_PROFILE_H264_*
+  */
+ int ff_h264_get_profile(const SPS *sps)
+ {
+     int profile = sps->profile_idc;
+     switch (sps->profile_idc) {
+     case FF_PROFILE_H264_BASELINE:
+         // constraint_set1_flag set to 1
+         profile |= (sps->constraint_set_flags & 1 << 1) ? FF_PROFILE_H264_CONSTRAINED : 0;
+         break;
+     case FF_PROFILE_H264_HIGH_10:
+     case FF_PROFILE_H264_HIGH_422:
+     case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
+         // constraint_set3_flag set to 1
+         profile |= (sps->constraint_set_flags & 1 << 3) ? FF_PROFILE_H264_INTRA : 0;
+         break;
+     }
+     return profile;
+ }
Simple merge
@@@ -55,9 -52,7 +54,10 @@@ typedef struct H264ParseContext 
      int is_avc;
      int nal_length_size;
      int got_first;
+     int picture_structure;
 +    uint8_t parse_history[6];
 +    int parse_history_count;
 +    int parse_last_mb;
  } H264ParseContext;
  
  
@@@ -143,12 -109,11 +143,13 @@@ static int h264_find_frame_end(H264Pars
  found:
      pc->state             = 7;
      pc->frame_start_found = 0;
 -    return i - (state & 5);
 +    if (p->is_avc)
 +        return next_avc;
 +    return i - (state & 5) - 5 * (state > 7);
  }
  
- static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb)
+ static int scan_mmco_reset(AVCodecParserContext *s, GetBitContext *gb,
+                            AVCodecContext *avctx)
  {
      H264PredWeightTable pwt;
      int slice_type_nos = s->pict_type & 3;
          get_bits1(gb); // direct_spatial_mv_pred
  
      if (ff_h264_parse_ref_count(&list_count, ref_count, gb, p->ps.pps,
-                                 slice_type_nos, h->picture_structure, h->avctx) < 0)
 -                                slice_type_nos, p->picture_structure) < 0)
++                                slice_type_nos, p->picture_structure, avctx) < 0)
          return AVERROR_INVALIDDATA;
  
      if (slice_type_nos != AV_PICTURE_TYPE_I) {
                      unsigned int reordering_of_pic_nums_idc = get_ue_golomb_31(gb);
  
                      if (reordering_of_pic_nums_idc < 3)
 -                        get_ue_golomb(gb);
 +                        get_ue_golomb_long(gb);
                      else if (reordering_of_pic_nums_idc > 3) {
-                         av_log(h->avctx, AV_LOG_ERROR,
+                         av_log(avctx, AV_LOG_ERROR,
                                 "illegal reordering_of_pic_nums_idc %d\n",
                                 reordering_of_pic_nums_idc);
                          return AVERROR_INVALIDDATA;
@@@ -256,12 -200,13 +256,11 @@@ static inline int get_avc_nalsize(H264P
   */
  static inline int parse_nal_units(AVCodecParserContext *s,
                                    AVCodecContext *avctx,
 -                                  const uint8_t *buf, int buf_size)
 +                                  const uint8_t * const buf, int buf_size)
  {
      H264ParseContext *p = s->priv_data;
-     H264Context      *h = &p->h;
 -    const uint8_t *buf_end = buf + buf_size;
 -
      H2645NAL nal = { NULL };
 -
 +    int buf_index, next_avc;
      unsigned int pps_id;
      unsigned int slice_type;
      int state = -1, got_reset = 0;
      s->key_frame         = 0;
      s->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN;
  
-     h->avctx = avctx;
      ff_h264_sei_uninit(&p->sei);
-     h->sei.frame_packing.frame_packing_arrangement_cancel_flag = -1;
++    p->sei.frame_packing.frame_packing_arrangement_cancel_flag = -1;
  
      if (!buf_size)
          return 0;
          nal.ref_idc = get_bits(&nal.gb, 2);
          nal.type    = get_bits(&nal.gb, 5);
  
-         h->gb            = nal.gb;
-         h->nal_ref_idc   = nal.ref_idc;
-         h->nal_unit_type = nal.type;
-         switch (h->nal_unit_type) {
+         switch (nal.type) {
          case NAL_SPS:
 -            ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps);
 +            ff_h264_decode_seq_parameter_set(&nal.gb, avctx, &p->ps, 0);
              break;
          case NAL_PPS:
              ff_h264_decode_picture_parameter_set(&nal.gb, avctx, &p->ps,
              }
              p->ps.sps = (SPS*)p->ps.sps_list[p->ps.pps->sps_id]->data;
  
-             h->ps.sps = p->ps.sps;
-             h->ps.pps = p->ps.pps;
              sps = p->ps.sps;
  
-             if (h->ps.sps->ref_frame_count <= 1 && h->ps.pps->ref_count[0] <= 1 && s->pict_type == AV_PICTURE_TYPE_I)
 +            // heuristic to detect non marked keyframes
++            if (p->ps.sps->ref_frame_count <= 1 && p->ps.pps->ref_count[0] <= 1 && s->pict_type == AV_PICTURE_TYPE_I)
 +                s->key_frame = 1;
 +
              p->poc.frame_num = get_bits(&nal.gb, sps->log2_max_frame_num);
  
              s->coded_width  = 16 * sps->mb_width;
                  }
              }
  
-             if (h->nal_unit_type == NAL_IDR_SLICE)
+             if (nal.type == NAL_IDR_SLICE)
 -                get_ue_golomb(&nal.gb); /* idr_pic_id */
 +                get_ue_golomb_long(&nal.gb); /* idr_pic_id */
              if (sps->poc_type == 0) {
                  p->poc.poc_lsb = get_bits(&nal.gb, sps->log2_max_poc_lsb);
  
              av_freep(&nal.rbsp_buffer);
              return 0; /* no need to evaluate the rest */
          }
 -        buf += consumed;
 +    }
 +    if (q264) {
 +        av_freep(&nal.rbsp_buffer);
 +        return 0;
      }
      /* didn't find a picture! */
-     av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
 -    av_log(avctx, AV_LOG_ERROR, "missing picture in access unit\n");
++    av_log(avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
  fail:
      av_freep(&nal.rbsp_buffer);
      return -1;
@@@ -667,9 -566,7 +651,7 @@@ static void h264_close(AVCodecParserCon
      ParseContext *pc = &p->pc;
      int i;
  
 -    av_free(pc->buffer);
 +    av_freep(&pc->buffer);
-     ff_h264_free_context(h);
  
      ff_h264_sei_uninit(&p->sei);