Commit graph

42 commits

Author SHA1 Message Date
He Junyan
64b596103a va: Do not use a common parent_class in vabasedec.
We have only one copy of gst_va_base_dec_parent_class inside the
vabasedec, so it can not handle the case when there are multi va
decoders inside one pipeline. The pipeline:

  gst-launch-1.0 filesrc location=xxx.h264 ! h264parse \
      ! vah264dec ! msdkh265enc ! vah265dec ! fakesink

generates a assertion of

"invalid cast from 'GstVaH264Dec' to 'GstH265Decoder"

and gets a crash.

We should keep the parent_class for each decoder type.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2231>
2021-05-10 22:47:11 +08:00
Víctor Manuel Jáquez Leal
5e78c4bafc va: h264dec: remove spurious if validation
The first if checks for caps, thus else doesn't need to recheck for the
opposite.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1999>
2021-02-05 21:24:02 +01:00
Víctor Manuel Jáquez Leal
14c28415b9 va: Remove gst_va_decoder_destroy_buffers()
Since GstVaDecodePicture is destroyed completely with its free() function and
it's used as destroy notify by codecs picture, there's no need to call
gst_va_decoder_destroy_buffers() externally, since the codecs base classes
destroy the codec picture when it's required.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1841>
2020-11-30 16:53:25 +01:00
He Junyan
f5c7ada98e va: Destroy picture unreleased buffers when finalize.
The current way of GstVaDecodePicture's finalize will leak some
resource such as parameter buffers and slice data.
The current way deliberately leaves these resource releasing logic
to va decoder related function and trigger a warning if we free the
GstVaDecodePicture without releasing these resources.
But in practice, sometimes, you do not have the chance to release
these resource before picture is freed. For example, H264/Mpeg2
support multi slice NALs/Packets for one frame. It is possible that
we already succeed to parse and generate the first several slices
data by _decode_slice(), but then we get a wrong slice NAL/packet
and fail to parse it. We decide to discard the whole frame in the
decoder's base class, it just free the current picture and does not
trigger sub class's function again. In this kind of cases, we do
not have the chance to cleanup the resource, and the resource will
be leaked.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1841>
2020-11-30 13:03:11 +00:00
Seungha Yang
483768cfa7 va: h264dec: Add support for interlaced stream
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 20:20:32 +09:00
Víctor Manuel Jáquez Leal
eadda27dde va: h264dec: implement gst_va_h264_dec_new_field_picture()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:57:35 +09:00
Seungha Yang
215835b201 va: h264dec: Fix picture_height_in_mbs_minus1
Fix for interlaced stream (when sps->frame_mbs_only_flag is equal to one)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:57:35 +09:00
Víctor Manuel Jáquez Leal
a9ae00a2c1 va: h264dec: admit baseline if stream obeys A.2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1812>
2020-11-17 19:57:35 +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
d3d2af6c84 vah264dec: Fix for long term reference picture signalling
Allocate a GArray which is used to fill
VAPictureParameterBufferH264.ReferenceFrames (called per frame),
instead of alloc/free per frame.
Also this commit is to fix the condition where long-term reference
picture is needed for VAPictureParameterBufferH264.ReferenceFrames
entry.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1813>
2020-11-16 15:06:33 +00:00
Seungha Yang
9011a58491 vah264dec: Allow missing reference picture
baseclass might provide reference picture list with null picture.
Ensure picture before filling picture information.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1809>
2020-11-14 16:17:18 +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
He Junyan
caf28d8f12 va: h264dec: Set the padding to VideoAlignment's right.
In our va implemenation, we just use image's info to map the buffer.
The padding info just plays a role as a place holder to expand the
allocation size in caps when decoding size is bigger than display
size. So the padding_right or padding_left does not change the result.
But we find if using padding_left, it is hard to meet the requirement
of gst_video_meta_validate_alignment(), when the video meta's stride
is different from the allocation width.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1698>
2020-10-27 14:18:07 +00:00
Víctor Manuel Jáquez Leal
18444fd993 va: basedec: copy frames logic to decide_allocation()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1673>
2020-10-10 17:18:04 +00:00
Víctor Manuel Jáquez Leal
a6398eca17 va: basedec: add gstvabasedec helper
This is a helper for all decoders.

