If the backbuffer count is larger than 3, it could still try to assign
backbuffers to pointers beyond the variable's array size when calling
swap->GetBuffer.
Use a d3d9 device and allocator to encode in QSV.
This fixes a random crash that could only happen on Windows 7. The QSV
Deviced returned a DEVICE_FAILURE after a random amount of time with the
old method.
This fix is totally based on Shinck's QSVHelper.exe patch for OBS
Classic (see
https://obsproject.com/forum/threads/0-633b-qsvhelper-exe-was-killed-encode-failed.19230/page-3#post-161984
for more information)
This is more like a proof of concept, but that fix is currently stable
and tested more than 50 hours, with a single session of +14 hours.
That commit doesn't respect all OBS Guidelines. It is currently
recommended to wait for a more "cleaner" implementation.
Due to using FindWindowEx to search for certain windows, certain windows
will show up that aren't usable/capturable. Prevent these windows from
showing up in the window lists.
For some unknown reason, GetWindow will not traverse the entire window
tree. It could be due to Microsoft purposely hiding certain UWP
windows, though the reason is unknown. For some equally unknown reason
FindWindowEx does work in its place.
This fixes the issue of not being able to find/capture certain windows,
such as halo 5: forge.
D3D12 capture does not take in to account when multiple backbuffers are
in used. With previous versions of Direct3D there was no need to do
this, but with D3D12 you must explicitly capture each specific
backbuffer currently in use.
The encoder name was changed from "nvenc_h264" to "h264_nvenc", and will
throw a warning in the log file if you use the former, so try the latter
first, then the former.
Similar to the parent commit, do not reset the blend state if the source
is not marked as a custom drawn source. Filters applied won't have the
correct blend state and the alpha edges of the text will be partially
black.
The blend state does not need to (and should not) be changed. This
fixes an issue where if filters are applied to an image source, the
image source will paint incorrectly.
Replaces the "Color Correction" filter with a newer version that uses a
matrix, adds hue and saturation, and improves the contrast option.
Closesjp9000/obs-studio#708
If capturing a UWP window, do not fall back to matching windows with the
same window class if the exact window is not found, as this will get any
other UWP window on the system (due to the fact that they all have the
same window class name).
Because the hook cannot get the window handle of UWP windows, fall back
to using the window handle stored in the game capture source itself if
it's unavailable from the hook.
Under certain circumstances, the program may not be able to acquire the
window thread ID for a UWP process, but will be able to acquire the
process ID. In this case, it should soft fail and retry, rather than
assume it's unacquirable and stop trying to reacquire.
The "attempting to hook [executable]" message would not display the
correct executable if it's fallen back to a different window with the
same window class.
Now that the game capture hook creates and controls all the
synchronization objects, it's no longer possible to expect that the hook
is fully loaded by the time game capture tries to initialize it. In
that case, allow game capture to retry the hook for a few frames before
assuming something failed.
This detects whether the target process is a UWP process, and then uses
the open_app_* functions for mutexes/events/mapping. Also slightly
refactors named object open functions.
The only way to open named kernel objects within a UWP "app" is to get
the AppContainer SID, and then open the objects with their full
system namespace names via undocumented NT functions.
All named objects (including file mapped shared memory) need to be
created within the hook itself due to the fact that UWP programs cannot
access named objects outside of the UWP process.
Because shared memory needs to be created within the hook, the capture
loop cannot start until the shared memory has been filled with valid
data. Creating an additional "initialize" event fixes this issue.
Additionally, changed the way that named kernel objects are
opened/created. Before, there were functions that would first try to
open named objects and then implicitly create them if opening failed
(assuming that if the hook didn't create it first, game capture would),
now it's been changed so that you can only either explicitly open or
create.
To check to make sure game capture is still active in the capture
program, it currently uses a named event, and then it checks to see if
that named event exists. However with UWP programs, you can't open a
named event outside of the UWP process. FindWindow on the other hand
does work, so instead of checking to see if a named kernel object
exists, create a window and check to see if that window exists.
The "main" windows detected for UWP programs are basically to help
sandbox the programs -- they run in the ApplicationFrameHost process and
help reduce the possibility of other programs trying to access the
actual process window, which is a child window.
To bypass this, go through the list of child windows for the
ApplicationFrameHost window, and then find the one that's attached to
a different process; that different process will always be the target,
and will allows us to open the actual process of the UWP program.
Instead of calling OpenThread, use DuplicateHandle with the minimal
access rights (SYNCHRONIZE) to be able to get the current thread handle
within a UWP program.
This prevents issues with using standard C functions, where microsoft
would otherwise spit out pointless warnings to encourage using
microsoft-specific functions instead.
This reverts commit 0edaebe192.
The commit was actually less optimal than it was before. Shaders are
always fully unfolded and both sides of a branch are always executed.
Despite that fact, the "avoid branching" commit actually *added* two
extra unnecessary instructions with the same number of actual sample
instructions, making it arguably less optimal than before.
This was tested via the D3DDissamble function.
(Note: This commit also modifies the ipc-util/seg-service modules)
When compiling the final project, always compile
ipc-util/get-graphics-offsets/graphics-hook/inject-helper/seg-service
with static MSVC runtimes to prevent the need of requiring the MSVC
runtimes for both architectures.
QSV frame priority bits are not being marked correctly; their priorities
are always marked either low or disposable, whereas I-frames should be
marked as highest (3), P-frames should be marked as high (2), and other
frames should be marked as either low or disposable. This helps ensure
that the correct frames are dropped when frames need to be dropped.
On certain switchable laptops with AMD graphics, due to a driver
bug/issue, the program will crash when querying capabilities. The
commit this updates to fixes that by not querying capabilities on
startup.
There are two variables used for 'priority', the general marked frame
priority, and the drop priority. They can sometimes be different
because some encoders don't always use the correct frame priority.
Whenever a cursor is captured and the cursor icon changes, it creates a
new texture. This isn't particularly optimal, so instead just store a
cache of cursor textures (based on size), and make the textures dynamic.
Doing this will prevent unnecessary texture reallocation.
Branching is not recommended in shaders and only recently gained
widespread support without causing massive branch misprediction issues. Also sampling inside a branch will cause cache misses and additional texture load instructions.
For some reason librtmp treats a close message as a request to reconnect.
It does this syncronously, and uses the same event processing so that
another close request will continue the cycle until the stack is exhausted
and the application crashes.
Fixes https://obsproject.com/mantis/view.php?id=634
Twitch no longer recommend Main profile on their "Broadcast requirements"
page. The number of devices that can't decode High profile is very small
and limited to old, legacy devices such as the 1st generation iPad (six
years old). Additionally, these devices have limited resolution / FPS
support, so streams are often encoded at levels beyond what they could
decode even disregarding the H264 profile requirement. It's not worth
degrading the quality of streams for modern devices just to support these
legacy decoders. Twitch still provides low-complexity transcodes for
devices which cannot handle Source quality streams.
When a pulseaudio source is created from existing settings and the
device is not found, then the private data will return NULL, making it
impossible to change the source to use a different device. NULL should
never be returned when possible, otherwise settings cannot be changed
and properties cannot be displayed.
Closesjp9000/obs-studio#604
The maximum shutdown timeout value was added as a setting, but never
actually fully implemented. This implements it properly, and sets its
default timeout value to 30 seconds.
This commit fixes the issue outlined in the following thread:
https://obsproject.com/forum/threads/50045/
When the image source file was replaced by an outside process, it would
only reload when the file's new timestamp was newer than the file's
previous timestamp. This fixes that behavior. Now an image source
will reload any time the file's new timestamp is different than its
previous timestamp.
libvlc_media_new_path implies a file. To get media based upon URLs, use
libvlc_media_new_location. Additionally, if using a URL, it's best to
give it some playback caching/buffering, at least 100 milliseconds.
Closesjp9000/obs-studio#590
Previously, for an unknown reason p-frames were marked as highest
priority along with i-frames (keyframes), which means they could not be
dropped. This would cause a problem where if for whatever reason
there's too much congestion, data would continually buffer. This fixes
the issue by dropping p-frames at a separate (higher) threshold than
b-frames.
Measures packet data rate and sleeps to prevent data from going above
the set data rate. Uncomment the TEST_FRAMEDROPS macro, then set
DROPTEST_MAX_KBPS to the desired kb/s (for example 3000 for 3000
kilobits per second), and then it will limit the data rate to that
specified amount, forcing the thread to sleep to ensure it can only
output the desired data rate.
Causes issues with certain servers that don't parse it properly and only
expect a specific string.
Use the RTMP onMetaData to get the OBS version instead when possible.
Even if the hotkey is not enabled, always allow configuration of the
hotkey. Fixes a bug where the hotkey configuration settings would not
save if the settings were changed.
Annoyingly this means that the hotkey will still be shown to the user,
possibly confusing the user as to whether they can use it, but for the
time being it's better than having their hotkey configuration removed
each time they change the mode.
It's supposed to look for patch segments in ascending order, from the
smallest offset to the largest offset. Patch type/comparison is
identical to the one it's being swapped with, so only the offsets need
to be swapped.
(Note: This commit also modifies coreaudio-encoder, win-capture, and
win-mf modules)
This reduces logging to the user's log file. Most of the things
specified are not useful for examining log files, and make reading log
files more painful.
The things that are useful to log should be up to the front-end to
implement. The core and core plugins should have minimal mandatory
logging.
Prevents the common problem of injecting in to certain processes and
getting the hook DLL "stuck":
- windows explorer
- steam
- battle.net
- gog galaxy
- skype
- uplay
- origin
- microsoft visual studio
- task manager
- league of legends lobby window
- windows 10 system settings window
Changed the first property of game capture to be a "mode" list (with
"any fullscreen window", "specific window", and "hotkey").
When hotkey mode is set, it'll add a hotkey pair to hotkey settings to
activate/deactivate game capture. When the hotkey to activate is
pressed, it'll treat the current foreground window as the target window
similar to "selected window" mode; it'll keep trying to capture the same
window even if the window or its application closes/reopens, and will
continue to do so until deactivated via the deactivate hotkey, or until
a new window is set via the activate hotkey.
Doing something like '#if TRUE' when 'TRUE' isn't defined is the
equivalent to '#if 0' because the preprocessor evaluates an undefined
macro as 0/false.
These comments have been added to clean up the code and make it more
clear of what the code is doing. The code felt a bit messy, and this
should help prevent the original author of the noise suppression filter
from being lost in case he decides to modify/improve the filter.
When buffering audio data, we don't want to buffer audio data that may
be old. If the audio timing jumps significant and old audio data is
buffered, clear that old data.
The noise suppression filter mistakenly operated on the assumption that
input audio data would always be in 10ms segments, and would crash if
audio data was larger than that size.
Because speexdsp operates on fixed audio frame sizes only, we must
buffer audio data to fit that frame processing size. This creates a
troublesome situation where you must buffer around that specified frame
size.
The new steps for processing are:
1. Push audio data to input circular buffer.
2. Push number of audio frames and timestamp for that audio packet to an
'info' circular buffer.
3. Check size of input circular buffer, and while it's equal to or above
the speexdsp frame size (10ms for minimum latency), pop from the
input buffer to a temporary buffer (10ms frames) and process it, then
push that temporary buffer to the output circular buffer.
4. Peek at the front of the 'info' circular buffer.
5. If the output circular buffer frame size is equal or larger than next
expected number of frames, pop both the info and output buffer, and
return the audio data with the expected audio frames/timestamp.
libVLC doesn't seem to provide full speaker configuration info, so when
downmixing audio from a file that had more than 2 channels, the audio
would sound wrong.
This change makes it so that libVLC does the downmixing to stereo rather
than libobs, just due to that lack of speaker configuration info.
It seems that it is not possible to create multiple OpenGL textures
for the same window. When sources are duplicated in studio mode this
causes window capture sources to become black. The
OBS_SOURCE_DO_NOT_DUPLICATE flag prevents that this happens.
Update Restream.io ingests list and set recommended keyframe interval to
2.
(Commit edited and formatted by Jim: Fixed commit message)
Closesjp9000/obs-studio#565
Whether buffer size is visible is determined by the value of the "Use
buffer size" property (the "use_bufsize" setting).
(Commit edited and formatted by Jim: separated this code from the
previous commit, and gave it a proper commit message)
Closesjp9000/obs-studio#567
This is why macros should be used for settings strings.
(Commit edited and formatted by Jim: separated this code from the
following commit, and gave it a proper commit message)
Closesjp9000/obs-studio#567
This reverts commit 4c505e7030.
Reverting this for the time being due to issues with quakelive. This
will be more thoroughly tested and hopefully added again.
When the crop filter was changed to a crop/pad filter, the sampler state
was changed to use a transparent border for the U/V addressing mode.
However, what was not realized at the time was that the scroll filter
also shared the crop effect file, and the scroll filter depended on the
old sampler state (wrap u/v).
This fixes the issue by simply setting a u/v wrap sampler state in the
scroll filter.
Tested using FTL (steam): SwapBuffers ultimately calls wgl_swap_buffers
causing an additional copy which just isn't necessary
This also causes game capture to sometimes capture overlays even when
not intended
This reverts commit bd70e73c25.
Turns out the commit was due to a miscommunication -- the commit it was
fixing actually worked fine, and this fix was unnecessary.
If window capture fails to find a window with a matching title, search
for a window with the same window class additionally as a backup.
Replaces the third part of the internal window string with the class
name instead of the program path due to the fact that the program path
rarely seemed to work.
Allows the ability to pad in addition to cropping. Changes the name to
Crop/Pad filter.
(Additional edits by Jim: Greatly refactored/simplified filter code)
Closesjp9000/obs-studio#532
Removing this union fixes the internal compile error that would occur on
visual studio 2015 update 2 and above when these variables were all in a
union.
(Note: This commit also modifies obs-ffmpeg and obs-outputs)
API Changed:
obs_output_info::void (*stop)(void *data);
To:
obs_output_info::void (*stop)(void *data, uint64_t ts);
This fixes the long-time design flaw where obs_output_stop and the
output 'stop' callback would just shut down the output without
considering the timing of when obs_output_stop was used, discarding any
possible buffering and causing the output to get cut off at an
unexpected timing.
The 'stop' callback of obs_output_info now takes a timestamp with the
expectation that the output will use that timestamp to stop output data
in accordance to that timing. obs_output_stop now records the timestamp
at the time that the function is called and calls the 'stop' callback
with that timestamp. If needed, obs_output_force_stop will still stop
the output immediately without buffering.
Because output stop timing has been fixed, there is no need to send the
remaining packets in the queue because it now just waits for the stop
timing anyway.
Fixes a bug where if a D3D9 program recreates its device the capture
would become invalid. Certain games (especially blizzard games) will
completely recreate their Direct3D device if a critical D3D9 error
occurs.
Adds the ability to add video playlists via libvlc instead of via the
media source. This is mostly just being added as a secondary option to
the media source to reduce maintenance costs and save time. Currently
libff cannot pause/unpause/seek, and isn't programmed to handle
playlists yet.
If VLC is installed on the computer (with the same architecture) it will
allow video playback via libVLC. In the future, users should be able to
optionally download VLC libraries via the installer as well if they
don't want to necessarily install VLC to get the plugin working.
This plugin performs runtime linking instead of compile-time linking;
compiling VLC is not required, only its headers are required. To
compile, clone the VLC repository and set the VLCPath cmake variable to
point to the VLC repository directory.
The xcomposite window capture crashes were due to a few factors:
-------------------------------
1.) The source's X error handler was possibly being overwritten by
another part of the program despite us locking the display, presumably
something in Qt which isn't locking the display when pushing/popping its
own error handler (though this is not yet certain). The source's calls
to X functions happen in the graphics thread, which is separate from the
UI thread, and it was noticed that somehow the error handler would be
overwritten almost seemingly at random, indicating that something else
in the program outside of OBS code was not locking the display while
pushing/popping the error handler.
To replicate this, make it so that the source cannot find the target
window and so it continually searches for it each video_tick call, then
resize the main OBS window continually (which causes Qt to push/pop its
own error handlers). A crash will almost always occur due to BadWindow
despite our error handling.
2.) Calling X functions with a window ID that no longer exists,
particularly XGetWindowAttributes, in conjunction the unknown error
handler set in case #1 would cause the program to outright crash because
that error handler is programmed to crash on BadWindow for whatever
reason. The source would call X functions without even checking if
'win' was 0.
3.) The source stored window IDs (in JSON, even if they've long since
become invalid/pointless, such as system restarts). This is a bad
practice and will result in more cases of BadWindow.
Fixing the problem (reducing the possibility of getting BadWindow):
-------------------------------
Step 1.) Deprecate and ignore window IDs in stored settings. Instead of
using window IDs to find the window, we now must always search the
windows and find the target window via the window name exclusively.
This helps ensure that we actually consistently have a working window
ID.
Step 2.) Do not call any X functions if the window ID is 0.
Step 3.) Reset the window ID to 0 any time the window has updated, and
make the source find the window again to ensure it still exists before
attempting to use any X functions on the window ID again.
Add checks to make sure the pulseaudio operation objects are actually
valid and the request did not fail right away. Other pulseaudio
functions dealing with the objects expect them not to be NULL,
otherwise they will kill the application with a failing assert.
For some reason in the FFmpeg output, this AVCodecContext variable is
being set to 1 by FFmpeg itself somewhere, and it's causing a massive
slowdown when encoding with FFmpeg directly. This should be set to 0 to
specify to use as many threads as necessary.
This reverts commit 8d520b970d.
This can actually cause a hard lock due to the windows API when
destroying window capture. When the graphics thread locks the source
list for doing tick or render, and then the UI thread tries to destroy a
source, the UI thread will wait for the graphics thread to complete
rendering/ticking of sources. The video_tick of window capture would
then check windows in the same process and try to query the window's
name via GetWindowText. However, GetWindowText is synchronous, and will
not return until the window event has been processed by the UI thread,
so it will perpetually lock because the two threads are waiting for each
other to finish.
On windows, if you were saving a file name or directory with characters
that are not of the current windows character set, it could cause the
file saving process to fail. This fixes it so that on windows it uses
wmain and converts the unicode command line to a UTF-8 command line,
which works with FFmpeg.
Prevents game capture from acting as a global source. This fixes an
issue where a game capture in another scene could capture a window and
prevent a separate game capture in the current scene from being able to
capture that same window.
Completely shut down monitor capture when it's not being shown in the
program (for example in a different scene). This fixes an issue where
it would cause lag when a game enters fullscreen mode.