Commit graph

167 commits

Author SHA1 Message Date
Seungha Yang
405d311106 codecs: av1decoder: Use GstFlowReturn everywhere
The same modification as that of VP8 decoder

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2528>
2021-09-20 13:03:44 +00:00
Seungha Yang
e009e80178 codecs: vp9decoder: Use GstFlowReturn everywhere
The same modification as that of VP8 decoder

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2528>
2021-09-20 13:03:44 +00:00
Seungha Yang
aaeb76f09c codecs: vp8decoder: Use GstFlowReturn everywhere
boolean return value is not sufficient for representing the reason
of error in most cases. For instance, any errors around new_sequence()
would mean negotiation error, not just *ERROR*.
And some subclasses will allocate buffer/memory/surface on new_picture()
but it could be failed because of expected error, likely flushing

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2528>
2021-09-20 13:03:44 +00:00
Víctor Manuel Jáquez Leal
f51371d7b9 codecs: mpeg2decoder: Use tsg framerate for latency.
Latency setting relies on src pad caps, but they aren't set when the
function is called, and latency is never updated.

In order to fix it, this patch uses TSG framerate first, and if it's
not set yet, sinkpad caps are used to get the framerate.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2514>
2021-09-17 12:48:33 +00:00
He Junyan
162026961b codecs: h264dec: Check bumping again after inserting current picture.
In order to get the lowest latency, we can add another bumping check after
inserting the current picture into the DPB immediately. That can avoid
waiting for another decoding circle of the next frame and so the latency
is lower.

Fix: #1628
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2501>
2021-09-15 13:20:28 +00:00
He Junyan
28eb729b53 codecs: h264: Add protection to to_insert picture in bump check.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2501>
2021-09-15 13:20:28 +00:00
He Junyan
5c73725c9b codecs: h264dec: Improve the policy to infer max_num_reorder_frames.
The max_num_reorder_frames number can change the way we bumping the
pictures in the DPB. The smaller it is, the lower latency we will
get. So it is important for live mode streams, but it is not given
in VUI parameters sometimes. We now improve the policy to infer it:
1. Never guess it in the "strict" compliance.
2. For baseline and constrained baseline profiles, which do not have
   B frames, set it to 0.
3. For -intra only profiles, set it to 0.
4. Otherwise, not guess it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2501>
2021-09-15 13:20:28 +00:00
He Junyan
0b949ec07c codecs: h264dec: Improve the fast bump for the live mode.
We control the policy of fast bump by the profile and the compliance
property. For baseline and constrained baseline profiles, we can use
more radical bump policy. User can also change the bump policy by
setting the compliance property in run time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2432>
2021-09-13 06:37:28 +00:00
He Junyan
56269d127f codecs: h264: Change the low_latency to an enum for dpb_needs_bump().
The bool parameter of low_latency is not enough. We have multi policies for
low latency bumping, from the safest to something radical. So we need an enum
to represent the proper latency requirement.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2432>
2021-09-13 06:37:28 +00:00
He Junyan
3c975ed918 codecs: h264dec: Add a compliance property to control behavior.
Some features such as the low-latency DPB bumping and mapping the
baseline profile as the constrained-baseline profile do not conform
to the H264 offical spec. But in practice, they are very useful and
are widely needed. We add this compliance property to control the
behavior of the decoder, make it fit more requirement.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2432>
2021-09-13 06:37:28 +00:00
Daniel Almeida
b8c826afe3 codecs: gstvp9statefulparser: feature_data should be 0 if feature_enable is 0
The spec says in 6.2.11 that feature_data[i][j] should be zero if
feature_enabled[i][j] is zero. Instead we retained the old value in the parser.
Fix it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2449>
2021-09-09 18:32:42 +00:00
Mengkejiergeli Ba
702e69e841 codecs: av1dec: Fix to output frame with highest spatial layer
During the output process, if there are multiple frames in a TU (i.e. multi-spatial
layers case), only one frame with the highest spatial layer id should be selected
according to av1 spec. The highest spatial layer id is obtained from idc value of
the operating point.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2475>
2021-08-27 15:27:31 +00:00
He Junyan
70ce2327d0 codecs: h264dec: Output the picture directly if already a frame.
We forget one case that is the frame and field pictures may be mixed
together. For this case, the dpb is interlaced while the last picture
may be a complete frame. We do not need to cache that complete picture
and should output it directly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2448>
2021-08-12 07:41:28 +00:00
He Junyan
704689ec4a codecs: h264dec: Improve the find_first_field_picture().
We need to consider the first field of the last picture when the
last picture can not enter the DPB.

