summaryrefslogtreecommitdiffstats
path: root/contrib/ffmpeg/A01-h264-recovery-point.patch
blob: 8688c021c9911ad3b5be9f2f5505663d4c904f50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 848d6a2..5a12fdb 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -2164,6 +2164,7 @@ static void flush_dpb(AVCodecContext *avctx)
 
     flush_change(h);
     ff_mpeg_flush(avctx);
+    h->recovery_frame= -1;
 }
 
 static int init_poc(H264Context *h)
@@ -3992,9 +3993,18 @@ again:
                 if ((err = decode_slice_header(hx, h)))
                     break;
 
+                if (h->sei_recovery_frame_cnt >= 0 && h->recovery_frame < 0) {
+                    h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %
+                                        (1 << h->sps.log2_max_frame_num);
+                }
+
                 s->current_picture_ptr->f.key_frame |=
-                    (hx->nal_unit_type == NAL_IDR_SLICE) ||
-                    (h->sei_recovery_frame_cnt >= 0);
+                        (hx->nal_unit_type == NAL_IDR_SLICE);
+
+                if (h->recovery_frame == h->frame_num) {
+                    s->current_picture_ptr->f.key_frame |= 1;
+                    h->recovery_frame = -1;
+                }
 
                 if (h->current_slice == 1) {
                     if (!(s->flags2 & CODEC_FLAG2_CHUNKS))
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 898ebf7..42aaa6f 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -568,6 +568,13 @@ typedef struct H264Context {
      * frames.
      */
     int sei_recovery_frame_cnt;
+    /**
+     * recovery_frame is the frame_num at which the next frame should
+     * be fully constructed.
+     *
+     * Set to -1 when not expecting a recovery point.
+     */
+    int recovery_frame;
 
     int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
     int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 2e5fb65..ea33a18 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -38,6 +38,7 @@ static const uint8_t sei_num_clock_ts_table[9]={
 };
 
 void ff_h264_reset_sei(H264Context *h) {
+    h->recovery_frame               = -1;
     h->sei_recovery_frame_cnt       = -1;
     h->sei_dpb_output_delay         =  0;
     h->sei_cpb_removal_delay        = -1;