Commit graph

148 commits

Author SHA1 Message Date
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
Gwenole Beauchesne
e8fe78824b decoder: h264: fix inter-view references array growth.
Let the utility layer handle dynamic growth of the inter-view pictures
array. By definition, setting a new size to the array will effectively
grow the array, but would also fill in the newly created elements with
empty entries (NULL), thus also increasing the reported length, which
is not correct.
2014-06-06 17:58:50 +02:00
Gwenole Beauchesne
60af04901f decoder: h264: reduce ReferenceFrames entries to the essential set.
When decoding Multiview High profile streams with a large number of
views, it is not possible to make the VAPictureParameterBufferH264.
ReferenceFrames[] array hold the complete DPB, with all possibly
active pictures to be used for inter-view prediction in the current
access unit.

So reduce the scope of the ReferenceFrames[] array to only include
the set of reference pictures that are going to be used for decoding
the current picture. Basically, this is a union of all RefPicListX[]
array, for all slices constituting the decoded picture.
2014-06-06 17:34:02 +02:00
Gwenole Beauchesne
e670e36007 decoder: h264: fix MVC inter-view prediction process.
The inter-view reference components and inter-view only reference
components that are included in the reference picture lists shall
be considered as not being marked as "used for short-term reference"
or "used for long-term reference". This means that reference flags
should all be removed from VAPictureH264.flags.

This fixes decoding of MVCNV-2.264.
2014-06-04 19:10:44 +02:00
Gwenole Beauchesne
f36486a1e2 decoder: h264: fix detection of profile changes for MVC.
If the VA driver exposes ad-hoc H.264 MVC profiles, then we have to
be careful to detect profiles changes and not reset the underlying
VA context erroneously. In MVC situations, we could indeed get a
profile_idc change for every SPS that gets activated, alternatively
(base-view -> non-base view -> base-view, etc.).

An improved fix would be to characterize the exact profile to use
once and for all when SPS NAL units are parsed. This would also
allow for fallbacks to a base-view decoding only mode.
2014-06-04 19:08:18 +02:00
Gwenole Beauchesne
f0d3d9cd3c decoder: h264: compute view ids only once per slice.
Optimize lookups of view ids / view order indices by caching the result
of the calculatiosn right into the GstVaapiParserInfoH264 struct. This
terribly simplifies is_new_access_unit() and find_first_field() functions.
2014-05-22 10:13:34 +02:00
Gwenole Beauchesne
abcc8bb7a2 decoder: h264: add support for MVC interlaced streams.
Fix support for MVC Stereo High profile streams with interlaced frames.
Also improve the detection logic of the first field.
2014-05-21 20:04:35 +02:00
Gwenole Beauchesne
5d76afb40d decoder: h264: add MVC profiles compatibility logic.
Add safe fallbacks for MVC profiles:
- all MultiView High profile streams with 2 views at most can be decoded
  with a Stereo High profile compliant decoder ;
- all Stereo High profile streams with only progressive views can be
  decoded with a MultiView High profile compliant decoder ;
- all drivers that support slice-level decoding could normally support
  MVC profiles when the DPB holds at most 16 frames.
2014-05-21 20:04:35 +02:00
Gwenole Beauchesne
8c5e89c298 decoder: h264: add initial support for MVC.
https://bugzilla.gnome.org/show_bug.cgi?id=721772
2014-05-21 20:04:34 +02:00
Gwenole Beauchesne
42b112f8bd decoder: h264: dynamically allocate the DPB.
Dynamically allocate the Decoded Picture Buffer (DPB) and add provisions
for supporting the MVC allocation requirements.
2014-05-21 19:59:52 +02:00
Gwenole Beauchesne
ae1d8267d9 decoder: h264: fix detection of access unit boundaries.
In order to have a stricter conforming implementation, we need to carefully
detect access unit boundaries. Additional operations could be necessary to
perform at those boundaries.
2014-05-21 19:59:52 +02:00
Sreerenj Balachandran
a6215a0757 decoder: h264: detect the first VCL NAL unit of a picture for MVC.
Detect the first VCL NAL unit of a picture for MVC, based on the
view_id as per H.7.4.1.2.4. Note that we only need to detect new
view components.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-05-21 19:59:52 +02:00
Sreerenj Balachandran
e4166f5a91 decoder: h264: properly handle Prefix NAL units.
Always cache the previous NAL unit so that we could check whether
there is a Prefix NAL unit immediately preceding the current slice
or IDR NAL unit. In that case, the NAL unit metadata is copied into
the current NAL unit. Otherwise, some default values are inferred,
tentatively. e.g. view_id shall be set to 0 and inter_view_flag to 1.

[infer default values for slice if previous NAL was not a Prefix]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-05-21 19:59:52 +02:00
Xiaowei Li
79118904a0 decoder: h264: add support for MVC base views.
Allow decoding for base views of MVC encoded streams. For now, just skip
the slice extension and prefix NAL units, and skip non-base view frames.

Signed-off-by: Xiaowei Li <xiaowei.a.li@intel.com>
[fixed memory leak, improved check for MVC NAL units]
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2014-05-21 19:59:52 +02:00
Gwenole Beauchesne
1c46990ecd decoder: h264: simplify storage of decoded picture into DPB.
Factor out process by which the decoded picture with the lowest POC
is found, and possibly output. Likewise, the storage and marking of
a reference decoded, or non-reference decoded picture, into the DPB
could also be simplified as they mostly share the same operations.
2014-05-21 19:59:52 +02:00
Gwenole Beauchesne
a571350dee decoder: h264: minor clean-ups.
Make init_picture_ref_lists() more consistent with other functions
related to the reference marking process by supplying the current
picture as argument.
2014-05-21 19:59:52 +02:00