+2008-11-13 Wim Taymans <wim.taymans@collabora.co.uk>
+
+ * gst-libs/gst/rtp/gstrtpbuffer.c: (gst_rtp_buffer_validate_data),
+ (gst_rtp_buffer_set_packet_len), (gst_rtp_buffer_get_packet_len),
+ (gst_rtp_buffer_get_header_len), (gst_rtp_buffer_get_version),
+ (gst_rtp_buffer_set_version), (gst_rtp_buffer_get_padding),
+ (gst_rtp_buffer_set_padding), (gst_rtp_buffer_pad_to),
+ (gst_rtp_buffer_get_extension), (gst_rtp_buffer_set_extension),
+ (gst_rtp_buffer_get_extension_data),
+ (gst_rtp_buffer_set_extension_data), (gst_rtp_buffer_get_ssrc),
+ (gst_rtp_buffer_set_ssrc), (gst_rtp_buffer_get_csrc_count),
+ (gst_rtp_buffer_get_csrc), (gst_rtp_buffer_set_csrc),
+ (gst_rtp_buffer_get_marker), (gst_rtp_buffer_set_marker),
+ (gst_rtp_buffer_get_payload_type),
+ (gst_rtp_buffer_set_payload_type), (gst_rtp_buffer_get_seq),
+ (gst_rtp_buffer_set_seq), (gst_rtp_buffer_get_timestamp),
+ (gst_rtp_buffer_set_timestamp),
+ (gst_rtp_buffer_get_payload_subbuffer),
+ (gst_rtp_buffer_get_payload_len), (gst_rtp_buffer_get_payload):
+ Avoid expensive type checks we already did as part of the
+ _validate() function that should be called first.
+
2008-11-11 Wim Taymans <wim.taymans@collabora.co.uk>
* gst-libs/gst/rtp/gstbasertpdepayload.c: (create_segment_event),
goto wrong_length;
/* check version */
- version = (data[0] & 0xc0) >> 6;
- if (G_UNLIKELY (version != GST_RTP_VERSION))
+ version = (data[0] & 0xc0);
+ if (G_UNLIKELY (version != (GST_RTP_VERSION << 6)))
goto wrong_version;
/* calc header length with csrc */
*
* Check if the data pointed to by @buffer is a valid RTP packet using
* gst_rtp_buffer_validate_data().
+ * Use this function to validate a packet before using the other functions in
+ * this module.
*
* Returns: TRUE if @buffer is a valid RTP packet.
*/
{
guint oldlen;
- g_return_if_fail (GST_IS_BUFFER (buffer));
-
oldlen = GST_BUFFER_SIZE (buffer);
if (oldlen < len) {
guint
gst_rtp_buffer_get_packet_len (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
-
return GST_BUFFER_SIZE (buffer);
}
{
guint len;
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
-
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer);
if (GST_RTP_HEADER_EXTENSION (buffer))
len += GST_READ_UINT16_BE (GST_BUFFER_DATA (buffer) + len + 2) * 4 + 4;
guint8
gst_rtp_buffer_get_version (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return GST_RTP_HEADER_VERSION (buffer);
}
void
gst_rtp_buffer_set_version (GstBuffer * buffer, guint8 version)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
g_return_if_fail (version < 0x04);
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
GST_RTP_HEADER_VERSION (buffer) = version;
}
gboolean
gst_rtp_buffer_get_padding (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
-
return GST_RTP_HEADER_PADDING (buffer);
}
void
gst_rtp_buffer_set_padding (GstBuffer * buffer, gboolean padding)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_PADDING (buffer) = padding;
}
void
gst_rtp_buffer_pad_to (GstBuffer * buffer, guint len)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
if (len > 0)
GST_RTP_HEADER_PADDING (buffer) = TRUE;
else
gboolean
gst_rtp_buffer_get_extension (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
-
return GST_RTP_HEADER_EXTENSION (buffer);
}
void
gst_rtp_buffer_set_extension (GstBuffer * buffer, gboolean extension)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_EXTENSION (buffer) = extension;
}
guint len;
guint8 *pdata;
- g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
-
if (!GST_RTP_HEADER_EXTENSION (buffer))
return FALSE;
guint32 min_size = 0;
guint8 *data;
- g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
-
/* check if the buffer is big enough to hold the extension */
min_size =
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer) + 4 +
guint32
gst_rtp_buffer_get_ssrc (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return g_ntohl (GST_RTP_HEADER_SSRC (buffer));
}
void
gst_rtp_buffer_set_ssrc (GstBuffer * buffer, guint32 ssrc)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_SSRC (buffer) = g_htonl (ssrc);
}
guint8
gst_rtp_buffer_get_csrc_count (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return GST_RTP_HEADER_CSRC_COUNT (buffer);
}
guint32
gst_rtp_buffer_get_csrc (GstBuffer * buffer, guint8 idx)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (buffer), 0);
return GST_READ_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, idx));
void
gst_rtp_buffer_set_csrc (GstBuffer * buffer, guint8 idx, guint32 csrc)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
g_return_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (buffer));
GST_WRITE_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, idx), csrc);
gboolean
gst_rtp_buffer_get_marker (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, FALSE);
-
return GST_RTP_HEADER_MARKER (buffer);
}
void
gst_rtp_buffer_set_marker (GstBuffer * buffer, gboolean marker)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_MARKER (buffer) = marker;
}
guint8
gst_rtp_buffer_get_payload_type (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return GST_RTP_HEADER_PAYLOAD_TYPE (buffer);
}
void
gst_rtp_buffer_set_payload_type (GstBuffer * buffer, guint8 payload_type)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
g_return_if_fail (payload_type < 0x80);
GST_RTP_HEADER_PAYLOAD_TYPE (buffer) = payload_type;
guint16
gst_rtp_buffer_get_seq (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return g_ntohs (GST_RTP_HEADER_SEQ (buffer));
}
void
gst_rtp_buffer_set_seq (GstBuffer * buffer, guint16 seq)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_SEQ (buffer) = g_htons (seq);
}
guint32
gst_rtp_buffer_get_timestamp (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
return g_ntohl (GST_RTP_HEADER_TIMESTAMP (buffer));
}
void
gst_rtp_buffer_set_timestamp (GstBuffer * buffer, guint32 timestamp)
{
- g_return_if_fail (GST_IS_BUFFER (buffer));
- g_return_if_fail (GST_BUFFER_DATA (buffer) != NULL);
-
GST_RTP_HEADER_TIMESTAMP (buffer) = g_htonl (timestamp);
}
{
guint poffset, plen;
- g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, NULL);
-
plen = gst_rtp_buffer_get_payload_len (buffer);
/* we can't go past the length */
if (G_UNLIKELY (offset >= plen))
{
guint len, size;
- g_return_val_if_fail (GST_IS_BUFFER (buffer), 0);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, 0);
-
size = GST_BUFFER_SIZE (buffer);
len = size - gst_rtp_buffer_get_header_len (buffer);
gpointer
gst_rtp_buffer_get_payload (GstBuffer * buffer)
{
- g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
- g_return_val_if_fail (GST_BUFFER_DATA (buffer) != NULL, NULL);
-
return GST_BUFFER_DATA (buffer) + gst_rtp_buffer_get_header_len (buffer);
}