Commit graph

420 commits

Author SHA1 Message Date
tytan652 678b0287e6 libobs: Calm stringop-overflow warning on GCC
Those warnings appeared with GCC 12 with -O2, those are potentially
created by regression from GCC.
2023-01-19 13:08:46 -05:00
tytan652 c648222332 libobs,libobs-opengl,obs-ffmpeg-mux: Calm deprecation warnings on *nix
Calm libobs-opengl deprecation warnings on macOS.

Calm FFmpeg deprecation warning with LIBAVFORMAT_VERSION_MAJOR < 59.
2023-01-19 13:08:46 -05:00
Norihiro Kamae 1805712f46 libobs/util: Fix text-lookup not always case-insensitive
Convert `lookup` to upper-case before creating the tree so that later
code does not need to consider the case-insensitivity.
When converting to upper-case, use `toupper` instead of adding 0x20 so
that the behavior is consistent with `astrcmpi_n`.
2023-01-14 15:09:25 -08:00
jp9000 78f3389d17 libobs: Add funcs to get windows video adapter LUIDs
Useful for providing adapter order to encoder test subprocesses
2022-12-19 11:59:44 -08:00
PatTheMav c6cb1eb7d1
libobs: Replace invocations of sprintf with snprintf
Fixes deprecation warnings in Xcode 14/clang on macOS and reduces
chance of buffer overflows.
2022-11-11 19:51:27 +01:00
Tommy Vercetti 41efdc498c libobs/util: Add function to get Windows x64 emulation status 2022-11-09 03:03:26 -08:00
derrod 567505b2ed libobs: Fix reading Windows release name 2022-11-08 08:47:23 -05:00
derrod 1b6e1ce655 libobs: Add utility function to get total RAM 2022-11-08 05:38:37 -08:00
Kurt Kartaltepe 615728fa3b libobs/util: Reject plugins linking Qt5 library for Linux
Since obs-studio switched to Qt6, old plugins linking Qt5 should be
rejected. On Linux system, OBS and it's plugins link the system
libraries so that obs could be crashed by such plugins that links Qt5
when Qt5 functions are called.

Co-authored-by: Norihiro Kamae <norihiro@nagater.net>
2022-09-19 10:01:18 -03:00
PatTheMav 2bb0818fb4 libobs: Use system header notation for pthread.h include
Using a relative path for the pthread.h header by w32-pthreads breaks
compilation of plugins which include threading.h from libobs (as
w32-pthreads will exist at a different location relative to the
libobs header).

As w32-pthreads (and its include directory) is added to the libobs
target by CMake, the pthread.h header will be found even when using
system header notation.

Fixes https://github.com/obsproject/obs-studio/issues/7155
2022-08-24 05:40:37 -07:00
Richard Stanway 86963f65d2
libobs, win-capture: Don't export ms_get_obfuscated_func
Since this was included in things like the inject helper and game
capture DLLs, it added an additional export to those programs. Instead,
simply share the source files directly in the projects that need it.

