Commit graph

136 commits

Author SHA1 Message Date
tt2468 d584aed501 libobs: Add obs_encoder_parent_video() method
Allows parent video object of an encoder with an FPS divisor to be
fetched.
2024-05-03 10:33:46 -07:00
Ruwen Hahn 2edc555af7 libobs: Fix grouped encoders never starting again after disconnect
(based on <340c205ce2>)
2024-04-20 16:54:26 -07:00
Ruwen Hahn c288d42cfd libobs: Add obs_encoder_group_keyframe_aligned_encoders
Ensures grouped encoders start on the same input frame
2024-04-12 14:52:32 -07:00
derrod 20d8779d30 libobs: Prevent encoder reconfiguration after initialization 2024-01-29 17:35:11 -05:00
Exeldro c4c2f5b382 libobs: Fix GPU scaling using the main mix 2024-01-25 14:10:00 -05:00
derrod 2963959e71 libobs: Replace circlebuf with deque 2024-01-16 16:45:09 +01:00
Rodney d96ad4ac98 libobs: Add encoder ROI functions 2024-01-11 13:36:35 +01:00
derrod ca865f80cc libobs: Pair video encoder with all audio encoders 2023-12-05 15:36:37 -06:00
derrod 49e796c6fc libobs: Fix GPU scaling always using the main mix 2023-12-02 17:47:33 -06:00
tt2468 05d52ee3a7 libobs: Fix PTS incrementation when FPS divisor is enabled
When using a PTS divisor, OBS would still increment the PTS by only the
original `fps_den` value, not considering that PTS values should be
multiplied by the divisor.

For example, `60/1` increases like `0,1,2,3`. `60000/1001` increases
like `0,1001,2002,3003`.

Without this fix, `60/1` main OBS framerate with a divisor of `2`
produces `0,1,2,3`, while the correct pattern would be `0,2,4,6`
2023-11-29 16:23:24 +01:00
Ruwen Hahn ac8ccf4027 libobs: Fix GPU scaled video encoder media not being cleared
During encoder shutdown `maybe_clear_encoder_core_video_mix` is
called to clear created mixes that are no longer needed; at that
time `obs_encoder_set_video` rejects changes to `media` since
the encoder is still active, so we bypass those checks

This is an issue e.g. when a rtmp stream disconnects (and thus
all encoders are cleared) and subsequently reconnects
2023-07-26 05:03:12 -07:00
Richard Stanway 4118fa7ac1 libobs: Don't defer encoder updates if not necessary
When #5169 implemented deferred encoder updates, it did not account for
the case when the encoder hadn't started yet. This means the encoder would
start and then immediately call update with the same settings it was
started with, which in the case of some hardware encoders would trigger
a reconfiguration request to the driver.
2023-07-15 16:31:19 -07:00
Ryan Foster 80864197fb libobs: Fix back-to-back GPU encoder sessions breaking
Reset frame_rate_divisor_counter to 0 on encoder shutdown.

After starting and stopping a GPU encoder session, obs_encoder_shutdown
would set frame_rate_divisor_counter to 1. When the next GPU encoder
session was started, in libobs/obs-video-gpu-encode.c, gpu_encode_thread
would set skip to this value (1), and increment
frame_rate_divisor_counter to 2. This causes the next check to fail, as
frame_rate_divisor is 1 by default (2 == 1 is false), so
frame_rate_divisor_counter retains its value. Since skip is non-zero,
the next check, if(skip), passes, and skip to the next loop iteration.

This will continue forever, because frame_rate_divisor_counter will
continue to increment, so it will never hold the same value as
frame_rate_divisor. This means that send_off_encoder_packet is never
called, so the muxer never receives encoded packets.