Another change is, when prev field's frame_num is not equal to the
current field's frame_num, we should also return FASLE because it
is also a case of losing some field.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2430>
2021-07-28 10:54:21 +00:00
He Junyan
f95aa0a374 codecs: h264dec: consider the last field when add picture to DPB.
There are cases that the first field of the last picture is not a
ref but the second field is a ref. We need to add both of them
because the bumping always needs a complete frame in the DPB.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2430>
2021-07-28 10:54:21 +00:00
He Junyan
055ded53e9 codecs: h264dec: Consider the field case when directly output.
For interlaced streams, it is also possible that the last frame is
not able to be inserted into DPB when the DPB is full and the last
frame is a non ref. For this case, we need to hold a extra ref for
the first field of the last frame and wait for the complete frame
with both top and bottom fields. For the progressive stream, the
behaviour is unchanged.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2430>
2021-07-28 10:54:21 +00:00
He Junyan
04974015ec codecs: h264dec: Fix a error print of dpb_add.
When the dpb is interlaced, the max size should be 2*dpb->max_num_frames,
correcting the error print info for that.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2430>
2021-07-28 10:54:21 +00:00
He Junyan
f9d7b708e1 codecs: h264decoder: let print_ref_pic_list_b print the correct list name.
The print_ref_pic_list_b now not only needs to trace the ref_pic_list_b0/1,
but also need to trace the ref_frame_list_0_short_term. We need to pass the
name directly to it rather than an index to refer to ref_pic_list_b0/1.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2425>
2021-07-23 19:52:48 +00:00
He Junyan
eef9067619 codecs: h264dec: Fix a typo in construct_ref_field_pic_lists_b.
The array sort of ref_frame_list_0_short_term has some typo. The
typo makes this list not in the POC ascend order and generate wrong
decoding result for interlaced streams.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2425>
2021-07-23 19:52:48 +00:00
He Junyan
130205629f codecs: h264dec: Improve the algorithm for low latency mode.
In low_latency mode, try to bump the picture as soon as possible
without the frames disorder:
1. We can directly output the continuous non-reference frame.
2. Consider max_num_reorder_frames, which is special useful for
   I-P mode.
3. Consider the leading pictures with negative POC.
4  Output small POC pictures when non-reference frame comes.
4. Output the POC increment<=2 pictures. This is not 100% safe,
   but in practice this condition can be used.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
573d3f5ba5 codecs: h264dec: Add help function of dpb_set_max_num_reorder_frames.
The max_num_reorder_frames can be useful for bump check. We store it
in the DPB and no need for the decoder now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
be223ad316 codecs: h264dec: Add a flag to record whether picture is reference.
The picture->ref field will change from time to time according to decoder's
state and reference sliding window. We need another flag to record whether
the picture is a reference picture when it is created, and this can help
the bumping check.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
b4e3887449 codecs: h264dec: Change the order of dpb_add and dpb_bump.
The current behavior is different from the SPEC. We should check
and bump the DPB or drain the DPB before we insert the current
picture into it. This may cause the output picture disorder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
f1df120797 codecs: h264dec: Modify the DPB need bump check.
Accord to spec, we should not add the current picture into the DPB
when we check whether it needs to bump, so the checks of the IDR and
the "memory_management_control_operation equal to 5" are no needed.

And the spec also says that the DPB only needs to bump when there is
no empty frame buffer left(We handle the IDR cases in other places).
We need to follow that and the max_num_reorder_frames is useless.

