# HG changeset patch
# Node ID eb6e78176693
# Parent  95f59c2bc50d
diff --git a/libpurple/media.c b/libpurple/media.c
--- a/libpurple/media.c
+++ b/libpurple/media.c
@@ -234,22 +234,20 @@ purple_media_init (PurpleMedia *media)
 static void
 purple_media_stream_free(PurpleMediaStream *stream)
 {
-	if (stream == NULL)
+	if (stream == NULL) {
 		return;
+	}
 
 	g_free(stream->participant);
 
-	if (stream->local_candidates)
-		purple_media_candidate_list_free(stream->local_candidates);
-	if (stream->remote_candidates)
-		purple_media_candidate_list_free(stream->remote_candidates);
-
-	if (stream->active_local_candidates)
-		purple_media_candidate_list_free(
-				stream->active_local_candidates);
-	if (stream->active_remote_candidates)
-		purple_media_candidate_list_free(
-				stream->active_remote_candidates);
+	g_clear_pointer(&stream->local_candidates,
+	                purple_media_candidate_list_free);
+	g_clear_pointer(&stream->remote_candidates,
+	                purple_media_candidate_list_free);
+	g_clear_pointer(&stream->active_local_candidates,
+	                purple_media_candidate_list_free);
+	g_clear_pointer(&stream->active_remote_candidates,
+	                purple_media_candidate_list_free);
 
 	g_free(stream);
 }
