Browse Source

libobs: Allow sending NULL to obs_encoder_set_video/audio()

There is currently no way to clear a video_t or audio_t object from an
encoder once applied. `audio_t`/`video_t` objects can be destructed at
any time, and it is dangerous to prevent these object references from
even being cleared.

This does not fix the issue where destroying an audio/video object does
not clear the reference from all subscribed encoders.

(cherry picked from commit eb0d9dc5d2492bf3365bf3d6ab596c5447507553)
tt2468 2 years ago
parent
commit
9ead538009
1 changed files with 19 additions and 14 deletions
  1. 19 14
      libobs/obs-encoder.c

+ 19 - 14
libobs/obs-encoder.c

@@ -800,14 +800,16 @@ void obs_encoder_set_video(obs_encoder_t *encoder, video_t *video)
 		return;
 	}
 
-	if (!video)
-		return;
-
-	voi = video_output_get_info(video);
-
-	encoder->media = video;
-	encoder->timebase_num = voi->fps_den;
-	encoder->timebase_den = voi->fps_num;
+	if (video) {
+		voi = video_output_get_info(video);
+		encoder->media = video;
+		encoder->timebase_num = voi->fps_den;
+		encoder->timebase_den = voi->fps_num;
+	} else {
+		encoder->media = NULL;
+		encoder->timebase_num = 0;
+		encoder->timebase_den = 0;
+	}
 }
 
 void obs_encoder_set_audio(obs_encoder_t *encoder, audio_t *audio)
@@ -829,12 +831,15 @@ void obs_encoder_set_audio(obs_encoder_t *encoder, audio_t *audio)
 		return;
 	}
 
-	if (!audio)
-		return;
-
-	encoder->media = audio;
-	encoder->timebase_num = 1;
-	encoder->timebase_den = audio_output_get_sample_rate(audio);
+	if (audio) {
+		encoder->media = audio;
+		encoder->timebase_num = 1;
+		encoder->timebase_den = audio_output_get_sample_rate(audio);
+	} else {
+		encoder->media = NULL;
+		encoder->timebase_num = 0;
+		encoder->timebase_den = 0;
+	}
 }
 
 video_t *obs_encoder_video(const obs_encoder_t *encoder)