h264parse: introduce new state tracking variables.
[platform/upstream/gstreamer-vaapi.git] / patches / videoparsers / 0003-h264parse-add-initial-support-for-MVC-NAL-units.patch
1 From 3ef58fae7a578f72c4607b57434ed54a0ee9ee1d Mon Sep 17 00:00:00 2001
2 From: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
3 Date: Tue, 19 Mar 2013 14:23:00 +0200
4 Subject: [PATCH 3/3] h264parse: add initial support for MVC NAL units.
5
6 Initial support for MVC NAL units. It is only needed to propagate the
7 complete set of NAL units downstream at this time.
8
9 https://bugzilla.gnome.org/show_bug.cgi?id=696135
10
11 Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
12 Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
13 ---
14  gst/vaapi/gsth264parse.c |   20 ++++++++++++++------
15  1 file changed, 14 insertions(+), 6 deletions(-)
16
17 diff --git a/gst/vaapi/gsth264parse.c b/gst/vaapi/gsth264parse.c
18 index 7c970ee..e9b9481 100644
19 --- a/gst/vaapi/gsth264parse.c
20 +++ b/gst/vaapi/gsth264parse.c
21 @@ -415,7 +415,7 @@ gst_h264_parser_store_nal (GstH264Parse * h264parse, guint id,
22    GstBuffer *buf, **store;
23    guint size = nalu->size, store_size;
24  
25 -  if (naltype == GST_H264_NAL_SPS) {
26 +  if (naltype == GST_H264_NAL_SPS || naltype == GST_H264_NAL_SUBSET_SPS) {
27      store_size = GST_H264_MAX_SPS_COUNT;
28      store = h264parse->sps_nals;
29      GST_DEBUG_OBJECT (h264parse, "storing sps %u", id);
30 @@ -551,10 +551,16 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
31        nal_type, _nal_name (nal_type), nalu->size);
32  
33    switch (nal_type) {
34 +    case GST_H264_NAL_SUBSET_SPS:
35 +      if (!GST_H264_PARSE_STATE_VALID (h264parse, GST_H264_PARSE_STATE_GOT_SPS))
36 +        return FALSE;
37 +      goto process_sps;
38 +
39      case GST_H264_NAL_SPS:
40        /* reset state, everything else is obsolete */
41        h264parse->state = 0;
42  
43 +    process_sps:
44        pres = gst_h264_parser_parse_sps (nalparser, nalu, &sps, TRUE);
45        /* arranged for a fallback sps.id, so use that one and only warn */
46        if (pres != GST_H264_PARSER_OK) {
47 @@ -631,6 +637,7 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
48      case GST_H264_NAL_SLICE_DPB:
49      case GST_H264_NAL_SLICE_DPC:
50      case GST_H264_NAL_SLICE_IDR:
51 +    case GST_H264_NAL_SLICE_EXT:
52        h264parse->state &= GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS;
53  
54        /* don't need to parse the whole slice (header) here */
55 @@ -638,13 +645,15 @@ gst_h264_parse_process_nal (GstH264Parse * h264parse, GstH264NalUnit * nalu)
56          return FALSE;
57  
58        /* don't need to parse the whole slice (header) here */
59 -      if (*(nalu->data + nalu->offset + 1) & 0x80) {
60 +      if (*(nalu->data + nalu->offset + nalu->header_bytes) & 0x80) {
61          /* means first_mb_in_slice == 0 */
62          /* real frame data */
63          GST_DEBUG_OBJECT (h264parse, "first_mb_in_slice = 0");
64          h264parse->frame_start = TRUE;
65        }
66        GST_DEBUG_OBJECT (h264parse, "frame start: %i", h264parse->frame_start);
67 +      if (nal_type == GST_H264_NAL_SLICE_EXT && !GST_H264_IS_MVC_NALU (nalu))
68 +        break;
69        {
70          GstH264SliceHdr slice;
71  
72 @@ -677,7 +681,8 @@ gst_h264_parse_collect_nal (GstH264Parse * h264parse, const guint8 * data,
73    /* coded slice NAL starts a picture,
74     * i.e. other types become aggregated in front of it */
75    h264parse->picture_start |= (nal_type == GST_H264_NAL_SLICE ||
76 -      nal_type == GST_H264_NAL_SLICE_DPA || nal_type == GST_H264_NAL_SLICE_IDR);
77 +      nal_type == GST_H264_NAL_SLICE_DPA || nal_type == GST_H264_NAL_SLICE_IDR
78 +      || nal_type == GST_H264_NAL_SLICE_EXT);
79  
80    /* consider a coded slices (IDR or not) to start a picture,
81     * (so ending the previous one) if first_mb_in_slice == 0
82 @@ -687,16 +692,18 @@ gst_h264_parse_collect_nal (GstH264Parse * h264parse, const guint8 * data,
83     * and also works with broken frame_num in NAL
84     * (where spec-wise would fail) */
85    nal_type = nnalu.type;
86 -  complete = h264parse->picture_start && (nal_type >= GST_H264_NAL_SEI &&
87 -      nal_type <= GST_H264_NAL_AU_DELIMITER);
88 +  complete = h264parse->picture_start && ((nal_type >= GST_H264_NAL_SEI &&
89 +          nal_type <= GST_H264_NAL_AU_DELIMITER) ||
90 +      (nal_type >= 14 && nal_type <= 18));
91  
92    GST_LOG_OBJECT (h264parse, "next nal type: %d %s", nal_type,
93        _nal_name (nal_type));
94    complete |= h264parse->picture_start && (nal_type == GST_H264_NAL_SLICE
95        || nal_type == GST_H264_NAL_SLICE_DPA
96 +      || nal_type == GST_H264_NAL_SLICE_EXT
97        || nal_type == GST_H264_NAL_SLICE_IDR) &&
98        /* first_mb_in_slice == 0 considered start of frame */
99 -      (nnalu.data[nnalu.offset + 1] & 0x80);
100 +      (nnalu.data[nnalu.offset + nnalu.header_bytes] & 0x80);
101  
102    GST_LOG_OBJECT (h264parse, "au complete: %d", complete);
103  
104 @@ -960,6 +967,7 @@ gst_h264_parse_handle_frame (GstBaseParse * parse,
105      }
106  
107      if (nalu.type == GST_H264_NAL_SPS ||
108 +        nalu.type == GST_H264_NAL_SUBSET_SPS ||
109          nalu.type == GST_H264_NAL_PPS ||
110          (h264parse->have_sps && h264parse->have_pps)) {
111        gst_h264_parse_process_nal (h264parse, &nalu);
112 -- 
113 1.7.9.5
114