h264parse: fix collection of access units to preserve config headers.
[platform/upstream/gstreamer-vaapi.git] / patches / videoparsers / 0007-h264parse-fix-collection-of-access-units-to-preserve.patch
1 From def7c6b2a0fcd08969940349e458248dd0c7b3da Mon Sep 17 00:00:00 2001
2 From: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
3 Date: Thu, 26 Jun 2014 09:44:26 +0200
4 Subject: [PATCH 7/8] h264parse: fix collection of access units to preserve
5  config headers.
6
7 Always use a GstAdapter when collecting access units (alignment="au")
8 in either byte-stream or avcC format. This is required to properly
9 preserve config headers like SPS and PPS when invalid or broken NAL
10 units are subsequently parsed.
11
12 More precisely, this fixes scenario like:
13 <SPS> <PPS> <invalid-NAL> <slice>
14
15 where we used to reset the output frame buffer when an invalid or
16 broken NAL is parsed, i.e. SPS and PPS NAL units were lost, thus
17 preventing the next slice unit to be decoded, should this also
18 represent any valid data.
19
20 https://bugzilla.gnome.org/show_bug.cgi?id=732203
21
22 Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
23 ---
24  gst/vaapi/gsth264parse.c |   11 +++++++++--
25  1 file changed, 9 insertions(+), 2 deletions(-)
26
27 diff --git a/gst/vaapi/gsth264parse.c b/gst/vaapi/gsth264parse.c
28 index 805c55f..413a227 100644
29 --- a/gst/vaapi/gsth264parse.c
30 +++ b/gst/vaapi/gsth264parse.c
31 @@ -393,7 +393,8 @@ gst_h264_parse_negotiate (GstH264Parse * h264parse, gint in_format,
32    h264parse->format = format;
33    h264parse->align = align;
34  
35 -  h264parse->transform = (in_format != h264parse->format);
36 +  h264parse->transform = in_format != h264parse->format ||
37 +      align == GST_H264_PARSE_ALIGN_AU;
38  }
39  
40  static GstBuffer *
41 @@ -1054,7 +1055,13 @@ out:
42  
43  skip:
44    GST_DEBUG_OBJECT (h264parse, "skipping %d", *skipsize);
45 -  gst_h264_parse_reset_frame (h264parse);
46 +  /* If we are collecting access units, we need to preserve the initial
47 +   * config headers (SPS, PPS et al.) and only reset the frame if another
48 +   * slice NAL was received. This means that broken pictures are discarded */
49 +  if (h264parse->align != GST_H264_PARSE_ALIGN_AU ||
50 +      !(h264parse->state & GST_H264_PARSE_STATE_VALID_PICTURE_HEADERS) ||
51 +      (h264parse->state & GST_H264_PARSE_STATE_GOT_SLICE))
52 +    gst_h264_parse_reset_frame (h264parse);
53    goto out;
54  
55  invalid_stream:
56 -- 
57 1.7.9.5
58