[Pkg-voip-commits] [janus] 207/282: Use GQueue instead of GList, when last item is important

Jonas Smedegaard dr at jones.dk
Wed Dec 20 21:53:41 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.6-1
in repository janus.

commit d7087578d157550fece54319ad77d014b79ca876
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Tue Nov 28 15:27:11 2017 +0100

    Use GQueue instead of GList, when last item is important
---
 ice.c   | 107 +++++++++++++++-------------------------------------------------
 ice.h   |   6 ++--
 janus.c |   4 +--
 3 files changed, 30 insertions(+), 87 deletions(-)

diff --git a/ice.c b/ice.c
index 443ee11..179d9ab 100644
--- a/ice.c
+++ b/ice.c
@@ -329,17 +329,14 @@ static void janus_cleanup_nack_buffer(gint64 now, janus_ice_stream *stream) {
 		janus_ice_component *component = stream->rtp_component;
 		janus_mutex_lock(&component->mutex);
 		if(component->retransmit_buffer) {
-			GList *first = g_list_first(component->retransmit_buffer);
-			janus_rtp_packet *p = (janus_rtp_packet *)first->data;
+			janus_rtp_packet *p = (janus_rtp_packet *)g_queue_peek_head(component->retransmit_buffer);
 			while(p && (now - p->created >= (gint64)max_nack_queue*1000)) {
 				/* Packet is too old, get rid of it */
-				first->data = NULL;
-				component->retransmit_buffer = g_list_delete_link(component->retransmit_buffer, first);
+				g_queue_pop_head(component->retransmit_buffer);
 				g_free(p->data);
 				p->data = NULL;
 				g_free(p);
-				first = g_list_first(component->retransmit_buffer);
-				p = (janus_rtp_packet *)(first ? first->data : NULL);
+				p = (janus_rtp_packet *)g_queue_peek_head(component->retransmit_buffer);
 			}
 		}
 		janus_mutex_unlock(&component->mutex);
@@ -956,17 +953,15 @@ void janus_ice_stats_reset(janus_ice_stats *stats) {
 	stats->audio_packets = 0;
 	stats->audio_bytes = 0;
 	if(stats->audio_bytes_lastsec)
-		g_list_free_full(stats->audio_bytes_lastsec, &janus_ice_stats_queue_free);
+		g_queue_free_full(stats->audio_bytes_lastsec, &janus_ice_stats_queue_free);
 	stats->audio_bytes_lastsec = NULL;
-	stats->audio_bytes_lastsec_last = NULL;
 	stats->audio_notified_lastsec = FALSE;
 	stats->audio_nacks = 0;
 	stats->video_packets = 0;
 	stats->video_bytes = 0;
 	if(stats->video_bytes_lastsec)
-		g_list_free_full(stats->video_bytes_lastsec, &janus_ice_stats_queue_free);
+		g_queue_free_full(stats->video_bytes_lastsec, &janus_ice_stats_queue_free);
 	stats->video_bytes_lastsec = NULL;
-	stats->video_bytes_lastsec_last = NULL;
 	stats->video_notified_lastsec = FALSE;
 	stats->video_nacks = 0;
 	stats->data_packets = 0;
@@ -1384,18 +1379,13 @@ void janus_ice_component_free(GHashTable *components, janus_ice_component *compo
 	}
 	if(component->retransmit_buffer != NULL) {
 		janus_rtp_packet *p = NULL;
-		GList *first = g_list_first(component->retransmit_buffer);
-		while(first != NULL) {
-			p = (janus_rtp_packet *)first->data;
-			first->data = NULL;
-			component->retransmit_buffer = g_list_delete_link(component->retransmit_buffer, first);
+		while(g_queue_get_length(component->retransmit_buffer) > 0) {
+			p = (janus_rtp_packet *)g_queue_pop_head(component->retransmit_buffer);
 			g_free(p->data);
 			p->data = NULL;
 			g_free(p);
-			first = g_list_first(component->retransmit_buffer);
 		}
-		component->retransmit_buffer = NULL;
-		component->retransmit_buffer_last = NULL;
+		g_queue_free(component->retransmit_buffer);
 	}
 	if(component->candidates != NULL) {
 		GSList *i = NULL, *candidates = component->candidates;
@@ -2092,26 +2082,12 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 						}
 						component->in_stats.audio_packets++;
 						component->in_stats.audio_bytes += buflen;
-						GList *last = g_list_alloc();
-						last->data = s;
-						last->next = NULL;
-						last->prev = NULL;
-						if(component->in_stats.audio_bytes_lastsec_last == NULL) {
-							/* First stat in queue */
-							component->in_stats.audio_bytes_lastsec = last;
-							component->in_stats.audio_bytes_lastsec_last = last;
-						} else {
-							/* Append after last stat in queue */
-							component->in_stats.audio_bytes_lastsec_last->next = last;
-							last->prev = component->in_stats.audio_bytes_lastsec_last;
-							component->in_stats.audio_bytes_lastsec_last = last;
-						}
-						if(g_list_length(component->in_stats.audio_bytes_lastsec) > 100) {
-							GList *first = g_list_first(component->in_stats.audio_bytes_lastsec);
-							s = (janus_ice_stats_item *)first->data;
+						if(component->in_stats.audio_bytes_lastsec == NULL)
+							component->in_stats.audio_bytes_lastsec = g_queue_new();
+						g_queue_push_tail(component->in_stats.audio_bytes_lastsec, s);
+						if(g_queue_get_length(component->in_stats.audio_bytes_lastsec) > 100) {
+							s = (janus_ice_stats_item *)g_queue_pop_head(component->in_stats.audio_bytes_lastsec);
 							g_free(s);
-							first->data = NULL;
-							component->in_stats.audio_bytes_lastsec = g_list_delete_link(component->in_stats.audio_bytes_lastsec, first);
 						}
 					} else {
 						if(component->in_stats.video_bytes == 0 || component->in_stats.video_notified_lastsec) {
@@ -2121,26 +2097,12 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 						}
 						component->in_stats.video_packets++;
 						component->in_stats.video_bytes += buflen;
-						GList *last = g_list_alloc();
-						last->data = s;
-						last->next = NULL;
-						last->prev = NULL;
-						if(component->in_stats.video_bytes_lastsec_last == NULL) {
-							/* First stat in queue */
-							component->in_stats.video_bytes_lastsec = last;
-							component->in_stats.video_bytes_lastsec_last = last;
-						} else {
-							/* Append after last stat in queue */
-							component->in_stats.video_bytes_lastsec_last->next = last;
-							last->prev = component->in_stats.video_bytes_lastsec_last;
-							component->in_stats.video_bytes_lastsec_last = last;
-						}
-						if(g_list_length(component->in_stats.video_bytes_lastsec) > 100) {
-							GList *first = g_list_first(component->in_stats.video_bytes_lastsec);
-							s = (janus_ice_stats_item *)first->data;
+						if(component->in_stats.video_bytes_lastsec == NULL)
+							component->in_stats.video_bytes_lastsec = g_queue_new();
+						g_queue_push_tail(component->in_stats.video_bytes_lastsec, s);
+						if(g_queue_get_length(component->in_stats.video_bytes_lastsec) > 100) {
+							s = (janus_ice_stats_item *)g_queue_pop_head(component->in_stats.video_bytes_lastsec);
 							g_free(s);
-							first->data = NULL;
-							component->in_stats.video_bytes_lastsec = g_list_delete_link(component->in_stats.video_bytes_lastsec, first);
 						}
 					}
 					janus_mutex_unlock(&component->mutex);
@@ -2363,7 +2325,7 @@ static void janus_ice_cb_nice_recv(NiceAgent *agent, guint stream_id, guint comp
 					while(list) {
 						unsigned int seqnr = GPOINTER_TO_UINT(list->data);
 						JANUS_LOG(LOG_DBG, "[%"SCNu64"]   >> %u\n", handle->handle_id, seqnr);
-						GList *rp = component->retransmit_buffer;
+						GList *rp = g_queue_peek_head_link(component->retransmit_buffer);
 						while(rp) {
 							janus_rtp_packet *p = (janus_rtp_packet *)rp->data;
 							if(p) {
@@ -3063,7 +3025,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
 		audio_rtp->do_audio_nacks = FALSE;
 		audio_rtp->do_video_nacks = FALSE;
 		audio_rtp->retransmit_buffer = NULL;
-		audio_rtp->retransmit_buffer_last = NULL;
 		audio_rtp->retransmit_log_ts = 0;
 		audio_rtp->retransmit_recent_cnt = 0;
 		audio_rtp->nack_sent_log_ts = 0;
@@ -3130,7 +3091,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
 			audio_rtcp->do_audio_nacks = FALSE;
 			audio_rtcp->do_video_nacks = FALSE;
 			audio_rtcp->retransmit_buffer = NULL;
-			audio_rtcp->retransmit_buffer_last = NULL;
 			audio_rtcp->retransmit_log_ts = 0;
 			audio_rtcp->retransmit_recent_cnt = 0;
 			janus_ice_stats_reset(&audio_rtcp->in_stats);
@@ -3228,7 +3188,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
 		video_rtp->do_audio_nacks = FALSE;
 		video_rtp->do_video_nacks = FALSE;
 		video_rtp->retransmit_buffer = NULL;
-		video_rtp->retransmit_buffer_last = NULL;
 		video_rtp->retransmit_log_ts = 0;
 		video_rtp->retransmit_recent_cnt = 0;
 		video_rtp->nack_sent_log_ts = 0;
@@ -3295,7 +3254,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
 			video_rtcp->do_audio_nacks = FALSE;
 			video_rtcp->do_video_nacks = FALSE;
 			video_rtcp->retransmit_buffer = NULL;
-			video_rtcp->retransmit_buffer_last = NULL;
 			video_rtcp->retransmit_log_ts = 0;
 			video_rtcp->retransmit_recent_cnt = 0;
 			janus_ice_stats_reset(&video_rtcp->in_stats);
@@ -3388,7 +3346,6 @@ int janus_ice_setup_local(janus_ice_handle *handle, int offer, int audio, int vi
 		data_component->do_audio_nacks = FALSE;
 		data_component->do_video_nacks = FALSE;
 		data_component->retransmit_buffer = NULL;
-		data_component->retransmit_buffer_last = NULL;
 		data_component->retransmit_log_ts = 0;
 		data_component->retransmit_recent_cnt = 0;
 		janus_ice_stats_reset(&data_component->in_stats);
@@ -3482,8 +3439,7 @@ void *janus_ice_send_thread(void *data) {
 		if(no_media_timer > 0 && now-before >= G_USEC_PER_SEC) {
 			if(handle->audio_stream && handle->audio_stream->rtp_component) {
 				janus_ice_component *component = handle->audio_stream->rtp_component;
-				GList *lastitem = component->in_stats.audio_bytes_lastsec_last;
-				janus_ice_stats_item *last = lastitem ? ((janus_ice_stats_item *)lastitem->data) : NULL;
+				janus_ice_stats_item *last = (janus_ice_stats_item *)g_queue_peek_tail(component->in_stats.audio_bytes_lastsec);
 				if(!component->in_stats.audio_notified_lastsec && last && now-last->when >= (gint64)no_media_timer*G_USEC_PER_SEC) {
 					/* We missed more than no_second_timer seconds of audio! */
 					component->in_stats.audio_notified_lastsec = TRUE;
@@ -3491,8 +3447,7 @@ void *janus_ice_send_thread(void *data) {
 					janus_ice_notify_media(handle, FALSE, FALSE);
 				}
 				if(!component->in_stats.video_notified_lastsec && janus_flags_is_set(&handle->webrtc_flags, JANUS_ICE_HANDLE_WEBRTC_BUNDLE)) {
-					lastitem = component->in_stats.video_bytes_lastsec_last;
-					last = lastitem ? ((janus_ice_stats_item *)lastitem->data) : NULL;
+					last = (janus_ice_stats_item *)g_queue_peek_tail(component->in_stats.video_bytes_lastsec);
 					if(last && now-last->when >= (gint64)no_media_timer*G_USEC_PER_SEC) {
 						/* We missed more than no_second_timer seconds of video! */
 						component->in_stats.video_notified_lastsec = TRUE;
@@ -3503,8 +3458,7 @@ void *janus_ice_send_thread(void *data) {
 			}
 			if(handle->video_stream && handle->video_stream->rtp_component) {
 				janus_ice_component *component = handle->video_stream->rtp_component;
-				GList *lastitem = component->in_stats.video_bytes_lastsec_last;
-				janus_ice_stats_item *last = lastitem ? ((janus_ice_stats_item *)lastitem->data) : NULL;
+				janus_ice_stats_item *last = (janus_ice_stats_item *)g_queue_peek_tail(component->in_stats.video_bytes_lastsec);
 				if(!component->in_stats.video_notified_lastsec && last && now-last->when >= (gint64)no_media_timer*G_USEC_PER_SEC) {
 					/* We missed more than no_second_timer seconds of video! */
 					component->in_stats.video_notified_lastsec = TRUE;
@@ -3977,20 +3931,9 @@ void *janus_ice_send_thread(void *data) {
 							p->created = janus_get_monotonic_time();
 							p->last_retransmit = 0;
 							janus_mutex_lock(&component->mutex);
-							GList *last = g_list_alloc();
-							last->data = p;
-							last->next = NULL;
-							last->prev = NULL;
-							if(component->retransmit_buffer_last == NULL) {
-								/* First packet in queue */
-								component->retransmit_buffer = last;
-								component->retransmit_buffer_last = last;
-							} else {
-								/* Append after last packet in queue */
-								component->retransmit_buffer_last->next = last;
-								last->prev = component->retransmit_buffer_last;
-								component->retransmit_buffer_last = last;
-							}
+							if(component->retransmit_buffer == NULL)
+								component->retransmit_buffer = g_queue_new();
+							g_queue_push_tail(component->retransmit_buffer, p);
 							janus_mutex_unlock(&component->mutex);
 						}
 					}
diff --git a/ice.h b/ice.h
index 2a5121d..a898860 100644
--- a/ice.h
+++ b/ice.h
@@ -194,7 +194,7 @@ typedef struct janus_ice_stats {
 	/*! \brief Audio bytes sent or received */
 	guint64 audio_bytes;
 	/*! \brief Audio bytes sent or received in the last second */
-	GList *audio_bytes_lastsec, *audio_bytes_lastsec_last;
+	GQueue *audio_bytes_lastsec;
 	/*! \brief Whether or not we notified about audio lastsec issues already */
 	gboolean audio_notified_lastsec;
 	/*! \brief Number of audio NACKs sent or received */
@@ -204,7 +204,7 @@ typedef struct janus_ice_stats {
 	/*! \brief Video bytes sent or received */
 	guint64 video_bytes;
 	/*! \brief Video bytes sent or received in the last second */
-	GList *video_bytes_lastsec, *video_bytes_lastsec_last;
+	GQueue *video_bytes_lastsec;
 	/*! \brief Whether or not we notified about video lastsec issues already */
 	gboolean video_notified_lastsec;
 	/*! \brief Number of video NACKs sent or received */
@@ -450,7 +450,7 @@ struct janus_ice_component {
 	/*! \brief Whether we should do NACKs (in or out) for video */
 	gboolean do_video_nacks;
 	/*! \brief List of previously sent janus_rtp_packet RTP packets, in case we receive NACKs */
-	GList *retransmit_buffer, *retransmit_buffer_last;
+	GQueue *retransmit_buffer;
 	/*! \brief Last time a log message about sending retransmits was printed */
 	gint64 retransmit_log_ts;
 	/*! \brief Number of retransmitted packets since last log message */
diff --git a/janus.c b/janus.c
index bb12d00..7f6b718 100644
--- a/janus.c
+++ b/janus.c
@@ -2556,7 +2556,7 @@ json_t *janus_admin_component_summary(janus_ice_component *component) {
 			gint64 now = janus_get_monotonic_time();
 			guint64 bytes = 0;
 			if(component->in_stats.audio_bytes_lastsec) {
-				GList *lastsec = component->in_stats.audio_bytes_lastsec;
+				GList *lastsec = g_queue_peek_head_link(component->in_stats.audio_bytes_lastsec);
 				while(lastsec) {
 					janus_ice_stats_item *s = (janus_ice_stats_item *)lastsec->data;
 					if(s && now-s->when < G_USEC_PER_SEC)
@@ -2576,7 +2576,7 @@ json_t *janus_admin_component_summary(janus_ice_component *component) {
 			gint64 now = janus_get_monotonic_time();
 			guint64 bytes = 0;
 			if(component->in_stats.video_bytes_lastsec) {
-				GList *lastsec = component->in_stats.video_bytes_lastsec;
+				GList *lastsec = g_queue_peek_head_link(component->in_stats.video_bytes_lastsec);
 				while(lastsec) {
 					janus_ice_stats_item *s = (janus_ice_stats_item *)lastsec->data;
 					if(s && now-s->when < G_USEC_PER_SEC)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list