Commit graph

163 commits

Author SHA1 Message Date
Hyunjun Ko
9397cd7d4d libs: decoder: h264: initialize active_sps/pps in reset
Since commits in https://bugzilla.gnome.org/show_bug.cgi?id=781142 landed,
they introduced regression in seek.

Formerly, once seek is done, decoder drops P-frames until I-frame arrives.
But since the commits landed, it doesn't drop P-frame and does try to
decode it continuously because active_sps is still alive. See ensure_sps function.
But there are prev_frames and prev_ref_frames reset already, then it
causes assertion.

So it's necessary to reset active_sps/pps also in reset method.

https://bugzilla.gnome.org/show_bug.cgi?id=783726
2017-06-15 13:40:27 +02:00
Jan Schmidt
bae56fe0c2 h264 decoder: Implement reset() for faster flush
Implement a custom reset() function for faster flushes
that just clear the reference pictures but don't reallocate
the DPB or clear out SPS/PPS

https://bugzilla.gnome.org/show_bug.cgi?id=781142
2017-04-12 10:43:49 +10:00
Jan Schmidt
a7a9b33ad9 Implement decoder reset on flush, rather than recreating
Clear decoders out on a flush but keep the same instance,
rather than completely recreating them. That avoids
unecessarily freeing and recreating surface pools
and contexts, which can be quite expensive

https://bugzilla.gnome.org/show_bug.cgi?id=781142
2017-04-12 10:43:49 +10:00
Víctor Manuel Jáquez Leal
d6738f3f93 libs: decoder: h264,h265 avoid uninitialized variable
Configuring GCC to verify possible usage of uninitialized variables,
shows that found_index might be used without previous assignation.

This patch assigns a initial value to found_index, also avoid a
branching when returning the result value.

https://bugzilla.gnome.org/show_bug.cgi?id=778782
2017-02-16 18:46:35 +01:00
Hyunjun Ko
d89a3bd258 libs: decoder: h264: reduce frame number of gaps
Reduce frame num gaps so that we don't have to create unnecessary
dummy pictures, just throw them away.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=777506
2017-02-07 11:30:02 +01:00
Hyunjun Ko
58e7b575bb libs: decoder: h264: don't update cloned attributes
If the frame is a cloned picture, its PTS comes from its parent
picture.  In addition, the base decoder doesn't set a valid PTS to
the frame corresponding to the cloned picture.

https://bugzilla.gnome.org/show_bug.cgi?id=774254
2017-01-10 12:54:39 +01:00
Víctor Manuel Jáquez Leal
b1f6da98de libs: fix code style for errors 2016-11-03 12:51:44 +01:00
Víctor Manuel Jáquez Leal
9afa0ce471 vaapidecode: codec_data minimal size is 7
When the format of a H.264 stream is AVC3, the SPS and PPS are inside the
stream, not in the codec_data, so the size of codec_data might be 7.

This patch reduces the minimal size of the codec_data buffer from 8 to 7.

https://bugzilla.gnome.org/show_bug.cgi?id=771441
2016-09-15 10:38:08 +02:00
Thiago Santos
2b47bf8c74 vaapidecoder_h264: plug leak of h264 parsing info
If something goes wrong while parsing, the info object is
being leaked

https://bugzilla.gnome.org/show_bug.cgi?id=763121
2016-03-09 15:39:31 +01:00
Thiago Santos
056a69cf2a vaapidecoder_h264: fix parsing of NALU aligned data
Don't assume the whole buffer is a single NAL, instead look for the
next start code in case there are multiple NALs per buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=762328
2016-02-19 15:37:45 +01:00
Víctor Manuel Jáquez Leal
ac730d0a62 libs: humongous code style fix
As part of the upstreaming process of gstreamer-vaapi into the GStreamer
umbrella, we need to comply with the project's code style. This meant to
change a lot of code.

It was decided to use a single massive patch to update the code style.

