1 From fcdf7736ca43b9847b22100042e19bf64005ee39 Mon Sep 17 00:00:00 2001
2 From: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
3 Date: Wed, 25 Jun 2014 11:06:41 +0200
4 Subject: [PATCH 5/8] h264parse: introduce new state tracking variables.
6 Improve parser state tracking by introducing new flags reflecting
7 it: "got-sps", "got-pps" and "got-slice". This is an addition for
10 Older have_sps and have_pps variables are kept because they have
11 a different meaning. i.e. they are used for deciding on when to
12 submit updated caps or not, and rather mean "have new SPS/PPS to
15 Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
17 gst/vaapi/gsth264parse.c | 30 +++++++++++++++++++++++++++++-
18 gst/vaapi/gsth264parse.h | 3 +++
19 2 files changed, 32 insertions(+), 1 deletion(-)
21 diff --git a/gst/vaapi/gsth264parse.c b/gst/vaapi/gsth264parse.c
22 index 4800c2b..1542a82 100644
23 --- a/gst/vaapi/gsth264parse.c
24 +++ b/gst/vaapi/gsth264parse.c
25 @@ -61,6 +61,22 @@ enum
26 GST_H264_PARSE_ALIGN_AU
31 + GST_H264_PARSE_STATE_GOT_SPS = 1 << 0,
32 + GST_H264_PARSE_STATE_GOT_PPS = 1 << 1,
33 + GST_H264_PARSE_STATE_GOT_SLICE = 1 << 2,
35 + GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS = (GST_H264_PARSE_STATE_GOT_SPS |
36 + GST_H264_PARSE_STATE_GOT_PPS),
37 + GST_H264_PARSE_STATE_VALID_PICTURE =
38 + (GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS |
39 + GST_H264_PARSE_STATE_GOT_SLICE)
42 +#define GST_H264_PARSE_STATE_VALID(parse, expected_state) \
43 + (((parse)->state & (expected_state)) == (expected_state))
45 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
48 @@ -535,6 +551,9 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
51 case GST_H264_NAL_SPS:
52 + /* reset state, everything else is obsolete */
53 + h264parse->state = 0;
55 pres = gst_h264_parser_parse_sps (nalparser, nalu, &sps, TRUE);
56 /* arranged for a fallback sps.id, so use that one and only warn */
57 if (pres != GST_H264_PARSER_OK)
58 @@ -553,8 +572,11 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
61 gst_h264_parser_store_nal (h264parse, sps.id, nal_type, nalu);
62 + h264parse->state |= GST_H264_PARSE_STATE_GOT_SPS;
64 case GST_H264_NAL_PPS:
65 + h264parse->state &= GST_H264_PARSE_STATE_GOT_SPS;
67 pres = gst_h264_parser_parse_pps (nalparser, nalu, &pps);
68 /* arranged for a fallback pps.id, so use that one and only warn */
69 if (pres != GST_H264_PARSER_OK)
70 @@ -576,6 +598,7 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
73 gst_h264_parser_store_nal (h264parse, pps.id, nal_type, nalu);
74 + h264parse->state |= GST_H264_PARSE_STATE_GOT_PPS;
76 case GST_H264_NAL_SEI:
77 gst_h264_parse_process_sei (h264parse, nalu);
78 @@ -595,6 +618,8 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
79 case GST_H264_NAL_SLICE_DPB:
80 case GST_H264_NAL_SLICE_DPC:
81 case GST_H264_NAL_SLICE_IDR:
82 + h264parse->state &= GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS;
84 /* don't need to parse the whole slice (header) here */
85 if (*(nalu->data + nalu->offset + 1) & 0x80) {
86 /* means first_mb_in_slice == 0 */
87 @@ -615,6 +640,7 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
88 if (GST_H264_IS_I_SLICE (&slice) || GST_H264_IS_SI_SLICE (&slice))
89 h264parse->keyframe |= TRUE;
91 + h264parse->state |= GST_H264_PARSE_STATE_GOT_SLICE;
92 h264parse->field_pic_flag = slice.field_pic_flag;
95 @@ -964,7 +990,8 @@ gst_h264_parse_handle_frame (GstBaseParse * parse,
97 if (nalu.type == GST_H264_NAL_SPS ||
98 nalu.type == GST_H264_NAL_PPS ||
99 - (h264parse->have_sps && h264parse->have_pps)) {
100 + GST_H264_PARSE_STATE_VALID (h264parse,
101 + GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS)) {
102 gst_h264_parse_process_nal (h264parse, &nalu);
104 GST_WARNING_OBJECT (h264parse,
105 @@ -1761,6 +1788,7 @@ gst_h264_parse_pre_push_frame (GstBaseParse * parse, GstBaseParseFrame * frame)
106 h264parse->push_codec = FALSE;
107 h264parse->have_sps = FALSE;
108 h264parse->have_pps = FALSE;
109 + h264parse->state &= GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS;
113 diff --git a/gst/vaapi/gsth264parse.h b/gst/vaapi/gsth264parse.h
114 index 4c3fdd4..c9d188b 100644
115 --- a/gst/vaapi/gsth264parse.h
116 +++ b/gst/vaapi/gsth264parse.h
117 @@ -69,12 +69,15 @@ struct _GstH264Parse
120 GstH264NalParser *nalparser;
126 GstClockTime last_report;
128 + /* The following variables have a meaning in context of "have
129 + * SPS/PPS to push downstream", e.g. to update caps */