Commit graph

87 commits

Author SHA1 Message Date
Edward Hervey
3da1c9c8d5 codecparsers: Add READ_UE_MAX macro
READ_UE_ALLOWED was almost exclusively used with min == 0, which doesn't
make much point for unsigned integers.

Add a READ_UE_MAX variant and use that instead. Also replaced two usages
of CHECK_ALLOWED (a,0,something) by CHECK_ALLOWED_MAX (a, something)
2015-01-23 12:24:52 +01:00
Sebastian Dröge
80e02cbdf9 Constify some static arrays everywhere 2015-01-21 10:18:50 +01:00
Vincent Penquerc'h
c73a5e0c54 h264parser: fix stack smashing
Ensure that we do not trust the bitstream when filling a table
with a fixed max size.
Additionally, the code was not quite matching what the spec says:
- a value of 3 broke from the loop before adding an entry
- an unhandled value did not add an entry
The reference algorithm does these things differently (7.3.3.1
in ITU-T Rec. H.264 (05/2003)).

This plays (apparently correctly) the original repro file, with
no stack smashing.

Based on a patch and bug report by André Draszik <git@andred.net>
2015-01-14 11:39:55 +00:00
Gwenole Beauchesne
8c76b5897a codecparsers: h264: fix derivation of MaxPicNum variable.
The logic to compute the MaxPicNum variable was reversed. In paricular,
MaxPicNum is double MaxFrameNum only if field_pic_flag is set to 1.

https://bugzilla.gnome.org/show_bug.cgi?id=739291
2014-11-14 09:36:27 +01:00
Gwenole Beauchesne
65fc58da4d codecparsers: h264: recognize SVC NAL units.
Identify SVC NAL units and tag them as such. This is necessary for
gst_h264_parser_parse_slice_hdr() to fail gracefully, if the user
did not perform the check himself.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-10-29 15:00:56 +01:00
Gwenole Beauchesne
b50c3e2127 codecparsers: h264: fix number of list0 {,non-}anchor refs.
Fix copy-paste error in gst_h264_sps_mvc_copy() where num_anchor_refs_l0
and num_non_anchor_refs_l0 were incorrectly initialized from list1.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-10-29 15:00:56 +01:00
Tim-Philipp Müller
3e62612259 codecparsers: sprinkle some gtk-doc Since: markers for new API 2014-10-29 13:15:51 +00:00
Jan Schmidt
86b948587e codecparsers: Initialise nalu extension type to NONE
Always set a default NALU extension type, and override it
when we find a supported extension, to avoid having it unset/random
for unsupported NALU extensions
2014-10-29 23:23:02 +11:00
Jan Schmidt
cc71119539 h264parser: Fix frame packing SEI parsing 2014-10-29 23:21:47 +11:00
Sreerenj Balachandran
3776e78ae6 codecparsers: h264: add support for Frame Packing Arrangement SEI message.
This parses the frame_packing_arragement() payload in SEI message.
This information can be used by decoders to appropriately rearrange the
samples which belong to Stereoscopic and Multiview High profiles.

https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-10-29 23:09:41 +11:00
Sreerenj Balachandran
51f003e469 codecparsers: h264: add support for Stereo Video Information SEI message.
Add the necessary payload parsing support for stereo_video_info.

https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
2014-10-29 23:09:41 +11:00
Gwenole Beauchesne
8911a80662 codecparsers: h264: parse seq_parameter_set_mvc_extension().
https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-10-29 23:09:41 +11:00
Gwenole Beauchesne
c1deab84e6 codecparsers: h264: parse MVC syntax elements.
https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-10-29 23:09:41 +11:00
Sreerenj Balachandran
e93551d5b0 codecparser: h264: Use proper bit_reader api while parsing buffering_period SEI
https://bugzilla.gnome.org/show_bug.cgi?id=734970
2014-08-18 11:45:54 +01:00
Aurélien Zanelli
41df512eb9 codecparsers_h264: initialize some fields of pic_timing structure
Otherwise pic timing structure can have invalid cpb_removal_delay,
dpb_output_delay or pic_struct_present_flag which are blindly retrieved
in h264parse.

https://bugzilla.gnome.org/show_bug.cgi?id=734124
2014-08-01 17:06:29 +02:00
Gwenole Beauchesne
22b68b60ec codecparsers: h264: fix identification of EOSEQ and EOS NALs.
An end_of_seq() [EOSEQ] or end_of_stream() [EOS] NAL unit is really
one byte long because this shall include the NalHeaderBytes (1) too.
The NALU.offset starts from the first byte of the header.

