浏览代码

libobs: Don't keep the sources mutex in tick_sources

Allow other threads to use sources while the graphics thread does
video_tick, update, activate and deactivate on sources

(cherry picked from commit a77789b2667388485851605fc3ede805c9fa569f)
Exeldro 2 年之前
父节点
当前提交
59cb2c2185
共有 3 个文件被更改,包括 20 次插入11 次删除
  1. 1 0
      libobs/obs-internal.h
  2. 18 11
      libobs/obs-video.c
  3. 1 0
      libobs/obs.c

+ 1 - 0
libobs/obs-internal.h

@@ -419,6 +419,7 @@ struct obs_core_data {
 	volatile bool valid;
 
 	DARRAY(char *) protocols;
+	DARRAY(obs_source_t *) sources_to_tick;
 };
 
 /* user hotkeys */

+ 18 - 11
libobs/obs-video.c

@@ -45,35 +45,42 @@ static uint64_t tick_sources(uint64_t cur_time, uint64_t last_time)
 	/* ------------------------------------- */
 	/* call tick callbacks                   */
 
-	pthread_mutex_lock(&obs->data.draw_callbacks_mutex);
+	pthread_mutex_lock(&data->draw_callbacks_mutex);
 
-	for (size_t i = obs->data.tick_callbacks.num; i > 0; i--) {
+	for (size_t i = data->tick_callbacks.num; i > 0; i--) {
 		struct tick_callback *callback;
-		callback = obs->data.tick_callbacks.array + (i - 1);
+		callback = data->tick_callbacks.array + (i - 1);
 		callback->tick(callback->param, seconds);
 	}
 
-	pthread_mutex_unlock(&obs->data.draw_callbacks_mutex);
+	pthread_mutex_unlock(&data->draw_callbacks_mutex);
 
 	/* ------------------------------------- */
-	/* call the tick function of each source */
+	/* get an array of all sources to tick   */
+
+	data->sources_to_tick.num = 0;
 
 	pthread_mutex_lock(&data->sources_mutex);
 
 	source = data->sources;
 	while (source) {
 		obs_source_t *s = obs_source_get_ref(source);
-
-		if (s) {
-			obs_source_video_tick(s, seconds);
-			obs_source_release(s);
-		}
-
+		if (s)
+			da_push_back(data->sources_to_tick, &s);
 		source = (struct obs_source *)source->context.hh_uuid.next;
 	}
 
 	pthread_mutex_unlock(&data->sources_mutex);
 
+	/* ------------------------------------- */
+	/* call the tick function of each source */
+
+	for (size_t i = 0; i < data->sources_to_tick.num; i++) {
+		obs_source_t *s = data->sources_to_tick.array[i];
+		obs_source_video_tick(s, seconds);
+		obs_source_release(s);
+	}
+
 	return cur_time;
 }
 

+ 1 - 0
libobs/obs.c

@@ -1083,6 +1083,7 @@ static void obs_free_data(void)
 	for (size_t i = 0; i < data->protocols.num; i++)
 		bfree(data->protocols.array[i]);
 	da_free(data->protocols);
+	da_free(data->sources_to_tick);
 }
 
 static const char *obs_signals[] = {