0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
Commit Graph

388 Commits

Author SHA1 Message Date
jpark37
fbcb053cfa libobs/util: Use integer math for Windows timing
Cleaner and faster than double math.
2022-02-28 10:11:03 -08:00
jp9000
4f15f1062d libobs/util: Fix rounding error with os_sleepto_ns()
os_sleepto_ns() can occasionally return false on times that the
processor may not have reached yet. The reason is because the
count_target, which converts time_target into a QPC counter, is subject
to a rounding error.

Using numbers I generated from an actual clock cycle on my own CPU, I
can show an example of this occurring: if the clock frequency value is
10000000.0, and you call os_sleepto_ns(42164590320600), it will convert
that number first to a double floating point of its QPC value:
421645903205.99994. Then, because it converts that to a LONGLONG
integer, it of course strips off the decimal point. If you convert
421645903205 *back* to a time value, the new value will be
42164590320500, which is lower than the original value by approximately
100 nanoseconds. While this may seem insignificant, it was apparently
enough to cause the os_sleepto_ns() call in video_sleep() to sometimes
return false despite the current time being lower than the target time,
which would cause it to incorrectly calculate how many frames were
duplicated by subtracting the frame time from the current system time,
divide that by the current frame interval, set the vframe_info.count
value to 0, and thus cause an infinite loop in the encode_gpu()
function because queue_frame now starts returning negative numbers in
perpetuity.

This change fixes some rare reports of users having their video lock up
and disconnect, forcing the user to have to forcibly shut down the
program.

Thanks to Twitch user SNLabat for having the patience to kindly provide
us with a dump file from the freeze, and to Matt for coordinating with
that user to obtain it from them.
2022-02-28 02:07:13 -08:00
jpark37
3a1124a5fd libobs/util: Fix VS static analysis warnings 2022-02-12 15:06:10 -08:00
Jim
03d9bda387 libobs: Deprecate obs object addref functions
Deprecates:
obs_source_addref()
obs_output_addref()
obs_encoder_addref()
obs_service_addref()
obs_scene_addref()

These functions should be considered unsafe and not used. Instead, use:
obs_source_get_ref()
obs_output_get_ref()
obs_encoder_get_ref()
obs_service_get_ref()
obs_scene_get_ref()

These functions return a pointer to the incremented object only if the
object is still valid, otherwise they will return null, indicating that
the object is no longer valid or is unsafe to use.

The reason why this is being done is because certain third party plugins
seem to be using addref, and are somehow managing to call addref on
sources that have already been fully released. For the sake of safety,
almost all usage of these functions within OBS have also been replaced
as well.
2022-01-25 05:20:03 -08:00
jp9000
5a36bd5c9a libobs/util: Add task queue helper
Adds a cool little task queue thing so a dedicated task thread can be
spawned
2021-12-19 11:25:57 -08:00
jp9000
96631d580a libobs/util: Fix end_pos when pushing empty circlebuf front
When pushing to the front of an empty circular buffer, it would not
update the end_pos, so end_pos would be left on 0, and it would break
when trying to push to the back after that. The reason why this bug was
never discovered until now is because breakage only happens when pushing
to the front of an empty buffer, then pushing to the back right after
that.
2021-12-09 20:18:42 -08:00
Richard Stanway
e7aa332d38 libobs: Disable function attributes for SWIG 2021-12-09 03:36:40 +01:00
Richard Stanway
b37acbcbc1 libobs: Add OBS_NORETURN and use it for crash handler
Fixes some analyzers flagging code after a crashing path makes it
impossible to reach.
2021-12-09 02:42:37 +01:00
Tommy Vercetti
19fab46ef7 simde: Update README.libobs 2021-10-24 02:26:17 -07:00
Tommy Vercetti
24a6766543 simde: Don't format simde 2021-10-24 02:26:17 -07:00
Ryan Foster
5f68991911 clang-format: Commit file changes for clang-format 12 2021-10-13 20:00:04 +11:00
jpark37
e69f051736 libobs/util: Improve os_sleepto_ns on Windows
Avoid nanosecond abstraction to reduce math operations.

Replace Sleep(0) with YieldProcessor(). We want the thread to remain
scheduled, the current CPU core to do less work, and the hyperthread
sibling to perform better.