I would like to apologize with the original developers of this code because of
the history breakage.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
2016-02-03 20:03:47 +01:00
Tim-Philipp Müller
24168a2093 vaapi: fix 'ISO C90 forbids mixed declarations and code' compiler warnings
Declare variables at the beginning of a code block, which
is how it's done in GStreamer.

https://bugzilla.gnome.org/show_bug.cgi?id=759192
2016-02-02 16:17:43 +01:00
Víctor Manuel Jáquez Leal
1c722efe54 Remove old gst version guards
As gstreamer-vaapi now only supports from GStreamer 1.6, this patch removes
all the old GStreamer version guards.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
2016-01-25 12:09:40 +00:00
Víctor Manuel Jáquez Leal
f6ae00a6bb decoder: h264: initialize PPS's slice_group_id
When the GstVaapiParserInfoH264 is allocated, the memory is not initialized,
so it contains random data.

When gst_h264_parser_parse_pps() fails, the PPS structure keeps slice_group_id
pointer uninitialized, leading to a segmentation fault when the memory is
freed.

This patch prevents this by initializing the slice_group_id before the PPS
parsing.

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>

https://bugzilla.gnome.org/show_bug.cgi?id=754845
2015-09-15 19:36:37 +02:00
Jan Schmidt
b0194a1dc5 multiview: initial attempt at stereo/multiview support
Add support for marking caps and buffers for multiview or
stereoscopic output.

https://bugzilla.gnome.org/show_bug.cgi?id=750835
2015-08-31 17:51:56 +02:00
Gwenole Beauchesne
52adebe779 decoder: h264: track previous reference frames.
Improve closure of gaps in frame_num by strictly following and trying
to fill them with previous reference frames. So, they are now tracked
thus avoiding insertion of dummy ("greenish") frames.
2015-07-20 15:25:46 +02:00
Gwenole Beauchesne
06147100f2 decoder: h264: fix integration of second field into the DPB.
If the new picture to be added to the DPB is not a first field, then
it shall be the second field of the previous picture that was added
before.

This removes the need for dpb_find_picture() now that we track the
immediately preceding decoded picture, in decode order.
2015-07-20 15:25:46 +02:00
Gwenole Beauchesne
d4ccae8398 decoder: h264: fix closure of "other-field" gap.
When a dummy "other-field" is inserted, it is assumed to inherit the
reference flags from the first field, and the sliding window decoded
reference picture marking process is also executed so that corrupted
frames are moved out as early as possible.

While doing so, we also try to output frames that now contain a single
valid field picture, prior to inserting any other picture into the DPB.
Note: this may be superfluous currently based on the fact that dpb_add()
combines the two most recent pairable fields, but this process would be
further simplified later on.
2015-07-20 15:25:46 +02:00
Gwenole Beauchesne
80a7ab0959 decoder: h264: track corrupted frames.
Mark the picture as "corrupted" if it is reconstructed from corrupted
references or if those references are fake, e.g. resulting from lost
frames.

This is useful for notifying the upper layer, or downstream elements,
that the decoded frame may contain artefacts.

https://bugzilla.gnome.org/show_bug.cgi?id=703921
2015-07-20 15:25:46 +02:00
Gwenole Beauchesne
d2791a7844 decoder: h264: fix uninitialized variables in avcC mode.
Fix uninitialized variables when decoding SPS and PPS NAL units from
"codec-data" buffers. This is particularly important when seeking ops
are involved, and the new persistent states are used more often.

https://bugzilla.gnome.org/show_bug.cgi?id=750094
2015-06-02 11:50:56 +02:00
Gwenole Beauchesne
5abd2b90b6 decoder: h264: add initial support for loss of pictures.
Implement decoding process for gaps in frame_num (8.5.2). This
also somewhat supports unintentional loss of pictures.

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

Original-patch-by: Wind Yuan <feng.yuan@intel.com>
[fixed derivation of POC, ensured clone is valid for reference,
 actually fixed detection of gaps in FrameNum by PrevRefFrameNum]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2015-05-28 10:51:44 +02:00