@@ -257,8 +255,9 @@ purple_media_stream_free(PurpleMediaStre
 static void
 purple_media_session_free(PurpleMediaSession *session)
 {
-	if (session == NULL)
+	if (session == NULL) {
 		return;
+	}
 
 	g_free(session->id);
 	g_free(session);
@@ -274,20 +273,9 @@ purple_media_dispose(GObject *media)
 
 	purple_media_manager_remove_media(priv->manager, PURPLE_MEDIA(media));
 
-	if (priv->backend) {
-		g_object_unref(priv->backend);
-		priv->backend = NULL;
-	}
-
-	if (priv->manager) {
-		g_object_unref(priv->manager);
-		priv->manager = NULL;
-	}
-
-	if (priv->conference_type) {
-		g_free(priv->conference_type);
-		priv->conference_type = NULL;
-	}
+	g_clear_object(&priv->backend);
+	g_clear_object(&priv->manager);
+	g_clear_pointer(&priv->conference_type, g_free);
 
 	G_OBJECT_CLASS(purple_media_parent_class)->dispose(media);
 }
@@ -327,34 +315,27 @@ purple_media_set_property (GObject *obje
 			media->priv->account = g_value_get_object(value);
 			break;
 		case PROP_CONFERENCE_TYPE:
-			media->priv->conference_type =
-					g_value_dup_string(value);
+			media->priv->conference_type = g_value_dup_string(value);
 			media->priv->backend = g_object_new(
-					purple_media_manager_get_backend_type(
-					purple_media_manager_get()),
-					"conference-type",
-					media->priv->conference_type,
+					purple_media_manager_get_backend_type(purple_media_manager_get()),
+					"conference-type", media->priv->conference_type,
 					"media", media,
 					NULL);
 			g_signal_connect(media->priv->backend,
 					"active-candidate-pair",
-					G_CALLBACK(
-					purple_media_candidate_pair_established_cb),
+					G_CALLBACK(purple_media_candidate_pair_established_cb),
 					media);
 			g_signal_connect(media->priv->backend,
 					"candidates-prepared",
-					G_CALLBACK(
-					purple_media_candidates_prepared_cb),
+					G_CALLBACK(purple_media_candidates_prepared_cb),
 					media);
 			g_signal_connect(media->priv->backend,
 					"codecs-changed",
-					G_CALLBACK(
-					purple_media_codecs_changed_cb),
+					G_CALLBACK(purple_media_codecs_changed_cb),
 					media);
 			g_signal_connect(media->priv->backend,
 					"new-candidate",
-					G_CALLBACK(
-					purple_media_new_local_candidate_cb),
+					G_CALLBACK(purple_media_new_local_candidate_cb),
 					media);
 			break;
 		case PROP_INITIATOR:
@@ -388,8 +369,7 @@ purple_media_get_property (GObject *obje
 			g_value_set_object(value, media->priv->account);
 			break;
 		case PROP_CONFERENCE_TYPE:
-			g_value_set_string(value,
-					media->priv->conference_type);
+			g_value_set_string(value, media->priv->conference_type);
 			break;
 		case PROP_INITIATOR:
 			g_value_set_boolean(value, media->priv->initiator);
@@ -425,7 +405,9 @@ purple_media_get_stream(PurpleMedia *med
 		PurpleMediaStream *stream = streams->data;
 		if (purple_strequal(stream->session->id, session) &&
 				purple_strequal(stream->participant, participant))
+		{
 			return stream;
+		}
 	}
 
 	return NULL;
@@ -448,7 +430,9 @@ purple_media_get_streams(PurpleMedia *me
 				purple_strequal(stream->session->id, session)) &&
 				(participant == NULL ||
 				purple_strequal(stream->participant, participant)))
+		{
 			ret = g_list_append(ret, stream);
+		}
 	}
 
 	return ret;
@@ -599,13 +583,16 @@ purple_media_end(PurpleMedia *media,
 		media->priv->streams =
 				g_list_remove(media->priv->streams, stream);
 
-		if (g_list_find(sessions, stream->session) == NULL)
+		if (g_list_find(sessions, stream->session) == NULL) {
 			sessions = g_list_prepend(sessions, stream->session);
+		}
 
 		if (g_list_find_custom(participants, stream->participant,
 				(GCompareFunc)strcmp) == NULL)
+		{
 			participants = g_list_prepend(participants,
 					g_strdup(stream->participant));
+		}
 
 		purple_media_stream_free(stream);
 	}
@@ -692,12 +679,10 @@ purple_media_stream_info(PurpleMedia *me
 
 		g_return_if_fail(PURPLE_IS_MEDIA(media));
 
-		streams = purple_media_get_streams(media,
-				session_id, participant);
+		streams = purple_media_get_streams(media, session_id, participant);
 
 		/* Emit stream acceptance */
-		for (; streams; streams =
-				g_list_delete_link(streams, streams)) {
+		for (; streams; streams = g_list_delete_link(streams, streams)) {
 			PurpleMediaStream *stream = streams->data;
 
 			stream->accepted = TRUE;
@@ -707,15 +692,16 @@ purple_media_stream_info(PurpleMedia *me
 					0, type, stream->session->id,
 					stream->participant, local);
 
-			if (g_list_find(sessions, stream->session) == NULL)
-				sessions = g_list_prepend(sessions,
-						stream->session);
+			if (g_list_find(sessions, stream->session) == NULL) {
+				sessions = g_list_prepend(sessions, stream->session);
+			}
 
 			if (g_list_find_custom(participants,
 					stream->participant,
-					(GCompareFunc)strcmp) == NULL)
+					(GCompareFunc)strcmp) == NULL) {
 				participants = g_list_prepend(participants,
 						g_strdup(stream->participant));
+			}
 		}
 
 		/* Emit session acceptance */
@@ -723,11 +709,12 @@ purple_media_stream_info(PurpleMedia *me
 				g_list_delete_link(sessions, sessions)) {
 			PurpleMediaSession *session = sessions->data;
 
-			if (purple_media_accepted(media, session->id, NULL))
+			if (purple_media_accepted(media, session->id, NULL)) {
 				g_signal_emit(media, purple_media_signals[
 						STREAM_INFO], 0,
 						PURPLE_MEDIA_INFO_ACCEPT,
 						session->id, NULL, local);
+			}
 		}
 
 		/* Emit participant acceptance */
@@ -735,21 +722,23 @@ purple_media_stream_info(PurpleMedia *me
 				participants, participants)) {
 			gchar *participant = participants->data;
 
-			if (purple_media_accepted(media, NULL, participant))
+			if (purple_media_accepted(media, NULL, participant)) {
 				g_signal_emit(media, purple_media_signals[
 						STREAM_INFO], 0,
 						PURPLE_MEDIA_INFO_ACCEPT,
 						NULL, participant, local);
+			}
 
 			g_free(participant);
 		}
 
 		/* Emit conference acceptance */