Hacky profiling showed maybe 10-25 µs skid reduction per function call.
I think power/performance gains would be hard to measure, so I haven't
tried, but it would be shocking if they got worse.
2021-10-10 19:13:19 -07:00
jpark37
4ca8cdfc0a libobs/util: Simplify emmintrin.h wrapper macro
Also add WIN32_LEAN_AND_MEAN for external Windows.h include.
2021-10-10 19:12:45 -07:00
Norihiro Kamae
93ee7c4775 libobs/util: Add type test in darray macros for GCC
Previously darray macros did not test the types of arguments so that
developers cannot notice even if a wrong type of a variable is passed.
This commit add a type test that relys on GCC's extension. Since OBS
Studio is built with GCC for Ubuntu, testing only under GCC is
sufficient to catch future bugs.
2021-10-01 13:00:00 +09:00
Norihiro Kamae
ef5e04a621 libobs/util: Add a cast for da_push_back_array argument 2021-10-01 12:59:35 +09:00
jpark37
0c0ff1195f libobs: Simplify util_mul_div64 for x64 on Windows
Use intrinsics to perform 128-bit math directly.
2021-09-29 02:22:01 -07:00
Georges Basile Stavracas Neto
62a2513369 libobs: Make portal inhibitor asynchronous
Currently, libobs contains two inhibitors: the portal-based one, and the
regular one based on each desktop environment's session manager. The portal
inhibitor takes precedence over the session manager one, when available.

Like the session manager inhibitor, the portal inhibitor performs all D-Bus
calls synchronously in the calling thread, which can lead to stalls. This is
not a good practice.

Make the portal inhibitor asynchronous, by using g_dbus_connection_call()
instead of g_dbus_connection_call_sync(). If an uninhibit call is made
before the previous inhibit call finishes, cancel the inhibit call instead.

Fixes obsproject/obs-studio#5314
2021-09-23 07:35:47 -07:00
jpark37
23f43f46db libobs: Support move for mismatched ComPtr 2021-09-15 02:52:12 -07:00
jpark37
f20a7c0540 libobs: Remove dependency on psapi.lib 2021-09-12 14:10:36 -07:00
Tommy Vercetti
aed2211dcd libobs: Restrict emmintrin.h to x86(_64) platform
There is a new toolchain called ARM64EC on MSVC which allows linking x64 objects to ARM64 objects.

It defines multiple architecture preprocessor definition including but not limited to `_M_X64`, `_M_ARM64` and `_M_ARM64EC`.

The original implementation will fail if compiling to ARM64EC.
2021-09-11 15:52:47 -07:00
jpark37
aa342ab6fc libobs/util: Const-correct win_version_compare 2021-09-10 20:19:24 -07:00
jpark37
920a160600 libobs: FIx missing noexcept warnings
warning C26439: This kind of function may not throw. Declare it
'noexcept' (f.6).
2021-09-05 20:35:46 -07:00
jpark37
1eb20ad5aa libobs/util: Improve SetThreadDescription usage
Fix warning about potential passing of NULL to FreeLibrary, and switch
from Kernel32.dll to KernelBase.dll based on MS documentation.
2021-08-30 22:33:17 -07:00
Jim
9b6cc99828
Merge pull request #5180 from jpark37/leaks
Fix a bunch of pthread leaks
2021-08-27 22:55:58 -07:00
tt2468
3e4c275efc libobs/util: Remove old ifdefs
These defs inadvertently redefinine `std::strtoll` in C++ code
that includes the header, causing lots of problems. They only
serve to provide compatability with very old MSVC versions.
As such, they can just be removed entirely.
2021-08-27 08:12:53 -07:00
jpark37
8a43c55918 libobs/util: Fix pthread mutex leaks 2021-08-23 22:57:10 -07:00
jpark37
b9657f6239 libobs/util: pthread_mutex_init_recursive helper
Add helper for creating a recursive mutex because it's easy to forget to
destroy the pthread_mutexattr_t.
2021-08-23 22:09:08 -07:00
Norihiro Kamae
bdb8f3f27b libobs/util: Fix reading memory usage on Linux
Memory usage displayed on Stats was too small due to a misaligned unit
of `resident_size` read from `statm` file and libobs.
2021-08-09 11:42:34 -07:00
Norihiro Kamae
7b4ae8611c libobs: Fix da_push_back taking a wrong type of item
Since the darray `sys_include_dirs` is an array of `char *`, it is
required to take a pointer to `char *`, that is `char **`. However,
`char *` was passed.
Since this function never called, another fix is removing entire
function `cf_preprocessor_add_sys_include_dir`.
2021-07-31 15:29:26 -07:00
Georges Basile Stavracas Neto
99559aab5a libobs: Add portal inhibitor
XDG Portals provide a plethora of features meant to be used inside and
outside sandboxed environments. OBS Studio currently uses portals to
implement Wayland-compatible monitor and window captures.

However, OBS Studio performs another action that can be done through
portals: inhibit the screensaver. Under the Desktop portal (the same
used by the captures mentioned above), there is an "Inhibit" portal
that provides session inhibition.

