changeset 25735:4a208844bb63

Make voice calls work with Finch.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sun, 24 Aug 2008 07:49:50 +0000
parents 9104d46df299
children 9ff63ec7d869
files finch/gntmedia.c
diffstat 1 files changed, 20 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntmedia.c	Sun Aug 24 06:01:51 2008 +0000
+++ b/finch/gntmedia.c	Sun Aug 24 07:49:50 2008 +0000
@@ -162,6 +162,10 @@
 static void
 finch_media_finalize (GObject *media)
 {
+	FinchMedia *gntmedia = FINCH_MEDIA(media);
+	purple_debug_info("gntmedia", "finch_media_finalize\n");
+	if (gntmedia->priv->media)
+		g_object_unref(gntmedia->priv->media);
 }
 
 static void
@@ -170,55 +174,9 @@
 	g_signal_emit(gntmedia, finch_media_signals[MESSAGE], 0, msg);
 }
 
-static gboolean
-level_message_cb(GstBus *bus, GstMessage *message, FinchMedia *gntmedia)
-{
-	/* XXX: I am hesitant to just remove this function altogether, because I don't
-	 * know how necessary it is to have a callback to 'message'. If it isn't essential,
-	 * I suppose this should be removed.
-	 */
-	return TRUE;
-#if 0
-	const GstStructure *s;
-	const gchar *name;
-
-	int channels;
-	gdouble rms_db, peak_db, decay_db;
-	gdouble rms;
-	const GValue *list;
-	const GValue *value;
-
-	GstElement *src = GST_ELEMENT(message);
-
-	if (message->type != GST_MESSAGE_ELEMENT)
-		return TRUE;
-
-	s = gst_message_get_structure(message);
-	name = gst_structure_get_name(s);
-
-	if (strcmp(name, "level"))
-		return TRUE;
-
-	list = gst_structure_get_value(s, "rms");
-
-	/* Only bother with the first channel. */
-	value = gst_value_list_get_value(list, 0);
-	rms_db = g_value_get_double(value);
-
-	if (!strcmp(gst_element_get_name(src), "sendlevel"))
-		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gntmedia->priv->send_progress), pow(10, rms_db / 20) * 5);
-	else
-		gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gntmedia->priv->recv_progress), pow(10, rms_db / 20) * 5);
-
-	return TRUE;
-#endif
-}
-
 static void
 finch_media_ready_cb(PurpleMedia *media, FinchMedia *gntmedia)
 {
-	GstElement *element = purple_media_get_pipeline(media);
-
 	GstElement *sendbin, *sendlevel;
 	GstElement *recvbin, *recvlevel;
 
@@ -233,18 +191,16 @@
 	}
 	g_list_free(sessions);
 
-	g_object_set(gntmedia, "send-level", &sendlevel,
-		     "recv-level", &recvlevel,
+	g_object_set(gntmedia, "send-level", sendlevel,
+		     "recv-level", recvlevel,
 		     NULL);
-
-	gst_bus_add_signal_watch(GST_BUS(gst_pipeline_get_bus(GST_PIPELINE(element))));
-	g_signal_connect(G_OBJECT(gst_pipeline_get_bus(GST_PIPELINE(element))), "message", G_CALLBACK(level_message_cb), gntmedia);
 }
 
 static void
 finch_media_accept_cb(PurpleMedia *media, FinchMedia *gntmedia)
 {
 	GntWidget *parent;
+	GstElement *sendbin = NULL, *recvbin = NULL;
 
 	finch_media_emit_message(gntmedia, _("Call in progress."));
 
@@ -267,6 +223,10 @@
 		parent = parent->parent;
 	gnt_box_readjust(GNT_BOX(parent));
 	gnt_widget_draw(parent);
+
+	purple_media_get_elements(media, &sendbin, &recvbin, NULL, NULL);
+	gst_element_set_state(GST_ELEMENT(sendbin), GST_STATE_PLAYING);
+	gst_element_set_state(GST_ELEMENT(recvbin), GST_STATE_PLAYING);
 }
 
 static void
@@ -282,11 +242,6 @@
 	gnt_box_add_widget(GNT_BOX(gntmedia), gntmedia->priv->calling);
 	gnt_box_add_widget(GNT_BOX(gntmedia), gntmedia->priv->hangup);
 
-	gnt_widget_destroy(gntmedia->priv->accept);
-	gnt_widget_destroy(gntmedia->priv->reject);
-	gntmedia->priv->accept = NULL;
-	gntmedia->priv->reject = NULL;
-
 	parent = GNT_WIDGET(gntmedia);
 	while (parent->parent)
 		parent = parent->parent;
@@ -300,6 +255,8 @@
 	finch_media_emit_message(gntmedia, _("You have ended the call."));
 	finch_conversation_set_info_widget(gntmedia->priv->conv, NULL);
 	gnt_widget_destroy(GNT_WIDGET(gntmedia));
+	/* XXX: This shouldn't have to be here to free the FinchMedia widget */
+	g_object_unref(gntmedia);
 }
 
 static void
@@ -308,6 +265,8 @@
 	finch_media_emit_message(gntmedia, _("The call has been terminated."));
 	finch_conversation_set_info_widget(gntmedia->priv->conv, NULL);
 	gnt_widget_destroy(GNT_WIDGET(gntmedia));
+	/* XXX: This shouldn't have to be here to free the FinchMedia widget */
+	g_object_unref(gntmedia);
 }
 
 static void
@@ -316,6 +275,8 @@
 	finch_media_emit_message(gntmedia, _("You have rejected the call."));
 	finch_conversation_set_info_widget(gntmedia->priv->conv, NULL);
 	gnt_widget_destroy(GNT_WIDGET(gntmedia));
+	/* XXX: This shouldn't have to be here to free the FinchMedia widget */
+	g_object_unref(gntmedia);
 }
 
 static void
@@ -436,10 +397,9 @@
 {
 	PurpleAccount *account = purple_conversation_get_account(conv);
 
-	PurpleMedia *media =
-		purple_prpl_initiate_media(account,
-							purple_conversation_get_name(conv),
-							PURPLE_MEDIA_RECV_AUDIO & PURPLE_MEDIA_SEND_AUDIO);
+	PurpleMedia *media = purple_prpl_initiate_media(account,
+			purple_conversation_get_name(conv),
+			PURPLE_MEDIA_AUDIO);
 
 	if (!media)
 		return PURPLE_CMD_STATUS_FAILED;