From b4c797bc1de3005d9f4bc40534670bf7b316f953 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 3 Nov 2014 14:13:14 -0800 Subject: [PATCH] Fix asset crash interleaving with active encoders Apparently the audio isn't guaranteed to start up past the first video frame, so it would trigger that assert (which I'm glad I put in). I didn't originally have this happen when I was testing because my audio buffering was not at the default value and didn't trigger it to occur. A blunder on my part, and once again a fine example of how you should never make assumptions about possible code path. --- libobs/obs-output.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libobs/obs-output.c b/libobs/obs-output.c index 3931a56a2..5d00a6c01 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -686,12 +686,10 @@ static struct encoder_packet *find_first_packet_type(struct obs_output *output, return packet; } - /* should never get here for this particular function */ - assert(0); return NULL; } -static void initialize_interleaved_packets(struct obs_output *output) +static bool initialize_interleaved_packets(struct obs_output *output) { struct encoder_packet *video; struct encoder_packet *audio; @@ -699,6 +697,14 @@ static void initialize_interleaved_packets(struct obs_output *output) video = find_first_packet_type(output, OBS_ENCODER_VIDEO); audio = find_first_packet_type(output, OBS_ENCODER_AUDIO); + if (!audio) + output->received_audio = false; + if (!video) + output->received_video = false; + if (!audio || !video) { + return false; + } + /* get new offsets */ output->video_offset = video->dts; output->audio_offset = audio->dts; @@ -713,6 +719,8 @@ static void initialize_interleaved_packets(struct obs_output *output) &output->interleaved_packets.array[i]; apply_interleaved_packet_offset(output, packet); } + + return true; } static inline void insert_interleaved_packet(struct obs_output *output, @@ -764,11 +772,13 @@ static void interleave_packets(void *data, struct encoder_packet *packet) if (output->received_audio && output->received_video) { if (!was_started) { prune_interleaved_packets(output); - initialize_interleaved_packets(output); - resort_interleaved_packets(output); + if (initialize_interleaved_packets(output)) { + resort_interleaved_packets(output); + send_interleaved(output); + } + } else { + send_interleaved(output); } - - send_interleaved(output); } pthread_mutex_unlock(&output->interleaved_mutex);