Gwenole Beauchesne
8dd93e9c8a decoder: h264: add support for missing first field.
Try to identify missing first fields too, thus disregarding any
intermediate gaps in frames. We also assume that we keep the same
field sequence, i.e. if previous frames were in top-field-first
(TFF) order, then so are subsequent frames.

Note that insertion of dummy first fields need to operate in two
steps: (i) create the original first field that the current field
will inherit from, and (ii) submit that field into the DPB prior
to initializing the current (other) field POC values but after any
reference flag was set. i.e. copy reference flags from the child
(other field) to the parent (first field).

https://bugzilla.gnome.org/show_bug.cgi?id=745048
2015-05-28 10:51:43 +02:00
Gwenole Beauchesne
efaadfc7c0 decoder: h264: add support for missing second field.
Interlaced H.264 video frames always have two fields to decode and
display. However, in some cases, e.g. packet loss, one of the field
can be missing. This perturbs the reference picture marking process,
whereby the number of references available in DPB no longer matches
the expected value.

This patch adds initial support for missing field within a decoded
frame. The current strategy taken is to find out the nearest field,
by POC value, and with the same parity.

https://bugzilla.gnome.org/show_bug.cgi?id=745048
2015-05-28 10:51:43 +02:00
Gwenole Beauchesne
4776138d4a decoder: h264: improve tracking of "top-field-first" flag.
Try to maintain a "top-field-first" (TFF) flag, even if the H.264 standard
does not mandate it. This will be useful for tracking missing fields, and
also for more correct _split_fields() implementation for frames in the DPB.
2015-05-28 10:51:43 +02:00
Gwenole Beauchesne
b4e920843b decoder: h264: skip all pictures prior the first I-frame.
Don't try to decode pictures until the first I-frame is received within
the currently active sequence. There is no point is decoding and then
displaying frames with artifacts.
2015-05-28 10:51:43 +02:00
Gwenole Beauchesne
6229ad4f7f decoder: h264: fix processing of EOSEQ NAL.
Fix decoding of end_of_seq() NAL unit so that to not submit the current
picture for decoding again. This is pretty vintage code that dates back
before the existing of the whole decoder units machinery.

One issue that could be arising if that code was kept is that we could
have submitted a picture, and subsequently a GstVideoCodec frame, twice.
Once without the decode_only flag set, and once with that flag set. The
end result is that the GstVideoDecoder would release the codec frame
twice, thus releasing stale data.

In short, the piece of code that is removed by this patch is for once
completely obsolete for a while, and secondly error-prone in corner
cases.
2015-05-28 10:51:43 +02:00
Wind Yuan
a89a8cf1e3 decoder: add utility function to clone picture objects.
https://bugzilla.gnome.org/show_bug.cgi?id=703921

Signed-off-by: Wind Yuan <feng.yuan@intel.com>
[added cosmetic changes, fixed propagation of "one-field" flag to
 children, fixed per-codec clone modes (h264)]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2015-05-28 10:51:43 +02:00
Víctor Manuel Jáquez Leal
c9f0807752 decoder: cast GST_VAAPI_DECODER_STATUS_DROP_FRAME
Since GST_VAAPI_DECODER_STATUS_DROP_FRAME is not part of the enum
GstVaapiDecoderStatus, we need to cast it to avoid compiler complains.

https://bugzilla.gnome.org/show_bug.cgi?id=747312
2015-04-08 16:20:55 +02:00
Víctor Manuel Jáquez Leal
671b1ea305 Fix compiler warnings
This patch fixes some warnings that gcc 4.9 reports.