This is the proper fix to commit d37f842. In practice, this fixes
parsing of FRExt1_Panasonic_D and FRExt2_Panasonic_C, that include
additional frames after an EOSEQ.

https://bugzilla.gnome.org/show_bug.cgi?id=732553

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-07-01 16:26:48 +02:00
Gwenole Beauchesne
9bd186a960 codecparsers: h264: fix memory leak in GstH264PPS.
The gst_h264_parse_pps() function dynamically allocates the slice
group ids map array, so that needs to be cleared before parsing a
new PPS NAL unit again, or when it is no longer needed.

Likewise, a clean copy to the internal NAL parser state needs to be
performed so that to avoid a double-free corruption.

https://bugzilla.gnome.org/show_bug.cgi?id=707282

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-06-27 14:00:10 +02:00
Aurélien Zanelli
67df207280 codecparsers: h264: add support for Recovery Point SEI message.
The recovery point SEI message helps a decoder in determining if the
decoding process would produce acceptable pictures for display after
the decoder initiates random access or after the encoder indicates
a broken link in the coded video sequence.

This is not used in the h264parse element, but it could help debugging.

https://bugzilla.gnome.org/show_bug.cgi?id=723380
2014-06-26 17:22:26 +02:00
Gwenole Beauchesne
0440cabf49 codecparsers: h264: add nal_reader_skip_long() helper.
Add nal_reader_skip_long() helper function to allow an arbitrary number
of bits to be skipped. The former nal_reader_skip() function is too
limited to the actual cache size.

Use this new function to simplify gst_h264_parser_parse_sei_message()
default case, that skips unsupported payloads.

v2: made args consistent from header to source file.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-06-26 17:22:26 +02:00
Gwenole Beauchesne
db887f05ca codecparsers: h264: fix quantization matrix conversion routine names.
Fix routine names for zigzag/raster scan order conversion routines for
quantization matrices. This ought to use the gst_h264_quant_matrix_*()
naming convention instead of gst_h264_video_quant_matrix_*(), which
derived from the MPEG-2 function names.

https://bugzilla.gnome.org/show_bug.cgi?id=731524

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-06-12 10:26:26 +02:00
Nicolas Dufresne
9cdafffe7f Revert "h264parser: Remove unused fps_num/fps_den fields"
This breaks the build since mss has not been ported.

This reverts commit aeb6a52074.
2014-05-22 13:03:33 -04:00
Sebastian Dröge
aeb6a52074 h264parser: Remove unused fps_num/fps_den fields
Instead the newly added function should be used to calculate
the framerate properly.
2014-05-22 16:12:36 +02:00
Aurélien Zanelli
753701bf68 codecparsers_h264: add gst_h264_video_calculate_framerate()
Add a new function to calculate video stream framerate which rely on
SPS, slice header and pic timing using formula:

         time_scale                1                         1
fps = -----------------  x  ---------------  x  ------------------------
      num_units_in_tick     DeltaTfiDivisor     (field_pic_flag ? 2 : 1)

See section E2.1 of H264 specification for definition of variables.

https://bugzilla.gnome.org/show_bug.cgi?id=723352
2014-05-22 16:12:35 +02:00
Gwenole Beauchesne
a66f2dca60 codecparsers: h264: fix parsing of slice groups for map type = 2.
When parsing slice groups information for slice_group_map_type = 2, we
should only be reading up to num_slice_groups_minus1 groups since there
is always a "leftover" slice group and as many "foreground" slice groups
as needed.

This fixes parsing for SVCBMT-5 and SVCBMT-12 whereby the base layer would
have incorrectly been parsed to have up to 38 reference frames in list0,
which is not possible.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-04-27 23:41:19 +02:00
Gwenole Beauchesne
1b9e8a25a0 codecparsers: h264: fix derivation of default scaling lists.
When useDefaultScalingMatrixFlag is computed to be 1 while parsing
scaling_list(), then the scaling list shall be inferred to be equal
to the default list (7.4.2.1.1.1). That default list is really one
of Default_4x4_{Intra,Inter} or Default_8x8_{Intra,Inter} and not
one from fall-back rule sets A or B.

This fixes parsing for FRExt1_Panasonic_D, FRExt2_Panasonic_C,
FRExt3_Panasonic_E and FRExt4_Panasonic_B.