It is not an abstract subclass, just merely a helper that avoids code
duplication among the decoders.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1673>
2020-10-10 17:18:04 +00:00
Víctor Manuel Jáquez Leal
a0ba72ed50 va: h264dec: set video alignment definition earlier
This patch renames need_cropping variable to need_videoalign which is clearer
with its function. And now GstVideoAlignment is part of GstVaH264Dec structure,
so it can be set earlier.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1673>
2020-10-10 17:18:04 +00:00
Víctor Manuel Jáquez Leal
fbbf9c629a va: allocator: add _set_format() and _get_format()
Since allocators keep an available memory queue to reuse, video format and usage
hint are now persistant while allocator's memories are around.

This patch adds _set_format() and _get_format() for both VA allocators.

_set_format() validates if given format can be used or reused. If no allocated
surface previously it creates a dummy one to fetch its offsets and
strides. Updated info is returned to callee.

GstVaPool uses _set_format() at config to verify the allocator capacity and to
get the surfaces offsets and strides, which are going to be used by the video
meta.

Allocator extracted caps are compared with caps from config and if they have
different strides or offsets, force_videometa is set.

A new bufferpool method gst_va_pool_requires_video_meta() is added return the
value of force_videometa. This value is checked in order to know if decoders
need to copy the surface if downstream doesn't announce video meta support.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1667>
2020-10-09 16:34:57 +02:00
Víctor Manuel Jáquez Leal
64eb0f0ed2 va: dec, vpp: don't get buffer size from allocators
Since buffer size is now ignored by bufferpool there's no need to get tha value
from the allocator.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1667>
2020-10-09 16:34:56 +02:00
Víctor Manuel Jáquez Leal
666eedc215 va: caps: centralize caps feature discovering
These function were repeated in the different implemented
elements. This patch centralize them.

The side effect is dmabuf memory type is no longer checked with the
current VAContext, but assuming that dmabuf is a consequence of caps
negotiation from dynamic generated caps templates, where the context's
memory types are validated, there's no need to validate them twice.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1644>
2020-10-04 15:22:04 +00:00
He Junyan
709bec8f07 va: Implement the VA vp8 decoder.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1587>
2020-09-25 17:07:30 +08:00
He Junyan
410938a069 va: util: make the _format_changed a common decoder function.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1587>
2020-09-25 17:07:05 +08:00
Víctor Manuel Jáquez Leal
00b73cfddd va: h264dec: allocate output buffers according DPB size
Instead of allocating the maximal number of references for output
buffers, this patch reduces the memory foot print in many cases by
just allocating the output buffers required for the DPB.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1595>
2020-09-24 20:35:49 +02:00
Víctor Manuel Jáquez Leal
755d769045 va: decoder: store output buffer rather than surface
GstVaDecodePicture stored the processed VASurfaceID, under the
assumption that the bufferpool with keep the referenced buffers, but
this approach is fragil.

This patch changes GstVaDecodePicture to store the output buffer,
which already contains its VASurfaceID, and provides a new method to
retrieve the VASurfaceID directly from picture.

Based on He Junyan <junyan.he@intel.com> patches for
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1587

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1594>
2020-09-24 15:36:06 +02:00
Víctor Manuel Jáquez Leal
b1a1e2d841 va: vah264dec: fix documentation
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1591>
2020-09-23 15:14:21 +00:00
Víctor Manuel Jáquez Leal
9e9e5c72d5 va: h264dec: add documentation
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1585>
2020-09-20 09:21:08 +02:00
Víctor Manuel Jáquez Leal
ad839ada5b va: h264dec: check is pad has fixed caps at caps query
Otherwise it will always reply with the possible driver caps, which
generates problems with Web MSE players.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1583>
2020-09-19 13:00:49 +02:00
Seungha Yang
2fe1afeafa va: h264dec: Don't need to set pts/dts/duration on outputting frame
It will be handled by videodecoder baseclass

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1582>
2020-09-18 23:50:54 +00:00
Víctor Manuel Jáquez Leal
261d6e463a Revert "va: h264dec: set latency"
This reverts commit 3aedef4c86.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1531>
2020-09-14 16:48:31 +00:00
Víctor Manuel Jáquez Leal
c905f6131d va: h264dec: check va allocator at decide allocation
And some code cleanups

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1516>
2020-08-24 19:35:57 +00:00
Víctor Manuel Jáquez Leal
3aedef4c86 va: h264dec: set latency
The min latency is calculated with the maximum number of frames that
precede any frame, if available, and it is lower than the maximum
number of frames in DBP.

