rtprtx: don't access type-system per buffer
authorHavard Graff <havard@pexip.com>
Mon, 8 Feb 2021 20:40:19 +0000 (21:40 +0100)
committerNirbheek Chauhan <nirbheek@centricular.com>
Mon, 7 Mar 2022 22:01:03 +0000 (22:01 +0000)
When doing only a single stream of audio/video this hardly matters,
but when doing many at the same time, the fact that you have to get
a hold of the glib global type-system lock every time you process a buffer,
means that there is a limit to how many streams you can process in
parallel.

Luckily the fix is very simple, by doing a cast rather than a full
type-check.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1873>

subprojects/gst-plugins-good/gst/rtpmanager/gstrtprtxreceive.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtprtxreceive.h
subprojects/gst-plugins-good/gst/rtpmanager/gstrtprtxsend.c
subprojects/gst-plugins-good/gst/rtpmanager/gstrtprtxsend.h

index 8a315f0..44adbb4 100644 (file)
@@ -258,7 +258,7 @@ gst_rtp_rtx_receive_reset (GstRtpRtxReceive * rtx)
 static void
 gst_rtp_rtx_receive_finalize (GObject * object)
 {
-  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE (object);
+  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE_CAST (object);
 
   g_hash_table_unref (rtx->ssrc2_ssrc1_map);
   g_hash_table_unref (rtx->seqnum_ssrc1_map);
@@ -326,7 +326,7 @@ static gboolean
 gst_rtp_rtx_receive_src_event (GstPad * pad, GstObject * parent,
     GstEvent * event)
 {
-  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE (parent);
+  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE_CAST (parent);
   gboolean res;
 
   switch (GST_EVENT_TYPE (event)) {
@@ -515,7 +515,7 @@ _gst_rtp_buffer_new_from_rtx (GstRTPBuffer * rtp, guint32 ssrc1,
 static GstFlowReturn
 gst_rtp_rtx_receive_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
 {
-  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE (parent);
+  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE_CAST (parent);
   GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
   GstFlowReturn ret = GST_FLOW_OK;
   GstBuffer *new_buffer = NULL;
@@ -692,7 +692,7 @@ static void
 gst_rtp_rtx_receive_get_property (GObject * object,
     guint prop_id, GValue * value, GParamSpec * pspec)
 {
-  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE (object);
+  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE_CAST (object);
 
   switch (prop_id) {
     case PROP_PAYLOAD_TYPE_MAP:
@@ -742,7 +742,7 @@ static void
 gst_rtp_rtx_receive_set_property (GObject * object,
     guint prop_id, const GValue * value, GParamSpec * pspec)
 {
-  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE (object);
+  GstRtpRtxReceive *rtx = GST_RTP_RTX_RECEIVE_CAST (object);
 
   switch (prop_id) {
     case PROP_PAYLOAD_TYPE_MAP:
@@ -768,7 +768,7 @@ gst_rtp_rtx_receive_change_state (GstElement * element,
   GstStateChangeReturn ret;
   GstRtpRtxReceive *rtx;
 
-  rtx = GST_RTP_RTX_RECEIVE (element);
+  rtx = GST_RTP_RTX_RECEIVE_CAST (element);
 
   switch (transition) {
     default:
index 4012780..96f1fef 100644 (file)
 #include <gst/rtp/gstrtpbuffer.h>
 
 G_BEGIN_DECLS
+typedef struct _GstRtpRtxReceive GstRtpRtxReceive;
+typedef struct _GstRtpRtxReceiveClass GstRtpRtxReceiveClass;
+
 #define GST_TYPE_RTP_RTX_RECEIVE (gst_rtp_rtx_receive_get_type())
 #define GST_RTP_RTX_RECEIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_RTX_RECEIVE, GstRtpRtxReceive))
 #define GST_RTP_RTX_RECEIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_RTX_RECEIVE, GstRtpRtxReceiveClass))
 #define GST_RTP_RTX_RECEIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTP_RTX_RECEIVE, GstRtpRtxReceiveClass))
 #define GST_IS_RTP_RTX_RECEIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_RTX_RECEIVE))
 #define GST_IS_RTP_RTX_RECEIVE_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_RTX_RECEIVE))
-typedef struct _GstRtpRtxReceive GstRtpRtxReceive;
-typedef struct _GstRtpRtxReceiveClass GstRtpRtxReceiveClass;
+#define GST_RTP_RTX_RECEIVE_CAST(obj) ((GstRtpRtxReceive *)(obj))
 
 struct _GstRtpRtxReceive
 {
index e24bf88..2fa42b0 100644 (file)
@@ -229,7 +229,7 @@ gst_rtp_rtx_send_reset (GstRtpRtxSend * rtx)
 static void
 gst_rtp_rtx_send_finalize (GObject * object)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (object);
 
   g_hash_table_unref (rtx->ssrc_data);
   g_hash_table_unref (rtx->rtx_ssrcs);
@@ -464,7 +464,7 @@ buffer_queue_items_cmp (BufferQueueItem * a, BufferQueueItem * b,
 static gboolean
 gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (parent);
   gboolean res;
 
   switch (GST_EVENT_TYPE (event)) {
@@ -604,7 +604,7 @@ gst_rtp_rtx_send_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
 static gboolean
 gst_rtp_rtx_send_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (parent);
 
   switch (GST_EVENT_TYPE (event)) {
     case GST_EVENT_FLUSH_START:
@@ -768,7 +768,7 @@ process_buffer (GstRtpRtxSend * rtx, GstBuffer * buffer)
 static GstFlowReturn
 gst_rtp_rtx_send_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (parent);
   GstFlowReturn ret;
 
   GST_OBJECT_LOCK (rtx);
@@ -790,7 +790,7 @@ static GstFlowReturn
 gst_rtp_rtx_send_chain_list (GstPad * pad, GstObject * parent,
     GstBufferList * list)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (parent);
   GstFlowReturn ret;
 
   GST_OBJECT_LOCK (rtx);
@@ -841,7 +841,7 @@ static gboolean
 gst_rtp_rtx_send_activate_mode (GstPad * pad, GstObject * parent,
     GstPadMode mode, gboolean active)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (parent);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (parent);
   gboolean ret = FALSE;
 
   switch (mode) {
@@ -866,7 +866,7 @@ static void
 gst_rtp_rtx_send_get_property (GObject * object,
     guint prop_id, GValue * value, GParamSpec * pspec)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (object);
 
   switch (prop_id) {
     case PROP_PAYLOAD_TYPE_MAP:
@@ -925,7 +925,7 @@ static void
 gst_rtp_rtx_send_set_property (GObject * object,
     guint prop_id, const GValue * value, GParamSpec * pspec)
 {
-  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND (object);
+  GstRtpRtxSend *rtx = GST_RTP_RTX_SEND_CAST (object);
 
   switch (prop_id) {
     case PROP_SSRC_MAP:
@@ -977,7 +977,7 @@ gst_rtp_rtx_send_change_state (GstElement * element, GstStateChange transition)
   GstStateChangeReturn ret;
   GstRtpRtxSend *rtx;
 
-  rtx = GST_RTP_RTX_SEND (element);
+  rtx = GST_RTP_RTX_SEND_CAST (element);
 
   switch (transition) {
     default:
index b70422f..5a74609 100644 (file)
 #include <gst/base/gstdataqueue.h>
 
 G_BEGIN_DECLS
+
+typedef struct _GstRtpRtxSend GstRtpRtxSend;
+typedef struct _GstRtpRtxSendClass GstRtpRtxSendClass;
+
 #define GST_TYPE_RTP_RTX_SEND (gst_rtp_rtx_send_get_type())
 #define GST_RTP_RTX_SEND(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_RTX_SEND, GstRtpRtxSend))
 #define GST_RTP_RTX_SEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_RTX_SEND, GstRtpRtxSendClass))
 #define GST_RTP_RTX_SEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_RTP_RTX_SEND, GstRtpRtxSendClass))
 #define GST_IS_RTP_RTX_SEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_RTX_SEND))
 #define GST_IS_RTP_RTX_SEND_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_RTX_SEND))
-typedef struct _GstRtpRtxSend GstRtpRtxSend;
-typedef struct _GstRtpRtxSendClass GstRtpRtxSendClass;
+#define GST_RTP_RTX_SEND_CAST(obj) ((GstRtpRtxSend *)(obj))
 
 struct _GstRtpRtxSend
 {