Commit Graph

502 Commits (master)

Author SHA1 Message Date
VodBox e8c1ec4035 libobs: Send activate and show signals to filters 2019-11-07 06:19:34 -08:00
Exeldro e5ae662e7a libobs: Export obs_group_from_source
Export obs_group_from_source to allow it to be used externally
2019-10-15 09:21:21 -07: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 abaed69627 libobs: Check to swap BGRX/BGRA in async filters
If for whatever reason the format is swapped between BGRA/BGRX in an
async filter, swap the texture to compensate for that.  This allows
plugins to change the format if necessary.
2019-09-17 13:51:40 -07:00
Jim 1523acd726
Merge pull request #2055 from jpark37/video-warnings
Fix video format warnings
2019-08-31 21:16:23 -07:00
jp9000 23111c317f libobs: Remove redundant function param and for loop
Originally when the audio_submix function was created, it used all mixer
tracks, but at a certain point that was removed because it can only use
the first track, so some older code was unintentionally left over,
causing the same code to be executed 6 times mistakenly.  This cleans
that up by removing the unnecessary function parameter and for loop.
2019-08-31 01:15:19 -07:00
jpark37 42bf026a49 libobs: Fix video warnings 2019-08-30 22:13:03 -07:00
jp9000 0845844e5d libobs: Insert sources to linked lists after creation
This fixes a race condition where the audio/video backends/threads may
start using sources before their obs_source_info::create function has
been called.
2019-08-25 19:19:57 -07:00
jp9000 2557ffce7e libobs: Add missing static to function
This function is not used outside of the source file, so make it static.
2019-08-25 19:19:57 -07:00
jp9000 2c3ea4af55 libobs: Fix null potential pointer dereference
When a source type has been removed (i.e. its plugin has been removed)
info can be null, which is permitted.
2019-08-25 19:19:57 -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
SoraYuki 21135f1483 libobs: Merge obs_source_process_filter_(tech_)?end functions 2019-08-14 14:03:34 +08:00
jpark37 3d6f5c8ad6 libobs: Add YUV alpha formats
This will allow YUV alpha formats to be converted to RGBA on the GPU.
2019-08-11 11:26:22 -07:00
jpark37 bdd8d64053 libobs: Separate textures for YUV input
The shaders to unpack YUV information from the same texture were rather
complicated. Breaking them up into separate textures makes the shaders
much simpler, and we can remove the PRECISION_OFFSET hack.

Performance also gets a nice boost on Intel for planar textures.

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

UYVY: 473 us -> 457 us
YUY2: 492 us -> 422 us
YVYU: 491 us -> 441 us
I420: 1637 us -> 505 us
I422: 1644 us -> 482 us
I444: 1653 us -> 504 us
NV12: 1656 us -> 369 us
Y800 (limited): 270 us -> 277 us
Y800 (full): 263 us -> 289 us
RGB (limited): 341 us -> 411 us
BGR3 (limited): 512 us -> 509 us
BGR3 (full): 527 us -> 534 us
2019-08-09 21:14:29 -07:00
jpark37 b0e7c5d0d3 libobs: Fix stale format in async frame cache
The video format is not updated if switching between cache-compatible
formats, e.g. YUY2 and YVYU, resulting in the wrong conversion technique
being used. This change ensures the format is always up-to-date.
2019-08-07 06:47:27 -07:00
James Park 37f663a789 libobs: obs-ffmpeg: win-dshow: Planar 4:2:2 video
This format has been seen when using FFmpeg MJPEG decompression.
2019-07-25 20:11:37 -07:00
Jim ffcfe4c9d9
Merge pull request #1951 from jpark37/audio-buffering
Fix audio buffering for devices like GV-USB2
2019-07-20 17:05:27 -07:00
Michael Fabian 'Xaymar' Dirks 3f6bbe2d49 libobs: Call both get_defaults and get_defaults2
Unlike get_properties, there is not reason to not call get_defaults if it is
given in addition to get_defaults2. Additonally this fixes the bug with
'init_encoder' which would only ever call get_defaults, resulting in broken
encoders if those used get_defaults2.
2019-07-13 00:49:18 +02:00
James Park da87f08da4 libobs: Buffer-smoothing enhancements
If an audio source does not provide enough data at a steady pace, the
timestamp update does not happen, and buffering increases until it
maxes out. To counteract this, update the timestamp anyway.

Another issue for decoupled audio sources is that timing is not
adjusted for divergence from system time. Making this adjustment is
better for timing stability.

5+ hours of stable audio without any buffering on my GV-USB2 where it
used to add 21ms every 5 mintues or so.

Fixes https://obsproject.com/mantis/view.php?id=1269
2019-07-05 09:13:18 -07:00
jpark37 2ef25ceb85 libobs: Fix format selection
Fix ternary test to use BGRX render targets for YUV to RGB
conversions. The previous behavior may have been fine though since
the shaders fill the alpha channel with 1.0 anyway.
2019-06-27 08:57:41 -05: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 aa22b61e3e libobs: Full-screen triangle format conversions
The cache coherency of rasterization for full-screen passes is better
using an oversized triangle that is clipped rather than two triangles.
Traversal order of rasterization is GPU-specific, but will almost
certainly be better using an undivided primitive.

A smaller benefit is that quads along the diagonal are not evaluated
multiple times, but that's minor in comparison.

Redo format shaders to bypass vertex buffer, and input layout. Add
global shader bool "obs_glsl_compile" to make API-specific decisions,
i.e. handle upside-down UVs. gl_ortho is not needed for format
conversion because the vertex shader does not use ViewProj anymore.

This can be applied to more situations, but start small first.

