Merge commit '8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6'
authorHendrik Leppkes <h.leppkes@gmail.com>
Tue, 17 May 2016 12:21:12 +0000 (14:21 +0200)
committerHendrik Leppkes <h.leppkes@gmail.com>
Tue, 17 May 2016 12:21:12 +0000 (14:21 +0200)
* commit '8d0cc8ca97678f4ca87948ebabcbaab5a4f4c1f6':
  h264_parser: switch to h2645_parse for NAL unescaping

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
1  2 
libavcodec/Makefile
libavcodec/h264.c
libavcodec/h264.h
libavcodec/h264_parser.c

Simple merge
Simple merge
Simple merge
index c86f0324f89d7401ed46c8f73942f005f39b7a6b,bcbaf1a2ce146de994e95e908f78e89f93688865..6cf4a236a098cdee63799d586825aa5f208eef78
@@@ -227,13 -194,15 +227,14 @@@ static inline int parse_nal_units(AVCod
      H264ParseContext *p = s->priv_data;
      H264Context      *h = &p->h;
      H264SliceContext *sl = &h->slice_ctx[0];
 -    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;
-     const uint8_t *ptr;
 +    int q264 = buf_size >=4 && !memcmp("Q264", buf, 4);
      int field_poc[2];
+     int ret;
  
      /* set some sane default values */
      s->pict_type         = AV_PICTURE_TYPE_I;
      if (!buf_size)
          return 0;
  
 +    buf_index     = 0;
 +    next_avc      = h->is_avc ? 0 : buf_size;
      for (;;) {
-         int src_length, dst_length, consumed, nalsize = 0;
 -        int src_length, consumed;
 -        buf = avpriv_find_start_code(buf, buf_end, &state);
 -        if (buf >= buf_end)
 -            break;
 -        --buf;
 -        src_length = buf_end - buf;
++        int src_length, consumed, nalsize = 0;
 +
 +        if (buf_index >= next_avc) {
 +            nalsize = get_avc_nalsize(h, buf, buf_size, &buf_index);
 +            if (nalsize < 0)
 +                break;
 +            next_avc = buf_index + nalsize;
 +        } else {
 +            buf_index = find_start_code(buf, buf_size, buf_index, next_avc);
 +            if (buf_index >= buf_size)
 +                break;
 +            if (buf_index >= next_avc)
 +                continue;
 +        }
 +        src_length = next_avc - buf_index;
 +
 +        state = buf[buf_index];
          switch (state & 0x1f) {
          case NAL_SLICE:
          case NAL_IDR_SLICE:
              }
              break;
          }
-         ptr = ff_h264_decode_nal(h, sl, buf + buf_index, &dst_length,
-                                  &consumed, src_length);
-         if (!ptr || dst_length < 0)
 -
 -        consumed = ff_h2645_extract_rbsp(buf, src_length, &nal);
++        consumed = ff_h2645_extract_rbsp(buf + buf_index, src_length, &nal);
+         if (consumed < 0)
              break;
  
 -        ret = init_get_bits(&nal.gb, nal.data, nal.size * 8);
 +        buf_index += consumed;
 +
-         init_get_bits(&h->gb, ptr, 8 * dst_length);
++        ret = init_get_bits8(&nal.gb, nal.data, nal.size);
+         if (ret < 0)
+             goto fail;
+         get_bits1(&nal.gb);
+         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) {
          case NAL_SPS:
 -            ff_h264_decode_seq_parameter_set(h);
 +            ff_h264_decode_seq_parameter_set(h, 0);
              break;
          case NAL_PPS:
              ff_h264_decode_picture_parameter_set(h, h->gb.size_in_bits);
              h->prev_poc_lsb          = 0;
          /* fall through */
          case NAL_SLICE:
-             init_get_bits(&sl->gb, ptr, 8 * dst_length);
+             sl->gb = nal.gb;
 -            get_ue_golomb(&sl->gb);  // skip first_mb_in_slice
 +            get_ue_golomb_long(&sl->gb);  // skip first_mb_in_slice
              slice_type   = get_ue_golomb_31(&sl->gb);
              s->pict_type = ff_h264_golomb_to_pict_type[slice_type % 5];
              if (h->sei_recovery_frame_cnt >= 0) {
                  s->field_order = AV_FIELD_UNKNOWN;
              }
  
+             av_freep(&nal.rbsp_buffer);
              return 0; /* no need to evaluate the rest */
          }
 -        buf += consumed;
 +    }
-     if (q264)
++    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\n");
 +    av_log(h->avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size);
+ fail:
+     av_freep(&nal.rbsp_buffer);
      return -1;
  }