From cd7bc32388ef4987f2588e968feca46cb01f8eae Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sat, 24 Dec 2016 02:13:50 -0800 Subject: [PATCH] libobs: Fix caption encoder packet reallocation Captions do something unusual with encoder packets: they reallocate them due to appending extra h.264 data. Due to the way allocations are handled with core encoder packets (they now store a reference in their data), instead of modifying the encoder data directly, create a new encoder packet instead and release the old packet. --- libobs/obs-output.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libobs/obs-output.c b/libobs/obs-output.c index e2e897d76..c6942b654 100644 --- a/libobs/obs-output.c +++ b/libobs/obs-output.c @@ -963,6 +963,7 @@ static const uint8_t nal_start[4] = {0, 0, 0, 1}; static bool add_caption(struct obs_output *output, struct encoder_packet *out) { + struct encoder_packet new_packet = *out; caption_frame_t cf; sei_t sei; uint8_t *data; @@ -970,15 +971,14 @@ static bool add_caption(struct obs_output *output, struct encoder_packet *out) DARRAY(uint8_t) out_data; - out_data.array = out->data; - out_data.num = out->size; - out_data.capacity = out->size; - if (out->priority > 1) return false; sei_init(&sei); + da_init(out_data); + da_copy_array(out_data, out->data, out->size); + caption_frame_init(&cf); caption_frame_from_text(&cf, &output->caption_head->text[0]); @@ -989,10 +989,15 @@ static bool add_caption(struct obs_output *output, struct encoder_packet *out) /* TODO SEI should come after AUD/SPS/PPS, but before any VCL */ da_push_back_array(out_data, nal_start, 4); da_push_back_array(out_data, data, size); - out->data = out_data.array; - out->size = out_data.num; free(data); + obs_encoder_packet_release(out); + + new_packet.data = out_data.array; + new_packet.size = out_data.num; + obs_encoder_packet_create_instance(out, &new_packet); + da_free(out_data); + sei_free(&sei); struct caption_text *next = output->caption_head->next;