1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*
* empathy-streamed-media-factory.c - Source for EmpathyStreamedMediaFactory
* Copyright (C) 2008-2011 Collabora Ltd.
* @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <telepathy-glib/account-channel-request.h>
#include <telepathy-glib/simple-handler.h>
#include <telepathy-glib/interfaces.h>
#include <telepathy-glib/util.h>
#include <libempathy/empathy-request-util.h>
#include <libempathy/empathy-utils.h>
#include "empathy-streamed-media-factory.h"
#include "empathy-streamed-media-handler.h"
#define DEBUG_FLAG EMPATHY_DEBUG_VOIP
#include <libempathy/empathy-debug.h>
G_DEFINE_TYPE(EmpathyStreamedMediaFactory, empathy_streamed_media_factory, G_TYPE_OBJECT)
static void handle_channels_cb (TpSimpleHandler *handler,
TpAccount *account,
TpConnection *connection,
GList *channels,
GList *requests_satisfied,
gint64 user_action_time,
TpHandleChannelsContext *context,
gpointer user_data);
/* signal enum */
enum
{
NEW_STREAMED_MEDIA_HANDLER,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = {0};
/* private structure */
typedef struct {
TpBaseClient *handler;
gboolean dispose_has_run;
} EmpathyStreamedMediaFactoryPriv;
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyStreamedMediaFactory)
static GObject *call_factory = NULL;
static void
empathy_streamed_media_factory_init (EmpathyStreamedMediaFactory *obj)
{
EmpathyStreamedMediaFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
EMPATHY_TYPE_STREAMED_MEDIA_FACTORY, EmpathyStreamedMediaFactoryPriv);
TpAccountManager *am;
obj->priv = priv;
am = tp_account_manager_dup ();
priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
EMPATHY_AV_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, obj, NULL);
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
NULL));
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
NULL));
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
NULL));
tp_base_client_add_handler_capabilities_varargs (priv->handler,
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
NULL);
g_object_unref (am);
}
static GObject *
empathy_streamed_media_factory_constructor (GType type, guint n_construct_params,
GObjectConstructParam *construct_params)
{
g_return_val_if_fail (call_factory == NULL, NULL);
call_factory = G_OBJECT_CLASS (empathy_streamed_media_factory_parent_class)->constructor
(type, n_construct_params, construct_params);
g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
return call_factory;
}
static void
empathy_streamed_media_factory_finalize (GObject *object)
{
/* free any data held directly by the object here */
if (G_OBJECT_CLASS (empathy_streamed_media_factory_parent_class)->finalize)
G_OBJECT_CLASS (empathy_streamed_media_factory_parent_class)->finalize (object);
}
static void
empathy_streamed_media_factory_dispose (GObject *object)
{
EmpathyStreamedMediaFactoryPriv *priv = GET_PRIV (object);
if (priv->dispose_has_run)
return;
priv->dispose_has_run = TRUE;
tp_clear_object (&priv->handler);
if (G_OBJECT_CLASS (empathy_streamed_media_factory_parent_class)->dispose)
G_OBJECT_CLASS (empathy_streamed_media_factory_parent_class)->dispose (object);
}
static void
empathy_streamed_media_factory_class_init (
EmpathyStreamedMediaFactoryClass *empathy_streamed_media_factory_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (empathy_streamed_media_factory_class);
g_type_class_add_private (empathy_streamed_media_factory_class,
sizeof (EmpathyStreamedMediaFactoryPriv));
object_class->constructor = empathy_streamed_media_factory_constructor;
object_class->dispose = empathy_streamed_media_factory_dispose;
object_class->finalize = empathy_streamed_media_factory_finalize;
signals[NEW_STREAMED_MEDIA_HANDLER] =
g_signal_new ("new-streamed-media-handler",
G_TYPE_FROM_CLASS (empathy_streamed_media_factory_class),
G_SIGNAL_RUN_LAST, 0,
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
2, EMPATHY_TYPE_STREAMED_MEDIA_HANDLER, G_TYPE_BOOLEAN);
}
EmpathyStreamedMediaFactory *
empathy_streamed_media_factory_initialise (void)
{
g_return_val_if_fail (call_factory == NULL, NULL);
return EMPATHY_STREAMED_MEDIA_FACTORY (g_object_new (EMPATHY_TYPE_STREAMED_MEDIA_FACTORY, NULL));
}
EmpathyStreamedMediaFactory *
empathy_streamed_media_factory_get (void)
{
g_return_val_if_fail (call_factory != NULL, NULL);
return EMPATHY_STREAMED_MEDIA_FACTORY (call_factory);
}
static void
create_streamed_media_handler (EmpathyStreamedMediaFactory *factory,
EmpathyTpStreamedMedia *call)
{
EmpathyStreamedMediaHandler *handler;
g_return_if_fail (factory != NULL);
handler = empathy_streamed_media_handler_new_for_channel (call);
g_signal_emit (factory, signals[NEW_STREAMED_MEDIA_HANDLER], 0,
handler, FALSE);
g_object_unref (handler);
}
static void
call_status_changed_cb (EmpathyTpStreamedMedia *call,
GParamSpec *spec,
EmpathyStreamedMediaFactory *self)
{
if (empathy_tp_streamed_media_get_status (call) <= EMPATHY_TP_STREAMED_MEDIA_STATUS_READYING)
return;
create_streamed_media_handler (self, call);
g_signal_handlers_disconnect_by_func (call, call_status_changed_cb, self);
g_object_unref (call);
}
static void
handle_channels_cb (TpSimpleHandler *handler,
TpAccount *account,
TpConnection *connection,
GList *channels,
GList *requests_satisfied,
gint64 user_action_time,
TpHandleChannelsContext *context,
gpointer user_data)
{
EmpathyStreamedMediaFactory *self = user_data;
GList *l;
for (l = channels; l != NULL; l = g_list_next (l))
{
TpChannel *channel = l->data;
EmpathyTpStreamedMedia *call;
if (tp_proxy_get_invalidated (channel) != NULL)
continue;
if (tp_channel_get_channel_type_id (channel) !=
TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
continue;
call = empathy_tp_streamed_media_new (account, channel);
if (empathy_tp_streamed_media_get_status (call) <= EMPATHY_TP_STREAMED_MEDIA_STATUS_READYING)
{
/* We have to wait that the TpStreamedMedia is ready as the
* call-handler rely on it. */
tp_g_signal_connect_object (call, "notify::status",
G_CALLBACK (call_status_changed_cb), self, 0);
continue;
}
create_streamed_media_handler (self, call);
g_object_unref (call);
}
tp_handle_channels_context_accept (context);
}
gboolean
empathy_streamed_media_factory_register (EmpathyStreamedMediaFactory *self,
GError **error)
{
EmpathyStreamedMediaFactoryPriv *priv = GET_PRIV (self);
return tp_base_client_register (priv->handler, error);
}
|