Commit graph

108 commits

Author SHA1 Message Date
Michael Olbrich c6a7c88fd9 v4l2src: handle resolution change when buffers are copied
When buffers are copied then GST_V4L2_FLOW_RESOLUTION_CHANGE is returned by
gst_v4l2_buffer_pool_process() so do renegotiation here as well.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4980>
2023-07-06 14:59:22 +02:00
Nicolas Dufresne 170dcd58db v4l2: Fix support for left and top padding
In the current implementation, we support for most pixel format left
and top padding by changing the offset in the video meta. Though, to
align driver bytesused to the offset, we recalculate the offset, which
removed the modification we did before.

Instead, save the plane size, and truncate the driver reported bytesused
to the expected size, which ensures that the offsets still match. This
should also fix issues were the buffer size ended up bigger then the
pool size due to driver introduced padding.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4920>
2023-06-28 01:56:05 +00:00
Matthieu Volat d228b8d96f oss: add a GstDeviceProvider plugin
Based on Alsa's GstDeviceProvider structure, relies on sndstat
file for OSS device enumeration but uses already existing utils
to query caps and names.

Reviewed and thanks to @slomo

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4879>
2023-06-27 09:34:33 +03:00
Daniel Morin 6f43bdce49 v4l2src: adding support for bayer 10,12,14,16
- Adding bayer 10,12,14,16 bits components with 16 bits storage. These
  changes only adds capabilities. Capability format string is a complete
  description of the frame and pixels layout. Only mapping LE bayer
  formats as v4l2 only define LE bayer formats.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4852>
2023-06-15 18:41:42 +00:00
Nicolas Dufresne aea74db1a2 v4l2: Sync headers to current media_stage
commit d78b9d6671decdaedb539635b1d0a34f8f5934f8

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3447>
2023-06-15 14:32:32 +00:00
Daniel Morin 6ece5f3b90 v4l2src: fix support for bayer format
- Define a new function that identify if the v4l2object is raw based
on pixel format
- Only consider setting delta flag on buffer if the video is not raw.

Sponsored by Living Optics Ltd.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4848>
2023-06-14 18:32:45 +00:00
ekwange e7cfc1f5bd v4l2: Change to query only up to V4L2_CID_PRIVATE_BASE+V4L2_CID_MAX_CTRLS
Fix to prevent infinite querying.
There are devices that exceed V4L2_CID_PRIVATE_BASE+V4L2_CID_MAX_CTRLS
but do not return EINVAL.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4790>
2023-06-13 13:04:37 +00:00
Hou Qi fe21b750f9 v4l2videodec: treat MPEG 1 format as MPEG 2
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4770>
2023-06-06 15:41:47 +00:00
YURI FEDOSEEV 8dd51501d0 v4l2videoenc: support force keyframe event in v4l2 encoder
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4663>
2023-05-24 12:42:24 +00:00
Nicolas Dufresne 0c9ab49579 v4l2: videodec: Fix stalls on empty buffer
Drivers may signal end of sequence using an empty buffer and LAST buffer
set, or just an empty buffer on certain legacy implementation. When this
occured, we'd send GST_V4L2_FLOW_LAST_BUFFER were the code expected
GST_FLOW_EOS. Stop abusing GST_FLOW_EOS and port all the code to the new
GST_V4L2_FLOW_LAST_BUFFER.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4669>
2023-05-19 23:06:06 +00:00
Shengqi Yu 5da9a8e2f4 v4l2object: fix some errors in probe_caps_for_fromat
1, there is a mistake when print stepwise.max_height, fix it
2, modify the calculation of width and height under the step wise
condition

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4562>
2023-05-18 13:45:11 +00:00
Hou Qi 783ebbeecb v4l2videoenc: fix set format failure when needs reset encoder
In cases that encoder needs to reset format, there is race while draining.
v4l2videoenc finish() sends CMD_STOP command to driver, and desire to return
GST_FLOW_OK. But at this time, encoder CAPTURE may have dequeued the last
buffer and got eos. finish() return value changes to be GST_FLOW_EOS which
causes set format fail. So there is no need to check return value for finish()
when set format.

