When frames are missing, h264_field_start() moves prev_frame_num up to
the new frame_num in two steps: it shortens the gap to ref_frame_count
frames, then inserts one stand-in frame per remaining missing frame_num.
Either step can carry prev_frame_num across MaxFrameNum, but neither adds
MaxFrameNum to prev_frame_num_offset. ff_h264_init_poc() then sees
frame_num > prev_frame_num and adds no offset either, so with
pic_order_cnt_type 1 or 2 the next picture gets a POC below the pictures
already output. Every picture up to the next IDR is then dropped as out
of order ("no picture ooo").

libx264 with one reference frame and no B-frames writes
log2_max_frame_num 4 and pic_order_cnt_type 2. With a 30-frame GOP,
losing the picture whose frame_num wraps to 0 (picture 16 of the GOP)
loses the remaining 13 pictures of that GOP.

Add MaxFrameNum to prev_frame_num_offset when the shortening jumps over
the wrap and when a stand-in frame takes it. When the new frame_num is
itself 0, neither step wraps and ff_h264_init_poc() counts the wrap as
before.

The new FATE tests drop picture 16 (frame_num 0), and pictures 16 and
17, of CAWP1_TOSHIBA_E.264, which has log2_max_frame_num 4 and
pic_order_cnt_type 2. Without this change the decoder outputs 75 of the 89 and 
75 of the
88 remaining pictures; with it, all of them.

Signed-off-by: Omar Ramadan <[email protected]>
---
 libavcodec/h264_slice.c                  |  7 ++
 tests/fate/h264.mak                      |  6 ++
 tests/ref/fate/h264-frame-num-gap-wrap   | 94 ++++++++++++++++++++++++
 tests/ref/fate/h264-frame-num-gap-wrap-2 | 93 +++++++++++++++++++++++
 4 files changed, 200 insertions(+)
 create mode 100644 tests/ref/fate/h264-frame-num-gap-wrap
 create mode 100644 tests/ref/fate/h264-frame-num-gap-wrap-2

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 1e28f2bdfa..0ff65897bf 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1470,6 +1470,9 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
             unwrap_prev_frame_num = (h->poc.frame_num - sps->ref_frame_count) 
- 1;
             if (unwrap_prev_frame_num < 0)
                 unwrap_prev_frame_num += max_frame_num;
+            else if (h->poc.prev_frame_num > h->poc.frame_num)
+                /* The skipped frames include the frame_num wrap. */
+                h->poc.prev_frame_num_offset += max_frame_num;
 
             h->poc.prev_frame_num = unwrap_prev_frame_num;
         }
@@ -1547,6 +1550,10 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
         }
 
         h->poc.prev_frame_num++;
+        /* This frame takes the frame_num wrap, which ff_h264_init_poc()
+         * cannot see in the next real picture. */
+        if (h->poc.prev_frame_num == 1 << sps->log2_max_frame_num)
+            h->poc.prev_frame_num_offset += 1 << sps->log2_max_frame_num;
         h->poc.prev_frame_num        %= 1 << sps->log2_max_frame_num;
         h->cur_pic_ptr->frame_num = h->poc.prev_frame_num;
         h->cur_pic_ptr->invalid_gap = !sps->gaps_in_frame_num_allowed_flag;
diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index 325d1733f5..2e91df14c0 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -524,6 +524,12 @@ fate-h264-bsf-redundant-pps-annexb: CMD = transcode h264 
$(TARGET_SAMPLES)/h264-
 fate-h264-bsf-redundant-pps-side-data: CMD = transcode mov 
$(TARGET_SAMPLES)/h264/thezerotheorem-cut.mp4 nut "-map 0:v -c copy -bsf 
h264_redundant_pps -syncpoints none -strict experimental" "-c copy"
 fate-h264-bsf-redundant-pps-side-data2: CMD = transcode mov 
$(TARGET_SAMPLES)/h264/extradata-reload-multi-stsd.mov nut "-map 0:v -c copy 
-bsf h264_redundant_pps -syncpoints none -strict experimental"
 
