Commit graph

411 commits

Author SHA1 Message Date
Sebastian Dröge
ffa4d84e54 h2645parser: Catch overflows in AVC/HEVC NAL unit length calculations
Offset and size are stored as 32 bit guint and might overflow when
adding the nal_length_size, so let's avoid that.

For the size this would happen if the AVC/HEVC NAL unit size happens to
be stored in 4 bytes and is 4294967292 or higher, which is likely
corrupted data anyway.

For the offset this is something for the caller of these functions to
take care of but is unlikely to happen as it would require parsing on a
>4GB buffer.

Allowing these overflows causes all kinds of follow-up bugs in the
h2645parse elements, ranging from infinite loops and memory leaks to
potential memory corruptions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2103>
2021-03-24 09:22:48 +00:00
Matthew Waters
640a65bf96 gst: don't use volatile to mean atomic
volatile is not sufficient to provide atomic guarantees and real atomics
should be used instead.  GCC 11 has started warning about using volatile
with atomic operations.

https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719

Discovered in https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/868

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2098>
2021-03-22 14:34:36 +11:00
He Junyan
e8ec8f7dd7 codecparsers: av1: Fix a typo in frame_restoration_type setting.
Fixes: #1500
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1974>
2021-01-23 10:53:44 +00:00
He Junyan
b93315fa6c codecparsers: Exclude the size of obu_size when identify OBU.
obu->obu_size does not contain the bytes of obu_size itself, we need
to exclude it when doing the saint check.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1614>
2021-01-19 18:38:03 +00:00
He Junyan
33fcb0faf0 codecparsers: av1: add the set_operating_point() API.
The av1 can support multi layers when scalability is enabled. We
need an API to set the operating point and filter the OBUs just
belonging to some layers(the layers are specified by the operating
point).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
c4aaeb0509 codecparsers: av1: Add an API to reset the annex_b state only.
In practice, we encounter streams that have one or more temporal units
error. When that kind of error temporal units is in annex b format, the
whole temporal unit should be discarded.
But the temporal units before it are correct and can be used. More
important, because of the error temporal unit, the parser is in a wrong
state and all later temporal unit are also parsed uncorrectly.
We need to add this API to reset the annex_b state only when we meet
some temporal unit error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
a4f459fe21 codecparsers: av1: clean the seen_frame_header in parse_tile_group().
The current seen_frame_header is not cleaned correctly. According
to the spec, it should be cleaned when tiles are parsed completely.
Also delete a verbose seen_frame_header init in reset_state().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
6dedbc30c5 codecparsers: av1: fix a typo in parse_metadata_scalability
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
227d7a9327 codecparsers: av1: Do not assert in identify_one_obu when check annex b size.
Some buggy stream just writes the wrong temporal unit and frame size in
the stream. We should return failure rather than assert to abort.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
b511761f70 codecparsers: av1: Add unknow AV1 profile define for saint check.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
0d4982a3d5 codecparsers: av1: Improve the parse_tile_info.
1. store more tile info when parse tile group.
   The column, row, tile offset and tile data size are all useful for
   decoder process, especially for HW kind decoder such as VAAPI dec.
   Also fix the tile group skip size for each tile data.
2. No min_inner_tile_width requirement in newest spec.
3. Calculate the sbs of each tile for both uniform tile and non-uniformi
   tile.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
da0584010c codecparsers: av1: Fix a tile info read typo in frame header.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
26567354b9 codecparsers: av1: Fix a typo when get value of segmentation params.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
2fd1da60ea codecparsers: av1: add valid check for global motion params.
The global motion params and its matrix values need to be verified
before we use them. If it is invalid, we should notify the decoder
that it should not be used.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
8f55c9d6d2 codecparsers: av1: uint8 range is not enough for av1_bitstreamfn_ns
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
900bd06939 codecparsers: av1: delete duplicated GST_AV1_GM_ABS_ALPHA_BITS define.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
fce380ec40 codecparsers: av1: Improve the loop filter setting.
1. loop_filter_ref_deltas should be int because it needs to compare
   with 0.
2. Move the loop filter init logic to setup_past_independence() and
   load_previous(), which make it more precise with the spec.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
f20798a1db codecparsers: av1: Fix a error report for metadata obu.
The metadata OBUs, for example, ITUT_T35 has an undefined payload such
as itu_t_t35_payload_bytes field in AV1 spec, which may cause the failure
of parsing the trailings bits. We can give a warning and ignore this kind
of errors.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
2c3a33eeab codecparsers: av1: Fix a level index bug in sequence.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
He Junyan
7e33863b10 codecparsers: av1: all ref idx should be gint8.
All the ref index need to compare with 0 in reference index decision
algorithm. We also need to init them to -1.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>
2020-11-17 19:31:09 +00:00
Nicolas Dufresne
6f556518c8 h265parser: Fix wrong warning message
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1714>
2020-11-04 17:53:23 +00:00
Nicolas Dufresne
2e2e93c303 h265parse: Add missing const qualifier
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1750>
2020-11-02 18:20:32 +00:00
Xavier Claessens
2efb4a7adb Meson: Use pkg-config generator 2020-10-23 11:14:18 -04:00
Andrew Wesie
11353b3f6e codecparsers: h264parser: guard against ref_pic_markings overflow
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1703>
2020-10-16 15:11:26 +00:00
He Junyan
d90e353daa codecparsers: vp8parser: clear the frame_hdr before parsing.
Uninited frame_hdr may have garbage and may contain some wrong
results after the parsing process.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1587>
2020-09-25 17:07:43 +08:00
Haihao Xiang
4a93f6e651 h265parse: recognize more HEVC extension streams
There are streams which have the right general_profile_idc and
general_profile_compatibility_flag, but don't have the right extension
flags. We may try to use chroma_format_idc and bit_depth to
recognize these streams.