Also need to flush encoder after draining to make sure flush is finished.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4495>
2023-05-17 17:59:29 +00:00
Piotr Brzeziński 5e45a1b1bd macos: Set activation policy in osxvideosink and glimagesink
Upon creating a window, glimagesink and osxvideosink now set the policy to
NSApplicationActivationPolicyRegular, which lets us show an icon in the Dock
for convenience and appear in the top menu bar like other apps.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4573>
2023-05-12 01:14:44 +02:00
Piotr Brzeziński f60c87769f macos: Remove old NSApp workaround related code
This is no longer needed since the introduction of `gst_macos_main()` in 1.22.
Before that existed, we had a patch for GLib in Cerbero, which did work but made it
impossible to update GLib at all. The code being removed was a fail-safe in case of
running without said patch being applied. It's no longer needed, since for macOS
we just wrap our GStreamer with an NSApplication using `gst_macos_main()`.

Warnings will be displayed if no NSApp/NSRunLoop is found wherever needed,
pointing the user towards using the new API.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4366>
2023-05-11 20:30:19 +02:00
Piotr Brzeziński 560d20a2c0 osxvideosink: fix deadlock upon closing output window
Invoking gst_osx_video_sink_osxwindow_destroy() can currently cause a deadlock
because showFrame() keeps trying to get the same lock as well. Moving the lock
closer to where it's actually needed seems to be enough to fix the issue for now.

Reported-by: Alexande B <abobrikovich@gmail.com>
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4559>
2023-05-11 06:35:02 +00:00
Nicolas Dufresne 3bd43672ec v4l2: device provider: Fix GMainLoop leak
On very quick start/stop, the mainloop may never be run. As a side
effect, our idle stop function is not really being ran, so we can't rely
on that to free the main loop. Simply unref the mainloop when the
thread have completely stop.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4521>
2023-05-03 10:04:58 +00:00
Nicolas Dufresne 51fa6a2656 v4l2: pool: Flush events on capture queue
Unfortunately streamoff does not flush the events, and this can cause all
sort of issues. Flush events on capture queue. We also return
GST_V4L2_FLOW_RESOLUTION_CHANGE in case a resolution change was seen.
This allow skipping streamon(capture) on flush, which could lead to a
configuration miss-match, or failure if the buffers aren't of the right
size.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 15:08:10 -04:00
Nicolas Dufresne 00492234bd v4l2: videodec: Detect flushes while setting up the capture
As we missed the fact we were flushing, we could create and activate
that buffer pool, and wait on it, causing a hang. We detect that we
are flushing by checking the related pad state.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:45:39 -04:00
Nicolas Dufresne c9841a5383 v4l2: bufferpool: Don't copy buffer when flushing
Threshold handling can race with flushing operation. This can lead to
avoidable buffer copies. Simply check and return the flushing status.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:45:16 -04:00
Nicolas Dufresne c6be3d7505 v4l2: videodec: Don't forcibly drain on resolution changes
Let the driver detects the change and reconfigure the capture side
transparently from there. This avoid reallocation of the output buffers,
and eliminates the need to stop and restart the capture task. This is
only happening if the driver have support for this, otherwise the old
behaviour is maintained.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:44:53 -04:00
Nicolas Dufresne f58d5dfd30 v4l2: videodec: Remove the spurious srccaps probe
We don't need to probe the srccaps in set_format() anymore, this
handled already in the capture thread while setting up the capture
queue.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:44:41 -04:00
Nicolas Dufresne 4a53beeb1f v4l2: videodec: Improve few logs
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:44:37 -04:00
Nicolas Dufresne fca61fad4d v4l2: videodec: Only warn of incomplete drain on success
We may have hit an error, or just flushing in order to stop the thread,
in which case, not having drain everything is expected and not a
driver bug.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:44:19 -04:00
Nicolas Dufresne 4dded20929 v4l2: bufferpool: Don't assert when orphaning is not needed
This may happen when shutting down and should not cause
any harm. This removes the associated assert when shutting
down the pipeline, notably with CTRL+C.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:43:36 -04:00
Nicolas Dufresne 66849fbdd1 v4l2: videodec: Wait for source change event
Stop doing capture buffer allocation based on guesses
and wait for the source change event when available.
Unlike stateless decoder, the stateful decoder is not aware of
the coded resolution, and this may lead to the wrong result
even when using TRY_FMT.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:43:16 -04:00
Nicolas Dufresne 5c820862fd v4l2: object: Move the GstPoll into v4l2object
Moves the GstPoll from the buffer pool into v4l2object. This will be
needed to poll for events before the pool has been created.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:43:03 -04:00
Nicolas Dufresne 457dd19a90 v4l2: object: Fix bogus debug objects pointers
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:42:59 -04:00
Nicolas Dufresne 52b916bdf5 v4l2: videodec: Move the capture setup into the processing loop
In previous implementation that job was split between handle_frame and
the processing loop and it wasn't clear if this mechanism was race
free. The capture setup would also be tried for every buffer, which was
not necessary.

