Commit Graph

264 Commits (2474775f40df39e58cc199733f94d59f90b5cc27)

Author SHA1 Message Date
tt2468 167f539416 libobs: Rename obs_audio_monitoring_supported to _available
With the reasonable possibility of monitoring support becoming a
runtime check, the phrase `available` is more fitting.
2021-12-22 02:43:14 -08:00
jp9000 49f9a055dc libobs: Fix destruction order for destruction task queue
Destruction of the task queue should probably happen after the audio and
video threads have been destroyed and all audio/video processing has
stopped.
2021-12-21 11:48:29 -08:00
jp9000 8b3416c1e7 libobs: Implement deferred destruction of sources
(This also modifies the UI)

The purpose of deferring destruction of sources is to ensure that:
1.) Hard locks from enumeration cannot occur with source destruction.
  For example, if the browser source is destroyed while in the graphics
  thread, the browser thread would wait for the graphics thread, but the
  graphics thread would still be waiting for the browser thread, causing
  a hard lock.
2.) When destroys occur during source enumeration, that the integrity of
  the context's next pointer in the linked list can no longer be
  compromised
3.) Source releases are fully asynchronous rather than having the risk
  of stalling the calling thread
4.) We can wait for source destruction when switching scene collections
  or when shutting down rather than hoping for threads to be finished
  with sources.

This introduces a new requirement when cleaning up scene/source data:
the obs_wait_for_destroy_queue() function. It is highly recommended that
this function be called after cleaning up sources. It will return true
if at least one or more sources were destroyed. Otherwise it will return
false. Forks are highly advised to call this function manually on source
cleanup -- preferably in a loop, in conjunction with processing
outstanding OBS signals and UI events.
2021-12-19 11:53:19 -08:00
jp9000 ab84214356 libobs: Add obs_in_task_thread() function
Allows determining which thread the caller is currently in, if any
2021-12-19 11:53:19 -08:00
jp9000 cf492ca271 libobs: Add ability to queue audio task
This is mostly framework for allowing the ability to wait for certain
threads
2021-12-19 11:53:14 -08:00
jp9000 408ce92146 Revert "libobs: Do not release while traversing sources for tick"
This reverts commit 080090c40e.
2021-12-19 11:25:57 -08:00
jp9000 080090c40e libobs: Do not release while traversing sources for tick
obs_source_release should not be called while iterating through the
global sources linked list, otherwise the linked list will be
compromised. Annoying.

Basically the same fix as obsproject/obs-studio#5600, but should be
slightly more optimal and a bit more explicit.
2021-12-15 11:57:52 -08:00
jp9000 243880b9ce libobs: Fix add/remove of raw audio callbacks 2021-11-28 02:49:04 -08:00
Clayton Groeneveld d45e92c10c libobs: Add raw audio callback function
This complements the already existing raw video callback function.
2021-11-24 01:32:31 -08:00
tt2468 ff22897d68 libobs/UI: Stop using preprocessor directives for monitor
**Code Cleanup**
Stop using preprocessor directives to determine if audio monitoring
is supported. Use runtime function instead
2021-11-20 20:00:59 -08:00
gxalpha c36a5ae92b libobs: Add obs_get_transition_by_name 2021-11-07 07:40:03 -08:00
jpark37 353868e87c libobs: Fix pthread mutex leaks 2021-08-23 22:57:10 -07:00
Richard Stanway 3dbfa4919a libobs: Add stop_audio function, change shutdown order
This fixes a crash that could occur during freeing of sources, as the
audio subsystem was destroyed before sources were released. If a source
had monitoring enabled, it would try to lock a mutex that has been
destroyed, resulting in a crash.

Freeing audio after obs_free_data was also not a solution, as the main
view is freed in obs_free_data, and the audio subsystem is still running
and trying to lock the main view channel mutex which has been freed.

This seems to be the best middle ground, making sure the audio subsystem
is stopped so it no longer tries to access the main view channel, then
freed after obs_free_data.

