Browse Source

libobs: Prevent encoders from initializing/starting if no media is set

This fixes a case of undefined behavior, where encoders can try to init
or start without actually having any video_t or audio_t object
assigned.

(cherry picked from commit c69e40734dcc547c844d14f221adf2f11ff77890)
tt2468 2 years ago
parent
commit
2fcac0e363
1 changed files with 8 additions and 1 deletions
  1. 8 1
      libobs/obs-encoder.c

+ 8 - 1
libobs/obs-encoder.c

@@ -443,6 +443,13 @@ static THREAD_LOCAL bool can_reroute = false;
 
 static inline bool obs_encoder_initialize_internal(obs_encoder_t *encoder)
 {
+	if (!encoder->media) {
+		blog(LOG_ERROR,
+		     "obs_encoder_initialize_internal: encoder '%s' has no media set",
+		     encoder->context.name);
+		return false;
+	}
+
 	if (encoder_active(encoder))
 		return true;
 	if (encoder->initialized)
@@ -552,7 +559,7 @@ static inline void obs_encoder_start_internal(
 	struct encoder_callback cb = {false, new_packet, param};
 	bool first = false;
 
-	if (!encoder->context.data)
+	if (!encoder->context.data || !encoder->media)
 		return;
 
 	pthread_mutex_lock(&encoder->callbacks_mutex);