Commit graph

87 commits

Author SHA1 Message Date
gxalpha 5ed0b8a0b8 libobs: Assume Qt 6, always warn about Qt 5 plugins 2023-07-19 11:56:54 -04:00
Lain 106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
derrod f72cc4498f libobs: Add os_generate_uuid() to platform utils 2023-03-12 01:11:38 +01:00
pkv a0a23e8a18 libobs: Fix leak with empty path in stats
If the recording path is left empty in Settings, a leak can occur in
window-basic-stats.cpp because a bmalloc is called for a size 1.
This fixes the leak by checking against the path in the
os_get_free_disk_space function.

Signed-off-by: pkv <pkv@obsproject.com>
2023-03-04 16:23:07 -08: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
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
Tommy Vercetti 3b64e74660 libobs/util: Add function to get Rosetta translation status 2022-06-19 01:37:15 +02: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
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
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 f20a7c0540 libobs: Remove dependency on psapi.lib 2021-09-12 14:10:36 -07: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
jp9000 46c8ef615d libobs/util: Use MAX_PATH for absolute path funcs
Makes these functions a bit more consistent with the rest of the
project.
2020-02-28 23:48:12 -08:00
jp9000 eadb96fbca libobs: Log windows release version
This logs the Windows release version (e.g. 1809, 1903, etc)
2020-01-04 14:25:28 -08:00
jp9000 de3de2a217 libobs: Find windows version
This uses three methods of obtaining the actual windows version,
RtlGetVersion which is the ntdll version of GetVersionEx that bypasses
the manifest check garbage, looking up the file version of a file that
is most likely to be updated per windows version (ntoskrnl), and the
registry.  Of the three values, it chooses the highest windows version
obtained by the three.

Closes obsproject/obs-studio#2294
2020-01-04 14:23:32 -08:00
jp9000 f53df7da64 clang-format: Apply formatting
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.
2019-06-23 23:49:10 -07:00
jp9000 0e8fe8bbbc libobs/util: Add function to get executable path 2019-04-26 13:24:30 -07:00
jp9000 8134b8afda libobs/util: Fix bug with get_winver
get_winver is supposed to return a 16bit value in a format equivalent to
0xMMmm (Major minor).  It was returning 0xMM00mm incorrectly instead.
2019-02-07 17:00:46 -08:00
jp9000 2e1a19456a libobs/util: Add get_win_ver_int() func (windows)
Returns the current version number of windows.  The lowest byte is the
minor version number, then the next lowest byte is the major version
number.  E.g. 0x601 for Windows 7, 0x602 for Windows 8, 0x603 for
Windows 8.1, and 0xA00 for Windows 10.
2019-02-07 17:00:46 -08:00
jp9000 8f106dc3c1 libobs, UI: Do not log redundant warnings
Reduces log file clutter by not logging certain warning messages that
were already safe/normal/expected failures.
2019-01-12 16:50:55 -08:00
JetMeta 18c1f10488 libobs/util: Cache windows CPU frequency
Caches the frequency of the performance counter.  It was supposed to be
caching it already, but it seems that code was unintentionally not
included.

