asfdepay: fix padding correction

Fix padding correction. gst_buffer_copy_into() appends the memory to the already
existing memory in the target buffer..

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=680536
This commit is contained in:
Wim Taymans 2012-07-25 09:37:08 +02:00
parent f0b0ffa1cf
commit a04d61ee6d

View file

@ -241,14 +241,13 @@ field_size (guint8 field)
} }
} }
/* /* Set the padding field to te correct value as the spec
* Set the padding field to te correct value as the spec
* says it should be se to 0 in the rtp packets * says it should be se to 0 in the rtp packets
*/ */
static void static GstBuffer *
gst_rtp_asf_depay_set_padding (GstRtpAsfDepay * depayload, gst_rtp_asf_depay_update_padding (GstRtpAsfDepay * depayload, GstBuffer * buf)
GstBuffer * buf, guint32 padding)
{ {
GstBuffer *result;
GstMapInfo map; GstMapInfo map;
guint8 *data; guint8 *data;
gint offset = 0; gint offset = 0;
@ -256,9 +255,26 @@ gst_rtp_asf_depay_set_padding (GstRtpAsfDepay * depayload,
guint8 seq_type; guint8 seq_type;
guint8 pad_type; guint8 pad_type;
guint8 pkt_type; guint8 pkt_type;
gsize plen, padding;
gst_buffer_map (buf, &map, GST_MAP_READ); plen = gst_buffer_get_size (buf);
if (plen == depayload->packet_size)
return buf;
padding = depayload->packet_size - plen;
GST_LOG_OBJECT (depayload,
"padding buffer size %" G_GSIZE_FORMAT " to packet size %d", plen,
depayload->packet_size);
result = gst_buffer_new_and_alloc (depayload->packet_size);
gst_buffer_map (result, &map, GST_MAP_READ);
data = map.data; data = map.data;
memset (data + plen, 0, padding);
gst_buffer_extract (buf, 0, data, plen);
gst_buffer_unref (buf);
aux = data[offset++]; aux = data[offset++];
if (aux & 0x80) { if (aux & 0x80) {
@ -267,8 +283,8 @@ gst_rtp_asf_depay_set_padding (GstRtpAsfDepay * depayload,
GST_WARNING_OBJECT (depayload, "Error correction length type should be " GST_WARNING_OBJECT (depayload, "Error correction length type should be "
"set to 0"); "set to 0");
/* this packet doesn't follow the spec */ /* this packet doesn't follow the spec */
gst_buffer_unmap (buf, &map); gst_buffer_unmap (result, &map);
return; return result;
} }
err_len = aux & 0x0F; err_len = aux & 0x0F;
offset += err_len; offset += err_len;
@ -305,7 +321,9 @@ gst_rtp_asf_depay_set_padding (GstRtpAsfDepay * depayload,
default: default:
break; break;
} }
gst_buffer_unmap (buf, &map); gst_buffer_unmap (result, &map);
return result;
} }
/* Docs: 'RTSP Protocol PDF' document from http://sdp.ppona.com/ (page 8) */ /* Docs: 'RTSP Protocol PDF' document from http://sdp.ppona.com/ (page 8) */
@ -342,7 +360,6 @@ gst_rtp_asf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
do { do {
guint packet_len; guint packet_len;
gsize plen;
/* packet header is at least 4 bytes */ /* packet header is at least 4 bytes */
if (payload_len < 4) if (payload_len < 4)
@ -459,23 +476,7 @@ gst_rtp_asf_depay_process (GstRTPBaseDepayload * depayload, GstBuffer * buf)
if (!outbuf) if (!outbuf)
return NULL; return NULL;
/* we need to pad with zeroes to packet_size if it's smaller */ outbuf = gst_rtp_asf_depay_update_padding (depay, outbuf);
plen = gst_buffer_get_size (outbuf);
if (plen < depay->packet_size) {
GstBuffer *tmp;
GST_LOG_OBJECT (depay,
"padding buffer size %" G_GSIZE_FORMAT " to packet size %d", plen,
depay->packet_size);
tmp = gst_buffer_new_and_alloc (depay->packet_size);
gst_buffer_copy_into (tmp, outbuf, GST_BUFFER_COPY_ALL, 0, plen);
gst_buffer_unref (outbuf);
outbuf = tmp;
gst_buffer_memset (outbuf, plen, 0, depay->packet_size - plen);
gst_rtp_asf_depay_set_padding (depay, outbuf, depay->packet_size - plen);
}
if (!S) if (!S)
GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);