mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 13:41:48 +00:00
[MOVED FROM BAD 13/28] ext/x264/gstx264enc.c: Allocate some buffers in more adaptive and economical fashion.
Original commit message from CVS: * ext/x264/gstx264enc.c: (gst_x264_enc_init), (gst_x264_enc_header_buf), (gst_x264_enc_encode_frame): Allocate some buffers in more adaptive and economical fashion.
This commit is contained in:
parent
a2ff3c6fde
commit
d22b361df8
1 changed files with 14 additions and 14 deletions
|
@ -424,7 +424,7 @@ gst_x264_enc_init (GstX264Enc * encoder, GstX264EncClass * klass)
|
||||||
|
|
||||||
/* resources */
|
/* resources */
|
||||||
encoder->delay = g_queue_new ();
|
encoder->delay = g_queue_new ();
|
||||||
encoder->buffer_size = 1040000;
|
encoder->buffer_size = 100000;
|
||||||
encoder->buffer = g_malloc (encoder->buffer_size);
|
encoder->buffer = g_malloc (encoder->buffer_size);
|
||||||
|
|
||||||
x264_param_default (&encoder->x264param);
|
x264_param_default (&encoder->x264param);
|
||||||
|
@ -637,16 +637,18 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This should be enough for a header buffer. */
|
/* x264 is expected to return an SEI (some identification info),
|
||||||
buffer_size = 100000;
|
* followed by an SPS and PPS */
|
||||||
buffer = g_malloc (buffer_size);
|
if (i_nal != 3 || nal[1].i_type != 7 || nal[2].i_type != 8) {
|
||||||
|
GST_ELEMENT_ERROR (encoder, STREAM, ENCODE, NULL,
|
||||||
if (nal[1].i_type != 7 || nal[2].i_type != 8) {
|
("Unexpected x264 header."));
|
||||||
GST_ELEMENT_ERROR (encoder, STREAM, ENCODE, ("Unexpected x264 header."),
|
|
||||||
("TODO avcC header construction for high profiles needs some work"));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* nal payloads with emulation_prevention_three_byte, and some header data */
|
||||||
|
buffer_size = (nal[1].i_payload + nal[2].i_payload) * 4 + 100;
|
||||||
|
buffer = g_malloc (buffer_size);
|
||||||
|
|
||||||
sps = nal[1].p_payload;
|
sps = nal[1].p_payload;
|
||||||
|
|
||||||
buffer[0] = 1; /* AVC Decoder Configuration Record ver. 1 */
|
buffer[0] = 1; /* AVC Decoder Configuration Record ver. 1 */
|
||||||
|
@ -672,9 +674,7 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
|
||||||
i_size += nal_size + 2;
|
i_size += nal_size + 2;
|
||||||
|
|
||||||
buf = gst_buffer_new_and_alloc (i_size);
|
buf = gst_buffer_new_and_alloc (i_size);
|
||||||
|
|
||||||
memcpy (GST_BUFFER_DATA (buf), buffer, i_size);
|
memcpy (GST_BUFFER_DATA (buf), buffer, i_size);
|
||||||
|
|
||||||
g_free (buffer);
|
g_free (buffer);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -906,12 +906,12 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
|
||||||
|
|
||||||
i_size = 0;
|
i_size = 0;
|
||||||
for (i = 0; i < *i_nal; i++) {
|
for (i = 0; i < *i_nal; i++) {
|
||||||
int i_data = encoder->buffer_size - i_size - 4;
|
gint i_data = encoder->buffer_size - i_size - 4;
|
||||||
|
|
||||||
if (i_data < encoder->buffer_size / 2) {
|
if (i_data < nal[i].i_payload * 2) {
|
||||||
encoder->buffer_size *= 2;
|
encoder->buffer_size += 2 * nal[i].i_payload;
|
||||||
encoder->buffer = g_realloc (encoder->buffer, encoder->buffer_size);
|
encoder->buffer = g_realloc (encoder->buffer, encoder->buffer_size);
|
||||||
i_data = encoder->buffer_size - i_size;
|
i_data = encoder->buffer_size - i_size - 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
nal_size =
|
nal_size =
|
||||||
|
|
Loading…
Reference in a new issue