Browse Source

libobs: Don't defer encoder updates if not necessary

When #5169 implemented deferred encoder updates, it did not account for
the case when the encoder hadn't started yet. This means the encoder would
start and then immediately call update with the same settings it was
started with, which in the case of some hardware encoders would trigger
a reconfiguration request to the driver.
Richard Stanway 2 years ago
parent
commit
4118fa7ac1
1 changed files with 17 additions and 5 deletions
  1. 17 5
      libobs/obs-encoder.c

+ 17 - 5
libobs/obs-encoder.c

@@ -505,12 +505,24 @@ void obs_encoder_update(obs_encoder_t *encoder, obs_data_t *settings)
 
 	obs_data_apply(encoder->context.settings, settings);
 
-	// Note, we don't actually apply the changes to the encoder here
-	// as it may be active in another thread. Setting this to true
-	// makes the changes apply at the next possible moment in the
-	// encoder / GPU encoder thread.
-	if (encoder->info.update)
+	// Encoder isn't initialized yet, only apply changes to settings
+	if (!encoder->context.data)
+		return;
+
+	// Encoder doesn't support updates
+	if (!encoder->info.update)
+		return;
+
+	// If the encoder is active we defer the update as it may not be
+	// reentrant. Setting reconfigure_requested to true makes the changes
+	// apply at the next possible moment in the encoder / GPU encoder
+	// thread.
+	if (encoder_active(encoder)) {
 		encoder->reconfigure_requested = true;
+	} else {
+		encoder->info.update(encoder->context.data,
+				     encoder->context.settings);
+	}
 }
 
 bool obs_encoder_get_extra_data(const obs_encoder_t *encoder,