From 4046970b01bb524007945c8cbb5d7977f256f16e Mon Sep 17 00:00:00 2001 From: Havard Graff Date: Mon, 2 Mar 2020 13:50:55 +0100 Subject: [PATCH] rtptwcc: make RTPTWCCManager a GObject --- gst/rtpmanager/rtpsession.c | 2 +- gst/rtpmanager/rtptwcc.c | 85 ++++++++++++++++++++++--------------- gst/rtpmanager/rtptwcc.h | 5 ++- 3 files changed, 56 insertions(+), 36 deletions(-) diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 401a69583f..36a8657269 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -733,7 +733,7 @@ rtp_session_finalize (GObject * object) for (i = 0; i < 1; i++) g_hash_table_destroy (sess->ssrcs[i]); - rtp_twcc_manager_free (sess->twcc); + g_object_unref (sess->twcc); rtp_twcc_stats_free (sess->twcc_stats); g_mutex_clear (&sess->lock); diff --git a/gst/rtpmanager/rtptwcc.c b/gst/rtpmanager/rtptwcc.c index 0d7b44605e..eb8a628477 100644 --- a/gst/rtpmanager/rtptwcc.c +++ b/gst/rtpmanager/rtptwcc.c @@ -29,29 +29,6 @@ GST_DEBUG_CATEGORY_EXTERN (rtp_session_debug); #define DELTA_UNIT (250 * GST_USECOND) #define MAX_TS_DELTA (0xff * DELTA_UNIT) -struct _RTPTWCCManager -{ - guint mtu; - guint max_packets_per_rtcp; - GArray *recv_packets; - - guint8 fb_pkt_count; - gint32 last_seqnum; - - GArray *sent_packets; - GArray *parsed_packets; - GQueue *rtcp_buffers; - - guint64 recv_sender_ssrc; - guint64 recv_media_ssrc; - - guint16 expected_recv_seqnum; - - gboolean first_fci_parse; - guint16 expected_parsed_seqnum; - guint8 expected_parsed_fb_pkt_count; -}; - typedef enum { RTP_TWCC_CHUNK_TYPE_RUN_LENGTH = 0, @@ -87,13 +64,37 @@ typedef struct gboolean lost; } SentPacket; -RTPTWCCManager * -rtp_twcc_manager_new (guint mtu) +struct _RTPTWCCManager { - RTPTWCCManager *twcc = g_new0 (RTPTWCCManager, 1); + GObject object; + guint mtu; + guint max_packets_per_rtcp; + GArray *recv_packets; + + guint8 fb_pkt_count; + gint32 last_seqnum; + + GArray *sent_packets; + GArray *parsed_packets; + GQueue *rtcp_buffers; + + guint64 recv_sender_ssrc; + guint64 recv_media_ssrc; + + guint16 expected_recv_seqnum; + + gboolean first_fci_parse; + guint16 expected_parsed_seqnum; + guint8 expected_parsed_fb_pkt_count; +}; + +G_DEFINE_TYPE (RTPTWCCManager, rtp_twcc_manager, G_TYPE_OBJECT); + +static void +rtp_twcc_manager_init (RTPTWCCManager * twcc) +{ twcc->recv_packets = g_array_new (FALSE, FALSE, sizeof (RecvPacket)); - twcc->sent_packets = g_array_new (FALSE, FALSE, sizeof (SentPacket)); twcc->parsed_packets = g_array_new (FALSE, FALSE, sizeof (RecvPacket)); @@ -103,21 +104,37 @@ rtp_twcc_manager_new (guint mtu) twcc->recv_media_ssrc = -1; twcc->recv_sender_ssrc = -1; - rtp_twcc_manager_set_mtu (twcc, mtu); - twcc->first_fci_parse = TRUE; - - return twcc; } -void -rtp_twcc_manager_free (RTPTWCCManager * twcc) +static void +rtp_twcc_manager_finalize (GObject * object) { + RTPTWCCManager *twcc = RTP_TWCC_MANAGER_CAST (object); + g_array_unref (twcc->recv_packets); g_array_unref (twcc->sent_packets); g_array_unref (twcc->parsed_packets); g_queue_free_full (twcc->rtcp_buffers, (GDestroyNotify) gst_buffer_unref); - g_free (twcc); + + G_OBJECT_CLASS (rtp_twcc_manager_parent_class)->finalize (object); +} + +static void +rtp_twcc_manager_class_init (RTPTWCCManagerClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + gobject_class->finalize = rtp_twcc_manager_finalize; +} + +RTPTWCCManager * +rtp_twcc_manager_new (guint mtu) +{ + RTPTWCCManager *twcc = g_object_new (RTP_TYPE_TWCC_MANAGER, NULL); + + rtp_twcc_manager_set_mtu (twcc, mtu); + + return twcc; } static void diff --git a/gst/rtpmanager/rtptwcc.h b/gst/rtpmanager/rtptwcc.h index 39f9d58e0a..ac8f57add5 100644 --- a/gst/rtpmanager/rtptwcc.h +++ b/gst/rtpmanager/rtptwcc.h @@ -29,6 +29,10 @@ typedef struct _RTPTWCCManager RTPTWCCManager; typedef struct _RTPTWCCPacket RTPTWCCPacket; typedef enum _RTPTWCCPacketStatus RTPTWCCPacketStatus; +G_DECLARE_FINAL_TYPE (RTPTWCCManager, rtp_twcc_manager, RTP, TWCC_MANAGER, GObject) +#define RTP_TYPE_TWCC_MANAGER (rtp_twcc_manager_get_type()) +#define RTP_TWCC_MANAGER_CAST(obj) ((RTPTWCCManager *)(obj)) + enum _RTPTWCCPacketStatus { RTP_TWCC_PACKET_STATUS_NOT_RECV = 0, @@ -49,7 +53,6 @@ struct _RTPTWCCPacket }; RTPTWCCManager * rtp_twcc_manager_new (guint mtu); -void rtp_twcc_manager_free (RTPTWCCManager * twcc); void rtp_twcc_manager_set_mtu (RTPTWCCManager * twcc, guint mtu);