https://bugzilla.gnome.org/show_bug.cgi?id=724518

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-04-26 22:24:45 +02:00
Thibault Saunier
15d00a32fd h264parse: Set framerate even for interlaced videos
Co-Authored by: Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>

https://bugzilla.gnome.org/show_bug.cgi?id=726752
2014-04-10 09:09:38 +02:00
Li Xiaowei
24c1ae72d3 codecparsers: h264: fix slice_header() parsing for MVC.
The idr_pic_id syntax element depends on IdrPicFlag, which is a calculated
value that does not only depend on NAL unit type (IDR), but possibly also
on MVC non_idr_flag syntax element.

The computed idr_pic_flag is already stored in GstH264NalUnit structure.

https://bugzilla.gnome.org/show_bug.cgi?id=721772

Signed-off-by: Li Xiaowei <xiaowei.a.li@intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 19:38:13 +01:00
Gwenole Beauchesne
8dc7ab49fe codecparsers: h264: add gst_h264_parse_nalu_header() helper.
Add helper to parse the NALU header. Move bounds checking to there.

https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 19:38:13 +01:00
Gwenole Beauchesne
e61ae7ffa2 codecparsers: h264: add gst_h264_parse_sps_data() helper.
Split seq_parameter_set_data() parsing off gst_h264_parse_sps() so
that it could be re-used later on.

https://bugzilla.gnome.org/show_bug.cgi?id=685215

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 19:38:13 +01:00
Gwenole Beauchesne
afff27651b codecparsers: h264: clean-up gst_h264_parser_parse_sei_message().
Fix build when GST_DISABLE_GST_DEBUG is not defined. Use a switch
statement to dispatch to the various SEI payload handlers.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 19:38:13 +01:00
Gwenole Beauchesne
1b42180817 codecparsers: h264: fix skipping of unsupported SEI messages.
The payloadSize does not account for emulation prevention bytes. So,
just use nal_reader_skip() for skipping payload_size bits. It should
be possible to further optimize this code since the NAL reader shall
be aligned to byte boundary already.

Kill the now unused nal_reader_skip_to_next_byte() function.

https://bugzilla.gnome.org/show_bug.cgi?id=726829

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 18:09:27 +01:00
Gwenole Beauchesne
aa73624638 codecparsers: h264: fix SEI buffering_period() parsing.
Fix parsing of buffering_period() SEI messages. The number of bits
used to express {nal,vcl}_initial_cpb_removal_delay{,_offset} syntax
elements is not 5 but 1 + initial_cpb_removal_delay_length_minus1.

https://bugzilla.gnome.org/show_bug.cgi?id=726828

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-03-24 18:09:27 +01:00
Edward Hervey
274387e8e9 codecparsers: Don't use gst_ as prefix for private symbols
Otherwise they get exposed/accessible in the resulting .so

And make check-exports will complain
2014-01-29 10:50:40 +01:00
Thiago Santos
61192a1619 codecparsers: refactor common nal parsing to nalutils
Moves common code from h264 and h265 to a separate file
2014-01-24 09:30:35 -03:00
Aurélien Zanelli
af78b45979 h264parse: Fix multiple SEI messages in one SEI RBSP parsing.
An SEI RBSP could contains more than one SEI message as specified in
7.4.2.3.1.

This commit change the parser API: the gst_h264_parser_parse_sei()
function now create and fill a GArray containing GstH264SEIMessage.

https://bugzilla.gnome.org/show_bug.cgi?id=721715
2014-01-23 20:18:53 +01:00
Thiago Santos
4f0fc9a16f h264parser: remove trailling 0x00 bytes as the spec doesn't allow them
The spec states that the last byte of a NAL 'shall not' be 0x00
and it is allowed for byte-stream format to add padding 0x00 for
alignment.

So our parser should strip any trailling 0x00.

https://bugzilla.gnome.org/show_bug.cgi?id=721384
2014-01-22 08:36:30 -03:00
Matej Knopp
6af387cd5a h264parser: not all startcodes should have 3-byte 0 prefix
The parser assumes that every time there is a 0 before the startcode,
it is part of the startcode. But that's not true.

From the specification

Byte stream NAL unit syntax
zero_byte is a single byte equal to 0x00.
  When any of the following conditions are fulfilled, the zero_byte syntax
  element shall be present.
  – the nal_unit_type within the nal_unit( ) is equal to 7 (sequence parameter
    set) or 8 (picture parameter set)
  – the byte stream NAL unit syntax structure contains the first NAL unit of an
    access unit in decoding order, as specified by subclause 7.4.1.2.3.

