mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-07-15 07:44:10 +00:00
libobs: Add function to allow custom output drawing
Optionally allows drawing directly to the primary output instead of having to use a source to draw.
This commit is contained in:
parent
ffef736640
commit
ad57aa1520
|
@ -315,6 +315,8 @@ struct obs_core_data {
|
|||
pthread_mutex_t encoders_mutex;
|
||||
pthread_mutex_t services_mutex;
|
||||
pthread_mutex_t audio_sources_mutex;
|
||||
pthread_mutex_t draw_callbacks_mutex;
|
||||
DARRAY(struct draw_callback) draw_callbacks;
|
||||
|
||||
struct obs_view main_view;
|
||||
|
||||
|
|
|
@ -105,6 +105,19 @@ static inline void render_main_texture(struct obs_core_video *video,
|
|||
gs_clear(GS_CLEAR_COLOR, &clear_color, 1.0f, 0);
|
||||
|
||||
set_render_size(video->base_width, video->base_height);
|
||||
|
||||
pthread_mutex_lock(&obs->data.draw_callbacks_mutex);
|
||||
|
||||
for (size_t i = 0; i < obs->data.draw_callbacks.num; i++) {
|
||||
struct draw_callback *callback;
|
||||
callback = obs->data.draw_callbacks.array+i;
|
||||
|
||||
callback->draw(callback->param,
|
||||
video->base_width, video->base_height);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&obs->data.draw_callbacks_mutex);
|
||||
|
||||
obs_view_render(&obs->data.main_view);
|
||||
|
||||
video->textures_rendered[cur_texture] = true;
|
||||
|
|
33
libobs/obs.c
33
libobs/obs.c
|
@ -542,6 +542,7 @@ static bool obs_init_data(void)
|
|||
assert(data != NULL);
|
||||
|
||||
pthread_mutex_init_value(&obs->data.displays_mutex);
|
||||
pthread_mutex_init_value(&obs->data.draw_callbacks_mutex);
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return false;
|
||||
|
@ -559,6 +560,8 @@ static bool obs_init_data(void)
|
|||
goto fail;
|
||||
if (pthread_mutex_init(&data->services_mutex, &attr) != 0)
|
||||
goto fail;
|
||||
if (pthread_mutex_init(&obs->data.draw_callbacks_mutex, NULL) != 0)
|
||||
goto fail;
|
||||
if (!obs_view_init(&data->main_view))
|
||||
goto fail;
|
||||
|
||||
|
@ -614,6 +617,8 @@ static void obs_free_data(void)
|
|||
pthread_mutex_destroy(&data->outputs_mutex);
|
||||
pthread_mutex_destroy(&data->encoders_mutex);
|
||||
pthread_mutex_destroy(&data->services_mutex);
|
||||
pthread_mutex_destroy(&data->draw_callbacks_mutex);
|
||||
da_free(data->draw_callbacks);
|
||||
}
|
||||
|
||||
static const char *obs_signals[] = {
|
||||
|
@ -1919,3 +1924,31 @@ void obs_get_audio_monitoring_device(const char **name, const char **id)
|
|||
if (id)
|
||||
*id = obs->audio.monitoring_device_id;
|
||||
}
|
||||
|
||||
void obs_add_main_render_callback(
|
||||
void (*draw)(void *param, uint32_t cx, uint32_t cy),
|
||||
void *param)
|
||||
{
|
||||
if (!obs)
|
||||
return;
|
||||
|
||||
struct draw_callback data = {draw, param};
|
||||
|
||||
pthread_mutex_lock(&obs->data.draw_callbacks_mutex);
|
||||
da_push_back(obs->data.draw_callbacks, &data);
|
||||
pthread_mutex_unlock(&obs->data.draw_callbacks_mutex);
|
||||
}
|
||||
|
||||
void obs_remove_main_render_callback(
|
||||
void (*draw)(void *param, uint32_t cx, uint32_t cy),
|
||||
void *param)
|
||||
{
|
||||
if (!obs)
|
||||
return;
|
||||
|
||||
struct draw_callback data = {draw, param};
|
||||
|
||||
pthread_mutex_lock(&obs->data.draw_callbacks_mutex);
|
||||
da_erase_item(obs->data.draw_callbacks, &data);
|
||||
pthread_mutex_unlock(&obs->data.draw_callbacks_mutex);
|
||||
}
|
||||
|
|
|
@ -591,6 +591,13 @@ EXPORT void obs_enum_audio_monitoring_devices(obs_enum_audio_device_cb cb,
|
|||
EXPORT bool obs_set_audio_monitoring_device(const char *name, const char *id);
|
||||
EXPORT void obs_get_audio_monitoring_device(const char **name, const char **id);
|
||||
|
||||
EXPORT void obs_add_main_render_callback(
|
||||
void (*draw)(void *param, uint32_t cx, uint32_t cy),
|
||||
void *param);
|
||||
EXPORT void obs_remove_main_render_callback(
|
||||
void (*draw)(void *param, uint32_t cx, uint32_t cy),
|
||||
void *param);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* View context */
|
||||
|
|
Loading…
Reference in a new issue