https://bugzilla.gnome.org/show_bug.cgi?id=744411
2015-02-18 11:46:11 +02:00
Gwenole Beauchesne
8f71f74c5d decoder: h264: add initial support for repeat-first-field (RFF) flag.
Use the SEI pic_timing() message to track and propagate down the repeat
first field (RFF) flag. This is only initial support as there is one
other condition that could induce the RFF flag, which is not handled
yet.
2014-11-14 10:11:41 +01:00
Gwenole Beauchesne
a4048a9d6b decoder: h264: fix picture ordering count type 0 with previous MMCO5.
Fix the decoding process for picture order count type 0 when the previous
picture had a memory_management_control_operation = 5. In particular, fix
the actual variable type for prev_pic_structure to hold the full bits of
the picture structure.

In practice, this used to work though, due to the underlying type used to
express a gboolean.
2014-11-14 10:11:41 +01:00
Gwenole Beauchesne
415d5df7ee decoder: h264: fix detection of top-field-first (TFF) flag.
Use the SEI pic_timing() message to track the pic_struct variable when
present, or infer it from the regular slice header flags field_pic_flag
and bottom_field_flag. This fixes temporal sequence ordering when the
output pictures are to be displayed.

https://bugzilla.gnome.org/show_bug.cgi?id=739291
2014-11-14 10:11:41 +01:00
Gwenole Beauchesne
b5f1bdd59a decoder: h264: detect incorrectly paired fields in frames.
When a DPB flush is required, e.g. at a natural and of stream or issued
explicitly through an IDR, try to detect any frame left in the DPB that
is interlaced but does not contain two decoded fields. In that case, mark
the picture as having a single field only.

This avoids a hang while decoding tv_cut.mkv.
2014-07-03 14:56:26 +02:00
Gwenole Beauchesne
a3e49d6d13 decoder: h264: simplify the DPB output process.
Simplify the dpb_output() function to exclusively rely on the frame store
buffer to output, since this is now always provided. Besides, also fix
cases where split fields would not be displayed.

This is a regression from f48b1e0.
2014-07-03 14:56:23 +02:00
Gwenole Beauchesne
cba9b97300 decoder: h264: fix memory leak in PPS.
Cope with latest changes from codecparsers/h264. It is now required
to explicitly clear the GstH264PPS structure as it could contain
additional allocations (slice_group_ids).
2014-07-01 17:18:08 +02:00
Gwenole Beauchesne
8bdef56cd4 decoder: h264: decode current picture earlier.
Slightly optimize decoding process by submitting the current VA surface
for decoding earlier to the hardware, and perform the reference picture
marking process and DPB update process afterwards.

This is a minor optimization to let the video decode engine kick in work
earlier, thus improving parallel resources utilization.
2014-06-30 19:13:25 +02:00
Gwenole Beauchesne
f48b1e0cd6 decoder: h264: fix output of second field when first field is not in DPB.
Fix decoding of interlaced streams where a first field (e.g. B-slice)
was immediately output and the current decoded field is to be paired
with that former frame, which is no longer in DPB.

https://bugzilla.gnome.org/show_bug.cgi?id=701340
2014-06-30 19:13:25 +02:00
Gwenole Beauchesne
a208a80c29 decoder: h264: slightly optimize the process to detect new pictures.
Optimize the process to detect new pictures or start of new access
units by checking if the previous NAL unit was the end of a picture,
or the end of the previous access unit.
2014-06-30 11:51:59 +02:00
Gwenole Beauchesne
8ed129b8bd decoder: h264: handle access unit ("au") optimization.
Optimize parsing when buffers are supplied with access unit alignment.
This helps determining faster when the end of an access unit is reached.
2014-06-30 11:51:57 +02:00
Gwenole Beauchesne
850d3d6a4d decoder: h264: fix tracking of DPB size changes.
Add support for MVC streams with multiple SPS and subset SPS headers
emitted regularly, e.g. at around every I-frame. Track the maximum
number of views in ensure_context() and really reset the DPB size to
the expected value, always. i.e. even if it decreased. dpb_reset()
only cares of ensuring the DPB allocation.
2014-06-28 07:41:00 +02:00
Gwenole Beauchesne
9169c520cb decoder: h264: fix the DPB compaction process.
Fix the compaction process when the DPB is cleared for a specific
view, i.e. fix the process of filling in the holes resulting from
removing frame buffers matching the current picture.
2014-06-27 20:44:24 +02:00
Gwenole Beauchesne
bea0d07042 decoder: h264: fix marking of non-reference picture into DPB.
Fix search for a picture in the DPB that has a lower POC value than
the current picture. The dpb_find_lowest_poc() function will return
a picture with the lowest POC in DPB and that is marked as "needed
for output", but an additional check against the actual POC value
of the current picture is needed.

