0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00
Commit Graph

218 Commits

Author SHA1 Message Date
jp9000
f109be3010 libobs: Fix potential bug destroying filters
When OBS is shutting down, if for some reason the filter is destroyed
before the parent source is destroyed, it would try to remove itself
from the source, but it would decrement the reference and try to destroy
itself again while already in the process of destroying itself.

So, the solution was simply to make sure that if it's removing itself
from the source that it doesn't decrement its own reference.
2015-03-25 10:03:15 -07:00
jp9000
18afe82304 libobs: Skip filter if internal data not present
If the filter's binary was recently removed, the data will be invalid,
so make sure that it properly handles that situation by skipping the
filter.
2015-03-25 10:03:14 -07:00
jp9000
e31fea66be libobs: Add API to mute/unmute sources 2015-03-25 10:03:13 -07:00
jp9000
f04ef236ac libobs: Add ability to disable sources/filters 2015-03-25 10:03:13 -07:00
jp9000
98a6c8f0d0 libobs: Always enumerate filter list in reverse
The "last" filter that's rendered is technically at filter index 0, so
enumeration needs to be from the last index in the list to the first
index in the list.
2015-03-25 10:03:12 -07:00
jp9000
64943f3fc6 libobs: Lock mutex when changing filter order
Refactors the function a bit to ensure that the filter mutex is locked
when changing the filter order.
2015-03-25 10:03:11 -07:00
jp9000
dedc454caf libobs: Add "reorder_filters" source signal
Signals when the filter order has been changed for a source.
2015-03-25 10:03:10 -07:00
jp9000
4aa8f2d14b libobs: Fix bug when changing filter order
The 'idx' variable is the incorrect variable to be using here, the
variable that was supposed to be used was 'i'.
2015-03-25 10:03:09 -07:00
jp9000
86a0f370c3 libobs: Insert new filters at index 0
Technically, the "last" filter rendered is the filter at index 0, so
inserting a new filter at that point makes the most sense.
2015-03-25 10:03:08 -07:00
jp9000
c0cc81d20f libobs: Turn blending off for filter renders
When rendering a filter to a texture, the target is empty and unused, so
there's no reason for blending to be on when rendering the filter to a
render target.
2015-03-25 10:03:07 -07:00
jp9000
44e484ad34 (API Change) Fix filter rendering design flaw
obs_source_process_filter tried to do everything in a single function,
but the problem is that effect parameters would not properly be
accounted for due to the way it internally draws, therefore it was
necessary to split the functions in to two, you first call
obs_source_process_filter_begin, then you set your effect parameters,
then you finally call obs_source_process_filter_end.  This ensures that
when the filter is drawn, that the effect parameters are set.
2015-03-25 10:03:06 -07:00
jp9000
44f103de9c libobs: Fix rendering at end of the filter chain
When the filter chain finally reaches the source and the last filter in
the chain is set to not render directly (meaning it has to render to
texture), it would not render the source with any effect due to the fact
that it expects a filter to be present.
2015-03-25 10:03:05 -07:00
jp9000
7878fda442 libobs: Add filter_remove callback for sources
Adds a source callback function that is used when a filter is removed
from a source.  This ensures that any data that might be associated with
that source can be cleaned up if necessary.
2015-03-25 10:03:04 -07:00
jp9000
cd7d045ff3 libobs: Make filter mutex recursive 2015-03-25 10:03:03 -07:00
jp9000
c2775eaa3d libobs: Add obs_source_skip_video_filter function
This allows a filter to skip its step and move on to the next target in
the chain without affecting performance.
2015-03-25 10:03:02 -07:00
jp9000
f4af2fcadc libobs: Always clear render target filter
This fixes a bug where the previous contents of a filter's render target
texture might become visible if using alpha.
2015-03-25 10:03:01 -07:00
jp9000
dfde8d4a63 libobs: Use 'can_bypass' func for filter bypassing
There are a few more conditions which need to be checked to ensure
whether we can actually bypass or not; in this particular case we are
using the YUV texture shaders, plus the image can also be flipped, so we
can't really use the bypass optimization in those situations.
2015-03-25 10:03:00 -07:00
jp9000
b9eef3c4f2 libobs: Add API to get base source dimensions
These functions are primarily for use with filters, filters need to be
able to get the width/height of a target source without it necessarily
getting the post-filtered dimensions.
2015-03-25 10:02:59 -07:00
jp9000
506e30da10 libobs: Do not clear frame cache if 0,0 dimension
Previously I had it set so that it would set the async_width and
async_height variables to 0,0 if a null frame occurs, but the problem
with this is that it was inadvertently cause the frame cache to clear
when it starts receiving textures again because it detects it as a size
change.

