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

91 Commits

Author SHA1 Message Date
jp9000
d4e236dd03 libobs: Fix formatting 2019-07-13 19:01:48 -07:00
Colin Edwards
c64d82530d
Merge pull request #1960 from Xaymar/patch-get_defaults2
libobs: Call both get_defaults and get_defaults2
2019-07-13 20:40:20 -05: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
jp9000
153fa6337f libobs: Implement pausing of outputs
This implements pausing of outputs.  To accomplish this, raw audio/video
data is halted to the encoders or raw output.  Pausing is as precisely
timed as possible according to the timing of the obs_output_pause call,
and audio data will be spliced down to the exact audio sample in
accordance to that timing at the start/end marks.

Outputs that support this (outputs used for recording) can set the
OBS_OUTPUT_CAN_PAUSE capability flag.
2019-07-07 16:38:22 -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
jp9000
973d31b8c2 libobs: Fix lockup when an encode call fails
(This commit also modifies the UI, obs-ffmpeg, and obs-output modules)

Fixes a long-time regression where the program would lock up if an
encode call fails.  Shuts down all outputs associated with the failing
encoder and displays an error message to the user.

Ideally, it would be best if a more detailed error could be displayed to
the user about the nature of the error, though the primary problem is
the encoder errors are typically not something the user would be able to
understand.  The current message is a bit of a generic error message;
improvement is welcome.

Another suggestion is to try to have the encoder restart seamlessly,
though it would take a significant amount of work to be able to make it
do something like that properly, and it sort of assumes that encoder
failures are sporadic, which may not necessarily be the case with some
hardware encoders on some systems.  It may be better just to use another
encoder in that case.  For now, seamless restart is ruled out.
2019-05-17 01:51:12 -07:00
jp9000
17e85f04fd libobs: Add func to get encoder caps by encoder pointer 2019-02-26 08:02:57 -08:00
jp9000
131fb7b460 libobs: Fix potential race condition on shutdown
If the remove_connection call of obs_encoder_stop_internal took too
long, obs_encoder_destroy could get called before that function
completed, causing a race condition.
2019-02-12 16:07:14 -08:00
jp9000
93ba6e7128 libobs: Add texture-based encoding support
Allows the ability to encode by passing NV12 textures.  This uses a
separate thread for texture-based encoders with a small queue of
textures.  An output texture with a keyed mutex shared texture is locked
between OBS and each encoder.  A new encoder callback and capability
flag is used to encode with textures.
2019-02-07 17:00:46 -08:00
jp9000
cd1607ca6e libobs: Split do_encode in to two funcs
This splits the "do_encode" function in to "do_encode" and
"send_off_encoder_packet", the latter of which allows the ability for
texture-based encoders to manage their own encoding and just simply send
off a packet to the outputs.
2019-02-07 17:00:46 -08:00
jp9000
9b8bc22ffa libobs: Add ability to reroute encoders
Allows the ability for one encoder to defer to another in case of
failure or unsupported feature.  Okay, fine, it's mostly a hack so the
new NVENC encoder can fall back to the FFmpeg encoder if NV12 textures
aren't in use, that way it does not have to implement raw fallback
support itself.  The settings and properties are pretty much the same,
so there's no reason not to utilize it in order to save time that could
otherwise be spent more productively.
2019-02-07 17:00:46 -08:00
Michael Fabian 'Xaymar' Dirks
93549ea17c libobs: Add get_defaults2 and get_properties2 for encoders
Adds optional alternate functions to allow passing the encoder type_data
to reduce code duplication.

Closes obsproject/obs-studio#1541
2019-01-04 12:23:46 -08:00
jp9000
621c519cc5 libobs: Add function to get encoder object's defaults
Rather than relying on the encoder's type identifier, additionally allow
the ability to get defaults via an encoder object.
2018-07-20 01:49:32 -07:00
jp9000
45b5291530 libobs: Deactivate unnecessary GPU ops when not encoding
Reduces GPU usage when encoding is not active.  Does not perform color
conversion, frame staging, or frame downloading unless encoding is
explicitly active.
2018-04-23 08:14:18 -07:00
SuslikV
d4676e27dd
libobs: Fix height return value condition
This should fix "Output fails" when Rescale Output height set to 0.
2017-11-27 15:27:14 +02:00
jp9000
2f04010a4a libobs: Fix paired audio encoder discarding one segment
On audio encoder startup, audio encoders paired with a video encoder
would unintentionally discard a single audio data segment, causing it to
be 1024 audio frames out of sync.
2017-10-02 07:36:02 -07:00
jp9000
7d6e6eee79 libobs: Use reference counting for encoder packets
Prevents reallocation of encoded packet data.

