Commit graph

57 commits

Author SHA1 Message Date
Víctor Manuel Jáquez Leal
1a5862dd39 codecs: h264decoder: fix memory leak
gst_h264_dbp_get_picture_all() returns a full transfer of the GArray, which
needs be unrefed. But it is not unrefed in
gst_h264_decoder_find_first_field_picture() leaking it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1827>
2020-11-23 15:23:35 +01:00
Seungha Yang
64ea751cd2 codecs: h264decoder: Add support for field ref picture list modification
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:57:30 +09:00
Seungha Yang
88ebe8031a codecs: h264decoder: Add more option arguments for reference picture getter
In case that "pic_order_cnt_type" is equal to zero, ref picture
list for B slice should not include non-existing picture
as per spec 8.2.4.2.3. And, the second field is not needed
for the process of frame picture reference list construction
since it needs to be frame unit, not field picture in that case.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:44:04 +09:00
Seungha Yang
e1adc572a7 codecs: h264decoder: Split gap picture as well if needed
field pair pictures might be required for reference list
depending on context.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:08:47 +09:00
Nicolas Dufresne
4ee6167616 h264dec: Fix POC calculation for type 0
This is mostly for future use as it only fixes the caclulation for interlaced
cases, the case of frame seemed correct already.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:00:39 +09:00
Seungha Yang
11509fded1 codecs: h264decoder: Don't try to construct RefPicList0 and RefPicList1 if not required
We were trying to construct reference picture list even for
I slice before this commit. Reference list is required only for
P, SP and B slices. Also, if all existing reference pictures
are gap pictures, we don't need to construct lists.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 18:29:54 +09:00
Seungha Yang
caa5eb65d1 codecs: h264decoder: Split frame picture into field pictures if needed
In case of interlaced stream, frame pictures need to be splitted
into field for reference marking process.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1810>
2020-11-16 14:25:36 +00:00
Seungha Yang
7b42b1f9fb codecs: h264decoder: Add util macro for frame/field picture identification
Add a macro to check whether given GstH264Picture is for frame or field
decoding.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1810>
2020-11-16 14:25:36 +00:00
Seungha Yang
f9af93d841 codecs: h264decoder: Don't give up to decode due to missing reference picture
Missing reference picture is very common thing for broken/malformed stream.
Decoder should be able to keep decoding if it's not a very critical error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1809>
2020-11-14 16:17:18 +00:00
Seungha Yang
0b9f975b36 codecs: h264decoder: Add support for interlaced stream
Initial support for interlaced stream. Subclass should implement
new_field_picture() vfunc. Otherwise, baseclass will assume that
subclass doesn't support interlaced stream.

Restrictions:
* Reference picture modification process for interlaced stream
  is not implemented yet
* PAFF (Picture Adaptive Frame Field) is not properly implemented.
* Field display ordering (e.g., top-field-first) decision should
  be enhanced via picture timing SEI parsing
* Gap in field picture should be handled

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1534>
2020-11-13 15:25:43 +00:00
Seungha Yang
52a8864076 codecs: h264decoder: Rename DPB methods
Clarify wheter it's for picture(field) or frame in order to
support interlaced stream, because DPB size is frame unit, not picture
in case of interlaced stream.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1534>
2020-11-13 15:25:42 +00:00
Seungha Yang
9bd6b5f0b4 codecs: h264decoder: Remove interlaced stream related constraints
... and add new_field_picture() vfunc so that ensure interlaced
decoding support by subclass.
The method will be used later with interlaced stream support.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1534>
2020-11-13 15:25:42 +00:00
Seungha Yang
7a53d7a4aa codecs: h264decoder: Store reference picture type using enum value
Managing reference picture type by using two variables
(ref and long_term) seems to be redundant and that can be
represented by using a single enum value.

This is to sync this implementation with gstreamer-vaapi so that
make comparison between this and gstreamer-vaapi easier and also
in order to minimize the change required for subclass to be able
to support interlaced.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1534>
2020-11-13 15:25:42 +00:00
Seungha Yang
227456d240 codecs: h264decoder: Remove DPB size related spammy debug message
It's not informative at all if SPS wasn't updated. Also we are printing
DPB size related debug message in another place already.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1806>
2020-11-13 14:50:09 +00:00
Seungha Yang
6a6f8c967c codecs: h264decoder: Don't fill gap picture if it's not allowed
We should fill gap picture only if sps->gaps_in_frame_num_value_allowed_flag
is set.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1801>
2020-11-12 14:38:56 +00:00
Seungha Yang
64c1218948 codecs: h264decoder: Try reference picture marking process in any case
... even if there is some invalid conditions
(because of broken stream, our implementation fault or so).
Otherwise baseclass will keep such reference pictures and
it would result to DPB full.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1783>
2020-11-09 14:40:06 +00:00
Seungha Yang
e78dc91f9e codecs: h264decoder: Fix for MMCO type 2
As per 8.2.5.4.2, we should mark a picture which has
LongTermPicNum == long_term_pic_num as "unused for reference",
not pic_num.

