Commit graph

32 commits

Author SHA1 Message Date
Daniel Almeida
9e86ac4a22 v4l2codecs: add wrappers for alpha decode
codecalpha is a new plugin introduced to support VP8/VP9 alpha as
defined in the WebM and Matroska specifications. It splits the stream
into two streams, one for the alpha and one for the actual content,
then it decodes them separately with vpxdec and finally combine the
results as A420 or AV12 (i.e. YUV + an extra alpha plane).

The workflow above is setup by means of a bin, gstcodecalphabin.

This patch simulates the same workflow into the v4l2codecs namespace,
thus using the new v4l2 stateless decoders for hardware acceleration.

This is so we can register the new alpha decode elements only if the
hardware produces formats we support, i.e. I420 or NV12 for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2272>
2021-05-27 17:00:06 -04:00
Nicolas Dufresne
24eda30bd7 v4l2codecs: Fix holding of reference picture buffer
The picture buffer (V4L2 CAPTURE buffer) was being released immediatly
when the request was done. This was problematic since even after the
request is done, the picture buffer might still be used as a reference
and should not be reused for further decoding yet.

This change effectively bind the picture buffer lifetime to the request.
So that if the picture is never showned (decode only frame) or the request
queue is full before the buffer is displayed, the picture buffer will
remain alive.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2142>
2021-04-07 19:00:21 +00:00
Daniel Almeida
4373535bb5 v4l2codecs: gstv4l2decoder.c: Add missing include
Add missing include for sys/ioctl.h so that these warnings dissapear
when compiling:
../subprojects/gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c:179:9:
warning: implicit declaration of function ‘ioctl’
[-Wimplicit-function-declaration]

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2140>
2021-04-06 17:34:18 +00:00
Ezequiel Garcia
010565eb7f v4l2codecs: h264: Add API checks
Check that the V4L2 H264 controls' sizes match
our expectation. If not, then probably there's an API
mismatch which will cause errors or decoding corruption.

Also, print a warning if the kernel version is too old.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1624>
2021-03-02 22:03:34 +00:00
Seungha Yang
95e1ce7e7a v4l2decoder: Small documentation fix
Fixing documentation even though those methods are v4l2codecs plugin internals

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2000>
2021-02-02 04:33:33 +09:00
Nicolas Dufresne
99ebbf72ef v4l2codecs: h264: Enable 1 frame delay on non-live
When doing non-live decoding, enable 1 frame of delay. This will ensure
that we queue the next decoding job before we actually wait for the previous
to complete. This improves throughput notably on RK3399.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
241a490084 v4l2codecs: Add support for render delay
This add support for render delay in the decoder helper.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
88b93416fe v4l2codecs: Coding style fix
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
13a40b1da9 v4l2codecs: Poll inside set_done()
This removes the need for the gst_v4l2_decoder_is_done() helper and
simplify slightly the subclass code.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
1c2f391b57 v4l2codecs: Make request structure ref-counted
This adds a non-thread safe refcount to the GstV4l2Request. This will
allow holding on more then one request in order to implement render
delay. This is made non-thread safe for speed as we know this will all
happen on the same streaming thread.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
3db6f45ca9 v4l2codecs: Rework handling of queues and pending requests
Starting from this patch, all queue and dequeue operation happening
on V4L2 is now abstracted with the request. Buffers are dequeued
automatically when pending requests are marked done and only 1 in-flight
request is now used.

Along with fixing issues with request not being reused with slice
decoders, this change reduces the memory footprint by allocating only
two bitstream buffers.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1881>
2021-01-29 19:44:48 +00:00
Nicolas Dufresne
a3e6d9fc24 v4l2codecs: decoder: Unmark previously pending request
requests are executed in order, so while dequeuing sink buffers for previous
request, also mark these request as no longer pending. This will allow reusing
the request later.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1696>
2020-10-15 13:15:02 -04:00
Nicolas Dufresne
2e3bc60422 v4l2codecs: decoder: Properly remove pending requests
Pass the pointer instead of NULL in order to find and remove properly any
pending request from the queue. This coding error was leading to use after
free in error and early exit cases.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1696>
2020-10-15 13:14:57 -04:00
Nicolas Dufresne
1bef43f9d4 v4l2decoder: Track pending request
With the asynchronous slice decoding, we only queue up to 2 slices
per frames. That side effect is that now we are dequeuing bitstream
buffers in both decoding and presentation order. This would lead to
a bitstream buffer from a previous frame being dequeued instead of
the expected last slice buffer and lead to us trying to queue an
already queued bitstream buffer.

