rtp: pass data to macros instead of GstBuffer

This commit is contained in:
Wim Taymans 2009-06-18 18:03:40 +02:00
parent e0ba5bf646
commit f385081c92

View file

@ -69,20 +69,19 @@ typedef struct _GstRTPHeader
guint8 csrclist[4]; /* optional CSRC list, 32 bits each */
} GstRTPHeader;
#define GST_RTP_HEADER_VERSION(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->version)
#define GST_RTP_HEADER_PADDING(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->padding)
#define GST_RTP_HEADER_EXTENSION(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->extension)
#define GST_RTP_HEADER_CSRC_COUNT(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->csrc_count)
#define GST_RTP_HEADER_MARKER(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->marker)
#define GST_RTP_HEADER_PAYLOAD_TYPE(buf)(((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->payload_type)
#define GST_RTP_HEADER_SEQ(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->seq)
#define GST_RTP_HEADER_TIMESTAMP(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->timestamp)
#define GST_RTP_HEADER_SSRC(buf) (((GstRTPHeader *)(GST_BUFFER_DATA (buf)))->ssrc)
#define GST_RTP_HEADER_CSRC_LIST_OFFSET(buf,i) \
GST_BUFFER_DATA (buf) + \
G_STRUCT_OFFSET(GstRTPHeader, csrclist) + \
#define GST_RTP_HEADER_VERSION(data) (((GstRTPHeader *)(data))->version)
#define GST_RTP_HEADER_PADDING(data) (((GstRTPHeader *)(data))->padding)
#define GST_RTP_HEADER_EXTENSION(data) (((GstRTPHeader *)(data))->extension)
#define GST_RTP_HEADER_CSRC_COUNT(data) (((GstRTPHeader *)(data))->csrc_count)
#define GST_RTP_HEADER_MARKER(data) (((GstRTPHeader *)(data))->marker)
#define GST_RTP_HEADER_PAYLOAD_TYPE(data) (((GstRTPHeader *)(data))->payload_type)
#define GST_RTP_HEADER_SEQ(data) (((GstRTPHeader *)(data))->seq)
#define GST_RTP_HEADER_TIMESTAMP(data) (((GstRTPHeader *)(data))->timestamp)
#define GST_RTP_HEADER_SSRC(data) (((GstRTPHeader *)(data))->ssrc)
#define GST_RTP_HEADER_CSRC_LIST_OFFSET(data,i) \
data + G_STRUCT_OFFSET(GstRTPHeader, csrclist) + \
((i) * sizeof(guint32))
#define GST_RTP_HEADER_CSRC_SIZE(buf) (GST_RTP_HEADER_CSRC_COUNT(buf) * sizeof (guint32))
#define GST_RTP_HEADER_CSRC_SIZE(data) (GST_RTP_HEADER_CSRC_COUNT(data) * sizeof (guint32))
/**
* gst_rtp_buffer_allocate_data:
@ -101,6 +100,7 @@ gst_rtp_buffer_allocate_data (GstBuffer * buffer, guint payload_len,
guint8 pad_len, guint8 csrc_count)
{
guint len;
guint8 *data;
g_return_if_fail (csrc_count <= 15);
g_return_if_fail (GST_IS_BUFFER (buffer));
@ -108,22 +108,23 @@ gst_rtp_buffer_allocate_data (GstBuffer * buffer, guint payload_len,
len = GST_RTP_HEADER_LEN + csrc_count * sizeof (guint32)
+ payload_len + pad_len;
GST_BUFFER_MALLOCDATA (buffer) = g_malloc (len);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
data = g_malloc (len);
GST_BUFFER_MALLOCDATA (buffer) = data;
GST_BUFFER_DATA (buffer) = data;
GST_BUFFER_SIZE (buffer) = len;
/* fill in defaults */
GST_RTP_HEADER_VERSION (buffer) = GST_RTP_VERSION;
GST_RTP_HEADER_PADDING (buffer) = FALSE;
GST_RTP_HEADER_EXTENSION (buffer) = FALSE;
GST_RTP_HEADER_CSRC_COUNT (buffer) = csrc_count;
memset (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, 0), 0,
GST_RTP_HEADER_VERSION (data) = GST_RTP_VERSION;
GST_RTP_HEADER_PADDING (data) = FALSE;
GST_RTP_HEADER_EXTENSION (data) = FALSE;
GST_RTP_HEADER_CSRC_COUNT (data) = csrc_count;
memset (GST_RTP_HEADER_CSRC_LIST_OFFSET (data, 0), 0,
csrc_count * sizeof (guint32));
GST_RTP_HEADER_MARKER (buffer) = FALSE;
GST_RTP_HEADER_PAYLOAD_TYPE (buffer) = 0;
GST_RTP_HEADER_SEQ (buffer) = 0;
GST_RTP_HEADER_TIMESTAMP (buffer) = 0;
GST_RTP_HEADER_SSRC (buffer) = 0;
GST_RTP_HEADER_MARKER (data) = FALSE;
GST_RTP_HEADER_PAYLOAD_TYPE (data) = 0;
GST_RTP_HEADER_SEQ (data) = 0;
GST_RTP_HEADER_TIMESTAMP (data) = 0;
GST_RTP_HEADER_SSRC (data) = 0;
}
/**
@ -406,20 +407,20 @@ void
gst_rtp_buffer_set_packet_len (GstBuffer * buffer, guint len)
{
guint oldlen;
guint8 *data;
oldlen = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
if (oldlen < len) {
guint8 *newdata;
newdata = g_realloc (GST_BUFFER_MALLOCDATA (buffer), len);
GST_BUFFER_MALLOCDATA (buffer) = newdata;
GST_BUFFER_DATA (buffer) = newdata;
data = g_realloc (GST_BUFFER_MALLOCDATA (buffer), len);
GST_BUFFER_MALLOCDATA (buffer) = data;
GST_BUFFER_DATA (buffer) = data;
}
GST_BUFFER_SIZE (buffer) = len;
/* remove any padding */
GST_RTP_HEADER_PADDING (buffer) = FALSE;
GST_RTP_HEADER_PADDING (data) = FALSE;
}
/**
@ -449,10 +450,13 @@ guint
gst_rtp_buffer_get_header_len (GstBuffer * buffer)
{
guint len;
guint8 *data;
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;
data = GST_BUFFER_DATA (buffer);
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data);
if (GST_RTP_HEADER_EXTENSION (data))
len += GST_READ_UINT16_BE (data + len + 2) * 4 + 4;
return len;
}
@ -468,7 +472,7 @@ gst_rtp_buffer_get_header_len (GstBuffer * buffer)
guint8
gst_rtp_buffer_get_version (GstBuffer * buffer)
{
return GST_RTP_HEADER_VERSION (buffer);
return GST_RTP_HEADER_VERSION (GST_BUFFER_DATA (buffer));
}
/**
@ -483,7 +487,7 @@ gst_rtp_buffer_set_version (GstBuffer * buffer, guint8 version)
{
g_return_if_fail (version < 0x04);
GST_RTP_HEADER_VERSION (buffer) = version;
GST_RTP_HEADER_VERSION (GST_BUFFER_DATA (buffer)) = version;
}
/**
@ -497,7 +501,7 @@ gst_rtp_buffer_set_version (GstBuffer * buffer, guint8 version)
gboolean
gst_rtp_buffer_get_padding (GstBuffer * buffer)
{
return GST_RTP_HEADER_PADDING (buffer);
return GST_RTP_HEADER_PADDING (GST_BUFFER_DATA (buffer));
}
/**
@ -510,7 +514,7 @@ gst_rtp_buffer_get_padding (GstBuffer * buffer)
void
gst_rtp_buffer_set_padding (GstBuffer * buffer, gboolean padding)
{
GST_RTP_HEADER_PADDING (buffer) = padding;
GST_RTP_HEADER_PADDING (GST_BUFFER_DATA (buffer)) = padding;
}
/**
@ -526,10 +530,14 @@ gst_rtp_buffer_set_padding (GstBuffer * buffer, gboolean padding)
void
gst_rtp_buffer_pad_to (GstBuffer * buffer, guint len)
{
guint8 *data;
data = GST_BUFFER_DATA (buffer);
if (len > 0)
GST_RTP_HEADER_PADDING (buffer) = TRUE;
GST_RTP_HEADER_PADDING (data) = TRUE;
else
GST_RTP_HEADER_PADDING (buffer) = FALSE;
GST_RTP_HEADER_PADDING (data) = FALSE;
/* FIXME, set the padding byte at the end of the payload data */
}
@ -545,7 +553,7 @@ gst_rtp_buffer_pad_to (GstBuffer * buffer, guint len)
gboolean
gst_rtp_buffer_get_extension (GstBuffer * buffer)
{
return GST_RTP_HEADER_EXTENSION (buffer);
return GST_RTP_HEADER_EXTENSION (GST_BUFFER_DATA (buffer));
}
/**
@ -558,7 +566,7 @@ gst_rtp_buffer_get_extension (GstBuffer * buffer)
void
gst_rtp_buffer_set_extension (GstBuffer * buffer, gboolean extension)
{
GST_RTP_HEADER_EXTENSION (buffer) = extension;
GST_RTP_HEADER_EXTENSION (GST_BUFFER_DATA (buffer)) = extension;
}
/**
@ -586,12 +594,14 @@ gst_rtp_buffer_get_extension_data (GstBuffer * buffer, guint16 * bits,
guint len;
guint8 *pdata;
if (!GST_RTP_HEADER_EXTENSION (buffer))
pdata = GST_BUFFER_DATA (buffer);
if (!GST_RTP_HEADER_EXTENSION (pdata))
return FALSE;
/* move to the extension */
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer);
pdata = GST_BUFFER_DATA (buffer) + len;
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (pdata);
pdata += len;
if (bits)
*bits = GST_READ_UINT16_BE (pdata);
@ -625,9 +635,11 @@ gst_rtp_buffer_set_extension_data (GstBuffer * buffer, guint16 bits,
guint32 min_size = 0;
guint8 *data;
data = GST_BUFFER_DATA (buffer);
/* check if the buffer is big enough to hold the extension */
min_size =
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (buffer) + 4 +
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data) + 4 +
length * sizeof (guint32);
if (G_UNLIKELY (min_size > GST_BUFFER_SIZE (buffer)))
goto too_small;
@ -635,8 +647,7 @@ gst_rtp_buffer_set_extension_data (GstBuffer * buffer, guint16 bits,
/* now we can set the extension bit */
gst_rtp_buffer_set_extension (buffer, TRUE);
data = GST_BUFFER_DATA (buffer) + GST_RTP_HEADER_LEN +
GST_RTP_HEADER_CSRC_SIZE (buffer);
data += GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data);
GST_WRITE_UINT16_BE (data, bits);
GST_WRITE_UINT16_BE (data + 2, length);
@ -663,7 +674,7 @@ too_small:
guint32
gst_rtp_buffer_get_ssrc (GstBuffer * buffer)
{
return g_ntohl (GST_RTP_HEADER_SSRC (buffer));
return g_ntohl (GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer)));
}
/**
@ -676,7 +687,7 @@ gst_rtp_buffer_get_ssrc (GstBuffer * buffer)
void
gst_rtp_buffer_set_ssrc (GstBuffer * buffer, guint32 ssrc)
{
GST_RTP_HEADER_SSRC (buffer) = g_htonl (ssrc);
GST_RTP_HEADER_SSRC (GST_BUFFER_DATA (buffer)) = g_htonl (ssrc);
}
/**
@ -690,7 +701,7 @@ gst_rtp_buffer_set_ssrc (GstBuffer * buffer, guint32 ssrc)
guint8
gst_rtp_buffer_get_csrc_count (GstBuffer * buffer)
{
return GST_RTP_HEADER_CSRC_COUNT (buffer);
return GST_RTP_HEADER_CSRC_COUNT (GST_BUFFER_DATA (buffer));
}
/**
@ -705,9 +716,13 @@ gst_rtp_buffer_get_csrc_count (GstBuffer * buffer)
guint32
gst_rtp_buffer_get_csrc (GstBuffer * buffer, guint8 idx)
{
g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (buffer), 0);
guint8 *data;
return GST_READ_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, idx));
data = GST_BUFFER_DATA (buffer);
g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data), 0);
return GST_READ_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (data, idx));
}
/**
@ -721,9 +736,13 @@ gst_rtp_buffer_get_csrc (GstBuffer * buffer, guint8 idx)
void
gst_rtp_buffer_set_csrc (GstBuffer * buffer, guint8 idx, guint32 csrc)
{
g_return_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (buffer));
guint8 *data;
GST_WRITE_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (buffer, idx), csrc);
data = GST_BUFFER_DATA (buffer);
g_return_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data));
GST_WRITE_UINT32_BE (GST_RTP_HEADER_CSRC_LIST_OFFSET (data, idx), csrc);
}
/**
@ -737,7 +756,7 @@ gst_rtp_buffer_set_csrc (GstBuffer * buffer, guint8 idx, guint32 csrc)
gboolean
gst_rtp_buffer_get_marker (GstBuffer * buffer)
{
return GST_RTP_HEADER_MARKER (buffer);
return GST_RTP_HEADER_MARKER (GST_BUFFER_DATA (buffer));
}
/**
@ -750,7 +769,7 @@ gst_rtp_buffer_get_marker (GstBuffer * buffer)
void
gst_rtp_buffer_set_marker (GstBuffer * buffer, gboolean marker)
{
GST_RTP_HEADER_MARKER (buffer) = marker;
GST_RTP_HEADER_MARKER (GST_BUFFER_DATA (buffer)) = marker;
}
/**
@ -764,7 +783,7 @@ gst_rtp_buffer_set_marker (GstBuffer * buffer, gboolean marker)
guint8
gst_rtp_buffer_get_payload_type (GstBuffer * buffer)
{
return GST_RTP_HEADER_PAYLOAD_TYPE (buffer);
return GST_RTP_HEADER_PAYLOAD_TYPE (GST_BUFFER_DATA (buffer));
}
/**
@ -779,7 +798,7 @@ gst_rtp_buffer_set_payload_type (GstBuffer * buffer, guint8 payload_type)
{
g_return_if_fail (payload_type < 0x80);
GST_RTP_HEADER_PAYLOAD_TYPE (buffer) = payload_type;
GST_RTP_HEADER_PAYLOAD_TYPE (GST_BUFFER_DATA (buffer)) = payload_type;
}
/**
@ -793,7 +812,7 @@ gst_rtp_buffer_set_payload_type (GstBuffer * buffer, guint8 payload_type)
guint16
gst_rtp_buffer_get_seq (GstBuffer * buffer)
{
return g_ntohs (GST_RTP_HEADER_SEQ (buffer));
return g_ntohs (GST_RTP_HEADER_SEQ (GST_BUFFER_DATA (buffer)));
}
/**
@ -806,7 +825,7 @@ gst_rtp_buffer_get_seq (GstBuffer * buffer)
void
gst_rtp_buffer_set_seq (GstBuffer * buffer, guint16 seq)
{
GST_RTP_HEADER_SEQ (buffer) = g_htons (seq);
GST_RTP_HEADER_SEQ (GST_BUFFER_DATA (buffer)) = g_htons (seq);
}
/**
@ -820,7 +839,7 @@ gst_rtp_buffer_set_seq (GstBuffer * buffer, guint16 seq)
guint32
gst_rtp_buffer_get_timestamp (GstBuffer * buffer)
{
return g_ntohl (GST_RTP_HEADER_TIMESTAMP (buffer));
return g_ntohl (GST_RTP_HEADER_TIMESTAMP (GST_BUFFER_DATA (buffer)));
}
/**
@ -833,7 +852,7 @@ gst_rtp_buffer_get_timestamp (GstBuffer * buffer)
void
gst_rtp_buffer_set_timestamp (GstBuffer * buffer, guint32 timestamp)
{
GST_RTP_HEADER_TIMESTAMP (buffer) = g_htonl (timestamp);
GST_RTP_HEADER_TIMESTAMP (GST_BUFFER_DATA (buffer)) = g_htonl (timestamp);
}
/**
@ -907,13 +926,15 @@ guint
gst_rtp_buffer_get_payload_len (GstBuffer * buffer)
{
guint len, size;
guint8 *data;
size = GST_BUFFER_SIZE (buffer);
data = GST_BUFFER_DATA (buffer);
len = size - gst_rtp_buffer_get_header_len (buffer);
if (GST_RTP_HEADER_PADDING (buffer))
len -= GST_BUFFER_DATA (buffer)[size - 1];
if (GST_RTP_HEADER_PADDING (data))
len -= data[size - 1];
return len;
}