[FFmpeg-cvslog] Merge commit '7ab5d577a9affe3397c08b032f983f9bf7101865'

Clément Bœsch git at videolan.org
Wed Jun 29 20:04:46 CEST 2016


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Wed Jun 29 20:04:23 2016 +0200| [c28aecc56ace7a6f5f21c1484d00932d4777f4e8] | committer: Clément Bœsch

Merge commit '7ab5d577a9affe3397c08b032f983f9bf7101865'

* commit '7ab5d577a9affe3397c08b032f983f9bf7101865':
  h264: move initializing the slice start out of h264_slice_header_parse()

Merged-by: Clément Bœsch <u at pkh.me>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c28aecc56ace7a6f5f21c1484d00932d4777f4e8
---

 libavcodec/h264.h       |    1 +
 libavcodec/h264_slice.c |   33 ++++++++++++++++-----------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 2544e9d..42f144f 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -370,6 +370,7 @@ typedef struct H264SliceContext {
     int mb_xy;
     int resync_mb_x;
     int resync_mb_y;
+    unsigned int first_mb_addr;
     // index of the first MB of the next slice
     int next_slice_idx;
     int mb_skip_run;
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 0e09ee2..e5fb64f 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1024,7 +1024,6 @@ static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)
 {
     const SPS *sps;
     const PPS *pps;
-    unsigned int first_mb_in_slice;
     unsigned int pps_id;
     int ret;
     unsigned int slice_type, tmp, i;
@@ -1039,9 +1038,9 @@ static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)
     if (first_slice)
         av_assert0(!h->setup_finished);
 
-    first_mb_in_slice = get_ue_golomb_long(&sl->gb);
+    sl->first_mb_addr = get_ue_golomb_long(&sl->gb);
 
-    if (first_mb_in_slice == 0) { // FIXME better field boundary detection
+    if (sl->first_mb_addr == 0) { // FIXME better field boundary detection
         if (h->current_slice) {
             if (h->setup_finished) {
                 av_log(h->avctx, AV_LOG_ERROR, "Too many fields\n");
@@ -1090,7 +1089,7 @@ static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)
     if (slice_type > 9) {
         av_log(h->avctx, AV_LOG_ERROR,
                "slice type %d too large at %d\n",
-               slice_type, first_mb_in_slice);
+               slice_type, sl->first_mb_addr);
         return AVERROR_INVALIDDATA;
     }
     if (slice_type > 4) {
@@ -1524,19 +1523,6 @@ static int h264_slice_header_parse(H264Context *h, H264SliceContext *sl)
         }
     }
 
-    av_assert1(h->mb_num == h->mb_width * h->mb_height);
-    if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
-        first_mb_in_slice >= h->mb_num) {
-        av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
-        return AVERROR_INVALIDDATA;
-    }
-    sl->resync_mb_x = sl->mb_x =  first_mb_in_slice % h->mb_width;
-    sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
-                                 FIELD_OR_MBAFF_PICTURE(h);
-    if (h->picture_structure == PICT_BOTTOM_FIELD)
-        sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
-    av_assert1(sl->mb_y < h->mb_height);
-
     if (h->picture_structure == PICT_FRAME) {
         h->curr_pic_num = h->poc.frame_num;
         h->max_pic_num  = 1 << sps->log2_max_frame_num;
@@ -1692,6 +1678,19 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
     if (ret) // can not be ret<0 because of SLICE_SKIPED, SLICE_SINGLETHREAD, ...
         return ret;
 
+    av_assert1(h->mb_num == h->mb_width * h->mb_height);
+    if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
+        sl->first_mb_addr >= h->mb_num) {
+        av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
+        return AVERROR_INVALIDDATA;
+    }
+    sl->resync_mb_x = sl->mb_x =  sl->first_mb_addr % h->mb_width;
+    sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) <<
+                                 FIELD_OR_MBAFF_PICTURE(h);
+    if (h->picture_structure == PICT_BOTTOM_FIELD)
+        sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
+    av_assert1(sl->mb_y < h->mb_height);
+
     if (!h->setup_finished)
         ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc,
                          h->ps.sps, &h->poc, h->picture_structure, h->nal_ref_idc);


======================================================================

