Commit graph

93 commits

Author SHA1 Message Date
Víctor Manuel Jáquez Leal
078560e70a v4l2: use GstV4l2Error in gst_v4l2_open()
gst_v4l2_open() is called by gst_v4l2_device_provider_probe_device(),
where the GstV4l2Object is created without an associated GstElement.

If gst_v4l2_open() fails, it raises a bus message, but without an
element, a precondition check fails on
gst_element_message_full_with_details() generating a crash if running
with fatal-warnings debug mode.

GstV4l2Error is a helper to raise error bus messages when it is
appropiated. This patch changes the direct bus messages to this
helper, and the elements will actually send the error message.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/694>
2020-08-11 01:44:17 +00:00
Xavier Claessens
c187684b78 v4l2: Do not renegotiate if only framerate changed
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/602>
2020-07-03 18:10:14 +00:00
Jordan Petridis
3e2420361a Use gst_element_class_set_metadata when passing dynamic strings
gst_element_class_set_metadata is meant to only be used with
static or inlined strings, which isn't the case for the 2 elements
here resulting in use-after-free later on.

https://gstreamer.freedesktop.org/documentation/gstreamer/gstelement.html?gi-language=c#gst_element_class_set_static_metadata

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/622>
2020-06-11 20:39:33 +03:00
Nicolas Dufresne
d93664d65d v4l2: codec: Fix GValue leak
The levels and profiles probe function returned a dynamically allocated GValue
that was leaked. Simplify this by using a stack allocated GValue and a boolean
return value.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/599>
2020-05-22 19:11:47 +00:00
Nicolas Dufresne
8e3184a213 v4l2videodec: Increase internal bitstream pool size
This patch will now set the maximum of buffers to 32, allowing to grow the
pool for drivers that supports that and will respect the minimum buffers
reported by the driver. This was made to fix a stall with the virtio CODEC
driver.

Fixes #672
2020-04-15 20:19:48 +00:00
James Cowgill
51b83d5ca1 v4l2videodec: ensure pool exists before orphaning it
In commit e2ff87732d ("v4l2videodec: support orphaning") support for
orphaning the capture buffer pool was added when the format is
renegotiated. However, the commit forgot to check that a pool existed
before doing this. This is needed because it's possible for the format
to be renegotiated before a capture pool is allocated, which would
result in trying to orphan a NULL pool and lead to a NULL pointer
dereference.

Fix this by checking a pool exists first. If the pool doesn't exist,
there are no buffers to be reclaimed, so skip the allocation query in
that case.
2019-10-29 14:46:22 +00:00
Kevin Song
9d42b2dd5d v4l2videodec: Check stop in flush() to avoid race condition.
Backward playback will drain and flush every frame. Stop playback
when backward playback have race condition between exit thread and
streaming thread flush. Add one check to avoid it.

Fixes #639
2019-10-11 12:27:12 +00:00
Aaron Boxer
46989dca96 documentation: fix a number of typos 2019-10-05 22:38:11 +00:00
Philipp Zabel
5c8d8723d2 v4l2: Add MPEG-2 profile and level support
Add support for V4L2 MPEG-2 decoders reporting supported profiles and
levels.
2019-09-27 08:47:20 +02:00
Seungha Yang
dbb4849a32 v4l2: Remove misleading comments
gst_pad_template_new() does not take ownership of the caps
2019-07-09 19:51:20 +09:00
Song Bing
f49d610ebe v4l2videodec: Fix drain() function return type
Return right type for drain() function.
2019-06-24 14:43:21 +00:00
Philippe Normand
6ce195e9d1 v4l2: Profile and level probing support for encoders and decoders
There used to be some profile/level support in encoders. This code was moved to
GstV4l2Codecs and is now also used for decoders. The caps templates for the
H.264, H.265, MPEG4, VP8 and VP9 encoders and decoders should now reflect the
profiles and levels advertised by the kernel.
2019-06-05 10:23:40 +01:00
Guillaume Desmottes
443c16e1e3 v4l2: fix use after free when handling events
The sink_event parent function may consume the event so we shouldn't use
it after having calling it.
2019-04-16 14:53:15 +05:30
Philipp Zabel
e2ff87732d v4l2videodec: support orphaning
Recent kernels allow REQBUFS(0) on a queue that still has buffers in
use (mmapped or exported via dmabuf), orphaning all buffers on the queue.
If this is supported, the v4l2videodec element does not have to send a
drain request downstream.
2019-04-05 16:01:55 +00:00
Philippe Normand
3296a4b7e2 v4l2: Set Hardware classifier on video decoders 2019-03-18 10:51:07 +00:00
Matthew Waters
0acbf40060 v4l2dec: also remove the colorimetry and chroma-site fields
If a different format is chosen, then these values are incorrect.
2019-02-26 07:04:54 +00:00
Song Bing
1dc6881a13 v4l2videodec: Add HEVC decoder support
https://bugzilla.gnome.org/show_bug.cgi?id=771686
2018-09-13 20:48:09 -04:00
Nicolas Dufresne
2510b5937d v4l2videodec: Move capture probe after input format is set
This is to support Amlogic CODEC driver which does not provide a full
list of formats when the driver is initially opened. GStreamer does
not strictly need this full list initially, but only later, in order
to negotiate with downstream if multiple format can be selected.

