plugins: port some plugins to the new memory API

This commit is contained in:
Wim Taymans 2011-03-27 16:35:28 +02:00 committed by Tim-Philipp Müller
parent ce639b529b
commit 0e90a45365
2 changed files with 35 additions and 52 deletions

View file

@ -285,17 +285,23 @@ gst_gdp_depay_chain (GstPad * pad, GstBuffer * buffer)
goto wrong_type; goto wrong_type;
} }
if (this->payload_length if (this->payload_length) {
&& (!gst_dp_validate_payload (GST_DP_HEADER_LENGTH, this->header, const guint8 *data;
gst_adapter_peek (this->adapter, this->payload_length)))) { gboolean res;
goto payload_validate_error;
data = gst_adapter_map (this->adapter, this->payload_length);
res = gst_dp_validate_payload (GST_DP_HEADER_LENGTH, this->header,
data);
gst_adapter_unmap (this->adapter, 0);
if (!res)
goto payload_validate_error;
} }
break; break;
} }
case GST_GDP_DEPAY_STATE_BUFFER: case GST_GDP_DEPAY_STATE_BUFFER:
{ {
/* if we receive a buffer without caps first, we error out */ /* if we receive a buffer without caps first, we error out */
if (!this->caps) if (!this->caps)
goto no_caps; goto no_caps;
@ -309,9 +315,11 @@ gst_gdp_depay_chain (GstPad * pad, GstBuffer * buffer)
if (this->payload_length > 0) { if (this->payload_length > 0) {
guint8 *payload; guint8 *payload;
payload = gst_adapter_take (this->adapter, this->payload_length); payload = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memcpy (GST_BUFFER_DATA (buf), payload, this->payload_length); gst_adapter_copy (this->adapter, payload, 0, this->payload_length);
g_free (payload); gst_buffer_unmap (buf, payload, this->payload_length);
gst_adapter_flush (this->adapter, this->payload_length);
} }
/* set caps and push */ /* set caps and push */
@ -319,12 +327,12 @@ gst_gdp_depay_chain (GstPad * pad, GstBuffer * buffer)
GST_LOG_OBJECT (this, "deserialized buffer %p, pushing, timestamp %" GST_LOG_OBJECT (this, "deserialized buffer %p, pushing, timestamp %"
GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT GST_TIME_FORMAT ", duration %" GST_TIME_FORMAT
", offset %" G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT ", offset %" G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT
", size %d, flags 0x%x", ", size %" G_GSIZE_FORMAT ", flags 0x%x",
buf, buf,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)), GST_TIME_ARGS (GST_BUFFER_DURATION (buf)),
GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf), GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf),
GST_BUFFER_SIZE (buf), GST_BUFFER_FLAGS (buf)); gst_buffer_get_size (buf), GST_BUFFER_FLAGS (buf));
ret = gst_pad_push (this->srcpad, buf); ret = gst_pad_push (this->srcpad, buf);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto push_error; goto push_error;

View file