Deprecates:
obs_duplicate_encoder_packet
obs_free_encoder_packet

Replaces those functions with:
obs_encoder_packet_ref
obs_encoder_packet_release
2016-12-08 03:27:39 -08:00
Christoph Hohmann
e775abaa71 libobs: Fix missing call to profile_end() when encoding fails
The do_encode() method does not call profile_end() when encoding fails
which causes an error message about mismatching names being logged.
2016-10-24 13:44:28 +02: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
3d53cf3a6c libobs: Store system timestamp DTS on packets 2016-06-20 02:28:52 -07:00
jp9000
caa5723c21 libobs: Don't parse sei if sei callback returns 0/NULL 2016-04-19 08:29:25 -07:00
jp9000
e38a5c61d3 libobs: Add encoder caps (with deprecated flag)
Allows the ability to mark an encoder as deprecated (such as the media
foundation h264 encoders)
2016-04-13 19:01:06 -07:00
jp9000
d069302b2e libobs: Add function to get obs object type 2016-02-27 02:49:03 -08:00
jp9000
9aa18d3de5 libobs: Ensure paired encoders start up at the same time
With the new audio subsystem, audio buffering is minimal at all times.
However, when the audio buffering is too small or non-existent, it would
cause the audio encoders to start with a timestamp that was actually
higher than the first video frame timestamp.  Video would have some
inherent buffering/delay, but then audio could return and encode almost
immediately.  This created a possible window of empty time between the
first encoded video packet and the first encoded audio packet, where as
audio buffering would cause the first audio packet's timestamp to always
be way before the first video packet's timestamp.  It would then
incorrectly assume the two starting points were in sync.

So instead of assuming the audio data is always first, this patch makes
video wait for audio data comes in, and conversely buffers audio data
until video comes in, and tries to find a starting point within that
video data instead, ensuring a synced starting point whether audio
buffering is active or not.
2016-01-31 00:55:01 -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
c4657da2f1 libobs: Subtract packet dts_usec with first packet offset
Ensures that the packet dts_usec vals which are generated for
syncing/interleaving use the proper offset relative to where they're
supposed to be starting from.  The negative DTS of a first video packet
could potentially have been applied twice due to this.
2016-01-25 17:29:09 -08:00
jp9000
346ddd502f libobs: Fix potential race condition
Fixes potential race conditions when two threads are trying to
initialize/start/stop the same encoders at the same time.
2016-01-25 17:29:09 -08:00
jp9000
63f7daa61c libobs: Add API to get object ids 2015-10-21 07:46:41 -07:00
jp9000
f07ce8501f libobs: Add null debug messages for base obs funcs 2015-10-21 06:30:32 -07:00
jp9000
fb32b85f4c libobs: Shut down encoder if valid but not active
It's not impossible that this sort of thing could happen, although
unlikely.
2015-09-17 14:47:51 -07:00
jp9000
6285a47726 (API Change) libobs: Pass type data to get_name callbacks
API changed from:
obs_source_info::get_name(void)
obs_output_info::get_name(void)
obs_encoder_info::get_name(void)
obs_service_info::get_name(void)

API changed to:
obs_source_info::get_name(void *type_data)
obs_output_info::get_name(void *type_data)
obs_encoder_info::get_name(void *type_data)
obs_service_info::get_name(void *type_data)

This allows the type data to be used when getting the name of the
object (useful for plugin wrappers primarily).

