rtpbuffer: keep more state

Prepare for the future, make it possible to map multiple buffer regions, like
the header and the payload.
This commit is contained in:
Wim Taymans 2012-04-02 10:31:18 +02:00
parent 9ef519d99a
commit 92f46c07fe
2 changed files with 49 additions and 42 deletions

View file

@ -423,10 +423,12 @@ gst_rtp_buffer_map (GstBuffer * buffer, GstMapFlags flags, GstRTPBuffer * rtp)
g_return_val_if_fail (rtp != NULL, FALSE); g_return_val_if_fail (rtp != NULL, FALSE);
g_return_val_if_fail (rtp->buffer == NULL, FALSE); g_return_val_if_fail (rtp->buffer == NULL, FALSE);
if (!gst_buffer_map (buffer, &rtp->map, flags)) if (!gst_buffer_map (buffer, &rtp->map[0], flags))
return FALSE; return FALSE;
rtp->buffer = buffer; rtp->buffer = buffer;
rtp->state = 0;
rtp->n_map = 1;
return TRUE; return TRUE;
} }
@ -437,8 +439,9 @@ gst_rtp_buffer_unmap (GstRTPBuffer * rtp)
g_return_val_if_fail (rtp != NULL, FALSE); g_return_val_if_fail (rtp != NULL, FALSE);
g_return_val_if_fail (rtp->buffer != NULL, FALSE); g_return_val_if_fail (rtp->buffer != NULL, FALSE);
gst_buffer_unmap (rtp->buffer, &rtp->map); gst_buffer_unmap (rtp->buffer, &rtp->map[0]);
rtp->buffer = NULL; rtp->buffer = NULL;
rtp->n_map = 0;
return TRUE; return TRUE;
} }
@ -457,15 +460,15 @@ gst_rtp_buffer_set_packet_len (GstRTPBuffer * rtp, guint len)
{ {
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
if (rtp->map.maxsize <= len) { if (rtp->map[0].maxsize <= len) {
/* FIXME, realloc bigger space */ /* FIXME, realloc bigger space */
g_warning ("not implemented"); g_warning ("not implemented");
} }
gst_buffer_set_size (rtp->buffer, len); gst_buffer_set_size (rtp->buffer, len);
rtp->map.size = len; rtp->map[0].size = len;
/* remove any padding */ /* remove any padding */
GST_RTP_HEADER_PADDING (data) = FALSE; GST_RTP_HEADER_PADDING (data) = FALSE;
@ -500,7 +503,7 @@ gst_rtp_buffer_get_header_len (GstRTPBuffer * rtp)
guint len; guint len;
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data); len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data);
if (GST_RTP_HEADER_EXTENSION (data)) if (GST_RTP_HEADER_EXTENSION (data))
@ -520,7 +523,7 @@ gst_rtp_buffer_get_header_len (GstRTPBuffer * rtp)
guint8 guint8
gst_rtp_buffer_get_version (GstRTPBuffer * rtp) gst_rtp_buffer_get_version (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_VERSION (rtp->map.data); return GST_RTP_HEADER_VERSION (rtp->map[0].data);
} }
/** /**
@ -535,7 +538,7 @@ gst_rtp_buffer_set_version (GstRTPBuffer * rtp, guint8 version)
{ {
g_return_if_fail (version < 0x04); g_return_if_fail (version < 0x04);
GST_RTP_HEADER_VERSION (rtp->map.data) = version; GST_RTP_HEADER_VERSION (rtp->map[0].data) = version;
} }
/** /**
@ -549,7 +552,7 @@ gst_rtp_buffer_set_version (GstRTPBuffer * rtp, guint8 version)
gboolean gboolean
gst_rtp_buffer_get_padding (GstRTPBuffer * rtp) gst_rtp_buffer_get_padding (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_PADDING (rtp->map.data); return GST_RTP_HEADER_PADDING (rtp->map[0].data);
} }
/** /**
@ -562,7 +565,7 @@ gst_rtp_buffer_get_padding (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_padding (GstRTPBuffer * rtp, gboolean padding) gst_rtp_buffer_set_padding (GstRTPBuffer * rtp, gboolean padding)
{ {
GST_RTP_HEADER_PADDING (rtp->map.data) = padding; GST_RTP_HEADER_PADDING (rtp->map[0].data) = padding;
} }
/** /**
@ -580,7 +583,7 @@ gst_rtp_buffer_pad_to (GstRTPBuffer * rtp, guint len)
{ {
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
if (len > 0) if (len > 0)
GST_RTP_HEADER_PADDING (data) = TRUE; GST_RTP_HEADER_PADDING (data) = TRUE;
@ -601,7 +604,7 @@ gst_rtp_buffer_pad_to (GstRTPBuffer * rtp, guint len)
gboolean gboolean
gst_rtp_buffer_get_extension (GstRTPBuffer * rtp) gst_rtp_buffer_get_extension (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_EXTENSION (rtp->map.data); return GST_RTP_HEADER_EXTENSION (rtp->map[0].data);
} }
/** /**
@ -614,7 +617,7 @@ gst_rtp_buffer_get_extension (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_extension (GstRTPBuffer * rtp, gboolean extension) gst_rtp_buffer_set_extension (GstRTPBuffer * rtp, gboolean extension)
{ {
GST_RTP_HEADER_EXTENSION (rtp->map.data) = extension; GST_RTP_HEADER_EXTENSION (rtp->map[0].data) = extension;
} }
/** /**
@ -642,7 +645,7 @@ gst_rtp_buffer_get_extension_data (GstRTPBuffer * rtp, guint16 * bits,
guint len; guint len;
guint8 *pdata; guint8 *pdata;
pdata = rtp->map.data; pdata = rtp->map[0].data;
if (!GST_RTP_HEADER_EXTENSION (pdata)) if (!GST_RTP_HEADER_EXTENSION (pdata))
return FALSE; return FALSE;
@ -684,17 +687,17 @@ gst_rtp_buffer_set_extension_data (GstRTPBuffer * rtp, guint16 bits,
guint32 min_size = 0; guint32 min_size = 0;
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
/* check if the buffer is big enough to hold the extension */ /* check if the buffer is big enough to hold the extension */
min_size = min_size =
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data) + 4 + GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data) + 4 +
length * sizeof (guint32); length * sizeof (guint32);
if (G_UNLIKELY (min_size > rtp->map.size)) if (G_UNLIKELY (min_size > rtp->map[0].size))
goto too_small; goto too_small;
/* now we can set the extension bit */ /* now we can set the extension bit */
GST_RTP_HEADER_EXTENSION (rtp->map.data) = TRUE; GST_RTP_HEADER_EXTENSION (rtp->map[0].data) = TRUE;
data += GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data); data += GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data);
GST_WRITE_UINT16_BE (data, bits); GST_WRITE_UINT16_BE (data, bits);
@ -707,7 +710,7 @@ too_small:
{ {
g_warning g_warning
("rtp buffer too small: need more than %d bytes but only have %" ("rtp buffer too small: need more than %d bytes but only have %"
G_GSIZE_FORMAT " bytes", min_size, rtp->map.size); G_GSIZE_FORMAT " bytes", min_size, rtp->map[0].size);
return FALSE; return FALSE;
} }
} }
@ -723,7 +726,7 @@ too_small:
guint32 guint32
gst_rtp_buffer_get_ssrc (GstRTPBuffer * rtp) gst_rtp_buffer_get_ssrc (GstRTPBuffer * rtp)
{ {
return g_ntohl (GST_RTP_HEADER_SSRC (rtp->map.data)); return g_ntohl (GST_RTP_HEADER_SSRC (rtp->map[0].data));
} }
/** /**
@ -736,7 +739,7 @@ gst_rtp_buffer_get_ssrc (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_ssrc (GstRTPBuffer * rtp, guint32 ssrc) gst_rtp_buffer_set_ssrc (GstRTPBuffer * rtp, guint32 ssrc)
{ {
GST_RTP_HEADER_SSRC (rtp->map.data) = g_htonl (ssrc); GST_RTP_HEADER_SSRC (rtp->map[0].data) = g_htonl (ssrc);
} }
/** /**
@ -750,7 +753,7 @@ gst_rtp_buffer_set_ssrc (GstRTPBuffer * rtp, guint32 ssrc)
guint8 guint8
gst_rtp_buffer_get_csrc_count (GstRTPBuffer * rtp) gst_rtp_buffer_get_csrc_count (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_CSRC_COUNT (rtp->map.data); return GST_RTP_HEADER_CSRC_COUNT (rtp->map[0].data);
} }
/** /**
@ -767,7 +770,7 @@ gst_rtp_buffer_get_csrc (GstRTPBuffer * rtp, guint8 idx)
{ {
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data), 0); g_return_val_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data), 0);
@ -787,7 +790,7 @@ gst_rtp_buffer_set_csrc (GstRTPBuffer * rtp, guint8 idx, guint32 csrc)
{ {
guint8 *data; guint8 *data;
data = rtp->map.data; data = rtp->map[0].data;
g_return_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data)); g_return_if_fail (idx < GST_RTP_HEADER_CSRC_COUNT (data));
@ -805,7 +808,7 @@ gst_rtp_buffer_set_csrc (GstRTPBuffer * rtp, guint8 idx, guint32 csrc)
gboolean gboolean
gst_rtp_buffer_get_marker (GstRTPBuffer * rtp) gst_rtp_buffer_get_marker (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_MARKER (rtp->map.data); return GST_RTP_HEADER_MARKER (rtp->map[0].data);
} }
/** /**
@ -818,7 +821,7 @@ gst_rtp_buffer_get_marker (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_marker (GstRTPBuffer * rtp, gboolean marker) gst_rtp_buffer_set_marker (GstRTPBuffer * rtp, gboolean marker)
{ {
GST_RTP_HEADER_MARKER (rtp->map.data) = marker; GST_RTP_HEADER_MARKER (rtp->map[0].data) = marker;
} }
/** /**
@ -832,7 +835,7 @@ gst_rtp_buffer_set_marker (GstRTPBuffer * rtp, gboolean marker)
guint8 guint8
gst_rtp_buffer_get_payload_type (GstRTPBuffer * rtp) gst_rtp_buffer_get_payload_type (GstRTPBuffer * rtp)
{ {
return GST_RTP_HEADER_PAYLOAD_TYPE (rtp->map.data); return GST_RTP_HEADER_PAYLOAD_TYPE (rtp->map[0].data);
} }
/** /**
@ -847,7 +850,7 @@ gst_rtp_buffer_set_payload_type (GstRTPBuffer * rtp, guint8 payload_type)
{ {
g_return_if_fail (payload_type < 0x80); g_return_if_fail (payload_type < 0x80);
GST_RTP_HEADER_PAYLOAD_TYPE (rtp->map.data) = payload_type; GST_RTP_HEADER_PAYLOAD_TYPE (rtp->map[0].data) = payload_type;
} }
/** /**
@ -861,7 +864,7 @@ gst_rtp_buffer_set_payload_type (GstRTPBuffer * rtp, guint8 payload_type)
guint16 guint16
gst_rtp_buffer_get_seq (GstRTPBuffer * rtp) gst_rtp_buffer_get_seq (GstRTPBuffer * rtp)
{ {
return g_ntohs (GST_RTP_HEADER_SEQ (rtp->map.data)); return g_ntohs (GST_RTP_HEADER_SEQ (rtp->map[0].data));
} }
/** /**
@ -874,7 +877,7 @@ gst_rtp_buffer_get_seq (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_seq (GstRTPBuffer * rtp, guint16 seq) gst_rtp_buffer_set_seq (GstRTPBuffer * rtp, guint16 seq)
{ {
GST_RTP_HEADER_SEQ (rtp->map.data) = g_htons (seq); GST_RTP_HEADER_SEQ (rtp->map[0].data) = g_htons (seq);
} }
/** /**
@ -888,7 +891,7 @@ gst_rtp_buffer_set_seq (GstRTPBuffer * rtp, guint16 seq)
guint32 guint32
gst_rtp_buffer_get_timestamp (GstRTPBuffer * rtp) gst_rtp_buffer_get_timestamp (GstRTPBuffer * rtp)
{ {
return g_ntohl (GST_RTP_HEADER_TIMESTAMP (rtp->map.data)); return g_ntohl (GST_RTP_HEADER_TIMESTAMP (rtp->map[0].data));
} }
/** /**
@ -901,7 +904,7 @@ gst_rtp_buffer_get_timestamp (GstRTPBuffer * rtp)
void void
gst_rtp_buffer_set_timestamp (GstRTPBuffer * rtp, guint32 timestamp) gst_rtp_buffer_set_timestamp (GstRTPBuffer * rtp, guint32 timestamp)
{ {
GST_RTP_HEADER_TIMESTAMP (rtp->map.data) = g_htonl (timestamp); GST_RTP_HEADER_TIMESTAMP (rtp->map[0].data) = g_htonl (timestamp);
} }
@ -979,8 +982,8 @@ gst_rtp_buffer_get_payload_len (GstRTPBuffer * rtp)
guint len, size; guint len, size;
guint8 *data; guint8 *data;
size = rtp->map.size; size = rtp->map[0].size;
data = rtp->map.data; data = rtp->map[0].data;
len = size - gst_rtp_buffer_get_header_len (rtp); len = size - gst_rtp_buffer_get_header_len (rtp);
@ -1002,7 +1005,7 @@ gst_rtp_buffer_get_payload_len (GstRTPBuffer * rtp)
gpointer gpointer
gst_rtp_buffer_get_payload (GstRTPBuffer * rtp) gst_rtp_buffer_get_payload (GstRTPBuffer * rtp)
{ {
return rtp->map.data + gst_rtp_buffer_get_header_len (rtp); return rtp->map[0].data + gst_rtp_buffer_get_header_len (rtp);
} }
/** /**
@ -1342,10 +1345,10 @@ gst_rtp_buffer_add_extension_onebyte_header (GstRTPBuffer * rtp, guint8 id,
return FALSE; return FALSE;
nextext = pdata + offset; nextext = pdata + offset;
offset = nextext - rtp->map.data; offset = nextext - rtp->map[0].data;
/* Don't add extra header if there isn't enough space */ /* Don't add extra header if there isn't enough space */
if (rtp->map.size < offset + size + 1) if (rtp->map[0].size < offset + size + 1)
return FALSE; return FALSE;
nextext[0] = (id << 4) | (0x0F & (size - 1)); nextext[0] = (id << 4) | (0x0F & (size - 1));
@ -1462,10 +1465,10 @@ gst_rtp_buffer_add_extension_twobytes_header (GstRTPBuffer * rtp,
nextext = pdata + offset; nextext = pdata + offset;
offset = nextext - rtp->map.data; offset = nextext - rtp->map[0].data;
/* Don't add extra header if there isn't enough space */ /* Don't add extra header if there isn't enough space */
if (rtp->map.size < offset + size + 2) if (rtp->map[0].size < offset + size + 2)
return FALSE; return FALSE;
nextext[0] = id; nextext[0] = id;

View file

@ -42,8 +42,9 @@ typedef struct _GstRTPBuffer GstRTPBuffer;
/** /**
* GstRTPBuffer: * GstRTPBuffer:
* @buffer: pointer to RTP buffer * @buffer: pointer to RTP buffer
* @flags: flags used when mapping * @state: internal state
* @map: the #GstMapInfo * @n_map: number of mappings in @map
* @map: array of #GstMapInfo
* *
* Data structure that points to an RTP packet. * Data structure that points to an RTP packet.
* The size of the structure is made public to allow stack allocations. * The size of the structure is made public to allow stack allocations.
@ -51,10 +52,13 @@ typedef struct _GstRTPBuffer GstRTPBuffer;
struct _GstRTPBuffer struct _GstRTPBuffer
{ {
GstBuffer *buffer; GstBuffer *buffer;
GstMapInfo map; guint state;
guint n_map;
GstMapInfo map[4];
}; };
#define GST_RTP_BUFFER_INIT { NULL, GST_MAP_INFO_INIT} #define GST_RTP_BUFFER_INIT { NULL, { GST_MAP_INFO_INIT, GST_MAP_INFO_INIT, \
GST_MAP_INFO_INIT, GST_MAP_INFO_INIT} }
/* creating buffers */ /* creating buffers */
void gst_rtp_buffer_allocate_data (GstBuffer *buffer, guint payload_len, void gst_rtp_buffer_allocate_data (GstBuffer *buffer, guint payload_len,