plugins: more porting to new memory API

This commit is contained in:
Wim Taymans 2011-03-27 18:30:24 +02:00
parent 5244770775
commit f379a5dacb
14 changed files with 215 additions and 145 deletions

View file

@ -651,6 +651,8 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
gboolean need_skip; gboolean need_skip;
const guint16 *data; const guint16 *data;
guint64 dist, timestamp; guint64 dist, timestamp;
guint8 *outdata;
gsize outsize;
GST_DEBUG_OBJECT (visual, "processing buffer"); GST_DEBUG_OBJECT (visual, "processing buffer");
@ -697,7 +699,7 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
/* Read VISUAL_SAMPLES samples per channel */ /* Read VISUAL_SAMPLES samples per channel */
data = data =
(const guint16 *) gst_adapter_peek (visual->adapter, (const guint16 *) gst_adapter_map (visual->adapter,
VISUAL_SAMPLES * visual->bps); VISUAL_SAMPLES * visual->bps);
#if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000 #if defined(VISUAL_API_VERSION) && VISUAL_API_VERSION >= 4000 && VISUAL_API_VERSION < 5000
@ -783,15 +785,20 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer)
if (outbuf == NULL) { if (outbuf == NULL) {
ret = get_buffer (visual, &outbuf); ret = get_buffer (visual, &outbuf);
if (ret != GST_FLOW_OK) { if (ret != GST_FLOW_OK) {
gst_adapter_unmap (visual->adapter, 0);
goto beach; goto beach;
} }
} }
visual_video_set_buffer (visual->video, GST_BUFFER_DATA (outbuf)); outdata = gst_buffer_map (outbuf, &outsize, NULL, GST_MAP_WRITE);
visual_video_set_buffer (visual->video, outdata);
visual_audio_analyze (visual->audio); visual_audio_analyze (visual->audio);
visual_actor_run (visual->actor, visual->audio); visual_actor_run (visual->actor, visual->audio);
visual_video_set_buffer (visual->video, NULL); visual_video_set_buffer (visual->video, NULL);
gst_buffer_unmap (outbuf, outdata, outsize);
GST_DEBUG_OBJECT (visual, "rendered one frame"); GST_DEBUG_OBJECT (visual, "rendered one frame");
gst_adapter_unmap (visual->adapter, 0);
GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
GST_BUFFER_DURATION (outbuf) = visual->duration; GST_BUFFER_DURATION (outbuf) = visual->duration;

View file

