adjusted the way source removal is handled to make it a bit more safe

This commit is contained in:
jp9000 2013-11-20 18:36:46 -07:00
parent 5fa2f28577
commit f1decd08f4
5 changed files with 47 additions and 31 deletions

View file

@ -33,7 +33,6 @@
/*#include "obs-service.h"*/
#define NUM_TEXTURES 2
#define MAX_CHANNELS 32
struct obs_display {
swapchain_t swap; /* can be NULL if just sound */
@ -65,6 +64,7 @@ struct obs_audio {
audio_t audio;
};
/* user sources, output channels, and displays */
struct obs_data {
DARRAY(struct obs_display*) displays;
DARRAY(struct obs_source*) sources;

View file

@ -17,12 +17,15 @@
#pragma once
/* Maximum number of source channels for output and per display */
#define MAX_CHANNELS 32
#define MODULE_SUCCESS 0
#define MODULE_ERROR -1
#define MODULE_FILENOTFOUND -2
#define MODULE_FUNCTIONNOTFOUND -3
#define MODULE_INCOMPATIBLE_VER -4
#define SOURCE_VIDEO (1<<0)
#define SOURCE_AUDIO (1<<1)
#define SOURCE_ASYNC_VIDEO (1<<2)
#define SOURCE_VIDEO (1<<0) /* Source has video */
#define SOURCE_AUDIO (1<<1) /* Source has audio */
#define SOURCE_ASYNC_VIDEO (1<<2) /* Async video (use with SOURCE_VIDEO) */

View file

@ -192,23 +192,46 @@ static void obs_source_destroy(obs_source_t source)
bfree(source);
}
void obs_source_addref(obs_source_t source)
int obs_source_addref(obs_source_t source)
{
assert(source != NULL);
if (!source)
return;
return 0;
++source->refs;
return ++source->refs;
}
void obs_source_release(obs_source_t source)
int obs_source_release(obs_source_t source)
{
int refs;
assert(source != NULL);
if (!source)
return;
return 0;
if (--source->refs == 0)
refs = --source->refs;
if (refs == 0)
obs_source_destroy(source);
return refs;
}
void obs_source_remove(obs_source_t source)
{
struct obs_data *data = &obs->data;
size_t id;
source->removed = true;
pthread_mutex_lock(&data->sources_mutex);
id = da_find(data->sources, &source, 0);
if (id != DARRAY_INVALID) {
da_erase_item(data->sources, &source);
obs_source_release(source);
}
pthread_mutex_unlock(&data->sources_mutex);
}
bool obs_source_removed(obs_source_t source)

View file

@ -343,23 +343,6 @@ bool obs_add_source(obs_source_t source)
return true;
}
void obs_delete_source(obs_source_t source)
{
struct obs_data *data = &obs->data;
size_t id;
pthread_mutex_lock(&data->sources_mutex);
id = da_find(data->sources, &source, 0);
if (id != DARRAY_INVALID) {
source->removed = true;
da_erase_item(data->sources, &source);
obs_source_release(source);
}
pthread_mutex_unlock(&data->sources_mutex);
}
obs_source_t obs_get_output_source(uint32_t channel)
{
assert(channel < MAX_CHANNELS);

View file

@ -200,14 +200,13 @@ EXPORT graphics_t obs_graphics(void);
EXPORT media_t obs_media(void);
/**
* Adds/removes a source to/from the user source list.
* Adds a source to the user source list.
*
* The user source list is the list of sources that are accessible by a user.
* Typically when a transition is active, it is not meant to be accessible by
* users, so there's no reason for a user to see such a source.
*/
EXPORT bool obs_add_source(obs_source_t source);
EXPORT void obs_delete_source(obs_source_t source);
/** Sets/gets the primary output source for a channel. */
EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
@ -259,8 +258,16 @@ EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
*/
EXPORT obs_source_t obs_source_create(enum obs_source_type type,
const char *name, const char *settings);
EXPORT void obs_source_addref(obs_source_t source);
EXPORT void obs_source_release(obs_source_t source);
/**
* Adds/releases a reference to a source. When the last reference is
* released, the source is destroyed.
*/
EXPORT int obs_source_addref(obs_source_t source);
EXPORT int obs_source_release(obs_source_t source);
/** Nofifies all references that the source should be released */
EXPORT void obs_source_remove(obs_source_t source);
/** Returns true if the source should be released */
EXPORT bool obs_source_removed(obs_source_t source);