@ -77,9 +77,7 @@ GST_BOILERPLATE_FULL (GstGDPPay, gst_gdp_pay, GstElement,
static void gst_gdp_pay_reset (GstGDPPay * this); static void gst_gdp_pay_reset (GstGDPPay * this);
static GstFlowReturn gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer); static GstFlowReturn gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer);
static gboolean gst_gdp_pay_src_event (GstPad * pad, GstEvent * event); static gboolean gst_gdp_pay_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event); static gboolean gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event);
static GstStateChangeReturn gst_gdp_pay_change_state (GstElement * static GstStateChangeReturn gst_gdp_pay_change_state (GstElement *
@ -112,7 +110,6 @@ static void
gst_gdp_pay_class_init (GstGDPPayClass * klass) gst_gdp_pay_class_init (GstGDPPayClass * klass)
{ {
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
gobject_class = (GObjectClass *) klass; gobject_class = (GObjectClass *) klass;
@ -216,7 +213,7 @@ static void
gst_gdp_stamp_buffer (GstGDPPay * this, GstBuffer * buffer) gst_gdp_stamp_buffer (GstGDPPay * this, GstBuffer * buffer)
{ {
GST_BUFFER_OFFSET (buffer) = this->offset; GST_BUFFER_OFFSET (buffer) = this->offset;
GST_BUFFER_OFFSET_END (buffer) = this->offset + GST_BUFFER_SIZE (buffer); GST_BUFFER_OFFSET_END (buffer) = this->offset + gst_buffer_get_size (buffer);
this->offset = GST_BUFFER_OFFSET_END (buffer); this->offset = GST_BUFFER_OFFSET_END (buffer);
} }
@ -224,12 +221,9 @@ static GstBuffer *
gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps) gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps)
{ {
GstBuffer *headerbuf; GstBuffer *headerbuf;
GstBuffer *payloadbuf; GstBuffer *payloadbuf;
guint8 *header, *payload; guint8 *header, *payload;
guint len, plen;
guint len;
if (!this->packetizer->packet_from_caps (caps, this->header_flag, &len, if (!this->packetizer->packet_from_caps (caps, this->header_flag, &len,
&header, &payload)) &header, &payload))
@ -237,13 +231,13 @@ gst_gdp_buffer_from_caps (GstGDPPay * this, GstCaps * caps)
GST_LOG_OBJECT (this, "creating GDP header and payload buffer from caps"); GST_LOG_OBJECT (this, "creating GDP header and payload buffer from caps");
headerbuf = gst_buffer_new (); headerbuf = gst_buffer_new ();
gst_buffer_set_data (headerbuf, header, len); gst_buffer_take_memory (headerbuf,
GST_BUFFER_MALLOCDATA (headerbuf) = header; gst_memory_new_wrapped (0, header, g_free, len, 0, len));
payloadbuf = gst_buffer_new (); payloadbuf = gst_buffer_new ();
gst_buffer_set_data (payloadbuf, payload, plen = gst_dp_header_payload_length (header);
gst_dp_header_payload_length (header)); gst_buffer_take_memory (payloadbuf,
GST_BUFFER_MALLOCDATA (payloadbuf) = payload; gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
return gst_buffer_join (headerbuf, payloadbuf); return gst_buffer_join (headerbuf, payloadbuf);
@ -259,9 +253,7 @@ static GstBuffer *
gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer) gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer)
{ {
GstBuffer *headerbuf; GstBuffer *headerbuf;
guint8 *header; guint8 *header;
guint len; guint len;
if (!this->packetizer->header_from_buffer (buffer, this->header_flag, &len, if (!this->packetizer->header_from_buffer (buffer, this->header_flag, &len,
@ -270,8 +262,8 @@ gst_gdp_pay_buffer_from_buffer (GstGDPPay * this, GstBuffer * buffer)
GST_LOG_OBJECT (this, "creating GDP header and payload buffer from buffer"); GST_LOG_OBJECT (this, "creating GDP header and payload buffer from buffer");
headerbuf = gst_buffer_new (); headerbuf = gst_buffer_new ();
gst_buffer_set_data (headerbuf, header, len); gst_buffer_take_memory (headerbuf,
GST_BUFFER_MALLOCDATA (headerbuf) = header; gst_memory_new_wrapped (0, header, g_free, len, 0, len));
/* we do not want to lose the ref on the incoming buffer */ /* we do not want to lose the ref on the incoming buffer */
gst_buffer_ref (buffer); gst_buffer_ref (buffer);
@ -290,13 +282,9 @@ static GstBuffer *
gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event) gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event)
{ {
GstBuffer *headerbuf; GstBuffer *headerbuf;
GstBuffer *payloadbuf; GstBuffer *payloadbuf;
guint8 *header, *payload; guint8 *header, *payload;
guint len, plen;
guint len;
gboolean ret; gboolean ret;
ret = ret =
@ -307,13 +295,13 @@ gst_gdp_buffer_from_event (GstGDPPay * this, GstEvent * event)
GST_LOG_OBJECT (this, "creating GDP header and payload buffer from event"); GST_LOG_OBJECT (this, "creating GDP header and payload buffer from event");
headerbuf = gst_buffer_new (); headerbuf = gst_buffer_new ();
gst_buffer_set_data (headerbuf, header, len); gst_buffer_take_memory (headerbuf,
GST_BUFFER_MALLOCDATA (headerbuf) = header; gst_memory_new_wrapped (0, header, g_free, len, 0, len));
payloadbuf = gst_buffer_new (); payloadbuf = gst_buffer_new ();
gst_buffer_set_data (payloadbuf, payload, plen = gst_dp_header_payload_length (header);
gst_dp_header_payload_length (header)); gst_buffer_take_memory (payloadbuf,
GST_BUFFER_MALLOCDATA (payloadbuf) = payload; gst_memory_new_wrapped (0, payload, g_free, plen, 0, plen));
return gst_buffer_join (headerbuf, payloadbuf); return gst_buffer_join (headerbuf, payloadbuf);
@ -333,14 +321,10 @@ static GstFlowReturn
gst_gdp_pay_reset_streamheader (GstGDPPay * this) gst_gdp_pay_reset_streamheader (GstGDPPay * this)
{ {
GstCaps *caps; GstCaps *caps;
/* We use copies of these to avoid circular refcounts */ /* We use copies of these to avoid circular refcounts */
GstBuffer *new_segment_buf, *caps_buf, *tag_buf; GstBuffer *new_segment_buf, *caps_buf, *tag_buf;
GstStructure *structure; GstStructure *structure;
GstFlowReturn r = GST_FLOW_OK; GstFlowReturn r = GST_FLOW_OK;
gboolean version_one_zero = TRUE; gboolean version_one_zero = TRUE;
GValue array = { 0 }; GValue array = { 0 };
@ -474,10 +458,9 @@ gst_gdp_pay_reset_streamheader (GstGDPPay * this)
GST_DEBUG_OBJECT (this, "Setting caps on src pad %" GST_PTR_FORMAT, caps); GST_DEBUG_OBJECT (this, "Setting caps on src pad %" GST_PTR_FORMAT, caps);
gst_pad_set_caps (this->srcpad, caps); gst_pad_set_caps (this->srcpad, caps);
this->caps_buf = gst_buffer_make_metadata_writable (this->caps_buf); this->caps_buf = gst_buffer_make_writable (this->caps_buf);
gst_buffer_set_caps (this->caps_buf, caps); gst_buffer_set_caps (this->caps_buf, caps);
this->new_segment_buf = this->new_segment_buf = gst_buffer_make_writable (this->new_segment_buf);
gst_buffer_make_metadata_writable (this->new_segment_buf);
gst_buffer_set_caps (this->new_segment_buf, caps); gst_buffer_set_caps (this->new_segment_buf, caps);
/* if these are our first ever buffers, send out new_segment first */ /* if these are our first ever buffers, send out new_segment first */
@ -579,11 +562,8 @@ static GstFlowReturn
gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer) gst_gdp_pay_chain (GstPad * pad, GstBuffer * buffer)
{ {
GstGDPPay *this; GstGDPPay *this;
GstCaps *caps; GstCaps *caps;
GstBuffer *outbuffer; GstBuffer *outbuffer;
GstFlowReturn ret; GstFlowReturn ret;
this = GST_GDP_PAY (gst_pad_get_parent (pad)); this = GST_GDP_PAY (gst_pad_get_parent (pad));
@ -698,11 +678,8 @@ static gboolean
gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event) gst_gdp_pay_sink_event (GstPad * pad, GstEvent * event)
{ {
GstBuffer *outbuffer; GstBuffer *outbuffer;
GstGDPPay *this = GST_GDP_PAY (gst_pad_get_parent (pad)); GstGDPPay *this = GST_GDP_PAY (gst_pad_get_parent (pad));
GstFlowReturn flowret; GstFlowReturn flowret;
gboolean ret = TRUE; gboolean ret = TRUE;
GST_DEBUG_OBJECT (this, "received event %p of type %s (%d)", GST_DEBUG_OBJECT (this, "received event %p of type %s (%d)",
@ -784,7 +761,6 @@ static gboolean
gst_gdp_pay_src_event (GstPad * pad, GstEvent * event) gst_gdp_pay_src_event (GstPad * pad, GstEvent * event)
{ {
GstGDPPay *this; GstGDPPay *this;
gboolean res = TRUE; gboolean res = TRUE;
this = GST_GDP_PAY (gst_pad_get_parent (pad)); this = GST_GDP_PAY (gst_pad_get_parent (pad));
@ -865,7 +841,6 @@ static GstStateChangeReturn
gst_gdp_pay_change_state (GstElement * element, GstStateChange transition) gst_gdp_pay_change_state (GstElement * element, GstStateChange transition)
{ {
GstStateChangeReturn ret; GstStateChangeReturn ret;
GstGDPPay *this = GST_GDP_PAY (element); GstGDPPay *this = GST_GDP_PAY (element);
switch (transition) { switch (transition) {