This also simplify the handling of SRC_CH event, dropping the unneeded
atomic boolean.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:42:35 -04:00
Nicolas Dufresne 1ca7f6949e v4l2: videodec: Ensure object is inactive on failure
Sprinkle stop() calls in error case to guaranty that the capture object
is inactive on failure. Not doing so could allow some code to be called
in unexpected (and possibly undefined) conditions.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4437>
2023-05-01 13:42:02 -04:00
jeri.li 2b63e30852 v4l2bufferpool: add lock as atomic operation for seek
When seek flush, gst v4l2 buffer pool flush is not atomic which will
lead double enqueue buffer (qbuf) issue, and v4l2 buffer pool qbuf is
also not atomic which will lead no free buffer found in the pool.
1. add lock for calculate enqueue number in streamon function
2. add lock for v4l2 capture end streamoff in pool flush function
3. lock the whole funciton of v4l2 buffer pool qbuf, then the buffer
   pool index and qbuf operation are atomic

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4465>
2023-05-01 15:53:02 +00:00
Haihua Hu 1c488626da v4l2src: fix cannot reuse current caps when fixate caps in negotiation
when regotiation happens, v4l2src will check if it can reuse current caps,
but we need check if current caps is subset of all query caps from downstream
instead of check it with query caps one by one.

Assuming that the current caps is not the subset of first caps from query caps,
it will go to try fmt. when try fmt success, v4l2src will make pending_set_fmt
to TRUE and going to reset.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4500>
2023-05-01 15:05:26 +00:00
Nicolas Dufresne e709e2d97c meson: Add a wrap file for libgudev
And allow fallback to it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4447>
2023-04-19 22:47:19 +00:00
Nicolas Dufresne 2e76371666 v4l2: Fix use after free of fmtdesc part 2
Add missing code in merge commit e890e6e8d8
("v4l2: Fix use after free of fmtdesc"). The v4l2object code was
missing.

Related to https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4317

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4411>
2023-04-13 13:54:32 -04:00
Nicolas Dufresne e890e6e8d8 v4l2: Fix use after free of fmtdesc
The decoder needs to force another enumeration of the format. For
this it was clearing the v4l2object insternal list, leaving a fmtdesc
pointer pointing to freed memory. This patch clears the fmtdesc pointer
that has just been free. It also makes sure the probe function does not
use the cached formats list. The probe function will restore the current
fmtdesc pointer based on the currently configured pixelformat.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4317>
2023-04-13 15:32:14 +00:00
Nicolas Dufresne 3a17200638 v4l2: videodec: Prefer acquired caps over anything downstream
As we don't have anything smart in the fixation process, we may endup with
a format that has a lower bitdepth, even if downstream can handle higher
depth. it is notably the case when negotiating with deinterlace, which places
is non-passthrough caps before its passthrough one. This makes the generic
fixation prefer the formats natively supported by deinterlace element over
the HW 10bit format. As some HW can downscale 10bit to 8bit, this can break
10bit decoding.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4317>
2023-04-13 15:32:13 +00:00
Nicolas Dufresne 89854fd2f3 v4l2: videodec: Remove leading space in comment
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4317>
2023-04-13 15:32:13 +00:00
Alexande B 452c06782e osxvideosink: fix broken aspect ration and frame drawing region
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3336>
2023-04-05 09:48:34 +00:00
Shengqi Yu 8cf21fe744 v4l2object: Add support for YVU420M format
This is a multi-planar format with planes non contiguous in memory. It
is intended to be used only in drivers and applications that support the
multi-planar API.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4287>
2023-03-31 13:42:05 +00:00
Michael Tretter a11f811155 v4l2object: mark jpeg as parsed
Assuming that V4L2 CAPTURE devices always use one buffer per JPEG image, we can
always mark JPEGs provided by a V4L2 element as parsed.