With this change, we will no longer probe twice the device, since the
probed list can be directly used for negotation.
2018-09-13 20:48:09 -04:00
Ezequiel Garcia
7f42b12e8c v4l2: Add a debug message beforing waiting for codec stop
Add a debug message right before waiting for the driver.
This is useful in order to debug drivers without a properly
implemented decoder or encoder stop command.
2018-09-13 20:48:09 -04:00
Ezequiel Garcia
944debd3db v4l2: Add FWHT codec support
The recently added vicodec (virtual codec) V4L driver
uses the Fast Walsh-Hadamard Transform for encoding
and decoding.

Add support for it.
2018-09-13 20:48:09 -04:00
Nicolas Dufresne
c87f9eb37b v4l2videodec: Protect double calls to set_format()
In some cases, set_format() may get called twice before the output
format is set. Running an allocation query in this case is both not
needed and will cause assertion due tot he NULL caps.
2018-07-09 14:01:00 -04:00
Michael Tretter
35ab185d75 v4l2videodec: do not call streamon while pool is flushing
gst_v4l2_buffer_pool_flush() executes streamoff for the output, but
streamoff->streamon for the capture of the decoder.
gst_v4l2_buffer_pool_streamon() on capture assumes that is able to
resurrect the buffers from the pool, but acquiring buffers fails if the
buffer pool is still flushing.

The decoder needs to stop flushing the pools before calling
gst_v4l2_buffer_pool_flush() to restart the v4l2 device. Otherwise
starting the decoding thread might fail, because there are no buffers in
the capture pool.

This fixes a regression that was introduced in 97985a335c
("v4l2videodec: Add dynamic resolution change support").

https://bugzilla.gnome.org/show_bug.cgi?id=796681
2018-06-27 16:32:23 -04:00
Edward Hervey
e555596d48 v4l2: Fix typo in debug messages
It's a decoder, not an encoder :)

https://bugzilla.gnome.org/show_bug.cgi?id=795941
2018-05-12 08:04:03 +02:00
Guillaume Desmottes
2bbe877a6e v4l2: rely on gst_v4l2_dup() to set no_initial_format and keep_aspect
gst_v4l2_dup() will now take care of setting
v4l2capture->no_initial_format and keep_aspect instead of doing it
manually.

Fix a typo as keep_aspect was set twice on v4l2output but never on
v4l2capture.

https://bugzilla.gnome.org/show_bug.cgi?id=795028
2018-04-26 15:36:16 -04:00
Peter Seiderer
d2f9040e1d v4l2videodec: add property set/get PROP_CAPTURE_IO_MODE error handling
https://bugzilla.gnome.org/show_bug.cgi?id=791841
2018-01-12 09:21:18 -05:00
Peter Seiderer
2cd772b97a v4l2videodec: fold property set/get PROP_OUTPUT_IO_MODE case into default
https://bugzilla.gnome.org/show_bug.cgi?id=791841
2018-01-12 09:21:18 -05:00
Nicolas Dufresne
97985a335c v4l2videodec: Add dynamic resolution change support
This implements a "big hammer" reallocation method. We effectively
drain and stop both side of the decoder and restart. This though is
the most generic method. This change should enable on most drivers
adaptive streaming.