Passing conformance bitstream test with MR2_MW_A

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1768>
2020-11-05 14:56:28 +00:00
Seungha Yang
0e53668a9b codecs: h264picture: Add more trace log
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1768>
2020-11-05 14:56:28 +00:00
Seungha Yang
5527cc4a2e codecs: h264decoder: Rework for DPB management
Sync with recent h265decoder DPB implementation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1761>
2020-11-05 02:26:47 +09:00
Seungha Yang
b70ceb4235 codecs: h264decoder: Remove unused pts variable
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1761>
2020-11-05 00:33:34 +09:00
Víctor Manuel Jáquez Leal
3dd8276551 codecs: h264: unref leaked caps
Unref a leaked caps at set_latency().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1590>
2020-09-23 11:52:47 +02:00
Víctor Manuel Jáquez Leal
e0e37a0d92 codecs: h264decoder: Calculate and set latency
Add gst_h264_decoder_set_latency(), which calculates and sets
latency on base decoder class, after new_sequence is called.

This assumes that in new_sequence() vmethod, callee negotiates
downstream caps.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1531>
2020-09-15 11:20:13 -04:00
Nicolas Dufresne
f4b2da3c63 h264decoder: Fix various typos
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1563>
2020-09-10 15:21:57 +00:00
Seungha Yang
25c87a1315 codecs: h264decoder: Fix possible GstH264Picture leak and small cleanup
Don't leak pictures when dpb is full unexpectedly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1527>
2020-08-24 20:35:01 +00:00
Seungha Yang
bf659379cf codecs: h264decoder: Update document with Since marks
To make documentation CI happy with the newly added APIs.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 18:30:07 +09:00
Seungha Yang
973a2569d4 codecs: h264decoder: Rename API arguments
Although it's not public ones, make them consistent with vfunc
for them to be nicer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 17:53:29 +09:00
Nicolas Dufresne
6523c5bcb6 h264decoder: Add ability to lookup by system_frame_number
This is to avoid having to create a reference chain in decoders from
GstVideoCodecFrame to GstH264PIcture to implementation wrapper.

So this change introduces:

 - gst_h264_dpb_remove_outputed (dpb)
 - gst_h264_dpb_get_picture(dpb, system_frame_num)
 - gst_h264_decoder_get_picture (dec, system_frame_num)

In order to ensure that frames can be looked up during the draining
process, we now first remove all (including reference) frames that
have been outputed but are still in the DPB. Then for each remaining
buffers, we remove it from the DPB to reach reference 1 and output it.

Previously we could take all not outputed outside of the DPB which would
prevent lookup by the base class.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 17:18:42 +09:00
Seungha Yang
82fb55bdff codecs: h264decoder: Make GstVideoCodecFrame hold the last reference of the buffer
... when gst_video_decoder_finish_frame() is called.

Some subclasses attach GstBuffer to GstH264Picture as an user data
which will increase reference count of the buffer. It would result
to buffer copy per every frame.

Background here is, GstVideoDecoder wants writable output buffer for
GstMeta handling, and if the output buffer is not writable
(i.e., reference count is not one), the buffer will be copied.
Even if underlying GstMemory wouldn't be copied, buffer copy operation
will introduce extra memory allocation overhead which is not optimal.

By this modification, subclass might be able to receive the last
reference to GstH264Picture

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 17:18:42 +09:00
Seungha Yang
e921a07715 codecs: h264decoder: Pass GstVideoCodecFrame to output_picture()
All subclasses are retrieving list to get target output frame, which
can be done by baseclass. And pass the ownership of the GstH264Picture
to subclass so that subclass can clear implementation dependent resources
before finishing the frame.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 17:18:42 +09:00
Seungha Yang
7a024a740f codecs: h264decoder: Don't attach extra ref of GstH264Picture to GstVideoCodecFrame
The lifecycle of GstH264Picture is being managed by our DPB
implementation. If it's still required, subclass can do that
by itself in the new_picture() method.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1449>
2020-07-21 17:18:42 +09:00
Seungha Yang
14f6799f93 codecs: h264decoder: Drop non-decodable frames
Otherwise GstVideoDecoder baseclass will hold the corresponding broken frames
until new reset event happens such as FLUSH or downwards state change.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1450>
2020-07-20 21:00:48 +09:00
Seungha Yang
487f9a08de codecs: h264decoder: Fix for DPB size calculation
Some bitstreams might require more DPB size than that of what we've
calculated.

This change should've been part of initial commit of h264 stateless
codec implementation but it was missed.

See also https://chromium-review.googlesource.com/c/chromium/src/+/760276/

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1385>
2020-06-30 22:20:29 +00:00
Víctor Manuel Jáquez Leal
9ff332e15d codecs: h264decoder: update max_dpb_frames only if VUI is present
There are some streams, with HRD, where the the calculated
max_dpb_frames is zero (max_dpb_mbs is less than size mb). In order to
get the dbp size it is required to rely on the VUI parameters if they
are present.

According to the spec Annex E.2.1