diff --cc libavcodec/h264_slice.c
index 0e09ee2,5cb5844..e5fb64f
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@@ -1029,51 -909,19 +1028,51 @@@ static int h264_slice_header_parse(H264
      int ret;
      unsigned int slice_type, tmp, i;
      int last_pic_structure, last_pic_droppable;
 +    int must_reinit;
      int needs_reinit = 0;
      int field_pic_flag, bottom_field_flag;
 +    int first_slice = sl == h->slice_ctx && !h->current_slice;
      int frame_num, droppable, picture_structure;
 -    int mb_aff_frame = 0;
 +    int mb_aff_frame, last_mb_aff_frame;
 +
 +    if (first_slice)
 +        av_assert0(!h->setup_finished);
  
-     first_mb_in_slice = get_ue_golomb_long(&sl->gb);
 -    sl->first_mb_addr = get_ue_golomb(&sl->gb);
++    sl->first_mb_addr = get_ue_golomb_long(&sl->gb);
  
-     if (first_mb_in_slice == 0) { // FIXME better field boundary detection
+     if (sl->first_mb_addr == 0) { // FIXME better field boundary detection
 -        if (h->current_slice && h->cur_pic_ptr && FIELD_PICTURE(h)) {
 -            ff_h264_field_end(h, sl, 1);
 +        if (h->current_slice) {
 +            if (h->setup_finished) {
 +                av_log(h->avctx, AV_LOG_ERROR, "Too many fields\n");
 +                return AVERROR_INVALIDDATA;
 +            }
 +            if (h->max_contexts > 1) {
 +                if (!h->single_decode_warning) {
 +                    av_log(h->avctx, AV_LOG_WARNING, "Cannot decode multiple access units as slice threads\n");
 +                    h->single_decode_warning = 1;
 +                }
 +                h->max_contexts = 1;
 +                return SLICE_SINGLETHREAD;
 +            }
 +
 +            if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) {
 +                ret = ff_h264_field_end(h, h->slice_ctx, 1);
 +                h->current_slice = 0;
 +                if (ret < 0)
 +                    return ret;
 +            } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type  == NAL_IDR_SLICE) {
 +                av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n");
 +                ret = ff_h264_field_end(h, h->slice_ctx, 1);
 +                h->current_slice = 0;
 +                ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
 +                ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
 +                h->cur_pic_ptr = NULL;
 +                if (ret < 0)
 +                    return ret;
 +            } else
 +                return AVERROR_INVALIDDATA;
          }
  
 -        h->current_slice = 0;
          if (!h->first_field) {
              if (h->cur_pic_ptr && !h->droppable) {
                  ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
@@@ -1513,30 -1271,8 +1512,17 @@@
          } else {
              release_unused_pictures(h, 0);
          }
 +        /* Some macroblocks can be accessed before they're available in case
 +        * of lost slices, MBAFF or threading. */
 +        if (FIELD_PICTURE(h)) {
 +            for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++)
 +                memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table));
 +        } else {
 +            memset(h->slice_table, -1,
 +                (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table));
 +        }
      }
  
-     av_assert1(h->mb_num == h->mb_width * h->mb_height);
-     if (first_mb_in_slice << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
-         first_mb_in_slice >= h->mb_num) {
-         av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
-         return AVERROR_INVALIDDATA;
-     }
-     sl->resync_mb_x = sl->mb_x =  first_mb_in_slice % h->mb_width;
-     sl->resync_mb_y = sl->mb_y = (first_mb_in_slice / h->mb_width) <<
-                                  FIELD_OR_MBAFF_PICTURE(h);
-     if (h->picture_structure == PICT_BOTTOM_FIELD)
-         sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
-     av_assert1(sl->mb_y < h->mb_height);
- 
      if (h->picture_structure == PICT_FRAME) {
          h->curr_pic_num = h->poc.frame_num;
          h->max_pic_num  = 1 << sps->log2_max_frame_num;
@@@ -1689,9 -1425,22 +1675,22 @@@ int ff_h264_decode_slice_header(H264Con
      int i, j, ret = 0;
  
      ret = h264_slice_header_parse(h, sl);
 -    if (ret < 0)
 +    if (ret) // can not be ret<0 because of SLICE_SKIPED, SLICE_SINGLETHREAD, ...
          return ret;
  
 -    assert(h->mb_num == h->mb_width * h->mb_height);
++    av_assert1(h->mb_num == h->mb_width * h->mb_height);
+     if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num ||
+         sl->first_mb_addr >= h->mb_num) {
+         av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n");
+         return AVERROR_INVALIDDATA;
+     }
+     sl->resync_mb_x = sl->mb_x =  sl->first_mb_addr % h->mb_width;
+     sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) <<
+                                  FIELD_OR_MBAFF_PICTURE(h);
+     if (h->picture_structure == PICT_BOTTOM_FIELD)
+         sl->resync_mb_y = sl->mb_y = sl->mb_y + 1;
 -    assert(sl->mb_y < h->mb_height);
++    av_assert1(sl->mb_y < h->mb_height);
+ 
      if (!h->setup_finished)
          ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc,
                           h->ps.sps, &h->poc, h->picture_structure, h->nal_ref_idc);



More information about the ffmpeg-cvslog mailing list