The V4L2 elements require that JPEG images sent to V4L2 OUTPUT devices must
always be parsed.

This is necessary to link a V4L2 CAPTURE device with a V4L2 OUTPUT device
without explicitly marking the stream as parsed or adding a jpegparse into the
pipeline.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4229>
2023-03-21 14:58:15 +00:00
Sebastian Dröge ccad9a7338 plugins: Fix various trivial clang compiler warnings
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4210>
2023-03-18 16:16:55 +02:00
Tim-Philipp Müller 0fc568c6b1 gst-plugins-good: re-indent with GNU indent 2.2.12
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4182>
2023-03-17 03:18:54 +00:00
Khem Raj 817339c4de v4l2: Define ioctl_req_t for posix/linux case
this is an issue seen with musl based linux distros e.g. alpine [1]
musl is not going to change this since it breaks ABI/API interfaces
Newer compilers are stringent ( e.g. clang16 ) which can now detect
signature mismatches in function pointers too, existing code warned but
did not error with older clang

Fixes
gstv4l2object.c:544:23: error: incompatible function pointer types assigning to 'gint (*)(gint, ioctl_req_t, ...)' (aka 'int (*)(int, unsigned long, ...)') from 'int (int, int, ...)' [-Wincompatible-function-pointer-types]
    v4l2object->ioctl = ioctl;
                      ^ ~~~~~

[1] https://gitlab.alpinelinux.org/alpine/aports/-/issues/7580

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3950>
2023-02-14 20:36:28 +00:00
Pawel Stawicki 492d2b6498 v4l2h264dec: Fix Raspberry Pi4 will not play video in application
Ensure object v4l2object->pool will be released by
correctly releasing the temporary thread-safety lock

Fixes issue #1729

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3786>
2023-01-25 16:07:50 +00:00
Tim-Philipp Müller f6950b4537 v4l2: drop use of GSlice
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3695>
2023-01-24 15:25:07 +00:00
Nicolas Dufresne c4cd94f465 v4l2src: Fix crash in renegotiation
This regression was introduce by fix for making buffer pool thread safe. When
we renegotiate, the pool will be setup after we set the format. But the code
has been simplified to only get the pool once before, which caused a null
pointer deref.

Fixes 94ba019 ("v4l2: Fix SIGSEGV on 'change state' during 'format change'")
Related to !3481
Fixes #1626

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3513>
2022-12-02 19:25:52 +00:00
Pawel Stawicki 94ba019397 v4l2: Fix SIGSEGV on 'change state' during 'format change'
Ensure all access to v4l2object->pool imply taking a lock and a hard ref on the pool

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3481>
2022-12-01 12:47:54 +00:00
Elliot Chen 63ff99ca8e v4l2: bypass check some transfer types in colorimetry
v4l2 will report fail for some streams whose colorimetry value such as 2:4:8:3.
Can bypass check these transfer types in colorimetry to avoid error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3440>
2022-11-23 13:06:29 +00:00
Nicolas Dufresne 5980fb76e7 video: Add arbitrary tile dimensions support
In current tile representation, only tiles with power of two
width and height in bytes are supported. This limitation
prevents adding more complex tiles formats.

In this patch, we deprecate tile_ws and tile_hs from GstVideoFormatInfo and
replace if with an array of GstVideoTileInfo. Each plane tiles are then
described with their pixels width/height, line stride and total size.
The helper gst_video_format_info_get_tile_sizes() that depends on the
deprecated API is also being removed. This can simply be removed as it wasn't
in any stable release yet.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3424>
2022-11-18 22:59:29 +00:00
F. Duncanh d77fe9495a v4l2videodec: Fixes three H.264/HEVC ITU conformance tests
Postpone the cleanup of any consecutive sequence of lost frames
which starts at frame 0, until frame 100 is dequeued from driver.

This allows fluster tests JVT/CVWP2_TOSHIBA_E, JVC/CVWP3_TOSHIBA_E
and HEVC/POC_A_Bossen_3 that sends out-of-order frames to successfully
complete  (e.g., test of Amphion vpu driver).

Fixes #1569

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3398>
2022-11-16 10:00:03 +00:00
Jakub Adam 2125dbbd0b ximagesrc: grab the server while capturing screen image
Makes sure screen resolution doesn't change in the middle of the
process.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1562>
2022-10-27 18:42:38 +00:00