So instead of changing async_width and async_height to 0 when a null
frame occurs, change it so that if the source is set to an inactive
state, make obs_source_get_width/_get_height return 0 for their
dimensions instead.
2015-03-25 10:02:58 -07:00
jp9000
26206f6af4 libobs: Use reference counting with source frames
When a frame is processed by a filter, it comes directly from the
source's video frame cache.  However, if a filter is using or processing
those frames for whatever reason, there would be no guarantee that the
frames would persist during processing, and frames could eventually be
deallocated unexpected, for example when the resolution or format
changes.

So the solution is to implement simple reference counting for the frames
so that the frames will exist until they have been released by any
source or filter that's using them.
2015-03-25 10:02:57 -07:00
jp9000
ebee67097a libobs: Prevent video cache clear on first frame
Fix a bug where when a source first starts up its async cache, it
unintentionally resets its cache, which means that the first few frames
would be lost.
2015-03-22 19:18:19 -07:00
jp9000
13046145f7 libobs: Fix filter dimension issue
The wrong function was being used to recurse through the filter chain in
obs_source_process_filter, obs_source_get_[width/height] would get the
post-effect dimensions rather than the pre-effect dimensions.
2015-03-22 18:38:40 -07:00
jp9000
95e63992cb libobs: Fix filter rendering bug
The parameters order was wrong; sort of a rare thing to see, but it can
happen, especially when it's a function that's not used very often.
2015-03-22 18:28:12 -07:00
jp9000
0f31880c3c libobs: Fix bug (source resampler not resetting)
If the audio data had the same format/samplerate as the obs audio
subsystem, it would fail to simply destroy the resampler and set it to
NULL, and then any audio data going through would use the resampler that
was being used before that, causing audio to become garbage.

This bug only started appearing when I recently changed the libobs
internal audio subsystem format to non-interleaved floating point, which
is a common format, and thus caused this bug to actually occur more
often.
2015-03-13 01:03:01 -07:00
jp9000
4fdd8fb570 libobs: Don't ignore starting audio if async
I when a source has both async audio/video capability, it would ignore
audio until the video has started.  There's really no need to do this,
when the video starts it'll just fix up the timing automatically.

This should fix the case where things like the media source would not be
able to play audio-only files.
2015-03-12 22:27:36 -07:00
jp9000
9832a760b8 (API Change) Always use planar float audio output
Core API functions changed:
-----------------------------
EXPORT bool obs_reset_audio(struct audio_output_info *aoi);
EXPORT bool obs_get_audio_info(struct audio_output_info *aoi);

To:
-----------------------------
EXPORT bool obs_reset_audio(const struct obs_audio_info *oai);
EXPORT bool obs_get_audio_info(struct obs_audio_info *oai);

Core structure added:
-----------------------------
struct obs_audio_info {
	uint32_t            samples_per_sec;
	enum speaker_layout speakers;
	uint64_t            buffer_ms;
};

Non-interleaved (planar) floating point output is standard with audio
filtering, so to prevent audio filters from having to worry about
different audio format implementations and for the sake consistency
between user interfaces, make it so that audio is always set to
non-interleaved floating point output.
2015-03-12 22:22:02 -07:00
Palana
89b7230652 libobs: Fix async plane offset calculation
Frames allocated via video_frame_init from media-io/video-frame.c have
their planes aligned which the original offset calculation didn't take
into account, resulting in some planes being drawn incorrectly.

Example media file to reproduce via the ffmpeg (media) source:
http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi
2015-03-10 18:20:49 +01:00
jp9000
50a36f45cd libobs: Add obs_source_get_filter_by_name function 2015-03-06 09:13:56 -08:00
jp9000
9f82085243 libobs: Add obs_source_enum_filters function
Enumerates filters that are currently present on a source.
2015-03-06 09:12:00 -08:00
jp9000
0b5a5c16a9 libobs: Fix bug rendering async video with filters
This code was originally meant to skip some checks as an optimization,
but it did not account for async video sources and would call
obs_source_default_render (which is only for synchronous video sources),
this fixes the issue by just calling obs_source_video_render.
2015-03-06 09:09:57 -08:00
jp9000
502f4005f1 libobs: Fix race condition when adding a filter
The source would sometimes be rendered before the code to add it to the
filter chain was executed, therefore it would cause a crash.
2015-03-06 09:09:57 -08:00
jp9000
b1ba8561ff libobs: Keep references to filters when on sources
When a filter is added to a source, it does not currently keep a
reference when it's associated that that source, this fixes that
problem.
2015-03-06 09:09:56 -08:00
jp9000
3510e69121 libobs: Account for filters in source dimensions
The obs_source_get_width and obs_source_get_height functions need to
account for filters that may change their width/height such as a crop
filter or something similar.

