From f379a5dacb2557a84200ea489e7a3e948fee7511 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 27 Mar 2011 18:30:24 +0200 Subject: [PATCH] plugins: more porting to new memory API --- ext/libvisual/visual.c | 11 ++++++-- ext/ogg/gstoggaviparse.c | 38 ++++++++++++++------------- ext/ogg/gstoggdemux.c | 17 ++++++------ ext/ogg/gstoggmux.c | 36 ++++++++++++++++--------- ext/ogg/gstoggparse.c | 17 ++++++------ ext/ogg/gstoggstream.c | 11 ++------ ext/ogg/gstogmparse.c | 30 ++++++++++----------- ext/pango/gsttextoverlay.c | 55 ++++++++++++++++++++------------------ ext/pango/gsttextrender.c | 12 ++++++--- ext/theora/gsttheoradec.c | 58 +++++++++++++++++++++-------------------- ext/theora/gsttheoraenc.c | 32 ++++++++++++++++------- ext/theora/gsttheoraparse.c | 6 ++--- gst-libs/gst/tag/gstvorbistag.c | 33 ++++++++++++++++++++++- gst-libs/gst/tag/tag.h | 4 +++ 14 files changed, 215 insertions(+), 145 deletions(-) diff --git a/ext/libvisual/visual.c b/ext/libvisual/visual.c index 6a69c35..6c71c05 100644 --- a/ext/libvisual/visual.c +++ b/ext/libvisual/visual.c @@ -651,6 +651,8 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer) gboolean need_skip; const guint16 *data; guint64 dist, timestamp; + guint8 *outdata; + gsize outsize; GST_DEBUG_OBJECT (visual, "processing buffer"); @@ -697,7 +699,7 @@ gst_visual_chain (GstPad * pad, GstBuffer * buffer) /* Read VISUAL_SAMPLES samples per channel */ data = - (const guint16 *) gst_adapter_peek (visual->adapter, + (const guint16 *) gst_adapter_map (visual->adapter, VISUAL_SAMPLES * visual->bps); #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) { ret = get_buffer (visual, &outbuf); if (ret != GST_FLOW_OK) { + gst_adapter_unmap (visual->adapter, 0); 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_actor_run (visual->actor, visual->audio); visual_video_set_buffer (visual->video, NULL); + gst_buffer_unmap (outbuf, outdata, outsize); GST_DEBUG_OBJECT (visual, "rendered one frame"); + gst_adapter_unmap (visual->adapter, 0); + GST_BUFFER_TIMESTAMP (outbuf) = timestamp; GST_BUFFER_DURATION (outbuf) = visual->duration; diff --git a/ext/ogg/gstoggaviparse.c b/ext/ogg/gstoggaviparse.c index 2851e52..b9e1dc9 100644 --- a/ext/ogg/gstoggaviparse.c +++ b/ext/ogg/gstoggaviparse.c @@ -196,8 +196,8 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps) GstStructure *structure; const GValue *codec_data; GstBuffer *buffer; - guint8 *data; - guint size; + guint8 *data, *ptr; + gsize size, left; guint32 sizes[3]; GstCaps *outcaps; 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 * Then we get 3 LE guint32 with the 3 header sizes * then we get the bytes of the 3 headers. */ - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); + + ptr = data; + left = size; - GST_LOG_OBJECT (ogg, "configuring codec_data of size %u", size); + GST_LOG_OBJECT (ogg, "configuring codec_data of size %u", left); /* skip headers */ - data += 22; - size -= 22; + ptr += 22; + left -= 22; /* we need at least 12 bytes for the packet sizes of the 3 headers */ - if (size < 12) + if (left < 12) goto buffer_too_small; /* read sizes of the 3 headers */ - sizes[0] = GST_READ_UINT32_LE (data); - sizes[1] = GST_READ_UINT32_LE (data + 4); - sizes[2] = GST_READ_UINT32_LE (data + 8); + sizes[0] = GST_READ_UINT32_LE (ptr); + sizes[1] = GST_READ_UINT32_LE (ptr + 4); + sizes[2] = GST_READ_UINT32_LE (ptr + 8); GST_DEBUG_OBJECT (ogg, "header sizes: %u %u %u", sizes[0], sizes[1], sizes[2]); - size -= 12; + left -= 12; /* 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; /* set caps */ @@ -264,6 +266,7 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps) offs += sizes[i]; } + gst_buffer_unmap (buffer, data, size); gst_caps_unref (outcaps); return TRUE; @@ -282,6 +285,7 @@ wrong_format: buffer_too_small: { GST_DEBUG_OBJECT (ogg, "codec_data is too small"); + gst_buffer_unmap (buffer, data, size); return FALSE; } } @@ -319,7 +323,7 @@ gst_ogg_avi_parse_push_packet (GstOggAviParse * ogg, ogg_packet * packet) /* allocate space for header and body */ 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); @@ -340,15 +344,13 @@ gst_ogg_avi_parse_chain (GstPad * pad, GstBuffer * buffer) { GstFlowReturn result = GST_FLOW_OK; GstOggAviParse *ogg; - guint8 *data; guint size; gchar *oggbuf; gint ret = -1; ogg = GST_OGG_AVI_PARSE (GST_OBJECT_PARENT (pad)); - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); + size = gst_buffer_get_size (buffer); 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 */ oggbuf = ogg_sync_buffer (&ogg->sync, size); - memcpy (oggbuf, data, size); + gst_buffer_extract (buffer, 0, oggbuf, size); ogg_sync_wrote (&ogg->sync, size); gst_buffer_unref (buffer); diff --git a/ext/ogg/gstoggdemux.c b/ext/ogg/gstoggdemux.c index b27a9a7..14b8564 100644 --- a/ext/ogg/gstoggdemux.c +++ b/ext/ogg/gstoggdemux.c @@ -581,7 +581,8 @@ gst_ogg_demux_chain_peer (GstOggPad * pad, ogg_packet * packet, GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT); /* 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_DURATION (buf) = out_duration; @@ -1400,15 +1401,14 @@ gst_ogg_demux_sink_event (GstPad * pad, GstEvent * event) static GstFlowReturn gst_ogg_demux_submit_buffer (GstOggDemux * ogg, GstBuffer * buffer) { - gint size; + gsize size; guint8 *data; gchar *oggbuffer; GstFlowReturn ret = GST_FLOW_OK; - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); - GST_DEBUG_OBJECT (ogg, "submitting %u bytes", size); + GST_DEBUG_OBJECT (ogg, "submitting %" G_GSIZE_FORMAT " bytes", size); if (G_UNLIKELY (size == 0)) goto done; @@ -1421,6 +1421,7 @@ gst_ogg_demux_submit_buffer (GstOggDemux * ogg, GstBuffer * buffer) goto write_failed; done: + gst_buffer_unmap (buffer, data, size); gst_buffer_unref (buffer); return ret; @@ -1479,7 +1480,7 @@ gst_ogg_demux_get_data (GstOggDemux * ogg, gint64 end_offset) if (ret != GST_FLOW_OK) 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); @@ -1725,7 +1726,7 @@ gst_ogg_demux_set_header_on_caps (GstOggDemux * ogg, GstCaps * caps, ogg_packet *op = headers->data; g_assert (op); 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); g_value_init (&value, GST_TYPE_BUFFER); gst_value_take_buffer (&value, buffer); @@ -3272,7 +3273,7 @@ gst_ogg_demux_loop_forward (GstOggDemux * ogg) goto done; } - ogg->offset += GST_BUFFER_SIZE (buffer); + ogg->offset += gst_buffer_get_size (buffer); if (G_UNLIKELY (ogg->newsegment)) { gst_ogg_demux_send_event (ogg, ogg->newsegment); diff --git a/ext/ogg/gstoggmux.c b/ext/ogg/gstoggmux.c index f2194f5..26da8a6 100644 --- a/ext/ogg/gstoggmux.c +++ b/ext/ogg/gstoggmux.c @@ -494,9 +494,8 @@ gst_ogg_mux_buffer_from_page (GstOggMux * mux, ogg_page * page, gboolean delta) /* allocate space for header and body */ buffer = gst_buffer_new_and_alloc (page->header_len + page->body_len); - memcpy (GST_BUFFER_DATA (buffer), page->header, page->header_len); - memcpy (GST_BUFFER_DATA (buffer) + page->header_len, - page->body, page->body_len); + gst_buffer_fill (buffer, 0, page->header, page->header_len); + gst_buffer_fill (buffer, page->header_len, page->body, page->body_len); /* 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 @@ -519,7 +518,7 @@ gst_ogg_mux_push_buffer (GstOggMux * mux, GstBuffer * buffer) /* fix up OFFSET and OFFSET_END again */ 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; /* 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 */ ogg_packet packet; gboolean is_header; + gsize size; - packet.packet = GST_BUFFER_DATA (buf); - packet.bytes = GST_BUFFER_SIZE (buf); + packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + packet.bytes = size; if (GST_BUFFER_OFFSET_END_IS_VALID (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) */ is_header = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_IN_CAPS); + gst_buffer_unmap (buf, packet.packet, size); + if (is_header) { GST_DEBUG_OBJECT (ogg_mux, "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; /* 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); g_value_init (&value, GST_TYPE_BUFFER); @@ -1046,6 +1049,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux) GstCaps *caps; GstStructure *structure; GstBuffer *hbuf; + gsize size; pad = (GstOggPadData *) walk->data; thepad = pad->collect.pad; @@ -1077,8 +1081,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux) } /* create a packet from the buffer */ - packet.packet = GST_BUFFER_DATA (buf); - packet.bytes = GST_BUFFER_SIZE (buf); + packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + packet.bytes = size; packet.granulepos = GST_BUFFER_OFFSET_END (buf); if (packet.granulepos == -1) packet.granulepos = 0; @@ -1090,6 +1094,8 @@ gst_ogg_mux_send_headers (GstOggMux * mux) /* swap the packet in */ ogg_stream_packetin (&pad->map.stream, &packet); + + gst_buffer_unmap (buf, packet.packet, size); gst_buffer_unref (buf); 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); ogg_packet packet; ogg_page page; + gsize size; hwalk = hwalk->next; /* create a packet from the buffer */ - packet.packet = GST_BUFFER_DATA (buf); - packet.bytes = GST_BUFFER_SIZE (buf); + packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + packet.bytes = size; packet.granulepos = GST_BUFFER_OFFSET_END (buf); if (packet.granulepos == -1) packet.granulepos = 0; @@ -1159,6 +1166,7 @@ gst_ogg_mux_send_headers (GstOggMux * mux) /* swap the packet in */ ogg_stream_packetin (&pad->map.stream, &packet); + gst_buffer_unmap (buf, packet.packet, size); gst_buffer_unref (buf); /* 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; gint64 duration; gboolean force_flush; + gsize size; 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))); } /* create a packet from the buffer */ - packet.packet = GST_BUFFER_DATA (buf); - packet.bytes = GST_BUFFER_SIZE (buf); + packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + packet.bytes = size; packet.granulepos = GST_BUFFER_OFFSET_END (buf); if (packet.granulepos == -1) 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"); ogg_stream_packetin (&pad->map.stream, &packet); + gst_buffer_unmap (buf, packet.packet, size); pad->data_pushed = TRUE; gp_time = GST_BUFFER_OFFSET (pad->buffer); diff --git a/ext/ogg/gstoggparse.c b/ext/ogg/gstoggparse.c index ffbba86..ce1488e 100644 --- a/ext/ogg/gstoggparse.c +++ b/ext/ogg/gstoggparse.c @@ -286,15 +286,14 @@ gst_ogg_parse_dispose (GObject * object) static GstFlowReturn gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer) { - guint size; + gsize size; guint8 *data; gchar *oggbuffer; GstFlowReturn ret = GST_FLOW_OK; - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); - GST_DEBUG_OBJECT (ogg, "submitting %u bytes", size); + GST_DEBUG_OBJECT (ogg, "submitting %" G_GSIZE_FORMAT " bytes", size); if (G_UNLIKELY (size == 0)) goto done; @@ -314,6 +313,7 @@ gst_ogg_parse_submit_buffer (GstOggParse * ogg, GstBuffer * buffer) } done: + gst_buffer_unmap (buffer, data, size); gst_buffer_unref (buffer); return ret; @@ -368,8 +368,8 @@ gst_ogg_parse_buffer_from_page (ogg_page * page, int size = page->header_len + page->body_len; GstBuffer *buf = gst_buffer_new_and_alloc (size); - memcpy (GST_BUFFER_DATA (buf), page->header, page->header_len); - memcpy (GST_BUFFER_DATA (buf) + page->header_len, page->body, page->body_len); + gst_buffer_fill (buf, 0, page->header, page->header_len); + gst_buffer_fill (buf, page->header_len, page->body, page->body_len); GST_BUFFER_TIMESTAMP (buf) = timestamp; 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)); - GST_LOG_OBJECT (ogg, "Chain function received buffer of size %d", - GST_BUFFER_SIZE (buffer)); + GST_LOG_OBJECT (ogg, + "Chain function received buffer of size %" G_GSIZE_FORMAT, + gst_buffer_get_size (buffer)); gst_ogg_parse_submit_buffer (ogg, buffer); diff --git a/ext/ogg/gstoggstream.c b/ext/ogg/gstoggstream.c index caa9865..d192668 100644 --- a/ext/ogg/gstoggstream.c +++ b/ext/ogg/gstoggstream.c @@ -303,19 +303,14 @@ static gboolean tag_list_from_vorbiscomment_packet (ogg_packet * packet, const guint8 * id_data, const guint id_data_length, GstTagList ** tags) { - GstBuffer *buf = NULL; gchar *encoder = NULL; GstTagList *list; gboolean ret = TRUE; g_return_val_if_fail (tags != NULL, FALSE); - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) packet->packet; - GST_BUFFER_SIZE (buf) = packet->bytes; - - list = gst_tag_list_from_vorbiscomment_buffer (buf, id_data, id_data_length, - &encoder); + list = gst_tag_list_from_vorbiscomment (packet->packet, packet->bytes, + id_data, id_data_length, &encoder); if (!list) { GST_WARNING ("failed to decode vorbis comments"); @@ -335,8 +330,6 @@ exit: gst_tag_list_free (*tags); *tags = list; - gst_buffer_unref (buf); - return ret; } diff --git a/ext/ogg/gstogmparse.c b/ext/ogg/gstogmparse.c index 6b054a2..271296b 100644 --- a/ext/ogg/gstogmparse.c +++ b/ext/ogg/gstogmparse.c @@ -725,32 +725,27 @@ gst_ogm_parse_comment_packet (GstOgmParse * ogm, GstBuffer * buf) static void gst_ogm_text_parse_strip_trailing_zeroes (GstOgmParse * ogm, GstBuffer * buf) { - const guint8 *data; - guint size; + guint8 *data; + 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 */ - data = GST_BUFFER_DATA (buf); - size = GST_BUFFER_SIZE (buf); + data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE); while (size > 0 && data[size - 1] == '\0') { --size; } - - GST_BUFFER_SIZE (buf) = size; + gst_buffer_unmap (buf, data, size); } 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; - const guint8 *data; GstBuffer *sbuf; gboolean keyframe; - guint size, len, n, xsize = 0; - - data = GST_BUFFER_DATA (buf); - size = GST_BUFFER_SIZE (buf); + guint len, n, xsize = 0; if ((data[0] & 0x01) != 0) goto invalid_startcode; @@ -857,9 +852,10 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf) { GstFlowReturn ret = GST_FLOW_OK; GstOgmParse *ogm = GST_OGM_PARSE (GST_PAD_PARENT (pad)); - guint8 *data = GST_BUFFER_DATA (buf); - guint size = GST_BUFFER_SIZE (buf); + guint8 *data; + gsize size; + data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); if (size < 1) goto buffer_too_small; @@ -875,11 +871,12 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf) break; } default:{ - ret = gst_ogm_parse_data_packet (ogm, buf); + ret = gst_ogm_parse_data_packet (ogm, buf, data, size); break; } } + gst_buffer_unmap (buf, data, size); gst_buffer_unref (buf); if (ret != GST_FLOW_OK) { @@ -892,6 +889,7 @@ gst_ogm_parse_chain (GstPad * pad, GstBuffer * buf) buffer_too_small: { GST_ELEMENT_ERROR (ogm, STREAM, DECODE, (NULL), ("buffer too small")); + gst_buffer_unmap (buf, data, size); gst_buffer_unref (buf); return GST_FLOW_ERROR; } diff --git a/ext/pango/gsttextoverlay.c b/ext/pango/gsttextoverlay.c index ca38dc1..4957ce8 100644 --- a/ext/pango/gsttextoverlay.c +++ b/ext/pango/gsttextoverlay.c @@ -1754,12 +1754,16 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame) gint width, height; GstTextOverlayVAlign valign; GstTextOverlayHAlign halign; + guint8 *data; + gsize size; width = overlay->image_width; height = overlay->image_height; video_frame = gst_buffer_make_writable (video_frame); + data = gst_buffer_map (video_frame, &size, NULL, GST_MAP_WRITE); + if (overlay->use_vertical_render) halign = GST_TEXT_OVERLAY_HALIGN_RIGHT; else @@ -1820,24 +1824,24 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame) case GST_VIDEO_FORMAT_I420: case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV21: - gst_text_overlay_shade_planar_Y (overlay, - GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, + gst_text_overlay_shade_planar_Y (overlay, data, + xpos, xpos + overlay->image_width, ypos, ypos + overlay->image_height); break; case GST_VIDEO_FORMAT_AYUV: case GST_VIDEO_FORMAT_UYVY: - gst_text_overlay_shade_packed_Y (overlay, - GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, + gst_text_overlay_shade_packed_Y (overlay, data, + xpos, xpos + overlay->image_width, ypos, ypos + overlay->image_height); break; case GST_VIDEO_FORMAT_xRGB: - gst_text_overlay_shade_xRGB (overlay, - GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, + gst_text_overlay_shade_xRGB (overlay, data, + xpos, xpos + overlay->image_width, ypos, ypos + overlay->image_height); break; case GST_VIDEO_FORMAT_BGRx: - gst_text_overlay_shade_BGRx (overlay, - GST_BUFFER_DATA (video_frame), xpos, xpos + overlay->image_width, + gst_text_overlay_shade_BGRx (overlay, data, + xpos, xpos + overlay->image_width, ypos, ypos + overlay->image_height); break; default: @@ -1851,34 +1855,30 @@ gst_text_overlay_push_frame (GstTextOverlay * overlay, GstBuffer * video_frame) if (overlay->text_image) { switch (overlay->format) { case GST_VIDEO_FORMAT_I420: - gst_text_overlay_blit_I420 (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_I420 (overlay, data, xpos, ypos); break; case GST_VIDEO_FORMAT_NV12: case GST_VIDEO_FORMAT_NV21: - gst_text_overlay_blit_NV12_NV21 (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_NV12_NV21 (overlay, data, xpos, ypos); break; case GST_VIDEO_FORMAT_UYVY: - gst_text_overlay_blit_UYVY (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_UYVY (overlay, data, xpos, ypos); break; case GST_VIDEO_FORMAT_AYUV: - gst_text_overlay_blit_AYUV (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_AYUV (overlay, data, xpos, ypos); break; case GST_VIDEO_FORMAT_BGRx: - gst_text_overlay_blit_BGRx (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_BGRx (overlay, data, xpos, ypos); break; case GST_VIDEO_FORMAT_xRGB: - gst_text_overlay_blit_xRGB (overlay, - GST_BUFFER_DATA (video_frame), xpos, ypos); + gst_text_overlay_blit_xRGB (overlay, data, xpos, ypos); break; default: g_assert_not_reached (); } } + gst_buffer_unmap (video_frame, data, size); + 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 (clip_start != start || (stop != -1 && clip_stop != stop)) { 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; if (stop != -1) GST_BUFFER_DURATION (buffer) = clip_stop - clip_start; @@ -2365,11 +2365,13 @@ wait_for_text_buf: /* Push the video frame */ ret = gst_pad_push (overlay->srcpad, buffer); } else { - gchar *in_text; - gsize in_size; + gchar *in_text, *otext; + gsize in_size, osize; - in_text = (gchar *) GST_BUFFER_DATA (overlay->text_buffer); - in_size = GST_BUFFER_SIZE (overlay->text_buffer); + otext = + 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 * 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_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); GST_OBJECT_UNLOCK (overlay); diff --git a/ext/pango/gsttextrender.c b/ext/pango/gsttextrender.c index c937244..0c02ad2 100644 --- a/ext/pango/gsttextrender.c +++ b/ext/pango/gsttextrender.c @@ -466,13 +466,15 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) GstFlowReturn ret; GstBuffer *outbuf; GstCaps *caps = NULL; - guint8 *data = GST_BUFFER_DATA (inbuf); - guint size = GST_BUFFER_SIZE (inbuf); + guint8 *data; + gsize size; gint n; gint xpos, ypos; 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... */ while (size > 0 && (data[size - 1] == '\r' || @@ -484,6 +486,7 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) GST_DEBUG ("rendering '%*s'", size, data); pango_layout_set_markup (render->layout, (gchar *) data, size); gst_text_render_render_pangocairo (render); + gst_buffer_unmap (inbuf, data, size); gst_text_render_check_argb (render); @@ -512,8 +515,8 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) if (ret != GST_FLOW_OK) goto done; - gst_buffer_copy_metadata (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS); - data = GST_BUFFER_DATA (outbuf); + gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1); + data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE); if (render->use_ARGB) { memset (data, 0, render->width * render->height * 4); @@ -562,6 +565,7 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) render->width * 4); } } + gst_buffer_unmap (outbuf, data, size); ret = gst_pad_push (render->srcpad, outbuf); diff --git a/ext/theora/gsttheoradec.c b/ext/theora/gsttheoradec.c index 96e12ee..e4ade2b 100644 --- a/ext/theora/gsttheoradec.c +++ b/ext/theora/gsttheoradec.c @@ -716,28 +716,30 @@ theora_dec_setcaps (GstPad * pad, GstCaps * caps) if ((codec_data = gst_structure_get_value (s, "codec_data"))) { if (G_VALUE_TYPE (codec_data) == GST_TYPE_BUFFER) { GstBuffer *buffer; - guint8 *data; - guint size; + guint8 *data, *ptr; + gsize size, left; guint offset; buffer = gst_value_get_buffer (codec_data); offset = 0; - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); + data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ); - while (size > 2) { + ptr = data; + left = size; + + while (left > 2) { guint psize; GstBuffer *buf; - psize = (data[0] << 8) | data[1]; + psize = (ptr[0] << 8) | ptr[1]; /* skip header */ - data += 2; - size -= 2; + ptr += 2; + left -= 2; offset += 2; /* make sure we don't read too much */ - psize = MIN (psize, size); + psize = MIN (psize, left); buf = gst_buffer_create_sub (buffer, offset, psize); @@ -749,10 +751,11 @@ theora_dec_setcaps (GstPad * pad, GstCaps * caps) theora_dec_chain (pad, buf); /* skip the data */ - size -= psize; - data += psize; + left -= psize; + ptr += psize; offset += psize; } + gst_buffer_unmap (buffer, data, size); } } @@ -765,20 +768,13 @@ static GstFlowReturn theora_handle_comment_packet (GstTheoraDec * dec, ogg_packet * packet) { gchar *encoder = NULL; - GstBuffer *buf; GstTagList *list; GST_DEBUG_OBJECT (dec, "parsing comment packet"); - buf = gst_buffer_new (); - GST_BUFFER_SIZE (buf) = packet->bytes; - GST_BUFFER_DATA (buf) = packet->packet; - list = - gst_tag_list_from_vorbiscomment_buffer (buf, (guint8 *) "\201theora", 7, - &encoder); - - gst_buffer_unref (buf); + gst_tag_list_from_vorbiscomment (packet->packet, packet->bytes, + (guint8 *) "\201theora", 7, &encoder); if (!list) { 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; GstVideoFormat format; guint8 *dest, *src; + gsize size; + guint8 *data; switch (dec->info.pixel_fmt) { case TH_PF_444: @@ -1081,13 +1079,14 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out) return result; } + data = gst_buffer_map (*out, &size, NULL, GST_MAP_WRITE); + for (plane = 0; plane < 3; plane++) { width = gst_video_format_get_component_width (format, plane, dec->width); height = gst_video_format_get_component_height (format, plane, dec->height); stride = gst_video_format_get_row_stride (format, plane, dec->width); - dest = - GST_BUFFER_DATA (*out) + gst_video_format_get_component_offset (format, + dest = data + gst_video_format_get_component_offset (format, plane, dec->width, dec->height); src = buf[plane].data; 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; } } + gst_buffer_unmap (*out, data, size); return GST_FLOW_OK; } @@ -1268,10 +1268,11 @@ theora_dec_decode_buffer (GstTheoraDec * dec, GstBuffer * buf) ogg_packet packet; GstFlowReturn result = GST_FLOW_OK; GstClockTime timestamp, duration; + gsize size; /* make ogg_packet out of the buffer */ - packet.packet = GST_BUFFER_DATA (buf); - packet.bytes = GST_BUFFER_SIZE (buf); + packet.packet = gst_buffer_map (buf, &size, NULL, GST_MAP_READ); + packet.bytes = size; packet.granulepos = -1; packet.packetno = 0; /* we don't really care */ packet.b_o_s = dec->have_header ? 0 : 1; @@ -1299,8 +1300,9 @@ theora_dec_decode_buffer (GstTheoraDec * dec, GstBuffer * buf) } else { result = theora_handle_data_packet (dec, &packet, timestamp, duration); } - done: + gst_buffer_unmap (buf, packet.packet, size); + return result; } @@ -1430,7 +1432,7 @@ theora_dec_chain_reverse (GstTheoraDec * dec, gboolean discont, GstBuffer * buf) GST_DEBUG_OBJECT (dec, "received discont,gathering buffers"); while (dec->gather) { GstBuffer *gbuf; - guint8 *data; + guint8 data[1]; gbuf = GST_BUFFER_CAST (dec->gather->data); /* 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); /* 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) { GST_DEBUG_OBJECT (dec, "copied keyframe"); 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 */ 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); return res; diff --git a/ext/theora/gsttheoraenc.c b/ext/theora/gsttheoraenc.c index 6a09c2c..e2953db 100644 --- a/ext/theora/gsttheoraenc.c +++ b/ext/theora/gsttheoraenc.c @@ -748,7 +748,7 @@ theora_buffer_from_packet (GstTheoraEnc * enc, ogg_packet * packet, 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)); /* see ext/ogg/README; OFFSET_END takes "our" granulepos, OFFSET its * time representation */ @@ -786,7 +786,7 @@ theora_push_buffer (GstTheoraEnc * enc, GstBuffer * buffer) { GstFlowReturn ret; - enc->bytes_out += GST_BUFFER_SIZE (buffer); + enc->bytes_out += gst_buffer_get_size (buffer); ret = gst_pad_push (enc->srcpad, buffer); @@ -1049,17 +1049,21 @@ theora_enc_read_multipass_cache (GstTheoraEnc * enc) while (!done) { if (gst_adapter_available (enc->multipass_cache_adapter) == 0) { + guint8 *data; + gsize size; + 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, - (gchar *) GST_BUFFER_DATA (cache_buf), GST_BUFFER_SIZE (cache_buf), - &bytes_read, NULL); + (gchar *) data, size, &bytes_read, NULL); if (bytes_read <= 0) { + gst_buffer_unmap (cache_buf, data, 0); gst_buffer_unref (cache_buf); break; } 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); } } @@ -1069,11 +1073,13 @@ theora_enc_read_multipass_cache (GstTheoraEnc * enc) bytes_read = 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 = th_encode_ctl (enc->encoder, TH_ENCCTL_2PASS_IN, (guint8 *) cache_data, bytes_read); + gst_adapter_unmap (enc->multipass_cache_adapter, 0); + done = bytes_consumed <= 0; if (bytes_consumed > 0) gst_adapter_flush (enc->multipass_cache_adapter, bytes_consumed); @@ -1258,8 +1264,11 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer) { th_ycbcr_buffer ycbcr; 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)) { theora_enc_reset (enc); @@ -1274,6 +1283,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer) if (enc->multipass_cache_fd && enc->multipass_mode == MULTIPASS_MODE_SECOND_PASS) { if (!theora_enc_read_multipass_cache (enc)) { + gst_buffer_unmap (buffer, data, size); ret = GST_FLOW_ERROR; goto multipass_read_failed; } @@ -1286,6 +1296,7 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer) if (enc->multipass_cache_fd && enc->multipass_mode == MULTIPASS_MODE_FIRST_PASS) { if (!theora_enc_write_multipass_cache (enc)) { + gst_buffer_unmap (buffer, data, size); ret = GST_FLOW_ERROR; goto multipass_write_failed; } @@ -1302,9 +1313,12 @@ theora_enc_chain (GstPad * pad, GstBuffer * buffer) next_time - enc->next_ts); enc->next_ts = next_time; - if (ret != GST_FLOW_OK) + if (ret != GST_FLOW_OK) { + gst_buffer_unmap (buffer, data, size); goto data_push; + } } + gst_buffer_unmap (buffer, data, size); gst_buffer_unref (buffer); } diff --git a/ext/theora/gsttheoraparse.c b/ext/theora/gsttheoraparse.c index 0ce68d9..74aa062 100644 --- a/ext/theora/gsttheoraparse.c +++ b/ext/theora/gsttheoraparse.c @@ -267,7 +267,7 @@ theora_parse_set_header_on_caps (GstTheoraParse * parse, GstCaps * caps) if (bufs[i] == NULL) 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); g_value_init (&value, GST_TYPE_BUFFER); @@ -367,7 +367,7 @@ theora_parse_push_headers (GstTheoraParse * parse) GstBuffer *buf; 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_pad_push (parse->srcpad, buf); parse->streamheader[i] = NULL; @@ -624,7 +624,7 @@ theora_parse_queue_buffer (GstTheoraParse * parse, GstBuffer * buf) { 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); diff --git a/gst-libs/gst/tag/gstvorbistag.c b/gst-libs/gst/tag/gstvorbistag.c index 450061d..2700ae4 100644 --- a/gst-libs/gst/tag/gstvorbistag.c +++ b/gst-libs/gst/tag/gstvorbistag.c @@ -364,7 +364,7 @@ convert_failed: } /** - * gst_tag_list_from_vorbiscomment_buffer: + * gst_tag_list_from_vorbiscomment: * @data: data to convert * @size: size of @data * @id_data: identification data at start of stream @@ -453,6 +453,37 @@ error: #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 { guint count; diff --git a/gst-libs/gst/tag/tag.h b/gst-libs/gst/tag/tag.h index 10ae2ee..4386ee4 100644 --- a/gst-libs/gst/tag/tag.h +++ b/gst-libs/gst/tag/tag.h @@ -450,6 +450,10 @@ GstTagList * gst_tag_list_from_vorbiscomment (const guint8 * const guint8 * id_data, const guint id_data_length, 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, const guint8 * id_data, const guint id_data_length, -- 2.7.4