Fixes https://github.com/obsproject/obs-studio/issues/4409
2021-07-24 22:34:44 +02:00
tt2468 53a8a326da libobs: Add `obs_enum_all_sources()`
There is currently no way to enumerate *all* sources in OBS. Only
inputs and scenes have a way to be enumerated. Some applications
like obs-websocket have features that need to take advantage
of enumerating all sources in order to function properly.
2021-07-09 17:33:17 +12:00
jp9000 33c5563c1e libobs: Add obs_obj_is_private()
Returns true if an obs object is considered private. (Author's note: the
concept of "private" objects is not ideal, but we're stuck with it for
now)
2021-04-09 04:30:30 -07:00
jp9000 ca08df9fb2 libobs: Add obs_source_load2()
Allows loading a source and all of its filters automatically.
Previously, the original obs_source_load would not load filters.
2021-04-09 04:30:29 -07:00
Richard Stanway 6078dfef76 libobs: Don't save temporarily removed sources
The only references to these sources exist in the undo buffer, they are
not attached to a scene and cause issues when loaded on the next
startup.
2021-04-04 00:09:17 +02:00
Richard Stanway cdbb216bd0 libobs: Remove unnecessary null check 2021-04-03 00:31:07 +02:00
Jim 5f00f8c42a
Merge pull request #3014 from notr1ch/remove-excessive-null-checks
libobs: Remove excessive null checks
2020-06-21 04:56:45 -07:00
jpark37 6aa50b3ef1 libobs: Use autoreleasepool for graphics thread
Apparently necessary to clean up macOS leaks.
2020-06-08 13:16:35 -07:00
Richard Stanway b62ced9bf2 libobs: Unload modules while OBS core is active
Modules are now unloaded while OBS core is still active, allowing
modules that call into libobs in their unload function to continue to
work. This changes the behavior of such calls - previously they were a
no-op since the OBS core would be gone, but they are now executed with
the OBS core still being active.
2020-06-01 15:54:46 +02:00
Richard Stanway dd519123c6 libobs: Remove excessive null checks
libobs functions check for a null obs_core inconsistently. If the core
is null, the functions silently return with no indication of an error to
the API user. This commit removes all null checks in libobs functions
that require libobs to be initialized. For OBS Studio, we are
(hopefully!) using the API properly so this should have no impact.
2020-06-01 15:54:23 +02:00
张昆 eb44e05169 libobs: Fix unnecessary duplication
Original code makes duplicated item and bad memory

Closes obsproject/obs-studio#2837
2020-05-03 06:28:21 -07:00
Exeldro 874820ec2f libobs: Don't save removed sources 2020-04-18 08:30:06 +02:00
jp9000 934a18625e libobs: Remove repeated semicolons 2020-03-14 10:54:37 -07:00
jp9000 8de20ab3be libobs: Add task scheduling features
(This commit also modifies the UI)

Adds the ability to schedule tasks for certain threads
2020-03-14 10:54:37 -07:00
jp9000 39d8ea235c libobs: Fix another group id comparison
Fixes a group id comparison where it was comparing the pointer of the
group name rather than the string contents itself, causing it to treat
it as a non-group source.
2020-03-13 08:03:06 -07:00
jp9000 19068c2960 libobs: Handle removed plugins for versioned sources
When someone adds a source and the plugin is removed for whatever
reason, it would cause a crash with the new source versioning system.
This fixes that by ensuring the unversioned id is also backed up along
with the normal id.
2020-03-09 16:53:44 -07:00
jp9000 8d5ab2be3b libobs: Don't return false, return NULL 2020-03-09 16:42:50 -07:00
jp9000 3e01a85d39 libobs: Fix crash when querying versioned id
The wrong array was used, thus it couldn't find "group" or "scene".
2020-03-09 16:37:46 -07:00
jp9000 b2302902a3 libobs: Fix source type versioning system
(This also modifies image-source, obs-text, text-freetype2, and UI)

This improves source definition versioning.  To do this, it now stores
two identifier names.  One "unversioned" which is the original name, and
one "versioned" with the version number appended.