https://bugzilla.gnome.org/show_bug.cgi?id=752962
2018-01-08 17:16:22 -05:00
Nicolas Dufresne
e575e4eda8 v4l2object: Use a debug object for tracing
This way we can pass the pad name instead of the element for tracing
which helps identifying which v4l2object is used withing M2M element
like decoder, encoder and transform. For the reference, pads are name
<parent-name>:<pad-name>.
2017-12-13 14:42:25 -05:00
Philipp Zabel
5e05cadb17 v4l2videodec: Handle drivers that only round up height
Commit 1f31715c98 ("v4l2videodec: use visible size, not coded size,
for downstream negotiation filter") added support for removing the
padding obtained as the difference between width/height from G_FMT and
visible width/height from G_SELECTION from the probed caps obtained
via TRY_FMT.
This patch fixes the padding removal for drivers that only round up
height, but not width, to the padded frame size. This might happen
because horizontal padding can be handled by line stride (bytesperline),
but there is no such thing as plane stride in the V4L2 API for
single-buffer planar formats.

https://bugzilla.gnome.org/show_bug.cgi?id=791271
2017-12-06 14:01:02 -05:00
Nicolas Dufresne
cebb5baaa6 v4l2videoenc/dec: Don't leak template caps 2017-10-07 17:33:41 -04:00
Nicolas Dufresne
fb26575b73 v4l2videodec: Don't leak codec name 2017-09-19 17:55:58 -04:00
Nicolas Dufresne
1f902e2f6e v4l2bufferpool: Don't stop streaming when pool is flushing
The purpose of being able to flush the buffer pool is only to
unlock any blocked operation. Doing streamoff/streamon had the
side effect of turning off and on the camera. As we do a flush_start
/ flush_stop sequence when shutting down, that would cause a really
quick sequence of streamoff/streamon/streamoff/close which was
causing some cameras to stop working.

https://bugzilla.gnome.org/show_bug.cgi?id=783945
2017-09-19 17:33:35 -04:00
Nicolas Dufresne
0e9fe263ca v4l2: Enable VP9 format
This was missing, preventing the encoder and decoder to work
properly. This also adds support for camera that would produce
VP9 (if that exists).
2017-08-02 17:13:55 -04:00
Nicolas Dufresne
1762c2e713 v4l2: Ignore register issue and keep probing
Don't stop registering the other dynamic plugins if one registration
fails.
2017-07-27 12:12:00 -04:00
Nicolas Dufresne
31d8a1d929 v4l2: Add run-time environment to enable libv4l2
The library has started preventing a lot of interesting use cases,
like CREATE_BUFS, DMABuf, usage of TRY_FMT. As the libv4l2 is totally
inactive and not maintained, we decided to disable it. As a convenience
we added a run-time environment that let you enable it for testing.

  GST_V4L2_USE_LIBV4L2=1

This of course only works if you have enabled libv4l2 at build time.
2017-07-24 14:19:02 -04:00
Nicolas Dechesne
52c017caca v4l2videodec: add some useful debug messages
Add a couple of useful debug traces , they happened to be useful to
debug/investigate a 4K video playback issue with v4l2, so let's make these
changes more permanent.

Signed-off-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>

https://bugzilla.gnome.org/show_bug.cgi?id=785109
2017-07-19 10:25:11 -04:00
Nicolas Dufresne
bec03858fa v4l2: Merge v4l2_calls.h into gstv4l2object.h
First step of a larger cleanup, all function from v4l2_calls are in fact
methods on GstV4l2Object. This split makes the code really confusing.
This also remove no longer unused macros.
2017-07-17 20:48:28 -04:00
Nicolas Dufresne
06424c438e v4l2: Don't probe for unneeded format
For v4l2videodec/enc, we generate elements per formats, and in
this case we can speed up the start up by only probing the format
we care about.
2017-07-14 13:31:30 -04:00
Nicolas Dufresne
724a3ceec5 v4l2videodec: Implement stable element names
Before that, each m2m node would be wrapped as a single, multi-format
decoder element. As a unique name was needed, we where using the device
name, which changes between re-boots. This led to unpredictable element
names. In this patch, we generate an element per codec, using
v4l2<codec>dec name. If there is multiple decoder for the same format,
the following elements will be named v4l2<node><codec>dec.

https://bugzilla.gnome.org/show_bug.cgi?id=784908
2017-07-14 13:31:30 -04:00
Nicolas Dufresne
7dc57e381b v4l2videodec: Remove unused forward declaration
https://bugzilla.gnome.org/show_bug.cgi?id=728438
2017-05-24 14:00:22 -04:00
Thibault Saunier
7b7a809818 v4l2dec: Fix race when going from PAUSED to READY
Running `gst-validate-launcher -t validate.file.playback.change_state_intensive.vorbis_vp8_1_webm`
on odroid XU4 (s5p-mfc v4l2 driver) often leads to:

  ERROR:../subprojects/gst-plugins-good/sys/v4l2/gstv4l2videodec.c:215:gst_v4l2_video_dec_stop: assertion failed: (g_atomic_int_get (&self->processing) == FALSE)

This happens when the following race happens:

- T0: Main thread
- T1: Upstream streaming thread
- T2. v4l2dec processing thread)