Testbed full screen passes, Intel HD Graphics 530:
RGBA -> UYVX: 467 -> 439 us, ~6% savings
UYVX -> uv: 295 -> 239 us, ~19% savings
2019-06-18 22:29:07 -07:00
Jim fafda14963
Merge pull request #1906 from jpark37/bgr-three
libobs: linux-v412: obs-ffmpeg: Add packed BGR3 video support
2019-06-15 16:40:44 -07:00
James Park e72eb39e47 libobs: Disable blending when converting sources
This fixes the issue where limited-range RGB sources were being
composited with dirty render targets.
2019-06-12 22:23:51 -07:00
James Park 614025742b libobs: linux-v412: obs-ffmpeg: Add packed BGR3 video support
Someone mentioned this format preserves the most quality for a
particular capture card using V4L2.
2019-05-30 06:05:53 -07:00
James Park ab8e895b12 libobs: Remove unreachable YUV decode paths
A previous refactoring to make DrawMatrix unnecessary has left behind
unreachable YUV conversions. Even if this code was somehow reachable,
DrawMatrix for YUV -> RGB doesn't exist anymore, so they would render
incorrectly anyway.
2019-05-19 21:27:18 -07:00
VodBox 52235ba86d libobs: Add transition and showing counter functions
This commit adds a function to forcefully stop a transition, and to
increment/decrement the showing counter for a source with the MAIN_VIEW
type.

These functions are needed for the transition previews to work as
intended.
2019-05-12 21:13:21 -07:00
James Park f03b4dc965 libobs: Restore casts to fix Clang warnings
Clang doesn't like it if you convert T** to const T* const* without
casting even though it should be safe. Might be a C language thing.
2019-05-09 21:59:38 -07:00
James Park a86710ec5b libobs: Support limited color range for RGB/Y800 sources
libobs: Add support for limited to full color range conversions when
using RGB or Y800 formats, and move RGB converison for Y800 formats to
the GPU.

decklink: Stop hiding color space/range properties for RGB formats, and
remove "YUV" from "YUV Color Space" and "YUV Color Range".

win-dshow: Remove "YUV" from "YUV Color Space" and "YUV Color Range".

UI: Remove "YUV" from "YUV Color Space" and "YUV Color Range".
2019-04-25 15:13:05 -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
jp9000 f109d1c2bf Revert "libobs: libobs-d3d11: obs-filters: No excess alpha"
This reverts commit d91bd327d7, which
broke alpha with sources, scenes, and filter, causing them all to become
opaque unintentionally.
2019-04-25 08:36:41 -07:00
Jim f1399b6d18
Merge pull request #1765 from jpark37/blend-alpha
libobs: libobs-d3d11: Fix blend alpha overflow
2019-04-14 00:22:20 -07:00
James Park 69c215345a libobs: Simplify YUV conversion
Currently several shaders need "DrawMatrix" techniques to support the
possibility that the input texture is a "YUV" format. Also, "DrawMatrix"
is overloaded for translation in both directions when it is written for
RGB to "YUV" only.

A cleaner solution is to handle "YUV" to RGB up-front as part of format
conversion, and ensure only RGB inputs reach the other shaders. This is
necessary to someday perform correct scale filtering without the cost of
redundant "YUV" conversions per texture tap.

A necessary prerequisite for this is to add conversion support for
VIDEO_FORMAT_I444, and that is now in place. There was already a hack in
place to cover VIDEO_FORMAT_Y800. All other "YUV" formats already have
conversion functions.

"DrawMatrix" has been removed from shaders that only supported "YUV" to
RGB conversions. It still exists in shaders that perform RGB to "YUV"
conversions, and the implementations have been sanitized accordingly.
2019-04-11 23:00:03 -07:00
James Park 21f4dd63d4 libobs: UI: Use graphics debug markers
Add D3D/GL debug markers to make RenderDoc captures easier to tranverse.

Also add obs_source_get_name_no_null() to avoid boilerplate for safe
string formatting.

Closes obsproject/obs-studio#1799
2019-04-08 02:05:37 -07:00
James Park d91bd327d7 libobs: libobs-d3d11: obs-filters: No excess alpha
Currently SrcBlendAlpha and DestBlendAlpha are both ONE, and can
combine together to form two. This is not a noticeable problem for
UNORM targets because the channels are clamped, but it will likely
become a problem if FLOAT targets are more widely used.

This change switches DestBlendAlpha to INVSRCALPHA, and starts
backgrounds as opaque black instead of transparent black. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.
2019-04-07 18:16:56 -07:00
jp9000 4fa30c619c libobs: Fix starting timestamp for preloaded frames
If audio monitoring is enabled and set to output only, the
obs_source_show_preloaded_video function would still incorrectly set the
current source audio output timestamp to the current system time, which
would cause audio to use an incorrect starting point from long ago for
the first starting audio segment if audio monitoring is then turned off
some time after having started the source.

Instead, the starting timestamp should be set to 0 if audio monitoring
is enabled with no output to stream, so that if/when audio monitoring is
disabled, it recalculates the starting timestamp of the first audio
packet on the spot again.