@ -196,8 +196,8 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps)
GstStructure *structure; GstStructure *structure;
const GValue *codec_data; const GValue *codec_data;
GstBuffer *buffer; GstBuffer *buffer;
guint8 *data; guint8 *data, *ptr;
guint size; gsize size, left;
guint32 sizes[3]; guint32 sizes[3];
GstCaps *outcaps; GstCaps *outcaps;
gint i, offs; gint i, offs;
@ -221,31 +221,33 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps)
/* first 22 bytes are bits_per_sample, channel_mask, GUID /* first 22 bytes are bits_per_sample, channel_mask, GUID
* Then we get 3 LE guint32 with the 3 header sizes * Then we get 3 LE guint32 with the 3 header sizes
* then we get the bytes of the 3 headers. */ * then we get the bytes of the 3 headers. */
data = GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
size = GST_BUFFER_SIZE (buffer);
GST_LOG_OBJECT (ogg, "configuring codec_data of size %u", size); ptr = data;
left = size;
GST_LOG_OBJECT (ogg, "configuring codec_data of size %u", left);
/* skip headers */ /* skip headers */
data += 22; ptr += 22;
size -= 22; left -= 22;
/* we need at least 12 bytes for the packet sizes of the 3 headers */ /* we need at least 12 bytes for the packet sizes of the 3 headers */
if (size < 12) if (left < 12)
goto buffer_too_small; goto buffer_too_small;
/* read sizes of the 3 headers */ /* read sizes of the 3 headers */
sizes[0] = GST_READ_UINT32_LE (data); sizes[0] = GST_READ_UINT32_LE (ptr);
sizes[1] = GST_READ_UINT32_LE (data + 4); sizes[1] = GST_READ_UINT32_LE (ptr + 4);
sizes[2] = GST_READ_UINT32_LE (data + 8); sizes[2] = GST_READ_UINT32_LE (ptr + 8);
GST_DEBUG_OBJECT (ogg, "header sizes: %u %u %u", sizes[0], sizes[1], GST_DEBUG_OBJECT (ogg, "header sizes: %u %u %u", sizes[0], sizes[1],
sizes[2]); sizes[2]);
size -= 12; left -= 12;
/* and we need at least enough data for all the headers */ /* and we need at least enough data for all the headers */
if (size < sizes[0] + sizes[1] + sizes[2]) if (left < sizes[0] + sizes[1] + sizes[2])
goto buffer_too_small; goto buffer_too_small;
/* set caps */ /* set caps */
@ -264,6 +266,7 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps)
offs += sizes[i]; offs += sizes[i];
} }
gst_buffer_unmap (buffer, data, size);
gst_caps_unref (outcaps); gst_caps_unref (outcaps);
return TRUE; return TRUE;
@ -282,6 +285,7 @@ wrong_format:
buffer_too_small: buffer_too_small:
{ {
GST_DEBUG_OBJECT (ogg, "codec_data is too small"); GST_DEBUG_OBJECT (ogg, "codec_data is too small");
gst_buffer_unmap (buffer, data, size);
return FALSE; return FALSE;
} }
} }
@ -319,7 +323,7 @@ gst_ogg_avi_parse_push_packet (GstOggAviParse * ogg, ogg_packet * packet)
/* allocate space for header and body */ /* allocate space for header and body */
buffer = gst_buffer_new_and_alloc (packet->bytes); buffer = gst_buffer_new_and_alloc (packet->bytes);
memcpy (GST_BUFFER_DATA (buffer), packet->packet, packet->bytes); gst_buffer_fill (buffer, 0, packet->packet, packet->bytes);
GST_LOG_OBJECT (ogg, "created buffer %p from page", buffer); GST_LOG_OBJECT (ogg, "created buffer %p from page", buffer);
@ -340,15 +344,13 @@ gst_ogg_avi_parse_chain (GstPad * pad, GstBuffer * buffer)
{ {
GstFlowReturn result = GST_FLOW_OK; GstFlowReturn result = GST_FLOW_OK;
GstOggAviParse *ogg; GstOggAviParse *ogg;
guint8 *data;
guint size; guint size;
gchar *oggbuf; gchar *oggbuf;
gint ret = -1; gint ret = -1;
ogg = GST_OGG_AVI_PARSE (GST_OBJECT_PARENT (pad)); ogg = GST_OGG_AVI_PARSE (GST_OBJECT_PARENT (pad));
data = GST_BUFFER_DATA (buffer); size = gst_buffer_get_size (buffer);
size = GST_BUFFER_SIZE (buffer);
GST_LOG_OBJECT (ogg, "Chain function received buffer of size %d", size); GST_LOG_OBJECT (ogg, "Chain function received buffer of size %d", size);
@ -359,7 +361,7 @@ gst_ogg_avi_parse_chain (GstPad * pad, GstBuffer * buffer)
/* write data to sync layer */ /* write data to sync layer */
oggbuf = ogg_sync_buffer (&ogg->sync, size); oggbuf = ogg_sync_buffer (&ogg->sync, size);
memcpy (oggbuf, data, size); gst_buffer_extract (buffer, 0, oggbuf, size);
ogg_sync_wrote (&ogg->sync, size); ogg_sync_wrote (&ogg->sync, size);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -581,7 +581,8 @@ gst_ogg_demux_chain_peer (GstOggPad * pad, ogg_packet * packet,
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT);
/* copy packet in buffer */ /* copy packet in buffer */
memcpy (buf->data, packet->packet + offset, packet->bytes - offset - trim); gst_buffer_fill (buf, 0, packet->packet + offset,
packet->bytes - offset - trim);
GST_BUFFER_TIMESTAMP (buf) = out_timestamp; GST_BUFFER_TIMESTAMP (buf) = out_timestamp;
GST_BUFFER_DURATION (buf) = out_duration; GST_BUFFER_DURATION (buf) = out_duration;
@ -1400,15 +1401,14 @@ gst_ogg_demux_sink_event (GstPad * pad, GstEvent * event)
static GstFlowReturn static GstFlowReturn
gst_ogg_demux_submit_buffer (GstOggDemux * ogg, GstBuffer * buffer) gst_ogg_demux_submit_buffer (GstOggDemux * ogg, GstBuffer * buffer)
{ {
gint size; gsize size;
guint8 *data; guint8 *data;
gchar *oggbuffer; gchar *oggbuffer;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
size = GST_BUFFER_SIZE (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buffer);
GST_DEBUG_OBJECT (ogg, "submitting %u bytes", size); GST_DEBUG_OBJECT (ogg, "submitting %" G_GSIZE_FORMAT " bytes", size);
if (G_UNLIKELY (size == 0)) if (G_UNLIKELY (size == 0))
goto done; goto done;
@ -1421,6 +1421,7 @@ gst_ogg_demux_submit_buffer (GstOggDemux * ogg, GstBuffer * buffer)
goto write_failed; goto write_failed;
done: done:
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
return ret; return ret;
@ -1479,7 +1480,7 @@ gst_ogg_demux_get_data (GstOggDemux * ogg, gint64 end_offset)
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto error; goto error;
ogg->read_offset += GST_BUFFER_SIZE (buffer); ogg->read_offset += gst_buffer_get_size (buffer);
ret = gst_ogg_demux_submit_buffer (ogg, buffer); ret = gst_ogg_demux_submit_buffer (ogg, buffer);
@ -1725,7 +1726,7 @@ gst_ogg_demux_set_header_on_caps (GstOggDemux * ogg, GstCaps * caps,
ogg_packet *op = headers->data; ogg_packet *op = headers->data;
g_assert (op); g_assert (op);
buffer = gst_buffer_new_and_alloc (op->bytes); buffer = gst_buffer_new_and_alloc (op->bytes);
memcpy (GST_BUFFER_DATA (buffer), op->packet, op->bytes); gst_buffer_fill (buffer, 0, op->packet, op->bytes);
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
g_value_init (&value, GST_TYPE_BUFFER); g_value_init (&value, GST_TYPE_BUFFER);
gst_value_take_buffer (&value, buffer); gst_value_take_buffer (&value, buffer);
@ -3272,7 +3273,7 @@ gst_ogg_demux_loop_forward (GstOggDemux * ogg)
goto done; goto done;
} }
ogg->offset += GST_BUFFER_SIZE (buffer); ogg->offset += gst_buffer_get_size (buffer);
if (G_UNLIKELY (ogg->newsegment)) { if (G_UNLIKELY (ogg->newsegment)) {
gst_ogg_demux_send_event (ogg, ogg->newsegment); gst_ogg_demux_send_event (ogg, ogg->newsegment);

View file

@ -494,9 +494,8 @@ gst_ogg_mux_buffer_from_page (GstOggMux * mux, ogg_page * page, gboolean delta)
/* allocate space for header and body */ /* allocate space for header and body */
buffer = gst_buffer_new_and_alloc (page->header_len + page->body_len); buffer = gst_buffer_new_and_alloc (page->header_len + page->body_len);
memcpy (GST_BUFFER_DATA (buffer), page->header, page->header_len); gst_buffer_fill (buffer, 0, page->header, page->header_len);
memcpy (GST_BUFFER_DATA (buffer) + page->header_len, gst_buffer_fill (buffer, page->header_len, page->body, page->body_len);
page->body, page->body_len);
/* Here we set granulepos as our OFFSET_END to give easy direct access to /* Here we set granulepos as our OFFSET_END to give easy direct access to
* this value later. Before we push it, we reset this to OFFSET + SIZE * this value later. Before we push it, we reset this to OFFSET + SIZE
@ -519,7 +518,7 @@ gst_ogg_mux_push_buffer (GstOggMux * mux, GstBuffer * buffer)
/* fix up OFFSET and OFFSET_END again */ /* fix up OFFSET and OFFSET_END again */
GST_BUFFER_OFFSET (buffer) = mux->offset; GST_BUFFER_OFFSET (buffer) = mux->offset;
mux->offset += GST_BUFFER_SIZE (buffer); mux->offset += gst_buffer_get_size (buffer);
GST_BUFFER_OFFSET_END (buffer) = mux->offset; GST_BUFFER_OFFSET_END (buffer) = mux->offset;
/* Ensure we have monotonically increasing timestamps in the output. */ /* Ensure we have monotonically increasing timestamps in the output. */
@ -805,9 +804,10 @@ gst_ogg_mux_queue_pads (GstOggMux * ogg_mux)
/* and we have one */ /* and we have one */
ogg_packet packet; ogg_packet packet;
gboolean is_header; gboolean is_header;
gsize size;
packet.packet = GST_BUFFER_DATA (buf); packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
packet.bytes = GST_BUFFER_SIZE (buf); packet.bytes = size;
if (GST_BUFFER_OFFSET_END_IS_VALID (buf)) if (GST_BUFFER_OFFSET_END_IS_VALID (buf))
packet.granulepos = GST_BUFFER_OFFSET_END (buf); packet.granulepos = GST_BUFFER_OFFSET_END (buf);
@ -831,6 +831,8 @@ gst_ogg_mux_queue_pads (GstOggMux * ogg_mux)
else /* fallback (FIXME 0.11: remove IN_CAPS hack) */ else /* fallback (FIXME 0.11: remove IN_CAPS hack) */
is_header = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_IN_CAPS); is_header = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_IN_CAPS);
gst_buffer_unmap (buf, packet.packet, size);
if (is_header) { if (is_header) {
GST_DEBUG_OBJECT (ogg_mux, GST_DEBUG_OBJECT (ogg_mux,
"got header buffer in control state, ignoring"); "got header buffer in control state, ignoring");
@ -978,7 +980,8 @@ gst_ogg_mux_set_header_on_caps (GstCaps * caps, GList * buffers)
walk = walk->next; walk = walk->next;
/* mark buffer */ /* mark buffer */
GST_LOG ("Setting IN_CAPS on buffer of length %d", GST_BUFFER_SIZE (buf)); GST_LOG ("Setting IN_CAPS on buffer of length %d",
gst_buffer_get_size (buf));
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_IN_CAPS);
g_value_init (&value, GST_TYPE_BUFFER); g_value_init (&value, GST_TYPE_BUFFER);
@ -1046,6 +1049,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
GstCaps *caps; GstCaps *caps;
GstStructure *structure; GstStructure *structure;
GstBuffer *hbuf; GstBuffer *hbuf;
gsize size;
pad = (GstOggPadData *) walk->data; pad = (GstOggPadData *) walk->data;
thepad = pad->collect.pad; thepad = pad->collect.pad;
@ -1077,8 +1081,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
} }
/* create a packet from the buffer */ /* create a packet from the buffer */
packet.packet = GST_BUFFER_DATA (buf); packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
packet.bytes = GST_BUFFER_SIZE (buf); packet.bytes = size;
packet.granulepos = GST_BUFFER_OFFSET_END (buf); packet.granulepos = GST_BUFFER_OFFSET_END (buf);
if (packet.granulepos == -1) if (packet.granulepos == -1)
packet.granulepos = 0; packet.granulepos = 0;
@ -1090,6 +1094,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
/* swap the packet in */ /* swap the packet in */
ogg_stream_packetin (&pad->map.stream, &packet); ogg_stream_packetin (&pad->map.stream, &packet);
gst_buffer_unmap (buf, packet.packet, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
GST_LOG_OBJECT (thepad, "flushing out BOS page"); GST_LOG_OBJECT (thepad, "flushing out BOS page");
@ -1142,12 +1148,13 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
GstBuffer *buf = GST_BUFFER (hwalk->data); GstBuffer *buf = GST_BUFFER (hwalk->data);
ogg_packet packet; ogg_packet packet;
ogg_page page; ogg_page page;
gsize size;
hwalk = hwalk->next; hwalk = hwalk->next;
/* create a packet from the buffer */ /* create a packet from the buffer */
packet.packet = GST_BUFFER_DATA (buf); packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
packet.bytes = GST_BUFFER_SIZE (buf); packet.bytes = size;
packet.granulepos = GST_BUFFER_OFFSET_END (buf); packet.granulepos = GST_BUFFER_OFFSET_END (buf);
if (packet.granulepos == -1) if (packet.granulepos == -1)
packet.granulepos = 0; packet.granulepos = 0;
@ -1159,6 +1166,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux)
/* swap the packet in */ /* swap the packet in */
ogg_stream_packetin (&pad->map.stream, &packet); ogg_stream_packetin (&pad->map.stream, &packet);
gst_buffer_unmap (buf, packet.packet, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
/* if last header, flush page */ /* if last header, flush page */
@ -1315,6 +1323,7 @@ gst_ogg_mux_process_best_pad (GstOggMux * ogg_mux, GstOggPadData * best)
GstOggPadData *pad = ogg_mux->pulling; GstOggPadData *pad = ogg_mux->pulling;
gint64 duration; gint64 duration;
gboolean force_flush; gboolean force_flush;
gsize size;
GST_LOG_OBJECT (ogg_mux->pulling->collect.pad, "pulling from pad"); GST_LOG_OBJECT (ogg_mux->pulling->collect.pad, "pulling from pad");
@ -1338,8 +1347,8 @@ gst_ogg_mux_process_best_pad (GstOggMux * ogg_mux, GstOggPadData * best)
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf))); GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
} }
/* create a packet from the buffer */ /* create a packet from the buffer */
packet.packet = GST_BUFFER_DATA (buf); packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
packet.bytes = GST_BUFFER_SIZE (buf); packet.bytes = size;
packet.granulepos = GST_BUFFER_OFFSET_END (buf); packet.granulepos = GST_BUFFER_OFFSET_END (buf);
if (packet.granulepos == -1) if (packet.granulepos == -1)
packet.granulepos = 0; packet.granulepos = 0;
@ -1428,6 +1437,7 @@ gst_ogg_mux_process_best_pad (GstOggMux * ogg_mux, GstOggPadData * best)
GST_DEBUG_OBJECT (pad->collect.pad, "swapping in BOS packet"); GST_DEBUG_OBJECT (pad->collect.pad, "swapping in BOS packet");
ogg_stream_packetin (&pad->map.stream, &packet); ogg_stream_packetin (&pad->map.stream, &packet);
gst_buffer_unmap (buf, packet.packet, size);
pad->data_pushed = TRUE; pad->data_pushed = TRUE;
gp_time = GST_BUFFER_OFFSET (pad->buffer); gp_time = GST_BUFFER_OFFSET (pad->buffer);