As a side effect of this commit, because these functions need to lock
the filter mutex, these functions can no longer be used with a
const-qualified obs_source_t pointer.
2015-03-06 09:09:56 -08:00
jp9000
46341725c2 libobs: Remove inline from function
This function is somewhat big and is a function called conditionally,
therefore having it be inline is somewhat of a waste if it's not always
being called.
2015-03-06 09:09:56 -08:00
jp9000
818a57c33f libobs: Fix graphics memory leak
Graphics data has to be freed inside of an active graphics context,
otherwise the resources will not be freed; in the future, we should
probably make sure that the graphics subsystem automatically
asserts/warns about this scenario.
2015-03-06 09:09:56 -08:00
jp9000
8e5a0970b1 libobs: Fix releasing filters on source destroy
I was iterating through the obs_source::filters array to remove filters,
but every time I removed a filter, it would remove itself from the
array, therefore it would end up skipping items in the array, therefore
leaving filters unreleased.  This just removes the first filter until
all filters have been removed.
2015-03-06 09:09:56 -08:00
jp9000
95a5e8009f libobs: Add filter add/remove signals
Adds "filter_remove" and "filter_add" signals that signal when a filter
is added or removed
2015-03-06 09:09:55 -08:00
jp9000
8323799113 libobs: Use video thread for show/active callbacks
For the show/hide and activate/deactivate callbacks, schedule these
callbacks to only be called from within the video thread rather than in
a separate thread.  This ensures that any potential graphics activity
that occurs within them is kept in the same thread.
2015-03-02 18:53:25 -08:00
jp9000
7055775c7c libobs: Add functions to show/hide sources
obs_source_inc_showing and obs_source_dec_showing are used to indicate
that a source is showing or no longer being shown in a particular area
of the program outside from the main render view.

One could use an obs_view, but I felt like it was unnecessary because
using an obs_view just to display a single source feels somewhat
superfluous.
2015-03-02 12:23:25 -08:00
Palana
d085d6e4a1 libobs: Allow duplicate sources per scene
Previously having a source multiple times in a single scene would cause
the recursion check to trigger. Example scenes.json:

{
    "current_scene": "Scene",
    "sources": [
        {
            "flags": 0,
            "id": "scene",
            "mixers": 0,
            "name": "Scene",
            "settings": {
                "items": [
                    {
                        "align": 5,
                        "bounds": {
                            "x": 0.0,
                            "y": 0.0
                        },
                        "bounds_align": 0,
                        "bounds_type": 0,
                        "name": "Text (FreeType 2)",
                        "pos": {
                            "x": 0.0,
                            "y": 0.0
                        },
                        "rot": 0.0,
                        "scale": {
                            "x": 1.0,
                            "y": 1.0
                        },
                        "visible": true
                    },
                    {
                        "align": 5,
                        "bounds": {
                            "x": 0.0,
                            "y": 0.0
                        },
                        "bounds_align": 0,
                        "bounds_type": 0,
                        "name": "Text (FreeType 2)",
                        "pos": {
                            "x": 0.0,
                            "y": 98.0
                        },
                        "rot": 0.0,
                        "scale": {
                            "x": 1.0,
                            "y": 1.0
                        },
                        "visible": true
                    }
                ]
            },
            "sync": 0,
            "volume": 1.0
        },
        {
            "flags": 0,
            "id": "text_ft2_source",
            "mixers": 0,
            "name": "Text (FreeType 2)",
            "settings": {},
            "sync": 0,
            "volume": 1.0
        }
    ]
}
2015-02-17 13:41:49 +01:00
jp9000
84e1f47ced (API Change) Add support for multiple audio mixers
API changed:
--------------------------

void obs_output_set_audio_encoder(
		obs_output_t *output,
		obs_encoder_t *encoder);

obs_encoder_t *obs_output_get_audio_encoder(
		const obs_output_t *output);

obs_encoder_t *obs_audio_encoder_create(
		const char *id,
		const char *name,
		obs_data_t *settings);