Closes obsproject/obs-studio#1522
2018-12-03 08:44:55 -08:00
jp9000 0951039322 libobs: Do not process panning if panning centered
Fixes a bug where audio panning would always be processed even if
panning was centered (and thus inactive).
2018-11-23 03:24:11 -08:00
Jim 31561b3231
Merge pull request #1428 from pantherrui/master
fix heap corruption when video capture thread release the frame before it push into source->async_frames.
2018-09-17 05:19:58 -07:00
wangrui05 26d3f42b89 libobs: Fix heap corruption in obs_source_output_video 2018-09-17 18:46:47 +08:00
jp9000 f1aa71bef1 libobs: Don't call width/height funcs if context invalid
Don't allow calling a source's custom get_width or get_height callbacks
unless the context is valid.  Fixes a bug where a null pointer could be
passed to those functions.
2018-09-13 06:54:58 -07:00
cg2121 a4a7deeed6 UI: Implement stereo balancing 2018-09-07 09:27:14 -05:00
jp9000 5dfab20a46 libobs: Allow group duplication 2018-07-16 19:03:34 -07:00
Bas van Meel 1653d258fe libobs: add obs_source_frame_copy 2018-06-11 10:03:37 +02:00
jp9000 516c0de2e0 libobs: Don't signal "source_create" for private sources 2018-05-03 12:38:47 -07:00
Jim 6f4985e4d6
Merge pull request #1261 from Andersama/patch-11
libobs: Fix pasting filters crash when missing sources
2018-04-22 06:56:52 -07:00
sorayuki fc26e3cfcf libobs: Fix potential filter rendering race condition
The filters array should not be accessed without locking the filter
mutex.  This locks the filter mutex, grabs a reference to the first
filter, unlocks the mutex, renders the filter, and then releases the
reference.

Closes obsproject/obs-studio#1215
2018-04-20 01:55:52 -07:00
Alex Anderson b0cd7fe890 libobs: Fix pasting filters crash when missing sources
Solves crash when a user tries to paste filters without selecting a
source or when pasting filters from a deleted source. This commit
checks if both sources are still valid before pasting.

