diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2020-01-30 16:09:40 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2020-01-31 08:54:49 +0200 |
commit | e9df80b2356a98fc718e72bd54ddf59acc4fbf71 (patch) | |
tree | 98cd00de62c920f15e5412d58e06883c8672b44a /ext/sctp | |
parent | fa0a233fa7237ce6cd26f6408791fbc22f67a2e2 (diff) | |
download | gstreamer-plugins-bad-e9df80b2356a98fc718e72bd54ddf59acc4fbf71.tar.gz |
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().
Diffstat (limited to 'ext/sctp')
-rw-r--r-- | ext/sctp/gstsctpdec.c | 15 | ||||
-rw-r--r-- | ext/sctp/sctpassociation.c | 14 | ||||
-rw-r--r-- | ext/sctp/sctpassociation.h | 6 |
3 files changed, 23 insertions, 12 deletions
diff --git a/ext/sctp/gstsctpdec.c b/ext/sctp/gstsctpdec.c index 08551ad25..bdf24e2f2 100644 --- a/ext/sctp/gstsctpdec.c +++ b/ext/sctp/gstsctpdec.c @@ -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); diff --git a/ext/sctp/sctpassociation.c b/ext/sctp/sctpassociation.c index fb3206380..2a72364cc 100644 --- a/ext/sctp/sctpassociation.c +++ b/ext/sctp/sctpassociation.c @@ -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); } diff --git a/ext/sctp/sctpassociation.h b/ext/sctp/sctpassociation.h index fc5387860..f520994ee 100644 --- a/ext/sctp/sctpassociation.h +++ b/ext/sctp/sctpassociation.h @@ -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, |