diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-06-18 18:47:49 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-06-18 18:51:04 +0200 |
commit | e2ccc1ee390f303dd4117c46316b00c33cf67241 (patch) | |
tree | 17f632f0cf33cab86e7e27da055a9562f380ed72 | |
parent | 66c388a0e00ad639d5c3f76a6ac033a5c432848c (diff) |
rtp: cleanupsrtp-list
Add Since tags to docs
Move some code around
Add win32 symbols
-rw-r--r-- | gst-libs/gst/rtp/gstrtpbuffer.c | 383 | ||||
-rw-r--r-- | win32/common/libgstrtp.def | 9 |
2 files changed, 205 insertions, 187 deletions
diff --git a/gst-libs/gst/rtp/gstrtpbuffer.c b/gst-libs/gst/rtp/gstrtpbuffer.c index 87b36d4dc..9fb96726f 100644 --- a/gst-libs/gst/rtp/gstrtpbuffer.c +++ b/gst-libs/gst/rtp/gstrtpbuffer.c @@ -92,14 +92,6 @@ typedef enum NO_MORE } rtp_header_data_type; -static gboolean validate_data (guint8 * data, guint len, guint8 * payload, - guint payload_len); -static guint8 *gst_rtp_buffer_list_get_data (GstBufferList * list); -static void gst_rtp_buffer_list_set_rtp_headers (GstBufferList * list, - gpointer data, rtp_header_data_type type); -static void gst_rtp_buffer_list_set_data (guint8 * rtp_header, gpointer data, - rtp_header_data_type type); - /** * gst_rtp_buffer_allocate_data: * @buffer: a #GstBuffer @@ -302,6 +294,95 @@ gst_rtp_buffer_calc_payload_len (guint packet_len, guint8 pad_len, } /** + * validate_data: + * @data: the data to validate + * @len: the length of @data to validate + * @payload: the payload if @data represents the header only + * @payload_len: the len of the payload + * + * Checks if @data is a valid RTP packet. + * + * Returns: TRUE if @data is a valid RTP packet + */ +static gboolean +validate_data (guint8 * data, guint len, guint8 * payload, guint payload_len) +{ + guint8 padding; + guint8 csrc_count; + guint header_len; + guint8 version; + + g_return_val_if_fail (data != NULL, FALSE); + + header_len = GST_RTP_HEADER_LEN; + if (G_UNLIKELY (len < header_len)) + goto wrong_length; + + /* check version */ + version = (data[0] & 0xc0); + if (G_UNLIKELY (version != (GST_RTP_VERSION << 6))) + goto wrong_version; + + /* calc header length with csrc */ + csrc_count = (data[0] & 0x0f); + header_len += csrc_count * sizeof (guint32); + + /* calc extension length when present. */ + if (data[0] & 0x10) { + guint8 *extpos; + guint16 extlen; + + /* this points to the extenstion bits and header length */ + extpos = &data[header_len]; + + /* skip the header and check that we have enough space */ + header_len += 4; + if (G_UNLIKELY (len < header_len)) + goto wrong_length; + + /* skip id */ + extpos += 2; + /* read length as the number of 32 bits words */ + extlen = GST_READ_UINT16_BE (extpos); + + header_len += extlen * sizeof (guint32); + } + + /* check for padding */ + if (data[0] & 0x20) { + if (payload) + padding = payload[payload_len - 1]; + else + padding = data[len - 1]; + } else { + padding = 0; + } + + /* check if padding and header not bigger than packet length */ + if (G_UNLIKELY (len < padding + header_len)) + goto wrong_padding; + + return TRUE; + + /* ERRORS */ +wrong_length: + { + GST_DEBUG ("len < header_len check failed (%d < %d)", len, header_len); + return FALSE; + } +wrong_version: + { + GST_DEBUG ("version check failed (%d != %d)", version, GST_RTP_VERSION); + return FALSE; + } +wrong_padding: + { + GST_DEBUG ("padding check failed (%d - %d < %d)", len, header_len, padding); + return FALSE; + } +} + +/** * gst_rtp_buffer_validate_data: * @data: the data to validate * @len: the length of @data to validate @@ -353,6 +434,8 @@ gst_rtp_buffer_validate (GstBuffer * buffer) * this module. * * Returns: TRUE if @list consists only of valid RTP packets. + * + * Since: 0.10.24 */ gboolean gst_rtp_buffer_list_validate (GstBufferList * list) @@ -376,7 +459,8 @@ gst_rtp_buffer_list_validate (GstBufferList * list) guint packet_size; /* each group should consists of 2 buffers: one containing the RTP header - * and the other one the payload */ + * and the other one the payload, FIXME, relax the requirement of only one + * payload buffer. */ if (gst_buffer_list_iterator_n_buffers (it) != 2) goto invalid_list; @@ -417,98 +501,13 @@ gst_rtp_buffer_list_validate (GstBufferList * list) } gst_buffer_list_iterator_free (it); - return TRUE; - -invalid_list: - gst_buffer_list_iterator_free (it); - g_return_val_if_reached (FALSE); -} - -/** - * validate_data: - * @data: the data to validate - * @len: the length of @data to validate - * @payload: the payload if @data represents the header only - * @payload_len: the len of the payload - * - * Checks if @data is a valid RTP packet. - * - * Returns: TRUE if @data is a valid RTP packet - */ -static gboolean -validate_data (guint8 * data, guint len, guint8 * payload, guint payload_len) -{ - guint8 padding; - guint8 csrc_count; - guint header_len; - guint8 version; - - g_return_val_if_fail (data != NULL, FALSE); - - header_len = GST_RTP_HEADER_LEN; - if (G_UNLIKELY (len < header_len)) - goto wrong_length; - - /* check version */ - version = (data[0] & 0xc0); - if (G_UNLIKELY (version != (GST_RTP_VERSION << 6))) - goto wrong_version; - - /* calc header length with csrc */ - csrc_count = (data[0] & 0x0f); - header_len += csrc_count * sizeof (guint32); - - /* calc extension length when present. */ - if (data[0] & 0x10) { - guint8 *extpos; - guint16 extlen; - - /* this points to the extenstion bits and header length */ - extpos = &data[header_len]; - - /* skip the header and check that we have enough space */ - header_len += 4; - if (G_UNLIKELY (len < header_len)) - goto wrong_length; - - /* skip id */ - extpos += 2; - /* read length as the number of 32 bits words */ - extlen = GST_READ_UINT16_BE (extpos); - - header_len += extlen * sizeof (guint32); - } - - /* check for padding */ - if (data[0] & 0x20) { - if (payload) - padding = payload[payload_len - 1]; - else - padding = data[len - 1]; - } else { - padding = 0; - } - - /* check if padding and header not bigger than packet length */ - if (G_UNLIKELY (len < padding + header_len)) - goto wrong_padding; return TRUE; /* ERRORS */ -wrong_length: - { - GST_DEBUG ("len < header_len check failed (%d < %d)", len, header_len); - return FALSE; - } -wrong_version: - { - GST_DEBUG ("version check failed (%d != %d)", version, GST_RTP_VERSION); - return FALSE; - } -wrong_padding: +invalid_list: { - GST_DEBUG ("padding check failed (%d - %d < %d)", len, header_len, padding); + gst_buffer_list_iterator_free (it); return FALSE; } } @@ -795,6 +794,32 @@ gst_rtp_buffer_get_ssrc (GstBuffer * buffer) return g_ntohl (GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer))); } +/* Returns ponter to the RTP header of the first packet within the list */ +static guint8 * +gst_rtp_buffer_list_get_data (GstBufferList * list) +{ + GstBufferListIterator *it; + GstBuffer *rtpbuf; + + it = gst_buffer_list_iterate (list); + if (!gst_buffer_list_iterator_next_group (it)) + goto invalid_list; + + rtpbuf = gst_buffer_list_iterator_next (it); + if (!rtpbuf) + goto invalid_list; + + gst_buffer_list_iterator_free (it); + + return GST_BUFFER_DATA (rtpbuf); + +invalid_list: + { + gst_buffer_list_iterator_free (it); + return NULL; + } +} + /** * gst_rtp_buffer_list_get_ssrc: * @list: the list @@ -803,13 +828,17 @@ gst_rtp_buffer_get_ssrc (GstBuffer * buffer) * All RTP packets within @list have the same SSRC. * * Returns: the SSRC of @list in host order. + * + * Since: 0.10.24 */ guint32 gst_rtp_buffer_list_get_ssrc (GstBufferList * list) { guint8 *data; + data = gst_rtp_buffer_list_get_data (list); g_return_val_if_fail (data != NULL, 0); + return g_ntohl (GST_RTP_HEADER_SSRC (data)); } @@ -826,12 +855,63 @@ gst_rtp_buffer_set_ssrc (GstBuffer * buffer, guint32 ssrc) GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer)) = g_htonl (ssrc); } +/* Sets the field specified by @type to @data. + * When setting SEQ number, this function will also increase + * @data by one. */ +static void +gst_rtp_buffer_list_set_data (guint8 * rtp_header, + gpointer data, rtp_header_data_type type) +{ + switch (type) { + case PAYLOAD_TYPE: + GST_RTP_HEADER_PAYLOAD_TYPE (rtp_header) = *(guint8 *) data; + break; + case SEQ: + GST_RTP_HEADER_SEQ (rtp_header) = g_htons (*(guint16 *) data); + (*(guint16 *) data)++; + break; + case SSRC: + GST_RTP_HEADER_SSRC (rtp_header) = g_htonl (*(guint32 *) data); + break; + case TIMESTAMP: + GST_RTP_HEADER_TIMESTAMP (rtp_header) = g_htonl (*(guint32 *) data); + break; + default: + g_warning ("Unknown data type"); + break; + } +} + +/* Sets the field specified by @type to @data. + * This function updates all RTP headers within @list. */ +static void +gst_rtp_buffer_list_set_rtp_headers (GstBufferList * list, + gpointer data, rtp_header_data_type type) +{ + GstBufferListIterator *it; + + it = gst_buffer_list_iterate (list); + + while (gst_buffer_list_iterator_next_group (it)) { + GstBuffer *rtpbuf; + guint8 *rtp_header; + + rtpbuf = gst_buffer_list_iterator_next (it); + rtp_header = GST_BUFFER_DATA (rtpbuf); + + gst_rtp_buffer_list_set_data (rtp_header, data, type); + } + gst_buffer_list_iterator_free (it); +} + /** * gst_rtp_buffer_list_set_ssrc: * @list: the buffer list * @ssrc: the new SSRC * * Set the SSRC on each RTP packet in @list to @ssrc. + * + * Since: 0.10.24 */ void gst_rtp_buffer_list_set_ssrc (GstBufferList * list, guint32 ssrc) @@ -943,13 +1023,17 @@ gst_rtp_buffer_get_payload_type (GstBuffer * buffer) * All packets in @list should have the same payload type. * * Returns: The payload type. + * + * Since: 0.10.24 */ guint8 gst_rtp_buffer_list_get_payload_type (GstBufferList * list) { guint8 *data; + data = gst_rtp_buffer_list_get_data (list); g_return_val_if_fail (data != NULL, 0); + return GST_RTP_HEADER_PAYLOAD_TYPE (data); } @@ -974,6 +1058,8 @@ gst_rtp_buffer_set_payload_type (GstBuffer * buffer, guint8 payload_type) * @payload_type: the new type * * Set the payload type of each RTP packet in @list to @payload_type. + * + * Since: 0.10.24 */ void gst_rtp_buffer_list_set_payload_type (GstBufferList * list, guint8 payload_type) @@ -1018,11 +1104,14 @@ gst_rtp_buffer_set_seq (GstBuffer * buffer, guint16 seq) * Set the sequence number of each RTP packet in @list to @seq. * * Returns: The seq number of the last packet in the list + 1. + * + * Since: 0.10.24 */ guint16 gst_rtp_buffer_list_set_seq (GstBufferList * list, guint16 seq) { gst_rtp_buffer_list_set_rtp_headers (list, &seq, SEQ); + return seq; } @@ -1048,13 +1137,17 @@ gst_rtp_buffer_get_timestamp (GstBuffer * buffer) * All packets within @list have the same timestamp. * * Returns: The timestamp in host order. + * + * Since: 0.10.24 */ guint32 gst_rtp_buffer_list_get_timestamp (GstBufferList * list) { guint8 *data; + data = gst_rtp_buffer_list_get_data (list); g_return_val_if_fail (data != NULL, 0); + return g_ntohl (GST_RTP_HEADER_TIMESTAMP (data)); } @@ -1077,6 +1170,8 @@ gst_rtp_buffer_set_timestamp (GstBuffer * buffer, guint32 timestamp) * @timestamp: the new timestamp * * Set the timestamp of each RTP packet in @list to @timestamp. + * + * Since: 0.10.24 */ void gst_rtp_buffer_list_set_timestamp (GstBufferList * list, guint32 timestamp) @@ -1175,13 +1270,17 @@ gst_rtp_buffer_get_payload_len (GstBuffer * buffer) * Get the length of the payload of the RTP packet in @list. * * Returns: The length of the payload in @list. + * + * Since: 0.10.24 */ guint gst_rtp_buffer_list_get_payload_len (GstBufferList * list) { - guint len = 0; + guint len; GstBufferListIterator *it; + it = gst_buffer_list_iterate (list); + len = 0; while (gst_buffer_list_iterator_next_group (it)) { guint i; @@ -1311,93 +1410,3 @@ gst_rtp_buffer_ext_timestamp (guint64 * exttimestamp, guint32 timestamp) return result; } - -/** - * gst_rtp_buffer_list_get_data: - * @list: a buffer list - * - * Returns ponter to the RTP header of the first packet within the list - * - * Returns: pointer to the first RTP header - */ -static guint8 * -gst_rtp_buffer_list_get_data (GstBufferList * list) -{ - GstBufferListIterator *it; - GstBuffer *rtpbuf; - - it = gst_buffer_list_iterate (list); - if (!gst_buffer_list_iterator_next_group (it)) - goto invalid_list; - rtpbuf = gst_buffer_list_iterator_next (it); - if (!rtpbuf) - goto invalid_list; - - gst_buffer_list_iterator_free (it); - return GST_BUFFER_DATA (rtpbuf); - -invalid_list: - gst_buffer_list_iterator_free (it); - g_return_val_if_reached (FALSE); -} - -/** - * gst_rtp_buffer_list_set_rtp_headers: - * @list: a buffer list - * @data: data to be set - * @type: which field in the header to be set - * - * Sets the field specified by @type to @data. - * This function updates all RTP headers within @list. - */ -static void -gst_rtp_buffer_list_set_rtp_headers (GstBufferList * list, - gpointer data, rtp_header_data_type type) -{ - GstBufferListIterator *it; - it = gst_buffer_list_iterate (list); - - while (gst_buffer_list_iterator_next_group (it)) { - GstBuffer *rtpbuf; - guint8 *rtp_header; - rtpbuf = gst_buffer_list_iterator_next (it); - rtp_header = GST_BUFFER_DATA (rtpbuf); - gst_rtp_buffer_list_set_data (rtp_header, data, type); - } - - gst_buffer_list_iterator_free (it); -} - -/** - * gst_rtp_buffer_list_set_data: - * @rtp_header: rtp header to be updated - * @data: data to be set - * @type: which field in the header to be set - * - * Sets the field specified by @type to @data. - * When setting SEQ number, this function will also increase - * @data by one. - */ -static void -gst_rtp_buffer_list_set_data (guint8 * rtp_header, - gpointer data, rtp_header_data_type type) -{ - switch (type) { - case PAYLOAD_TYPE: - GST_RTP_HEADER_PAYLOAD_TYPE (rtp_header) = *(guint8 *) data; - break; - case SEQ: - GST_RTP_HEADER_SEQ (rtp_header) = g_htons (*(guint16 *) data); - (*(guint16 *) data)++; - break; - case SSRC: - GST_RTP_HEADER_SSRC (rtp_header) = g_htonl (*(guint32 *) data); - break; - case TIMESTAMP: - GST_RTP_HEADER_TIMESTAMP (rtp_header) = g_htonl (*(guint32 *) data); - break; - default: - g_warning ("Unknown data type"); - break; - } -} diff --git a/win32/common/libgstrtp.def b/win32/common/libgstrtp.def index 75b2c7c3a..50612fdaf 100644 --- a/win32/common/libgstrtp.def +++ b/win32/common/libgstrtp.def @@ -87,6 +87,15 @@ EXPORTS gst_rtp_buffer_get_ssrc gst_rtp_buffer_get_timestamp gst_rtp_buffer_get_version + gst_rtp_buffer_list_get_payload_len + gst_rtp_buffer_list_get_payload_type + gst_rtp_buffer_list_get_ssrc + gst_rtp_buffer_list_get_timestamp + gst_rtp_buffer_list_set_payload_type + gst_rtp_buffer_list_set_seq + gst_rtp_buffer_list_set_ssrc + gst_rtp_buffer_list_set_timestamp + gst_rtp_buffer_list_validate gst_rtp_buffer_new_allocate gst_rtp_buffer_new_allocate_len gst_rtp_buffer_new_copy_data |