[The decoder is in PAUSED state]

T0. The validate scenario runs `Executing (36/40) set-state: state=null repeat=40`
T1- The decoder handles a frame
T2- A decoded frame is push downstream
T2- Downstream returns FLUSHING as it is already flushing changing state
T2- The decoder stops its processing thread and sets `->processing = FALSE`
T1- The decoder handles another frame
T1- `->process` is FALSE so the decoder restarts its streaming thread
T0- In v4l2dec-> stop the processing thread is stopped
NOTE: At this point the processing thread loop never started.
T0- assertion failed: (g_atomic_int_get (&self->processing) == FALSE)

Here I am removing the whole ->processing logic to base it all on the
GstTask state to avoid duplicating the knowledge.

https://bugzilla.gnome.org/show_bug.cgi?id=778830
2017-04-07 11:31:03 -03:00
Nicolas Dufresne
3342d86d9b v4l2videodec: Fix 32bit only printf format
The previous patch was using %llu for 64bits printf, which is 32bit
specific. We also trace the latency in time human readable form now.
2017-04-05 09:46:31 -04:00
Philipp Zabel
1d43f6d852 v4l2videodec: only set latency if the frame duration is valid
If the duration of the v4l2object is GST_CLOCK_TIME_NONE, because the
sink did not specify a framerate in the caps and the driver accepts the
framerate, the decoder element uses GST_CLOCK_TIME_NONE to calculate and
set the element latency.

While this is a bug of the capture driver, the decoder element should
not use the invalid duration to calculate a latency, but print a warning
instead.

https://bugzilla.gnome.org/show_bug.cgi?id=779466
2017-04-05 09:20:19 -04:00
Nicolas Dufresne
462800e9c6 v4l2videodec: Keep part of the input buffer
Instead of completely getting rid of the input buffer, copy
the metadata, the flags and the timestamp into an empty buffer.
This way the decoder base class can copy that information again
to the output buffer.

https://bugzilla.gnome.org/show_bug.cgi?id=758424
2016-06-07 17:03:40 -04:00
Nicolas Dufresne
a0a590369a v4l2videodec: Coding style fixes 2016-06-07 17:02:47 -04:00
Nicolas Dufresne
3b5cac3659 v4l2: Add an error return to _try/_set_format
This way one can easily ignore errors. Previously, error were always
posted ont he bus.

https://bugzilla.gnome.org/show_bug.cgi?id=766172
2016-06-07 17:02:43 -04:00
Philipp Zabel
96d82357f2 v4l2videodec: use decoder stop command instead of queueing empty buffers
Only if the decoder stop command fails, keep queueing empty buffers to
signal end of stream as before.

https://bugzilla.gnome.org/show_bug.cgi?id=733864
2016-06-07 10:49:43 -04:00
Peter Seiderer
ddf7d9d6de v4l2videodec: add gst_v4l2_decoder_cmd helper
https://bugzilla.gnome.org/show_bug.cgi?id=733864
2016-06-07 10:49:43 -04:00
Philipp Zabel
1f31715c98 v4l2videodec: use visible size, not coded size, for downstream negotiation filter
gst_v4l2_probe_caps() returns the coded size, not the visible size. Subtract
the known padding from probed caps with the coded size before using them as
filter for caps negotiation with downstream elements.

https://bugzilla.gnome.org/show_bug.cgi?id=766382
2016-06-06 17:35:47 -04:00
Tim-Philipp Müller
30a3551163 v4l2src: fix indentation 2016-02-19 15:03:41 +00:00