rtpasfdepay: set padding size to the correct value

asf packets in rtp packets should come with their padding fields
set to 0 and the depayload must update them to the correct
value before pushing downstream
This commit is contained in:
Thiago Santos 2009-07-31 00:25:43 -03:00
parent 79d4b18044
commit 6adb49c501

View file

@ -207,6 +207,90 @@ invalid_headers:
}
}
static gint
field_size (guint8 field)
{
switch (field) {
/* DWORD - 32 bits */
case 3:
return 4;
/* WORD - 16 bits */
case 2:
return 2;
/* BYTE - 8 bits */
case 1:
return 1;
/* non-exitent */
case 0:
default:
return 0;
}
}
/*
* Set the padding field to te correct value as the spec
* says it should be se to 0 in the rtp packets
*/
static void
gst_rtp_asf_depay_set_padding (GstRtpAsfDepay * depayload,
GstBuffer * buf, guint32 padding)
{
guint8 *data = GST_BUFFER_DATA (buf);
gint offset = 0;
guint8 aux;
guint8 seq_type;
guint8 pad_type;
guint8 pkt_type;
aux = data[offset++];
if (aux & 0x80) {
guint8 err_len = 0;
if (aux & 0x60) {
GST_WARNING_OBJECT (depayload, "Error correction length type should be "
"set to 0");
/* this packet doesn't follow the spec */
return;
}
err_len = aux & 0x0F;
offset += err_len;
aux = data[offset++];
}
seq_type = (aux >> 1) & 0x3;
pad_type = (aux >> 3) & 0x3;
pkt_type = (aux >> 5) & 0x3;
offset += 1; /* skip property flags */
offset += field_size (pkt_type); /* skip packet length */
offset += field_size (seq_type); /* skip sequence field */
/* write padding */
switch (pad_type) {
/* DWORD */
case 3:
GST_WRITE_UINT32_LE (&(data[offset]), padding);
break;
/* WORD */
case 2:
GST_WRITE_UINT16_LE (&(data[offset]), padding);
break;
/* BYTE */
case 1:
data[offset] = (guint8) padding;
break;
/* non-existent */
case 0:
default:
break;
}
}
/* Docs: 'RTSP Protocol PDF' document from http://sdp.ppona.com/ (page 8) */
static GstBuffer *
@ -339,6 +423,8 @@ gst_rtp_asf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
memset (GST_BUFFER_DATA (outbuf) + available, 0,
depay->packet_size - available);
gst_buffer_unref (sub);
gst_rtp_asf_depay_set_padding (depay, outbuf,
depay->packet_size - available);
} else
outbuf = sub;
}
@ -370,6 +456,8 @@ gst_rtp_asf_depay_process (GstBaseRTPDepayload * depayload, GstBuffer * buf)
memcpy (GST_BUFFER_DATA (outbuf), payload, packet_len);
memset (GST_BUFFER_DATA (outbuf) + packet_len, 0,
depay->packet_size - packet_len);
gst_rtp_asf_depay_set_padding (depay, outbuf,
depay->packet_size - packet_len);
}
gst_buffer_set_caps (outbuf, GST_PAD_CAPS (depayload->srcpad));