mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
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:
parent
9ef519d99a
commit
92f46c07fe
2 changed files with 49 additions and 42 deletions
|
@ -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->buffer == NULL, FALSE);
|
||||
|
||||
if (!gst_buffer_map (buffer, &rtp->map, flags))
|
||||
if (!gst_buffer_map (buffer, &rtp->map[0], flags))
|
||||
return FALSE;
|
||||
|
||||
rtp->buffer = buffer;
|
||||
rtp->state = 0;
|
||||
rtp->n_map = 1;
|
||||
|
||||
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->buffer != NULL, FALSE);
|
||||
|
||||
gst_buffer_unmap (rtp->buffer, &rtp->map);
|
||||
gst_buffer_unmap (rtp->buffer, &rtp->map[0]);
|
||||
rtp->buffer = NULL;
|
||||
rtp->n_map = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -457,15 +460,15 @@ gst_rtp_buffer_set_packet_len (GstRTPBuffer * rtp, guint len)
|
|||
{
|
||||
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 */
|
||||
g_warning ("not implemented");
|
||||
}
|
||||
|
||||
gst_buffer_set_size (rtp->buffer, len);
|
||||
rtp->map.size = len;
|
||||
rtp->map[0].size = len;
|
||||
|
||||
/* remove any padding */
|
||||
GST_RTP_HEADER_PADDING (data) = FALSE;
|
||||
|
@ -500,7 +503,7 @@ gst_rtp_buffer_get_header_len (GstRTPBuffer * rtp)
|
|||
guint len;
|
||||
guint8 *data;
|
||||
|
||||
data = rtp->map.data;
|
||||
data = rtp->map[0].data;
|
||||
|
||||
len = GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data);
|
||||
if (GST_RTP_HEADER_EXTENSION (data))
|
||||
|
@ -520,7 +523,7 @@ gst_rtp_buffer_get_header_len (GstRTPBuffer * rtp)
|
|||
guint8
|
||||
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);
|
||||
|
||||
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
|
||||
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
|
||||
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;
|
||||
|
||||
data = rtp->map.data;
|
||||
data = rtp->map[0].data;
|
||||
|
||||
if (len > 0)
|
||||
GST_RTP_HEADER_PADDING (data) = TRUE;
|
||||
|
@ -601,7 +604,7 @@ gst_rtp_buffer_pad_to (GstRTPBuffer * rtp, guint len)
|
|||
gboolean
|
||||
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
|
||||
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;
|
||||
guint8 *pdata;
|
||||
|
||||
pdata = rtp->map.data;
|
||||
pdata = rtp->map[0].data;
|
||||
|
||||
if (!GST_RTP_HEADER_EXTENSION (pdata))
|
||||
return FALSE;
|
||||
|
@ -684,17 +687,17 @@ gst_rtp_buffer_set_extension_data (GstRTPBuffer * rtp, guint16 bits,
|
|||
guint32 min_size = 0;
|
||||
guint8 *data;
|
||||
|
||||
data = rtp->map.data;
|
||||
data = rtp->map[0].data;
|
||||
|
||||
/* check if the buffer is big enough to hold the extension */
|
||||
min_size =
|
||||
GST_RTP_HEADER_LEN + GST_RTP_HEADER_CSRC_SIZE (data) + 4 +
|
||||
length * sizeof (guint32);
|
||||
if (G_UNLIKELY (min_size > rtp->map.size))
|
||||
if (G_UNLIKELY (min_size > rtp->map[0].size))
|
||||
goto too_small;
|
||||
|
||||
/* 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);
|
||||
GST_WRITE_UINT16_BE (data, bits);
|
||||
|
@ -707,7 +710,7 @@ too_small:
|
|||
{
|
||||
g_warning
|
||||
("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;
|
||||
}
|
||||
}
|
||||
|
@ -723,7 +726,7 @@ too_small:
|
|||
guint32
|
||||
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
|
||||
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
|
||||
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;
|
||||
|
||||
data = rtp->map.data;
|
||||
data = rtp->map[0].data;
|
||||
|
||||
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;
|
||||
|
||||
data = rtp->map.data;
|
||||
data = rtp->map[0].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
|
||||
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
|
||||
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
|
||||
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);
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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;
|
||||
guint8 *data;
|
||||
|
||||
size = rtp->map.size;
|
||||
data = rtp->map.data;
|
||||
size = rtp->map[0].size;
|
||||
data = rtp->map[0].data;
|
||||
|
||||
len = size - gst_rtp_buffer_get_header_len (rtp);
|
||||
|
||||
|
@ -1002,7 +1005,7 @@ gst_rtp_buffer_get_payload_len (GstRTPBuffer * rtp)
|
|||
gpointer
|
||||
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;
|
||||
|
||||
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 */
|
||||
if (rtp->map.size < offset + size + 1)
|
||||
if (rtp->map[0].size < offset + size + 1)
|
||||
return FALSE;
|
||||
|
||||
nextext[0] = (id << 4) | (0x0F & (size - 1));
|
||||
|
@ -1462,10 +1465,10 @@ gst_rtp_buffer_add_extension_twobytes_header (GstRTPBuffer * rtp,
|
|||
|
||||
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 */
|
||||
if (rtp->map.size < offset + size + 2)
|
||||
if (rtp->map[0].size < offset + size + 2)
|
||||
return FALSE;
|
||||
|
||||
nextext[0] = id;
|
||||
|
|
|
@ -42,8 +42,9 @@ typedef struct _GstRTPBuffer GstRTPBuffer;
|
|||
/**
|
||||
* GstRTPBuffer:
|
||||
* @buffer: pointer to RTP buffer
|
||||
* @flags: flags used when mapping
|
||||
* @map: the #GstMapInfo
|
||||
* @state: internal state
|
||||
* @n_map: number of mappings in @map
|
||||
* @map: array of #GstMapInfo
|
||||
*
|
||||
* Data structure that points to an RTP packet.
|
||||
* The size of the structure is made public to allow stack allocations.
|
||||
|
@ -51,10 +52,13 @@ typedef struct _GstRTPBuffer GstRTPBuffer;
|
|||
struct _GstRTPBuffer
|
||||
{
|
||||
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 */
|
||||
void gst_rtp_buffer_allocate_data (GstBuffer *buffer, guint payload_len,
|
||||
|
|
Loading…
Reference in a new issue