We also minus 1 in has_empty_frame_buffer because the current frame
has not been added yet.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
4411a4e00f codecs: h264dec: Make dpb_has_empty_frame_buffer a codecs API.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
23b15aa5d0 codecs: h264dec: Set picture to a small poc when mem_mgmt_5.
When current frame memory_management_control_operation equal to 5, that
means we need to drain the dpb and the current picture act as an IDR frame.
So it should have smaller poc than the later pictures to ensure the output
order.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2373>
2021-07-21 15:23:17 +00:00
He Junyan
4299596d16 codecs: h265decoder: Fix a typo of NumPocTotalCurr when process ref pic list.
We should use the NumPocTotalCurr value stored in decoder, which is a calculated
valid value, rather than use the invalid value in the slice header. Most of the
time, the NumPocTotalCurr is 0 and make the tmp_refs a very short length, and
causes the decoder's wrong result.
By the way, the NumPocTotalCurr is not the correct name specified in H265 spec,
its name should be NumPicTotalCurr. We change it to the correct name.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2414>
2021-07-16 23:05:18 +08:00
Mads Buvik Sandvei
bc6b68215f codecs: h265decoder: Always free messages while parsing SEI
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2390>
2021-07-14 17:56:27 +00:00
He Junyan
55ccc581b2 codecs: vp9statefulparser: not init segmentation_abs_or_delta_update.
The segmentation_abs_or_delta_update is a stateful var, it should not
be inited every time when parsing the segmentation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2403>
2021-07-13 15:34:57 +00:00
He Junyan
078b2699e7 codecs: h265dec: Disable the POC order warning for negative POC.
There may be leading frames after the IRAP frames, which has negative
POC. This kind of frames are allowed and they will be displayed before
the IRAP frame. So the warning should not be triggered for them. Init
the last_output_poc to G_MININT32 can avoid this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2380>
2021-07-06 14:33:21 +00:00
He Junyan
1fa9f26a53 codecs: h264dec: Disable the POC order warning for negative POC.
There may be leading frames after the IDR frame, which has negative
POC. This kind of frames are allowed and they will be displayed before
the IDR frame. So the warning should not be triggered for them. Init
the last_output_poc to G_MININT32 can avoid this.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2380>
2021-07-06 14:33:21 +00:00
He Junyan
17e8fea158 codecparsers: vp9statefulparser: Fix the gst_vp9_get_qindex clamp issue.
The alternate quantizer is a delta value and should be int type.
We mark it wrongly as uint, that will make CLAMP (data, 0, 255)
always choose 255 rather than 0 if the data < 0.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2369>
2021-07-02 08:44:15 +00:00
He Junyan
5d96e9e7bd codecs: h265decoder: Consider the conformance window changes when new_sequence().
The change of conformance_window_flag and crop windows size also has impact on the
output resolution and caps. So it deserves a trigger of new_sequence() to notify
the sub class to update caps and pool.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2312>
2021-07-01 14:39:53 +00:00
Seungha Yang
b5b13a6f5c h265decoder: Don't hold reference to GstVideoCodecFrame for dropped picture
We are dropping RASL (Random Access Skipped Leading picture) which
is associated with an IRAP (Intra Random Access Picture) that has
NoRaslOutputFlag equal to 1, since the RASL picture will not be
outputted and also it should not be used for reference picture.
So, corresponding GstVideoCodecFrame should be released immediately.
Otherwise GstVideoDecoder baseclass will hold the unused frame.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2330>
2021-07-01 14:10:30 +00:00
Seungha Yang
c3b26de1f2 av1decoder: Store display resolution for duplicated picture
Target display resolution might be required by subclass implementation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2365>
2021-06-29 07:12:27 +00:00
Seungha Yang
7a1effc499 av1decoder: Fix debug typo
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2365>
2021-06-29 07:12:27 +00:00
Nicolas Dufresne
2696bcd9e2 vp8decoder: Drain the output queue on EOS/finish
The finish() virtual method was flushing the queue, instead push the
remaining buffers. It is not required to reset in finish() unlike
drain(). This a regression causing last frame to always be lost.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2333>
2021-06-16 17:34:54 +00:00
Nicolas Dufresne
e5e2b6a652 v4l2slvp8dec: Only ask for output delay once per negotiation
While it's technically possible to change it per frame, asking for
that every frame is not very useful. This mimic H264 decoder better.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2333>
2021-06-16 17:34:54 +00:00
He Junyan
2db3ce32ef codecs: Fix the H265 poc out of order warning.
We always get a warning such as:
h265decoder gsth265decoder.c:1432:gst_h265_decoder_do_output_picture: \
<vah265dec0> Outputting out of order 255 -> 0, likely a broken stream
in H265 decoder.

The problem is caused because we fail to reset the last_output_poc when
we get IDR and BLA. The incoming IDR and BLA frame already bump all the
frames in the DPB, but we forget to reset the last_output_poc, which
make the POC out of order and generate the warning all the time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2294>
2021-06-10 12:36:34 +00:00
He Junyan
c442c9bd5e codecs: Integrate H265 DPB full check into need_bump().
The current DPB check of H265 is not very correct. The current frame
is already in the DPB when we check whether the DPB is full.
For example, the DPB max size is 16 and we have 15 ref frames in the
DPB, so the gst_h265_dpb_delete_unused() cleans no one, and then plus
the current frame, the DPB is 16. This causes an error return, but in
fact, the stream is correct.
We now integrate the DPB full check into the need_bump() function.
We add the correct frame into to DPB and then check whether the picture
num is bigger than max_num_pics of DPB(which means there is no room for
the current picture). If true, we bump the DPB immediately.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2291>
2021-06-02 13:10:35 +00:00
Daniel Almeida
82c0005793 codecs: gstvp8decoder: add support for render delay
Some decoding APIs support delayed output for performance reasons.
One example would be to request decoding for multiple frames and
then query for the oldest frame in the output queue.