We now fix this by tracking pending requests. As request are executed
in decoding order, we marking a request done, we can effectively
dequeue bitstream buffer from all previous request, as they have been
executed already.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1395>
2020-07-02 12:21:51 -04:00
Nicolas Dufresne
a88e63dd2f v4l2decoder: Improve debug tracing
Add some missing traces and move per-slice operation to TRACE level to
reduce the noise level.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1395>
2020-07-02 12:21:51 -04:00
Nicolas Dufresne
d5a205cff4 v4l2decoder: Convert request pool to GstQueueArray
The decoder is not being access from multiple threads, instead it is
always protected by the streaming lock. For this reason, a
GstAtomicQueue for the request pool is overkill and may even introduce
unneeded overhead. Use a GstQueueArray in replacement, the
GstQueueArray is a good fit since the number of item is predictable and
unlikely to vary at run-time.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1395>
2020-07-02 12:21:51 -04:00
Nicolas Dufresne
2160239548 v4l2slh264dec: Request large enough bitstream buffer
The Cedrus driver would otherwise choose 1KB buffer, which is too small.
This follows what some drivers do, which is simply to use the size a
packed raw image would have. Specifications do not really guaranty any minimum
compression ratio.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1268>
2020-05-19 17:51:11 +00:00
Nicolas Dufresne
037730a787 v4l2slh264dec: Add slice based decoder support
This adds support for slice based decoder like the Allwinner/Cedrus driver. In
order to keep things efficient, we hold the sink buffer until we reach the end
of the picture. Note that as we don't know which one is last, we lazy queue the
slices. This effectively introduces one slice latency.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1268>
2020-05-19 17:51:11 +00:00
Nicolas Dufresne
26264163de v4l2decoder: Add legacy non-multiplanar support
The Cedrus driver uses the lagacy buffer type (non-mplane). This automatically
detect and use the right v4l2_buf_type. This also affect code using
v4l2_buffer and v4l2_format structures.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1268>
2020-05-19 17:51:11 +00:00
Nicolas Dufresne
bf9f82c8c3 v4l2codecs: Factor out plugin registration
This introduce a common place for generic functions and factor out the plugin
registration code. This code is nearly identical between implementation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1216>
2020-04-28 22:53:11 +00:00
Nicolas Dufresne
de2cccaa47 v4l2decoder: Relax width/height return value check
The driver adjust the width/height to coded size. This was not an issue for
H264, as the coded size is in the bitstream, but is an issue with VP8.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1216>
2020-04-28 22:53:11 +00:00
Nicolas Dufresne
f5da12bcf5 v4l2decoder: Fix file descriptor leak
A copy paste error was leading to file descriptor leak. This was detected by
Coverity.

CID 1461285
2020-04-07 17:10:08 -04:00
Nicolas Dufresne
e70993bf43 v4l2codecs: Wait for buffers to come back
This code add required mechanism to try and allocate (not implemented yet)
otherwise wait for more buffers. This also comes with mechanism to terminate
the wait on flush or PAUSED_TO_READY transitions.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
09a9ffcda6 v4l2codecs: Implement flushing sequence
This simply consit of cycling through STREAMOFF/STREAMON with stateless
decoders.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
390cbe1f00 v4l2slh264dec: Add output format negotiation
This allow negotiating the output format through caps. Some drivers can
pipeline the decoder buffer through an image processor. This only support
colorspace conversion for now.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
b107c20198 v4l2codecs: Fix bytesused value
Pass the actual amount of bytes we have copied into the bitstream buffer. Also
unmap the memory before queuing.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
3cc6643050 v4l2codecdecoder: Add support for dequeuing buffers
This includings polling of the request and streamon/streamoff.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
a307499437 v4l2decoder: Add helpers to queue buffer and requests 2020-03-31 09:34:05 -04:00
Nicolas Dufresne
d476e6d689 v4l2codec: decoder: Add allocation helper 2020-03-31 09:34:05 -04:00
Nicolas Dufresne
7ae57631d4 v4l2codecs: Implement H264 format negotiation 2020-03-31 09:34:05 -04:00
Nicolas Dufresne
a007e2dd9d v4l2codecs: Add skeleton of H264 decoder
This introduces the skeleton of the H264 decoder. The plugin will list the
devices and register a subclass of the GstV4L2CodecH264Dec base class. The
subclass will pick the required specific information from the GstV4L2Device
stored in the subclass structure.
2020-03-31 09:34:05 -04:00
Nicolas Dufresne
b7762fc332 v4l2codec: Add GstV4L2Deocder helper object
This is a GstObject which will be used to hold on media and video device file
descriptor and provide abstracted ioctl calls with these descriptor. At the
moment this helper contains just enough to enumerate the supported format.
This part will be used by the plugin to register the CODEC specific elements..
2020-03-31 09:34:05 -04:00