Add a new portal-based inhibitor. This inhibitor is only used when the
Desktop portal is available and running; the previous D-Bus implementation
is used in the absence of the portal. Because it's basically another set
of D-Bus operations, wrap the new portal inhibitor under the HAVE_DBUS
call too.
2021-07-18 14:04:44 -07:00
jpark37
83cb43f166 libobs: Mark unused parameters 2021-05-08 14:12:54 -07:00
jpark37
3c09074ed5 libobs/util: Skip pointless free for null 2021-03-31 06:07:11 -07:00
jpark37
d5e265d7dd libobs/util: Fix warnings for about null usages 2021-03-31 06:07:11 -07:00
jpark37
a20b4c67eb libobs/util: Compiler barriers for ARM64 atomics
Unsure if the intrinsics imply ordering. Safer to assume they don't.
2021-03-07 21:11:32 -08:00
Richard Stanway
6c0d234385 libobs: Minor fixes / code cleanups
Fixes some warnings generated by code analysis tools, removing redundant
checks etc.
2021-03-04 19:29:33 +01:00
Doug Kelly
4ab5a3bea1 libobs: use clock_gettime_nsec_np() for macOS
macOS should use the function clock_gettime_nsec_np() to get the
current clock in nanoseconds, instead of manually using
mach_absolute_time() and manually adjusting the timebase. This
greatly simplifies the platform-specific code to manage the
current time in nanoseconds.
2021-02-28 19:00:43 -08:00
Georges Basile Stavracas Neto
7f27963caa libobs/util: Split bus name from interface
When calling D-Bus methods, three fields are required:

 * The bus name, which is what applications own when they
   want to expose themselves to D-Bus;

 * The object path, which represents a D-Bus object exported
   under a bus name;

 * The interface, which holds the methods and signals;

While out of pure coincidence all the D-Bus buses have a
matching interface name, it is technically incorrect to assume
that.

Add a new 'interface' field to service_info, and split the bus
name.
2021-02-25 12:32:44 -08:00
Georges Basile Stavracas Neto
ec1b07cc85 libobs/util: Replace libdbus by GDBus
GDBus is more and better maintained than libdbus these days. In the
future, a potential Wayland-compatible capture plugin will need to
interact with D-Bus in a way that's way too complicated for libdbus,
and it won't be nice to have both libraries talking to the D-Bus
socket.

Replace the libdbus usage by GDBus. As it turns out, it results in less
code.
2021-02-25 12:32:44 -08:00
Georges Basile Stavracas Neto
94d2166951 libobs/util: Rename struct field 'id' to 'cookie'
All D-Bus interfaces call the unique identifier that is returned by their
calls "cookie", so rename the 'id' field to 'cookie' to match that.
2021-02-25 12:32:44 -08:00
jpark37
951acf2dfe libobs/util: More atomic fixes
Use _ARM_BARRIER_ISH for ARM path.

Remove useless conversion in os_atomic_load_bool.
2021-02-04 17:14:46 -08:00
jpark37
3df4a1109c libobs/util: ARM atomic fixes
Use native instructions on ARM64 (dmb is slow).

Use magic number for 32-bit ARM since _ARM64_BARRIER_ISH is for ARM64.
2021-02-03 22:18:26 -08:00
jpark37
1f90f0e36b libobs/util: Various atomic improvements
Add exchange functions to alias the poorly named set functions.

Add store without reading previous. Faster on non-x86 processors.

Add compare-exchange that updates previous to avoid redundant fetch.

On Windows, load bool without conversion from char.

On Windows, load using mov with compiler barrier. Still seq_cst.

On POSIX, use GCC __atomic builtins.
2021-02-03 08:51:31 -08:00
jpark37
54047ef9ca libobs: Avoid strncpy warning 2021-01-30 00:24:16 -08:00
jpark37
98d1f340da libobs: Fix unused parameter 2021-01-29 21:50:06 -08:00
jpark37
ccf16ddb65 libobs: Fix dstr leak 2021-01-22 22:16:17 -08:00
Richard Stanway
900b5341eb libobs: Add os_is_obs_plugin function
This function determines if something is an OBS plugin before attempting
to load it. On Windows, many plugins ship their dependent DLLs alongside
the plugin DLL, so OBS would load things like libcef.dll on startup only
to immediately free it. For other platforms, this is less of a concern
so this function is a no-op for now.

This improves startup time and reduces risk from dependent DLLs
potentially running code with unwanted side effects in DllMain.
2021-01-18 19:05:41 -08:00
Michael R. Crusoe
1e96573328 libobs: Update to SIMDe 0.7.1
c3d7abfaba

Simplify usage of the SIMDe header

This obviates the need for sse2neon as well and fixes compilation of all
plugins that referenced sse-intrin.h on all architectures, not just
arm*.
2021-01-02 04:07:55 -08:00
Vadim Zhukov
0d222b6b56 Add OpenBSD support 2020-11-14 11:55:22 -08:00
Colin Edwards
923f06bfa6 decklink: Add ability to ingest/embed cea 708 captions
(This commit also modifies libobs, UI)
2020-11-01 22:28:49 -08:00
jp9000
18486853a5 obs-ffmpeg: Add ability to debug ffmpeg-mux subprocess
Adds a cmake variable (DEBUG_FFMPEG_MUX) which enables FFmpeg debug
output in the ffmpeg-mux subprocess, and if on Windows, shows the
console window of the ffmpeg-mux subprocess so the current output can be
seen.
2020-10-14 18:42:22 -07:00