Changed to:
--------------------------

/* 'idx' specifies the track index of the output */
void obs_output_set_audio_encoder(
		obs_output_t *output,
		obs_encoder_t *encoder,
		size_t idx);

/* 'idx' specifies the track index of the output */
obs_encoder_t *obs_output_get_audio_encoder(
		const obs_output_t *output,
		size_t idx);

/* 'mixer_idx' specifies the mixer index to capture audio from */
obs_encoder_t *obs_audio_encoder_create(
		const char *id,
		const char *name,
		obs_data_t *settings,
		size_t mixer_idx);

Overview
--------------------------
This feature allows multiple audio mixers to be used at a time.  This
capability was able to be added with surprisingly very little extra
overhead.  Audio will not be mixed unless it's assigned to a specific
mixer, and mixers will not mix unless they have an active mix
connection.

Mostly this will be useful for being able to separate out specific audio
for recording versus streaming, but will also be useful for certain
streaming services that support multiple audio streams via RTMP.

I didn't want to use a variable amount of mixers due to the desire to
reduce heap allocations, so currently I set the limit to 4 simultaneous
mixers; this number can be increased later if needed, but honestly I
feel like it's just the right number to use.

Sources:

Sources can now specify which audio mixers their audio is mixed to; this
can be a single mixer or multiple mixers at a time.  The
obs_source_set_audio_mixers function sets the audio mixer which an audio
source applies to.  For example, 0xF would mean that the source applies
to all four mixers.

Audio Encoders:

Audio encoders now must specify which specific audio mixer they use when
they encode audio data.

Outputs:

Outputs that use encoders can now support multiple audio tracks at once
if they have the OBS_OUTPUT_MULTI_TRACK capability flag set.  This is
mostly only useful for certain types of RTMP transmissions, though may
be useful for file formats that support multiple audio tracks as well
later on.
2015-02-04 16:51:29 -08:00
jp9000
12d149bd3a libobs: Fix cache overflowing (memory leak)
Fixes a bug where all frames in the cache would get marked as 'in use',
this causing it to continually allocate new frames continually.
2015-01-06 14:29:40 -08:00
jp9000
c3e498d25f libobs: Add frame caching for async video sources
The temporary unoptimized code we were using before just completely
allocated a new copy of each frame every single time a new async frame
was output by the source plugin.  This just creates a cache of frames as
needed for the current format/width/height to minimize the allocation
and deallocation.  If new frames come in that are of a different
format/width/height, it'll just clear the cache.  This is a fairly
important optimization.
2015-01-05 02:10:33 -08:00
jp9000
ae39e5bb77 libobs: Rename some variables for consistency
all the async video related stuff usually started with async_*, and
there were two that didn't.  So I just renamed them so they have the
same naming convention
2015-01-05 02:10:32 -08:00
jp9000
8b065fd068 libobs: Allow disabling of async video texture
If an async video source stops video for whatever reason, it would get
stuck on the last frame that was played.  This was particularly awkward
when I wanted to give the user the ability to deactivate a source such
as a webcam because it would get stuck on the last frame.
2015-01-03 20:47:29 -08:00
jp9000
f2287c8a28 libobs: Add obs_source_set_default_flags
This allows sources to set default flags on creation without interfering
with user set flags
2015-01-03 02:37:15 -08:00
jp9000
eac55edca0 libobs: Add obs_source_showing function
This allows the ability to see whether the source is being displayed
somewhere (though not necessarily active in the main output)
2015-01-03 02:37:15 -08:00
jp9000
fd8f8cfda8 libobs: Fix potential null pointer dereference 2015-01-03 02:37:14 -08:00
jp9000
e14050bbe1 libobs: Fix crash if missing plugin for a source
I forgot that the info variable may be intentionally NULL if a source's
plugin in missing.
2015-01-03 02:37:14 -08:00
jp9000
caa6251054 libobs: Fix force mono channel count
I unintentionally made it use obs_source::sample_info instead of using
the actual target channel count, which is designated by the OBS output
sampler info.  obs_source::sample_info is actually used to indicate the
currently set sampler information for incoming samples.  So if a source
is outputting 5.1 channel 48khz audio, and OBS is running at stereo
44.1khz, then the obs_source::sample_info value would be set to
5.1/48khz, not the other way around.  It indicates what the source
itself is running at, not what OBS is running at.

I suppose the variable needs a better name because even I used it
incorrectly despite actually having been the one who wrote it.
2014-12-28 03:51:06 -08:00