Co-authored-by: jpark37 <jpark37@users.noreply.github.com>
2022-08-07 19:41:23 +02:00
jp9000 a0eae6f33c libobs/util: Add get_plugin_info (internal)
Allows the ability to get additional information about the plugin beyond
just whether it's an OBS plugin. For this case, whether it can load,
which is primarily used on Windows and mostly just determines whether it
has an incompatible Qt version.
2022-07-28 16:36:01 -07:00
jp9000 f6e349f033 libobs/util: Put module load detection in its own func
Puts the detection of obs_module_load in Windows DLLs for the "is this
an obs plugin" check into its own function
2022-07-28 14:53:58 -07:00
gxalpha 9d68c8a848 libobs: Fix crash handler noreturn compiler warning
Maybe not the most correct solution since it never gets hit but much
less code and ifdefs compared to what we'd have else wise.
2022-07-27 12:05:16 -04:00
jpark37 0d129988a9 libobs: Allow Chrome class executable matching
Lets OBS find Spotify.exe even if the window title changes.
2022-07-23 17:41:34 -07:00
jpark37 69ff026647 libobs, win-capture: Share window helper code
Add "ms_" prefix as makeshift namespace.
2022-07-23 17:41:34 -07:00
jpark37 7864c8649a libobs/util: Add WinModule RAII wrapper 2022-07-23 17:41:34 -07:00
tytan652 447f2869ab libobs: Remove OBS_UNUSED 2022-07-20 09:03:31 +02:00
tytan652 12657e4fcc libobs: Replace OBS_UNUSED with UNUSED_PARAMETER
OBS_UNUSED is not portable to MSVC.
2022-07-20 08:22:08 +02:00
Norihiro Kamae af3890a4a9 libobs: Cleanup unused-parameters
- Add OBS_UNUSED to unused function parameters
- Remove unnecessary UNUSED_PARAMETER
Also update libobs-opengl/
2022-07-19 11:01:00 -04:00
Richard Stanway c5965c8605 libobs: Log errors for bmalloc(0)
malloc(0) is implementation defined and almost always a mistake. I
believe we should be more like malloc and treat bmalloc(0) as an error
instead of tying to handle it. For now we can log an error in case 3rd
party plugins are broken, in the future I would suggest this becomes a
crash-worthy error.
2022-07-16 15:20:55 -07:00
Richard Stanway dbdbfe79d2 libobs: Deprecate base_set_allocator and make it no-op
Hopefully nothing is actually using this in the first place. As a
library libobs has alignment requirements so we should probably not
allow an application to replace our aligned mallocs with something else.
This also allows more aggressive optimizations inside libobs as the call
can be completely inlined into a libc malloc.
2022-07-16 15:20:55 -07:00
Tommy Vercetti 3b64e74660 libobs/util: Add function to get Rosetta translation status 2022-06-19 01:37:15 +02:00
tt2468 f6a77ec0a6 libobs/util: Add %s string replacement for unix time
Adds %s which replaces the keyword with the current unix epoch time.

The %s keyword is common in languages like PHP and Python, and even
some C implementations, but it is not standard so this is a fallback.
2022-05-28 18:30:41 -04:00
Norihiro Kamae c491594a51 libobs/util: Add os_sleepto_ns_fast
The function `os_sleepto_ns` has a spin loop so it will consume CPU
resource. The new function has same interface but consumes less CPU
resource with a drawback of less precision.
2022-05-15 02:31:31 -07:00
tt2468 9168797361 libobs,obs-outputs: Fix librtmp1 interference
Details in #6226, basically this fixes an issue where OBS links
to the system-installed librtmp1, which is incompatible with our
librtmp.

Co-authored-by: ewhac <ewhac@ewhac.org>
2022-04-25 18:45:05 -07:00
jp9000 493f6337f3 libobs/util: Add ConfigFile::OpenString()
For convenience
2022-04-22 12:49:38 -07:00
jp9000 a9ce118794 libobs/util: Add missing extern "C" header guard 2022-04-22 12:48:54 -07:00
tt2468 af67ef8e57 libobs, UI: Fix --verbose logging for stdout
Verbosity of stdout was previously hardcoded to INFO, while log viewer
and log files had correct verbosity. This makes the behavior of
--verbose make sense in all places.
2022-04-09 16:48:37 -07:00
jp9000 5e2c757cd1 libobs/util: Remove deprecation visibility from swig 2022-03-24 22:32:19 -07:00
jpark37 6f8b364565 libobs: Add OBS_COUNTOF for array count 2022-03-23 09:15:25 -07:00
PatTheMav 1fd7770548
libobs: Update CMakeLists.txt for libobs and associated libraries
Also updates libobs-opengl, libobs-d3d11, libobs-winrt
2022-03-16 23:11:08 +01:00
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