diff options
author | Vincent Penquerc'h <vincent.penquerch@collabora.co.uk> | 2011-09-14 19:56:40 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2011-09-19 09:39:00 +0200 |
commit | d8684fffa12a13d32efb8e74b8cd23519b3d76f6 (patch) | |
tree | 85435a16847ed24a277677891dab695740219a35 /ext/celt | |
parent | 06764fcd3f6c738075cf52f8858a157cf8a350b9 (diff) | |
download | gstreamer-plugins-bad-d8684fffa12a13d32efb8e74b8cd23519b3d76f6.tar.gz |
celtenc: cleanup header creation
Avoid an extra copy via a temporary fixed size stack buffer.
Use libcelt's header size to allocate a buffer of the correct
size in the first place (libcelt has an off by 4 there, so
account for this).
While there, make size unsigned, and granpos signed.
https://bugzilla.gnome.org/show_bug.cgi?id=659087
Diffstat (limited to 'ext/celt')
-rw-r--r-- | ext/celt/gstceltenc.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/ext/celt/gstceltenc.c b/ext/celt/gstceltenc.c index e602e09f0..2b09238d2 100644 --- a/ext/celt/gstceltenc.c +++ b/ext/celt/gstceltenc.c @@ -699,16 +699,18 @@ encoder_creation_failed: /* prepare a buffer for transmission */ static GstBuffer * gst_celt_enc_buffer_from_data (GstCeltEnc * enc, guchar * data, - gint data_len, guint64 granulepos) + guint data_len, gint64 granulepos) { GstBuffer *outbuf; - outbuf = gst_buffer_new_and_alloc (data_len); - memcpy (GST_BUFFER_DATA (outbuf), data, data_len); + outbuf = gst_buffer_new (); + GST_BUFFER_DATA (outbuf) = data; + GST_BUFFER_MALLOCDATA (outbuf) = data; + GST_BUFFER_SIZE (outbuf) = data_len; GST_BUFFER_OFFSET (outbuf) = enc->bytes_out; GST_BUFFER_OFFSET_END (outbuf) = granulepos; - GST_LOG_OBJECT (enc, "encoded buffer of %d bytes", GST_BUFFER_SIZE (outbuf)); + GST_LOG_OBJECT (enc, "encoded buffer of %u bytes", GST_BUFFER_SIZE (outbuf)); return outbuf; } @@ -907,11 +909,13 @@ gst_celt_enc_chain (GstPad * pad, GstBuffer * buf) constraints */ GstBuffer *buf1, *buf2; GstCaps *caps; - guchar data[100]; + /* libcelt has a bug which underestimates header size by 4... */ + unsigned int header_size = enc->header.header_size + 4; + unsigned char *data = g_malloc (header_size); /* create header buffer */ - celt_header_to_packet (&enc->header, data, 100); - buf1 = gst_celt_enc_buffer_from_data (enc, data, 100, 0); + celt_header_to_packet (&enc->header, data, header_size); + buf1 = gst_celt_enc_buffer_from_data (enc, data, header_size, 0); /* create comment buffer */ buf2 = gst_celt_enc_create_metadata_buffer (enc); |