e.g.
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/SCC/IBF_Disabled_A_MediaTek_2.zip

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1328>
2020-09-16 16:51:45 +00:00
Haihao Xiang
626af12498 h265parser: select the right profile for high throughput SCC stream
Currently screen-extended-high-throughput-444 is recognized as
screen-extended-main-444, screen-extended-high-throughput-444-10 is
recognized as screen-extended-main-444-10 because they have the same
extension flags, so without this patch, it is possible that a decoder
which supports SCC but doesn't support throughput SCC will try to decode
a throughput SCC stream.

e.g.
https://www.itu.int/wftp3/av-arch/jctvc-site/bitstream_exchange/draft_conformance/SCC/HT_A_SCC_Apple_2.zip

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1328>
2020-09-16 16:51:45 +00:00
Seungha Yang
2d71ad49f8 h265parser: Fix possible invalid memory access
... and do more strict validation for num_tile_columns_minus1 and
num_tile_rows_minus1.

As per specification Table A.8, allowed maximum number of tile rows
and tile columns are 22 and 20, respectively. So we should adjust the size
of each array.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1372>
2020-07-14 16:34:46 +00:00
Nicolas Dufresne
c213b6ea17 nalutils: Improve slightly the error trace
Until now, bound check would simply trace the values and the range. This
enhances the trace by also tracing the name of the variable that was to be set
or read. This is not magically perfect in all cases, but greatly speed the
debugging work. Here's an example before and after this change:

Before: gst_h264_parser_parse_slice_hdr: value not in allowed range. value: 819183, range -87-77
After:  gst_h264_parser_parse_slice_hdr: value for 'slice->slice_qp_delta' not in allowed range. value: 819183, range -87-77
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1356>
2020-06-20 19:47:49 +00:00
Stéphane Cerveau
06f3a0ed2c codecparsers: fix typo in GstH265RegisteredUserData doc
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1303>
2020-05-27 22:43:39 +00:00
Nicolas Dufresne
540c287a73 codecparsers: h264: Only set relevant default weight values
This is minor optimization to avoid setting values we don't need. It also
makes debugging easier since only relevant values a non-zero now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:09 +00:00
Nicolas Dufresne
d062677b3f codecparsers: h264: Fix default ref list size
The default in PPS was not applied properly. The default does not apply for
I-Slice and l1 default only applies for B-Slice.  This fixes the slice values
for num_ref_idx_l0_active_minus1 and num_ref_idx_l1_active_minus1.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:09 +00:00
Nicolas Dufresne
90ca8850de h265parse: Ensure parsing ends on start-code + full header
The parser is used all over the place assuming that after calling
gst_h265_parser_identify_nalu(), the start-code found is can also be
identified. In H264 this works, because scan_for_start_code rely on
gst_byte_reader_masked_scan_uint32() that ensures that 1 byte passed the 3
bytes start code is found. But for HEVC, we need two bytes to identify the
following NAL.

This patch will return NO_NAL_END, even if a start code is found in the case
there was not enough bytes. This solution was chosen to maintain backward
compatibility, and reduce complexicity.

Fixes #1287

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>
2020-05-07 13:59:33 -04:00
Nicolas Dufresne
80524fb3da h264parser: Removed impossible error case
Same as done for H264, this error was trying to catch the case where we had
a start code without any bytes afterward. This will never happen since the
start code scanner only returns a match if there is one byte after start
code (pattern 0x00000100 / mask 0xffffff00). In H264, once byte is sufficient
to identify the NALU.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>
2020-05-07 12:08:36 -04:00
Nicolas Dufresne
dc4c470d75 h264parse: Properly handle 4 bytes start code
This will stop stripping four bytes start code. This was fixed and broken
again as it was causing the a timestamp shift. We now call
gst_base_parse_set_ts_at_offset() with the offset of the first NAL to ensure
that fixing a moderatly broken input stream won't affect the timestamps. We
also fixes the unit test, removing a comment about the stripping behaviour not
being correct.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>
2020-05-07 12:08:36 -04:00
Nicolas Dufresne
9029631f75 h265parser: Fix NAL size check for identification
Unlike H264, H265 requires 2 bytes after the start code to allow NAL
identification. This would otherwise report a broken NAL and skip
important data.

