mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 04:42:18 +02:00
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.
This commit is contained in:
parent
9e7daff511
commit
cd7bc32388
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user