+# CAWP1_TOSHIBA_E has log2_max_frame_num 4 and pic_order_cnt_type 2: dropping
+# picture 16 (frame_num 0), or 16 and 17, puts the frame_num wrap inside a gap
+fate-h264-frame-num-gap-wrap:   CMD = framecrc -bsf:v "noise=drop=eq(n\,16)" 
-i $(TARGET_SAMPLES)/h264-conformance/CAWP1_TOSHIBA_E.264
+fate-h264-frame-num-gap-wrap-2: CMD = framecrc -bsf:v 
"noise=drop=eq(n\,16)+eq(n\,17)" -i 
$(TARGET_SAMPLES)/h264-conformance/CAWP1_TOSHIBA_E.264
+FATE_H264-$(call FRAMECRC, H264, H264, H264_PARSER NOISE_BSF) += 
fate-h264-frame-num-gap-wrap fate-h264-frame-num-gap-wrap-2
+
 fate-h264-encparams: CMD = venc_data 
$(TARGET_SAMPLES)/h264-conformance/FRext/FRExt_MMCO4_Sony_B.264 0 1
 FATE_SAMPLES_DUMP_DATA += fate-h264-encparams
 
diff --git a/tests/ref/fate/h264-frame-num-gap-wrap 
b/tests/ref/fate/h264-frame-num-gap-wrap
new file mode 100644
index 0000000000..1e6663398d
--- /dev/null
+++ b/tests/ref/fate/h264-frame-num-gap-wrap
@@ -0,0 +1,94 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0xabf9ae05
+0,          1,          1,        1,   152064, 0x20418b16
+0,          2,          2,        1,   152064, 0xc26760ae
+0,          3,          3,        1,   152064, 0x7ed0c861
+0,          4,          4,        1,   152064, 0x1a13d207
+0,          5,          5,        1,   152064, 0x700bdb09
+0,          6,          6,        1,   152064, 0x7fa6476e
+0,          7,          7,        1,   152064, 0x951158c6
+0,          8,          8,        1,   152064, 0x263a2dfc
+0,          9,          9,        1,   152064, 0xa25c5371
+0,         10,         10,        1,   152064, 0xd67bd5c5
+0,         11,         11,        1,   152064, 0x73e6d7c0
+0,         12,         12,        1,   152064, 0x509967e4
+0,         13,         13,        1,   152064, 0x27574b8f
+0,         14,         14,        1,   152064, 0xa701d36f
+0,         15,         15,        1,   152064, 0x3d457728
+0,         16,         16,        1,   152064, 0x33b3542b
+0,         17,         17,        1,   152064, 0x5635d3fa
+0,         18,         18,        1,   152064, 0x51dbc0bd
+0,         19,         19,        1,   152064, 0xa2287df1
+0,         20,         20,        1,   152064, 0xc4b22092
+0,         21,         21,        1,   152064, 0xfd05e083
+0,         22,         22,        1,   152064, 0xfadce02d
+0,         23,         23,        1,   152064, 0xf67cc1da
+0,         24,         24,        1,   152064, 0x4e7bc654
+0,         25,         25,        1,   152064, 0x5b686f11
+0,         26,         26,        1,   152064, 0xb8e33dc8
+0,         27,         27,        1,   152064, 0x0ff224ca
+0,         28,         28,        1,   152064, 0xcd98c152
+0,         29,         29,        1,   152064, 0x4fdfb595
+0,         30,         30,        1,   152064, 0xb1b7f4fc
+0,         31,         31,        1,   152064, 0x666ccd6a
+0,         32,         32,        1,   152064, 0x80e9c1a3
+0,         33,         33,        1,   152064, 0x304b9be3
+0,         34,         34,        1,   152064, 0x9741fb13
+0,         35,         35,        1,   152064, 0x5e016501
+0,         36,         36,        1,   152064, 0x50dd4139
+0,         37,         37,        1,   152064, 0x9a4ef972
+0,         38,         38,        1,   152064, 0x03b7da4e
+0,         39,         39,        1,   152064, 0x17fd7d8a
+0,         40,         40,        1,   152064, 0xc0137bb0
+0,         41,         41,        1,   152064, 0xaf167d40
+0,         42,         42,        1,   152064, 0xde191051
+0,         43,         43,        1,   152064, 0x1cdcee05
+0,         44,         44,        1,   152064, 0xa8d1b139
+0,         45,         45,        1,   152064, 0xade6bf62
+0,         46,         46,        1,   152064, 0x4515a552
+0,         47,         47,        1,   152064, 0xb05036fe
+0,         48,         48,        1,   152064, 0xfa500b17
+0,         49,         49,        1,   152064, 0x512dec06
+0,         50,         50,        1,   152064, 0x0e77ff69
+0,         51,         51,        1,   152064, 0x06f7b2cd
+0,         52,         52,        1,   152064, 0x9bc99b67
+0,         53,         53,        1,   152064, 0x6b68301b
+0,         54,         54,        1,   152064, 0xe31321ba
+0,         55,         55,        1,   152064, 0x9ad0192e
+0,         56,         56,        1,   152064, 0xcc14d7c8
+0,         57,         57,        1,   152064, 0xf6ab91ec
+0,         58,         58,        1,   152064, 0xf76afbce
+0,         59,         59,        1,   152064, 0xb7d7f1dc
+0,         60,         60,        1,   152064, 0xca95e688
+0,         61,         61,        1,   152064, 0xc36bb8ac
+0,         62,         62,        1,   152064, 0xc1c06a2e
+0,         63,         63,        1,   152064, 0xf2a08f2a
+0,         64,         64,        1,   152064, 0xb81013d2
+0,         65,         65,        1,   152064, 0xf30cee41
+0,         66,         66,        1,   152064, 0xad85c0d6
+0,         67,         67,        1,   152064, 0x087b7807
+0,         68,         68,        1,   152064, 0x178c39f0
+0,         69,         69,        1,   152064, 0x6e0e3e66
+0,         70,         70,        1,   152064, 0x9a020bcf
+0,         71,         71,        1,   152064, 0xc33d4749
+0,         72,         72,        1,   152064, 0x6370dbad
+0,         73,         73,        1,   152064, 0x928cbe47
+0,         74,         74,        1,   152064, 0xb8b036cc
+0,         75,         75,        1,   152064, 0x79d92c37
+0,         76,         76,        1,   152064, 0xc4cf0d8f
+0,         77,         77,        1,   152064, 0xfe706c76
+0,         78,         78,        1,   152064, 0x6a37de81
+0,         79,         79,        1,   152064, 0x659eb2c1
+0,         80,         80,        1,   152064, 0x0630855f
+0,         81,         81,        1,   152064, 0xfa964f67
+0,         82,         82,        1,   152064, 0xc5a1ff95
+0,         83,         83,        1,   152064, 0xa131b89f
+0,         84,         84,        1,   152064, 0x73007c16
+0,         85,         85,        1,   152064, 0x4d237a3b
+0,         86,         86,        1,   152064, 0xe68f44be
+0,         87,         87,        1,   152064, 0x065f0be3
+0,         88,         88,        1,   152064, 0x39cab454
diff --git a/tests/ref/fate/h264-frame-num-gap-wrap-2 
b/tests/ref/fate/h264-frame-num-gap-wrap-2
new file mode 100644
index 0000000000..217dff932d
--- /dev/null
+++ b/tests/ref/fate/h264-frame-num-gap-wrap-2
@@ -0,0 +1,93 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 352x288
+#sar 0: 0/1
+0,          0,          0,        1,   152064, 0xabf9ae05
+0,          1,          1,        1,   152064, 0x20418b16
+0,          2,          2,        1,   152064, 0xc26760ae
+0,          3,          3,        1,   152064, 0x7ed0c861
+0,          4,          4,        1,   152064, 0x1a13d207
+0,          5,          5,        1,   152064, 0x700bdb09
+0,          6,          6,        1,   152064, 0x7fa6476e
+0,          7,          7,        1,   152064, 0x951158c6
+0,          8,          8,        1,   152064, 0x263a2dfc
+0,          9,          9,        1,   152064, 0xa25c5371
+0,         10,         10,        1,   152064, 0xd67bd5c5
+0,         11,         11,        1,   152064, 0x73e6d7c0
+0,         12,         12,        1,   152064, 0x509967e4
+0,         13,         13,        1,   152064, 0x27574b8f
+0,         14,         14,        1,   152064, 0xa701d36f
+0,         15,         15,        1,   152064, 0x3d457728
+0,         16,         16,        1,   152064, 0x5635d3fa
+0,         17,         17,        1,   152064, 0x51dbc0bd
+0,         18,         18,        1,   152064, 0xa2287df1
+0,         19,         19,        1,   152064, 0xefd7f1db
+0,         20,         20,        1,   152064, 0xfd05e083
+0,         21,         21,        1,   152064, 0xfadce02d
+0,         22,         22,        1,   152064, 0xf67cc1da
+0,         23,         23,        1,   152064, 0x4e7bc654
+0,         24,         24,        1,   152064, 0x5b686f11
+0,         25,         25,        1,   152064, 0xb8e33dc8
+0,         26,         26,        1,   152064, 0x0ff224ca
+0,         27,         27,        1,   152064, 0xcd98c152
+0,         28,         28,        1,   152064, 0x4fdfb595
+0,         29,         29,        1,   152064, 0xb1b7f4fc
+0,         30,         30,        1,   152064, 0x666ccd6a
+0,         31,         31,        1,   152064, 0x80e9c1a3
+0,         32,         32,        1,   152064, 0x304b9be3
+0,         33,         33,        1,   152064, 0x9741fb13
+0,         34,         34,        1,   152064, 0x5e016501
+0,         35,         35,        1,   152064, 0x50dd4139
+0,         36,         36,        1,   152064, 0x9a4ef972
+0,         37,         37,        1,   152064, 0x03b7da4e
+0,         38,         38,        1,   152064, 0x17fd7d8a
+0,         39,         39,        1,   152064, 0xc0137bb0
+0,         40,         40,        1,   152064, 0xaf167d40
+0,         41,         41,        1,   152064, 0xde191051
+0,         42,         42,        1,   152064, 0x1cdcee05
+0,         43,         43,        1,   152064, 0xa8d1b139
+0,         44,         44,        1,   152064, 0xade6bf62
+0,         45,         45,        1,   152064, 0x4515a552
+0,         46,         46,        1,   152064, 0xb05036fe
+0,         47,         47,        1,   152064, 0xfa500b17
+0,         48,         48,        1,   152064, 0x512dec06
+0,         49,         49,        1,   152064, 0x0e77ff69
+0,         50,         50,        1,   152064, 0x06f7b2cd
+0,         51,         51,        1,   152064, 0x9bc99b67
+0,         52,         52,        1,   152064, 0x6b68301b
+0,         53,         53,        1,   152064, 0xe31321ba
+0,         54,         54,        1,   152064, 0x9ad0192e
+0,         55,         55,        1,   152064, 0xcc14d7c8
+0,         56,         56,        1,   152064, 0xf6ab91ec
+0,         57,         57,        1,   152064, 0xf76afbce
+0,         58,         58,        1,   152064, 0xb7d7f1dc
+0,         59,         59,        1,   152064, 0xca95e688
+0,         60,         60,        1,   152064, 0xc36bb8ac
+0,         61,         61,        1,   152064, 0xc1c06a2e
+0,         62,         62,        1,   152064, 0xf2a08f2a
+0,         63,         63,        1,   152064, 0xb81013d2
+0,         64,         64,        1,   152064, 0xf30cee41
+0,         65,         65,        1,   152064, 0xad85c0d6
+0,         66,         66,        1,   152064, 0x087b7807
+0,         67,         67,        1,   152064, 0x178c39f0
+0,         68,         68,        1,   152064, 0x6e0e3e66
+0,         69,         69,        1,   152064, 0x9a020bcf
+0,         70,         70,        1,   152064, 0xc33d4749
+0,         71,         71,        1,   152064, 0x6370dbad
+0,         72,         72,        1,   152064, 0x928cbe47
+0,         73,         73,        1,   152064, 0xb8b036cc
+0,         74,         74,        1,   152064, 0x79d92c37
+0,         75,         75,        1,   152064, 0xc4cf0d8f
+0,         76,         76,        1,   152064, 0xfe706c76
+0,         77,         77,        1,   152064, 0x6a37de81
+0,         78,         78,        1,   152064, 0x659eb2c1
+0,         79,         79,        1,   152064, 0x0630855f
+0,         80,         80,        1,   152064, 0xfa964f67
+0,         81,         81,        1,   152064, 0xc5a1ff95
+0,         82,         82,        1,   152064, 0xa131b89f
+0,         83,         83,        1,   152064, 0x73007c16
+0,         84,         84,        1,   152064, 0x4d237a3b
+0,         85,         85,        1,   152064, 0xe68f44be
+0,         86,         86,        1,   152064, 0x065f0be3
+0,         87,         87,        1,   152064, 0x39cab454
-- 
2.43.0


_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to