Fixes #1287

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>
2020-05-07 12:08:36 -04:00
Nicolas Dufresne
4332dc195d h265parser: Removed impossible error case
This error was trying to catch the case where we had a start code without any
bytes afterward. This will never happen since the start code scanner only returns
a match if there is one byte adter start code (pattern 0x00000100 / mask
0xffffff00).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1251>
2020-05-07 12:08:36 -04:00
He Junyan
3be186fe85 libs: parser: h265: Add SCC extension support.
Add support for screen content coding extensions profiles.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1146>
2020-05-05 17:07:41 +00:00
Georg Ottinger
13d55627f0 libs: parser: Adds AV1 parser.
This is the first version of AV1 parser implementation in GStreamer.

A test file is also provied with several test cases. It contains a
test sequence taken from the aom testdata set, with one key and one
inter-frame. The same test sequence has been reencoded to annexb.

testdata is taken from aom testdata (and reencoded for annexb) as well
as handcrafted testcases. Once reference testdata is available, the
testing could be imporved aswell.

Co-author: He Junyan <junyan.he@hotmail.com>
Co-author: Víctor Manuel Jáquez Leal <vjaquez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/785>
2020-05-01 19:55:41 +00:00
He Junyan
bd2fb6cbb9 libs: h265parser: Add High throughput scc extensions profiles' IDC.
It is compitable with scc and we use scc's function to identify it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1121>
2020-04-28 13:54:11 +00:00
He Junyan
35bf824b6d libs: h265parser: select extension profile by profile idc.
the old manner does not consider the profile idc. The profile idc should
play an more important role in recognizing the profile than the other
information. And there is no need to mix profiles of different extensions
together to find the closest profile when the bits stream is not standard,
different extensions support different features and should not be mixed.

The correct way should be recognize the extension category by profile idc
firstly, and then find the closest profile.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1121>
2020-04-28 13:54:11 +00:00
He Junyan
f4ddccb08e libs: h265parser: rename the FormatRangeExtensionProfile
FormatRangeExtensionProfile declares the common bits used for not
only format range extensions profiles, but also for several different
h265 extension profiles, such as high throughput, screen content
coding extensions, etc. And So the old name is not proper.
We also rename the get_h265_extension_profile function.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1121>
2020-04-28 13:54:11 +00:00
He Junyan
e99b962c0f libs: h265parser: Fix a bug for getting extension profile.
We should use the traget ExtensionProfile's IDC to check the
profile_compatibility_flag, rather than the profile_idc in the
stream. The old profile_compatibility_flag check always return
true. This causes that profiles with same constraint flags but
different profile_idc can't be recognized correctly. For example,
the screen-extended-main-444 profile is always be recognized as
the high-throughput-444 profile.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1121>
2020-04-28 13:54:11 +00:00
Mathieu Duponchelle
d3be83a26c gsth265parser.h: escape link-like syntax in doc 2020-04-28 00:29:52 +02:00
Seungha Yang
eeb3dd6605 h265parser: Fix some coverity issues
- Remove useless comparison
- Fix invalid memory access

CID: 1461477, 1461476, 1461475, 1461474, 1461279
2020-04-13 12:28:14 +00:00
Seungha Yang
a2f68762b0 h265parser: Add APIs to allow update VPS/SPS/PPS
gst_h265_parser_parse_{vps,sps,pps} APIs were used to parse VPS/SPS/PPS and
also in order to update parser's internal state at once. Meanwhile
gst_h265_parse_{vps,sps,pps} APIs are to parse VPS/SPS/PPS without state update.
This commit introduces new APIs so that only accepted VPS/SPS/PPS by user
can be updated to be used by parser.
2020-04-09 19:33:56 +00:00
Seungha Yang
a61549cbde h264parser: Add APIs to allow update SPS/PPS
gst_h264_parser_parse_{sps,pps} APIs were used to parse SPS/PPS and
also in order to update parser's internal state at once. Meanwhile
gst_h264_parse_{sps,pps} APIs are to parse SPS/PPS without state update.
This commit introduces new APIs so that only accepted SPS/PPS by user
can be updated to be used by parser.
2020-04-09 19:33:56 +00:00
Seungha Yang
1a09251699 h264parser: Parse all SEI payload type even if it's not handled by parser
... so that user can handle it from outside of parser API
2020-04-08 15:39:12 +00:00
Seungha Yang
db1ea18276 h264parser: Add support for creating picture timing SEI
This new method can make it possible to inject timecode meta into
h264 bitstream
2020-04-08 15:39:12 +00:00
Seungha Yang
28ce6c2a40 h264parser: Make GstH264PicTiming self-containing all the syntax information
... and store all parsed values.

We are storing pic_struct_present_flag although it's not part of
this SEI message but GstH264PicTiming includes it to clarify
following syntax values.
In addition to that, by adding CpbDpbDelaysPresentFlag, we don't need to
refer to VUI anymore.
2020-04-08 15:39:12 +00:00