View file

@ -286,15 +286,14 @@ gst_ogg_parse_dispose (GObject * object)
static GstFlowReturn static GstFlowReturn
gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer) gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer)
{ {
guint size; gsize size;
guint8 *data; guint8 *data;
gchar *oggbuffer; gchar *oggbuffer;
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
size = GST_BUFFER_SIZE (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buffer);
GST_DEBUG_OBJECT (ogg, "submitting %u bytes", size); GST_DEBUG_OBJECT (ogg, "submitting %" G_GSIZE_FORMAT " bytes", size);
if (G_UNLIKELY (size == 0)) if (G_UNLIKELY (size == 0))
goto done; goto done;
@ -314,6 +313,7 @@ gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer)
} }
done: done:
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
return ret; return ret;
@ -368,8 +368,8 @@ gst_ogg_parse_buffer_from_page (ogg_page * page,
int size = page->header_len + page->body_len; int size = page->header_len + page->body_len;
GstBuffer *buf = gst_buffer_new_and_alloc (size); GstBuffer *buf = gst_buffer_new_and_alloc (size);
memcpy (GST_BUFFER_DATA (buf), page->header, page->header_len); gst_buffer_fill (buf, 0, page->header, page->header_len);
memcpy (GST_BUFFER_DATA (buf) + page->header_len, page->body, page->body_len); gst_buffer_fill (buf, page->header_len, page->body, page->body_len);
GST_BUFFER_TIMESTAMP (buf) = timestamp; GST_BUFFER_TIMESTAMP (buf) = timestamp;
GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET (buf) = offset;
@ -394,8 +394,9 @@ gst_ogg_parse_chain (GstPad * pad, GstBuffer * buffer)
ogg = GST_OGG_PARSE (GST_OBJECT_PARENT (pad)); ogg = GST_OGG_PARSE (GST_OBJECT_PARENT (pad));
GST_LOG_OBJECT (ogg, "Chain function received buffer of size %d", GST_LOG_OBJECT (ogg,
GST_BUFFER_SIZE (buffer)); "Chain function received buffer of size %" G_GSIZE_FORMAT,
gst_buffer_get_size (buffer));
gst_ogg_parse_submit_buffer (ogg, buffer); gst_ogg_parse_submit_buffer (ogg, buffer);

View file

@ -303,19 +303,14 @@ static gboolean
tag_list_from_vorbiscomment_packet (ogg_packet * packet, tag_list_from_vorbiscomment_packet (ogg_packet * packet,
const guint8 * id_data, const guint id_data_length, GstTagList ** tags) const guint8 * id_data, const guint id_data_length, GstTagList ** tags)
{ {
GstBuffer *buf = NULL;
gchar *encoder = NULL; gchar *encoder = NULL;
GstTagList *list; GstTagList *list;
gboolean ret = TRUE; gboolean ret = TRUE;
g_return_val_if_fail (tags != NULL, FALSE); g_return_val_if_fail (tags != NULL, FALSE);
buf = gst_buffer_new (); list = gst_tag_list_from_vorbiscomment (packet->packet, packet->bytes,
GST_BUFFER_DATA (buf) = (guint8 *) packet->packet; id_data, id_data_length, &encoder);
GST_BUFFER_SIZE (buf) = packet->bytes;
list = gst_tag_list_from_vorbiscomment_buffer (buf, id_data, id_data_length,
&encoder);
if (!list) { if (!list) {
GST_WARNING ("failed to decode vorbis comments"); GST_WARNING ("failed to decode vorbis comments");
@ -335,8 +330,6 @@ exit:
gst_tag_list_free (*tags); gst_tag_list_free (*tags);
*tags = list; *tags = list;
gst_buffer_unref (buf);
return ret; return ret;
} }

View file

@ -725,32 +725,27 @@ gst_ogm_parse_comment_packet (GstOgmParse * ogm, GstBuffer * buf)
static void static void
gst_ogm_text_parse_strip_trailing_zeroes (GstOgmParse * ogm, GstBuffer * buf) gst_ogm_text_parse_strip_trailing_zeroes (GstOgmParse * ogm, GstBuffer * buf)
{ {
const guint8 *data; guint8 *data;
guint size; gsize size;
g_assert (gst_buffer_is_metadata_writable (buf)); g_assert (gst_buffer_is_writable (buf));
/* zeroes are not valid UTF-8 characters, so strip them from output */ /* zeroes are not valid UTF-8 characters, so strip them from output */
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
size = GST_BUFFER_SIZE (buf);
while (size > 0 && data[size - 1] == '\0') { while (size > 0 && data[size - 1] == '\0') {
--size; --size;
} }
gst_buffer_unmap (buf, data, size);
GST_BUFFER_SIZE (buf) = size;
} }
static GstFlowReturn static GstFlowReturn
gst_ogm_parse_data_packet (GstOgmParse * ogm, GstBuffer * buf) gst_ogm_parse_data_packet (GstOgmParse * ogm, GstBuffer * buf,
const guint8 * data, gsize size)
{ {
GstFlowReturn ret; GstFlowReturn ret;
const guint8 *data;
GstBuffer *sbuf; GstBuffer *sbuf;
gboolean keyframe; gboolean keyframe;
guint size, len, n, xsize = 0; guint len, n, xsize = 0;
data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf);
if ((data[0] & 0x01) != 0) if ((data[0] & 0x01) != 0)
goto invalid_startcode; goto invalid_startcode;
@ -857,9 +852,10 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
GstOgmParse *ogm = GST_OGM_PARSE (GST_PAD_PARENT (pad)); GstOgmParse *ogm = GST_OGM_PARSE (GST_PAD_PARENT (pad));
guint8 *data = GST_BUFFER_DATA (buf); guint8 *data;
guint size = GST_BUFFER_SIZE (buf); gsize size;
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
if (size < 1) if (size < 1)
goto buffer_too_small; goto buffer_too_small;
@ -875,11 +871,12 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf)
break; break;
} }
default:{ default:{
ret = gst_ogm_parse_data_packet (ogm, buf); ret = gst_ogm_parse_data_packet (ogm, buf, data, size);
break; break;
} }
} }
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
if (ret != GST_FLOW_OK) { if (ret != GST_FLOW_OK) {
@ -892,6 +889,7 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf)
buffer_too_small: buffer_too_small:
{ {
GST_ELEMENT_ERROR (ogm, STREAM, DECODE, (NULL), ("buffer too small")); GST_ELEMENT_ERROR (ogm, STREAM, DECODE, (NULL), ("buffer too small"));
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }

View file

@ -1754,12 +1754,16 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame)
gint width, height; gint width, height;
GstTextOverlayVAlign valign; GstTextOverlayVAlign valign;
GstTextOverlayHAlign halign; GstTextOverlayHAlign halign;
guint8 *data;
gsize size;
width = overlay->image_width; width = overlay->image_width;
height = overlay->image_height; height = overlay->image_height;
video_frame = gst_buffer_make_writable (video_frame); video_frame = gst_buffer_make_writable (video_frame);
data = gst_buffer_map (video_frame, &size, NULL, GST_MAP_WRITE);
if (overlay->use_vertical_render) if (overlay->use_vertical_render)
halign = GST_TEXT_OVERLAY_HALIGN_RIGHT; halign = GST_TEXT_OVERLAY_HALIGN_RIGHT;
else else
@ -1820,24 +1824,24 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame)
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21: case GST_VIDEO_FORMAT_NV21:
gst_text_overlay_shade_planar_Y (overlay, gst_text_overlay_shade_planar_Y (overlay, data,
GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, xpos, xpos + overlay->image_width,
ypos, ypos + overlay->image_height); ypos, ypos + overlay->image_height);
break; break;
case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV:
case GST_VIDEO_FORMAT_UYVY: case GST_VIDEO_FORMAT_UYVY:
gst_text_overlay_shade_packed_Y (overlay, gst_text_overlay_shade_packed_Y (overlay, data,
GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, xpos, xpos + overlay->image_width,
ypos, ypos + overlay->image_height); ypos, ypos + overlay->image_height);
break; break;
case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_xRGB:
gst_text_overlay_shade_xRGB (overlay, gst_text_overlay_shade_xRGB (overlay, data,
GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, xpos, xpos + overlay->image_width,
ypos, ypos + overlay->image_height); ypos, ypos + overlay->image_height);
break; break;
case GST_VIDEO_FORMAT_BGRx: case GST_VIDEO_FORMAT_BGRx:
gst_text_overlay_shade_BGRx (overlay, gst_text_overlay_shade_BGRx (overlay, data,
GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, xpos, xpos + overlay->image_width,
ypos, ypos + overlay->image_height); ypos, ypos + overlay->image_height);
break; break;
default: default:
@ -1851,34 +1855,30 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame)
if (overlay->text_image) { if (overlay->text_image) {
switch (overlay->format) { switch (overlay->format) {
case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_I420:
gst_text_overlay_blit_I420 (overlay, gst_text_overlay_blit_I420 (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV12:
case GST_VIDEO_FORMAT_NV21: case GST_VIDEO_FORMAT_NV21:
gst_text_overlay_blit_NV12_NV21 (overlay, gst_text_overlay_blit_NV12_NV21 (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
case GST_VIDEO_FORMAT_UYVY: case GST_VIDEO_FORMAT_UYVY:
gst_text_overlay_blit_UYVY (overlay, gst_text_overlay_blit_UYVY (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_AYUV:
gst_text_overlay_blit_AYUV (overlay, gst_text_overlay_blit_AYUV (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
case GST_VIDEO_FORMAT_BGRx: case GST_VIDEO_FORMAT_BGRx:
gst_text_overlay_blit_BGRx (overlay, gst_text_overlay_blit_BGRx (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
case GST_VIDEO_FORMAT_xRGB: case GST_VIDEO_FORMAT_xRGB:
gst_text_overlay_blit_xRGB (overlay, gst_text_overlay_blit_xRGB (overlay, data, xpos, ypos);
GST_BUFFER_DATA (video_frame), xpos, ypos);
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
} }
} }
gst_buffer_unmap (video_frame, data, size);
return gst_pad_push (overlay->srcpad, video_frame); return gst_pad_push (overlay->srcpad, video_frame);
} }
@ -2237,7 +2237,7 @@ gst_text_overlay_video_chain (GstPad * pad, GstBuffer * buffer)
/* if the buffer is only partially in the segment, fix up stamps */ /* if the buffer is only partially in the segment, fix up stamps */
if (clip_start != start || (stop != -1 && clip_stop != stop)) { if (clip_start != start || (stop != -1 && clip_stop != stop)) {
GST_DEBUG_OBJECT (overlay, "clipping buffer timestamp/duration to segment"); GST_DEBUG_OBJECT (overlay, "clipping buffer timestamp/duration to segment");
buffer = gst_buffer_make_metadata_writable (buffer); buffer = gst_buffer_make_writable (buffer);
GST_BUFFER_TIMESTAMP (buffer) = clip_start; GST_BUFFER_TIMESTAMP (buffer) = clip_start;
if (stop != -1) if (stop != -1)
GST_BUFFER_DURATION (buffer) = clip_stop - clip_start; GST_BUFFER_DURATION (buffer) = clip_stop - clip_start;
@ -2365,11 +2365,13 @@ wait_for_text_buf:
/* Push the video frame */ /* Push the video frame */
ret = gst_pad_push (overlay->srcpad, buffer); ret = gst_pad_push (overlay->srcpad, buffer);
} else { } else {
gchar *in_text; gchar *in_text, *otext;
gsize in_size; gsize in_size, osize;
in_text = (gchar *) GST_BUFFER_DATA (overlay->text_buffer); otext =
in_size = GST_BUFFER_SIZE (overlay->text_buffer); gst_buffer_map (overlay->text_buffer, &osize, NULL, GST_MAP_READ);
in_text = otext;
in_size = osize;
/* g_markup_escape_text() absolutely requires valid UTF8 input, it /* g_markup_escape_text() absolutely requires valid UTF8 input, it
* might crash otherwise. We don't fall back on GST_SUBTITLE_ENCODING * might crash otherwise. We don't fall back on GST_SUBTITLE_ENCODING
@ -2403,8 +2405,9 @@ wait_for_text_buf:
GST_DEBUG_OBJECT (overlay, "No text to render (empty buffer)"); GST_DEBUG_OBJECT (overlay, "No text to render (empty buffer)");
gst_text_overlay_render_text (overlay, " ", 1); gst_text_overlay_render_text (overlay, " ", 1);
} }
gst_buffer_unmap (overlay->text_buffer, otext, osize);
if (in_text != (gchar *) GST_BUFFER_DATA (overlay->text_buffer)) if (in_text != otext)
g_free (in_text); g_free (in_text);
GST_OBJECT_UNLOCK (overlay); GST_OBJECT_UNLOCK (overlay);

View file

@ -466,13 +466,15 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
GstFlowReturn ret; GstFlowReturn ret;
GstBuffer *outbuf; GstBuffer *outbuf;
GstCaps *caps = NULL; GstCaps *caps = NULL;
guint8 *data = GST_BUFFER_DATA (inbuf); guint8 *data;
guint size = GST_BUFFER_SIZE (inbuf); gsize size;
gint n; gint n;
gint xpos, ypos; gint xpos, ypos;
render = GST_TEXT_RENDER (gst_pad_get_parent (pad)); render = GST_TEXT_RENDER (gst_pad_get_parent (pad));
data = gst_buffer_map (inbuf, &size, NULL, GST_MAP_READ);
/* somehow pango barfs over "\0" buffers... */ /* somehow pango barfs over "\0" buffers... */
while (size > 0 && while (size > 0 &&
(data[size - 1] == '\r' || (data[size - 1] == '\r' ||
@ -484,6 +486,7 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
GST_DEBUG ("rendering '%*s'", size, data); GST_DEBUG ("rendering '%*s'", size, data);
pango_layout_set_markup (render->layout, (gchar *) data, size); pango_layout_set_markup (render->layout, (gchar *) data, size);
gst_text_render_render_pangocairo (render); gst_text_render_render_pangocairo (render);
gst_buffer_unmap (inbuf, data, size);
gst_text_render_check_argb (render); gst_text_render_check_argb (render);
@ -512,8 +515,8 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto done; goto done;
gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS); gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
data = GST_BUFFER_DATA (outbuf); data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE);
if (render->use_ARGB) { if (render->use_ARGB) {
memset (data, 0, render->width * render->height * 4); memset (data, 0, render->width * render->height * 4);
@ -562,6 +565,7 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
render->width * 4); render->width * 4);
} }
} }
gst_buffer_unmap (outbuf, data, size);
ret = gst_pad_push (render->srcpad, outbuf); ret = gst_pad_push (render->srcpad, outbuf);

View file

@ -716,28 +716,30 @@ theora_dec_setcaps (GstPad * pad, GstCaps * caps)
if ((codec_data = gst_structure_get_value (s, "codec_data"))) { if ((codec_data = gst_structure_get_value (s, "codec_data"))) {
if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) { if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) {
GstBuffer *buffer; GstBuffer *buffer;
guint8 *data; guint8 *data, *ptr;
guint size; gsize size, left;
guint offset; guint offset;
buffer = gst_value_get_buffer (codec_data); buffer = gst_value_get_buffer (codec_data);
offset = 0; offset = 0;
size = GST_BUFFER_SIZE (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buffer);
while (size > 2) { ptr = data;
left = size;
while (left > 2) {
guint psize; guint psize;
GstBuffer *buf; GstBuffer *buf;
psize = (data[0] << 8) | data[1]; psize = (ptr[0] << 8) | ptr[1];
/* skip header */ /* skip header */
data += 2; ptr += 2;
size -= 2; left -= 2;
offset += 2; offset += 2;
/* make sure we don't read too much */ /* make sure we don't read too much */
psize = MIN (psize, size); psize = MIN (psize, left);
buf = gst_buffer_create_sub (buffer, offset, psize); buf = gst_buffer_create_sub (buffer, offset, psize);
@ -749,10 +751,11 @@ theora_dec_setcaps (GstPad * pad, GstCaps * caps)
theora_dec_chain (pad, buf); theora_dec_chain (pad, buf);
/* skip the data */ /* skip the data */
size -= psize; left -= psize;
data += psize; ptr += psize;
offset += psize; offset += psize;
} }
gst_buffer_unmap (buffer, data, size);
} }
} }
@ -765,20 +768,13 @@ static GstFlowReturn
theora_handle_comment_packet (GstTheoraDec * dec, ogg_packet * packet) theora_handle_comment_packet (GstTheoraDec * dec, ogg_packet * packet)
{ {
gchar *encoder = NULL; gchar *encoder = NULL;
GstBuffer *buf;
GstTagList *list; GstTagList *list;
GST_DEBUG_OBJECT (dec, "parsing comment packet"); GST_DEBUG_OBJECT (dec, "parsing comment packet");
buf = gst_buffer_new ();
GST_BUFFER_SIZE (buf) = packet->bytes;
GST_BUFFER_DATA (buf) = packet->packet;
list = list =
gst_tag_list_from_vorbiscomment_buffer (buf, (guint8 *) "\201theora", 7, gst_tag_list_from_vorbiscomment (packet->packet, packet->bytes,
&encoder); (guint8 *) "\201theora", 7, &encoder);
gst_buffer_unref (buf);
if (!list) { if (!list) {
GST_ERROR_OBJECT (dec, "couldn't decode comments"); GST_ERROR_OBJECT (dec, "couldn't decode comments");
@ -1056,6 +1052,8 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out)
int i, plane; int i, plane;
GstVideoFormat format; GstVideoFormat format;
guint8 *dest, *src; guint8 *dest, *src;
gsize size;
guint8 *data;
switch (dec->info.pixel_fmt) { switch (dec->info.pixel_fmt) {
case TH_PF_444: case TH_PF_444:
@ -1081,13 +1079,14 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out)
return result; return result;
} }
data = gst_buffer_map (*out, &size, NULL, GST_MAP_WRITE);
for (plane = 0; plane < 3; plane++) { for (plane = 0; plane < 3; plane++) {
width = gst_video_format_get_component_width (format, plane, dec->width); width = gst_video_format_get_component_width (format, plane, dec->width);
height = gst_video_format_get_component_height (format, plane, dec->height); height = gst_video_format_get_component_height (format, plane, dec->height);
stride = gst_video_format_get_row_stride (format, plane, dec->width); stride = gst_video_format_get_row_stride (format, plane, dec->width);
dest = dest = data + gst_video_format_get_component_offset (format,
GST_BUFFER_DATA (*out) + gst_video_format_get_component_offset (format,
plane, dec->width, dec->height); plane, dec->width, dec->height);
src = buf[plane].data; src = buf[plane].data;
src += ((height == dec->height) ? dec->offset_y : dec->offset_y / 2) src += ((height == dec->height) ? dec->offset_y : dec->offset_y / 2)
@ -1101,6 +1100,7 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out)
src += buf[plane].stride; src += buf[plane].stride;
} }
} }
gst_buffer_unmap (*out, data, size);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -1268,10 +1268,11 @@ theora_dec_decode_buffer (GstTheoraDec * dec, GstBuffer * buf)
ogg_packet packet; ogg_packet packet;
GstFlowReturn result = GST_FLOW_OK; GstFlowReturn result = GST_FLOW_OK;
GstClockTime timestamp, duration; GstClockTime timestamp, duration;
gsize size;
/* make ogg_packet out of the buffer */ /* make ogg_packet out of the buffer */
packet.packet = GST_BUFFER_DATA (buf); packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
packet.bytes = GST_BUFFER_SIZE (buf); packet.bytes = size;
packet.granulepos = -1; packet.granulepos = -1;
packet.packetno = 0; /* we don't really care */ packet.packetno = 0; /* we don't really care */
packet.b_o_s = dec->have_header ? 0 : 1; packet.b_o_s = dec->have_header ? 0 : 1;
@ -1299,8 +1300,9 @@ theora_dec_decode_buffer (GstTheoraDec * dec, GstBuffer * buf)
} else { } else {
result = theora_handle_data_packet (dec, &packet, timestamp, duration); result = theora_handle_data_packet (dec, &packet, timestamp, duration);
} }
done: done:
gst_buffer_unmap (buf, packet.packet, size);
return result; return result;
} }
@ -1430,7 +1432,7 @@ theora_dec_chain_reverse (GstTheoraDec * dec, gboolean discont, GstBuffer * buf)
GST_DEBUG_OBJECT (dec, "received discont,gathering buffers"); GST_DEBUG_OBJECT (dec, "received discont,gathering buffers");
while (dec->gather) { while (dec->gather) {
GstBuffer *gbuf; GstBuffer *gbuf;
guint8 *data; guint8 data[1];
gbuf = GST_BUFFER_CAST (dec->gather->data); gbuf = GST_BUFFER_CAST (dec->gather->data);
/* remove from the gather list */ /* remove from the gather list */
@ -1439,7 +1441,7 @@ theora_dec_chain_reverse (GstTheoraDec * dec, gboolean discont, GstBuffer * buf)
dec->decode = g_list_prepend (dec->decode, gbuf); dec->decode = g_list_prepend (dec->decode, gbuf);
/* if we copied a keyframe, flush and decode the decode queue */ /* if we copied a keyframe, flush and decode the decode queue */
data = GST_BUFFER_DATA (gbuf); gst_buffer_extract (gbuf, 0, data, 1);
if ((data[0] & 0x40) == 0) { if ((data[0] & 0x40) == 0) {
GST_DEBUG_OBJECT (dec, "copied keyframe"); GST_DEBUG_OBJECT (dec, "copied keyframe");
res = theora_dec_flush_decode (dec); res = theora_dec_flush_decode (dec);
@ -1449,7 +1451,7 @@ theora_dec_chain_reverse (GstTheoraDec * dec, gboolean discont, GstBuffer * buf)
/* add buffer to gather queue */ /* add buffer to gather queue */
GST_DEBUG_OBJECT (dec, "gathering buffer %p, size %u", buf, GST_DEBUG_OBJECT (dec, "gathering buffer %p, size %u", buf,
GST_BUFFER_SIZE (buf)); gst_buffer_get_size (buf));
dec->gather = g_list_prepend (dec->gather, buf); dec->gather = g_list_prepend (dec->gather, buf);
return res; return res;

View file

@ -748,7 +748,7 @@ theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet,
goto done; goto done;
} }
memcpy (GST_BUFFER_DATA (buf), packet->packet, packet->bytes); gst_buffer_fill (buf, 0, packet->packet, packet->bytes);
gst_buffer_set_caps (buf, GST_PAD_CAPS (enc->srcpad)); 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 */
@ -786,7 +786,7 @@ theora_push_buffer (GstTheoraEnc * enc, GstBuffer * buffer)
{ {
GstFlowReturn ret; GstFlowReturn ret;
enc->bytes_out += GST_BUFFER_SIZE (buffer); enc->bytes_out += gst_buffer_get_size (buffer);
ret = gst_pad_push (enc->srcpad, buffer); ret = gst_pad_push (enc->srcpad, buffer);
@ -1049,17 +1049,21 @@ theora_enc_read_multipass_cache (GstTheoraEnc * enc)
while (!done) { while (!done) {
if (gst_adapter_available (enc->multipass_cache_adapter) == 0) { if (gst_adapter_available (enc->multipass_cache_adapter) == 0) {
guint8 *data;
gsize size;
cache_buf = gst_buffer_new_and_alloc (512); cache_buf = gst_buffer_new_and_alloc (512);
data = gst_buffer_map (cache_buf, &size, NULL, GST_MAP_READ);
stat = g_io_channel_read_chars (enc->multipass_cache_fd, stat = g_io_channel_read_chars (enc->multipass_cache_fd,
(gchar *) GST_BUFFER_DATA (cache_buf), GST_BUFFER_SIZE (cache_buf), (gchar *) data, size, &bytes_read, NULL);
&bytes_read, NULL);
if (bytes_read <= 0) { if (bytes_read <= 0) {
gst_buffer_unmap (cache_buf, data, 0);
gst_buffer_unref (cache_buf); gst_buffer_unref (cache_buf);
break; break;
} else { } else {
GST_BUFFER_SIZE (cache_buf) = bytes_read; gst_buffer_unmap (cache_buf, data, bytes_read);
gst_adapter_push (enc->multipass_cache_adapter, cache_buf); gst_adapter_push (enc->multipass_cache_adapter, cache_buf);
} }
} }
@ -1069,11 +1073,13 @@ theora_enc_read_multipass_cache (GstTheoraEnc * enc)
bytes_read = bytes_read =
MIN (gst_adapter_available (enc->multipass_cache_adapter), 512); MIN (gst_adapter_available (enc->multipass_cache_adapter), 512);
cache_data = gst_adapter_peek (enc->multipass_cache_adapter, bytes_read); cache_data = gst_adapter_map (enc->multipass_cache_adapter, bytes_read);
bytes_consumed = bytes_consumed =
th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_IN, (guint8 *) cache_data, th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_IN, (guint8 *) cache_data,
bytes_read); bytes_read);
gst_adapter_unmap (enc->multipass_cache_adapter, 0);
done = bytes_consumed <= 0; done = bytes_consumed <= 0;
if (bytes_consumed > 0) if (bytes_consumed > 0)
gst_adapter_flush (enc->multipass_cache_adapter, bytes_consumed); gst_adapter_flush (enc->multipass_cache_adapter, bytes_consumed);
@ -1258,8 +1264,11 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
{ {
th_ycbcr_buffer ycbcr; th_ycbcr_buffer ycbcr;
gint res; gint res;
guint8 *data;
gsize size;
theora_enc_init_buffer (ycbcr, &enc->info, GST_BUFFER_DATA (buffer)); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
theora_enc_init_buffer (ycbcr, &enc->info, data);
if (theora_enc_is_discontinuous (enc, running_time, duration)) { if (theora_enc_is_discontinuous (enc, running_time, duration)) {
theora_enc_reset (enc); theora_enc_reset (enc);
@ -1274,6 +1283,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
if (enc->multipass_cache_fd if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) { && enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) {
if (!theora_enc_read_multipass_cache (enc)) { if (!theora_enc_read_multipass_cache (enc)) {
gst_buffer_unmap (buffer, data, size);
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
goto multipass_read_failed; goto multipass_read_failed;
} }
@ -1286,6 +1296,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
if (enc->multipass_cache_fd if (enc->multipass_cache_fd
&& enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) { && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) {
if (!theora_enc_write_multipass_cache (enc)) { if (!theora_enc_write_multipass_cache (enc)) {
gst_buffer_unmap (buffer, data, size);
ret = GST_FLOW_ERROR; ret = GST_FLOW_ERROR;
goto multipass_write_failed; goto multipass_write_failed;
} }
@ -1302,9 +1313,12 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer)
next_time - enc->next_ts); next_time - enc->next_ts);
enc->next_ts = next_time; enc->next_ts = next_time;
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK) {
gst_buffer_unmap (buffer, data, size);
goto data_push; goto data_push;
}
} }
gst_buffer_unmap (buffer, data, size);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
} }

View file

@ -267,7 +267,7 @@ theora_parse_set_header_on_caps (GstTheoraParse * parse, GstCaps * caps)
if (bufs[i] == NULL) if (bufs[i] == NULL)
continue; continue;
bufs[i] = gst_buffer_make_metadata_writable (bufs[i]); bufs[i] = gst_buffer_make_writable (bufs[i]);
GST_BUFFER_FLAG_SET (bufs[i], GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (bufs[i], GST_BUFFER_FLAG_IN_CAPS);
g_value_init (&value, GST_TYPE_BUFFER); g_value_init (&value, GST_TYPE_BUFFER);
@ -367,7 +367,7 @@ theora_parse_push_headers (GstTheoraParse * parse)
GstBuffer *buf; GstBuffer *buf;
if ((buf = parse->streamheader[i])) { if ((buf = parse->streamheader[i])) {
buf = gst_buffer_make_metadata_writable (buf); buf = gst_buffer_make_writable (buf);
gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad)); gst_buffer_set_caps (buf, GST_PAD_CAPS (parse->srcpad));
gst_pad_push (parse->srcpad, buf); gst_pad_push (parse->srcpad, buf);
parse->streamheader[i] = NULL; parse->streamheader[i] = NULL;
@ -624,7 +624,7 @@ theora_parse_queue_buffer (GstTheoraParse * parse, GstBuffer * buf)
{ {
GstFlowReturn ret = GST_FLOW_OK; GstFlowReturn ret = GST_FLOW_OK;
buf = gst_buffer_make_metadata_writable (buf); buf = gst_buffer_make_writable (buf);
g_queue_push_tail (parse->buffer_queue, buf); g_queue_push_tail (parse->buffer_queue, buf);

View file

@ -364,7 +364,7 @@ convert_failed:
} }
/** /**
* gst_tag_list_from_vorbiscomment_buffer: * gst_tag_list_from_vorbiscomment:
* @data: data to convert * @data: data to convert
* @size: size of @data * @size: size of @data
* @id_data: identification data at start of stream * @id_data: identification data at start of stream
@ -453,6 +453,37 @@ error:
#undef ADVANCE #undef ADVANCE
} }
/**
* gst_tag_list_from_vorbiscomment_buffer:
* @buffer: buffer to convert
* @id_data: identification data at start of stream
* @id_data_length: length of identification data
* @vendor_string: pointer to a string that should take the vendor string
* of this vorbis comment or NULL if you don't need it.
*
* Creates a new tag list that contains the information parsed out of a
* vorbiscomment packet.
*
* Returns: A new #GstTagList with all tags that could be extracted from the
* given vorbiscomment buffer or NULL on error.
*/
GstTagList *
gst_tag_list_from_vorbiscomment_buffer (GstBuffer * buffer,
const guint8 * id_data, const guint id_data_length, gchar ** vendor_string)
{
GstTagList *res;
guint8 *data;
gsize size;
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
res =
gst_tag_list_from_vorbiscomment (data, size, id_data, id_data_length,
vendor_string);
gst_buffer_unmap (buffer, data, size);
return res;
}
typedef struct typedef struct
{ {
guint count; guint count;

View file

@ -450,6 +450,10 @@ GstTagList * gst_tag_list_from_vorbiscomment (const guint8 *
const guint8 * id_data, const guint8 * id_data,
const guint id_data_length, const guint id_data_length,
gchar ** vendor_string); gchar ** vendor_string);
GstTagList * gst_tag_list_from_vorbiscomment_buffer (GstBuffer * buffer,
const guint8 * id_data,
const guint id_data_length,
gchar ** vendor_string);
GstBuffer * gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list, GstBuffer * gst_tag_list_to_vorbiscomment_buffer (const GstTagList * list,
const guint8 * id_data, const guint8 * id_data,
const guint id_data_length, const guint id_data_length,