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.
This commit is contained in:
tt2468
2023-01-15 21:24:36 -08:00
committed by John R. Bradley
parent 7e30d3f8a2
commit c69e40734d
+8 -1
View File
@@ -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);