Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
/******************************************************************************
|
2023-05-19 02:37:26 +02:00
|
|
|
Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "obs.h"
|
2014-01-27 02:48:14 +01:00
|
|
|
#include "obs-internal.h"
|
2020-03-21 10:55:12 +01:00
|
|
|
#include "util/util_uint64.h"
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
#define encoder_active(encoder) os_atomic_load_bool(&encoder->active)
|
|
|
|
#define set_encoder_active(encoder, val) \
|
|
|
|
os_atomic_set_bool(&encoder->active, val)
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
#define get_weak(encoder) ((obs_weak_encoder_t *)encoder->context.control)
|
|
|
|
|
2023-07-25 16:51:48 +02:00
|
|
|
static void encoder_set_video(obs_encoder_t *encoder, video_t *video);
|
|
|
|
|
2014-07-29 01:08:56 +02:00
|
|
|
struct obs_encoder_info *find_encoder(const char *id)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < obs->encoder_types.num; i++) {
|
Revamp API and start using doxygen
The API used to be designed in such a way to where it would expect
exports for each individual source/output/encoder/etc. You would export
functions for each and it would automatically load those functions based
on a specific naming scheme from the module.
The idea behind this was that I wanted to limit the usage of structures
in the API so only functions could be used. It was an interesting idea
in theory, but this idea turned out to be flawed in a number of ways:
1.) Requiring exports to create sources/outputs/encoders/etc meant that
you could not create them by any other means, which meant that
things like faruton's .net plugin would become difficult.
2.) Export function declarations could not be checked, therefore if you
created a function with the wrong parameters and parameter types,
the compiler wouldn't know how to check for that.
3.) Required overly complex load functions in libobs just to handle it.
It makes much more sense to just have a load function that you call
manually. Complexity is the bane of all good programs.
4.) It required that you have functions of specific names, which looked
and felt somewhat unsightly.
So, to fix these issues, I replaced it with a more commonly used API
scheme, seen commonly in places like kernels and typical C libraries
with abstraction. You simply create a structure that contains the
callback definitions, and you pass it to a function to register that
definition (such as obs_register_source), which you call in the
obs_module_load of the module.
It will also automatically check the structure size and ensure that it
only loads the required values if the structure happened to add new
values in an API change.
The "main" source file for each module must include obs-module.h, and
must use OBS_DECLARE_MODULE() within that source file.
Also, started writing some doxygen documentation in to the main library
headers. Will add more detailed documentation as I go.
2014-02-12 16:04:50 +01:00
|
|
|
struct obs_encoder_info *info = obs->encoder_types.array + i;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
|
|
|
if (strcmp(info->id, id) == 0)
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-08-04 17:41:15 +02:00
|
|
|
const char *obs_encoder_get_display_name(const char *id)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
2014-07-29 01:13:04 +02:00
|
|
|
struct obs_encoder_info *ei = find_encoder(id);
|
2015-09-16 10:30:51 +02:00
|
|
|
return ei ? ei->get_name(ei->type_data) : NULL;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
static bool init_encoder(struct obs_encoder *encoder, const char *name,
|
2014-11-01 21:41:17 +01:00
|
|
|
obs_data_t *settings, obs_data_t *hotkey_data)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
2016-01-25 10:42:06 +01:00
|
|
|
pthread_mutex_init_value(&encoder->init_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
pthread_mutex_init_value(&encoder->callbacks_mutex);
|
|
|
|
pthread_mutex_init_value(&encoder->outputs_mutex);
|
2019-07-07 21:27:13 +02:00
|
|
|
pthread_mutex_init_value(&encoder->pause.mutex);
|
2023-12-24 10:13:34 +01:00
|
|
|
pthread_mutex_init_value(&encoder->roi_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
2016-02-27 03:18:00 +01:00
|
|
|
if (!obs_context_data_init(&encoder->context, OBS_OBJ_TYPE_ENCODER,
|
2023-02-25 15:01:17 +01:00
|
|
|
settings, name, NULL, hotkey_data, false))
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
return false;
|
2021-08-24 07:06:00 +02:00
|
|
|
if (pthread_mutex_init_recursive(&encoder->init_mutex) != 0)
|
2016-01-25 10:42:06 +01:00
|
|
|
return false;
|
2021-08-24 07:06:00 +02:00
|
|
|
if (pthread_mutex_init_recursive(&encoder->callbacks_mutex) != 0)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
return false;
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
if (pthread_mutex_init(&encoder->outputs_mutex, NULL) != 0)
|
|
|
|
return false;
|
2019-07-07 21:27:13 +02:00
|
|
|
if (pthread_mutex_init(&encoder->pause.mutex, NULL) != 0)
|
|
|
|
return false;
|
2023-12-24 10:13:34 +01:00
|
|
|
if (pthread_mutex_init(&encoder->roi_mutex, NULL) != 0)
|
|
|
|
return false;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
2019-07-10 19:37:52 +02:00
|
|
|
if (encoder->orig_info.get_defaults) {
|
2018-10-13 05:16:04 +02:00
|
|
|
encoder->orig_info.get_defaults(encoder->context.settings);
|
2019-07-10 19:37:52 +02:00
|
|
|
}
|
|
|
|
if (encoder->orig_info.get_defaults2) {
|
2019-07-14 04:01:48 +02:00
|
|
|
encoder->orig_info.get_defaults2(encoder->context.settings,
|
|
|
|
encoder->orig_info.type_data);
|
2019-07-10 19:37:52 +02:00
|
|
|
}
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct obs_encoder *
|
|
|
|
create_encoder(const char *id, enum obs_encoder_type type, const char *name,
|
2014-11-01 21:41:17 +01:00
|
|
|
obs_data_t *settings, size_t mixer_idx, obs_data_t *hotkey_data)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
|
|
|
struct obs_encoder *encoder;
|
2014-07-29 01:13:04 +02:00
|
|
|
struct obs_encoder_info *ei = find_encoder(id);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
bool success;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
2015-09-13 20:55:06 +02:00
|
|
|
if (ei && ei->type != type)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
return NULL;
|
|
|
|
|
2014-02-09 20:34:07 +01:00
|
|
|
encoder = bzalloc(sizeof(struct obs_encoder));
|
(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-01-14 11:12:08 +01:00
|
|
|
encoder->mixer_idx = mixer_idx;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
2015-09-13 20:55:06 +02:00
|
|
|
if (!ei) {
|
|
|
|
blog(LOG_ERROR, "Encoder ID '%s' not found", id);
|
|
|
|
|
|
|
|
encoder->info.id = bstrdup(id);
|
|
|
|
encoder->info.type = type;
|
|
|
|
encoder->owns_info_id = true;
|
2018-10-13 05:16:04 +02:00
|
|
|
encoder->orig_info = encoder->info;
|
2015-09-13 20:55:06 +02:00
|
|
|
} else {
|
|
|
|
encoder->info = *ei;
|
2018-10-13 05:16:04 +02:00
|
|
|
encoder->orig_info = *ei;
|
2015-09-13 20:55:06 +02:00
|
|
|
}
|
|
|
|
|
2014-11-01 21:41:17 +01:00
|
|
|
success = init_encoder(encoder, name, settings, hotkey_data);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
if (!success) {
|
2015-06-01 01:37:36 +02:00
|
|
|
blog(LOG_ERROR, "creating encoder '%s' (%s) failed", name, id);
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_encoder_destroy(encoder);
|
2015-06-01 01:37:36 +02:00
|
|
|
return NULL;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
obs_context_init_control(&encoder->context, encoder,
|
|
|
|
(obs_destroy_cb)obs_encoder_destroy);
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_context_data_insert(&encoder->context, &obs->data.encoders_mutex,
|
|
|
|
&obs->data.first_encoder);
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
if (type == OBS_ENCODER_VIDEO) {
|
|
|
|
encoder->frame_rate_divisor = 1;
|
|
|
|
}
|
|
|
|
|
2016-08-06 00:36:10 +02:00
|
|
|
blog(LOG_DEBUG, "encoder '%s' (%s) created", name, id);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
return encoder;
|
|
|
|
}
|
2014-01-29 02:41:24 +01:00
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_encoder_t *obs_video_encoder_create(const char *id, const char *name,
|
2014-11-01 21:41:17 +01:00
|
|
|
obs_data_t *settings,
|
|
|
|
obs_data_t *hotkey_data)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
if (!name || !id)
|
|
|
|
return NULL;
|
2014-11-01 21:41:17 +01:00
|
|
|
return create_encoder(id, OBS_ENCODER_VIDEO, name, settings, 0,
|
|
|
|
hotkey_data);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_encoder_t *obs_audio_encoder_create(const char *id, const char *name,
|
2014-11-01 21:41:17 +01:00
|
|
|
obs_data_t *settings, size_t mixer_idx,
|
|
|
|
obs_data_t *hotkey_data)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
if (!name || !id)
|
|
|
|
return NULL;
|
2014-11-01 21:41:17 +01:00
|
|
|
return create_encoder(id, OBS_ENCODER_AUDIO, name, settings, mixer_idx,
|
|
|
|
hotkey_data);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void receive_video(void *param, struct video_data *frame);
|
(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-01-14 11:12:08 +01:00
|
|
|
static void receive_audio(void *param, size_t mix_idx, struct audio_data *data);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
2015-04-17 09:07:56 +02:00
|
|
|
static inline void get_audio_info(const struct obs_encoder *encoder,
|
2014-09-27 00:25:59 +02:00
|
|
|
struct audio_convert_info *info)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
const struct audio_output_info *aoi;
|
2014-08-06 00:07:54 +02:00
|
|
|
aoi = audio_output_get_info(encoder->media);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
if (info->format == AUDIO_FORMAT_UNKNOWN)
|
|
|
|
info->format = aoi->format;
|
|
|
|
if (!info->samples_per_sec)
|
|
|
|
info->samples_per_sec = aoi->samples_per_sec;
|
|
|
|
if (info->speakers == SPEAKERS_UNKNOWN)
|
|
|
|
info->speakers = aoi->speakers;
|
|
|
|
|
2015-04-17 09:07:56 +02:00
|
|
|
if (encoder->info.get_audio_info)
|
|
|
|
encoder->info.get_audio_info(encoder->context.data, info);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2015-04-17 09:07:56 +02:00
|
|
|
static inline void get_video_info(struct obs_encoder *encoder,
|
2014-09-27 00:25:59 +02:00
|
|
|
struct video_scale_info *info)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
2015-04-17 09:07:56 +02:00
|
|
|
const struct video_output_info *voi;
|
|
|
|
voi = video_output_get_info(encoder->media);
|
|
|
|
|
|
|
|
info->format = voi->format;
|
|
|
|
info->colorspace = voi->colorspace;
|
|
|
|
info->range = voi->range;
|
|
|
|
info->width = obs_encoder_get_width(encoder);
|
|
|
|
info->height = obs_encoder_get_height(encoder);
|
|
|
|
|
2014-08-05 06:27:52 +02:00
|
|
|
if (encoder->info.get_video_info)
|
2015-04-17 09:07:56 +02:00
|
|
|
encoder->info.get_video_info(encoder->context.data, info);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
2015-04-17 09:07:56 +02:00
|
|
|
if (info->width != voi->width || info->height != voi->height)
|
|
|
|
obs_encoder_set_scaled_size(encoder, info->width, info->height);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 02:37:40 +01:00
|
|
|
static inline bool gpu_encode_available(const struct obs_encoder *encoder)
|
|
|
|
{
|
2022-11-10 06:05:32 +01:00
|
|
|
struct obs_core_video_mix *video = get_mix_for_video(encoder->media);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
2019-02-06 02:37:40 +01:00
|
|
|
return (encoder->info.caps & OBS_ENCODER_CAP_PASS_TEXTURE) != 0 &&
|
2022-04-03 09:00:38 +02:00
|
|
|
(video->using_p010_tex || video->using_nv12_tex);
|
2019-02-06 02:37:40 +01:00
|
|
|
}
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
/**
|
|
|
|
* GPU based rescaling is currently implemented via core video mixes,
|
|
|
|
* i.e. a core mix with matching width/height/format/colorspace/range
|
|
|
|
* will be created if it doesn't exist already to generate encoder
|
|
|
|
* input
|
|
|
|
*/
|
|
|
|
static void maybe_set_up_gpu_rescale(struct obs_encoder *encoder)
|
|
|
|
{
|
2023-11-29 15:12:15 +01:00
|
|
|
struct obs_core_video_mix *mix, *current_mix;
|
2023-06-08 18:39:28 +02:00
|
|
|
bool create_mix = true;
|
|
|
|
struct obs_video_info ovi;
|
|
|
|
const struct video_output_info *info;
|
|
|
|
|
|
|
|
if (!encoder->media)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info = video_output_get_info(encoder->media);
|
|
|
|
|
|
|
|
if (encoder->gpu_scale_type == OBS_SCALE_DISABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!encoder->scaled_height && !encoder->scaled_width)
|
|
|
|
return;
|
|
|
|
|
2023-11-29 15:12:15 +01:00
|
|
|
current_mix = get_mix_for_video(encoder->media);
|
|
|
|
if (!current_mix)
|
|
|
|
return;
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
pthread_mutex_lock(&obs->video.mixes_mutex);
|
|
|
|
for (size_t i = 0; i < obs->video.mixes.num; i++) {
|
|
|
|
struct obs_core_video_mix *current = obs->video.mixes.array[i];
|
|
|
|
const struct video_output_info *voi =
|
|
|
|
video_output_get_info(current->video);
|
2023-11-29 15:12:15 +01:00
|
|
|
if (current_mix->view != current->view)
|
2023-06-08 18:39:28 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (voi->width != encoder->scaled_width ||
|
|
|
|
voi->height != encoder->scaled_height)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (voi->format != info->format ||
|
|
|
|
voi->colorspace != info->colorspace ||
|
|
|
|
voi->range != info->range)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
current->encoder_refs += 1;
|
|
|
|
obs_encoder_set_video(encoder, current->video);
|
|
|
|
create_mix = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&obs->video.mixes_mutex);
|
|
|
|
|
|
|
|
if (!create_mix)
|
|
|
|
return;
|
|
|
|
|
2023-11-29 15:12:15 +01:00
|
|
|
ovi = current_mix->ovi;
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
ovi.output_format = info->format;
|
|
|
|
ovi.colorspace = info->colorspace;
|
|
|
|
ovi.range = info->range;
|
|
|
|
|
|
|
|
ovi.output_height = encoder->scaled_height;
|
|
|
|
ovi.output_width = encoder->scaled_width;
|
|
|
|
ovi.scale_type = encoder->gpu_scale_type;
|
|
|
|
|
|
|
|
ovi.gpu_conversion = true;
|
|
|
|
|
|
|
|
mix = obs_create_video_mix(&ovi);
|
|
|
|
if (!mix)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mix->encoder_only_mix = true;
|
|
|
|
mix->encoder_refs = 1;
|
2023-11-29 15:12:15 +01:00
|
|
|
mix->view = current_mix->view;
|
2023-06-08 18:39:28 +02:00
|
|
|
|
|
|
|
pthread_mutex_lock(&obs->video.mixes_mutex);
|
|
|
|
|
|
|
|
// double check that nobody else added a matching mix while we've created our mix
|
|
|
|
for (size_t i = 0; i < obs->video.mixes.num; i++) {
|
|
|
|
struct obs_core_video_mix *current = obs->video.mixes.array[i];
|
|
|
|
const struct video_output_info *voi =
|
|
|
|
video_output_get_info(current->video);
|
2024-01-25 12:27:44 +01:00
|
|
|
if (current->view != current_mix->view)
|
2023-06-08 18:39:28 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (voi->width != encoder->scaled_width ||
|
|
|
|
voi->height != encoder->scaled_height)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (voi->format != info->format ||
|
|
|
|
voi->colorspace != info->colorspace ||
|
|
|
|
voi->range != info->range)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
obs_encoder_set_video(encoder, current->video);
|
|
|
|
create_mix = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!create_mix) {
|
|
|
|
obs_free_video_mix(mix);
|
|
|
|
} else {
|
|
|
|
da_push_back(obs->video.mixes, &mix);
|
|
|
|
obs_encoder_set_video(encoder, mix->video);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&obs->video.mixes_mutex);
|
|
|
|
}
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
static void add_connection(struct obs_encoder *encoder)
|
|
|
|
{
|
|
|
|
if (encoder->info.type == OBS_ENCODER_AUDIO) {
|
2015-04-17 09:07:56 +02:00
|
|
|
struct audio_convert_info audio_info = {0};
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
get_audio_info(encoder, &audio_info);
|
2015-04-17 09:07:56 +02:00
|
|
|
|
(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-01-14 11:12:08 +01:00
|
|
|
audio_output_connect(encoder->media, encoder->mixer_idx,
|
|
|
|
&audio_info, receive_audio, encoder);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
} else {
|
2015-04-17 09:07:56 +02:00
|
|
|
struct video_scale_info info = {0};
|
|
|
|
get_video_info(encoder, &info);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
2019-02-06 02:37:40 +01:00
|
|
|
if (gpu_encode_available(encoder)) {
|
|
|
|
start_gpu_encode(encoder);
|
|
|
|
} else {
|
2023-05-25 17:41:30 +02:00
|
|
|
start_raw_video(encoder->media, &info,
|
|
|
|
encoder->frame_rate_divisor,
|
|
|
|
receive_video, encoder);
|
2019-02-06 02:37:40 +01:00
|
|
|
}
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
2023-09-06 18:59:12 +02:00
|
|
|
if (encoder->encoder_group) {
|
|
|
|
bool ready = false;
|
|
|
|
pthread_mutex_lock(&encoder->encoder_group->mutex);
|
|
|
|
encoder->encoder_group->encoders_started += 1;
|
|
|
|
ready = encoder->encoder_group->encoders_started ==
|
|
|
|
encoder->encoder_group->encoders_added;
|
|
|
|
pthread_mutex_unlock(&encoder->encoder_group->mutex);
|
|
|
|
if (ready)
|
|
|
|
add_ready_encoder_group(encoder);
|
|
|
|
}
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
set_encoder_active(encoder, true);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
static void remove_connection(struct obs_encoder *encoder, bool shutdown)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
2019-02-06 02:37:40 +01:00
|
|
|
if (encoder->info.type == OBS_ENCODER_AUDIO) {
|
(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-01-14 11:12:08 +01:00
|
|
|
audio_output_disconnect(encoder->media, encoder->mixer_idx,
|
|
|
|
receive_audio, encoder);
|
2019-02-06 02:37:40 +01:00
|
|
|
} else {
|
|
|
|
if (gpu_encode_available(encoder)) {
|
|
|
|
stop_gpu_encode(encoder);
|
|
|
|
} else {
|
|
|
|
stop_raw_video(encoder->media, receive_video, encoder);
|
|
|
|
}
|
|
|
|
}
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
2023-09-06 18:59:12 +02:00
|
|
|
if (encoder->encoder_group) {
|
|
|
|
pthread_mutex_lock(&encoder->encoder_group->mutex);
|
|
|
|
encoder->encoder_group->encoders_started -= 1;
|
2024-04-18 18:04:46 +02:00
|
|
|
if (encoder->encoder_group->encoders_started == 0)
|
|
|
|
encoder->encoder_group->start_timestamp = 0;
|
|
|
|
|
2023-09-06 18:59:12 +02:00
|
|
|
pthread_mutex_unlock(&encoder->encoder_group->mutex);
|
|
|
|
}
|
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
/* obs_encoder_shutdown locks init_mutex, so don't call it on encode
|
|
|
|
* errors, otherwise you can get a deadlock with outputs when they end
|
|
|
|
* data capture, which will lock init_mutex and the video callback
|
|
|
|
* mutex in the reverse order. instead, call shutdown before starting
|
|
|
|
* up again */
|
|
|
|
if (shutdown)
|
|
|
|
obs_encoder_shutdown(encoder);
|
2016-01-25 10:42:06 +01:00
|
|
|
set_encoder_active(encoder, false);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
2014-02-14 23:13:36 +01:00
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
static inline void free_audio_buffers(struct obs_encoder *encoder)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
2023-11-30 16:11:18 +01:00
|
|
|
deque_free(&encoder->audio_input_buffer[i]);
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
bfree(encoder->audio_output_buffer[i]);
|
|
|
|
encoder->audio_output_buffer[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
static void obs_encoder_actually_destroy(obs_encoder_t *encoder)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
|
|
|
if (encoder) {
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
pthread_mutex_lock(&encoder->outputs_mutex);
|
|
|
|
for (size_t i = 0; i < encoder->outputs.num; i++) {
|
|
|
|
struct obs_output *output = encoder->outputs.array[i];
|
2023-01-17 00:33:15 +01:00
|
|
|
// This happens while the output is still "active", so
|
|
|
|
// remove without checking active
|
|
|
|
obs_output_remove_encoder_internal(output, encoder);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
}
|
|
|
|
da_free(encoder->outputs);
|
|
|
|
pthread_mutex_unlock(&encoder->outputs_mutex);
|
|
|
|
|
2016-08-06 00:36:10 +02:00
|
|
|
blog(LOG_DEBUG, "encoder '%s' destroyed",
|
|
|
|
encoder->context.name);
|
2014-07-13 14:01:02 +02:00
|
|
|
|
2023-09-06 18:59:12 +02:00
|
|
|
if (encoder->encoder_group) {
|
|
|
|
struct encoder_group *group = encoder->encoder_group;
|
|
|
|
bool release = false;
|
|
|
|
|
|
|
|
encoder->encoder_group = NULL;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&group->mutex);
|
|
|
|
group->encoders_added -= 1;
|
|
|
|
release = group->encoders_added == 0;
|
|
|
|
pthread_mutex_unlock(&group->mutex);
|
|
|
|
|
|
|
|
if (release) {
|
|
|
|
pthread_mutex_destroy(&group->mutex);
|
|
|
|
bfree(group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
free_audio_buffers(encoder);
|
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
if (encoder->context.data)
|
|
|
|
encoder->info.destroy(encoder->context.data);
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
da_free(encoder->callbacks);
|
2023-12-24 10:13:34 +01:00
|
|
|
da_free(encoder->roi);
|
2016-01-25 10:42:06 +01:00
|
|
|
pthread_mutex_destroy(&encoder->init_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
pthread_mutex_destroy(&encoder->callbacks_mutex);
|
|
|
|
pthread_mutex_destroy(&encoder->outputs_mutex);
|
2019-07-07 21:27:13 +02:00
|
|
|
pthread_mutex_destroy(&encoder->pause.mutex);
|
2023-12-24 10:13:34 +01:00
|
|
|
pthread_mutex_destroy(&encoder->roi_mutex);
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_context_data_free(&encoder->context);
|
2015-09-13 20:55:06 +02:00
|
|
|
if (encoder->owns_info_id)
|
|
|
|
bfree((void *)encoder->info.id);
|
2019-10-09 18:27:09 +02:00
|
|
|
if (encoder->last_error_message)
|
|
|
|
bfree(encoder->last_error_message);
|
2023-05-25 17:41:30 +02:00
|
|
|
if (encoder->fps_override)
|
|
|
|
video_output_free_frame_rate_divisor(
|
|
|
|
encoder->fps_override);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
bfree(encoder);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
/* does not actually destroy the encoder until all connections to it have been
|
|
|
|
* removed. (full reference counting really would have been superfluous) */
|
2014-09-26 02:44:05 +02:00
|
|
|
void obs_encoder_destroy(obs_encoder_t *encoder)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
|
|
|
if (encoder) {
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
bool destroy;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_context_data_remove(&encoder->context);
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
|
2019-02-13 00:41:04 +01:00
|
|
|
pthread_mutex_lock(&encoder->init_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
pthread_mutex_lock(&encoder->callbacks_mutex);
|
|
|
|
destroy = encoder->callbacks.num == 0;
|
|
|
|
if (!destroy)
|
|
|
|
encoder->destroy_on_stop = true;
|
|
|
|
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
2019-02-13 00:41:04 +01:00
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
|
|
|
if (destroy)
|
|
|
|
obs_encoder_actually_destroy(encoder);
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
const char *obs_encoder_get_name(const obs_encoder_t *encoder)
|
2014-07-13 11:58:55 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_name")
|
|
|
|
? encoder->context.name
|
|
|
|
: NULL;
|
2014-07-13 11:58:55 +02:00
|
|
|
}
|
|
|
|
|
2015-01-26 04:26:31 +01:00
|
|
|
void obs_encoder_set_name(obs_encoder_t *encoder, const char *name)
|
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_name"))
|
|
|
|
return;
|
2015-01-26 04:26:31 +01:00
|
|
|
|
|
|
|
if (name && *name && strcmp(name, encoder->context.name) != 0)
|
|
|
|
obs_context_data_setname(&encoder->context, name);
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
static inline obs_data_t *get_defaults(const struct obs_encoder_info *info)
|
2014-04-04 09:30:37 +02:00
|
|
|
{
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_data_t *settings = obs_data_create();
|
2019-07-10 19:37:52 +02:00
|
|
|
if (info->get_defaults) {
|
|
|
|
info->get_defaults(settings);
|
|
|
|
}
|
2018-11-10 14:07:16 +01:00
|
|
|
if (info->get_defaults2) {
|
|
|
|
info->get_defaults2(settings, info->type_data);
|
|
|
|
}
|
2014-04-04 09:30:37 +02:00
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_data_t *obs_encoder_defaults(const char *id)
|
2014-03-07 14:55:21 +01:00
|
|
|
{
|
2014-07-29 01:13:04 +02:00
|
|
|
const struct obs_encoder_info *info = find_encoder(id);
|
2014-04-04 09:30:37 +02:00
|
|
|
return (info) ? get_defaults(info) : NULL;
|
2014-03-07 14:55:21 +01:00
|
|
|
}
|
|
|
|
|
2018-07-20 10:49:32 +02:00
|
|
|
obs_data_t *obs_encoder_get_defaults(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_defaults"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return get_defaults(&encoder->info);
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_properties_t *obs_get_encoder_properties(const char *id)
|
2014-02-02 06:46:13 +01:00
|
|
|
{
|
2014-07-29 01:13:04 +02:00
|
|
|
const struct obs_encoder_info *ei = find_encoder(id);
|
2018-11-10 14:07:16 +01:00
|
|
|
if (ei && (ei->get_properties || ei->get_properties2)) {
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_data_t *defaults = get_defaults(ei);
|
2019-07-24 15:31:44 +02:00
|
|
|
obs_properties_t *properties = NULL;
|
2014-04-04 09:30:37 +02:00
|
|
|
|
2018-11-10 14:07:16 +01:00
|
|
|
if (ei->get_properties2) {
|
|
|
|
properties = ei->get_properties2(NULL, ei->type_data);
|
|
|
|
} else if (ei->get_properties) {
|
|
|
|
properties = ei->get_properties(NULL);
|
|
|
|
}
|
|
|
|
|
2014-04-04 09:30:37 +02:00
|
|
|
obs_properties_apply_settings(properties, defaults);
|
|
|
|
obs_data_release(defaults);
|
|
|
|
return properties;
|
|
|
|
}
|
2014-02-02 06:46:13 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
obs_properties_t *obs_encoder_properties(const obs_encoder_t *encoder)
|
2014-03-23 09:07:54 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_properties"))
|
|
|
|
return NULL;
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
if (encoder->orig_info.get_properties2) {
|
2018-11-10 14:07:16 +01:00
|
|
|
obs_properties_t *props;
|
2018-10-13 05:16:04 +02:00
|
|
|
props = encoder->orig_info.get_properties2(
|
|
|
|
encoder->context.data, encoder->orig_info.type_data);
|
2018-11-10 14:07:16 +01:00
|
|
|
obs_properties_apply_settings(props, encoder->context.settings);
|
|
|
|
return props;
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
} else if (encoder->orig_info.get_properties) {
|
2014-09-26 02:44:05 +02:00
|
|
|
obs_properties_t *props;
|
2018-10-13 05:16:04 +02:00
|
|
|
props = encoder->orig_info.get_properties(
|
|
|
|
encoder->context.data);
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_properties_apply_settings(props, encoder->context.settings);
|
2014-04-04 09:30:37 +02:00
|
|
|
return props;
|
|
|
|
}
|
2018-11-10 14:07:16 +01:00
|
|
|
|
2014-03-23 09:07:54 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
void obs_encoder_update(obs_encoder_t *encoder, obs_data_t *settings)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_update"))
|
|
|
|
return;
|
2014-02-14 23:13:36 +01:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_data_apply(encoder->context.settings, settings);
|
|
|
|
|
2023-07-14 02:34:50 +02:00
|
|
|
// Encoder isn't initialized yet, only apply changes to settings
|
|
|
|
if (!encoder->context.data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Encoder doesn't support updates
|
|
|
|
if (!encoder->info.update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the encoder is active we defer the update as it may not be
|
|
|
|
// reentrant. Setting reconfigure_requested to true makes the changes
|
|
|
|
// apply at the next possible moment in the encoder / GPU encoder
|
|
|
|
// thread.
|
|
|
|
if (encoder_active(encoder)) {
|
2021-08-21 21:27:45 +02:00
|
|
|
encoder->reconfigure_requested = true;
|
2023-07-14 02:34:50 +02:00
|
|
|
} else {
|
|
|
|
encoder->info.update(encoder->context.data,
|
|
|
|
encoder->context.settings);
|
|
|
|
}
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
bool obs_encoder_get_extra_data(const obs_encoder_t *encoder,
|
|
|
|
uint8_t **extra_data, size_t *size)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_extra_data"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (encoder->info.get_extra_data && encoder->context.data)
|
2014-08-05 06:27:52 +02:00
|
|
|
return encoder->info.get_extra_data(encoder->context.data,
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
extra_data, size);
|
2014-02-14 23:13:36 +01:00
|
|
|
|
|
|
|
return false;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
obs_data_t *obs_encoder_get_settings(const obs_encoder_t *encoder)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_settings"))
|
|
|
|
return NULL;
|
2014-02-14 23:13:36 +01:00
|
|
|
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
obs_data_addref(encoder->context.settings);
|
|
|
|
return encoder->context.settings;
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
static inline void reset_audio_buffers(struct obs_encoder *encoder)
|
|
|
|
{
|
|
|
|
free_audio_buffers(encoder);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < encoder->planes; i++)
|
|
|
|
encoder->audio_output_buffer[i] =
|
|
|
|
bmalloc(encoder->framesize_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void intitialize_audio_encoder(struct obs_encoder *encoder)
|
|
|
|
{
|
2015-04-17 09:07:56 +02:00
|
|
|
struct audio_convert_info info = {0};
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
get_audio_info(encoder, &info);
|
|
|
|
|
|
|
|
encoder->samplerate = info.samples_per_sec;
|
|
|
|
encoder->planes = get_audio_planes(info.format, info.speakers);
|
|
|
|
encoder->blocksize = get_audio_size(info.format, info.speakers, 1);
|
2014-08-05 06:27:52 +02:00
|
|
|
encoder->framesize =
|
|
|
|
encoder->info.get_frame_size(encoder->context.data);
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
encoder->framesize_bytes = encoder->blocksize * encoder->framesize;
|
|
|
|
reset_audio_buffers(encoder);
|
|
|
|
}
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
static THREAD_LOCAL bool can_reroute = false;
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
static inline bool obs_encoder_initialize_internal(obs_encoder_t *encoder)
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
{
|
2023-01-16 06:24:36 +01:00
|
|
|
if (!encoder->media) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_initialize_internal: encoder '%s' has no media set",
|
|
|
|
encoder->context.name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
if (encoder_active(encoder))
|
|
|
|
return true;
|
|
|
|
if (encoder->initialized)
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
return true;
|
2015-09-17 23:47:51 +02:00
|
|
|
|
|
|
|
obs_encoder_shutdown(encoder);
|
2014-04-05 08:21:19 +02:00
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
maybe_set_up_gpu_rescale(encoder);
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
if (encoder->orig_info.create) {
|
|
|
|
can_reroute = true;
|
|
|
|
encoder->info = encoder->orig_info;
|
|
|
|
encoder->context.data = encoder->orig_info.create(
|
2015-09-13 20:55:06 +02:00
|
|
|
encoder->context.settings, encoder);
|
2018-10-13 05:16:04 +02:00
|
|
|
can_reroute = false;
|
|
|
|
}
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
if (!encoder->context.data)
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
return false;
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
if (encoder->orig_info.type == OBS_ENCODER_AUDIO)
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
intitialize_audio_encoder(encoder);
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
encoder->initialized = true;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
return true;
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 05:16:04 +02:00
|
|
|
void *obs_encoder_create_rerouted(obs_encoder_t *encoder,
|
|
|
|
const char *reroute_id)
|
|
|
|
{
|
|
|
|
if (!obs_ptr_valid(encoder, "obs_encoder_reroute"))
|
|
|
|
return NULL;
|
|
|
|
if (!obs_ptr_valid(reroute_id, "obs_encoder_reroute"))
|
|
|
|
return NULL;
|
|
|
|
if (!can_reroute)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
const struct obs_encoder_info *ei = find_encoder(reroute_id);
|
|
|
|
if (ei) {
|
|
|
|
if (ei->type != encoder->orig_info.type ||
|
|
|
|
astrcmpi(ei->codec, encoder->orig_info.codec) != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
encoder->info = *ei;
|
|
|
|
return encoder->info.create(encoder->context.settings, encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
bool obs_encoder_initialize(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
if (!encoder)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->init_mutex);
|
|
|
|
success = obs_encoder_initialize_internal(encoder);
|
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
/**
|
|
|
|
* free video mix if it's an encoder only video mix
|
|
|
|
* see `maybe_set_up_gpu_rescale`
|
|
|
|
*/
|
|
|
|
static void maybe_clear_encoder_core_video_mix(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&obs->video.mixes_mutex);
|
|
|
|
for (size_t i = 0; i < obs->video.mixes.num; i++) {
|
|
|
|
struct obs_core_video_mix *mix = obs->video.mixes.array[i];
|
|
|
|
if (mix->video != encoder->media)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!mix->encoder_only_mix)
|
|
|
|
break;
|
|
|
|
|
2023-07-25 16:51:48 +02:00
|
|
|
encoder_set_video(encoder, obs_get_video());
|
2023-06-08 18:39:28 +02:00
|
|
|
mix->encoder_refs -= 1;
|
|
|
|
if (mix->encoder_refs == 0) {
|
|
|
|
da_erase(obs->video.mixes, i);
|
|
|
|
obs_free_video_mix(mix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&obs->video.mixes_mutex);
|
|
|
|
}
|
|
|
|
|
2015-09-14 00:49:06 +02:00
|
|
|
void obs_encoder_shutdown(obs_encoder_t *encoder)
|
|
|
|
{
|
2016-01-25 10:42:06 +01:00
|
|
|
pthread_mutex_lock(&encoder->init_mutex);
|
2015-09-14 00:49:06 +02:00
|
|
|
if (encoder->context.data) {
|
|
|
|
encoder->info.destroy(encoder->context.data);
|
2016-01-25 10:42:06 +01:00
|
|
|
encoder->context.data = NULL;
|
2023-12-03 18:41:39 +01:00
|
|
|
da_free(encoder->paired_encoders);
|
2016-01-25 10:47:42 +01:00
|
|
|
encoder->first_received = false;
|
|
|
|
encoder->offset_usec = 0;
|
2016-01-25 10:42:06 +01:00
|
|
|
encoder->start_ts = 0;
|
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 16:06:18 +02:00
|
|
|
encoder->frame_rate_divisor_counter = 0;
|
2023-06-08 18:39:28 +02:00
|
|
|
maybe_clear_encoder_core_video_mix(encoder);
|
2015-09-14 00:49:06 +02:00
|
|
|
}
|
2020-04-27 01:14:45 +02:00
|
|
|
obs_encoder_set_last_error(encoder, NULL);
|
2016-01-25 10:42:06 +01:00
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
2015-09-14 00:49:06 +02:00
|
|
|
}
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
static inline size_t
|
2014-09-27 00:25:59 +02:00
|
|
|
get_callback_idx(const struct obs_encoder *encoder,
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
void (*new_packet)(void *param, struct encoder_packet *packet),
|
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < encoder->callbacks.num; i++) {
|
|
|
|
struct encoder_callback *cb = encoder->callbacks.array + i;
|
|
|
|
|
|
|
|
if (cb->new_packet == new_packet && cb->param == param)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DARRAY_INVALID;
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
void pause_reset(struct pause_data *pause)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&pause->mutex);
|
|
|
|
pause->last_video_ts = 0;
|
|
|
|
pause->ts_start = 0;
|
|
|
|
pause->ts_end = 0;
|
|
|
|
pause->ts_offset = 0;
|
|
|
|
pthread_mutex_unlock(&pause->mutex);
|
|
|
|
}
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
static inline void obs_encoder_start_internal(
|
|
|
|
obs_encoder_t *encoder,
|
2014-02-14 23:13:36 +01:00
|
|
|
void (*new_packet)(void *param, struct encoder_packet *packet),
|
|
|
|
void *param)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
struct encoder_callback cb = {false, new_packet, param};
|
|
|
|
bool first = false;
|
|
|
|
|
2023-01-16 06:24:36 +01:00
|
|
|
if (!encoder->context.data || !encoder->media)
|
2015-10-17 11:51:13 +02:00
|
|
|
return;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->callbacks_mutex);
|
|
|
|
|
|
|
|
first = (encoder->callbacks.num == 0);
|
|
|
|
|
2014-04-14 22:55:14 +02:00
|
|
|
size_t idx = get_callback_idx(encoder, new_packet, param);
|
|
|
|
if (idx == DARRAY_INVALID)
|
|
|
|
da_push_back(encoder->callbacks, &cb);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
|
|
|
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
|
|
|
|
|
|
|
if (first) {
|
2019-07-07 21:27:13 +02:00
|
|
|
os_atomic_set_bool(&encoder->paused, false);
|
|
|
|
pause_reset(&encoder->pause);
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
encoder->cur_pts = 0;
|
|
|
|
add_connection(encoder);
|
|
|
|
}
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
void obs_encoder_start(obs_encoder_t *encoder,
|
|
|
|
void (*new_packet)(void *param,
|
|
|
|
struct encoder_packet *packet),
|
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_start"))
|
|
|
|
return;
|
|
|
|
if (!obs_ptr_valid(new_packet, "obs_encoder_start"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->init_mutex);
|
|
|
|
obs_encoder_start_internal(encoder, new_packet, param);
|
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool obs_encoder_stop_internal(
|
|
|
|
obs_encoder_t *encoder,
|
2014-02-14 23:13:36 +01:00
|
|
|
void (*new_packet)(void *param, struct encoder_packet *packet),
|
|
|
|
void *param)
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
{
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
bool last = false;
|
|
|
|
size_t idx;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->callbacks_mutex);
|
|
|
|
|
|
|
|
idx = get_callback_idx(encoder, new_packet, param);
|
|
|
|
if (idx != DARRAY_INVALID) {
|
|
|
|
da_erase(encoder->callbacks, idx);
|
|
|
|
last = (encoder->callbacks.num == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
|
|
|
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
if (last) {
|
2019-05-17 10:19:36 +02:00
|
|
|
remove_connection(encoder, true);
|
2016-01-25 10:42:06 +01:00
|
|
|
encoder->initialized = false;
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
2016-01-25 10:42:06 +01:00
|
|
|
if (encoder->destroy_on_stop) {
|
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
obs_encoder_actually_destroy(encoder);
|
2016-01-25 10:42:06 +01:00
|
|
|
return true;
|
|
|
|
}
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
}
|
2016-01-25 10:42:06 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_stop(obs_encoder_t *encoder,
|
|
|
|
void (*new_packet)(void *param,
|
|
|
|
struct encoder_packet *packet),
|
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
bool destroyed;
|
|
|
|
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_stop"))
|
|
|
|
return;
|
|
|
|
if (!obs_ptr_valid(new_packet, "obs_encoder_stop"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->init_mutex);
|
|
|
|
destroyed = obs_encoder_stop_internal(encoder, new_packet, param);
|
|
|
|
if (!destroyed)
|
|
|
|
pthread_mutex_unlock(&encoder->init_mutex);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
const char *obs_encoder_get_codec(const obs_encoder_t *encoder)
|
2014-04-01 20:55:18 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_codec")
|
|
|
|
? encoder->info.codec
|
|
|
|
: NULL;
|
2014-04-01 20:55:18 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 04:48:34 +01:00
|
|
|
const char *obs_get_encoder_codec(const char *id)
|
|
|
|
{
|
|
|
|
struct obs_encoder_info *info = find_encoder(id);
|
|
|
|
return info ? info->codec : NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-04 04:49:34 +01:00
|
|
|
enum obs_encoder_type obs_encoder_get_type(const obs_encoder_t *encoder)
|
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_type")
|
|
|
|
? encoder->info.type
|
|
|
|
: OBS_ENCODER_AUDIO;
|
2015-02-04 04:49:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enum obs_encoder_type obs_get_encoder_type(const char *id)
|
|
|
|
{
|
|
|
|
struct obs_encoder_info *info = find_encoder(id);
|
|
|
|
return info ? info->type : OBS_ENCODER_AUDIO;
|
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
void obs_encoder_set_scaled_size(obs_encoder_t *encoder, uint32_t width,
|
2014-08-11 01:50:44 +02:00
|
|
|
uint32_t height)
|
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_scaled_size"))
|
2014-08-11 01:50:44 +02:00
|
|
|
return;
|
2015-10-17 11:51:13 +02:00
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_scaled_size: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2016-01-25 10:42:06 +01:00
|
|
|
if (encoder_active(encoder)) {
|
2014-08-11 01:50:44 +02:00
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot set the scaled "
|
|
|
|
"resolution while the encoder is active",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2024-01-28 02:42:51 +01:00
|
|
|
if (encoder->initialized) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot set the scaled resolution "
|
|
|
|
"after the encoder has been initialized",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2014-08-11 01:50:44 +02:00
|
|
|
|
2023-02-25 16:33:54 +01:00
|
|
|
const struct video_output_info *voi;
|
|
|
|
voi = video_output_get_info(encoder->media);
|
|
|
|
if (voi && voi->width == width && voi->height == height) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Scaled resolution "
|
|
|
|
"matches output resolution, scaling "
|
|
|
|
"disabled",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
encoder->scaled_width = encoder->scaled_height = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-11 01:50:44 +02:00
|
|
|
encoder->scaled_width = width;
|
|
|
|
encoder->scaled_height = height;
|
|
|
|
}
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
void obs_encoder_set_gpu_scale_type(obs_encoder_t *encoder,
|
|
|
|
enum obs_scale_type gpu_scale_type)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_gpu_scale_type"))
|
|
|
|
return;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_gpu_scale_type: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (encoder_active(encoder)) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot enable GPU scaling "
|
|
|
|
"while the encoder is active",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2024-01-28 02:42:51 +01:00
|
|
|
if (encoder->initialized) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot enable GPU scaling "
|
|
|
|
"after the encoder has been initialized",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2023-06-08 18:39:28 +02:00
|
|
|
|
|
|
|
encoder->gpu_scale_type = gpu_scale_type;
|
|
|
|
}
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
bool obs_encoder_set_frame_rate_divisor(obs_encoder_t *encoder,
|
|
|
|
uint32_t frame_rate_divisor)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_frame_rate_divisor"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_frame_rate_divisor: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder_active(encoder)) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot set frame rate divisor "
|
|
|
|
"while the encoder is active",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-01-28 02:42:51 +01:00
|
|
|
if (encoder->initialized) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot set frame rate divisor "
|
|
|
|
"after the encoder has been initialized",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
if (frame_rate_divisor == 0) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot set frame "
|
|
|
|
"rate divisor to 0",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
encoder->frame_rate_divisor = frame_rate_divisor;
|
|
|
|
|
|
|
|
if (encoder->fps_override) {
|
|
|
|
video_output_free_frame_rate_divisor(encoder->fps_override);
|
|
|
|
encoder->fps_override = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder->media) {
|
|
|
|
encoder->fps_override =
|
|
|
|
video_output_create_with_frame_rate_divisor(
|
|
|
|
encoder->media, encoder->frame_rate_divisor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-02-19 05:58:58 +01:00
|
|
|
bool obs_encoder_scaling_enabled(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_scaling_enabled"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return encoder->scaled_width || encoder->scaled_height;
|
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
uint32_t obs_encoder_get_width(const obs_encoder_t *encoder)
|
2014-08-11 01:50:44 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_width"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_get_width: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!encoder->media)
|
2014-08-11 01:50:44 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return encoder->scaled_width != 0
|
|
|
|
? encoder->scaled_width
|
|
|
|
: video_output_get_width(encoder->media);
|
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
uint32_t obs_encoder_get_height(const obs_encoder_t *encoder)
|
2014-08-11 01:50:44 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_height"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_get_height: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!encoder->media)
|
2014-08-11 01:50:44 +02:00
|
|
|
return 0;
|
|
|
|
|
2017-11-27 14:27:14 +01:00
|
|
|
return encoder->scaled_height != 0
|
2014-08-11 01:50:44 +02:00
|
|
|
? encoder->scaled_height
|
|
|
|
: video_output_get_height(encoder->media);
|
|
|
|
}
|
|
|
|
|
2023-06-08 18:39:28 +02:00
|
|
|
bool obs_encoder_gpu_scaling_enabled(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_gpu_scaling_enabled"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_gpu_scaling_enabled: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoder->gpu_scale_type != OBS_SCALE_DISABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum obs_scale_type obs_encoder_get_scale_type(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_scale_type"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_get_scale_type: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoder->gpu_scale_type;
|
|
|
|
}
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
uint32_t obs_encoder_get_frame_rate_divisor(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_frame_rate_divisor"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_frame_rate_divisor: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoder->frame_rate_divisor;
|
|
|
|
}
|
|
|
|
|
2015-07-09 19:42:09 +02:00
|
|
|
uint32_t obs_encoder_get_sample_rate(const obs_encoder_t *encoder)
|
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_sample_rate"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_AUDIO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_get_sample_rate: "
|
|
|
|
"encoder '%s' is not an audio encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!encoder->media)
|
2015-07-09 19:42:09 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return encoder->samplerate != 0
|
|
|
|
? encoder->samplerate
|
|
|
|
: audio_output_get_sample_rate(encoder->media);
|
|
|
|
}
|
|
|
|
|
2021-12-26 17:28:18 +01:00
|
|
|
size_t obs_encoder_get_frame_size(const obs_encoder_t *encoder)
|
2021-12-23 13:03:11 +01:00
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_frame_size"))
|
|
|
|
return 0;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_AUDIO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_get_frame_size: "
|
|
|
|
"encoder '%s' is not an audio encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-12-26 17:28:18 +01:00
|
|
|
return encoder->framesize;
|
2021-12-23 13:03:11 +01:00
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
void obs_encoder_set_video(obs_encoder_t *encoder, video_t *video)
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
{
|
|
|
|
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_video"))
|
|
|
|
return;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_video: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2023-01-16 05:12:09 +01:00
|
|
|
if (encoder_active(encoder)) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot apply a new video_t "
|
|
|
|
"object while the encoder is active",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2024-01-28 02:42:51 +01:00
|
|
|
if (encoder->initialized) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot apply a new video_t object "
|
|
|
|
"after the encoder has been initialized",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2023-01-16 05:12:09 +01:00
|
|
|
|
2023-07-25 16:51:48 +02:00
|
|
|
encoder_set_video(encoder, video);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void encoder_set_video(obs_encoder_t *encoder, video_t *video)
|
|
|
|
{
|
|
|
|
const struct video_output_info *voi;
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
if (encoder->fps_override) {
|
|
|
|
video_output_free_frame_rate_divisor(encoder->fps_override);
|
|
|
|
encoder->fps_override = NULL;
|
|
|
|
}
|
|
|
|
|
2023-01-16 05:17:21 +01:00
|
|
|
if (video) {
|
|
|
|
voi = video_output_get_info(video);
|
|
|
|
encoder->media = video;
|
|
|
|
encoder->timebase_num = voi->fps_den;
|
|
|
|
encoder->timebase_den = voi->fps_num;
|
2023-05-25 17:41:30 +02:00
|
|
|
|
|
|
|
if (encoder->frame_rate_divisor) {
|
|
|
|
encoder->fps_override =
|
|
|
|
video_output_create_with_frame_rate_divisor(
|
|
|
|
video, encoder->frame_rate_divisor);
|
|
|
|
}
|
2023-01-16 05:17:21 +01:00
|
|
|
} else {
|
|
|
|
encoder->media = NULL;
|
|
|
|
encoder->timebase_num = 0;
|
|
|
|
encoder->timebase_den = 0;
|
|
|
|
}
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-26 02:44:05 +02:00
|
|
|
void obs_encoder_set_audio(obs_encoder_t *encoder, audio_t *audio)
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_audio"))
|
|
|
|
return;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_AUDIO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_audio: "
|
|
|
|
"encoder '%s' is not an audio encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
2023-01-16 05:12:09 +01:00
|
|
|
if (encoder_active(encoder)) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"encoder '%s': Cannot apply a new audio_t "
|
|
|
|
"object while the encoder is active",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-16 05:17:21 +01:00
|
|
|
if (audio) {
|
|
|
|
encoder->media = audio;
|
|
|
|
encoder->timebase_num = 1;
|
|
|
|
encoder->timebase_den = audio_output_get_sample_rate(audio);
|
|
|
|
} else {
|
|
|
|
encoder->media = NULL;
|
|
|
|
encoder->timebase_num = 0;
|
|
|
|
encoder->timebase_den = 0;
|
|
|
|
}
|
obs-studio UI: Implement stream settings UI
- Updated the services API so that it links up with an output and
the output gets data from that service rather than via settings.
This allows the service context to have control over how an output is
used, and makes it so that the URL/key/etc isn't necessarily some
static setting.
Also, if the service is attached to an output, it will stick around
until the output is destroyed.
- The settings interface has been updated so that it can allow the
usage of service plugins. What this means is that now you can create
a service plugin that can control aspects of the stream, and it
allows each service to create their own user interface if they create
a service plugin module.
- Testing out saving of current service information. Saves/loads from
JSON in to obs_data_t, seems to be working quite nicely, and the
service object information is saved/preserved on exit, and loaded
again on startup.
- I agonized over the settings user interface for days, and eventually
I just decided that the only way that users weren't going to be
fumbling over options was to split up the settings in to simple/basic
output, pre-configured, and then advanced for advanced use (such as
multiple outputs or services, which I'll implement later).
This was particularly painful to really design right, I wanted more
features and wanted to include everything in one interface but
ultimately just realized from experience that users are just not
technically knowledgable about it and will end up fumbling with the
settings rather than getting things done.
Basically, what this means is that casual users only have to enter in
about 3 things to configure their stream: Stream key, audio bitrate,
and video bitrate. I am really happy with this interface for those
types of users, but it definitely won't be sufficient for advanced
usage or for custom outputs, so that stuff will have to be separated.
- Improved the JSON usage for the 'common streaming services' context,
I realized that JSON arrays are there to ensure sorting, while
forgetting that general items are optimized for hashing. So
basically I'm just using arrays now to sort items in it.
2014-04-24 10:49:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
video_t *obs_encoder_video(const obs_encoder_t *encoder)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_video"))
|
|
|
|
return NULL;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_VIDEO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_video: "
|
|
|
|
"encoder '%s' is not a video encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
return encoder->fps_override ? encoder->fps_override : encoder->media;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
audio_t *obs_encoder_audio(const obs_encoder_t *encoder)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_audio"))
|
|
|
|
return NULL;
|
|
|
|
if (encoder->info.type != OBS_ENCODER_AUDIO) {
|
|
|
|
blog(LOG_WARNING,
|
|
|
|
"obs_encoder_set_audio: "
|
|
|
|
"encoder '%s' is not an audio encoder",
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return encoder->media;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
bool obs_encoder_active(const obs_encoder_t *encoder)
|
2014-06-17 06:29:11 +02:00
|
|
|
{
|
2015-10-17 11:51:13 +02:00
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_active")
|
2016-01-25 10:42:06 +01:00
|
|
|
? encoder_active(encoder)
|
|
|
|
: false;
|
2014-06-17 06:29:11 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 00:25:59 +02:00
|
|
|
static inline bool get_sei(const struct obs_encoder *encoder, uint8_t **sei,
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
size_t *size)
|
|
|
|
{
|
2014-08-05 06:27:52 +02:00
|
|
|
if (encoder->info.get_sei_data)
|
|
|
|
return encoder->info.get_sei_data(encoder->context.data, sei,
|
|
|
|
size);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_first_video_packet(struct obs_encoder *encoder,
|
|
|
|
struct encoder_callback *cb,
|
|
|
|
struct encoder_packet *packet)
|
|
|
|
{
|
|
|
|
struct encoder_packet first_packet;
|
|
|
|
DARRAY(uint8_t) data;
|
|
|
|
uint8_t *sei;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
/* always wait for first keyframe */
|
|
|
|
if (!packet->keyframe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
da_init(data);
|
|
|
|
|
2016-04-19 16:22:04 +02:00
|
|
|
if (!get_sei(encoder, &sei, &size) || !sei || !size) {
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
cb->new_packet(cb->param, packet);
|
2014-12-18 21:02:27 +01:00
|
|
|
cb->sent_first_packet = true;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
da_push_back_array(data, sei, size);
|
|
|
|
da_push_back_array(data, packet->data, packet->size);
|
|
|
|
|
|
|
|
first_packet = *packet;
|
|
|
|
first_packet.data = data.array;
|
|
|
|
first_packet.size = data.num;
|
|
|
|
|
|
|
|
cb->new_packet(cb->param, &first_packet);
|
|
|
|
cb->sent_first_packet = true;
|
|
|
|
|
|
|
|
da_free(data);
|
|
|
|
}
|
|
|
|
|
2021-03-29 05:16:46 +02:00
|
|
|
static const char *send_packet_name = "send_packet";
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
static inline void send_packet(struct obs_encoder *encoder,
|
|
|
|
struct encoder_callback *cb,
|
|
|
|
struct encoder_packet *packet)
|
|
|
|
{
|
2021-03-29 05:16:46 +02:00
|
|
|
profile_start(send_packet_name);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
/* include SEI in first video packet */
|
|
|
|
if (encoder->info.type == OBS_ENCODER_VIDEO && !cb->sent_first_packet)
|
|
|
|
send_first_video_packet(encoder, cb, packet);
|
|
|
|
else
|
|
|
|
cb->new_packet(cb->param, packet);
|
2021-03-29 05:16:46 +02:00
|
|
|
profile_end(send_packet_name);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2019-02-06 02:37:40 +01:00
|
|
|
void full_stop(struct obs_encoder *encoder)
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
{
|
|
|
|
if (encoder) {
|
2019-05-17 10:19:36 +02:00
|
|
|
pthread_mutex_lock(&encoder->outputs_mutex);
|
|
|
|
for (size_t i = 0; i < encoder->outputs.num; i++) {
|
|
|
|
struct obs_output *output = encoder->outputs.array[i];
|
|
|
|
obs_output_force_stop(output);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&output->interleaved_mutex);
|
|
|
|
output->info.encoded_packet(output->context.data, NULL);
|
|
|
|
pthread_mutex_unlock(&output->interleaved_mutex);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&encoder->outputs_mutex);
|
|
|
|
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
pthread_mutex_lock(&encoder->callbacks_mutex);
|
|
|
|
da_free(encoder->callbacks);
|
|
|
|
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
2019-05-17 10:19:36 +02:00
|
|
|
|
|
|
|
remove_connection(encoder, false);
|
|
|
|
encoder->initialized = false;
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 02:32:25 +01:00
|
|
|
void send_off_encoder_packet(obs_encoder_t *encoder, bool success,
|
|
|
|
bool received, struct encoder_packet *pkt)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
|
|
|
if (!success) {
|
|
|
|
blog(LOG_ERROR, "Error encoding with encoder '%s'",
|
libobs: Add services API, reduce repeated code
Add API for streaming services. The services API simplifies the
creation of custom service features and user interface.
Custom streaming services later on will be able to do things such as:
- Be able to use service-specific APIs via modules, allowing a more
direct means of communicating with the service and requesting or
setting service-specific information
- Get URL/stream key via other means of authentication such as OAuth,
or be able to build custom URLs for services that require that sort
of thing.
- Query information (such as viewer count, chat, follower
notifications, and other information)
- Set channel information (such as current game, current channel title,
activating commercials)
Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.
I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.) ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-20 05:38:53 +02:00
|
|
|
encoder->context.name);
|
2019-05-17 10:19:36 +02:00
|
|
|
full_stop(encoder);
|
2019-02-06 02:32:25 +01:00
|
|
|
return;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (received) {
|
2016-01-25 10:47:42 +01:00
|
|
|
if (!encoder->first_received) {
|
2019-02-06 02:32:25 +01:00
|
|
|
encoder->offset_usec = packet_dts_usec(pkt);
|
2016-01-25 10:47:42 +01:00
|
|
|
encoder->first_received = true;
|
|
|
|
}
|
|
|
|
|
2014-04-10 20:59:42 +02:00
|
|
|
/* we use system time here to ensure sync with other encoders,
|
|
|
|
* you do not want to use relative timestamps here */
|
2019-02-06 02:32:25 +01:00
|
|
|
pkt->dts_usec = encoder->start_ts / 1000 +
|
|
|
|
packet_dts_usec(pkt) - encoder->offset_usec;
|
|
|
|
pkt->sys_dts_usec = pkt->dts_usec;
|
2014-04-10 20:59:42 +02:00
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
pthread_mutex_lock(&encoder->pause.mutex);
|
|
|
|
pkt->sys_dts_usec += encoder->pause.ts_offset / 1000;
|
|
|
|
pthread_mutex_unlock(&encoder->pause.mutex);
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
pthread_mutex_lock(&encoder->callbacks_mutex);
|
|
|
|
|
2015-06-08 16:16:07 +02:00
|
|
|
for (size_t i = encoder->callbacks.num; i > 0; i--) {
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
struct encoder_callback *cb;
|
2015-06-08 16:16:07 +02:00
|
|
|
cb = encoder->callbacks.array + (i - 1);
|
2019-02-06 02:32:25 +01:00
|
|
|
send_packet(encoder, cb, pkt);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&encoder->callbacks_mutex);
|
|
|
|
}
|
2019-02-06 02:32:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *do_encode_name = "do_encode";
|
2019-05-17 10:19:36 +02:00
|
|
|
bool do_encode(struct obs_encoder *encoder, struct encoder_frame *frame)
|
2019-02-06 02:32:25 +01:00
|
|
|
{
|
|
|
|
profile_start(do_encode_name);
|
|
|
|
if (!encoder->profile_encoder_encode_name)
|
|
|
|
encoder->profile_encoder_encode_name =
|
|
|
|
profile_store_name(obs_get_profiler_name_store(),
|
|
|
|
"encode(%s)", encoder->context.name);
|
|
|
|
|
|
|
|
struct encoder_packet pkt = {0};
|
|
|
|
bool received = false;
|
|
|
|
bool success;
|
|
|
|
|
2021-08-21 21:27:45 +02:00
|
|
|
if (encoder->reconfigure_requested) {
|
|
|
|
encoder->reconfigure_requested = false;
|
|
|
|
encoder->info.update(encoder->context.data,
|
|
|
|
encoder->context.settings);
|
|
|
|
}
|
|
|
|
|
2023-05-25 17:41:30 +02:00
|
|
|
pkt.timebase_num = encoder->timebase_num * encoder->frame_rate_divisor;
|
2019-02-06 02:32:25 +01:00
|
|
|
pkt.timebase_den = encoder->timebase_den;
|
|
|
|
pkt.encoder = encoder;
|
|
|
|
|
|
|
|
profile_start(encoder->profile_encoder_encode_name);
|
|
|
|
success = encoder->info.encode(encoder->context.data, frame, &pkt,
|
|
|
|
&received);
|
|
|
|
profile_end(encoder->profile_encoder_encode_name);
|
|
|
|
send_off_encoder_packet(encoder, success, received, &pkt);
|
2015-07-11 08:04:46 +02:00
|
|
|
|
|
|
|
profile_end(do_encode_name);
|
2019-05-17 10:19:36 +02:00
|
|
|
|
|
|
|
return success;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
static inline bool video_pause_check_internal(struct pause_data *pause,
|
|
|
|
uint64_t ts)
|
|
|
|
{
|
|
|
|
pause->last_video_ts = ts;
|
|
|
|
if (!pause->ts_start) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-31 10:04:47 +02:00
|
|
|
if (ts == pause->ts_end) {
|
2019-07-07 21:27:13 +02:00
|
|
|
pause->ts_start = 0;
|
|
|
|
pause->ts_end = 0;
|
|
|
|
|
2019-08-31 10:04:47 +02:00
|
|
|
} else if (ts >= pause->ts_start) {
|
2019-07-07 21:27:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool video_pause_check(struct pause_data *pause, uint64_t timestamp)
|
|
|
|
{
|
|
|
|
bool ignore_frame;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&pause->mutex);
|
|
|
|
ignore_frame = video_pause_check_internal(pause, timestamp);
|
|
|
|
pthread_mutex_unlock(&pause->mutex);
|
|
|
|
|
|
|
|
return ignore_frame;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:04:46 +02:00
|
|
|
static const char *receive_video_name = "receive_video";
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
static void receive_video(void *param, struct video_data *frame)
|
|
|
|
{
|
2015-07-11 08:04:46 +02:00
|
|
|
profile_start(receive_video_name);
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
struct obs_encoder *encoder = param;
|
2023-12-03 18:41:39 +01:00
|
|
|
struct obs_encoder **paired = encoder->paired_encoders.array;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
struct encoder_frame enc_frame;
|
|
|
|
|
2023-09-06 18:59:12 +02:00
|
|
|
if (encoder->encoder_group && !encoder->start_ts) {
|
|
|
|
struct encoder_group *group = encoder->encoder_group;
|
|
|
|
bool ready = false;
|
|
|
|
pthread_mutex_lock(&group->mutex);
|
|
|
|
ready = group->start_timestamp == frame->timestamp;
|
|
|
|
pthread_mutex_unlock(&group->mutex);
|
|
|
|
if (!ready)
|
|
|
|
goto wait_for_audio;
|
|
|
|
}
|
|
|
|
|
2023-12-03 18:41:39 +01:00
|
|
|
if (!encoder->first_received && encoder->paired_encoders.num) {
|
|
|
|
for (size_t i = 0; i < encoder->paired_encoders.num; i++) {
|
|
|
|
if (!paired[i]->first_received ||
|
|
|
|
paired[i]->first_raw_ts > frame->timestamp) {
|
|
|
|
goto wait_for_audio;
|
|
|
|
}
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
if (video_pause_check(&encoder->pause, frame->timestamp))
|
|
|
|
goto wait_for_audio;
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
memset(&enc_frame, 0, sizeof(struct encoder_frame));
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
|
|
|
enc_frame.data[i] = frame->data[i];
|
|
|
|
enc_frame.linesize[i] = frame->linesize[i];
|
|
|
|
}
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
if (!encoder->start_ts)
|
|
|
|
encoder->start_ts = frame->timestamp;
|
|
|
|
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
enc_frame.frames = 1;
|
|
|
|
enc_frame.pts = encoder->cur_pts;
|
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
if (do_encode(encoder, &enc_frame))
|
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-11 11:24:46 +01:00
|
|
|
encoder->cur_pts +=
|
|
|
|
encoder->timebase_num * encoder->frame_rate_divisor;
|
2015-07-11 08:04:46 +02:00
|
|
|
|
2016-01-30 21:50:51 +01:00
|
|
|
wait_for_audio:
|
2015-07-11 08:04:46 +02:00
|
|
|
profile_end(receive_video_name);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
2016-01-30 21:50:51 +01:00
|
|
|
static void clear_audio(struct obs_encoder *encoder)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < encoder->planes; i++)
|
2023-11-30 16:11:18 +01:00
|
|
|
deque_free(&encoder->audio_input_buffer[i]);
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void push_back_audio(struct obs_encoder *encoder,
|
|
|
|
struct audio_data *data, size_t size,
|
|
|
|
size_t offset_size)
|
|
|
|
{
|
2022-02-10 19:13:43 +01:00
|
|
|
if (offset_size >= size)
|
|
|
|
return;
|
|
|
|
|
2016-01-30 21:50:51 +01:00
|
|
|
size -= offset_size;
|
|
|
|
|
|
|
|
/* push in to the circular buffer */
|
2022-02-10 19:13:43 +01:00
|
|
|
for (size_t i = 0; i < encoder->planes; i++)
|
2023-11-30 16:11:18 +01:00
|
|
|
deque_push_back(&encoder->audio_input_buffer[i],
|
|
|
|
data->data[i] + offset_size, size);
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t calc_offset_size(struct obs_encoder *encoder,
|
|
|
|
uint64_t v_start_ts, uint64_t a_start_ts)
|
|
|
|
{
|
|
|
|
uint64_t offset = v_start_ts - a_start_ts;
|
2020-03-21 10:55:12 +01:00
|
|
|
offset = util_mul_div64(offset, encoder->samplerate, 1000000000ULL);
|
2016-01-30 21:50:51 +01:00
|
|
|
return (size_t)offset * encoder->blocksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void start_from_buffer(struct obs_encoder *encoder, uint64_t v_start_ts)
|
|
|
|
{
|
|
|
|
size_t size = encoder->audio_input_buffer[0].size;
|
|
|
|
struct audio_data audio = {0};
|
|
|
|
size_t offset_size = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
|
|
|
audio.data[i] = encoder->audio_input_buffer[i].data;
|
|
|
|
memset(&encoder->audio_input_buffer[i], 0,
|
2023-11-30 16:11:18 +01:00
|
|
|
sizeof(struct deque));
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder->first_raw_ts < v_start_ts)
|
|
|
|
offset_size = calc_offset_size(encoder, v_start_ts,
|
|
|
|
encoder->first_raw_ts);
|
|
|
|
|
|
|
|
push_back_audio(encoder, &audio, size, offset_size);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++)
|
|
|
|
bfree(audio.data[i]);
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:04:46 +02:00
|
|
|
static const char *buffer_audio_name = "buffer_audio";
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
static bool buffer_audio(struct obs_encoder *encoder, struct audio_data *data)
|
|
|
|
{
|
2015-07-11 08:04:46 +02:00
|
|
|
profile_start(buffer_audio_name);
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
size_t size = data->frames * encoder->blocksize;
|
|
|
|
size_t offset_size = 0;
|
2016-01-30 21:50:51 +01:00
|
|
|
bool success = true;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
2023-12-03 18:41:39 +01:00
|
|
|
struct obs_encoder *paired_encoder = NULL;
|
|
|
|
/* Audio encoders can only be paired to one video encoder */
|
|
|
|
if (encoder->paired_encoders.num)
|
|
|
|
paired_encoder = encoder->paired_encoders.array[0];
|
|
|
|
|
|
|
|
if (!encoder->start_ts && paired_encoder) {
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
uint64_t end_ts = data->timestamp;
|
2023-12-03 18:41:39 +01:00
|
|
|
uint64_t v_start_ts = paired_encoder->start_ts;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
/* no video yet, so don't start audio */
|
2016-01-30 21:50:51 +01:00
|
|
|
if (!v_start_ts) {
|
|
|
|
success = false;
|
2015-07-11 08:04:46 +02:00
|
|
|
goto fail;
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
/* audio starting point still not synced with video starting
|
|
|
|
* point, so don't start audio */
|
2020-03-21 10:55:12 +01:00
|
|
|
end_ts += util_mul_div64(data->frames, 1000000000ULL,
|
|
|
|
encoder->samplerate);
|
2016-01-30 21:50:51 +01:00
|
|
|
if (end_ts <= v_start_ts) {
|
|
|
|
success = false;
|
2015-07-11 08:04:46 +02:00
|
|
|
goto fail;
|
2016-01-30 21:50:51 +01:00
|
|
|
}
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
/* ready to start audio, truncate if necessary */
|
2016-01-30 21:50:51 +01:00
|
|
|
if (data->timestamp < v_start_ts)
|
|
|
|
offset_size = calc_offset_size(encoder, v_start_ts,
|
|
|
|
data->timestamp);
|
|
|
|
if (data->timestamp <= v_start_ts)
|
|
|
|
clear_audio(encoder);
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
encoder->start_ts = v_start_ts;
|
2015-02-11 06:47:34 +01:00
|
|
|
|
2016-01-30 21:50:51 +01:00
|
|
|
/* use currently buffered audio instead */
|
|
|
|
if (v_start_ts < data->timestamp) {
|
|
|
|
start_from_buffer(encoder, v_start_ts);
|
|
|
|
}
|
|
|
|
|
2023-12-03 18:41:39 +01:00
|
|
|
} else if (!encoder->start_ts && !paired_encoder) {
|
2015-02-11 06:47:34 +01:00
|
|
|
encoder->start_ts = data->timestamp;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
}
|
|
|
|
|
2015-07-11 08:04:46 +02:00
|
|
|
fail:
|
2016-01-30 21:50:51 +01:00
|
|
|
push_back_audio(encoder, data, size, offset_size);
|
|
|
|
|
2015-07-11 08:04:46 +02:00
|
|
|
profile_end(buffer_audio_name);
|
2016-01-30 21:50:51 +01:00
|
|
|
return success;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
}
|
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
static bool send_audio_data(struct obs_encoder *encoder)
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
{
|
|
|
|
struct encoder_frame enc_frame;
|
|
|
|
|
|
|
|
memset(&enc_frame, 0, sizeof(struct encoder_frame));
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
for (size_t i = 0; i < encoder->planes; i++) {
|
2023-11-30 16:11:18 +01:00
|
|
|
deque_pop_front(&encoder->audio_input_buffer[i],
|
|
|
|
encoder->audio_output_buffer[i],
|
|
|
|
encoder->framesize_bytes);
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
enc_frame.data[i] = encoder->audio_output_buffer[i];
|
|
|
|
enc_frame.linesize[i] = (uint32_t)encoder->framesize_bytes;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
}
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
enc_frame.frames = (uint32_t)encoder->framesize;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
enc_frame.pts = encoder->cur_pts;
|
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
if (!do_encode(encoder, &enc_frame))
|
|
|
|
return false;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
|
|
|
encoder->cur_pts += encoder->framesize;
|
2019-05-17 10:19:36 +02:00
|
|
|
return true;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
static void pause_audio(struct pause_data *pause, struct audio_data *data,
|
|
|
|
size_t sample_rate)
|
|
|
|
{
|
|
|
|
uint64_t cutoff_frames = pause->ts_start - data->timestamp;
|
|
|
|
cutoff_frames = ns_to_audio_frames(sample_rate, cutoff_frames);
|
|
|
|
|
|
|
|
data->frames = (uint32_t)cutoff_frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unpause_audio(struct pause_data *pause, struct audio_data *data,
|
|
|
|
size_t sample_rate)
|
|
|
|
{
|
|
|
|
uint64_t cutoff_frames = pause->ts_end - data->timestamp;
|
|
|
|
cutoff_frames = ns_to_audio_frames(sample_rate, cutoff_frames);
|
|
|
|
|
2019-08-31 10:09:14 +02:00
|
|
|
for (size_t i = 0; i < MAX_AV_PLANES; i++) {
|
|
|
|
if (!data->data[i])
|
|
|
|
break;
|
|
|
|
data->data[i] += cutoff_frames * sizeof(float);
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
data->timestamp = pause->ts_start;
|
|
|
|
data->frames = data->frames - (uint32_t)cutoff_frames;
|
|
|
|
pause->ts_start = 0;
|
|
|
|
pause->ts_end = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool audio_pause_check_internal(struct pause_data *pause,
|
|
|
|
struct audio_data *data,
|
|
|
|
size_t sample_rate)
|
|
|
|
{
|
|
|
|
uint64_t end_ts;
|
|
|
|
|
|
|
|
if (!pause->ts_start) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_ts =
|
|
|
|
data->timestamp + audio_frames_to_ns(sample_rate, data->frames);
|
|
|
|
|
|
|
|
if (pause->ts_start >= data->timestamp) {
|
|
|
|
if (pause->ts_start <= end_ts) {
|
|
|
|
pause_audio(pause, data, sample_rate);
|
|
|
|
return !data->frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (pause->ts_end >= data->timestamp &&
|
|
|
|
pause->ts_end <= end_ts) {
|
|
|
|
unpause_audio(pause, data, sample_rate);
|
|
|
|
return !data->frames;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool audio_pause_check(struct pause_data *pause, struct audio_data *data,
|
|
|
|
size_t sample_rate)
|
|
|
|
{
|
|
|
|
bool ignore_audio;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&pause->mutex);
|
|
|
|
ignore_audio = audio_pause_check_internal(pause, data, sample_rate);
|
|
|
|
data->timestamp -= pause->ts_offset;
|
|
|
|
pthread_mutex_unlock(&pause->mutex);
|
|
|
|
|
|
|
|
return ignore_audio;
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:04:46 +02:00
|
|
|
static const char *receive_audio_name = "receive_audio";
|
2019-07-07 21:27:13 +02:00
|
|
|
static void receive_audio(void *param, size_t mix_idx, struct audio_data *in)
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
{
|
2015-07-11 08:04:46 +02:00
|
|
|
profile_start(receive_audio_name);
|
|
|
|
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
struct obs_encoder *encoder = param;
|
2019-07-07 21:27:13 +02:00
|
|
|
struct audio_data audio = *in;
|
Implement RTMP module (still needs drop code)
- Implement the RTMP output module. This time around, we just use a
simple FLV muxer, then just write to the stream with RTMP_Write.
Easy and effective.
- Fix the FLV muxer, the muxer now outputs proper FLV packets.
- Output API:
* When using encoders, automatically interleave encoded packets
before sending it to the output.
* Pair encoders and have them automatically wait for the other to
start to ensure sync.
* Change 'obs_output_signal_start_fail' to 'obs_output_signal_stop'
because it was a bit confusing, and doing this makes a lot more
sense for outputs that need to stop suddenly (disconnections/etc).
- Encoder API:
* Remove some unnecessary encoder functions from the actual API and
make them internal. Most of the encoder functions are handled
automatically by outputs anyway, so there's no real need to expose
them and end up inadvertently confusing plugin writers.
* Have audio encoders wait for the video encoder to get a frame, then
start at the exact data point that the first video frame starts to
ensure the most accrate sync of video/audio possible.
* Add a required 'frame_size' callback for audio encoders that
returns the expected number of frames desired to encode with. This
way, the libobs encoder API can handle the circular buffering
internally automatically for the encoder modules, so encoder
writers don't have to do it themselves.
- Fix a few bugs in the serializer interface. It was passing the wrong
variable for the data in a few cases.
- If a source has video, make obs_source_update defer the actual update
callback until the tick function is called to prevent threading
issues.
2014-04-08 07:00:10 +02:00
|
|
|
|
2016-01-30 21:50:51 +01:00
|
|
|
if (!encoder->first_received) {
|
2019-07-07 21:27:13 +02:00
|
|
|
encoder->first_raw_ts = audio.timestamp;
|
2016-01-30 21:50:51 +01:00
|
|
|
encoder->first_received = true;
|
|
|
|
clear_audio(encoder);
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:27:13 +02:00
|
|
|
if (audio_pause_check(&encoder->pause, &audio, encoder->samplerate))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (!buffer_audio(encoder, &audio))
|
2015-07-11 08:04:46 +02:00
|
|
|
goto end;
|
Implement encoder interface (still preliminary)
- Implement OBS encoder interface. It was previously incomplete, but
now is reaching some level of completion, though probably should
still be considered preliminary.
I had originally implemented it so that encoders only have a 'reset'
function to reset their parameters, but I felt that having both a
'start' and 'stop' function would be useful.
Encoders are now assigned to a specific video/audio media output each
rather than implicitely assigned to the main obs video/audio
contexts. This allows separate encoder contexts that aren't
necessarily assigned to the main video/audio context (which is useful
for things such as recording specific sources). Will probably have
to do this for regular obs outputs as well.
When creating an encoder, you must now explicitely state whether that
encoder is an audio or video encoder.
Audio and video can optionally be automatically converted depending
on what the encoder specifies.
When something 'attaches' to an encoder, the first attachment starts
the encoder, and the encoder automatically attaches to the media
output context associated with it. Subsequent attachments won't have
the same effect, they will just start receiving the same encoder data
when the next keyframe plays (along with SEI if any). When detaching
from the encoder, the last detachment will fully stop the encoder and
detach the encoder from the media output context associated with the
encoder.
SEI must actually be exported separately; because new encoder
attachments may not always be at the beginning of the stream, the
first keyframe they get must have that SEI data in it. If the
encoder has SEI data, it needs only add one small function to simply
query that SEI data, and then that data will be handled automatically
by libobs for all subsequent encoder attachments.
- Implement x264 encoder plugin, move x264 files to separate plugin to
separate necessary dependencies.
- Change video/audio frame output structures to not use const
qualifiers to prevent issues with non-const function usage elsewhere.
This was an issue when writing the x264 encoder, as the x264 encoder
expects non-const frame data.
Change stagesurf_map to return a non-const data type to prevent this
as well.
- Change full range parameter of video scaler to be an enum rather than
boolean
2014-03-17 00:21:34 +01:00
|
|
|
|
2019-05-17 10:19:36 +02:00
|
|
|
while (encoder->audio_input_buffer[0].size >=
|
|
|
|
encoder->framesize_bytes) {
|
|
|
|
if (!send_audio_data(encoder)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
(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-01-14 11:12:08 +01:00
|
|
|
|
|
|
|
UNUSED_PARAMETER(mix_idx);
|
2015-07-11 08:04:46 +02:00
|
|
|
|
|
|
|
end:
|
|
|
|
profile_end(receive_audio_name);
|
Add preliminary output/encoder interface
- First, I redid the output interface for libobs. I feel like it's
going in a pretty good direction in terms of design.
Right now, the design is so that outputs and encoders are separate.
One or more outputs can connect to a specific encoder to receive its
data, or the output can connect directly to raw data from libobs
output itself, if the output doesn't want to use a designated encoder.
Data is received via callbacks set when you connect to the encoder or
raw output. Multiple outputs can receive the data from a single
encoder context if need be (such as for streaming to multiple channels
at once, and/or recording with the same data).
When an encoder is first connected to, it will connect to raw output,
and start encoding. Additional connections will receive that same
data being encoded as well after that. When the last encoder has
disconnected, it will stop encoding. If for some reason the encoder
needs to stop, it will use the callback with NULL to signal that
encoding has stopped. Some of these things may be subject to change
in the future, though it feels pretty good with this design so far.
Will have to see how well it works out in practice versus theory.
- Second, Started adding preliminary RTMP/x264 output plugin code.
To speed things up, I might just make a direct raw->FFmpeg output to
create a quick output plugin that we can start using for testing all
the subsystems.
2014-01-17 06:34:51 +01:00
|
|
|
}
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
|
|
|
|
void obs_encoder_add_output(struct obs_encoder *encoder,
|
|
|
|
struct obs_output *output)
|
|
|
|
{
|
2023-01-16 05:12:09 +01:00
|
|
|
if (!encoder || !output)
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->outputs_mutex);
|
|
|
|
da_push_back(encoder->outputs, &output);
|
|
|
|
pthread_mutex_unlock(&encoder->outputs_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_remove_output(struct obs_encoder *encoder,
|
|
|
|
struct obs_output *output)
|
|
|
|
{
|
2023-01-16 05:12:09 +01:00
|
|
|
if (!encoder || !output)
|
Implement encoder usage with outputs
- Make it so that encoders can be assigned to outputs. If an encoder
is destroyed, it will automatically remove itself from that output.
I specifically didn't want to do reference counting because it leaves
too much potential for unchecked references and it just felt like it
would be more trouble than it's worth.
- Add a 'flags' value to the output definition structure. This lets
the output specify if it uses video/audio, and whether the output is
meant to be used with OBS encoders or not.
- Remove boilerplate code for outputs. This makes it easier to program
outputs. The boilerplate code involved before was mostly just
involving connecting to the audio/video data streams directly in each
output plugin.
Instead of doing that, simply add plugin callback functions for
receiving video/audio (either encoded or non-encoded, whichever it's
set to use), and then call obs_output_begin_data_capture and
obs_output_end_data_capture to automatically handle setting up
connections to raw or encoded video/audio streams for the plugin.
- Remove 'active' function from output callbacks, as it's no longer
really needed now that the libobs output context automatically knows
when the output is active or not.
- Make it so that an encoder cannot be destroyed until all data
connections to the encoder have been removed.
- Change the 'start' and 'stop' functions in the encoder interface to
just an 'initialize' callback, which initializes the encoder.
- Make it so that the encoder must be initialized first before the data
stream can be started. The reason why initialization was separated
from starting the encoder stream was because we need to be able to
check that the settings used with the encoder *can* be used first.
This problem was especially annoying if you had both video/audio
encoding. Before, you'd have to check the return value from
obs_encoder_start, and if that second encoder fails, then you
basically had to stop the first encoder again, making for
unnecessary boilerplate code whenever starting up two encoders.
2014-03-28 05:50:15 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->outputs_mutex);
|
|
|
|
da_erase_item(encoder->outputs, &output);
|
|
|
|
pthread_mutex_unlock(&encoder->outputs_mutex);
|
|
|
|
}
|
2014-04-01 20:55:18 +02:00
|
|
|
|
2016-12-07 21:45:25 +01:00
|
|
|
void obs_encoder_packet_create_instance(struct encoder_packet *dst,
|
2014-04-01 20:55:18 +02:00
|
|
|
const struct encoder_packet *src)
|
|
|
|
{
|
2016-12-07 21:45:25 +01:00
|
|
|
long *p_refs;
|
|
|
|
|
2014-04-01 20:55:18 +02:00
|
|
|
*dst = *src;
|
2016-12-07 21:45:25 +01:00
|
|
|
p_refs = bmalloc(src->size + sizeof(long));
|
|
|
|
dst->data = (void *)(p_refs + 1);
|
|
|
|
*p_refs = 1;
|
|
|
|
memcpy(dst->data, src->data, src->size);
|
|
|
|
}
|
|
|
|
|
2020-01-21 06:44:50 +01:00
|
|
|
/* OBS_DEPRECATED */
|
2016-12-07 21:45:25 +01:00
|
|
|
void obs_duplicate_encoder_packet(struct encoder_packet *dst,
|
|
|
|
const struct encoder_packet *src)
|
|
|
|
{
|
|
|
|
obs_encoder_packet_create_instance(dst, src);
|
2014-04-01 20:55:18 +02:00
|
|
|
}
|
|
|
|
|
2020-01-21 06:44:50 +01:00
|
|
|
/* OBS_DEPRECATED */
|
2014-04-01 20:55:18 +02:00
|
|
|
void obs_free_encoder_packet(struct encoder_packet *packet)
|
|
|
|
{
|
2016-12-07 21:45:25 +01:00
|
|
|
obs_encoder_packet_release(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_packet_ref(struct encoder_packet *dst,
|
|
|
|
struct encoder_packet *src)
|
|
|
|
{
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (src->data) {
|
|
|
|
long *p_refs = ((long *)src->data) - 1;
|
|
|
|
os_atomic_inc_long(p_refs);
|
|
|
|
}
|
|
|
|
|
|
|
|
*dst = *src;
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_packet_release(struct encoder_packet *pkt)
|
|
|
|
{
|
|
|
|
if (!pkt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pkt->data) {
|
|
|
|
long *p_refs = ((long *)pkt->data) - 1;
|
|
|
|
if (os_atomic_dec_long(p_refs) == 0)
|
|
|
|
bfree(p_refs);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(pkt, 0, sizeof(struct encoder_packet));
|
2014-04-01 20:55:18 +02:00
|
|
|
}
|
2015-04-17 08:10:56 +02:00
|
|
|
|
|
|
|
void obs_encoder_set_preferred_video_format(obs_encoder_t *encoder,
|
|
|
|
enum video_format format)
|
|
|
|
{
|
|
|
|
if (!encoder || encoder->info.type != OBS_ENCODER_VIDEO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
encoder->preferred_format = format;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum video_format
|
|
|
|
obs_encoder_get_preferred_video_format(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder || encoder->info.type != OBS_ENCODER_VIDEO)
|
|
|
|
return VIDEO_FORMAT_NONE;
|
|
|
|
|
|
|
|
return encoder->preferred_format;
|
|
|
|
}
|
2015-05-04 02:01:38 +02:00
|
|
|
|
|
|
|
void obs_encoder_addref(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder)
|
|
|
|
return;
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
obs_ref_addref(&encoder->context.control->ref);
|
2015-05-04 02:01:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_release(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder)
|
|
|
|
return;
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
obs_weak_encoder_t *control = get_weak(encoder);
|
2015-05-04 02:01:38 +02:00
|
|
|
if (obs_ref_release(&control->ref)) {
|
|
|
|
// The order of operations is important here since
|
|
|
|
// get_context_by_name in obs.c relies on weak refs
|
|
|
|
// being alive while the context is listed
|
|
|
|
obs_encoder_destroy(encoder);
|
|
|
|
obs_weak_encoder_release(control);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_weak_encoder_addref(obs_weak_encoder_t *weak)
|
|
|
|
{
|
|
|
|
if (!weak)
|
|
|
|
return;
|
|
|
|
|
|
|
|
obs_weak_ref_addref(&weak->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_weak_encoder_release(obs_weak_encoder_t *weak)
|
|
|
|
{
|
|
|
|
if (!weak)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (obs_weak_ref_release(&weak->ref))
|
|
|
|
bfree(weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_encoder_t *obs_encoder_get_ref(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder)
|
|
|
|
return NULL;
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
return obs_weak_encoder_get_encoder(get_weak(encoder));
|
2015-05-04 02:01:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_weak_encoder_t *obs_encoder_get_weak_encoder(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder)
|
|
|
|
return NULL;
|
|
|
|
|
2022-02-03 06:56:30 +01:00
|
|
|
obs_weak_encoder_t *weak = get_weak(encoder);
|
2015-05-04 02:01:38 +02:00
|
|
|
obs_weak_encoder_addref(weak);
|
|
|
|
return weak;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_encoder_t *obs_weak_encoder_get_encoder(obs_weak_encoder_t *weak)
|
|
|
|
{
|
|
|
|
if (!weak)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (obs_weak_ref_get_ref(&weak->ref))
|
|
|
|
return weak->encoder;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool obs_weak_encoder_references_encoder(obs_weak_encoder_t *weak,
|
|
|
|
obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return weak && encoder && weak->encoder == encoder;
|
|
|
|
}
|
2015-09-16 07:51:37 +02:00
|
|
|
|
|
|
|
void *obs_encoder_get_type_data(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_type_data")
|
2018-10-13 05:16:04 +02:00
|
|
|
? encoder->orig_info.type_data
|
|
|
|
: NULL;
|
2015-09-16 07:51:37 +02:00
|
|
|
}
|
2015-10-20 00:01:25 +02:00
|
|
|
|
|
|
|
const char *obs_encoder_get_id(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_id")
|
2018-10-13 05:16:04 +02:00
|
|
|
? encoder->orig_info.id
|
|
|
|
: NULL;
|
2015-10-20 00:01:25 +02:00
|
|
|
}
|
2016-04-11 14:02:39 +02:00
|
|
|
|
|
|
|
uint32_t obs_get_encoder_caps(const char *encoder_id)
|
|
|
|
{
|
|
|
|
struct obs_encoder_info *info = find_encoder(encoder_id);
|
|
|
|
return info ? info->caps : 0;
|
|
|
|
}
|
2019-02-26 17:02:57 +01:00
|
|
|
|
|
|
|
uint32_t obs_encoder_get_caps(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_get_caps")
|
|
|
|
? encoder->orig_info.caps
|
|
|
|
: 0;
|
|
|
|
}
|
2019-07-07 21:27:13 +02:00
|
|
|
|
|
|
|
bool obs_encoder_paused(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return obs_encoder_valid(encoder, "obs_encoder_paused")
|
|
|
|
? os_atomic_load_bool(&encoder->paused)
|
|
|
|
: false;
|
|
|
|
}
|
2019-10-09 18:27:09 +02:00
|
|
|
|
|
|
|
const char *obs_encoder_get_last_error(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_get_last_error"))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return encoder->last_error_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_set_last_error(obs_encoder_t *encoder, const char *message)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder, "obs_encoder_set_last_error"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (encoder->last_error_message)
|
|
|
|
bfree(encoder->last_error_message);
|
|
|
|
|
|
|
|
if (message)
|
|
|
|
encoder->last_error_message = bstrdup(message);
|
|
|
|
else
|
|
|
|
encoder->last_error_message = NULL;
|
|
|
|
}
|
2022-09-30 22:07:19 +02:00
|
|
|
|
|
|
|
uint64_t obs_encoder_get_pause_offset(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return encoder ? encoder->pause.ts_offset : 0;
|
|
|
|
}
|
2023-12-24 10:13:34 +01:00
|
|
|
|
|
|
|
bool obs_encoder_has_roi(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return encoder->roi.num > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool obs_encoder_add_roi(obs_encoder_t *encoder,
|
|
|
|
const struct obs_encoder_roi *roi)
|
|
|
|
{
|
|
|
|
if (!roi)
|
|
|
|
return false;
|
|
|
|
if (!(encoder->info.caps & OBS_ENCODER_CAP_ROI))
|
|
|
|
return false;
|
|
|
|
/* Area smaller than the smallest possible block (16x16) */
|
|
|
|
if (roi->bottom - roi->top < 16 || roi->right - roi->left < 16)
|
|
|
|
return false;
|
|
|
|
/* Other invalid ROIs */
|
|
|
|
if (roi->priority < -1.0f || roi->priority > 1.0f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->roi_mutex);
|
|
|
|
da_push_back(encoder->roi, roi);
|
|
|
|
encoder->roi_increment++;
|
|
|
|
pthread_mutex_unlock(&encoder->roi_mutex);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_clear_roi(obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
if (!encoder->roi.num)
|
|
|
|
return;
|
|
|
|
pthread_mutex_lock(&encoder->roi_mutex);
|
|
|
|
da_clear(encoder->roi);
|
|
|
|
encoder->roi_increment++;
|
|
|
|
pthread_mutex_unlock(&encoder->roi_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void obs_encoder_enum_roi(obs_encoder_t *encoder,
|
|
|
|
void (*enum_proc)(void *, struct obs_encoder_roi *),
|
|
|
|
void *param)
|
|
|
|
{
|
|
|
|
float scale_x = 0;
|
|
|
|
float scale_y = 0;
|
|
|
|
|
|
|
|
/* Scale ROI passed to callback to output size */
|
|
|
|
if (encoder->scaled_height && encoder->scaled_width) {
|
|
|
|
const uint32_t width = video_output_get_width(encoder->media);
|
|
|
|
const uint32_t height = video_output_get_height(encoder->media);
|
|
|
|
|
|
|
|
if (!width || !height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scale_x = (float)encoder->scaled_width / (float)width;
|
|
|
|
scale_y = (float)encoder->scaled_height / (float)height;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&encoder->roi_mutex);
|
|
|
|
|
|
|
|
size_t idx = encoder->roi.num;
|
|
|
|
while (idx) {
|
|
|
|
struct obs_encoder_roi *roi = &encoder->roi.array[--idx];
|
|
|
|
|
|
|
|
if (scale_x > 0 && scale_y > 0) {
|
|
|
|
struct obs_encoder_roi scaled_roi = {
|
|
|
|
.top = (uint32_t)((float)roi->top * scale_y),
|
|
|
|
.bottom = (uint32_t)((float)roi->bottom *
|
|
|
|
scale_y),
|
|
|
|
.left = (uint32_t)((float)roi->left * scale_x),
|
|
|
|
.right =
|
|
|
|
(uint32_t)((float)roi->right * scale_x),
|
|
|
|
.priority = roi->priority,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum_proc(param, &scaled_roi);
|
|
|
|
} else {
|
|
|
|
enum_proc(param, roi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&encoder->roi_mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t obs_encoder_get_roi_increment(const obs_encoder_t *encoder)
|
|
|
|
{
|
|
|
|
return encoder->roi_increment;
|
|
|
|
}
|
2023-09-06 18:59:12 +02:00
|
|
|
|
|
|
|
bool obs_encoder_group_keyframe_aligned_encoders(
|
|
|
|
obs_encoder_t *encoder, obs_encoder_t *encoder_to_be_grouped)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(encoder,
|
|
|
|
"obs_encoder_group_keyframe_aligned_encoders") ||
|
|
|
|
!obs_encoder_valid(encoder_to_be_grouped,
|
|
|
|
"obs_encoder_group_keyframe_aligned_encoders"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (obs_encoder_active(encoder) ||
|
|
|
|
obs_encoder_active(encoder_to_be_grouped)) {
|
|
|
|
obs_encoder_t *active = obs_encoder_active(encoder)
|
|
|
|
? encoder
|
|
|
|
: encoder_to_be_grouped;
|
|
|
|
obs_encoder_t *other = active == encoder ? encoder_to_be_grouped
|
|
|
|
: encoder;
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_keyframe_aligned_encoders: encoder '%s' "
|
|
|
|
"is already active, could not group with '%s'",
|
|
|
|
obs_encoder_get_name(active), obs_encoder_get_name(other));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder_to_be_grouped->encoder_group) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_keyframe_aligned_encoders: encoder '%s' "
|
|
|
|
"is already part of a keyframe aligned group while trying "
|
|
|
|
"to group with encoder '%s'",
|
|
|
|
obs_encoder_get_name(encoder_to_be_grouped),
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool unlock = false;
|
|
|
|
if (!encoder->encoder_group) {
|
|
|
|
encoder->encoder_group = bzalloc(sizeof(struct encoder_group));
|
|
|
|
if (pthread_mutex_init(&encoder->encoder_group->mutex, NULL) <
|
|
|
|
0) {
|
|
|
|
bfree(encoder->encoder_group);
|
|
|
|
encoder->encoder_group = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
encoder->encoder_group->encoders_added = 1;
|
|
|
|
} else {
|
|
|
|
pthread_mutex_lock(&encoder->encoder_group->mutex);
|
|
|
|
unlock = true;
|
|
|
|
if (encoder->encoder_group->encoders_started != 0) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_keyframe_aligned_encoders: "
|
|
|
|
"Can't add encoder '%s' to active group "
|
|
|
|
"from encoder '%s'",
|
|
|
|
obs_encoder_get_name(encoder_to_be_grouped),
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
pthread_mutex_unlock(&encoder->encoder_group->mutex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
encoder->encoder_group->encoders_added += 1;
|
|
|
|
encoder_to_be_grouped->encoder_group = encoder->encoder_group;
|
|
|
|
|
|
|
|
if (unlock)
|
|
|
|
pthread_mutex_unlock(&encoder->encoder_group->mutex);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool obs_encoder_group_remove_keyframe_aligned_encoder(
|
|
|
|
obs_encoder_t *encoder, obs_encoder_t *encoder_to_be_ungrouped)
|
|
|
|
{
|
|
|
|
if (!obs_encoder_valid(
|
|
|
|
encoder,
|
|
|
|
"obs_encoder_group_remove_keyframe_aligned_encoder") ||
|
|
|
|
!obs_encoder_valid(
|
|
|
|
encoder_to_be_ungrouped,
|
|
|
|
"obs_encoder_group_remove_keyframe_aligned_encoder"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (obs_encoder_active(encoder) ||
|
|
|
|
obs_encoder_active(encoder_to_be_ungrouped)) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_remove_keyframe_aligned_encoder: encoders are active, "
|
|
|
|
"could not ungroup encoder '%s' from '%s'",
|
|
|
|
obs_encoder_get_name(encoder_to_be_ungrouped),
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (encoder->encoder_group != encoder_to_be_ungrouped->encoder_group) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_remove_keyframe_aligned_encoder: "
|
|
|
|
"encoder '%s' does not belong to the same group as encoder '%s'",
|
|
|
|
obs_encoder_get_name(encoder_to_be_ungrouped),
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct encoder_group *current_group = encoder->encoder_group;
|
|
|
|
struct encoder_group *free_group = NULL;
|
|
|
|
|
|
|
|
pthread_mutex_lock(¤t_group->mutex);
|
|
|
|
|
|
|
|
if (current_group->encoders_started != 0) {
|
|
|
|
blog(LOG_ERROR,
|
|
|
|
"obs_encoder_group_remove_keyframe_aligned_encoder: "
|
|
|
|
"could not ungroup encoder '%s' from '%s' while "
|
|
|
|
"the group contains active encoders",
|
|
|
|
obs_encoder_get_name(encoder_to_be_ungrouped),
|
|
|
|
obs_encoder_get_name(encoder));
|
|
|
|
pthread_mutex_unlock(¤t_group->mutex);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_group->encoders_added -= 1;
|
|
|
|
encoder_to_be_ungrouped->encoder_group = NULL;
|
|
|
|
if (current_group->encoders_added == 1) {
|
|
|
|
free_group = current_group;
|
|
|
|
encoder->encoder_group = NULL;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(¤t_group->mutex);
|
|
|
|
|
|
|
|
if (free_group) {
|
|
|
|
pthread_mutex_destroy(&free_group->mutex);
|
|
|
|
bfree(free_group);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|