This is a regression from 1c46990.

https://bugzilla.gnome.org/show_bug.cgi?id=732130
2014-06-25 22:38:35 +02:00
Gwenole Beauchesne
8db72147c7 decoder: h264: fix DPB clear when no decoding actually started.
Fix dpb_clear() to clear previous frame buffers only if they actually
exist to begin with. If the decoder bailed out early, e.g. when it
does not support a specific profile, that array of previous frames
might not be allocated beforehand.
2014-06-19 17:08:47 +02:00
Sreerenj Balachandran
cb9f98f0d5 decoder: h264: add support for NALU "alignment" optimization.
We can avoid scanning for start codes again if the bitstream is fed
in NALU chunks. Currently, we always scan for start codes, and keep
track of remaining bits in a GstAdapter, even if, in practice, we
are likely receiving one GstBuffer per NAL unit. i.e. h264parse with
"nal" alignment.

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

[use gst_adapter_available_fast() to determine the top buffer size]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-06-19 15:29:12 +02:00
Gwenole Beauchesne
95c781c34f decoder: h264: fix caps to report interlace-mode accordingly.
The `vaapipostproc' element could never determine if the H.264 stream
was interlaced, and thus always assumed it to be progressive. Fix the
H.264 decoder to report interlace-mode accordingly, thus allowing the
vaapipostproc element to automatically enable deinterlacing.
2014-06-19 15:13:04 +02:00
Gwenole Beauchesne
799d7b7d0e decoder: h264: cope with new gst_h264_quant_matrix_*() interfaces.
New gst_h264_quant_matrix_*_get_raster_from_zigzag() were renamed
from gst_h264_video_quant_matrix_*_get_raster_from_zigzag().
2014-06-13 11:36:56 +02:00
Gwenole Beauchesne
c65aec1aa6 decoder: h264: factor out DPB pruning for MVC.
Factor out the removal process of unused inter-view only reference
pictures from the DPB, prior to the possible insertion of the current
picture.

Ideally, the compiler could still opt for generating two loops. But
at least, the code is now clearer for maintenance.
2014-06-10 18:33:59 +02:00
Gwenole Beauchesne
63fde28dfd decoder: h264: clean-ups.
Fix GST_VAAPI_PICTURE_IS_{INTER_VIEW,ANCHOR}() definitions to use
the base GST_VAAPI_PICTURE_FLAG_IS_SET() macro.
2014-06-10 18:33:59 +02:00
Gwenole Beauchesne
428b038dba decoder: h264: improve pruning of unused MVC inter-view frames.
Improve process for the removal of pictures from DPB before possible
insertion of the current picture (C.4.4) for H.264 MVC inter-view only
reference components. In particular, handle cases where picture to be
inserted is not the last one of the access unit and if it was already
output and is no longer marked as used for reference, including for
decoding next view components within the same access unit.
2014-06-10 18:33:59 +02:00
Gwenole Beauchesne
42ab3e0669 decoder: h264: improve DPB bumping process for MVC.
While invoking the DPB bumping process in presence of many views,
it could be necessary to output previous pictures that are ready,
in a whole. i.e. emitting all view components from the very first
view order index zero to the very last one in its original access
unit; and not starting from the view order index of the picture
that caused the DPB bumping process to be invoked.

As a reminder, the maximum number of frames in DPB for MultiView
High profile with more than 2 views is not necessarily a multiple
of the number of views.

This fixes decoding of MVCNV-4.264.
2014-06-10 18:33:59 +02:00