NOTE: Though a parameter was added, this is backward-compatible with
older plugins due to calling convention.  The new parameter will simply
be ignored by older plugins, and the stack (if used) will be cleaned up
by the caller.
2015-09-16 09:21:12 -07:00
jp9000
0ed913a136 libobs: Add functions to get private type data
The private type data is the type_data variable that's provided when
object types are registered by plugins.
2015-09-16 09:17:14 -07:00
jp9000
fa7286f84c libobs: Shut down encoder when not in use
This prevents encoders (hardware encoders in particular) from being
continually active when all outputs disconnect from an encoder.  This is
mostly just a temporary measure; the encoding interface may need a bit
of a redesign.  It will also definitely needs to be able to flush at
some point.  Currently when an output is stopped, the pending data is
discarded, which needs to be fixed.
2015-09-13 16:03:01 -07:00
jp9000
af310fb556 libobs: Allow object creation if id not found
Allows objects to be created regardless of whether the actual id exists
or not.  This is a precaution that preserves objects/settings if for
some reason the id was removed for whatever reason (plugin removed, or
hardware encoder that disappeared).  This was already added for sources,
but really needs to be added for other libobs objects as well: outputs,
encoders, services.
2015-09-13 11:55:06 -07:00
Palana
cf6b75e067 libobs: Add profiler calls 2015-08-12 15:30:29 +02:00
jp9000
9f96e691ae libobs: Add API to get encoder sample rate
In case the encoder has to use a different sample rate (due to the
sample rate being unsupported), we need an API function for the encoder
to get the sample rate that the encoder is actually running at.
2015-07-09 10:42:09 -07:00
jp9000
657985da94 libobs: Allow obs-encoder callback self-removal
Allows obs-encoder callbacks to remove themselves while in a callback.
2015-06-21 22:34:46 -07:00
Palana
4ee5c8e0f3 libobs: Fix crash on encoder initialization failure
Found via clang static analysis
2015-06-01 01:37:36 +02:00
Palana
1d39c3e9b6 (API Change) libobs: Add hotkey data to *_create functions 2015-05-11 20:45:25 +02:00
Palana
5ad553d06d libobs: Add global hotkey support 2015-05-11 20:45:24 +02:00
Palana
ba0b8eb0e1 (API Change) libobs: Make obs_encoder refcounted 2015-05-07 02:07:56 +02:00
jp9000
5c91d93d87 libobs: Refactor video/audio encoder conversion
I realized that the get_video_info and get_audio_info encoder callbacks
always have to manually query the libobs audio/video information.

This fixes that problem by passing the libobs video/audio information in
the structures passed to those callbacks so they don't have to query it
each time, reducing needless boilerplate code for encoders.
2015-04-17 20:17:43 -07:00
jp9000
1ee277ed33 libobs: Add preferred video format encoder funcs
Allows the ability to hint at encoders what format should be used.

This is particularly useful if libobs is currently operating in planar
4:4:4, but you want to force an encoder used for streaming to convert to
NV12 to prevent streaming issues.
2015-04-17 20:17:42 -07:00
jp9000
ffc7b3c666 libobs: Fix multi. video encoder sync issues
When using multiple video encoders together with a single audio encoder,
the audio wouldn't be in sync.

The reason why this occurred is because the dts_usec variable of the
encoder packet (which is based on system time) would always be reset to
a value based upon the dts (which is not guaranteed to be based on
system time) in the apply_interleaved_packet_offset function.  This
would then in turn cause it to miscalculate the starting audio/video
offsets, which are required to calculate sync.

So instead of calling that function unnecessarily, separate the check
for whether audio/video has been received in to a new function, and only
start applying the interleaved offsets after audio and video have
actually started up and the starting offsets have been calculated.
2015-02-10 22:10:41 -08:00
jp9000
bd76f16564 libobs: Add functions to get an encoder's type
'obs_encoder_get_type' to get the type of an existing encoder, and
'obs_get_encoder_type' to get the type via its identifier
2015-02-04 16:51:58 -08:00
jp9000
0e398c89be libobs: Add obs_get_encoder_codec function
This allows the ability to get the codec of an encoder via its
identifier string
2015-02-04 16:51:58 -08:00
jp9000
c0c24ab234 libobs: Add obs_encoder_set_name function 2015-02-04 16:51:55 -08: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
92c154017b libobs: Use def. colorspace when scaling encoder
When the encoder is set to scale to a different resolution than the obs
output resolution, make sure it uses the current video colorspace and
range by default.
2015-01-03 02:37:19 -08:00
jp9000
1a95004fe8 libobs: Fix bug when SEI not present
If an encoder did not possess any SEI data, it would never send data at
all because the sent_first_packet wasn't set despite the first packet
being sent.
2014-12-21 10:14:23 -08:00