To the end-user, this manifests as their second encoder session being
impossible to stop. They then have to force quit OBS and the
obs-ffmpeg-mux process. This change prevents that from occurring and
allows multiple back-to-back GPU encoder sessions to be completed.
2023-07-14 11:56:28 -04:00
Ruwen Hahn 6cdfb0a8b9 libobs: Allow configuring frame rate divisor for encoders
This allows encoders/outputs to output at a frame rate that is lower
than the configured base frame rate
2023-07-03 09:35:06 -07:00
Ruwen Hahn 03fa9acc7f libobs: Add obs_encoder_enable_gpu_scaling
Allows rescaling resolution for GPU encoders and allows moving
rescaling for CPU encoders from CPU to GPU

Rescaling is implemented via core video mixes; encoders create
their own core mix with matching width/height/format/colorspace/
range when gpu scaling is enabled and no matching core video
mix exists
2023-06-26 13:32:25 +02:00
Lain 106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
derrod 30519768ad libobs: Add UUIDs to obs_source objects 2023-03-12 01:11:38 +01:00
Richard Stanway 01786a3f11 libobs: Disable encoder scaling request if it matches output size
It was possible to set the encoder to scale the video to the same size
as the output, resulting in unnecessary passes through swscale and
skipping hardware encoders. This was a common user error in Advanced
Output mode where they would tick the rescale box but leave it at the
same resolution as their main output.
2023-03-04 15:14:42 -08:00
John Bradley d70171daa6 libobs: Make internal version of remove encoder 2023-01-18 11:54:20 -08:00
tt2468 c69e40734d libobs: Prevent encoders from initializing/starting if no media is set
This fixes a case of undefined behavior, where encoders can try to init
or start without actually having any video_t or audio_t object
assigned.
2023-01-18 12:17:35 -06:00
tt2468 7e30d3f8a2 libobs: Remove unused internal encoder util function
Was previously introduced in a0f679bc40,
but has since been made unused.
2023-01-18 12:17:35 -06:00
tt2468 eb0d9dc5d2 libobs: Allow sending NULL to obs_encoder_set_video/audio()
There is currently no way to clear a video_t or audio_t object from an
encoder once applied. `audio_t`/`video_t` objects can be destructed at
any time, and it is dangerous to prevent these object references from
even being cleared.

This does not fix the issue where destroying an audio/video object does
not clear the reference from all subscribed encoders.
2023-01-18 12:17:35 -06:00
tt2468 dfc20bbb31 libobs: Protect some encoder functions from being used while active
Protect `obs_encoder_set_video()` and `obs_encoder_set_audio()` from
being used if the encoder is active. Changing these values while active
is undefined behavior.
2023-01-18 12:17:35 -06:00
Antti Tapaninen c7f4c78a69 libobs: Allow overriding video resolution per view 2022-11-19 15:34:54 -08:00
jp9000 4741a9aa50 libobs: Add function to get encoder pause offset 2022-09-30 13:07:19 -07:00
Chip Bradford 7e39ee291c libobs: Add support for multiple video mixes
Split render_texture and derived fields in obs_core_video into new
obs_core_video_mix struct. Add new APIs to add additional obs_view to the render loop, each with a separate render_texture / obs_core_video_mix.
2022-07-31 15:35:36 -07:00
jpark37 0ed0f2cdb4 libobs: Add I010/P010 support, TRC enum 2022-04-03 00:01:25 -07:00
Exeldro 0751416db0 libobs: Fix overflow subtracting unsigned numbers
When offset_size is greater than size, size would overflow
2022-03-08 12:31:43 -08:00
jp9000 edfd5ad604 libobs: Add obs_object abstraction and functions
With this, you can now cast normal obs objects (services, outputs,
sources, encoders) to an obs_object_t, and then use obs_object_*
functions to get references, release references, and similar for weak
object references as well. This allows the ability for the frontend to
use an object of any of those types interchangeably in certain
situations without having to handle each specific type individually.