This also increases throughput for transcoding and improves seek
performance when supported by the underlying backend.

Introduce support in the vp8 base class, so that backends that
support render delays can actually implement it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2150>
2021-05-31 15:48:24 -04:00
Víctor Manuel Jáquez Leal
da27722351 libs: codecs: h264decoder: Assert output_picture virtual method.
For new code it's nice to assert if the derived class implemented the
output_picture virtual method. Otherwise a segmentation fault
occurs. All other decoders assert this method.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2228>
2021-05-07 20:20:59 +00:00
Daniel Almeida
4900e3583a codecs: gstvp9statefulparser: do not carry over segmentation flags
Do not carry over segmentation flags from previous frames. The spec
says in 7.2.10 that the feature data carry over from previous frames
if not updated, but the flags do not.

Consider what would happen if a flag B is to depend on a flag A, and
B carries over as set from another frame. Further consider that A is
now not set in this particular frame. This leads to the invalid state
in which flag B is set but flag A isn't.

This might cause the bitstream to be rejected by accelerators down
the line.

Fix it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2203>
2021-04-30 16:49:28 +00:00
Seungha Yang
fee725f3cc codecs: vp9decoder: Update docs
* Remove "FIXME 1.20": All the bits are addressed already by using
  vp9parse element
* Fix copy & paste errors: Some comments were copied from h264decoder
  blindly.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2151>
2021-04-09 12:13:24 +00:00
Seungha Yang
f7a341a1f0 codecs: vp9decoder: Make duplicate_picture() vfunc optional
The default implementation was required when superframe parsing
was handled by vp9decoder. For instance, if a superframe consists
of multiple frames with show_existing_frame header, it was vague
that which GstVp9Picture should consume GstVideoCodecFrame.

After 1.18 release, we introduced vp9parse element and
superframe should be handled by upstream vp9parse elemenet now.
So, we don't need to care about the superframe at vp9decoder class
level anymore. Simply, a frame corresponding to show_existing_frame
can be dropped if subclass doesn't implement duplicate_picture().

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2151>
2021-04-09 12:13:24 +00:00
Seungha Yang
50e116c4a7 codecs: vp9decoder: Allow decoding start with intra-only frame
As per spec "7.2 Uncompressed header semantics" and
"8.2 Frame order constraints", decoding can start with intra-only
frame. This commit is for fixing vp90-2-16-intra-only.webm
bitstream test failure.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2112>
2021-04-07 19:32:29 +00:00
Seungha Yang
6eb9856f59 codecs: vp9decoder: Pass GstVideoCodecFrame to duplicate_picture()
... and fix picture duplication logic for vavp9dec

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2112>
2021-04-07 19:32:29 +00:00
Seungha Yang
1f769839c0 codecs: vp9decoder: Port to GstVp9StatefulParser
Use newly implemented VP9 parser. Since new GstVp9FrameHeader
struct holds all the information of the stream, baseclass will not
pass parser object to new_sequence() method anymore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2112>
2021-04-07 19:32:29 +00:00
Seungha Yang
c36190cbda codecparsers: Reimplement VP9 parser
Existing VP9 parser implementation doesn't provide information
required by other stateless decoding APIs (i.e., DXVA and NVDEC),
specifically loop filter and segmentation parameters might not exist
current frame. So parser needs to fill the information by using previously
parsed information.
We can update the gstvp9parser implementation so that it can provide
all information required by stateless decoding APIs with a huge API break,
or adding more ugly struct in it.
Instead doing as such, this commit introduce a new VP9 parser implementation.

What is different from existing one?
* All variables will follow the specification as much as possible:
  VP9 Bitstream & Decoding Process Specification - v0.6 31st March 2016
* Parser will fill all the required information for decoding frame
  to GstVp9FrameHeader struct. In case of old VP9 parser,
  user needs to read additional data from parser's member variables.
* GstVp9StatefulParser object struct is completely completely opaque

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2112>
2021-04-07 19:32:29 +00:00
Seungha Yang
771326a0fb codecs: vp9decoder: Don't check codec change with show_existing_frame
Show existing frame will zero frame_type value but it doesn't mean
it's keyframe.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2112>
2021-04-07 19:32:29 +00:00