Browse Source

made the getframe function a bit more safe and modified a few names for clarity

jp9000 12 years ago
parent
commit
93dd3cec50
3 changed files with 52 additions and 16 deletions
  1. 8 1
      libobs/obs-source.c
  2. 22 5
      libobs/obs.c
  3. 22 10
      libobs/obs.h

+ 8 - 1
libobs/obs-source.c

@@ -850,10 +850,17 @@ struct source_frame *obs_source_getframe(obs_source_t source)
 
 unlock:
 	pthread_mutex_unlock(&source->video_mutex);
+
+	if (frame != NULL)
+		obs_source_addref(source);
+
 	return frame;
 }
 
 void obs_source_releaseframe(obs_source_t source, struct source_frame *frame)
 {
-	source_frame_destroy(frame);
+	if (frame) {
+		source_frame_destroy(frame);
+		obs_source_release(source);
+	}
 }

+ 22 - 5
libobs/obs.c

@@ -291,7 +291,7 @@ bool obs_reset_audio(struct audio_info *ai)
 	return true;
 }
 
-bool obs_enum_inputs(size_t idx, const char **name)
+bool obs_enum_input_types(size_t idx, const char **name)
 {
 	if (idx >= obs->input_types.num)
 		return false;
@@ -299,7 +299,7 @@ bool obs_enum_inputs(size_t idx, const char **name)
 	return true;
 }
 
-bool obs_enum_filters(size_t idx, const char **name)
+bool obs_enum_filter_types(size_t idx, const char **name)
 {
 	if (idx >= obs->filter_types.num)
 		return false;
@@ -307,7 +307,7 @@ bool obs_enum_filters(size_t idx, const char **name)
 	return true;
 }
 
-bool obs_enum_transitions(size_t idx, const char **name)
+bool obs_enum_transition_types(size_t idx, const char **name)
 {
 	if (idx >= obs->transition_types.num)
 		return false;
@@ -315,7 +315,7 @@ bool obs_enum_transitions(size_t idx, const char **name)
 	return true;
 }
 
-bool obs_enum_outputs(size_t idx, const char **name)
+bool obs_enum_output_types(size_t idx, const char **name)
 {
 	if (idx >= obs->output_types.num)
 		return false;
@@ -345,8 +345,12 @@ bool obs_add_source(obs_source_t source)
 
 obs_source_t obs_get_output_source(uint32_t channel)
 {
+	struct obs_source *source;
 	assert(channel < MAX_CHANNELS);
-	return obs->data.channels[channel];
+	source = obs->data.channels[channel];
+
+	obs_source_addref(source);
+	return source;
 }
 
 void obs_set_output_source(uint32_t channel, obs_source_t source)
@@ -362,3 +366,16 @@ void obs_set_output_source(uint32_t channel, obs_source_t source)
 	if (prev_source)
 		obs_source_release(prev_source);
 }
+
+void obs_enum_sources(ENUM_SOURCES_PROC enum_proc, void *param)
+{
+	struct obs_data *data = &obs->data;
+	size_t i;
+
+	pthread_mutex_lock(&data->sources_mutex);
+
+	for (i = 0; i < data->sources.num; i++)
+		enum_proc(data->sources.array[i], param);
+
+	pthread_mutex_unlock(&data->sources_mutex);
+}

+ 22 - 10
libobs/obs.h

@@ -127,6 +127,9 @@ typedef struct obs_scene_item *obs_sceneitem_t;
 typedef struct obs_output     *obs_output_t;
 typedef struct obs_service    *obs_service_t;
 
+/* typedefs */
+typedef void (*ENUM_SOURCES_PROC)(obs_source_t source, void *param);
+
 /* ------------------------------------------------------------------------- */
 /* OBS context */
 
@@ -162,36 +165,36 @@ EXPORT bool obs_reset_audio(struct audio_info *ai);
 EXPORT int obs_load_module(const char *path);
 
 /**
- * Enumerates all available inputs.
+ * Enumerates all available inputs source types.
  *
  *   Inputs are general source inputs (such as capture sources, device sources,
  * etc).
  */
-EXPORT bool obs_enum_inputs(size_t idx, const char **name);
+EXPORT bool obs_enum_input_types(size_t idx, const char **name);
 
 /**
- * Enumerates all available filters.
+ * Enumerates all available filter source types.
  *
  *   Filters are sources that are used to modify the video/audio output of
  * other sources.
  */
-EXPORT bool obs_enum_filters(size_t idx, const char **name);
+EXPORT bool obs_enum_filter_types(size_t idx, const char **name);
 
 /**
- * Enumerates all available transitions.
+ * Enumerates all available transition source types.
  *
  *   Transitions are sources used to transition between two or more other
  * sources.
  */
-EXPORT bool obs_enum_transitions(size_t idx, const char **name);
+EXPORT bool obs_enum_transition_types(size_t idx, const char **name);
 
 /**
- * Enumerates all available ouputs.
+ * Enumerates all available ouput types.
  *
  *   Outputs handle color space conversion, encoding, and output to file or
  * streams.
  */
-EXPORT bool obs_enum_outputs(size_t idx, const char **name);
+EXPORT bool obs_enum_output_types(size_t idx, const char **name);
 
 /** Gets the graphics context for this OBS context */
 EXPORT graphics_t obs_graphics(void);
@@ -200,7 +203,8 @@ EXPORT graphics_t obs_graphics(void);
 EXPORT media_t obs_media(void);
 
 /**
- * Adds a source to the user source list.
+ * Adds a source to the user source list and increments the reference counter
+ * for that source.
  *
  *   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
@@ -208,10 +212,18 @@ EXPORT media_t obs_media(void);
  */
 EXPORT bool obs_add_source(obs_source_t source);
 
-/** Sets/gets the primary output source for a channel. */
+/** Sets the primary output source for a channel. */
 EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
+
+/**
+ * Gets the primary output source for a channel and increments the reference
+ * counter for that source.  Use obs_source_release to release.
+ */
 EXPORT obs_source_t obs_get_output_source(uint32_t channel);
 
+/** Enumerates user sources */
+EXPORT void obs_enum_sources(ENUM_SOURCES_PROC enum_proc, void *param);
+
 /**
  * Returns the location of a plugin data file.
  *