This fixes both backward compatibility with older OBS versions, and
fixes the inability to use "add existing" in OBS itself on sources
created from older version definitions.
2020-03-09 06:12:22 -07:00
jpark37 00f280ff9d libobs: Rename DEPRECATED to OBS_DEPRECATED
Avoid collisions with other libraries that define DEPRECATED.
2020-01-20 21:44:50 -08:00
jpark37 66d78275e2 libobs: Robust COM initialization
Qt seems to force STA, so it's misleading to ask for MTA and ignore the
failure result, so just ask for STA. Also, don't uninitialize COM if
initialization failed.
2019-11-24 09:46:41 -08:00
Clayton Groeneveld a55f83a38f UI, libobs: Fix compiler warnings 2019-10-10 00:25:54 -05:00
jp9000 65c7e2d19d libobs: Add API to get last OBS version of a source
Allows the ability to change the behavior of a source depending on the
previous OBS version.
2019-09-20 00:13:51 -07:00
jp9000 33c09d91c2 libobs: Add funcs to determine whether audio active
Adds functions to allow sources to inform the UI whether the audio is
currently active or not.  Allows the ability to turn on/off the items in
the mixer.
2019-09-19 23:37:29 -07:00
jp9000 83e237fec1 libobs: Fix default mixer values
There are 6 mixers, so we want 0x3F for 6 bits, not 0xF which is only 4
bits.
2019-08-26 08:24:02 -07:00
jp9000 73704f20db libobs: Add audio lines
Adds the "audio_line" internal source type as a bare source type for the
sole purpose of outputting audio, and the obs_source_info::audio_mix
callback which allows mixing of those audio lines, which is then treated
as normal audio for the source.  Audio line objects should be added as
sub-sources when multiple audio lines from a single source are needed,
then mixed together with the audio_mix callback.

The difference between the new obs_source_info::audio_mix callback and
obs_source_info::audio_render is that obs_source_info::audio_mix (along
with the audio_line source) are only one track, and it outputs audio to
the source automatically via obs_source_output_audio() when the call
completes.  This allows the mixed audio to be treated like a normal
source's audio, in that you can filter it, change its volume, or monitor
it.

This change was necessary because the CEF (used with the browser source)
outputs multiple audio streams at once to a single browser source, so
it's the program's responsibility to mix those streams together itself.
2019-08-21 15:19:19 -07:00
jp9000 74a3e7246e libobs: Fix browser source settings resetting pre-24
Fixes an issue where the browser source settings will continually reset
pre-24.  Note that this is not 23.2.2, but the version is being
temporarily updated in order to fix the issue for the release candidate
build.
2019-08-17 06:21:19 -07:00
jp9000 bc3ed7bbf7 libobs: Reset mixers for "monitoring only" sources
Resets mixer values for sources that are upgrading to "monitoring only"
(the browser source)
2019-08-15 21:23:45 -07:00
jpark37 9aacc99b3e libobs: Separate textures for YUV output, fix chroma
The shaders to pack YUV information into the same texture were rather
complicated and suffering precision issues. Breaking them up into
separate textures makes the shaders much simpler and avoids having to
compute large integer offsets. Unfortunately, the code to handle
multiple textures is not as pleasant, but at least the NV12 rendering
path is no longer separate.

In addition, write chroma samples to "standard" offsets. For I444,
there's no difference, but I420/NV12 formats now have chroma shifted to
the left as 4:2:0 is shown in the H.264 specification.

Intel GPA, SetStablePowerState, Intel HD Graphics 530

Expect speed incrase:
I420: 844 us -> 493 us (254 us + 190 us + 274 us)
I444: 837 us -> 747 us (258 us + 276 us + 272 us)
NV12: 450 us -> 368 us (319 us + 168 us)

Expect no change:
NV12 (HW): 580 (481 us + 166 us) us -> 588 us (468 us + 247 us)
RGB: 359 us -> 387 us

Fixes https://obsproject.com/mantis/view.php?id=624
Fixes https://obsproject.com/mantis/view.php?id=1512
2019-07-26 23:21:41 -07:00
jp9000 aee84cc743 libobs: Add "monitoring by default" source cap
(This also modifies the UI module)

Adds the ability for a source to monitor by default.  This is mainly
aimed at browser sources, so that they do not stop outputting audio by
default like they used to.
2019-07-26 00:05:14 -07:00
jpark37 3456ed0644 libobs: UI: Remove DrawBackdrop() to save fullscreen pass
It's a waste of GPU time to do two fullscreen passes to render final mix
previews. Use blend states to simulate the black background of
DrawBackdrop() for the following situations:

- Main preview window (Studio Mode off)
- Studio Mode: Program

This does not effect:

- Studio Mode: Preview (still uses DrawBackdrop)
- Fullscreen Projector (uses GPU clear to black)
- Windowed Projector (uses GPU clear to black)

intel GPA, SetStablePowerState, Intel HD Graphics 530, 1920x1080

Before:
DrawBackdrop: ~529 us
main texture: ~367 us (Cheaper than drawing a black quad?)

After:
[DrawBackdrop optimized away]
main texture: ~383 us
2019-07-18 19:58:29 -07:00
jp9000 70ecbcd5d4 libobs: Add obs_get_frame_interval_ns
Returns the current video frame interval between frames, in nanoseconds.
2019-07-07 16:38:21 -07: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
James Park 8d6ed988e6 libobs: Remove unnecessary frame pipelining
Remove three instances of unnecessary double-buffering. They are not
needed to avoid stalls, and cause increased memory traffic when
measured on Intel HD 530, presumably because texture data will remain
in cache if sampled immediately after write.

(Note: GPU timings from Intel GPA are volatile.)

NV12, 3 Draws:
RGBA -> UYVX: 628 us -> 543 us
UYVX -> Y: 522 us -> 507 us
UYVX -> UV: 315 us -> 187 us
Total, Duration: 1594 us -> 1153 us
Total, GTI Read Throughput: 25.2 MB -> 15.9 MB
2019-05-24 01:03:21 -07:00
James Park ba21fb947e libobs: Fix various alpha issues
There are cases where alpha is multiplied unnecessarily. This change
attempts to use premultiplied alpha blending for composition.

To keep this change simple, The filter chain will continue to use
straight alpha. Otherwise, every source would need to modified to output
premultiplied, and every filter modified for premultiplied input.

"DrawAlphaDivide" shader techniques have been added to convert from
premultiplied alpha to straight alpha for final output. "DrawMatrix"
techniques ignore alpha, so they do not appear to need changing.

One remaining issue is that scale effects are set up here to use the
same shader logic for both scale filters (straight alpha - incorrectly),
and output composition (premultiplied alpha - correctly). A fix could be
made to add additional shaders for straight alpha, but the "real" fix
may be to eliminate the straight alpha path at some point.

For graphics, SrcBlendAlpha and DestBlendAlpha were both ONE, and could
combine together to form alpha values greater than one. This is not as
noticeable of a problem for UNORM targets because the channels are
clamped, but it will likely become a problem in more situations if FLOAT
targets are used.

This change switches DestBlendAlpha to INVSRCALPHA. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.

obs-transitions: Use premultiplied alpha blend, and simplify shaders
because both inputs and outputs use premultiplied alpha now.

Fixes https://obsproject.com/mantis/view.php?id=1108
2019-05-08 20:26:52 -07:00
jp9000 8d125dc01d libobs: Add better default source color range handling
Fixes handling of the `obs_source_frame::full_range` member variable,
which is often set to false by default by many plugins even when using
RGB, which would cause RGB to be marked as "partial range".  This change
is crucial for when partial range RBG support is implemented.

Adds `obs_source_frame2` structure that replaces the `full_range` member
variable with a `range` variable, which uses the `video_range_type` enum
to allow handling default range values.  This member variable treats
VIDEO_RANGE_DEFAULT as full range if the format is RGB, and partial
range if the format is YUV.

Also adds `obs_source_output_video2` and `obs_source_preload_video2`
functions which use the `obs_source_frame2` structure instead of the
`obs_source_frame` structure.

When using the original `obs_source_frame`, `obs_source_output_video`,
and `obs_source_preload_video` functions, RGB will always be full range
by default for backward compatibility purposes.
2019-04-25 15:12:08 -07:00
James Park cb67192077 libobs: Fix invalid max_anisotropy value
max_anisotropy is initialized to zero, but the minimum value is 1.
2019-03-19 01:26:28 -07:00
Colin Edwards 5c16a96770
Merge pull request #1715 from jpark37/area-filter
Add "Area" scale filter
2019-03-13 23:30:25 -05:00