Browse Source

libobs: Fix texture-based encoder decklock

Ensures that there are no textures being encoded before attempting to
shut down a texture-based encoder.
jp9000 6 years ago
parent
commit
b029453d30
3 changed files with 15 additions and 0 deletions
  1. 1 0
      libobs/obs-internal.h
  2. 12 0
      libobs/obs-video-gpu-encode.c
  3. 2 0
      libobs/obs.c

+ 1 - 0
libobs/obs-internal.h

@@ -271,6 +271,7 @@ struct obs_core_video {
 	struct circlebuf                gpu_encoder_avail_queue;
 	DARRAY(obs_encoder_t *)         gpu_encoders;
 	os_sem_t                        *gpu_encode_semaphore;
+	os_event_t                      *gpu_encode_inactive;
 	pthread_t                       gpu_encode_thread;
 	bool                            gpu_encode_thread_initialized;
 	volatile bool                   gpu_encode_stop;

+ 12 - 0
libobs/obs-video-gpu-encode.c

@@ -44,6 +44,8 @@ static void *gpu_encode_thread(void *unused)
 			continue;
 		}
 
+		os_event_reset(video->gpu_encode_inactive);
+
 		/* -------------- */
 
 		pthread_mutex_lock(&video->gpu_encoder_mutex);
@@ -128,6 +130,8 @@ static void *gpu_encode_thread(void *unused)
 		}
 
 		pthread_mutex_unlock(&video->gpu_encoder_mutex);
+
+		os_event_signal(video->gpu_encode_inactive);
 	}
 
 	da_free(encoders);
@@ -168,10 +172,14 @@ bool init_gpu_encoding(struct obs_core_video *video)
 
 	if (os_sem_init(&video->gpu_encode_semaphore, 0) != 0)
 		return false;
+	if (os_event_init(&video->gpu_encode_inactive, OS_EVENT_TYPE_MANUAL) != 0)
+		return false;
 	if (pthread_create(&video->gpu_encode_thread, NULL,
 				gpu_encode_thread, NULL) != 0)
 		return false;
 
+	os_event_signal(video->gpu_encode_inactive);
+
 	video->gpu_encode_thread_initialized = true;
 	return true;
 #else
@@ -196,6 +204,10 @@ void free_gpu_encoding(struct obs_core_video *video)
 		os_sem_destroy(video->gpu_encode_semaphore);
 		video->gpu_encode_semaphore = NULL;
 	}
+	if (video->gpu_encode_inactive) {
+		os_event_destroy(video->gpu_encode_inactive);
+		video->gpu_encode_inactive = NULL;
+	}
 
 #define free_circlebuf(x) \
 	do { \

+ 2 - 0
libobs/obs.c

@@ -2365,6 +2365,8 @@ void stop_gpu_encode(obs_encoder_t *encoder)
 		call_free = true;
 	pthread_mutex_unlock(&video->gpu_encoder_mutex);
 
+	os_event_wait(video->gpu_encode_inactive);
+
 	if (call_free) {
 		stop_gpu_encoding_thread(video);