The max latency is calculated with the maxium size of frames in DBP.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1500>
2020-08-17 09:32:41 +00:00
Víctor Manuel Jáquez Leal
122a3cc40c va: h264dec: remove spurious comment
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1499>
2020-08-10 15:36:47 +00:00
Víctor Manuel Jáquez Leal
159562faf7 va: h264dec: check return value of gst_va_handle_set_context()
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1499>
2020-08-10 15:36:47 +00:00
Víctor Manuel Jáquez Leal
6cf03b21f6 va: h264dec: log if upstream pool is kept
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1489>
2020-08-04 10:39:05 +02:00
Víctor Manuel Jáquez Leal
f7cfb422f1 va: context: instanciate VA display through GstContext
Add all the machinery to instanciate VA display through GstContext,
thus all va elements can share the same display and the user can set
a custom one.
2020-08-03 19:33:01 +02:00
Víctor Manuel Jáquez Leal
0cc1dccd84 va: h264dec: don't copy frames if VAMemory capsfeature is negotiated
Otherwise the VASurfaceID is lost.
2020-08-03 19:33:01 +02:00
Víctor Manuel Jáquez Leal
aa664a4eca va: h264dec: copy render_device_path in klass
It it's not copied both cdata and klass, the string is lost. Thus
also it's freed from cdata when freeing it.
2020-08-03 19:33:01 +02:00
Víctor Manuel Jáquez Leal
585295e82b va: decoder: remove unused argument
And that changes function's namespace
2020-08-03 19:33:01 +02:00
Víctor Manuel Jáquez Leal
d3ef3d562a va: allocator: get a surface format from a image format
For the allocator to create surfaces with the correct chroma an
fourcc, it should use a surface format, not necessarily the negotiated
format.

Instead of the previous arbitrary extra formats list, the decoder
extracts the valid pixel formats from the given VA config, and pass
that list to the allocator which stores it (full transfer).

Then, when the allocator allocates a new surface, it looks for a
surface color format chroma-compatible with the negotiated image color
format.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1483>
2020-08-03 15:54:45 +00:00
Víctor Manuel Jáquez Leal
1ca39b571d vah264dec: add documentation caps for pad templates
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1387>
2020-07-21 16:15:47 +00: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
Víctor Manuel Jáquez Leal
79d11c2022 va: VA-API H.264 decoder and infrastructure
New plugin with an element for H.264 decoding with VA-API. This novel
approach, different from gstreamer-vaapi, uses gstcodecs library for
state handling.

The code is expected to looks cleaner because it uses VA-API without
further layers or wrappers.

* It uses the first supported DRM device as default VA display (other
  displays will be supported through user's GstContext)
* Requires libva >= 1.6
* No multiview/stereo profiles neither interlaced streams because
  gstcodecs doesn't handle them yet
* It is incompatible with gstreamer-vaapi
* Even if memory:VAMemory is exposed, it is not handled yet by any
  other element
* Caps templates are generated dynamically querying VAAPI, but YV12
  and I420 are added for system memory caps because they seem to be
  supported for all the drivers when downloading frames onto main
  memory, as they are used by xvimagesink and others, avoiding color
  conversion.
* Surfaces aren't bounded to context, so they can grow beyond the DBP
  size, allowing smooth reverse playback.
* There isn't yet error handling and recovery.
* 10-bit H.264 streams aren't supported by libva.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1379>
2020-06-28 11:47:35 +02:00