This addresses Mantis Issue 1220
(https://obsproject.com/mantis/view.php?id=1220).
2018-04-18 09:11:47 -07:00
jp9000 8a1486d15f libobs: Fix rendering if filter context no longer exists
If a filter's implementation (its plugin for example) no longer exists,
it would cause the source to stop rendering if that filter was present
on the source.  Instead, just bypass the filter to ensure that the
source continues to render.
2018-01-17 02:08:06 -08:00
jp9000 d6ac457025 libobs: Optimize clearing of unused source audio mixes
Prevents calling memset on mixes that aren't currently active.
2018-01-16 12:02:00 -08:00
Christoph Hohmann f4142a8ac8 libobs: Fix audio buffer clear in custom source mixing
The memset in custom_audio_render() did not clear all audio buffers when
the number of output channels was less then 8.  This caused wrong audio
output on mixes that did not get cleared.

Closes jp9000/obs-studio#1123
2018-01-16 11:56:11 -08:00
Shaolin 78961818f8 libobs: Fix for int-in-bool-context-warning
The 'bool private' variable was receiving either OBS_SCENE_DUP_PRIVATE_COPY or
OBS_SCENE_DUP_COPY hence always being true.
2018-01-07 00:26:55 -02:00
SuslikV c706742097 libobs: Fix scene filter duplication
Scene filters were not being copied when a scene was duplicated with
obs_scene_duplicate.

Closes jp9000/obs-studio#1104
2018-01-04 20:36:11 -08:00
SuslikV f81adbd856 libobs: Fix bad source release placement
(This commit also modifies the UI)

The source release was being done in the wrong file.
2018-01-04 20:36:11 -08:00
jp9000 a730f9d6ce libobs: Add ability to disable source types
Because it would be troublesome to add the ability to remove source
types (in case for example a script fails to reload), instead make it so
source types can be temporarily disabled while the program is running.
2018-01-03 17:04:02 -08:00
jp9000 92b4276ee7 libobs: Add obs_source_info::get_properties2
Uses type_data to get the type-specific data of a source type
2018-01-02 13:51:03 -08:00
jp9000 5d7c899ebe libobs: Add obs_source_info::get_defaults2
Uses type_data to get the type-specific data of a source type
2018-01-02 13:51:03 -08:00
jp9000 e70b226e7e libobs: Duplicate private scene/source settings
Ensures that private settings data is also duplicated when a scene or a
source is duplicated.
2017-11-30 05:05:06 -08:00
Christoph Hohmann 0d305af9df libobs: Copy enabled state when duplicating filters
This fixes that in studio mode disabled filters are applied to sources in
the live scene.
2017-11-12 10:40:15 +01:00
jp9000 b54f70ef8d libobs: Add async video/audio decoupling functions
Decoupling the audio from the video causes the audio to be played right
when it's received rather than attempt to sync up to the video frames.
This is useful with certain async sources/devices when the audio/video
timestamps are not reliable.

Naturally because it plays audio right when it's received, this should
only be used when the async source is operating in unbuffered mode,
otherwise the video frame timing will be out of sync by the amount of
buffering the video currently has.
2017-10-10 06:45:34 -07:00
jp9000 ef97f15d6b libobs: Set video timing_adjust to obs video time
When an async video frame comes in and it sets the timing_adjust value
(used to sync audio to video based upon their timestamps), it would use
os_gettime_ns as a base.  Instead, it should use OBS' current video
frame time so that the audio and video playback is as accurate as
possible relative to the actual exact timestamp of the video frame.
(Results are almost insignificant, but it's nice to be as precise as
possible)
2017-10-02 07:36:02 -07:00
jp9000 dc1e233168 libobs: Move macro to internal C file
Modifying this value would cause the entire project to recompile when
it's only used in one file in the first place.
2017-10-02 07:36:02 -07:00
Jim 48cc90d5bb Merge pull request #996 from twitchalerts/audio-subsystem-crash-fix
libobs: Fix a potential divide by zero crash
2017-09-15 13:12:41 -07:00
jp9000 2ef00ecec4 libobs: Add private settings to scene items/sources
Allows setting and sharing of user data for sources and scene items.
2017-09-13 21:17:44 -07:00
Zachary Lund 9941ddb52c libobs: Fix a potential divide by zero crash 2017-08-09 01:07:50 +02:00
Shaolin e5756a922a libobs/plugins/UI: Suppress unused variables warnings
Closes jp9000/obs-studio#937
2017-06-27 21:55:37 -07:00
jp9000 eb7fb990b7 libobs: Do not allow incompatible filters on sources
Fixes a potential issue where copying filters from one source to another
might add filters from the old source that are not compatible with the
new source.
2017-05-19 00:25:27 -07:00
jp9000 2348a1ce83 libobs: Make obs_source_default_render exported
Allows directly rendering a non-async source without going through
filters.
2017-05-16 17:29:04 -07:00
jp9000 d13fa96851 libobs: Don't use source flags for async buffering
(This commit also modifies the decklink, linux-v4l2, mac-avcapture,
obs-ffmpeg, and win-dshow modules)

Originally, async buffering for sources was supposed to be a
user-controllable flag.  However, that turned out to be less than ideal
because sources (such as the win-dshow plugin) were programmed with
automatic control over their buffering (such as automatically detecting
USB 2.0 capture devices and then enabling in those cases).

The fact that it was a flag caused a design flaw to where buffering
values would be overwritten when a source is loaded from save data.

Because of that, this flag is being deprecated and replaced with a
specific function to enable unbuffered mode instead.
2017-05-13 23:32:40 -07:00
jp9000 d64542e10b Revert "libobs: Allow source to fully control source flags (for now)"
This reverts commit d85224bb9b.

Would cause other flags to stop saving.  Buffering needs to be split off
from the source flags.
2017-05-13 23:30:36 -07:00
jp9000 e7f754df97 libobs: Use tex.Load for reverse NV12/I420 funcs
Eventually, most things should be replaced with Load where applicable
(though in some cases sub-pixel sampling is desired).

This commit also fixes a bug where NV12 async sources wouldn't render
correctly.
2017-05-06 01:24:45 -07:00
Shaolin e006d961a4 audio-monitoring: Add ability to monitor Outputs
(Note: This commits also modifies the linux-pulseaudio, mac-capture, and
win-wasapi plugins)

Do not prevent the targeted output device from being monitored if the
selected monitor output device is a different one.

Closes jp9000/obs-studio#872
2017-04-05 18:58:08 -07:00
jp9000 0941a9c13d libobs: Add ability to preload async frames
Prevents any delay when starting up certain async video sources.
Additionally prevents old frames from being presented as well.
2017-03-28 09:39:47 -07:00
jp9000 d85224bb9b libobs: Allow source to fully control source flags (for now)
This change prevents source flags from being incorrectly overwritten and
set to 0.  Eventually flags need to be separated from source settings
and this should be reverted, but for now this solves an issue where
buffering would be enabled on async video sources regardless of whether
the user disabled it or not on the source.
2017-03-28 09:19:01 -07:00
cg2121 1ef7a48e9c libobs: Add obs_source_copy_filters function
Allows copying filters from one source to another.

Closes jp9000/obs-studio#860
2017-03-25 04:23:22 -07:00
Richard Stanway 8b640fae24
Fix various null pointer issues detected by Coverity 2017-02-25 16:45:45 +01:00
jp9000 d2934eca7e libobs: Implement audio monitoring
Adds functions to turn on audio monitoring to allow the user to hear
playback of an audio source over the user's speaker.  It can be set to
turn off monitoring and only output to stream, or it can be set to
output only to monitoring, or it can be set to both.

On windows, audio monitoring uses WASAPI.  Windows also is capable of
syncing the audio to the video according to when the video frame itself
was played.

On mac, it uses AudioQueue.

On linux, it's not currently implemented and won't do anything (to be
implemented).
2017-02-06 11:44:02 -08:00
jp9000 74f9c389cb libobs: Use original audio structure for audio signal
Ensures audio has the source-local timestamp when used with audio
monitoring.
2017-02-06 11:44:01 -08:00
jp9000 f728f5b9ec libobs: Mark parameter as constant if not modifying 2017-02-06 11:44:00 -08:00
jp9000 d60d222d71 libobs: Mark last video ts even when buffering off
Ensures that the system always has a record of when the last video frame
was played.
2017-02-06 11:43:59 -08:00
jp9000 69ec87b9a5 libobs: Enumerate full tree when adding active child
Fixes a bug that would allow possible infinite recursion within a source
tree.  To fix this, inactive sources must be enumerated as well in order
to prevent infinite recursion.
2017-01-16 09:53:16 -08:00
jp9000 2877f1d553 libobs: Add func to enum active and inactive child tree 2017-01-16 09:53:08 -08:00
jp9000 521c40460e libobs: Fix bug drawing RGB/BGR async sources
Commit 53955301a2 introduced a async source texture copy bug due to
creating a new case in a switch without adding a break to the one above
it, causing it to execute both cases by mistake.
2016-12-21 20:11:31 -08:00
jp9000 f10e2c6740 libobs: Increase maximum audio tracks to 6 2016-12-21 17:13:19 -08:00
jp9000 53955301a2 libobs: Fix line size issue when copying Y800 data 2016-12-17 22:53:52 -08:00
jp9000 919aecfd62 libobs: Fix format not being set for new source frames
With the previous Y800 fix a bug was introduced where the format for the
destination frame wouldn't be set if it wasn't Y800, causing a crash.
2016-12-17 21:56:10 -08:00
jp9000 85269fb5b2 libobs: Convert Y800 to RGBX manually
Because D3D11 specifically does not support an L8 texture format (you
have to use a shader swizzle), manually convert Y800 signals to RGBX
instead.  This also fixes a bug where Y800 signals will render red.

Closes jp9000/obs-studio#718
2016-12-17 19:58:01 -08:00
Jim 9982581a4f libobs: Ensure async source sizes are always reset
If an async source is cropped on one side, then when the program is
restarted and the source is loaded from file, the async source will
start out with a width/height of zero.  This will cause the async source
to not be drawn if cropping or scale filtering is added to the scene
item, because it has to be rendered to a texture first.  However, the
source cannot reset its size until it's drawn, so it leaves it in
perpetual state of having a 0x0 size.

This fixes that problem by ensuring that the async source size is always
reset even when not being rendered.

Close jp9000/obs-studio#686
2016-11-10 00:13:06 -08:00
Christoph Hohmann a276b9023b libobs: Duplicate filters of a scene when it is is duplicated
When a scene is duplicated the filters on the scene were not copied to
the new scene. This causes that a temporary copy of a scene renders
differently in the program than in the preview when using studio mode.
2016-11-05 19:51:06 +01:00
jp9000 526d390adb libobs: Reduce unnecessary logging (info -> debug)
(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.
2016-08-05 18:59:32 -07:00
jp9000 a9caa99c5b libobs: Fix source active/show incrementing/decrementing
The active_refs and show_refs variable would only increment/decrement
their children if their values were 1 and 0, which means that in the
case of scenes within scenes, sub-sources of scenes within scenes would
end up having the wrong ref values.
2016-07-02 14:13:17 -07:00
jp9000 643823505c libobs: Fix obs_source_duplicate on scenes
Scenes have special duplication handling, so make it internally call
obs_scene_duplicate instead.
2016-07-01 15:20:27 -07:00
jp9000 5cc59256e7 libobs: Fix 'set but unused' warnings 2016-06-22 14:10:43 -07:00
jp9000 b5df4537a9 libobs: Fix null pointer dereference w/ null private sources 2016-06-11 12:27:05 -07:00
jp9000 fb1ff173f9 libobs: Fix crash with 4:2:0 async source resolutions
When using GPU conversion for 4:2:0 frames on async video sources, it
would create a texture bigger than necessary and try to copy too much
data from the frame, resulting in a crash.
2016-06-06 23:46:56 -07:00
jp9000 cb9ce7547d libobs: Fix bug activating/showing transitions in a tree
When a transition is a sub-source of another source, it would not call
the transition's active source enum function, meaning that any sources
the transition had would not increment their active/showing refs (it
would only be called when activating the transition directly before).
That would result in negative/invalid active/showing refs on its
sub-sources, causing them to become permanently active/inactive and/or
permanently showing/hidden.
2016-05-26 08:13:21 -07:00
jp9000 2741624fbe libobs: Log when a filter is added/removed from a source 2016-05-04 20:29:26 -07:00
jp9000 ff99ba7818 libobs: Allow filter processing function to return false
(Note: this commit also modifies the obs-filters and test-input modules)

Changes the obs_source_process_filter_begin return type so that it
returns true/false to indicate that filter processing should or should
not continue (for example if the filter is bypassed or if there's some
other sort of issue that causes the filtering to fail)
2016-04-22 10:18:12 -07:00
Richard Stanway bc231eda75
libobs: Fix a race condition when initializing audio sources
The source shouldn't be inserted into obs->data.first_audio_source until it's
fully initialized, or other threads will access source->control and
dereference an uninitialized pointer.
2016-04-13 18:39:24 +02:00
Richard Stanway a73b09c74e
libobs: Remove various dead code found by static analysis
Detected by Coverity Scan (CID 92178, 92171)
2016-04-13 02:43:11 +02:00
jp9000 2274b57926 libobs: Mark filters as private (band-aid fix)
This patch fixes a specific crash where if the user named a filter the
same name as an input source that already existed in the system, scene
item loading code could find the filter with the same name instead of
the source, and mistakenly use it as the scene item's source directly.
This would cause a crash when trying to render that filter as a regular
source.

Marking filters as private is a temporary and simple workaround to the
solution.  Filters are currently not meant to be found via the main
enumeration/search functions, which is a design flaw (lack of
consistency).  In future major API revisions of libobs, filters should
be reworked to act as sources, with the sources they filter as
sub-sources ideally.

Additionally, the concept of "private context objects" and "primary
lists of context objects" in the back-end should probably also be
removed, allowing the font-end (or optional separate API layers) to
control all primary lists of obs context objects.  These minor issues
that occur ultimately stem from API design flaws which need to be
corrected.
2016-04-09 18:12:50 -07:00
jp9000 f23974ab64 libobs: Fix possible crash with filters
This crash happened when a filter was mistakenly used as a regular
source due to an unrelated bug in filter code and scene loading code.
The filter and the source it belongs to both had the same names, and the
source loading code found the filter and mistakenly used it as the
source instead of the actual source with the same name.
2016-04-09 18:12:49 -07:00
jpk c3629eacb5 libobs: Add Y800 color format support
(Note: Also modified the obs-ffmpeg plugin module)

Allows the ability for frame data to pass 8-bit grayscale images (Y800
color format).

Closes jp9000/obs-studio#515
2016-03-24 03:33:35 -07:00
jp9000 07c644c581 libobs: Add deinterlacing API functions
Adds deinterlacing API functions.  Both standard and 2x variants are
supported.  Deinterlacing is set via obs_source_set_deinterlace_mode and
obs_source_set_deinterlace_field_order.

This was implemented in to the core itself because deinterlacing should
happen before effect filters are processed, but after async filters are
processed.  If this were added as a filter, there is the possibility
that a different filter is processed before deinterlacing, which could
mess with the result.  It was also a bit easier to implement this way
due to the fact that that deinterlacing may need to have access to the
previous async frame.

Effects were split in to separate files to reduce load time (especially
for yadif shaders which take a significant amount of time to compile).
2016-03-21 21:22:32 -07:00
jp9000 11d9a8f3e4 libobs: Rename async_convert_texrender to async_texrender 2016-03-21 21:22:31 -07:00
jp9000 9a86a10f91 libobs: Update async textures via function parameters
Instead of just updating the async texture variables directly in the
source, allow the ability to pass the async texture variables via
function parameters to allow the ability to parse more than one frame to
more than one texture.

This code is primarily intended to be used to upload/convert the
"previous" async frame for the deinterlacer (if necessary).
2016-03-21 21:22:31 -07:00
jp9000 12cdaec1a7 libobs: Move frame-related functions to obs-internal.h
Allows access in other source files (particularly the deinterlacer)
2016-03-21 21:22:30 -07:00
John Bradley 310f390e1e libobs: Allow filters to specify technique 2016-03-21 21:22:27 -07:00
jp9000 9e15e3d8fd libobs: Remove need for DrawMatrix technique in effects
(Note: This commit also modifies obs-filters and text-freetype2)

This simplifies writing of effects.  DrawMatrix is no longer necessary
because there are no sources that require drawing with a color matrix
other than async sources, and async sources are automatically processed
and don't defer their initial render stage to filters.
2016-03-21 21:22:26 -07:00
jp9000 d069302b2e libobs: Add function to get obs object type 2016-02-27 02:49:03 -08:00
jp9000 a64f7dd649 libobs: Fix an issue that would cause audio stuttering
Under certain circumstances, the timing_adjust variable would cause line
1161 to continually trigger over and over again.  The "loop detection"
code incorrectly made it so that any timestamp that was just simply
below the expected value would be seen as a jump.  After that, the
timing_adjust variable would be set for the frame again, and then the
audio would see it as a jump again after that, and those two things
would continue endlessly.  This would cause stuttering particularly with
certain devices (particularly elgato/lgp/hdpvr) where the audio/video
data are decoded and sent at varying/different/unpredictable times.

To fix this issue, it should not detect values below as jumps, but
instead should only do it for values that exceed the MAX_TS_VAR (maximum
timestamp variance) value.
2016-02-21 11:04:34 -08:00
jp9000 fa8ae473cf libobs: Fix bug where source audio could stop outputting
If obs_source::audio_ts is set to 0 (such as by discard_if_stopped in
obs-audio.c), but the push_back variable in the source_output_audio_data
function in obs-source.c was being set to true (meaning it's within the
seamless audio smoothing threshold), it would cause it to never reset
the obs_source::audio_ts value, and thus all audio data from the source
would become perpetually ignored by the audio subsystem until there was
finally some sort of timestamp jump that caused it to call
source_output_audio_place, and thus reset obs_source::audio_ts.

obs_source::audio_ts is only reset in source_output_audio_place, not in
source_output_audio_push_back, so the most simple solution is to just
call source_output_audio_push_back is obs_source::audio_ts is 0.
2016-02-04 01:36:13 -08:00
jp9000 b86fdae4a8 libobs: Don't clear audio on ts jump (seamless loops)
There's technically no need to clear the audio data here, nor is there
any need to try to trick the timestamp in to a different position.  It
can simple just reset the audio timing.

Prevents a possible case where audio data might be deleted when it's not
necessary to delete any.
2016-02-03 11:29:09 -08:00
jp9000 d2f2783b44 libobs: Always reset last audio buf size when it changes
This variable is used to detect whether audio has stopped -- if audio
stops, it detects that no new data is coming in, and resets the audio
position so that it eliminates the chance of causing the audio buffering
to go haywire if audio starts up again.  However, this variable was not
being reset every time the value changes, which it should.
2016-01-31 14:08:37 -08:00
jp9000 971728a1a7 libobs: Fix variable being access outside of a mutex
audio_input_buf should never be accessed outside of audio_buf_mutex.
2016-01-31 00:54:55 -08:00
jp9000 d43d59ca8a libobs: Remove seamless audio loop handling
The seamless audio looping code would erroneously trigger for things
that weren't loops, causing the audio data to continually push back and
ignore timestamps, thus going out of sync.

There does need to be loop handling code, but due to the fact that other
things may need to trigger this code, it's best just to clear the audio
data and start from a fresh sync point.  Unfortunately for the case of
loops, this means the window in which audio data loops and video frames
loop need to be muted.
2016-01-31 00:54:54 -08:00
jp9000 eae1328a4f libobs: Always return audio as pending if not an audio source
This is an additional method/helper that prevents composite sources from
treating non-audio sources as audio sources.
2016-01-31 00:54:53 -08:00
jp9000 6f98bd9fed libobs: Use calldata with stack for simple signals
Makes signals use stack memory rather than allocate memory each time.
Most likely a completely insignificant and pointless optimization.
2016-01-26 11:49:56 -08:00
jp9000 ce0a189228 libobs: Fix audio issues with async video/audio looping
This fixes an age-old issue where audio samples could be lost or audio
could temporarily go out of sync in the case of looping videos.  When
audio/video data is looping, there's a window between when the audio
data resets its timestamp value and when the video data resets its
timestamp value.  This method simply pushes back the audio data while in
that window and does not modify sync, and when it detects that its out
of the loop window it simply forces a resync of the audio data in the
circular buffer.

This ensures that minimal audio data is lost in the loop process, and
minimizes the likelihood of any sort of sync issues associated with
looping.
2016-01-26 11:49:54 -08:00
jp9000 41fa9c1bdb libobs: Don't include sync offsets in TS smoothing
Apply user sync offset *after* timestamp smoothing, not before.
Prevents small or gradual sync offsets from not being properly applied.
2016-01-26 11:49:54 -08:00
jp9000 1089564b57 libobs: Apply resampler offset to system audio TS
Instead of applying the resampler offset right away (to each audio
packet), apply the resampler offset when the timestamps are converted to
system timestamps.  This fixes an issue where if audio timestamps reset
to 0 (for whatever reason), the offset would cause the timestamp to go
in to the negative.
2016-01-26 11:49:53 -08:00
jp9000 9661ba8142 libobs: Add obs_source_duplicate function
Allows full duplication of sources (with exception of sources that are
marked with the OBS_SOURCE_DO_NOT_DUPLICATE output capability flag)
2016-01-26 11:49:51 -08:00
jp9000 56dc605497 libobs: Add obs_is_source_configurable function
Mostly only used for transitions with the intention of automatically
creating transitions which don't require configuration, returns whether
the source has any properties or not (whether it's configurable)
2016-01-26 11:49:49 -08:00
jp9000 3371ff59c9 libobs: Add *_create_private functions
Allows creation of private/unlisted sources/outputs/services/encoders
2016-01-26 11:49:48 -08:00
jp9000 bccd3b0b0a libobs: Allow "private" contexts
The intention of this is to allow sources/outputs/etc to be created
without being visible to the UI or save/load functions.
2016-01-26 11:49:47 -08:00
jp9000 669da7ba36 libobs: Do not use signals with audio capture/controls
(Note: This commit also modifies UI)

Instead of using signals, use designated callback lists for audio
capture and audio control helpers.  Signals aren't suitable here due to
the fact that signals aren't meant for things that happen every frame or
things that happen every time audio/video is received.  Also prevents
audio from being allocated every time these functions are called due to
the calldata structure.
2016-01-26 11:49:47 -08:00
jp9000 6839ff7686 libobs: Implement transition sources
Transition sources are implemented by registering a source type as
OBS_SOURCE_TYPE_TRANSITION.  They're automatically marked as video
composite sources, and video_render/audio_render callbacks must be set
when registering the source.  get_width and get_height callbacks are
unused for these types of sources, as transitions automatically handle
width/height behind the scenes with the transition settings.

In the video_render callback, the helper function
obs_transition_video_render is used to assist in automatically
processing and rendering the audio.  A render callback is passed to the
function, which in turn passes to/from textures that are automatically
rendered in the back-end.

Similarly, in the audio_render callback, the helper function
obs_transition_audio_render is used to assist in automatically
processing and rendering the audio.  Two mix callbacks are used to
handle how the source/destination sources are mixed together.  To ensure
the best possible quality, audio processing is per-sample.

Transitions can be set to automatically resize, or they can be set to
have a fixed size.  Sources within transitions can be made to scale to
the transition size (with or without aspect ratio), or to not scale
unless they're bigger than the transition.  They can have a specific
alignment within the transition, or they just default to top-left.
These features are implemented for the purpose of extending transitions
to also act as "switch" sources later, where you can switch to/from two
different sources using the transition animation.

Planned (but not yet implemented and lower priority) features:

- "Switch" transitions which allow the ability to switch back and forth
  between two sources with a transitioning animation without discarding
  the references

- Easing options to allow the option to transition with a bezier or
  custom curve

- Manual transitioning to allow the front-end/user to manually control
  the transition offset
2016-01-26 11:49:45 -08:00
jp9000 5098f68db0 libobs: Move obs_source_dosignal to obs-internal.h
Allows using it in multiple source files
2016-01-26 11:49:40 -08:00
jp9000 b0104fcee0 (API Change) libobs: Remove source_type param from functions
(Note: test and UI are also modified by this commit)

API Changed (removed "enum obs_source_type type" parameter):
-------------------------
obs_source_get_display_name
obs_source_create
obs_get_source_output_flags
obs_get_source_defaults
obs_get_source_properties

Removes the "type" parameter from these functions.  The "type" parameter
really doesn't serve much of a purpose being a parameter in any of these
cases, the type is just to indicate what it's used for.
2016-01-26 11:49:37 -08:00
jp9000 c1dd156db8 libobs: Implement new audio subsystem
The new audio subsystem fixes two issues:

- First Primary issue it fixes is the ability for parent sources to
  intercept the audio of child sources, and do custom processing on
  them.  The main reason for this was the ability to do custom
  cross-fading in transitions, but it's also useful for things such as
  side-chain effects, applying audio effects to entire scenes, applying
  scene-specific audio filters on sub-sources, and other such
  possibilities.

- The secondary issue that needed fixing was audio buffering.
  Previously, audio buffering was always a fixed buffer size, so it
  would always have exactly a certain number of milliseconds of audio
  buffering (and thus output delay).  Instead, it now dynamically
  increases audio buffering only as necessary, minimizing output delay,
  and removing the need for users to have to worry about an audio
  buffering setting.

The new design makes it so that audio from the leaves of the scene graph
flow to the root nodes, and can be intercepted by parent sources.  Each
audio source handles its own buffering, and each audio tick a specific
number of audio frames are popped from the front of the circular buffer
on each audio source.  Composite sources (such as scenes) can access the
audio for child sources and do custom processing or mixing on that
audio.  Composite sources use the audio_render callback of sources to do
synchronous or deferred audio processing per audio tick.  Things like
scenes now mix audio from their sub-sources.
2016-01-26 11:49:34 -08:00
jp9000 ddfd89a673 libobs: Implement composite sources (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

Adds a "composite" source type which is used for sources that composite
one or more sub-sources.  The audio_render callback is called for
composite sources to allow those types of sources to do custom
processing of the audio of its sub-sources.
2016-01-26 11:49:33 -08:00
jp9000 a5c9350be5 libobs: Remove "presentation volume" and "base volume" (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

These variables are considered obsolete and will no longer be needed.
2016-01-26 11:49:32 -08:00
jp9000 73ec5906b7 libobs: Add function that checks whether source is muted (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)
2016-01-26 11:49:32 -08:00
jp9000 27438a5156 libobs/media-io: Remove 'volume' from audio_data (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

This variable is somewhat redundant.  Volume is already known/accessible
to front-ends.
2016-01-26 11:49:31 -08:00
jp9000 bc0b85cb79 libobs: Store circular audio buffer on source itself (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

Removes audio lines and stores the circular buffer for the audio on the
source itself.
2016-01-26 11:49:30 -08:00
jp9000 f73bbe6746 libobs: Store source audio mixers in obs_source (skip)
(Note: This commit breaks libobs compilation.  Skip if bisecting)

The mixers that a source was assigned to were originally stored in the
audio line.  This will store it in the sources themselves instead.
2016-01-26 11:49:29 -08:00
jp9000 ed8998e403 libobs: Do recursive height/width calls on non-filters
Originally this was programmed to call the recursive height/width
functions if the source type was an input with the intention of not
calling it on filters, but instead of doing that just program it to do
just that: only call the recursive height/width functions if it's not a
filter.
2016-01-23 07:17:47 -08:00
jp9000 8f7d8d05b2 libobs: Add sample_rate param to conv_frames_to_time
Prevents from having to query the base audio subsystem for the sample
rate each time the function is called
2015-12-22 06:18:21 -08:00
jp9000 96d9bf794c libobs: Store linked list of audio sources
Useful for going traversing the list of audio sources (particularly for
the new audio subsystem)
2015-12-22 06:18:20 -08:00
jp9000 a702d88c25 libobs: Don't track active transitions
This was originally used for calculating audio volume if transitions
were active, but transitions won't work that way so tracking the active
transitions is no longer needed.
2015-12-22 06:18:19 -08:00
jp9000 c8f4fbe42b (API Change) libobs: Rename funcs relating to active child sources
Renames:
----------------------------------------
obs_source_add_child
obs_source_remove_child
obs_source_enum_sources
obs_source_enum_tree
obs_source_info::enum_sources

To:
----------------------------------------
obs_source_add_active_child
obs_source_remove_active_child
obs_source_enum_active_sources
obs_source_enum_active_tree
obs_source_info::enum_active_sources

These functions/callbacks had misleading names: they originally implied
any child sources, when they actually meant active child sources that
are being used to render video or audio.  It's important that the
function names represent their actual purpose.
2015-12-22 05:49:02 -08:00
jp9000 70fec7ae8e (API Change) libobs: Remove "User sources list" (skip)
(Note: This commit breaks UI compilation.  Skip if bisecting)

API Removed:
------------------------
obs_add_source

API Changed:
------------------------
obs_source_remove: Now just marks/signals a source for removal

The concept of "user sources" is flawed: it was something that the
front-end was forced to deal with if it wanted to automate source
saving/loading, and often it had to code around it.  That's not how
saving/loading should work, a front-end should be allowed to manage
lists of sources in the way it explicitly chooses, and it should be able
to choose which sources it wants to save/load.
2015-12-22 05:48:43 -08:00
jp9000 59f0ba0c8a libobs: Add load/save signals for sources
These signals are meant to replace the add/remove signals.
2015-12-22 05:36:22 -08:00
jp9000 11922265de libobs: Keep reference to source when rendering 2015-12-15 01:11:11 -08:00
jp9000 332359d286 libobs: If filter size invalid, skip filter
This shouldn't happen anymore because crop was fixed, but if a filter
returns 0x0 size and is invalid it shouldn't stop the filter chain.
Instead, it should just be skipped.
2015-11-20 14:07:15 -08:00
jp9000 fea4f75157 libobs: Update async video texture before effect filters
When an async video source is about to be rendered, the async texture
should be updated before any effect filtering occurs, rather than right
when it's about to render.

Fixes a few bugs:

- If the async texture hadn't drawn for its first time, and the source
  has an effect filter, it would never end up rendering the first
  frame due to the fact that it would fail on obs-source.c:2434 for the
  first filter, causing it to never actually render the source, and thus
  never get to a point in which it could call set_async_texture_size to
  establish the async texture width/height for the first time.

- Any time the async texture size changed, it would only update the
  async texture size at the end of the filter loop, which means that the
  first frame after a size change would use the old size for the filters
  rather than update to the new size right away.
2015-10-22 17:46:54 -07:00
jp9000 db7aebb940 libobs: Allow null pointer with obs_source_release_frame
A null pointer to a release/destroy function should be considered legal,
and simply do nothing.
2015-10-22 17:45:58 -07:00
jp9000 485a006215 libobs: Check source textures before destroying
Check to make sure the texrenders and textures on a source are valid
before destroying.
2015-10-21 07:46:40 -07:00
jp9000 f07ce8501f libobs: Add null debug messages for base obs funcs 2015-10-21 06:30:32 -07:00
jp9000 c27ff7903d libobs: Display debug msg in data_valid if null
Uses obs_source_valid in data_valid which will ensure a debug message is
displayed if null.
2015-10-21 06:28:03 -07:00