Closes jp9000/obs-studio#1185
2018-02-19 22:11:55 -08:00
Richard Stanway 2f577c1b71
libobs: Make get_reg_dword handle missing keys
Previously if the key didn't exist it would return uninitialized stack
memory. Reported at https://obsproject.com/forum/threads/obs-freezes-computer-on-startup-sometimes.78030/#post-330590
2017-12-19 12:04:00 +01:00
Jim 5f1fd38731 Merge pull request #1047 from RytoEX/log-win10-game-mode
Log Windows 10 Gaming Features (Game Mode)
2017-10-25 11:31:31 -07:00
Ryan Foster 0759eeb5da libobs: Add wrapper function to query Windows registry 2017-10-14 00:31:41 -04:00
Ryan Foster d6ee57ae83 libobs/util: Fix Windows 10 revision detection
Follow-up to 47aa56b (PR #620). Windows 10 revision detection broke in
Build 15036 (Creators Update) after Revision 296. This aims to further
fix revision detection on Windows 10.
2017-10-08 04:16:48 -04:00
Richard Stanway 27d16f961b
libobs: Restore Windows Vista compatibility
Certain PSAPI functions moved to KERNEL32 after Vista, setting
PSAPI_VERSION 1 uses the old PSAPI exports for compatibility. Vista
support was unintentionally broken by a6318ff.
2017-09-28 13:28:46 +02:00
mntone a6318ffdca libobs/util: Add memory usage functions
Closes jp9000/obs-studio#953
2017-09-12 01:49:11 -07:00
jp9000 9e466a4697 libobs/util: Add function to get free disk space 2017-05-13 01:21:14 -07:00
jp9000 6fc74d69a9 libobs: Add functions to get logical/physical cores 2017-05-06 11:29:27 -07:00
jp9000 2537f9a5e2 libobs/util: Use MoveFileEx with MOVEFILE_REPLACE_EXISTING
Ensures that it will replace an old file if it exists.
2017-05-04 18:44:15 -07:00
jp9000 651d80c0df libobs/util: Add os_safe_replace function
Allows safely/atomically replacing a file and creating a backup of the
original.  The reason for adding this function is because Microsoft
provides a ReplaceFile function which does this in a single call.
2017-05-04 18:21:51 -07:00
Ryan Foster 788a1e22b7 libobs: Refactor check for Windows bitness/arch
Commit aa899c2 (PR #603) added logging for Windows bitness/arch, but it
was a bit incomplete/short-sighted.  It only added that information to
the regular logs.  This commit makes it easier to retrieve that
information for other purposes, like the crash handler.
2016-11-09 12:41:07 -08:00
Ryan Foster 87f4d586b0 libobs/util: Fix get_dll_ver not reporting DLL name
Follow-up to commit 2cf5c5f.
2016-09-24 14:14:53 -04:00
jp9000 2cf5c5f7f7 libobs/util: Fix get_dll_ver always getting kernel32 info 2016-09-19 17:52:20 -07:00
Ryan Foster 47aa56b3e9 libobs/util: Fix Windows 10 revision detection
Sometimes the revision number isn't put in to the kernel32.dll version
information.  It's best to use the registry in this case.
2016-09-19 17:52:19 -07:00
Colin Edwards 0c0f6031e2 libobs/util: Use FormatMessage on error when LoadLibrary fails
Outputting a human-readable error message on library load failure makes
it a little bit easier for plugin developers to determine why a plugin
library may have failed to load (such as missing dependency), rather
than having to look up the error code each time.

Closes jp9000/obs-studio#596
2016-08-19 17:04:44 -07:00
jp9000 4f4d7cde7e libobs/util: Add os_get_program_data_path* functions
Allows getting the system-local program data path.  Typically:

Windows:  C:\ProgramData
Mac:      /Library/Application Support
Linux:    /usr/local/share
2016-07-06 03:47:50 -07:00
jp9000 fa5c477826 libobs/util: Add os_breakpoint function 2015-11-18 12:42:15 -08:00
Richard Stanway 3671153a4f libobs: Don't use SPI_SETSCREENSAVEACTIVE on Windows
SetThreadExecutionState with ES_DISPLAY_REQUIRED has the same effect of preventing the screensaver from activating. Using SPI_SETSCREENSAVEACTIVE leaves the screensaver disabled system-wide if OBS crashes before it can re-enable it.
2015-11-05 03:58:26 +01:00
adray e354a433c7 libobs/util: Add function to get free space
Meant as a part of solving mantis issue 105 ("Disk space usage monitor
when recording").

From pull request: jp9000/obs-studio#374
Relevant mantis issue: https://obsproject.com/mantis/view.php?id=105
2015-10-15 01:43:23 -07:00
jp9000 d542663478 libobs/util: Add os_get_abs_path(_ptr) functions
These functions resolve the absolute path from a relative path.
2015-10-15 01:35:18 -07:00
jp9000 8a0a28bf27 libobs/util: Add get_dll_ver function (windows)
Used to get the version of a dynamic link library on windows.
2015-10-04 21:16:28 -07:00
jp9000 d78d0072a0 libobs/util: Add functions to inhibit sleep
These fucntions prevent the computer from going to sleep, hibernating,
or starting up a screen saver.

On linux, it will also attempt to use DBus to prevent gnome/kde/etc
sleep, but it's not necessarily required in order to compile the
library.  Otherwise, it will simply call "xdg-screensaver reset" once
every 30 seconds to reset the screensaver timer.
2015-09-12 22:08:05 -07:00