**max_dec_frame_buffering** specifies the required size of the HRD
decoded picture buffer (DPB) in units of frame buffers.  It is a
requirement of bitstream conformance that the coded video sequence
shall not require a decoded picture buffer with size of more than
Max(1, max_dec_frame_buffering) frame buffers to enable the output of
decoded pictures at the output times specified by dpb_output_delay of
the picture timing SEI messages. The value of max_dec_frame_buffering
shall be greater than or equal to max_num_ref_frames. An upper bound
for the value of max_dec_frame_buffering is specified by the level
limits in clauses A.3.1, A.3.2, G.10.2.1, and H.10.2.

When the max_dec_frame_buffering syntax element is not present, the
value of max_dec_frame_buffering shall be inferred as follows:

– If profile_idc is equal to 44, 86, 100, 110, 122, or 244 and
constraint_set3_flag is equal to 1, the value of
max_dec_frame_buffering shall be inferred to be equal to 0.

– Otherwise (profile_idc is not equal to 44, 86, 100, 110, 122, or 244
or constraint_set3_flag is equal to 0), the value of
max_dec_frame_buffering shall be inferred to be equal to MaxDpbFrames.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1381>
2020-06-27 14:05:25 +02:00
Seungha Yang
2e0a6cc020 h264decoder: Disallow multiple slice group as we don't support FMO
Even though it might be supported by accelerator, baseclass is not
ready to support it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1291>
2020-05-22 19:07:33 +00:00
Víctor Manuel Jáquez Leal
206d900573 codecs: h264decoder: chain finalize vmethod
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:09 +00:00
Nicolas Dufresne
28e30c8493 codecs: h264decoder: Use calculated values for max_pic_num/frame_num
The parser pre-calculate these already, just use them.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:09 +00:00
Víctor Manuel Jáquez Leal
d2aae6bb96 codecs: h264decoder: ref pic lists as decode_slice parameters
Pass reference picture lists to decode_slice() vmethods

Change gstv4l2codech264dec and gstnvh264dec accordingly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:09 +00:00
Víctor Manuel Jáquez Leal
990392d595 codecs: h264decoder: handle reference picture lists
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:08 +00:00
Nicolas Dufresne
7e63d1f5ad codecs: h264decoder: Port from GList to GArray
Using glist requires a lot of small allocation at runtime and also
it comes with a slow sort algorithm. As we play with that for very
frame and slices, use GArray instead. Note that we cache some arrays
in the instance as there is no support for stack allocated arrays
in GArray.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:08 +00:00
Nicolas Dufresne
f8736626a9 codecs: h264decoder: Make get_long_ref_by_pic_num() transfer none
We don't use the extra reference, so let's just avoid the extra
ref/unref.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:08 +00:00
Nicolas Dufresne
a20147f255 codecs: h264decoder: Make get_short_ref_by_pic_num() transfer none
We don't use the extra reference, so let's just avoid the extra
ref/unref.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1238>
2020-05-19 16:57:08 +00:00
Seungha Yang
24367cbff0 h264decoder: Allow frame gap even if it's not allowed by SPS
It's most likely the case where some frames were dropped for some reason
(e.g., broken stream, network loss or so). However, decoder might be able to
decode following frames even if some frames are visually broken.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1232>
2020-05-01 01:55:21 +09:00
Seungha Yang
1d38728d05 h264decoder: Perform low-latency outputting only for live pipeline
Frequent outputting might drop throughput-wise performance.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1211>
2020-04-28 13:23:53 +00:00
Seungha Yang
00ad871628 h264decoder: Output decoded pictures as soon as possible
In case of IDR, any previously decoded pictures must be drained
before the IDR and POC of IDR should be zero. So we can output
IDR immediately. Also, when POC of current picture is expected to be
the next output POC, decoder can output the picture as well
without waiting.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1211>
2020-04-28 13:23:53 +00:00
Víctor Manuel Jáquez Leal
23e99a7a77 codecs: set sys frame num before new_picture()
Derive classes might need to operate on the current frame at their
new_picture() vmethod, so it would be needed to set system_frame_number
on picture before calling the vmethod.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1209>
2020-04-23 19:54:17 +00:00
Seungha Yang
ba07768ca4 h264decoder: Don't handle gap frame num for the first picture
If the first picture is not IDR, it would have non-zero frame_num
but it's not gap. We should skip gap frame handling in that case
2020-04-20 13:55:49 +00:00
Seungha Yang
6a7ea29084 h264decoder: Add some debug messages 2020-04-20 13:55:49 +00:00
Víctor Manuel Jáquez Leal
a3395167a1 codecs: h264picture: typo in GstH264PictureField enum 2020-04-19 18:40:12 +02:00
Seungha Yang
5a29917a63 codecs: Add minimal state validation
... to prevent requesting decoding before the preparation.
For instance, baseclass should not request decoding a picture if there
is no parsed valid headers, since subclass is most likely
not ready to decoding it.
2020-04-09 19:33:56 +00:00
Thibault Saunier
b9e0ccd8b7 codecs: Add basic documentation stubs 2020-04-08 08:47:46 -04:00