Browse Source

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.
jp9000 8 years ago
parent
commit
cd7bc32388
1 changed files with 11 additions and 6 deletions
  1. 11 6
      libobs/obs-output.c

+ 11 - 6
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;