The problem with doing this for all startcodes is that a trailing zero can mess
up timestamps. The trailing zero gets prepended to the startcode, which will
carry the PTS and DTS of previous buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=664443
2013-12-14 12:17:40 +01:00
Cong Zhong
631d5d94ed codecparsers: h264: fix picture level scaling lists derivation (rule B).
Fix picture level scaling lists derivation from fall-back rule set B,
as specified in 7.4.2.2. More precisely, the sequence level scaling
lists need to be used but intra and inter lists arguments were swapped.

This fixes FRExt/freh5.264 from conformance testing.

https://bugzilla.gnome.org/show_bug.cgi?id=720099

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-12-10 10:32:43 +01:00
Aurélien Zanelli
660979bbf2 codecparsers: Fix bad condition in h264 parser
https://bugzilla.gnome.org/show_bug.cgi?id=711615
2013-11-07 18:48:22 +01:00
Sebastian Dröge
2b348161ed codecparsers: Remove some unused functions 2013-11-07 09:54:40 +01:00
Sreerenj Balachandran
e943f56bf8 codecparsers: h264: store quantization matrices in zig-zag order
Quantizer matrices are encoded in zigzag scan order in the bitstream,
so always parse it as it is.

https://bugzilla.gnome.org/show_bug.cgi?id=708629
2013-10-02 10:59:10 +02:00
Sreerenj Balachandran
8c9eaf0dc9 codecparsers: h264: add helpers to convert quantization matrices
Add utility functions to convert quantization matrices from zig-zag scan
order into raster scan order and vice-versa

https://bugzilla.gnome.org/show_bug.cgi?id=708629
2013-10-02 10:57:54 +02:00
Edward Hervey
97426a1caa all: Fix for GST_DISABLE_GST_DEBUG
Where applicable, remove methods that don't do anything different than
the default implementation.
2013-07-29 09:42:12 +02:00
Gwenole Beauchesne
ac9c1ae5a8 codecparsers: h264: fix calculation of the frame cropping rectangle.
Fix calculation of the frame cropping rectangle, and more precisely
the actual cropped height. The frame_crop_top_offset subtraction
was not scaled up with SubHeightC.

Also clean-up variables to align more with (7-18) to (7-21).

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-07-09 12:15:07 +02:00
Sreerenj Balachandran
529ece338f h264parser: Parse the cropping-rectangle separately.
Assign the un-cropped width/height to sps->width/sps->height
during sps header parsing. Added new fields to SPS header structure
to provide the crop-rectangle dimensions.

https://bugzilla.gnome.org/show_bug.cgi?id=694068
2013-07-09 12:15:07 +02:00
Sreerenj Balachandran
65758debf1 h264parser: Fix the return value type for the SEI palyload parsing methods.
The return value type of SEI payload parsing functions
are GstH264ParserResult.

https://bugzilla.gnome.org/show_bug.cgi?id=695475
2013-07-01 11:24:17 +02:00
Thiago Santos
529b248a89 codecparsers: ensure the debug category is properly initialized
The user of the library might not need to create a NalParser, so
the debug category needs to be initialized from other functions
as well if required.
2013-05-07 21:05:10 -03:00
Gwenole Beauchesne
56e2405a35 codecparsers: h264: add inferred value for slice_beta_offset_div2.
The standard specifies that when slice_beta_offset_div2 is not present
in the slice header, then the value of slice_beta_offset_div2 shall be
inferred to be equal to 0.

https://bugzilla.gnome.org/show_bug.cgi?id=692265

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-01-22 11:19:17 +01:00
Mark Nauwelaerts
c20d13d8f8 codecparsers: h264: zero-initialize SPS VUI parameters
... so all 'present' flags indicate no presence of optional parts
in case VUI parameters end up not being parsed.

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=681818
2013-01-15 19:44:06 +01:00
Gwenole Beauchesne
c951d201ec codecparsers: h264: fix error code for invalid size parsed in SPS.
gst_h264_parse_sps() returned FALSE if it parsed invalid (negative)
size components. Now make it gracefully return GST_H264_PARSER_ERROR
instead of GST_H264_PARSER_OK (FALSE).

https://bugzilla.gnome.org/show_bug.cgi?id=684568
2012-11-19 12:06:04 +00:00