ext/theora/theoraenc.c (theora_buffer_from_packet, theora_enc_chain): Don't use pad_alloc_buffer_and_set_caps to crea...

Original commit message from CVS:
* ext/theora/theoraenc.c (theora_buffer_from_packet, theora_enc_chain):
Don't use pad_alloc_buffer_and_set_caps to create a small header
packet, or, worse, to create a big temporary video buffer using the
src pad.
This commit is contained in:
Thomas Vander Stichele 2007-04-15 14:35:53 +00:00
parent 66a6f3413c
commit 096abcf3d6
2 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,10 @@
2007-04-15 Thomas Vander Stichele <thomas at apestaart dot org>
* ext/theora/theoraenc.c (theora_buffer_from_packet, theora_enc_chain):
Don't use pad_alloc_buffer_and_set_caps to create a small header
packet, or, worse, to create a big temporary video buffer using the
src pad.
2007-04-14 Thomas Vander Stichele <thomas at apestaart dot org> 2007-04-14 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/gdp/gstgdppay.c (gst_gdp_pay_chain): * gst/gdp/gstgdppay.c (gst_gdp_pay_chain):

View File

@ -420,14 +420,17 @@ theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet,
GstClockTime timestamp, GstClockTime duration, GstBuffer ** buffer) GstClockTime timestamp, GstClockTime duration, GstBuffer ** buffer)
{ {
GstBuffer *buf; GstBuffer *buf;
GstFlowReturn ret; GstFlowReturn ret = GST_FLOW_OK;
ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad, buf = gst_buffer_new_and_alloc (packet->bytes);
GST_BUFFER_OFFSET_NONE, packet->bytes, GST_PAD_CAPS (enc->srcpad), &buf); if (!buf) {
if (ret != GST_FLOW_OK) GST_WARNING_OBJECT (enc, "Could not allocate buffer");
goto no_buffer; ret = GST_FLOW_ERROR;
goto done;
}
memcpy (GST_BUFFER_DATA (buf), packet->packet, packet->bytes); memcpy (GST_BUFFER_DATA (buf), packet->packet, packet->bytes);
gst_buffer_set_caps (buf, GST_PAD_CAPS (enc->srcpad));
/* see ext/ogg/README; OFFSET_END takes "our" granulepos, OFFSET its /* see ext/ogg/README; OFFSET_END takes "our" granulepos, OFFSET its
* time representation */ * time representation */
GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_END (buf) =
@ -453,14 +456,9 @@ theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet,
} }
enc->packetno++; enc->packetno++;
done:
*buffer = buf; *buffer = buf;
return ret; return ret;
no_buffer:
{
*buffer = NULL;
return ret;
}
} }
/* push out the buffer and do internal bookkeeping */ /* push out the buffer and do internal bookkeeping */
@ -610,14 +608,15 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
in_time = GST_BUFFER_TIMESTAMP (buffer); in_time = GST_BUFFER_TIMESTAMP (buffer);
/* no packets written yet, setup headers */
if (enc->packetno == 0) { if (enc->packetno == 0) {
/* no packets written yet, setup headers */
GstCaps *caps; GstCaps *caps;
GstBuffer *buf1, *buf2, *buf3; GstBuffer *buf1, *buf2, *buf3;
enc->granulepos_offset = 0; enc->granulepos_offset = 0;
enc->timestamp_offset = 0; enc->timestamp_offset = 0;
GST_DEBUG_OBJECT (enc, "output headers");
/* Theora streams begin with three headers; the initial header (with /* Theora streams begin with three headers; the initial header (with
most of the codec setup parameters) which is mandated by the Ogg most of the codec setup parameters) which is mandated by the Ogg
bitstream spec. The second header holds any comment fields. The bitstream spec. The second header holds any comment fields. The
@ -717,6 +716,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
y_size = enc->info_width * enc->info_height; y_size = enc->info_width * enc->info_height;
if (enc->width == enc->info_width && enc->height == enc->info_height) { if (enc->width == enc->info_width && enc->height == enc->info_height) {
GST_LOG_OBJECT (enc, "no cropping/conversion needed");
/* easy case, no cropping/conversion needed */ /* easy case, no cropping/conversion needed */
pixels = GST_BUFFER_DATA (buffer); pixels = GST_BUFFER_DATA (buffer);
@ -735,6 +735,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
gint cwidth, cheight; gint cwidth, cheight;
gint offset_x, right_x, right_border; gint offset_x, right_x, right_border;
GST_LOG_OBJECT (enc, "cropping/conversion needed for strides");
/* source width/height */ /* source width/height */
width = enc->width; width = enc->width;
height = enc->height; height = enc->height;
@ -750,11 +751,13 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
dst_y_stride = enc->info_width; dst_y_stride = enc->info_width;
dst_uv_stride = enc->info_width / 2; dst_uv_stride = enc->info_width / 2;
ret = gst_pad_alloc_buffer_and_set_caps (enc->srcpad, newbuf = gst_buffer_new_and_alloc (y_size * 3 / 2);
GST_BUFFER_OFFSET_NONE, y_size * 3 / 2, GST_PAD_CAPS (enc->srcpad), if (!newbuf) {
&newbuf); ret = GST_FLOW_ERROR;
if (ret != GST_FLOW_OK)
goto no_buffer; goto no_buffer;
}
GST_BUFFER_OFFSET (newbuf) = GST_BUFFER_OFFSET_NONE;
gst_buffer_set_caps (newbuf, GST_PAD_CAPS (enc->srcpad));
dest_y = yuv.y = GST_BUFFER_DATA (newbuf); dest_y = yuv.y = GST_BUFFER_DATA (newbuf);
dest_u = yuv.u = yuv.y + y_size; dest_u = yuv.u = yuv.y + y_size;
@ -891,7 +894,6 @@ header_push:
} }
no_buffer: no_buffer:
{ {
gst_buffer_unref (buffer);
return ret; return ret;
} }
data_push: data_push: