Switch the increment of markersize from when it is used to when it is
returned from compute_resync_marker_size.
This also makes the CHECK_REMAINING in gst_mpeg4_parse_video_packet_header
check for the actually required number of bits now and not one too few.
https://bugzilla.gnome.org/show_bug.cgi?id=739345
This reverts commit 916b954315.
Clearly something else was intended, and it also makes
more sense to add the extra bit. The resync marker is
N zero bits plus a 1 bit, and the pattern/mask needs to
be run on N+1 bits too.
(Even after the rever the code doesn't do that of course, so
it still needs to be fixed differently.)
https://bugzilla.gnome.org/show_bug.cgi?id=739345
The EOS and EOB nals have the size 2 which is the size of
nal unit header itself. The gst_h265_parser_identify_nalu()
is not required to scan start code again in this case.
In other cases, for a valid nalunit the minimum required size
is 3 bytes (2 byte header and at least 1 byte RBSP payload)
Skip the byte alignment bits as per the logic of byte_alignment()
provided in hevc specification. This will fix the calculation of
slice header size.
https://bugzilla.gnome.org/show_bug.cgi?id=747613
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)
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>
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>
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>
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
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>
In simple profile, level set to 0 or 2 indicate low and medium level
respectively. In main profile, level set to 0, 2 or 4 indicate low,
medium and high level respectively.
Level values are defined in Annex J.1.2 of the SMPTE 421M.
https://bugzilla.gnome.org/show_bug.cgi?id=738230
sequence-layer is serialized in little-endian byte order except for
STRUCT_C which is serialized in big-endian byte order.
But since STRUCT_A and STRUCT_B fields are defined as unsigned int msb
first, we have to pass them as big-endian to their parsing function. So
we basically use temporary buffers to convert them in big-endian.
See SMPTE 421M Annex J and L.
https://bugzilla.gnome.org/show_bug.cgi?id=736871
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
The vlc table members cbits, cword and values were assigned in the wrong
order, causing the mpeg4 parser to fail when handling sprite
trajectories.
https://bugzilla.gnome.org/show_bug.cgi?id=733322
Fix documentation for GstH264NalUnit. The @ref_idc part was totally
unbalanced. Also add a note about @offset and @size fields to remind
that this is relative to the start of the NAL unit, thus including
the header bytes.
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>
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>
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
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>
Use the first _gst_reserved[] slot to hold the built-in range decoder
private data. The first slot was formerly the buffer size, which was
then promoted to semi-public namespace when it got integrated as git
commit 2940ac6.
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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>
Fix MPEG-4 and VP8 APIs to export their external symbols as pure C
symbols, i.e. un-mangled for C++.
https://bugzilla.gnome.org/show_bug.cgi?id=731522
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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
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>
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>
Import libvpx 1.3.0 range decoder files (dboolhuff.[ch]) to implement
the VP8 utilities native interface. Likewise, copy and use the default
libvpx generated entropy probabilities tables.
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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>
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>
Add missing NAL unit types. They are mostly related to alpha blending,
scalable video coding extensions (SVC, Annex.G), and multiview video
coding extensions (MVC, Annex.H).
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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>
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>
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>
Account for trailing zero bits when checking for rbsp_more_data().
In particular, fix an hypothetical stream whereby rbsp_more_data()
is called in the following conditions for PPS header: NalReader
reached position 20, 12 bits are remaining and trailing data at
current byte position is c8 00.
rbsp_more_data() used to return TRUE whereas it should obviously
return FALSE because x8 00 represents a valid rbsp_trailing_bits()
structure.
https://bugzilla.gnome.org/show_bug.cgi?id=685890
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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
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
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
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>
We only check input from the API user with g_return_*_if_fail().
Internal sanity checks should use g_assert() instead, which is
disabled by default for releases.
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>
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
Add API to parse the Slice header. This also calculates the macroblock
position as specified in 6.3.16.
https://bugzilla.gnome.org/show_bug.cgi?id=664274
Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
Add new interface to MPEG-2 video parser that takes GstMpegVideoPacket
arguments instead of data, size, and offset. New functions are called
after gst_mpeg_video_packet_*() and provide the default implementation.
Older API is moved to the deprecated namespace and uses the new functions.
https://bugzilla.gnome.org/show_bug.cgi?id=692933
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
Ignore the display_extension values if they are greater than the width/height
values provided by seqhdr and calculate the PAR based on the seqhdr values.T
his is what DVD players are doing.
Thanks to "David Schleef <ds@schleef.org>"
https://bugzilla.gnome.org/show_bug.cgi?id=685103
This can be used by parsers to provide pre-parsed information to
downstream elements that would require it (so they can avoid having
to parse the bitstream again).