This is useful because the properties view in particular doesn't care
what type of object it uses, it just needs to be able to hold weak
references to abstract OBS objects.
2022-02-02 22:35:56 -08:00
Richard Stanway 7d64e9d598 libobs: Use size_t for obs_encoder_get_frame_size 2021-12-26 17:32:00 +01:00
Norihiro Kamae d1b87e1642 libobs: Add API to get encoder frame size
When muxing to some format, duration of the packet is used. We need an
API for encoder to return the frame size.
2021-12-23 10:48:37 -08:00
Kurt Kartaltepe b47e4858b8 libobs: Add profiler section for send_packet
This makes it a bit more clear when muxing takes longer than expected
instead of attributing the time to the do_encode.
2021-09-11 15:33:02 -07:00
jpark37 353868e87c libobs: Fix pthread mutex leaks 2021-08-23 22:57:10 -07:00
Richard Stanway 4772a99e3e libobs: Defer reconfiguring encoders to the encode threads
Fixes a long-standing issue with Dynamic Bitrate where the RTMP output
thread could try to reconfigure an encoder while the encoder is in the
middle of encoding. x264 seems to handle multithreaded calls well, but
NVENC would deadlock in this situation with no error visible to the
user.
2021-08-23 18:26:37 -07:00
Jim 665180350d
Merge pull request #2657 from hselasky/improvement
libobs: Implement and use better scaling function for 64-bit integers
2020-05-21 18:07:53 -07:00
Richard Stanway 0ea39baf95 libobs: Clear last error on encoder shutdown
This fixes an issue where an encoder may error out on a path that
doesn't use obs_encoder_set_last_error, resulting in a stale error being
used.
2020-04-27 01:15:53 +02:00
Richard Stanway 5dc9f989d6 libobs: Add support functions for encoder error handling
Similar to how outputs can pass errors, add the same functionality for
encoders so that if an output encoder has an error, it is made available
to the output and eventually the UI / user.
2020-04-12 17:05:19 +02:00
Hans Petter Selasky 0e4ea14ba1 libobs: Implement and use better scaling function for 64-bit integers
As os_gettime_ns() gets large the current scaling methods, mostly by casting
to uint64_t, may lead to numerical overflows. Sweep the code and use
util_mul_div64() where applicable.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
2020-04-05 20:27:28 +02:00
jp9000 ca4b04754c Revert "libobs: Fix audio keyframe issue"
This reverts commit ff22c20019.

This caused a bug in FTL output, which started hitching after this
commit.  Presumably due to opus; it's likely you're not supposed to do
this with all audio encoders.
2020-02-27 06:44:20 -08:00
jp9000 de363d3e09 libobs: Add obs_encoder_scaling_enabled()
Returns whether rescaling is enabled for an encoder.  This will be used
with texture-based encoders to determine whether to fall back to
RAM-based encoding instead.
2020-02-18 20:58:58 -08:00
jp9000 ff22c20019 libobs: Fix audio keyframe issue
Audio packets are always considered keyframe packets, so if they weren't
already, mark them as keyframe packets.
2020-02-12 18:27:42 -08: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
jp9000 1a72b04951 libobs: Make sure to offset unpause audio data
When an unpause occurs, it takes an audio segment and splits it at the
exact point corresponding to the pause timestamp, and then it's supposed
to only send the ending part of the split.  However, the audio pointers
were not being incremented, therefore it was sending the front of the
audio segment to instead of the back of the audio segment by mistake.
2019-08-31 01:15:19 -07:00
jp9000 03e008fd2e libobs: Fix pause cutting out video data prematurely
When pause has been activated, the video_pause_check() function is used
when receiving raw frames in order to filter out frames that are in the
pause window, that way they aren't sent to the encoder or output.

However, when pause was enabled, it was unintentionally filtering out
some frames before the specified starting timestamp as well, causing
extra video data to get cut out prematurely.  This fixes that issue.
2019-08-31 01:15:19 -07:00
Michael Fabian 'Xaymar' Dirks 005921c67d libobs: Return NULL if there is no get_properties callback
If there's no get_properties function, return NULL instead of uninitialized memory.
2019-07-24 18:26:44 +02:00
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