-		if (purple_media_accepted(media, NULL, NULL))
+		if (purple_media_accepted(media, NULL, NULL)) {
 			g_signal_emit(media,
 					purple_media_signals[STREAM_INFO],
 					0, PURPLE_MEDIA_INFO_ACCEPT,
 					NULL, NULL, local);
+		}
 
 		return;
 	} else if (type == PURPLE_MEDIA_INFO_HANGUP ||
@@ -758,12 +747,10 @@ purple_media_stream_info(PurpleMedia *me
 
 		g_return_if_fail(PURPLE_IS_MEDIA(media));
 
-		streams = purple_media_get_streams(media,
-				session_id, participant);
+		streams = purple_media_get_streams(media, session_id, participant);
 
 		/* Emit for stream */
-		for (; streams; streams =
-				g_list_delete_link(streams, streams)) {
+		for (; streams; streams = g_list_delete_link(streams, streams)) {
 			PurpleMediaStream *stream = streams->data;
 
 			g_signal_emit(media,
@@ -779,9 +766,10 @@ purple_media_stream_info(PurpleMedia *me
 			GList *sessions = NULL;
 			GList *participants = media->priv->participants;
 
-			if (media->priv->sessions != NULL)
+			if (media->priv->sessions != NULL) {
 				sessions = g_hash_table_get_values(
 					media->priv->sessions);
+			}
 
 			/* Emit for sessions */
 			for (; sessions; sessions = g_list_delete_link(
@@ -878,9 +866,11 @@ purple_media_param_is_supported(PurpleMe
 	g_return_val_if_fail(param != NULL, FALSE);
 
 	params = purple_media_backend_get_available_params(media->priv->backend);
-	for (; *params != NULL; ++params)
-		if (purple_strequal(*params, param))
+	for (; *params != NULL; ++params) {
+		if (purple_strequal(*params, param)) {
 			return TRUE;
+		}
+	}
 #endif
 	return FALSE;
 }
@@ -1306,10 +1296,8 @@ purple_media_accepted(PurpleMedia *media
 			}
 		}
 	} else if (sess_id != NULL && participant == NULL) {
-		GList *streams = purple_media_get_streams(
-				media, sess_id, NULL);
-		for (; streams; streams =
-				g_list_delete_link(streams, streams)) {
+		GList *streams = purple_media_get_streams(media, sess_id, NULL);
+		for (; streams; streams = g_list_delete_link(streams, streams)) {
 			PurpleMediaStream *stream = streams->data;
 			if (stream->accepted == FALSE) {
 				g_list_free(streams);
@@ -1320,8 +1308,9 @@ purple_media_accepted(PurpleMedia *media
 	} else if (sess_id != NULL && participant != NULL) {
 		PurpleMediaStream *stream = purple_media_get_stream(
 				media, sess_id, participant);
-		if (stream == NULL || stream->accepted == FALSE)
+		if (stream == NULL || stream->accepted == FALSE) {
 			accepted = FALSE;
+		}
 	}
 
 	return accepted;
@@ -1401,19 +1390,19 @@ purple_media_send_dtmf(PurpleMedia *medi
 #ifdef USE_VV
 	PurpleMediaBackendInterface *backend_iface = NULL;
 
-	if (media)
-	{
+	if (media) {
 		backend_iface = PURPLE_MEDIA_BACKEND_GET_INTERFACE(media->priv->backend);
 	}
 
-	if (dtmf == 'a')
+	if (dtmf == 'a') {
 		dtmf = 'A';
-	else if (dtmf == 'b')
+	} else if (dtmf == 'b') {
 		dtmf = 'B';
-	else if (dtmf == 'c')
+	} else if (dtmf == 'c') {
 		dtmf = 'C';
-	else if (dtmf == 'd')
+	} else if (dtmf == 'd') {
 		dtmf = 'D';
+	}
 
 	g_return_val_if_fail(strchr("0123456789ABCD#*", dtmf), FALSE);
 
diff --git a/libpurple/media/backend-iface.c b/libpurple/media/backend-iface.c
--- a/libpurple/media/backend-iface.c
+++ b/libpurple/media/backend-iface.c
@@ -39,8 +39,9 @@ purple_media_backend_base_init(gpointer 
 {
 	static gboolean is_initialized = FALSE;
 
-	if (is_initialized)
+	if (is_initialized) {
 		return;
+	}
 
 	g_object_interface_install_property(iface,
 			g_param_spec_string("conference-type",
diff --git a/libpurple/media/candidate.c b/libpurple/media/candidate.c
--- a/libpurple/media/candidate.c
+++ b/libpurple/media/candidate.c
@@ -329,8 +329,9 @@ purple_media_candidate_copy(PurpleMediaC
 	PurpleMediaCandidatePrivate *priv;
 	PurpleMediaCandidate *new_candidate;
 
-	if (candidate == NULL)
+	if (candidate == NULL) {
 		return NULL;
+	}
 
 	priv = purple_media_candidate_get_instance_private(candidate);
 
diff --git a/libpurple/media/codec.c b/libpurple/media/codec.c
--- a/libpurple/media/codec.c
+++ b/libpurple/media/codec.c
@@ -308,7 +308,9 @@ purple_media_codec_get_optional_paramete
 		if (!g_ascii_strcasecmp(param->key, name) &&
 				(value == NULL ||
 				!g_ascii_strcasecmp(param->value, value)))
+		{
 			return param;
+		}
 	}
 
 	return NULL;
@@ -321,8 +323,9 @@ purple_media_codec_copy(PurpleMediaCodec
 	PurpleMediaCodec *new_codec;
 	GList *iter;
 
-	if (codec == NULL)
+	if (codec == NULL) {
 		return NULL;
+	}
 
 	priv = purple_media_codec_get_instance_private(codec);
 
@@ -361,19 +364,21 @@ purple_media_codec_to_string(PurpleMedia
 	gchar *charstring;
 	const gchar *media_type_str = NULL;
 
-	if (codec == NULL)
+	if (codec == NULL) {
 		return g_strdup("(NULL)");
+	}
 
 	priv = purple_media_codec_get_instance_private(codec);
 
 	string = g_string_new("");
 
-	if (priv->media_type & PURPLE_MEDIA_AUDIO)
+	if (priv->media_type & PURPLE_MEDIA_AUDIO) {
 		media_type_str = "audio";
-	else if (priv->media_type & PURPLE_MEDIA_VIDEO)
+	} else if (priv->media_type & PURPLE_MEDIA_VIDEO) {
 		media_type_str = "video";
-	else if (priv->media_type & PURPLE_MEDIA_APPLICATION)
+	} else if (priv->media_type & PURPLE_MEDIA_APPLICATION) {
 		media_type_str = "application";
+	}
 
 	g_string_printf(string, "%d: %s %s clock:%d channels:%d", priv->id,
 			media_type_str, priv->encoding_name,
diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -224,12 +224,12 @@ purple_media_manager_finalize (GObject *
 	g_list_free_full(priv->medias, g_object_unref);
 	g_list_free_full(priv->private_medias, g_object_unref);
 	g_list_free_full(priv->elements, g_object_unref);
-	if (priv->video_caps)
-		gst_caps_unref(priv->video_caps);
+	g_clear_pointer(&priv->video_caps, gst_caps_unref);
 #ifdef HAVE_MEDIA_APPLICATION
-	if (priv->appdata_info)
-		g_list_free_full (priv->appdata_info,
-			(GDestroyNotify) free_appdata_info_locked);
+	if (priv->appdata_info) {
+		g_list_free_full(priv->appdata_info,
+		                 (GDestroyNotify)free_appdata_info_locked);
+	}
 	g_mutex_clear (&priv->appdata_mutex);
 #endif
 	if (priv->device_monitor) {
@@ -247,8 +247,10 @@ purple_media_manager_get()
 #ifdef USE_VV
 	static PurpleMediaManager *manager = NULL;
 
-	if (manager == NULL)
+	if (manager == NULL) {
 		manager = PURPLE_MEDIA_MANAGER(g_object_new(purple_media_manager_get_type(), NULL));
+	}
+
 	return manager;
 #else
 	return NULL;
@@ -261,7 +263,7 @@ pipeline_bus_call(GstBus *bus, GstMessag
 {
 	switch(GST_MESSAGE_TYPE(msg)) {
 		case GST_MESSAGE_EOS:
-			purple_debug_info("mediamanager", "End of Stream\n");
+			purple_debug_info("mediamanager", "End of Stream");
 			break;
 		case GST_MESSAGE_ERROR: {
 			gchar *debug = NULL;
@@ -269,15 +271,13 @@ pipeline_bus_call(GstBus *bus, GstMessag
 
 			gst_message_parse_error(msg, &err, &debug);
 
-			purple_debug_error("mediamanager",
-					"gst pipeline error: %s\n",
-					err->message);
+			purple_debug_error("mediamanager", "gst pipeline error: %s",
+			                   err->message);
 			g_error_free(err);
 
 			if (debug) {
-				purple_debug_error("mediamanager",
-						"Debug details: %s\n", debug);
-				g_free (debug);
+				purple_debug_error("mediamanager", "Debug details: %s", debug);
+				g_free(debug);
 			}
 			break;
 		}
@@ -348,11 +348,13 @@ create_media(PurpleMediaManager *manager
 		}
 	}
 
-	if (private)
+	if (private) {
 		manager->priv->private_medias = g_list_append(
 			manager->priv->private_medias, media);
-	else
+	} else {
 		manager->priv->medias = g_list_append(manager->priv->medias, media);
+	}
+
 	return media;
 #else
 	return NULL;
@@ -363,10 +365,11 @@ static GList *
 get_media(PurpleMediaManager *manager, gboolean private)
 {
 #ifdef USE_VV
-	if (private)
+	if (private) {
 		return manager->priv->private_medias;
-	else
+	} else {
 		return manager->priv->medias;
+	}
 #else
 	return NULL;
 #endif
@@ -383,10 +386,11 @@ get_media_by_account(PurpleMediaManager 
 
 	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), NULL);
 
-	if (private)
+	if (private) {
 		iter = manager->priv->private_medias;
-	else
+	} else {
 		iter = manager->priv->medias;
+	}
 	for (; iter; iter = g_list_next(iter)) {
 		media_account = purple_media_get_account(iter->data);
 		if (media_account == account) {
@@ -495,8 +499,9 @@ free_appdata_info_locked (PurpleMediaApp
 	GstAppSrcCallbacks null_src_cb = { NULL, NULL, NULL, { NULL } };
 	GstAppSinkCallbacks null_sink_cb = { NULL, NULL, NULL , { NULL } };
 
-	if (info->notify)
-		info->notify (info->user_data);
+	if (info->notify) {
+		info->notify(info->user_data);
+	}
 
 	info->media = NULL;
 	if (info->appsrc) {
@@ -529,9 +534,7 @@ free_appdata_info_locked (PurpleMediaApp
 		info->writable_timer_id = 0;
 	}
 
-	if (info->current_sample)
-		gst_sample_unref (info->current_sample);
-	info->current_sample = NULL;
+	g_clear_pointer(&info->current_sample, gst_sample_unref);
 
 	/* Unblock any reading thread before destroying the GCond */
 	g_cond_broadcast (&info->readable_cond);
@@ -632,8 +635,7 @@ nonunique_src_unlinked_cb(GstPad *pad, G
 void
 purple_media_manager_set_video_caps(PurpleMediaManager *manager, GstCaps *caps)
 {
-	if (manager->priv->video_caps)
-		gst_caps_unref(manager->priv->video_caps);
+	g_clear_pointer(&manager->priv->video_caps, gst_caps_unref);
 
 	manager->priv->video_caps = caps;
 
@@ -657,9 +659,11 @@ purple_media_manager_set_video_caps(Purp
 GstCaps *
 purple_media_manager_get_video_caps(PurpleMediaManager *manager)
 {
-	if (manager->priv->video_caps == NULL)
+	if (manager->priv->video_caps == NULL) {
 		manager->priv->video_caps = gst_caps_from_string("video/x-raw,"
 			"width=[250,352], height=[200,288], framerate=[1/1,20/1]");
+	}
+
 	return manager->priv->video_caps;
 }
 #endif /* USE_VV */
@@ -714,9 +718,10 @@ appsrc_writable (gpointer user_data)
 	g_mutex_unlock (&manager->priv->appdata_mutex);
 
 
-	if (writable_cb && media)
+	if (writable_cb && media) {
 		writable_cb (manager, media, session_id, participant, writable,
 			cb_data);
+	}
 
 	g_object_unref (media);
 	g_free (session_id);
@@ -741,8 +746,9 @@ call_appsrc_writable_locked (PurpleMedia
 	PurpleMediaManager *manager = purple_media_manager_get ();
 
 	/* We already have a writable callback scheduled, don't create another one */
-	if (info->writable_cb_token || info->callbacks.writable == NULL)
+	if (info->writable_cb_token || info->callbacks.writable == NULL) {
 		return;
+	}
 
 	/* We can't use writable_timer_id as a token, because the timeout is added
 	 * into libpurple's main event loop, which runs in a different thread than
@@ -763,8 +769,9 @@ appsrc_need_data (GstAppSrc *appsrc, gui
 	if (!info->writable) {
 		info->writable = TRUE;
 		/* Only signal writable if we also established a connection */
-		if (info->connected)
+		if (info->connected) {
 			call_appsrc_writable_locked (info);
+		}
 	}
 	g_mutex_unlock (&manager->priv->appdata_mutex);
 }
@@ -821,8 +828,9 @@ media_established_cb (PurpleMedia *media
 	info->connected = TRUE;
 	/* We established the connection, if we were writable, then we need to
 	 * signal it now */
-	if (info->writable)
+	if (info->writable) {
 		call_appsrc_writable_locked (info);
+	}
 	g_mutex_unlock (&manager->priv->appdata_mutex);
 }
 
@@ -932,8 +940,9 @@ call_appsink_readable_locked (PurpleMedi
 	g_cond_broadcast (&info->readable_cond);
 
 	/* We already have a writable callback scheduled, don't create another one */
-	if (info->readable_cb_token || info->callbacks.readable == NULL)
+	if (info->readable_cb_token || info->callbacks.readable == NULL) {
 		return;
+	}
 
 	info->readable_cb_token = ++manager->priv->appdata_cb_token;
 	info->readable_timer_id = g_timeout_add (0, appsink_readable, info);
@@ -1051,21 +1060,23 @@ purple_media_manager_get_element(PurpleM
 	PurpleMediaElementInfo *info = NULL;
 	PurpleMediaElementType element_type;
 
-	if (type & PURPLE_MEDIA_SEND_AUDIO)
+	if (type & PURPLE_MEDIA_SEND_AUDIO) {
 		info = manager->priv->audio_src;
-	else if (type & PURPLE_MEDIA_RECV_AUDIO)
+	} else if (type & PURPLE_MEDIA_RECV_AUDIO) {
 		info = manager->priv->audio_sink;
-	else if (type & PURPLE_MEDIA_SEND_VIDEO)
+	} else if (type & PURPLE_MEDIA_SEND_VIDEO) {
 		info = manager->priv->video_src;
-	else if (type & PURPLE_MEDIA_RECV_VIDEO)
+	} else if (type & PURPLE_MEDIA_RECV_VIDEO) {
 		info = manager->priv->video_sink;
-	else if (type & PURPLE_MEDIA_SEND_APPLICATION)
+	} else if (type & PURPLE_MEDIA_SEND_APPLICATION) {
 		info = get_send_application_element_info ();
-	else if (type & PURPLE_MEDIA_RECV_APPLICATION)
+	} else if (type & PURPLE_MEDIA_RECV_APPLICATION) {
 		info = get_recv_application_element_info ();
+	}
 
-	if (info == NULL)
+	if (info == NULL) {
 		return NULL;
+	}
 
 	element_type = purple_media_element_info_get_element_type(info);
 
@@ -1100,8 +1111,9 @@ purple_media_manager_get_element(PurpleM
 
 				gst_bin_add_many(GST_BIN(bin), videoscale, capsfilter, NULL);
 				gst_element_link_many(ret, videoscale, capsfilter, tee, NULL);
-			} else
+			} else {
 				gst_element_link(ret, tee);
+			}
 
 			/*
 			 * This shouldn't be necessary, but it stops it from
@@ -1150,8 +1162,9 @@ purple_media_manager_get_element(PurpleM
 		}
 	}
 
-	if (ret == NULL)
+	if (ret == NULL) {
 		purple_debug_error("media", "Error creating source or sink\n");
+	}
 
 	return ret;
 }
@@ -1168,8 +1181,7 @@ purple_media_manager_get_element_info(Pu
 	iter = manager->priv->elements;
 
 	for (; iter; iter = g_list_next(iter)) {
-		gchar *element_id =
-				purple_media_element_info_get_id(iter->data);
+		gchar *element_id = purple_media_element_info_get_id(iter->data);
 		if (purple_strequal(element_id, id)) {
 			g_free(element_id);
 			g_object_ref(iter->data);
@@ -1225,8 +1237,7 @@ purple_media_manager_register_element(Pu
 		return FALSE;
 	}
 
-	manager->priv->elements =
-			g_list_prepend(manager->priv->elements, info);
+	manager->priv->elements = g_list_prepend(manager->priv->elements, info);
 
 	detail = element_info_to_detail(info);
 	if (detail != 0) {
@@ -1254,14 +1265,18 @@ purple_media_manager_unregister_element(
 		return FALSE;
 	}
 
-	if (manager->priv->audio_src == info)
+	if (manager->priv->audio_src == info) {
 		manager->priv->audio_src = NULL;
-	if (manager->priv->audio_sink == info)
+	}
+	if (manager->priv->audio_sink == info) {
 		manager->priv->audio_sink = NULL;
-	if (manager->priv->video_src == info)
+	}
+	if (manager->priv->video_src == info) {
 		manager->priv->video_src = NULL;
-	if (manager->priv->video_sink == info)
+	}
+	if (manager->priv->video_sink == info) {
 		manager->priv->video_sink = NULL;
+	}
 
 	detail = element_info_to_detail(info);
 
@@ -1294,10 +1309,11 @@ purple_media_manager_set_active_element(
 	info2 = purple_media_manager_get_element_info(manager, id);
 	g_free(id);
 
-	if (info2 == NULL)
+	if (info2 == NULL) {
 		purple_media_manager_register_element(manager, info);
-	else
+	} else {
 		g_object_unref(info2);
+	}
 
 	type = purple_media_element_info_get_element_type(info);
 
@@ -1332,20 +1348,21 @@ purple_media_manager_get_active_element(
 	g_return_val_if_fail(PURPLE_IS_MEDIA_MANAGER(manager), NULL);
 
 	if (type & PURPLE_MEDIA_ELEMENT_SRC) {
-		if (type & PURPLE_MEDIA_ELEMENT_AUDIO)
+		if (type & PURPLE_MEDIA_ELEMENT_AUDIO) {
 			return manager->priv->audio_src;
-		else if (type & PURPLE_MEDIA_ELEMENT_VIDEO)
+		} else if (type & PURPLE_MEDIA_ELEMENT_VIDEO) {
 			return manager->priv->video_src;
-		else if (type & PURPLE_MEDIA_ELEMENT_APPLICATION)
+		} else if (type & PURPLE_MEDIA_ELEMENT_APPLICATION) {
 			return get_send_application_element_info ();
+		}
 	} else if (type & PURPLE_MEDIA_ELEMENT_SINK) {
-		if (type & PURPLE_MEDIA_ELEMENT_AUDIO)
+		if (type & PURPLE_MEDIA_ELEMENT_AUDIO) {
 			return manager->priv->audio_sink;
-		else if (type & PURPLE_MEDIA_ELEMENT_VIDEO)
+		} else if (type & PURPLE_MEDIA_ELEMENT_VIDEO) {
 			return manager->priv->video_sink;
-		else if (type & PURPLE_MEDIA_ELEMENT_APPLICATION)
+		} else if (type & PURPLE_MEDIA_ELEMENT_APPLICATION) {
 			return get_recv_application_element_info ();
-
+		}
 	}
 
 	return NULL;
@@ -1373,8 +1390,9 @@ purple_media_manager_create_output_windo
 			GstElement *tee = purple_media_get_tee(media,
 					session_id, participant);
 
-			if (tee == NULL)
+			if (tee == NULL) {
 				continue;
+			}
 
 			queue = gst_element_factory_make("queue", NULL);
 			convert = gst_element_factory_make("videoconvert", NULL);
@@ -1388,14 +1406,14 @@ purple_media_manager_create_output_windo
 				/* aka this is a preview sink */
 				GObjectClass *klass =
 						G_OBJECT_GET_CLASS(ow->sink);
-				if (g_object_class_find_property(klass,
-						"sync"))
+				if (g_object_class_find_property(klass, "sync")) {
 					g_object_set(G_OBJECT(ow->sink),
 							"sync", FALSE, NULL);
-				if (g_object_class_find_property(klass,
-						"async"))
+				}
+				if (g_object_class_find_property(klass, "async")) {
 					g_object_set(G_OBJECT(ow->sink),
 							"async", FALSE, NULL);
+				}
 			}
 
 			gst_bin_add_many(GST_BIN(GST_ELEMENT_PARENT(tee)),
@@ -1437,9 +1455,10 @@ purple_media_manager_set_output_window(P
 	manager->priv->output_windows = g_list_prepend(
 			manager->priv->output_windows, output_window);
 
-	if (purple_media_get_tee(media, session_id, participant) != NULL)
+	if (purple_media_get_tee(media, session_id, participant) != NULL) {
 		purple_media_manager_create_output_window(manager,
 				media, session_id, participant);
+	}
 
 	return output_window->id;
 #else
@@ -1468,8 +1487,9 @@ purple_media_manager_remove_output_windo
 		}
 	}
 
-	if (output_window == NULL)
+	if (output_window == NULL) {
 		return FALSE;
+	}
 
 	if (output_window->sink != NULL) {
 		GstElement *element = output_window->sink;
@@ -1547,11 +1567,13 @@ purple_media_manager_remove_output_windo
 		PurpleMediaOutputWindow *ow = iter->data;
 		iter = g_list_next(iter);
 
-	if (media == ow->media &&
-			purple_strequal(session_id, ow->session_id) &&
-			purple_strequal(participant, ow->participant))
-		purple_media_manager_remove_output_window(
-				manager, ow->id);
+		if (media == ow->media &&
+				purple_strequal(session_id, ow->session_id) &&
+				purple_strequal(participant, ow->participant))
+		{
+			purple_media_manager_remove_output_window(
+					manager, ow->id);
+		}
 	}
 #endif
 }
@@ -1568,10 +1590,11 @@ purple_media_manager_set_ui_caps(PurpleM
 	oldcaps = manager->priv->ui_caps;
 	manager->priv->ui_caps = caps;
 
-	if (caps != oldcaps)
+	if (caps != oldcaps) {
 		g_signal_emit(manager,
 				purple_media_manager_signals[UI_CAPS_CHANGED],
 				0, caps, oldcaps);
+	}
 #endif
 }
 
@@ -1621,8 +1644,9 @@ purple_media_manager_set_application_dat
 	PurpleMediaAppDataInfo * info = ensure_app_data_info_and_lock (manager,
 		media, session_id, participant);
 
-	if (info->notify)
+	if (info->notify) {
 		info->notify (info->user_data);
+	}
 
 	if (info->readable_cb_token) {
 		g_source_remove (info->readable_timer_id);
@@ -1644,8 +1668,9 @@ purple_media_manager_set_application_dat
 	info->notify = notify;
 
 	call_appsrc_writable_locked (info);
-	if (info->num_samples > 0 || info->current_sample != NULL)
+	if (info->num_samples > 0 || info->current_sample != NULL) {
 		call_appsink_readable_locked (info);
+	}
 
 	g_mutex_unlock (&manager->priv->appdata_mutex);
 #endif
@@ -1711,8 +1736,9 @@ purple_media_manager_receive_application
 			if (!info->current_sample && info->appsink && info->num_samples > 0) {
 				info->current_sample = gst_app_sink_pull_sample (info->appsink);
 				info->sample_offset = 0;
-				if (info->current_sample)
+				if (info->current_sample) {
 					info->num_samples--;
+				}
 			}
 
 			if (info->current_sample) {
@@ -1726,9 +1752,8 @@ purple_media_manager_receive_application
 					gst_buffer_map (gstbuffer, &mapinfo, GST_MAP_READ);
 					/* We must copy only the data remaining in the buffer without
 					 * overflowing the buffer */
-					bytes_to_copy = max_size - bytes_read;
-					if (bytes_to_copy > mapinfo.size - info->sample_offset)
-						bytes_to_copy = mapinfo.size - info->sample_offset;
+					bytes_to_copy = MIN(max_size - bytes_read,
+					                    mapinfo.size - info->sample_offset);
 					memcpy ((guint8 *)buffer + bytes_read,
 						mapinfo.data + info->sample_offset,	bytes_to_copy);
 
@@ -1766,8 +1791,7 @@ purple_media_manager_receive_application
 					return bytes_read;
 				}
 			}
-		} while (bytes_read < max_size &&
-			(blocking || info->num_samples > 0));
+		} while (bytes_read < max_size && (blocking || info->num_samples > 0));
 
 		g_mutex_unlock (&manager->priv->appdata_mutex);
 		return bytes_read;
@@ -2351,8 +2375,7 @@ purple_media_element_info_set_property (
 			priv->create = g_value_get_pointer(value);
 			break;
 		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID(
-					object, prop_id, pspec);
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 			break;
 	}
 }
@@ -2381,8 +2404,7 @@ purple_media_element_info_get_property (
 			g_value_set_pointer(value, priv->create);
 			break;
 		default:
-			G_OBJECT_WARN_INVALID_PROPERTY_ID(
-					object, prop_id, pspec);
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 			break;
 	}
 }
@@ -2466,8 +2488,9 @@ purple_media_element_info_call_create(Pu
 	PurpleMediaElementCreateCallback create;
 	g_return_val_if_fail(PURPLE_IS_MEDIA_ELEMENT_INFO(info), NULL);
 	g_object_get(info, "create-cb", &create, NULL);
-	if (create)
+	if (create) {
 		return create(info, media, session_id, participant);
+	}
 	return NULL;
 }
 #endif /* USE_VV */
