sctp: Constify buffers in callbacks and functions

And free data with the correct free() function in the receive callback
by passing it to gst_buffer_new_wrapped_full() instead of
gst_buffer_new_wrapped().
This commit is contained in:
Sebastian Dröge 2020-01-30 16:09:40 +02:00
parent fa0a233fa7
commit e9df80b235
3 changed files with 23 additions and 12 deletions

View file

@ -155,8 +155,9 @@ static void gst_sctp_data_srcpad_loop (GstPad * pad);
static gboolean configure_association (GstSctpDec * self);
static void on_gst_sctp_association_stream_reset (GstSctpAssociation *
gst_sctp_association, guint16 stream_id, GstSctpDec * self);
static void on_receive (GstSctpAssociation * gst_sctp_association, guint8 * buf,
gsize length, guint16 stream_id, guint ppid, gpointer user_data);
static void on_receive (GstSctpAssociation * gst_sctp_association,
guint8 * buf, gsize length, guint16 stream_id, guint ppid,
gpointer user_data);
static void stop_srcpad_task (GstPad * pad);
static void stop_all_srcpad_tasks (GstSctpDec * self);
static void sctpdec_cleanup (GstSctpDec * self);
@ -324,7 +325,7 @@ gst_sctp_dec_packet_chain (GstPad * pad, GstSctpDec * self, GstBuffer * buf)
}
gst_sctp_association_incoming_packet (self->sctp_association,
(guint8 *) map.data, (guint32) map.size);
(const guint8 *) map.data, (guint32) map.size);
gst_buffer_unmap (buf, &map);
gst_buffer_unref (buf);
@ -625,8 +626,8 @@ data_queue_item_free (GstDataQueueItem * item)
}
static void
on_receive (GstSctpAssociation * sctp_association, guint8 * buf, gsize length,
guint16 stream_id, guint ppid, gpointer user_data)
on_receive (GstSctpAssociation * sctp_association, guint8 * buf,
gsize length, guint16 stream_id, guint ppid, gpointer user_data)
{
GstSctpDec *self = user_data;
GstSctpDecPad *sctpdec_pad;
@ -638,7 +639,9 @@ on_receive (GstSctpAssociation * sctp_association, guint8 * buf, gsize length,
g_assert (src_pad);
sctpdec_pad = GST_SCTP_DEC_PAD (src_pad);
gstbuf = gst_buffer_new_wrapped (buf, length);
gstbuf =
gst_buffer_new_wrapped_full (0, buf, length, 0, length, buf,
(GDestroyNotify) usrsctp_freedumpbuffer);
gst_sctp_buffer_add_receive_meta (gstbuf, ppid);
item = g_new0 (GstDataQueueItem, 1);

View file

@ -424,14 +424,14 @@ gst_sctp_association_set_on_packet_received (GstSctpAssociation * self,
}
void
gst_sctp_association_incoming_packet (GstSctpAssociation * self, guint8 * buf,
guint32 length)
gst_sctp_association_incoming_packet (GstSctpAssociation * self,
const guint8 * buf, guint32 length)
{
usrsctp_conninput ((void *) self, (const void *) buf, (size_t) length, 0);
}
gboolean
gst_sctp_association_send_data (GstSctpAssociation * self, guint8 * buf,
gst_sctp_association_send_data (GstSctpAssociation * self, const guint8 * buf,
guint32 length, guint16 stream_id, guint32 ppid, gboolean ordered,
GstSctpAssociationPartialReliability pr, guint32 reliability_param)
{
@ -685,6 +685,7 @@ receive_cb (struct socket *sock, union sctp_sockstore addr, void *data,
if (flags & MSG_NOTIFICATION) {
handle_notification (self, (const union sctp_notification *) data,
datalen);
/* We use this instead of a bare `free()` so that we use the `free` from
* the C runtime that usrsctp was built with. This makes a difference on
* Windows where libusrstcp and GStreamer can be linked to two different
@ -826,8 +827,15 @@ handle_message (GstSctpAssociation * self, guint8 * data, guint32 datalen,
{
g_rec_mutex_lock (&self->association_mutex);
if (self->packet_received_cb) {
/* It's the callbacks job to free the data correctly */
self->packet_received_cb (self, data, datalen, stream_id, ppid,
self->packet_received_user_data);
} else {
/* We use this instead of a bare `free()` so that we use the `free` from
* the C runtime that usrsctp was built with. This makes a difference on
* Windows where libusrstcp and GStreamer can be linked to two different
* CRTs. */
usrsctp_freedumpbuffer ((gchar *) data);
}
g_rec_mutex_unlock (&self->association_mutex);
}

View file

@ -111,9 +111,9 @@ void gst_sctp_association_set_on_packet_out (GstSctpAssociation * self,
void gst_sctp_association_set_on_packet_received (GstSctpAssociation * self,
GstSctpAssociationPacketReceivedCb packet_received_cb, gpointer user_data, GDestroyNotify destroy_notify);
void gst_sctp_association_incoming_packet (GstSctpAssociation * self,
guint8 * buf, guint32 length);
gboolean gst_sctp_association_send_data (GstSctpAssociation * self,
guint8 * buf, guint32 length, guint16 stream_id, guint32 ppid,
const guint8 * buf, guint32 length);
gint32 gst_sctp_association_send_data (GstSctpAssociation * self,
const guint8 * buf, guint32 length, guint16 stream_id, guint32 ppid,
gboolean ordered, GstSctpAssociationPartialReliability pr,
guint32 reliability_param);
void gst_sctp_association_reset_stream (GstSctpAssociation * self,