Sort video device entries with `alphasort` on non-Linux platforms,
as opposed to `versionsort` on Linux.
(`versionsort` is a GNU extension, unavailable on e.g. FreeBSD.)
UI: Fix call to `to_string` on FreeBSD
Previously the switch did not catch all cases issuing a quite large
warning. Also there was a const-ness warning for codecs on ffmpeg 5.0
that this addresses.
Previously we assumed mjpeg was always decoded to 422 but it seems some
cameras provide frames that decode to different pixel formats such as
420.
This change delays setting the obs frame pixel format until after we
have decoded the v4l2 frame.
fixes#5821
The timeout_usec variable is uint64_t, but the log format was set to %ld
(signed long int), so it would sometimes log a nonsensical value. Let's
use $PRIu64 instead, which should be equivalent to %llu (unsigned long
long int).
Fixes#5797.
Instead of trying to open devices /dev/video<0-63> check /dev for
all /dev/videoX devices that are existent in the tree. This allows
finding devices with higher names than 63. E.g. /dev/video100 can
now be found and opened which previously failed.
_GNU_SOURCE #define is introduced for versionsort() which is a GNU
extension.
Fixes#4347.
At least one V4L2 device reports a menu control when queried with
QUERYCTRL yet does not report supporting a single value in its legal
range when queried with QUERYMENU. Such devices are arguably
ill-behaved, but the Linux UVC driver takes no special care to ignore
such pathological controls, so we have to do it ourselves.
Without this patch, a menu control with no valid values would cause
v4l2_control_changed to go into an infinite loop, since every S_CTRL
request on such pathological control properties would always fail,
triggering an additional modification event. By ignoring these
properties altogether, we avoid that problem, and the user benefits by
not having the UI cluttered by a confusing and useless menu control.
It is not possible to run host system executables like modinfo, pkexec,
and modprobe inside a Flatpak sandbox. However, Flatpak provides a way
to run command on the host system: the flatpak-spawn executable.
flatpak-spawn is a tiny helper that, when executed with the '--host'
parameter, talks to the org.freedesktop.Flatpak D-Bus interface to run
and retrieve the return value of the executable. This provides OBS Studio
a way to escape this sandbox limitation without opening large holes in
the sandbox.
Make v4l2's implementation of VirtualCam run system commands using
flatpak-spawn when inside a Flatpak sandbox. The detection of the sandbox
is done by checking the existence of the /.flatpak-info file, which is
created by Flatpak itself, and only exists inside the sandbox. If OBS
Studio is not running inside a Flatpak sandbox, run the exact same command
it used to run before this commit.
Add the permission to talk to the org.freedesktop.Flatpak D-Bus interface
to the Flatpak manifest, so we can run flatpak-spawn with the '--host'
parameter.
Notice that the same constraints apply with and without Flatpak: the host
system needs to have the v4l2loopback kernel module available for the v4l2
implementation of VirtualCam to work.
While the current code only ever calls try_connect() with the input
argument 'device' in the range of 0 and MAX_DEVICES, this adds a check
to ensure that future code does not break the following sprintf.
In addition, use snprintf instead of sprintf to ensure that if anything
breaks, the sprintf does not lead to memory corruption. Again, the new
check should already make sure of that, but the additional effort of
using snprintf instead of sprintf is so low that it is worth to have a
little more security in the future.
Adds frame time multiple based timeout option, instead of the hardcoded
1 second timeout.
Adds optional automatic device stream reset when the device times out.
Helps with devices that "lock up" or "freeze", for example Magewell and
Elgato USB HDMI capture devices.
The automatic reset is by default off and optional. Turning it on can
cause issues for devices that work but drop a lot of frames.
The capture loop errors are now logged as such.
Increased the amount of information logged in debug mode, including
state of all buffers on timeout.
Add device name to all capture loop debug output, especially useful when
debugging issues with multiple v4l2 video streams.
When /bin/sh isn't bash, the previous line always appears to succeed,
and modinfo's output is not redirected, because it actually runs
modinfo in the background (which always succeeds) then opens and closes
/dev/null without doing anything to it. This causes us to always think
that the v4l2loopback module is installed, even when it isn't.
v4l2_outputparm includes unused fields, defined as
__u32 reserved[4]
Accesses to reserved[4] was out of bounds. Fix this and simplify by
just zeroing the entire struct v4l2_streamparm instead.
This commit fixes the case of two recently added attributes of the
v4l2_data struct (in PR #2978). The new attributes were named
"frameRateUnchanged" and "resolutionUnchanged", i.e. using CamelCase
while all other attributes use snake_case. This change changes the
name of the two attributes to snake_case.
This commit adds a basic check to see if the v4l2 stream requires a
restart. This is primarly implemented on the basis of the fact that
the options requiring a restart have values stored in the v4l2_data
structure. A restart is only needed if any of the values have changed
since the last update.
As of 3.17 using find_package_handle_standard_args checks that the name
of the FindXXX file and the first argument are the same case.
Some modules used non-standard variables or the old singular variables
instead of plurals. This normalizes variable usage to the new-style.
Some CMakeLists.txt did custom error checking instead of propagating
find_package errors. These were changes to call find_package with
REQUIRED or without QUIET where needed and shortens the custom status
messages. This helps users who want to enable that functionality see
what precisely wasnt found.
add_control_property() was previously static inline bool, but did not
return a value and failed to build on FreeBSD-CURRENT with Clang 10.0,
with:
error: non-void function 'add_control_property' should return a value
As of 3.17 using find_package_handle_standard_args checks that the name
of the FindXXX file and the first argument are the same case.
Some modules used non-standard variables or the old singular variables
instead of plurals. This normalizes variable usage to the new-style.
Some CMakeLists.txt did custom error checking instead of propagating
find_package errors. These were changes to call find_package with
REQUIRED or without QUIET where needed and shortens the custom status
messages. This helps users who want to enable that functionality see
what precisely wasnt found.
Previous fix in #2547 altered id before they were handed off to
callbacks and v4l2 wont strip its own flags from ids resulting in
invalid ids in the ioctl.
Instead add cleanup section and jump all branches there before looping.
(Jim edit: I'm changing this entire function so that it isn't horrible.)
v4l2_ioctl will clear the V4L2_CTRL_FLAG_NEXT_CTRL flag resulting in
infinite loops for any driver that reported readonly, disabled, or
volitile controls.
As currently all 64bit Linux platforms are respecting LP64
data model and most 32bit platforms are respecting ILP32, we
don't have to discuss pointer size case by case. LP64 is effective
enough to tell pointer size.
This fixes build for armhf and powerpc.
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed. Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.