---
 libavcodec/h264.c |  173 +++++++++++++++++++++++++++--------------------------
 1 files changed, 87 insertions(+), 86 deletions(-)
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 7c9714f..b7a7543 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2493,6 +2493,90 @@ static int frame_start(H264Context *h){
     return 0;
 }
 
+/**
+  * Run setup operations that must be run after slice header decoding.
+  * This includes finding the next displayed frame.
+  *
+  * @param h h264 master context
+  */
+static void decode_postinit(H264Context *h){
+    MpegEncContext * const s = &h->s;
+    Picture *out = s->current_picture_ptr;
+    Picture *cur = s->current_picture_ptr;
+    int i, pics, cross_idr, out_of_order, out_idx;
+
+    s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
+    s->current_picture_ptr->pict_type= s->pict_type;
+
+    // Don't do anything if it's the first field or we've already been called.
+    // FIXME the first field should call ff_report_frame_setup_done() even if it skips the rest
+    if (h->next_output_pic || cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) return;
+
+    cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE;
+    /* Derive top_field_first from field pocs. */
+    cur->top_field_first = cur->field_poc[0] < cur->field_poc[1];
+
+    //FIXME do something with unavailable reference frames
+
+    /* Sort B-frames into display order */
+
+    if(h->sps.bitstream_restriction_flag
+       && s->avctx->has_b_frames < h->sps.num_reorder_frames){
+        s->avctx->has_b_frames = h->sps.num_reorder_frames;
+        s->low_delay = 0;
+    }
+
+    if(   s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT
+       && !h->sps.bitstream_restriction_flag){
+        s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT;
+        s->low_delay= 0;
+    }
+
+    pics = 0;
+    while(h->delayed_pic[pics]) pics++;
+
+    assert(pics <= MAX_DELAYED_PIC_COUNT);
+
+    h->delayed_pic[pics++] = cur;
+    if(cur->reference == 0)
+        cur->reference = DELAYED_PIC_REF;
+
+    out = h->delayed_pic[0];
+    out_idx = 0;
+    for(i=1; h->delayed_pic[i] && h->delayed_pic[i]->poc; i++)
+        if(h->delayed_pic[i]->poc < out->poc){
+            out = h->delayed_pic[i];
+            out_idx = i;
+        }
+    cross_idr = !h->delayed_pic[0]->poc || !!h->delayed_pic[i];
+
+    out_of_order = !cross_idr && out->poc < h->outputed_poc;
+
+    if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
+        { }
+    else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT)
+       || (s->low_delay &&
+        ((!cross_idr && out->poc > h->outputed_poc + 2)
+         || cur->pict_type == FF_B_TYPE)))
+    {
+        s->low_delay = 0;
+        s->avctx->has_b_frames++;
+    }
+
+    if(out_of_order || pics > s->avctx->has_b_frames){
+        out->reference &= ~DELAYED_PIC_REF;
+        for(i=out_idx; h->delayed_pic[i]; i++)
+            h->delayed_pic[i] = h->delayed_pic[i+1];
+    }
+    if(!out_of_order && pics > s->avctx->has_b_frames){
+        h->next_output_pic = out;
+    }else{
+        av_log(s->avctx, AV_LOG_DEBUG, "no picture\n");
+    }
+
+    ff_report_frame_setup_done(s->avctx);
+}
+
 static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple){
     MpegEncContext * const s = &h->s;
     int i;
@@ -4231,6 +4315,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){
     h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16;
     h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;
 
+    if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && h->slice_num==1)
+        decode_postinit(h);
+
     if(s->avctx->debug&FF_DEBUG_PICT_INFO){
         av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n",
                h->slice_num,
@@ -6815,90 +6902,6 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8
 }
 
 /**
-  * Run setup operations that must be run after slice header decoding.
-  * This includes finding the next displayed frame.
-  *
-  * @param h h264 master context
-  */
-static void decode_postinit(H264Context *h){
-    MpegEncContext * const s = &h->s;
-    Picture *out = s->current_picture_ptr;
-    Picture *cur = s->current_picture_ptr;
-    int i, pics, cross_idr, out_of_order, out_idx;
-
-    s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264;
-    s->current_picture_ptr->pict_type= s->pict_type;
-
-    // Don't do anything if it's the first field or we've already been called.
-    // FIXME the first field should call ff_report_frame_setup_done() even if it skips the rest
-    if (h->next_output_pic || cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) return;
-
-    cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE;
-    /* Derive top_field_first from field pocs. */
-    cur->top_field_first = cur->field_poc[0] < cur->field_poc[1];
-
-    //FIXME do something with unavailable reference frames
-
-    /* Sort B-frames into display order */
-
-    if(h->sps.bitstream_restriction_flag
-       && s->avctx->has_b_frames < h->sps.num_reorder_frames){
-        s->avctx->has_b_frames = h->sps.num_reorder_frames;
-        s->low_delay = 0;
-    }
-
-    if(   s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT
-       && !h->sps.bitstream_restriction_flag){
-        s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT;
-        s->low_delay= 0;
-    }
-
-    pics = 0;
-    while(h->delayed_pic[pics]) pics++;
-
-    assert(pics <= MAX_DELAYED_PIC_COUNT);
-
-    h->delayed_pic[pics++] = cur;
-    if(cur->reference == 0)
-        cur->reference = DELAYED_PIC_REF;
-
-    out = h->delayed_pic[0];
-    out_idx = 0;
-    for(i=1; h->delayed_pic[i] && h->delayed_pic[i]->poc; i++)
-        if(h->delayed_pic[i]->poc < out->poc){
-            out = h->delayed_pic[i];
-            out_idx = i;
-        }
-    cross_idr = !h->delayed_pic[0]->poc || !!h->delayed_pic[i];
-
-    out_of_order = !cross_idr && out->poc < h->outputed_poc;
-
-    if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames)
-        { }
-    else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT)
-       || (s->low_delay &&
-        ((!cross_idr && out->poc > h->outputed_poc + 2)
-         || cur->pict_type == FF_B_TYPE)))
-    {
-        s->low_delay = 0;
-        s->avctx->has_b_frames++;
-    }
-
-    if(out_of_order || pics > s->avctx->has_b_frames){
-        out->reference &= ~DELAYED_PIC_REF;
-        for(i=out_idx; h->delayed_pic[i]; i++)
-            h->delayed_pic[i] = h->delayed_pic[i+1];
-    }
-    if(!out_of_order && pics > s->avctx->has_b_frames){
-        h->next_output_pic = out;
-    }else{
-        av_log(s->avctx, AV_LOG_DEBUG, "no picture\n");
-    }
-
-    ff_report_frame_setup_done(s->avctx);
-}
-
-/**
  * Report the last pixel row fully decoded.
  *
  * Lower rows than (last row of last MB - 3) might be changed in deblocking.
@@ -7577,8 +7580,6 @@ static void execute_decode_slices(H264Context *h, int context_count){
     H264Context *hx;
     int i;
 
-    if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) decode_postinit(h);
-
     if(context_count == 1) {
         decode_slice(avctx, h);
     } else {
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to