#include "empathy-call-handler.h"
#include "empathy-dispatcher.h"
#include "empathy-marshal.h"
+#include "empathy-utils.h"
G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
/* signal enum */
-enum
-{
+enum {
CONFERENCE_ADDED,
SRC_PAD_ADDED,
SINK_PAD_ADDED,
+ REQUEST_RESOURCE,
+ CLOSED,
LAST_SIGNAL
};
};
/* private structure */
-typedef struct _EmpathyCallHandlerPriv EmpathyCallHandlerPriv;
-struct _EmpathyCallHandlerPriv
-{
+typedef struct {
gboolean dispose_has_run;
EmpathyTpCall *call;
EmpathyContact *contact;
TfChannel *tfchannel;
- GstBus *bus;
-};
+} EmpathyCallHandlerPriv;
-#define GET_PRIV(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_HANDLER,\
- EmpathyCallHandlerPriv))
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
static void
-empathy_call_handler_init (EmpathyCallHandler *obj)
+empathy_call_handler_dispose (GObject *object)
{
- //EmpathyCallHandlerPriv *priv = GET_PRIV (obj);
+ EmpathyCallHandlerPriv *priv = GET_PRIV (object);
+
+ if (priv->dispose_has_run)
+ return;
+
+ priv->dispose_has_run = TRUE;
+
+ if (priv->contact != NULL)
+ g_object_unref (priv->contact);
+
+ priv->contact = NULL;
+
+ if (priv->tfchannel != NULL)
+ g_object_unref (priv->tfchannel);
+
+ priv->tfchannel = NULL;
+
+ if (priv->call != NULL)
+ {
+ empathy_tp_call_close (priv->call);
+ g_object_unref (priv->call);
+ }
- /* allocate any data required by the object here */
+ priv->call = NULL;
+
+ /* release any references held by the object here */
+ if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose)
+ G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
+}
+
+static void
+empathy_call_handler_finalize (GObject *object)
+{
+ /* free any data held directly by the object here */
+ if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize)
+ G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
}
-static void empathy_call_handler_dispose (GObject *object);
-static void empathy_call_handler_finalize (GObject *object);
+static void
+empathy_call_handler_init (EmpathyCallHandler *obj)
+{
+ EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
+ EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
+
+ obj->priv = priv;
+}
static void
empathy_call_handler_set_property (GObject *object,
case PROP_TP_CALL:
priv->call = g_value_dup_object (value);
break;
- case PROP_GST_BUS:
- priv->bus = g_value_dup_object (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
case PROP_TP_CALL:
g_value_set_object (value, priv->call);
break;
- case PROP_GST_BUS:
- g_value_set_object (value, priv->bus);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
- param_spec = g_param_spec_object ("gst-bus",
- "gst-bus", "The gstreamer bus",
- GST_TYPE_BUS,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (object_class, PROP_GST_BUS, param_spec);
-
param_spec = g_param_spec_object ("tp-call",
"tp-call", "The calls channel wrapper",
EMPATHY_TYPE_TP_CALL,
_empathy_marshal_VOID__OBJECT_UINT,
G_TYPE_NONE,
2, GST_TYPE_PAD, G_TYPE_UINT);
-}
-
-void
-empathy_call_handler_dispose (GObject *object)
-{
- EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
- EmpathyCallHandlerPriv *priv = GET_PRIV (self);
-
- if (priv->dispose_has_run)
- return;
-
- priv->dispose_has_run = TRUE;
-
- if (priv->contact != NULL)
- g_object_unref (priv->contact);
-
- priv->contact = NULL;
-
- if (priv->tfchannel != NULL)
- g_object_unref (priv->tfchannel);
-
- priv->tfchannel = NULL;
-
- if (priv->call != NULL)
- {
- empathy_tp_call_close (priv->call);
- g_object_unref (priv->call);
- }
-
- priv->call = NULL;
-
- /* release any references held by the object here */
- if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose)
- G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
-}
-void
-empathy_call_handler_finalize (GObject *object)
-{
- //EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
- //EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+ signals[REQUEST_RESOURCE] =
+ g_signal_new ("request-resource", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0,
+ g_signal_accumulator_true_handled, NULL,
+ _empathy_marshal_BOOLEAN__UINT_UINT,
+ G_TYPE_BOOLEAN, 2, G_TYPE_UINT, G_TYPE_UINT);
- /* free any data held directly by the object here */
-
- G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
+ signals[CLOSED] =
+ g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
}
EmpathyCallHandler *
"tp-call", call, NULL));
}
-static gboolean
-empathy_call_handler_pipeline_bus_watch (GstBus *bus, GstMessage *message,
- gpointer user_data)
+void
+empathy_call_handler_bus_message (EmpathyCallHandler *handler,
+ GstBus *bus, GstMessage *message)
{
- EmpathyCallHandler *handler = EMPATHY_CALL_HANDLER (user_data);
EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
- g_assert (priv->tfchannel != NULL);
+ if (priv->tfchannel == NULL)
+ return;
tf_channel_bus_message (priv->tfchannel, message);
-
- return TRUE;
}
static void
FsConference *conference, FsParticipant *participant,
EmpathyCallHandler *self)
{
- EmpathyCallHandlerPriv *priv = GET_PRIV (self);
-
- gst_bus_add_watch (priv->bus, empathy_call_handler_pipeline_bus_watch, self);
-
g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
GST_ELEMENT (conference));
}
empathy_call_handler_tf_stream_request_resource_cb (TfStream *stream,
guint direction, EmpathyTpCall *call)
{
- return TRUE;
+ gboolean ret;
+ guint media_type;
+
+ g_object_get (G_OBJECT (stream), "media-type", &media_type, NULL);
+
+ g_signal_emit (G_OBJECT (call),
+ signals[REQUEST_RESOURCE], 0, media_type, direction, &ret);
+
+ return ret;
}
static void
gst_object_unref (spad);
}
+static void
+empathy_call_handler_tf_channel_closed_cb (TfChannel *tfchannel,
+ EmpathyCallHandler *handler)
+{
+ g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
+}
+
+static GList *
+empathy_call_handler_tf_channel_codec_config_get_defaults (FsCodec *codecs)
+{
+ GList *l = NULL;
+ int i;
+
+ for (i = 0; codecs[i].encoding_name != NULL; i++)
+ l = g_list_append (l, fs_codec_copy (codecs + i));
+
+ return l;
+}
+
+static GList *
+empathy_call_handler_tf_channel_codec_config_cb (TfChannel *channel,
+ guint stream_id, FsMediaType media_type, guint direction, gpointer user_data)
+{
+ FsCodec audio_codecs[] = {
+ { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 16000, },
+ { FS_CODEC_ID_ANY, "SPEEX", FS_MEDIA_TYPE_AUDIO, 8000, },
+
+ { FS_CODEC_ID_DISABLE, "DV", FS_MEDIA_TYPE_AUDIO, },
+ { FS_CODEC_ID_DISABLE, "MPA", FS_MEDIA_TYPE_AUDIO, },
+ { FS_CODEC_ID_DISABLE, "VORBIS", FS_MEDIA_TYPE_AUDIO, },
+ { FS_CODEC_ID_DISABLE, "MP3", FS_MEDIA_TYPE_AUDIO, },
+ { 0, NULL, 0,}
+ };
+ FsCodec video_codecs[] = {
+ { FS_CODEC_ID_ANY, "H264", FS_MEDIA_TYPE_VIDEO, },
+ { FS_CODEC_ID_ANY, "THEORA", FS_MEDIA_TYPE_VIDEO, },
+ { FS_CODEC_ID_ANY, "H263", FS_MEDIA_TYPE_VIDEO, },
+
+ { FS_CODEC_ID_DISABLE, "DV", FS_MEDIA_TYPE_VIDEO, },
+ { FS_CODEC_ID_DISABLE, "JPEG", FS_MEDIA_TYPE_VIDEO, },
+ { FS_CODEC_ID_DISABLE, "MPV", FS_MEDIA_TYPE_VIDEO, },
+ { 0, NULL, 0}
+ };
+
+ switch (media_type)
+ {
+ case FS_MEDIA_TYPE_AUDIO:
+ return empathy_call_handler_tf_channel_codec_config_get_defaults
+ (audio_codecs);
+ case FS_MEDIA_TYPE_VIDEO:
+ return empathy_call_handler_tf_channel_codec_config_get_defaults
+ (video_codecs);
+ }
+
+ return NULL;
+}
+
static void
empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
{
G_CALLBACK (empathy_call_handler_tf_channel_session_created_cb), self);
g_signal_connect (priv->tfchannel, "stream-created",
G_CALLBACK (empathy_call_handler_tf_channel_stream_created_cb), self);
+ g_signal_connect (priv->tfchannel, "closed",
+ G_CALLBACK (empathy_call_handler_tf_channel_closed_cb), self);
+ g_signal_connect (priv->tfchannel, "stream-get-codec-config",
+ G_CALLBACK (empathy_call_handler_tf_channel_codec_config_cb), self);
g_object_unref (channel);
}
empathy_dispatch_operation_claim (operation);
}
-static void
-empathy_call_handler_contact_ready_cb (EmpathyContact *contact,
- const GError *error, gpointer user_data, GObject *object)
+void
+empathy_call_handler_start_call (EmpathyCallHandler *handler)
{
- EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
- EmpathyCallHandlerPriv *priv = GET_PRIV (self);
+
+ EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
EmpathyDispatcher *dispatcher;
- McAccount *account;
+ TpConnection *connection;
GStrv allowed;
GValue *value;
- GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
- (GDestroyNotify) tp_g_value_slice_free);
+ GHashTable *request;
+
+ if (priv->call != NULL)
+ {
+ empathy_call_handler_start_tpfs (handler);
+ empathy_tp_call_accept_incoming_call (priv->call);
+ return;
+ }
g_assert (priv->contact != NULL);
dispatcher = empathy_dispatcher_dup_singleton ();
- account = empathy_contact_get_account (priv->contact);
- allowed = empathy_dispatcher_find_channel_class (dispatcher, account,
+ connection = empathy_contact_get_connection (priv->contact);
+ allowed = empathy_dispatcher_find_channel_class (dispatcher, connection,
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT);
- if (!tp_strv_contains ((const gchar * const *)allowed,
+ if (!tp_strv_contains ((const gchar * const *) allowed,
TP_IFACE_CHANNEL ".TargetHandle"))
- g_assert_not_reached ();
+ return;
+
+ request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
+ (GDestroyNotify) tp_g_value_slice_free);
/* org.freedesktop.Telepathy.Channel.ChannelType */
value = tp_g_value_slice_new (G_TYPE_STRING);
g_value_set_uint (value, empathy_contact_get_handle (priv->contact));
g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
- empathy_dispatcher_create_channel (dispatcher, account,
- request, empathy_call_handler_request_cb, self);
+ empathy_dispatcher_create_channel (dispatcher, connection,
+ request, empathy_call_handler_request_cb, handler);
g_object_unref (dispatcher);
}
-void
-empathy_call_handler_start_call (EmpathyCallHandler *handler)
-{
-
- EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
-
- if (priv->call == NULL)
- {
- empathy_contact_call_when_ready (priv->contact,
- EMPATHY_CONTACT_READY_ID,
- empathy_call_handler_contact_ready_cb, NULL, NULL, G_OBJECT (handler));
- }
- else
- {
- empathy_call_handler_start_tpfs (handler);
- empathy_tp_call_accept_incoming_call (priv->call);
- }
-}
-
-void
-empathy_call_handler_set_bus (EmpathyCallHandler *handler, GstBus *bus)
-{
- EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
-
- g_assert (priv->bus == NULL);
-
- priv->bus = g_object_ref (bus);
-}
-