0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

Add more checks for NULL pointers

This commit is contained in:
jp9000 2014-02-23 22:39:33 -07:00
parent 096cce9a86
commit 268e4e7811
20 changed files with 589 additions and 133 deletions

View File

@ -164,7 +164,7 @@ bool calldata_getdata(calldata_t data, const char *name, void *out, size_t size)
uint8_t *pos;
size_t data_size;
if (!name || !*name)
if (!data || !name || !*name)
return false;
if (!cd_getparam(data, name, &pos))
@ -183,7 +183,7 @@ void calldata_setdata(calldata_t data, const char *name, const void *in,
{
uint8_t *pos;
if (!name || !*name)
if (!data || !name || !*name)
return;
if (!data->stack) {
@ -227,7 +227,7 @@ void calldata_setdata(calldata_t data, const char *name, const void *in,
bool calldata_getstring(calldata_t data, const char *name, const char **str)
{
uint8_t *pos;
if (!name || !*name)
if (!data || !name || !*name)
return false;
if (!cd_getparam(data, name, &pos))

View File

@ -54,6 +54,8 @@ void proc_handler_destroy(proc_handler_t handler)
void proc_handler_add(proc_handler_t handler, const char *name,
proc_handler_proc_t proc, void *data)
{
if (!handler) return;
struct proc_info pi = {bstrdup(name), data, proc};
da_push_back(handler->procs, &pi);
}
@ -61,6 +63,8 @@ void proc_handler_add(proc_handler_t handler, const char *name,
bool proc_handler_call(proc_handler_t handler, const char *name,
calldata_t params)
{
if (!handler) return false;
for (size_t i = 0; i < handler->procs.num; i++) {
struct proc_info *info = handler->procs.array+i;

View File

@ -135,6 +135,9 @@ void signal_handler_connect(signal_handler_t handler, const char *signal,
struct signal_callback cb_data = {callback, data};
size_t idx;
if (!handler)
return;
pthread_mutex_lock(&handler->mutex);
sig = getsignal(handler, signal, &last);
if (!sig) {
@ -166,6 +169,9 @@ static inline struct signal_info *getsignal_locked(signal_handler_t handler,
{
struct signal_info *sig;
if (!handler)
return NULL;
pthread_mutex_lock(&handler->mutex);
sig = getsignal(handler, name, NULL);
pthread_mutex_unlock(&handler->mutex);

View File

@ -31,11 +31,10 @@ void effect_destroy(effect_t effect)
technique_t effect_gettechnique(effect_t effect, const char *name)
{
size_t i;
struct effect_technique *array = effect->techniques.array;
if (!effect) return NULL;
for (i = 0; i < effect->techniques.num; i++) {
struct effect_technique *tech = array+i;
for (size_t i = 0; i < effect->techniques.num; i++) {
struct effect_technique *tech = effect->techniques.array+i;
if (strcmp(tech->name, name) == 0)
return tech;
}
@ -45,6 +44,8 @@ technique_t effect_gettechnique(effect_t effect, const char *name)
size_t technique_begin(technique_t tech)
{
if (!tech) return 0;
tech->effect->cur_technique = tech;
tech->effect->graphics->cur_effect = tech->effect;
@ -53,6 +54,8 @@ size_t technique_begin(technique_t tech)
void technique_end(technique_t tech)
{
if (!tech) return;
struct gs_effect *effect = tech->effect;
struct effect_param *params = effect->params.array;
size_t i;
@ -127,7 +130,8 @@ static inline void upload_parameters(struct gs_effect *effect,
void effect_updateparams(effect_t effect)
{
upload_parameters(effect, true);
if (effect)
upload_parameters(effect, true);
}
bool technique_beginpass(technique_t tech, size_t idx)
@ -135,7 +139,7 @@ bool technique_beginpass(technique_t tech, size_t idx)
struct effect_pass *passes;
struct effect_pass *cur_pass;
if (idx >= tech->passes.num)
if (!tech || idx >= tech->passes.num)
return false;
passes = tech->passes.array;
@ -152,8 +156,10 @@ bool technique_beginpass(technique_t tech, size_t idx)
bool technique_beginpassbyname(technique_t tech,
const char *name)
{
size_t i;
for (i = 0; i < tech->passes.num; i++) {
if (!tech)
return false;
for (size_t i = 0; i < tech->passes.num; i++) {
struct effect_pass *pass = tech->passes.array+i;
if (strcmp(pass->name, name) == 0) {
technique_beginpass(tech, i);
@ -167,9 +173,8 @@ bool technique_beginpassbyname(technique_t tech,
static inline void clear_tex_params(shader_t shader, struct darray *in_params)
{
struct pass_shaderparam *params = in_params->array;
size_t i;
for (i = 0; i < in_params->num; i++) {
for (size_t i = 0; i < in_params->num; i++) {
struct pass_shaderparam *param = params+i;
struct shader_param_info info;
@ -181,6 +186,8 @@ static inline void clear_tex_params(shader_t shader, struct darray *in_params)
void technique_endpass(technique_t tech)
{
if (!tech) return;
struct effect_pass *pass = tech->effect->cur_pass;
if (!pass)
return;
@ -192,13 +199,14 @@ void technique_endpass(technique_t tech)
size_t effect_numparams(effect_t effect)
{
return effect->params.num;
return effect ? effect->params.num : 0;
}
eparam_t effect_getparambyidx(effect_t effect, size_t param)
{
struct effect_param *params = effect->params.array;
if (!effect) return NULL;
struct effect_param *params = effect->params.array;
if (param >= effect->params.num)
return NULL;
@ -207,10 +215,11 @@ eparam_t effect_getparambyidx(effect_t effect, size_t param)
eparam_t effect_getparambyname(effect_t effect, const char *name)
{
struct effect_param *params = effect->params.array;
size_t i;
if (!effect) return NULL;
for (i = 0; i < effect->params.num; i++) {
struct effect_param *params = effect->params.array;
for (size_t i = 0; i < effect->params.num; i++) {
struct effect_param *param = params+i;
if (strcmp(param->name, name) == 0)
@ -233,6 +242,9 @@ static inline bool matching_effect(effect_t effect, eparam_t param)
void effect_getparaminfo(effect_t effect, eparam_t param,
struct effect_param_info *info)
{
if (!effect || !param)
return;
if (!matching_effect(effect, param))
return;
@ -242,12 +254,12 @@ void effect_getparaminfo(effect_t effect, eparam_t param,
eparam_t effect_getviewprojmatrix(effect_t effect)
{
return effect->view_proj;
return effect ? effect->view_proj : NULL;
}
eparam_t effect_getworldmatrix(effect_t effect)
{
return effect->world;
return effect ? effect->world : NULL;
}
static inline void effect_setval_inline(effect_t effect, eparam_t param,

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,9 @@ void texrender_destroy(texrender_t texrender)
static bool texrender_resetbuffer(texrender_t texrender, uint32_t cx,
uint32_t cy)
{
if (!texrender)
return false;
texture_destroy(texrender->target);
zstencil_destroy(texrender->zs);
@ -86,7 +89,7 @@ static bool texrender_resetbuffer(texrender_t texrender, uint32_t cx,
bool texrender_begin(texrender_t texrender, uint32_t cx, uint32_t cy)
{
if (texrender->rendered)
if (!texrender || texrender->rendered)
return false;
if (cx == 0)
@ -118,6 +121,9 @@ bool texrender_begin(texrender_t texrender, uint32_t cx, uint32_t cy)
void texrender_end(texrender_t texrender)
{
if (!texrender)
return;
gs_setrendertarget(texrender->prev_target, texrender->prev_zs);
gs_matrix_pop();
@ -129,10 +135,11 @@ void texrender_end(texrender_t texrender)
void texrender_reset(texrender_t texrender)
{
texrender->rendered = false;
if (texrender)
texrender->rendered = false;
}
texture_t texrender_gettexture(texrender_t texrender)
{
return texrender->target;
return texrender ? texrender->target : NULL;
}

View File

@ -503,6 +503,8 @@ bool audio_output_connect(audio_t audio,
{
bool success = false;
if (!audio) return false;
pthread_mutex_lock(&audio->input_mutex);
if (audio_get_input_idx(audio, callback, param) == DARRAY_INVALID) {
@ -541,6 +543,8 @@ void audio_output_disconnect(audio_t audio,
void (*callback)(void *param, const struct audio_data *data),
void *param)
{
if (!audio) return;
pthread_mutex_lock(&audio->input_mutex);
size_t idx = audio_get_input_idx(audio, callback, param);
@ -632,6 +636,8 @@ void audio_output_close(audio_t audio)
audio_line_t audio_output_createline(audio_t audio, const char *name)
{
if (!audio) return NULL;
struct audio_line *line = bzalloc(sizeof(struct audio_line));
line->alive = true;
line->audio = audio;
@ -661,7 +667,7 @@ audio_line_t audio_output_createline(audio_t audio, const char *name)
const struct audio_output_info *audio_output_getinfo(audio_t audio)
{
return &audio->info;
return audio ? &audio->info : NULL;
}
void audio_line_destroy(struct audio_line *line)
@ -682,17 +688,17 @@ bool audio_output_active(audio_t audio)
size_t audio_output_blocksize(audio_t audio)
{
return audio->block_size;
return audio ? audio->block_size : 0;
}
size_t audio_output_planes(audio_t audio)
{
return audio->planes;
return audio ? audio->planes : 0;
}
size_t audio_output_channels(audio_t audio)
{
return audio->channels;
return audio ? audio->channels : 0;
}
/* TODO: Optimization of volume multiplication functions */
@ -812,7 +818,7 @@ static void audio_line_place_data_pos(struct audio_line *line,
}
}
void audio_line_place_data(struct audio_line *line,
static void audio_line_place_data(struct audio_line *line,
const struct audio_data *data)
{
size_t pos = ts_diff_bytes(line->audio, data->timestamp,
@ -834,6 +840,8 @@ void audio_line_output(audio_line_t line, const struct audio_data *data)
/* TODO: prevent insertation of data too far away from expected
* audio timing */
if (!line || !data) return;
pthread_mutex_lock(&line->mutex);
if (!line->buffers[0].size) {

View File

@ -132,6 +132,8 @@ bool audio_resampler_resample(audio_resampler_t rs,
uint8_t *output[], uint32_t *out_frames, uint64_t *ts_offset,
const uint8_t *const input[], uint32_t in_frames)
{
if (!rs) return false;
struct SwrContext *context = rs->context;
int ret;

View File

@ -28,6 +28,8 @@ void video_frame_init(struct video_frame *frame, enum video_format format,
size_t offsets[MAX_AV_PLANES];
int alignment = base_get_alignment();
if (!frame) return;
memset(frame, 0, sizeof(struct video_frame));
memset(offsets, 0, sizeof(offsets));

View File

@ -261,6 +261,9 @@ bool video_output_connect(video_t video,
{
bool success = false;
if (!video || !callback)
return false;
pthread_mutex_lock(&video->input_mutex);
if (video_get_input_idx(video, callback, param) == DARRAY_INVALID) {
@ -297,6 +300,9 @@ void video_output_disconnect(video_t video,
void (*callback)(void *param, const struct video_data *frame),
void *param)
{
if (!video || !callback)
return;
pthread_mutex_lock(&video->input_mutex);
size_t idx = video_get_input_idx(video, callback, param);
@ -316,11 +322,13 @@ bool video_output_active(video_t video)
const struct video_output_info *video_output_getinfo(video_t video)
{
return &video->info;
return video ? &video->info : NULL;
}
void video_output_swap_frame(video_t video, struct video_data *frame)
{
if (!video) return;
pthread_mutex_lock(&video->data_mutex);
video->next_frame = *frame;
video->new_frame = true;
@ -329,18 +337,20 @@ void video_output_swap_frame(video_t video, struct video_data *frame)
bool video_output_wait(video_t video)
{
if (!video) return false;
event_wait(&video->update_event);
return event_try(&video->stop_event) == EAGAIN;
}
uint64_t video_getframetime(video_t video)
{
return video->frame_time;
return video ? video->frame_time : 0;
}
uint64_t video_gettime(video_t video)
{
return video->cur_video_time;
return video ? video->cur_video_time : 0;
}
void video_output_stop(video_t video)

View File

@ -264,8 +264,7 @@ static inline void obs_data_destroy(struct obs_data *data)
void obs_data_release(obs_data_t data)
{
if (!data)
return;
if (!data) return;
if (--data->ref == 0)
obs_data_destroy(data);
@ -273,6 +272,8 @@ void obs_data_release(obs_data_t data)
const char *obs_data_getjson(obs_data_t data)
{
if (!data) return NULL;
/* TODO */
#pragma message ("TODO: implement obs_data_getjson")
return data->json;
@ -280,8 +281,7 @@ const char *obs_data_getjson(obs_data_t data)
static struct obs_data_item *get_item(struct obs_data *data, const char *name)
{
if (!data)
return NULL;
if (!data) return NULL;
struct obs_data_item *item = data->first_item;
@ -298,6 +298,9 @@ static struct obs_data_item *get_item(struct obs_data *data, const char *name)
static inline struct obs_data_item *get_item_of(struct obs_data *data,
const char *name, enum obs_data_type type)
{
if (!data)
return NULL;
struct obs_data_item *item = get_item(data, name);
return (item && item->type == type) ? item : NULL;
}
@ -495,10 +498,12 @@ void obs_data_array_addref(obs_data_array_t array)
static inline void obs_data_array_destroy(obs_data_array_t array)
{
for (size_t i = 0; i < array->objects.num; i++)
obs_data_release(array->objects.array[i]);
da_free(array->objects);
bfree(array);
if (array) {
for (size_t i = 0; i < array->objects.num; i++)
obs_data_release(array->objects.array[i]);
da_free(array->objects);
bfree(array);
}
}
void obs_data_array_release(obs_data_array_t array)
@ -512,12 +517,16 @@ void obs_data_array_release(obs_data_array_t array)
size_t obs_data_array_count(obs_data_array_t array)
{
return array->objects.num;
return array ? array->objects.num : 0;
}
obs_data_t obs_data_array_item(obs_data_array_t array, size_t idx)
{
obs_data_t data;
if (!array)
return NULL;
data = (idx < array->objects.num) ? array->objects.array[idx] : NULL;
if (data)
@ -527,20 +536,28 @@ obs_data_t obs_data_array_item(obs_data_array_t array, size_t idx)
size_t obs_data_array_push_back(obs_data_array_t array, obs_data_t obj)
{
if (!array || !obj)
return 0;
obj->ref++;
return da_push_back(array->objects, &obj);
}
void obs_data_array_insert(obs_data_array_t array, size_t idx, obs_data_t obj)
{
if (!array || !obj)
return;
obj->ref++;
da_insert(array->objects, idx, &obj);
}
void obs_data_array_erase(obs_data_array_t array, size_t idx)
{
obs_data_release(array->objects.array[idx]);
da_erase(array->objects, idx);
if (array) {
obs_data_release(array->objects.array[idx]);
da_erase(array->objects, idx);
}
}
/* ------------------------------------------------------------------------- */
@ -548,6 +565,9 @@ void obs_data_array_erase(obs_data_array_t array, size_t idx)
obs_data_item_t obs_data_first(obs_data_t data)
{
if (!data)
return NULL;
if (data->first_item)
data->first_item->ref++;
return data->first_item;
@ -555,6 +575,9 @@ obs_data_item_t obs_data_first(obs_data_t data)
obs_data_item_t obs_data_item_byname(obs_data_t data, const char *name)
{
if (!data)
return NULL;
struct obs_data_item *item = get_item(data, name);
if (item)
item->ref++;
@ -597,7 +620,7 @@ void obs_data_item_remove(obs_data_item_t *item)
enum obs_data_type obs_data_item_gettype(obs_data_item_t item)
{
return item->type;
return item ? item->type : OBS_DATA_NULL;
}
void obs_data_item_setstring(obs_data_item_t *item, const char *val)

View File

@ -135,6 +135,11 @@ void obs_register_source(const struct obs_source_info *info)
struct obs_source_info data = {0};
struct darray *array;
if (!info) {
blog(LOG_WARNING, "obs_register_source: NULL info");
return;
}
if (!cur_source_info_size) {
blog(LOG_WARNING, "Tried to register obs_source_info"
" outside of obs_module_load");

View File

@ -58,19 +58,15 @@ char *find_plugin(const char *plugin)
struct dstr output;
dstr_init(&output);
if(sizeof(void*) == 4)
{
if(sizeof(void*) == 4) {
if (check_lib_path(plugin, "../../obs-plugins/32bit/", &output))
return output.array;
}
else
{
} else {
if (check_lib_path(plugin, "../../obs-plugins/64bit/", &output))
return output.array;
}
if (OBS_INSTALL_PREFIX [0] != 0)
{
if (OBS_INSTALL_PREFIX [0] != 0) {
if (check_lib_path(plugin,
OBS_INSTALL_PREFIX "lib/obs-plugins/",
&output))
@ -93,8 +89,7 @@ char *find_libobs_data_file(const char *file)
if (check_path(file, OBS_DATA_PATH "/libobs/", &output))
return output.array;
if (OBS_INSTALL_PREFIX [0] != 0)
{
if (OBS_INSTALL_PREFIX [0] != 0) {
if (check_path(file, OBS_INSTALL_DATA_PATH "/libobs/",
&output))
return output.array;
@ -116,8 +111,7 @@ char *obs_find_plugin_file(const char *file)
if (check_path(file, OBS_DATA_PATH "/obs-plugins/", &output))
return output.array;
if (OBS_INSTALL_PREFIX [0] != 0)
{
if (OBS_INSTALL_PREFIX [0] != 0) {
if (check_path(file, OBS_INSTALL_DATA_PATH "/obs-plugins/",
&output))
return output.array;

View File

@ -79,17 +79,18 @@ void obs_output_destroy(obs_output_t output)
bool obs_output_start(obs_output_t output)
{
return output->info.start(output->data);
return (output != NULL) ? output->info.start(output->data) : false;
}
void obs_output_stop(obs_output_t output)
{
output->info.stop(output->data);
if (output)
output->info.stop(output->data);
}
bool obs_output_active(obs_output_t output)
{
return output->info.active(output);
return (output != NULL) ? output->info.active(output) : false;
}
obs_properties_t obs_output_properties(const char *id, const char *locale)
@ -102,6 +103,8 @@ obs_properties_t obs_output_properties(const char *id, const char *locale)
void obs_output_update(obs_output_t output, obs_data_t settings)
{
if (!output) return;
obs_data_apply(output->settings, settings);
if (output->info.update)
@ -119,11 +122,11 @@ obs_data_t obs_output_get_settings(obs_output_t output)
bool obs_output_canpause(obs_output_t output)
{
return output->info.pause != NULL;
return (output != NULL) ? output->info.pause != NULL : false;
}
void obs_output_pause(obs_output_t output)
{
if (output->info.pause)
if (output && output->info.pause)
output->info.pause(output->data);
}

View File

@ -76,19 +76,23 @@ static void obs_category_destroy(struct obs_category *category)
void obs_properties_destroy(obs_properties_t props)
{
struct obs_category *c = props->first_category;
while (c) {
struct obs_category *next = c->next;
obs_category_destroy(c);
c = next;
}
if (props) {
struct obs_category *c = props->first_category;
while (c) {
struct obs_category *next = c->next;
obs_category_destroy(c);
c = next;
}
bfree(props);
bfree(props);
}
}
obs_category_t obs_properties_add_category(obs_properties_t props,
const char *name)
{
if (!props) return NULL;
struct obs_category *c = bzalloc(sizeof(struct obs_category));
c->name = name;
c->next = props->first_category;
@ -99,7 +103,7 @@ obs_category_t obs_properties_add_category(obs_properties_t props,
obs_category_t obs_properties_first_category(obs_properties_t props)
{
return props->first_category;
return (props != NULL) ? props->first_category : NULL;
}
/* ------------------------------------------------------------------------- */
@ -160,6 +164,8 @@ static inline void *get_type_data(struct obs_property *prop,
void obs_category_add_int(obs_category_t cat, const char *name,
const char *desc, int min, int max, int step)
{
if (!cat) return;
struct obs_property *p = new_prop(cat, name, desc, OBS_PROPERTY_INT);
struct int_data *data = get_property_data(p);
data->min = min;
@ -170,6 +176,8 @@ void obs_category_add_int(obs_category_t cat, const char *name,
void obs_category_add_float(obs_category_t cat, const char *name,
const char *desc, double min, double max, double step)
{
if (!cat) return;
struct obs_property *p = new_prop(cat, name, desc, OBS_PROPERTY_FLOAT);
struct float_data *data = get_property_data(p);
data->min = min;
@ -180,18 +188,22 @@ void obs_category_add_float(obs_category_t cat, const char *name,
void obs_category_add_text(obs_category_t cat, const char *name,
const char *desc)
{
if (!cat) return;
new_prop(cat, name, desc, OBS_PROPERTY_TEXT);
}
void obs_category_add_path(obs_category_t cat, const char *name,
const char *desc)
{
if (!cat) return;
new_prop(cat, name, desc, OBS_PROPERTY_PATH);
}
void obs_category_add_enum_list(obs_category_t cat, const char *name,
const char *desc, const char **strings)
{
if (!cat) return;
struct obs_property *p = new_prop(cat, name, desc, OBS_PROPERTY_ENUM);
struct list_data *data = get_property_data(p);
data->strings = strings;
@ -202,6 +214,8 @@ void obs_category_add_text_list(obs_category_t cat, const char *name,
const char *desc, const char **strings,
enum obs_dropdown_type type)
{
if (!cat) return;
struct obs_property *p = new_prop(cat, name, desc,
OBS_PROPERTY_TEXT_LIST);
struct list_data *data = get_property_data(p);
@ -212,6 +226,7 @@ void obs_category_add_text_list(obs_category_t cat, const char *name,
void obs_category_add_color(obs_category_t cat, const char *name,
const char *desc)
{
if (!cat) return;
new_prop(cat, name, desc, OBS_PROPERTY_COLOR);
}
@ -245,17 +260,17 @@ bool obs_property_next(obs_property_t *p)
const char *obs_property_name(obs_property_t p)
{
return p->name;
return p ? p->name : NULL;
}
const char *obs_property_description(obs_property_t p)
{
return p->desc;
return p ? p->desc : NULL;
}
enum obs_property_type obs_property_type(obs_property_t p)
{
return p->type;
return p ? p->type : OBS_PROPERTY_INVALID;
}
int obs_property_int_min(obs_property_t p)

View File

@ -244,7 +244,7 @@ obs_source_t obs_scene_getsource(obs_scene_t scene)
obs_scene_t obs_scene_fromsource(obs_source_t source)
{
if (source->info.type != OBS_SOURCE_TYPE_SCENE)
if (!source || source->info.type != OBS_SOURCE_TYPE_SCENE)
return NULL;
return source->data;
@ -254,6 +254,9 @@ obs_sceneitem_t obs_scene_findsource(obs_scene_t scene, const char *name)
{
struct obs_scene_item *item;
if (!scene)
return NULL;
pthread_mutex_lock(&scene->mutex);
item = scene->first_item;
@ -275,6 +278,9 @@ void obs_scene_enum_items(obs_scene_t scene,
{
struct obs_scene_item *item;
if (!scene || !callback)
return;
pthread_mutex_lock(&scene->mutex);
item = scene->first_item;
@ -397,36 +403,42 @@ void obs_sceneitem_remove(obs_sceneitem_t item)
obs_scene_t obs_sceneitem_getscene(obs_sceneitem_t item)
{
return item->parent;
return item ? item->parent : NULL;
}
obs_source_t obs_sceneitem_getsource(obs_sceneitem_t item)
{
return item->source;
return item ? item->source : NULL;
}
void obs_sceneitem_setpos(obs_sceneitem_t item, const struct vec2 *pos)
{
vec2_copy(&item->pos, pos);
if (item)
vec2_copy(&item->pos, pos);
}
void obs_sceneitem_setrot(obs_sceneitem_t item, float rot)
{
item->rot = rot;
if (item)
item->rot = rot;
}
void obs_sceneitem_setorigin(obs_sceneitem_t item, const struct vec2 *origin)
{
vec2_copy(&item->origin, origin);
if (item)
vec2_copy(&item->origin, origin);
}
void obs_sceneitem_setscale(obs_sceneitem_t item, const struct vec2 *scale)
{
vec2_copy(&item->scale, scale);
if (item)
vec2_copy(&item->scale, scale);
}
void obs_sceneitem_setorder(obs_sceneitem_t item, enum order_movement movement)
{
if (!item) return;
struct obs_scene *scene = item->parent;
obs_scene_addref(scene);
@ -461,20 +473,23 @@ void obs_sceneitem_setorder(obs_sceneitem_t item, enum order_movement movement)
void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos)
{
vec2_copy(pos, &item->pos);
if (item)
vec2_copy(pos, &item->pos);
}
float obs_sceneitem_getrot(obs_sceneitem_t item)
{
return item->rot;
return item ? item->rot : 0.0f;
}
void obs_sceneitem_getorigin(obs_sceneitem_t item, struct vec2 *origin)
{
vec2_copy(origin, &item->origin);
if (item)
vec2_copy(origin, &item->origin);
}
void obs_sceneitem_getscale(obs_sceneitem_t item, struct vec2 *scale)
{
vec2_copy(scale, &item->scale);
if (item)
vec2_copy(scale, &item->scale);
}

View File

@ -175,6 +175,10 @@ void source_frame_init(struct source_frame *frame, enum video_format format,
uint32_t width, uint32_t height)
{
struct video_frame vid_frame;
if (!frame)
return;
video_frame_init(&vid_frame, format, width, height);
frame->format = format;
frame->width = width;
@ -190,6 +194,9 @@ static void obs_source_destroy(struct obs_source *source)
{
size_t i;
if (!source)
return;
obs_source_dosignal(source, "source-destroy", "destroy");
if (source->filter_parent)
@ -250,8 +257,10 @@ void obs_source_remove(obs_source_t source)
pthread_mutex_lock(&data->sources_mutex);
if (!source || source->removed)
if (!source || source->removed) {
pthread_mutex_unlock(&data->sources_mutex);
return;
}
source->removed = true;
@ -271,7 +280,7 @@ void obs_source_remove(obs_source_t source)
bool obs_source_removed(obs_source_t source)
{
return source->removed;
return source ? source->removed : true;
}
obs_properties_t obs_source_properties(enum obs_source_type type,
@ -285,11 +294,13 @@ obs_properties_t obs_source_properties(enum obs_source_type type,
uint32_t obs_source_get_output_flags(obs_source_t source)
{
return source->info.output_flags;
return source ? source->info.output_flags : 0;
}
void obs_source_update(obs_source_t source, obs_data_t settings)
{
if (!source) return;
obs_data_apply(source->settings, settings);
if (source->info.update)
@ -399,6 +410,8 @@ void obs_source_deactivate(obs_source_t source, enum view_type type)
void obs_source_video_tick(obs_source_t source, float seconds)
{
if (!source) return;
/* reset the filter render texture information once every frame */
if (source->filter_texrender)
texrender_reset(source->filter_texrender);
@ -655,6 +668,8 @@ static inline void obs_source_main_render(obs_source_t source)
void obs_source_video_render(obs_source_t source)
{
if (!source) return;
if (source->info.video_render) {
if (source->filters.num && !source->rendering_filter)
obs_source_render_filters(source);
@ -671,30 +686,33 @@ void obs_source_video_render(obs_source_t source)
uint32_t obs_source_getwidth(obs_source_t source)
{
if (source->info.getwidth)
if (source && source->info.getwidth)
return source->info.getwidth(source->data);
return 0;
}
uint32_t obs_source_getheight(obs_source_t source)
{
if (source->info.getheight)
if (source && source->info.getheight)
return source->info.getheight(source->data);
return 0;
}
obs_source_t obs_filter_getparent(obs_source_t filter)
{
return filter->filter_parent;
return filter ? filter->filter_parent : NULL;
}
obs_source_t obs_filter_gettarget(obs_source_t filter)
{
return filter->filter_target;
return filter ? filter->filter_target : NULL;
}
void obs_source_filter_add(obs_source_t source, obs_source_t filter)
{
if (!source || !filter)
return;
pthread_mutex_lock(&source->filter_mutex);
if (da_find(source->filters, &filter, 0) != DARRAY_INVALID) {
@ -720,6 +738,9 @@ void obs_source_filter_remove(obs_source_t source, obs_source_t filter)
{
size_t idx;
if (!source || !filter)
return;
pthread_mutex_lock(&source->filter_mutex);
idx = da_find(source->filters, &filter, 0);
@ -742,8 +763,12 @@ void obs_source_filter_remove(obs_source_t source, obs_source_t filter)
void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
enum order_movement movement)
{
size_t idx = da_find(source->filters, &filter, 0);
size_t i;
size_t idx, i;
if (!source || !filter)
return;
idx = da_find(source->filters, &filter, 0);
if (idx == DARRAY_INVALID)
return;
@ -778,6 +803,8 @@ void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
obs_data_t obs_source_getsettings(obs_source_t source)
{
if (!source) return NULL;
obs_data_addref(source->settings);
return source->settings;
}
@ -863,6 +890,9 @@ static inline struct source_frame *cache_video(const struct source_frame *frame)
void obs_source_output_video(obs_source_t source,
const struct source_frame *frame)
{
if (!source || !frame)
return;
struct source_frame *output = cache_video(frame);
pthread_mutex_lock(&source->filter_mutex);
@ -982,9 +1012,13 @@ static void process_audio(obs_source_t source, const struct source_audio *audio)
void obs_source_output_audio(obs_source_t source,
const struct source_audio *audio)
{
uint32_t flags = source->info.output_flags;
uint32_t flags;
struct filtered_audio *output;
if (!source || !audio)
return;
flags = source->info.output_flags;
process_audio(source, audio);
pthread_mutex_lock(&source->filter_mutex);
@ -1074,6 +1108,9 @@ struct source_frame *obs_source_getframe(obs_source_t source)
int audio_time_refs = 0;
uint64_t sys_time;
if (!source)
return NULL;
pthread_mutex_lock(&source->video_mutex);
if (!source->video_frames.num)
@ -1110,7 +1147,7 @@ unlock:
void obs_source_releaseframe(obs_source_t source, struct source_frame *frame)
{
if (frame) {
if (source && frame) {
source_frame_destroy(frame);
obs_source_release(source);
}
@ -1118,11 +1155,13 @@ void obs_source_releaseframe(obs_source_t source, struct source_frame *frame)
const char *obs_source_getname(obs_source_t source)
{
return source->name;
return source ? source->name : NULL;
}
void obs_source_setname(obs_source_t source, const char *name)
{
if (!source) return;
bfree(source->name);
source->name = bstrdup(name);
}
@ -1130,6 +1169,8 @@ void obs_source_setname(obs_source_t source, const char *name)
void obs_source_gettype(obs_source_t source, enum obs_source_type *type,
const char **id)
{
if (!source) return;
if (type) *type = source->info.type;
if (id) *id = source->info.id;
}
@ -1173,15 +1214,22 @@ void obs_source_process_filter(obs_source_t filter, effect_t effect,
uint32_t width, uint32_t height, enum gs_color_format format,
enum allow_direct_render allow_direct)
{
obs_source_t target = obs_filter_gettarget(filter);
obs_source_t parent = obs_filter_getparent(filter);
uint32_t target_flags = target->info.output_flags;
uint32_t parent_flags = parent->info.output_flags;
int cx = obs_source_getwidth(target);
int cy = obs_source_getheight(target);
bool use_matrix = !!(target_flags & OBS_SOURCE_COLOR_MATRIX);
bool expects_def = !(parent_flags & OBS_SOURCE_CUSTOM_DRAW);
bool can_directly = allow_direct == ALLOW_DIRECT_RENDERING;
obs_source_t target, parent;
uint32_t target_flags, parent_flags;
int cx, cy;
bool use_matrix, expects_def, can_directly;
if (!filter) return;
target = obs_filter_gettarget(filter);
parent = obs_filter_getparent(filter);
target_flags = target->info.output_flags;
parent_flags = parent->info.output_flags;
cx = obs_source_getwidth(target);
cy = obs_source_getheight(target);
use_matrix = !!(target_flags & OBS_SOURCE_COLOR_MATRIX);
expects_def = !(parent_flags & OBS_SOURCE_CUSTOM_DRAW);
can_directly = allow_direct == ALLOW_DIRECT_RENDERING;
/* if the parent does not use any custom effects, and this is the last
* filter in the chain for the parent, then render the parent directly
@ -1213,7 +1261,7 @@ void obs_source_process_filter(obs_source_t filter, effect_t effect,
signal_handler_t obs_source_signalhandler(obs_source_t source)
{
return source->signals;
return source ? source->signals : NULL;
}
proc_handler_t obs_source_prochandler(obs_source_t source)

View File

@ -236,7 +236,6 @@ static inline void render_video(struct obs_core_video *video, int cur_texture,
gs_endscene();
}
/* TODO: replace with more optimal conversion */
static inline bool download_frame(struct obs_core_video *video,
int prev_texture, struct video_data *frame)
{

View File

@ -20,6 +20,8 @@
bool obs_view_init(struct obs_view *view)
{
if (!view) return false;
pthread_mutex_init_value(&view->channels_mutex);
if (pthread_mutex_init(&view->channels_mutex, NULL) != 0) {
@ -44,6 +46,8 @@ obs_view_t obs_view_create(void)
void obs_view_free(struct obs_view *view)
{
if (!view) return;
for (size_t i = 0; i < MAX_CHANNELS; i++)
obs_source_release(view->channels[i]);

View File

@ -430,7 +430,7 @@ bool obs_startup(void)
bool success;
if (obs) {
blog(LOG_ERROR, "Tried to call obs_startup more than once");
blog(LOG_WARNING, "Tried to call obs_startup more than once");
return false;
}
@ -443,8 +443,6 @@ bool obs_startup(void)
void obs_shutdown(void)
{
size_t i;
if (!obs)
return;
@ -465,7 +463,7 @@ void obs_shutdown(void)
proc_handler_destroy(obs->procs);
signal_handler_destroy(obs->signals);
for (i = 0; i < obs->modules.num; i++)
for (size_t i = 0; i < obs->modules.num; i++)
free_module(obs->modules.array+i);
da_free(obs->modules);
@ -559,6 +557,8 @@ bool obs_get_audio_info(struct audio_output_info *aoi)
bool obs_enum_input_types(size_t idx, const char **id)
{
if (!obs) return false;
if (idx >= obs->input_types.num)
return false;
*id = obs->input_types.array[idx].id;
@ -567,6 +567,8 @@ bool obs_enum_input_types(size_t idx, const char **id)
bool obs_enum_filter_types(size_t idx, const char **id)
{
if (!obs) return false;
if (idx >= obs->filter_types.num)
return false;
*id = obs->filter_types.array[idx].id;
@ -575,6 +577,8 @@ bool obs_enum_filter_types(size_t idx, const char **id)
bool obs_enum_transition_types(size_t idx, const char **id)
{
if (!obs) return false;
if (idx >= obs->transition_types.num)
return false;
*id = obs->transition_types.array[idx].id;
@ -583,6 +587,8 @@ bool obs_enum_transition_types(size_t idx, const char **id)
bool obs_enum_output_types(size_t idx, const char **id)
{
if (!obs) return false;
if (idx >= obs->output_types.num)
return false;
*id = obs->output_types.array[idx].id;
@ -642,6 +648,8 @@ int obs_exec_ui(const char *name, const char *task, const char *target,
struct obs_modal_ui *callback;
int errorcode = OBS_UI_NOTFOUND;
if (!obs) return errorcode;
callback = get_modal_ui_callback(name, task, target);
if (callback) {
bool success = callback->exec(data, ui_data);
@ -656,6 +664,8 @@ void *obs_create_ui(const char *name, const char *task, const char *target,
{
struct obs_modeless_ui *callback;
if (!obs) return NULL;
callback = get_modeless_ui_callback(name, task, target);
return callback ? callback->create(data, ui_data) : NULL;
}
@ -664,6 +674,8 @@ bool obs_add_source(obs_source_t source)
{
struct calldata params = {0};
if (!obs) return false;
pthread_mutex_lock(&obs->data.sources_mutex);
da_push_back(obs->data.sources, &source);
obs_source_addref(source);
@ -678,6 +690,7 @@ bool obs_add_source(obs_source_t source)
obs_source_t obs_get_output_source(uint32_t channel)
{
if (!obs) return NULL;
return obs_view_getsource(&obs->data.main_view, channel);
}
@ -722,6 +735,8 @@ void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t), void *param)
{
struct obs_core_data *data = &obs->data;
if (!obs) return;
pthread_mutex_lock(&data->outputs_mutex);
for (size_t i = 0; i < data->outputs.num; i++)
@ -735,6 +750,8 @@ void obs_enum_encoders(bool (*enum_proc)(void*, obs_encoder_t), void *param)
{
struct obs_core_data *data = &obs->data;
if (!obs) return;
pthread_mutex_lock(&data->encoders_mutex);
for (size_t i = 0; i < data->encoders.num; i++)
@ -748,6 +765,8 @@ void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t), void *param)
{
struct obs_core_data *data = &obs->data;
if (!obs) return;
pthread_mutex_lock(&data->sources_mutex);
for (size_t i = 0; i < data->sources.num; i++)
@ -763,6 +782,8 @@ obs_source_t obs_get_source_by_name(const char *name)
struct obs_source *source = NULL;
size_t i;
if (!obs) return NULL;
pthread_mutex_lock(&data->sources_mutex);
for (i = 0; i < data->sources.num; i++) {
@ -829,6 +850,7 @@ void obs_render_main_view(void)
void obs_set_master_volume(float volume)
{
struct calldata data = {0};
if (!obs) return;
calldata_setfloat(&data, "volume", volume);