Mercurial > pidgin.yaz
annotate libpurple/media/media.c @ 29549:41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
author | maiku@pidgin.im |
---|---|
date | Fri, 23 Oct 2009 02:11:33 +0000 |
parents | 30e8ab2a4bc2 |
children | 846a475a1573 |
rev | line source |
---|---|
29534 | 1 /** |
2 * @file media.c Media API | |
3 * @ingroup core | |
4 */ | |
5 | |
6 /* purple | |
7 * | |
8 * Purple is the legal property of its developers, whose names are too numerous | |
9 * to list here. Please refer to the COPYRIGHT file distributed with this | |
10 * source distribution. | |
11 * | |
12 * This program is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
25 */ | |
26 | |
27 #include <string.h> | |
28 | |
29 #include "internal.h" | |
30 | |
31 #include "account.h" | |
32 #include "media.h" | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
33 #include "media/backend-fs2.h" |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
34 #include "media/backend-iface.h" |
29534 | 35 #include "mediamanager.h" |
36 #include "network.h" | |
37 | |
38 #include "debug.h" | |
39 | |
40 #ifdef USE_GSTREAMER | |
41 #include "marshallers.h" | |
42 #include "media-gst.h" | |
43 #endif | |
44 | |
45 #ifdef USE_VV | |
46 | |
47 #include <gst/farsight/fs-conference-iface.h> | |
48 #include <gst/farsight/fs-element-added-notifier.h> | |
49 | |
50 /** @copydoc _PurpleMediaSession */ | |
51 typedef struct _PurpleMediaSession PurpleMediaSession; | |
52 /** @copydoc _PurpleMediaStream */ | |
53 typedef struct _PurpleMediaStream PurpleMediaStream; | |
54 /** @copydoc _PurpleMediaClass */ | |
55 typedef struct _PurpleMediaClass PurpleMediaClass; | |
56 /** @copydoc _PurpleMediaPrivate */ | |
57 typedef struct _PurpleMediaPrivate PurpleMediaPrivate; | |
58 | |
59 /** The media class */ | |
60 struct _PurpleMediaClass | |
61 { | |
62 GObjectClass parent_class; /**< The parent class. */ | |
63 }; | |
64 | |
65 /** The media class's private data */ | |
66 struct _PurpleMedia | |
67 { | |
68 GObject parent; /**< The parent of this object. */ | |
69 PurpleMediaPrivate *priv; /**< The private data of this object. */ | |
70 }; | |
71 | |
72 struct _PurpleMediaSession | |
73 { | |
74 gchar *id; | |
75 PurpleMedia *media; | |
76 GstElement *src; | |
77 GstElement *tee; | |
78 FsSession *session; | |
79 | |
80 PurpleMediaSessionType type; | |
81 gboolean initiator; | |
82 }; | |
83 | |
84 struct _PurpleMediaStream | |
85 { | |
86 PurpleMediaSession *session; | |
87 gchar *participant; | |
88 FsStream *stream; | |
89 GstElement *src; | |
90 GstElement *tee; | |
91 GstElement *volume; | |
92 GstElement *level; | |
93 | |
94 GList *local_candidates; | |
95 GList *remote_candidates; | |
96 | |
97 gboolean initiator; | |
98 gboolean accepted; | |
99 gboolean candidates_prepared; | |
100 | |
101 GList *active_local_candidates; | |
102 GList *active_remote_candidates; | |
103 | |
104 guint connected_cb_id; | |
105 }; | |
106 #endif | |
107 | |
108 struct _PurpleMediaPrivate | |
109 { | |
110 #ifdef USE_VV | |
111 PurpleMediaManager *manager; | |
112 PurpleAccount *account; | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
113 PurpleMediaBackend *backend; |
29534 | 114 FsConference *conference; |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
115 gchar *conference_type; |
29534 | 116 gboolean initiator; |
117 gpointer prpl_data; | |
118 | |
119 GHashTable *sessions; /* PurpleMediaSession table */ | |
120 GHashTable *participants; /* FsParticipant table */ | |
121 | |
122 GList *streams; /* PurpleMediaStream table */ | |
123 | |
124 GstElement *confbin; | |
125 #else | |
126 gpointer dummy; | |
127 #endif | |
128 }; | |
129 | |
130 #ifdef USE_VV | |
131 #define PURPLE_MEDIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MEDIA, PurpleMediaPrivate)) | |
132 | |
133 static void purple_media_class_init (PurpleMediaClass *klass); | |
134 static void purple_media_init (PurpleMedia *media); | |
135 static void purple_media_dispose (GObject *object); | |
136 static void purple_media_finalize (GObject *object); | |
137 static void purple_media_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
138 static void purple_media_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
139 | |
140 static void purple_media_new_local_candidate_cb(FsStream *stream, | |
141 FsCandidate *local_candidate, PurpleMediaSession *session); | |
142 static void purple_media_candidates_prepared_cb(FsStream *stream, | |
143 PurpleMediaSession *session); | |
144 static void purple_media_candidate_pair_established_cb(FsStream *stream, | |
145 FsCandidate *native_candidate, FsCandidate *remote_candidate, | |
146 PurpleMediaSession *session); | |
147 static gboolean media_bus_call(GstBus *bus, | |
148 GstMessage *msg, PurpleMedia *media); | |
149 | |
150 static GObjectClass *parent_class = NULL; | |
151 | |
152 | |
153 | |
154 enum { | |
155 S_ERROR, | |
156 CANDIDATES_PREPARED, | |
157 CODECS_CHANGED, | |
158 LEVEL, | |
159 NEW_CANDIDATE, | |
160 STATE_CHANGED, | |
161 STREAM_INFO, | |
162 LAST_SIGNAL | |
163 }; | |
164 static guint purple_media_signals[LAST_SIGNAL] = {0}; | |
165 | |
166 enum { | |
167 PROP_0, | |
168 PROP_MANAGER, | |
169 PROP_ACCOUNT, | |
170 PROP_CONFERENCE, | |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
171 PROP_CONFERENCE_TYPE, |
29534 | 172 PROP_INITIATOR, |
173 PROP_PRPL_DATA, | |
174 }; | |
175 #endif | |
176 | |
177 | |
178 GType | |
179 purple_media_get_type() | |
180 { | |
181 #ifdef USE_VV | |
182 static GType type = 0; | |
183 | |
184 if (type == 0) { | |
185 static const GTypeInfo info = { | |
186 sizeof(PurpleMediaClass), | |
187 NULL, | |
188 NULL, | |
189 (GClassInitFunc) purple_media_class_init, | |
190 NULL, | |
191 NULL, | |
192 sizeof(PurpleMedia), | |
193 0, | |
194 (GInstanceInitFunc) purple_media_init, | |
195 NULL | |
196 }; | |
197 type = g_type_register_static(G_TYPE_OBJECT, "PurpleMedia", &info, 0); | |
198 } | |
199 return type; | |
200 #else | |
201 return G_TYPE_NONE; | |
202 #endif | |
203 } | |
204 | |
205 #ifdef USE_VV | |
206 static void | |
207 purple_media_class_init (PurpleMediaClass *klass) | |
208 { | |
209 GObjectClass *gobject_class = (GObjectClass*)klass; | |
210 parent_class = g_type_class_peek_parent(klass); | |
211 | |
212 gobject_class->dispose = purple_media_dispose; | |
213 gobject_class->finalize = purple_media_finalize; | |
214 gobject_class->set_property = purple_media_set_property; | |
215 gobject_class->get_property = purple_media_get_property; | |
216 | |
217 g_object_class_install_property(gobject_class, PROP_MANAGER, | |
218 g_param_spec_object("manager", | |
219 "Purple Media Manager", | |
220 "The media manager that contains this media session.", | |
221 PURPLE_TYPE_MEDIA_MANAGER, | |
222 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); | |
223 | |
224 g_object_class_install_property(gobject_class, PROP_ACCOUNT, | |
225 g_param_spec_pointer("account", | |
226 "PurpleAccount", | |
227 "The account this media session is on.", | |
228 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); | |
229 | |
230 g_object_class_install_property(gobject_class, PROP_CONFERENCE, | |
231 g_param_spec_object("conference", | |
232 "Farsight conference", | |
233 "The FsConference associated with this media.", | |
234 FS_TYPE_CONFERENCE, | |
235 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)); | |
236 | |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
237 g_object_class_install_property(gobject_class, PROP_CONFERENCE_TYPE, |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
238 g_param_spec_string("conference-type", |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
239 "Conference Type", |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
240 "The type of conference that this media object " |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
241 "has been created to provide.", |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
242 NULL, |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
243 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
244 |
29534 | 245 g_object_class_install_property(gobject_class, PROP_INITIATOR, |
246 g_param_spec_boolean("initiator", | |
247 "initiator", | |
248 "If the local user initiated the conference.", | |
249 FALSE, | |
250 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)); | |
251 | |
252 g_object_class_install_property(gobject_class, PROP_PRPL_DATA, | |
253 g_param_spec_pointer("prpl-data", | |
254 "gpointer", | |
255 "Data the prpl plugin set on the media session.", | |
256 G_PARAM_READWRITE)); | |
257 | |
258 purple_media_signals[S_ERROR] = g_signal_new("error", G_TYPE_FROM_CLASS(klass), | |
259 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
260 g_cclosure_marshal_VOID__STRING, | |
261 G_TYPE_NONE, 1, G_TYPE_STRING); | |
262 purple_media_signals[CANDIDATES_PREPARED] = g_signal_new("candidates-prepared", G_TYPE_FROM_CLASS(klass), | |
263 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
264 purple_smarshal_VOID__STRING_STRING, | |
265 G_TYPE_NONE, 2, G_TYPE_STRING, | |
266 G_TYPE_STRING); | |
267 purple_media_signals[CODECS_CHANGED] = g_signal_new("codecs-changed", G_TYPE_FROM_CLASS(klass), | |
268 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
269 g_cclosure_marshal_VOID__STRING, | |
270 G_TYPE_NONE, 1, G_TYPE_STRING); | |
271 purple_media_signals[LEVEL] = g_signal_new("level", G_TYPE_FROM_CLASS(klass), | |
272 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
273 purple_smarshal_VOID__STRING_STRING_DOUBLE, | |
274 G_TYPE_NONE, 3, G_TYPE_STRING, | |
275 G_TYPE_STRING, G_TYPE_DOUBLE); | |
276 purple_media_signals[NEW_CANDIDATE] = g_signal_new("new-candidate", G_TYPE_FROM_CLASS(klass), | |
277 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
278 purple_smarshal_VOID__POINTER_POINTER_OBJECT, | |
279 G_TYPE_NONE, 3, G_TYPE_POINTER, | |
280 G_TYPE_POINTER, PURPLE_TYPE_MEDIA_CANDIDATE); | |
281 purple_media_signals[STATE_CHANGED] = g_signal_new("state-changed", G_TYPE_FROM_CLASS(klass), | |
282 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
283 purple_smarshal_VOID__ENUM_STRING_STRING, | |
284 G_TYPE_NONE, 3, PURPLE_MEDIA_TYPE_STATE, | |
285 G_TYPE_STRING, G_TYPE_STRING); | |
286 purple_media_signals[STREAM_INFO] = g_signal_new("stream-info", G_TYPE_FROM_CLASS(klass), | |
287 G_SIGNAL_RUN_LAST, 0, NULL, NULL, | |
288 purple_smarshal_VOID__ENUM_STRING_STRING_BOOLEAN, | |
289 G_TYPE_NONE, 4, PURPLE_MEDIA_TYPE_INFO_TYPE, | |
290 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
291 g_type_class_add_private(klass, sizeof(PurpleMediaPrivate)); | |
292 } | |
293 | |
294 | |
295 static void | |
296 purple_media_init (PurpleMedia *media) | |
297 { | |
298 media->priv = PURPLE_MEDIA_GET_PRIVATE(media); | |
299 memset(media->priv, 0, sizeof(*media->priv)); | |
300 } | |
301 | |
302 static void | |
303 purple_media_stream_free(PurpleMediaStream *stream) | |
304 { | |
305 if (stream == NULL) | |
306 return; | |
307 | |
308 /* Remove the connected_cb timeout */ | |
309 if (stream->connected_cb_id != 0) | |
310 purple_timeout_remove(stream->connected_cb_id); | |
311 | |
312 g_free(stream->participant); | |
313 | |
314 if (stream->local_candidates) | |
315 fs_candidate_list_destroy(stream->local_candidates); | |
316 if (stream->remote_candidates) | |
317 fs_candidate_list_destroy(stream->remote_candidates); | |
318 | |
319 if (stream->active_local_candidates) | |
320 fs_candidate_list_destroy(stream->active_local_candidates); | |
321 if (stream->active_remote_candidates) | |
322 fs_candidate_list_destroy(stream->active_remote_candidates); | |
323 | |
324 g_free(stream); | |
325 } | |
326 | |
327 static void | |
328 purple_media_session_free(PurpleMediaSession *session) | |
329 { | |
330 if (session == NULL) | |
331 return; | |
332 | |
333 g_free(session->id); | |
334 g_free(session); | |
335 } | |
336 | |
337 static void | |
338 purple_media_dispose(GObject *media) | |
339 { | |
340 PurpleMediaPrivate *priv = PURPLE_MEDIA_GET_PRIVATE(media); | |
341 GList *iter = NULL; | |
342 | |
343 purple_debug_info("media","purple_media_dispose\n"); | |
344 | |
345 purple_media_manager_remove_media(priv->manager, PURPLE_MEDIA(media)); | |
346 | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
347 if (priv->backend) { |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
348 g_object_unref(priv->backend); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
349 priv->backend = NULL; |
29534 | 350 } |
351 | |
352 for (iter = priv->streams; iter; iter = g_list_next(iter)) { | |
353 PurpleMediaStream *stream = iter->data; | |
354 if (stream->stream) { | |
355 g_object_unref(stream->stream); | |
356 stream->stream = NULL; | |
357 } | |
358 } | |
359 | |
360 if (priv->sessions) { | |
361 GList *sessions = g_hash_table_get_values(priv->sessions); | |
362 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
363 PurpleMediaSession *session = sessions->data; | |
364 if (session->session) { | |
365 g_object_unref(session->session); | |
366 session->session = NULL; | |
367 } | |
368 } | |
369 } | |
370 | |
371 if (priv->participants) { | |
372 GList *participants = g_hash_table_get_values(priv->participants); | |
373 for (; participants; participants = g_list_delete_link(participants, participants)) | |
374 g_object_unref(participants->data); | |
375 } | |
376 | |
377 if (priv->manager) { | |
378 GstElement *pipeline = purple_media_manager_get_pipeline( | |
379 priv->manager); | |
380 GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); | |
381 g_signal_handlers_disconnect_matched(G_OBJECT(bus), | |
382 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, | |
383 0, 0, 0, media_bus_call, media); | |
384 gst_object_unref(bus); | |
385 | |
386 g_object_unref(priv->manager); | |
387 priv->manager = NULL; | |
388 } | |
389 | |
390 G_OBJECT_CLASS(parent_class)->dispose(media); | |
391 } | |
392 | |
393 static void | |
394 purple_media_finalize(GObject *media) | |
395 { | |
396 PurpleMediaPrivate *priv = PURPLE_MEDIA_GET_PRIVATE(media); | |
397 purple_debug_info("media","purple_media_finalize\n"); | |
398 | |
399 for (; priv->streams; priv->streams = g_list_delete_link(priv->streams, priv->streams)) | |
400 purple_media_stream_free(priv->streams->data); | |
401 | |
402 if (priv->sessions) { | |
403 GList *sessions = g_hash_table_get_values(priv->sessions); | |
404 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
405 purple_media_session_free(sessions->data); | |
406 } | |
407 g_hash_table_destroy(priv->sessions); | |
408 } | |
409 | |
410 G_OBJECT_CLASS(parent_class)->finalize(media); | |
411 } | |
412 | |
413 static void | |
414 purple_media_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) | |
415 { | |
416 PurpleMedia *media; | |
417 g_return_if_fail(PURPLE_IS_MEDIA(object)); | |
418 | |
419 media = PURPLE_MEDIA(object); | |
420 | |
421 switch (prop_id) { | |
422 case PROP_MANAGER: | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
423 media->priv->manager = g_value_dup_object(value); |
29534 | 424 break; |
425 case PROP_ACCOUNT: | |
426 media->priv->account = g_value_get_pointer(value); | |
427 break; | |
428 case PROP_CONFERENCE: { | |
429 if (media->priv->conference) | |
430 gst_object_unref(media->priv->conference); | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
431 media->priv->conference = g_value_dup_object(value); |
29534 | 432 break; |
433 } | |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
434 case PROP_CONFERENCE_TYPE: |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
435 media->priv->conference_type = |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
436 g_value_dup_string(value); |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
437 /* Will eventually get this type from the media manager */ |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
438 media->priv->backend = g_object_new( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
439 PURPLE_TYPE_MEDIA_BACKEND_FS2, |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
440 "conference-type", |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
441 media->priv->conference_type, |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
442 "media", media, |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
443 NULL); |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
444 break; |
29534 | 445 case PROP_INITIATOR: |
446 media->priv->initiator = g_value_get_boolean(value); | |
447 break; | |
448 case PROP_PRPL_DATA: | |
449 media->priv->prpl_data = g_value_get_pointer(value); | |
450 break; | |
451 default: | |
452 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
453 break; | |
454 } | |
455 } | |
456 | |
457 static void | |
458 purple_media_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) | |
459 { | |
460 PurpleMedia *media; | |
461 g_return_if_fail(PURPLE_IS_MEDIA(object)); | |
462 | |
463 media = PURPLE_MEDIA(object); | |
464 | |
465 switch (prop_id) { | |
466 case PROP_MANAGER: | |
467 g_value_set_object(value, media->priv->manager); | |
468 break; | |
469 case PROP_ACCOUNT: | |
470 g_value_set_pointer(value, media->priv->account); | |
471 break; | |
472 case PROP_CONFERENCE: | |
473 g_value_set_object(value, media->priv->conference); | |
474 break; | |
29545
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
475 case PROP_CONFERENCE_TYPE: |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
476 g_value_set_string(value, |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
477 media->priv->conference_type); |
30e8ab2a4bc2
Add a conference-type parameter to PurpleMedia.
maiku@pidgin.im
parents:
29538
diff
changeset
|
478 break; |
29534 | 479 case PROP_INITIATOR: |
480 g_value_set_boolean(value, media->priv->initiator); | |
481 break; | |
482 case PROP_PRPL_DATA: | |
483 g_value_set_pointer(value, media->priv->prpl_data); | |
484 break; | |
485 default: | |
486 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
487 break; | |
488 } | |
489 | |
490 } | |
491 | |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
492 static FsCandidate * |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
493 purple_media_candidate_to_fs(PurpleMediaCandidate *candidate) |
29534 | 494 { |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
495 FsCandidate *fscandidate; |
29534 | 496 gchar *foundation; |
497 guint component_id; | |
498 gchar *ip; | |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
499 guint port; |
29534 | 500 gchar *base_ip; |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
501 guint base_port; |
29534 | 502 PurpleMediaNetworkProtocol proto; |
503 guint32 priority; | |
504 PurpleMediaCandidateType type; | |
505 gchar *username; | |
506 gchar *password; | |
507 guint ttl; | |
508 | |
509 if (candidate == NULL) | |
510 return NULL; | |
511 | |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
512 g_object_get(G_OBJECT(candidate), |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
513 "foundation", &foundation, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
514 "component-id", &component_id, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
515 "ip", &ip, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
516 "port", &port, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
517 "base-ip", &base_ip, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
518 "base-port", &base_port, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
519 "protocol", &proto, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
520 "priority", &priority, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
521 "type", &type, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
522 "username", &username, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
523 "password", &password, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
524 "ttl", &ttl, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
525 NULL); |
29534 | 526 |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
527 fscandidate = fs_candidate_new(foundation, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
528 component_id, type, |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
529 proto, ip, port); |
29534 | 530 |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
531 fscandidate->base_ip = base_ip; |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
532 fscandidate->base_port = base_port; |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
533 fscandidate->priority = priority; |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
534 fscandidate->username = username; |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
535 fscandidate->password = password; |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
536 fscandidate->ttl = ttl; |
29534 | 537 |
29536
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
538 g_free(foundation); |
f585e10f156b
Split out PurpleMediaCandidate into its own file.
maiku@pidgin.im
parents:
29535
diff
changeset
|
539 g_free(ip); |
29534 | 540 return fscandidate; |
541 } | |
542 | |
543 static PurpleMediaCandidate * | |
544 purple_media_candidate_from_fs(FsCandidate *fscandidate) | |
545 { | |
546 PurpleMediaCandidate *candidate; | |
547 | |
548 if (fscandidate == NULL) | |
549 return NULL; | |
550 | |
551 candidate = purple_media_candidate_new(fscandidate->foundation, | |
552 fscandidate->component_id, fscandidate->type, | |
553 fscandidate->proto, fscandidate->ip, fscandidate->port); | |
554 g_object_set(candidate, | |
555 "base-ip", fscandidate->base_ip, | |
556 "base-port", fscandidate->base_port, | |
557 "priority", fscandidate->priority, | |
558 "username", fscandidate->username, | |
559 "password", fscandidate->password, | |
560 "ttl", fscandidate->ttl, NULL); | |
561 return candidate; | |
562 } | |
563 | |
564 static GList * | |
565 purple_media_candidate_list_from_fs(GList *candidates) | |
566 { | |
567 GList *new_list = NULL; | |
568 | |
569 for (; candidates; candidates = g_list_next(candidates)) { | |
570 new_list = g_list_prepend(new_list, | |
571 purple_media_candidate_from_fs( | |
572 candidates->data)); | |
573 } | |
574 | |
575 new_list = g_list_reverse(new_list); | |
576 return new_list; | |
577 } | |
578 | |
579 static GList * | |
580 purple_media_candidate_list_to_fs(GList *candidates) | |
581 { | |
582 GList *new_list = NULL; | |
583 | |
584 for (; candidates; candidates = g_list_next(candidates)) { | |
585 new_list = g_list_prepend(new_list, | |
586 purple_media_candidate_to_fs( | |
587 candidates->data)); | |
588 } | |
589 | |
590 new_list = g_list_reverse(new_list); | |
591 return new_list; | |
592 } | |
593 | |
594 static FsMediaType | |
595 purple_media_to_fs_media_type(PurpleMediaSessionType type) | |
596 { | |
597 if (type & PURPLE_MEDIA_AUDIO) | |
598 return FS_MEDIA_TYPE_AUDIO; | |
599 else if (type & PURPLE_MEDIA_VIDEO) | |
600 return FS_MEDIA_TYPE_VIDEO; | |
601 else | |
602 return 0; | |
603 } | |
604 | |
605 static FsStreamDirection | |
606 purple_media_to_fs_stream_direction(PurpleMediaSessionType type) | |
607 { | |
608 if ((type & PURPLE_MEDIA_AUDIO) == PURPLE_MEDIA_AUDIO || | |
609 (type & PURPLE_MEDIA_VIDEO) == PURPLE_MEDIA_VIDEO) | |
610 return FS_DIRECTION_BOTH; | |
611 else if ((type & PURPLE_MEDIA_SEND_AUDIO) || | |
612 (type & PURPLE_MEDIA_SEND_VIDEO)) | |
613 return FS_DIRECTION_SEND; | |
614 else if ((type & PURPLE_MEDIA_RECV_AUDIO) || | |
615 (type & PURPLE_MEDIA_RECV_VIDEO)) | |
616 return FS_DIRECTION_RECV; | |
617 else | |
618 return FS_DIRECTION_NONE; | |
619 } | |
620 | |
621 static PurpleMediaSessionType | |
622 purple_media_from_fs(FsMediaType type, FsStreamDirection direction) | |
623 { | |
624 PurpleMediaSessionType result = PURPLE_MEDIA_NONE; | |
625 if (type == FS_MEDIA_TYPE_AUDIO) { | |
626 if (direction & FS_DIRECTION_SEND) | |
627 result |= PURPLE_MEDIA_SEND_AUDIO; | |
628 if (direction & FS_DIRECTION_RECV) | |
629 result |= PURPLE_MEDIA_RECV_AUDIO; | |
630 } else if (type == FS_MEDIA_TYPE_VIDEO) { | |
631 if (direction & FS_DIRECTION_SEND) | |
632 result |= PURPLE_MEDIA_SEND_VIDEO; | |
633 if (direction & FS_DIRECTION_RECV) | |
634 result |= PURPLE_MEDIA_RECV_VIDEO; | |
635 } | |
636 return result; | |
637 } | |
638 | |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
639 static FsCodec * |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
640 purple_media_codec_to_fs(const PurpleMediaCodec *codec) |
29534 | 641 { |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
642 FsCodec *new_codec; |
29534 | 643 gint id; |
644 char *encoding_name; | |
645 PurpleMediaSessionType media_type; | |
646 guint clock_rate; | |
647 guint channels; | |
648 GList *iter; | |
649 | |
650 if (codec == NULL) | |
651 return NULL; | |
652 | |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
653 g_object_get(G_OBJECT(codec), |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
654 "id", &id, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
655 "encoding-name", &encoding_name, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
656 "media-type", &media_type, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
657 "clock-rate", &clock_rate, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
658 "channels", &channels, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
659 "optional-params", &iter, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
660 NULL); |
29534 | 661 |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
662 new_codec = fs_codec_new(id, encoding_name, |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
663 purple_media_to_fs_media_type(media_type), |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
664 clock_rate); |
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
665 new_codec->channels = channels; |
29534 | 666 |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
667 for (; iter; iter = g_list_next(iter)) { |
29534 | 668 PurpleKeyValuePair *param = (PurpleKeyValuePair*)iter->data; |
669 fs_codec_add_optional_parameter(new_codec, | |
670 param->key, param->value); | |
671 } | |
672 | |
29538
e18c1d347e37
Break PurpleMediaCodec out into its own file.
maiku@pidgin.im
parents:
29536
diff
changeset
|
673 g_free(encoding_name); |
29534 | 674 return new_codec; |
675 } | |
676 | |
677 static PurpleMediaCodec * | |
678 purple_media_codec_from_fs(const FsCodec *codec) | |
679 { | |
680 PurpleMediaCodec *new_codec; | |
681 GList *iter; | |
682 | |
683 if (codec == NULL) | |
684 return NULL; | |
685 | |
686 new_codec = purple_media_codec_new(codec->id, codec->encoding_name, | |
687 purple_media_from_fs(codec->media_type, | |
688 FS_DIRECTION_BOTH), codec->clock_rate); | |
689 g_object_set(new_codec, "channels", codec->channels, NULL); | |
690 | |
691 for (iter = codec->optional_params; iter; iter = g_list_next(iter)) { | |
692 FsCodecParameter *param = (FsCodecParameter*)iter->data; | |
693 purple_media_codec_add_optional_parameter(new_codec, | |
694 param->name, param->value); | |
695 } | |
696 | |
697 return new_codec; | |
698 } | |
699 | |
700 static GList * | |
701 purple_media_codec_list_from_fs(GList *codecs) | |
702 { | |
703 GList *new_list = NULL; | |
704 | |
705 for (; codecs; codecs = g_list_next(codecs)) { | |
706 new_list = g_list_prepend(new_list, | |
707 purple_media_codec_from_fs( | |
708 codecs->data)); | |
709 } | |
710 | |
711 new_list = g_list_reverse(new_list); | |
712 return new_list; | |
713 } | |
714 | |
715 static GList * | |
716 purple_media_codec_list_to_fs(GList *codecs) | |
717 { | |
718 GList *new_list = NULL; | |
719 | |
720 for (; codecs; codecs = g_list_next(codecs)) { | |
721 new_list = g_list_prepend(new_list, | |
722 purple_media_codec_to_fs( | |
723 codecs->data)); | |
724 } | |
725 | |
726 new_list = g_list_reverse(new_list); | |
727 return new_list; | |
728 } | |
729 | |
730 static PurpleMediaSession* | |
731 purple_media_get_session(PurpleMedia *media, const gchar *sess_id) | |
732 { | |
733 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
734 return (PurpleMediaSession*) (media->priv->sessions) ? | |
735 g_hash_table_lookup(media->priv->sessions, sess_id) : NULL; | |
736 } | |
737 | |
738 static FsParticipant* | |
739 purple_media_get_participant(PurpleMedia *media, const gchar *name) | |
740 { | |
741 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
742 return (FsParticipant*) (media->priv->participants) ? | |
743 g_hash_table_lookup(media->priv->participants, name) : NULL; | |
744 } | |
745 | |
746 static PurpleMediaStream* | |
747 purple_media_get_stream(PurpleMedia *media, const gchar *session, const gchar *participant) | |
748 { | |
749 GList *streams; | |
750 | |
751 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
752 | |
753 streams = media->priv->streams; | |
754 | |
755 for (; streams; streams = g_list_next(streams)) { | |
756 PurpleMediaStream *stream = streams->data; | |
757 if (!strcmp(stream->session->id, session) && | |
758 !strcmp(stream->participant, participant)) | |
759 return stream; | |
760 } | |
761 | |
762 return NULL; | |
763 } | |
764 | |
765 static GList * | |
766 purple_media_get_streams(PurpleMedia *media, const gchar *session, | |
767 const gchar *participant) | |
768 { | |
769 GList *streams; | |
770 GList *ret = NULL; | |
771 | |
772 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
773 | |
774 streams = media->priv->streams; | |
775 | |
776 for (; streams; streams = g_list_next(streams)) { | |
777 PurpleMediaStream *stream = streams->data; | |
778 if ((session == NULL || | |
779 !strcmp(stream->session->id, session)) && | |
780 (participant == NULL || | |
781 !strcmp(stream->participant, participant))) | |
782 ret = g_list_append(ret, stream); | |
783 } | |
784 | |
785 return ret; | |
786 } | |
787 | |
788 static void | |
789 purple_media_add_session(PurpleMedia *media, PurpleMediaSession *session) | |
790 { | |
791 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
792 g_return_if_fail(session != NULL); | |
793 | |
794 if (!media->priv->sessions) { | |
795 purple_debug_info("media", "Creating hash table for sessions\n"); | |
796 media->priv->sessions = g_hash_table_new(g_str_hash, g_str_equal); | |
797 } | |
798 g_hash_table_insert(media->priv->sessions, g_strdup(session->id), session); | |
799 } | |
800 | |
801 static gboolean | |
802 purple_media_remove_session(PurpleMedia *media, PurpleMediaSession *session) | |
803 { | |
804 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
805 return g_hash_table_remove(media->priv->sessions, session->id); | |
806 } | |
807 | |
808 static FsParticipant * | |
809 purple_media_add_participant(PurpleMedia *media, const gchar *name) | |
810 { | |
811 FsParticipant *participant; | |
812 GError *err = NULL; | |
813 | |
814 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
815 | |
816 participant = purple_media_get_participant(media, name); | |
817 | |
818 if (participant) | |
819 return participant; | |
820 | |
821 participant = fs_conference_new_participant(media->priv->conference, | |
822 (gchar*)name, &err); | |
823 | |
824 if (err) { | |
825 purple_debug_error("media", "Error creating participant: %s\n", | |
826 err->message); | |
827 g_error_free(err); | |
828 return NULL; | |
829 } | |
830 | |
831 if (!media->priv->participants) { | |
832 purple_debug_info("media", "Creating hash table for participants\n"); | |
833 media->priv->participants = g_hash_table_new_full(g_str_hash, | |
834 g_str_equal, g_free, NULL); | |
835 } | |
836 | |
837 g_hash_table_insert(media->priv->participants, g_strdup(name), participant); | |
838 | |
839 return participant; | |
840 } | |
841 | |
842 static PurpleMediaStream * | |
843 purple_media_insert_stream(PurpleMediaSession *session, const gchar *name, FsStream *stream) | |
844 { | |
845 PurpleMediaStream *media_stream; | |
846 | |
847 g_return_val_if_fail(session != NULL, NULL); | |
848 | |
849 media_stream = g_new0(PurpleMediaStream, 1); | |
850 media_stream->stream = stream; | |
851 media_stream->participant = g_strdup(name); | |
852 media_stream->session = session; | |
853 | |
854 session->media->priv->streams = | |
855 g_list_append(session->media->priv->streams, media_stream); | |
856 | |
857 return media_stream; | |
858 } | |
859 | |
860 static void | |
861 purple_media_insert_local_candidate(PurpleMediaSession *session, const gchar *name, | |
862 FsCandidate *candidate) | |
863 { | |
864 PurpleMediaStream *stream; | |
865 | |
866 g_return_if_fail(session != NULL); | |
867 | |
868 stream = purple_media_get_stream(session->media, session->id, name); | |
869 stream->local_candidates = g_list_append(stream->local_candidates, candidate); | |
870 } | |
871 #endif | |
872 | |
873 GList * | |
874 purple_media_get_session_ids(PurpleMedia *media) | |
875 { | |
876 #ifdef USE_VV | |
877 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
878 return media->priv->sessions != NULL ? | |
879 g_hash_table_get_keys(media->priv->sessions) : NULL; | |
880 #else | |
881 return NULL; | |
882 #endif | |
883 } | |
884 | |
885 #ifdef USE_VV | |
886 static void | |
887 purple_media_set_src(PurpleMedia *media, const gchar *sess_id, GstElement *src) | |
888 { | |
889 PurpleMediaSession *session; | |
890 GstPad *sinkpad; | |
891 GstPad *srcpad; | |
892 | |
893 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
894 g_return_if_fail(GST_IS_ELEMENT(src)); | |
895 | |
896 session = purple_media_get_session(media, sess_id); | |
897 | |
898 if (session == NULL) { | |
899 purple_debug_warning("media", "purple_media_set_src: trying" | |
900 " to set src on non-existent session\n"); | |
901 return; | |
902 } | |
903 | |
904 if (session->src) | |
905 gst_object_unref(session->src); | |
906 session->src = src; | |
907 gst_element_set_locked_state(session->src, TRUE); | |
908 | |
909 session->tee = gst_element_factory_make("tee", NULL); | |
910 gst_bin_add(GST_BIN(session->media->priv->confbin), session->tee); | |
911 | |
912 /* This supposedly isn't necessary, but it silences some warnings */ | |
913 if (GST_ELEMENT_PARENT(session->media->priv->confbin) | |
914 == GST_ELEMENT_PARENT(session->src)) { | |
915 GstPad *pad = gst_element_get_static_pad(session->tee, "sink"); | |
916 GstPad *ghost = gst_ghost_pad_new(NULL, pad); | |
917 gst_object_unref(pad); | |
918 gst_pad_set_active(ghost, TRUE); | |
919 gst_element_add_pad(session->media->priv->confbin, ghost); | |
920 } | |
921 | |
922 gst_element_set_state(session->tee, GST_STATE_PLAYING); | |
923 gst_element_link(session->src, session->media->priv->confbin); | |
924 | |
925 g_object_get(session->session, "sink-pad", &sinkpad, NULL); | |
926 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
927 gchar *name = g_strdup_printf("volume_%s", session->id); | |
928 GstElement *level; | |
929 GstElement *volume = gst_element_factory_make("volume", name); | |
930 double input_volume = purple_prefs_get_int( | |
931 "/purple/media/audio/volume/input")/10.0; | |
932 g_free(name); | |
933 name = g_strdup_printf("sendlevel_%s", session->id); | |
934 level = gst_element_factory_make("level", name); | |
935 g_free(name); | |
936 gst_bin_add(GST_BIN(session->media->priv->confbin), volume); | |
937 gst_bin_add(GST_BIN(session->media->priv->confbin), level); | |
938 gst_element_set_state(level, GST_STATE_PLAYING); | |
939 gst_element_set_state(volume, GST_STATE_PLAYING); | |
940 gst_element_link(volume, level); | |
941 gst_element_link(session->tee, volume); | |
942 srcpad = gst_element_get_static_pad(level, "src"); | |
943 g_object_set(volume, "volume", input_volume, NULL); | |
944 } else { | |
945 srcpad = gst_element_get_request_pad(session->tee, "src%d"); | |
946 } | |
947 purple_debug_info("media", "connecting pad: %s\n", | |
948 gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK | |
949 ? "success" : "failure"); | |
950 gst_element_set_locked_state(session->src, FALSE); | |
951 gst_object_unref(session->src); | |
952 } | |
953 #endif | |
954 | |
955 #ifdef USE_GSTREAMER | |
956 GstElement * | |
957 purple_media_get_src(PurpleMedia *media, const gchar *sess_id) | |
958 { | |
959 #ifdef USE_VV | |
960 PurpleMediaSession *session; | |
961 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
962 session = purple_media_get_session(media, sess_id); | |
963 return (session != NULL) ? session->src : NULL; | |
964 #else | |
965 return NULL; | |
966 #endif | |
967 } | |
968 #endif /* USE_GSTREAMER */ | |
969 | |
970 #ifdef USE_VV | |
971 static PurpleMediaSession * | |
972 purple_media_session_from_fs_stream(PurpleMedia *media, FsStream *stream) | |
973 { | |
974 FsSession *fssession; | |
975 GList *values; | |
976 | |
977 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
978 g_return_val_if_fail(FS_IS_STREAM(stream), NULL); | |
979 | |
980 g_object_get(stream, "session", &fssession, NULL); | |
981 | |
982 values = g_hash_table_get_values(media->priv->sessions); | |
983 | |
984 for (; values; values = g_list_delete_link(values, values)) { | |
985 PurpleMediaSession *session = values->data; | |
986 | |
987 if (session->session == fssession) { | |
988 g_list_free(values); | |
989 g_object_unref(fssession); | |
990 return session; | |
991 } | |
992 } | |
993 | |
994 g_object_unref(fssession); | |
995 return NULL; | |
996 } | |
997 | |
998 static gboolean | |
999 media_bus_call(GstBus *bus, GstMessage *msg, PurpleMedia *media) | |
1000 { | |
1001 switch(GST_MESSAGE_TYPE(msg)) { | |
1002 case GST_MESSAGE_ELEMENT: { | |
1003 if (g_signal_has_handler_pending(media, | |
1004 purple_media_signals[LEVEL], 0, FALSE) | |
1005 && gst_structure_has_name( | |
1006 gst_message_get_structure(msg), "level")) { | |
1007 GstElement *src = GST_ELEMENT(GST_MESSAGE_SRC(msg)); | |
1008 gchar *name; | |
1009 gchar *participant = NULL; | |
1010 PurpleMediaSession *session = NULL; | |
1011 gdouble rms_db; | |
1012 gdouble percent; | |
1013 const GValue *list; | |
1014 const GValue *value; | |
1015 | |
1016 if (!PURPLE_IS_MEDIA(media) || | |
1017 GST_ELEMENT_PARENT(src) != | |
1018 media->priv->confbin) | |
1019 break; | |
1020 | |
1021 name = gst_element_get_name(src); | |
1022 if (!strncmp(name, "sendlevel_", 10)) { | |
1023 session = purple_media_get_session( | |
1024 media, name+10); | |
1025 } else { | |
1026 GList *iter = media->priv->streams; | |
1027 for (; iter; iter = g_list_next(iter)) { | |
1028 PurpleMediaStream *stream = iter->data; | |
1029 if (stream->level == src) { | |
1030 session = stream->session; | |
1031 participant = stream->participant; | |
1032 break; | |
1033 } | |
1034 } | |
1035 } | |
1036 g_free(name); | |
1037 if (!session) | |
1038 break; | |
1039 | |
1040 list = gst_structure_get_value( | |
1041 gst_message_get_structure(msg), "rms"); | |
1042 value = gst_value_list_get_value(list, 0); | |
1043 rms_db = g_value_get_double(value); | |
1044 percent = pow(10, rms_db / 20) * 5; | |
1045 if(percent > 1.0) | |
1046 percent = 1.0; | |
1047 | |
1048 g_signal_emit(media, purple_media_signals[LEVEL], | |
1049 0, session->id, participant, percent); | |
1050 break; | |
1051 } | |
1052 if (!FS_IS_CONFERENCE(GST_MESSAGE_SRC(msg)) || | |
1053 !PURPLE_IS_MEDIA(media) || | |
1054 media->priv->conference != | |
1055 FS_CONFERENCE(GST_MESSAGE_SRC(msg))) | |
1056 break; | |
1057 | |
1058 if (gst_structure_has_name(msg->structure, "farsight-error")) { | |
1059 FsError error_no; | |
1060 gst_structure_get_enum(msg->structure, "error-no", | |
1061 FS_TYPE_ERROR, (gint*)&error_no); | |
1062 switch (error_no) { | |
1063 case FS_ERROR_NO_CODECS: | |
1064 purple_media_error(media, _("No codecs found. Install some GStreamer codecs found in GStreamer plugins packages.")); | |
1065 purple_media_end(media, NULL, NULL); | |
1066 break; | |
1067 case FS_ERROR_NO_CODECS_LEFT: | |
1068 purple_media_error(media, _("No codecs left. Your codec preferences in fs-codecs.conf are too strict.")); | |
1069 purple_media_end(media, NULL, NULL); | |
1070 break; | |
1071 case FS_ERROR_UNKNOWN_CNAME: | |
1072 /* | |
1073 * Unknown CName is only a problem for the | |
1074 * multicast transmitter which isn't used. | |
1075 * It is also deprecated. | |
1076 */ | |
1077 break; | |
1078 default: | |
1079 purple_debug_error("media", "farsight-error: %i: %s\n", error_no, | |
1080 gst_structure_get_string(msg->structure, "error-msg")); | |
1081 break; | |
1082 } | |
1083 | |
1084 if (FS_ERROR_IS_FATAL(error_no)) { | |
1085 purple_media_error(media, _("A non-recoverable Farsight2 error has occurred.")); | |
1086 purple_media_end(media, NULL, NULL); | |
1087 } | |
1088 } else if (gst_structure_has_name(msg->structure, | |
1089 "farsight-new-local-candidate")) { | |
1090 FsStream *stream = g_value_get_object(gst_structure_get_value(msg->structure, "stream")); | |
1091 FsCandidate *local_candidate = g_value_get_boxed(gst_structure_get_value(msg->structure, "candidate")); | |
1092 PurpleMediaSession *session = purple_media_session_from_fs_stream(media, stream); | |
1093 purple_media_new_local_candidate_cb(stream, local_candidate, session); | |
1094 } else if (gst_structure_has_name(msg->structure, | |
1095 "farsight-local-candidates-prepared")) { | |
1096 FsStream *stream = g_value_get_object(gst_structure_get_value(msg->structure, "stream")); | |
1097 PurpleMediaSession *session = purple_media_session_from_fs_stream(media, stream); | |
1098 purple_media_candidates_prepared_cb(stream, session); | |
1099 } else if (gst_structure_has_name(msg->structure, | |
1100 "farsight-new-active-candidate-pair")) { | |
1101 FsStream *stream = g_value_get_object(gst_structure_get_value(msg->structure, "stream")); | |
1102 FsCandidate *local_candidate = g_value_get_boxed(gst_structure_get_value(msg->structure, "local-candidate")); | |
1103 FsCandidate *remote_candidate = g_value_get_boxed(gst_structure_get_value(msg->structure, "remote-candidate")); | |
1104 PurpleMediaSession *session = purple_media_session_from_fs_stream(media, stream); | |
1105 purple_media_candidate_pair_established_cb(stream, local_candidate, remote_candidate, session); | |
1106 } else if (gst_structure_has_name(msg->structure, | |
1107 "farsight-recv-codecs-changed")) { | |
1108 GList *codecs = g_value_get_boxed(gst_structure_get_value(msg->structure, "codecs")); | |
1109 FsCodec *codec = codecs->data; | |
1110 purple_debug_info("media", "farsight-recv-codecs-changed: %s\n", codec->encoding_name); | |
1111 | |
1112 } else if (gst_structure_has_name(msg->structure, | |
1113 "farsight-component-state-changed")) { | |
1114 FsStreamState fsstate = g_value_get_enum(gst_structure_get_value(msg->structure, "state")); | |
1115 guint component = g_value_get_uint(gst_structure_get_value(msg->structure, "component")); | |
1116 const gchar *state; | |
1117 switch (fsstate) { | |
1118 case FS_STREAM_STATE_FAILED: | |
1119 state = "FAILED"; | |
1120 break; | |
1121 case FS_STREAM_STATE_DISCONNECTED: | |
1122 state = "DISCONNECTED"; | |
1123 break; | |
1124 case FS_STREAM_STATE_GATHERING: | |
1125 state = "GATHERING"; | |
1126 break; | |
1127 case FS_STREAM_STATE_CONNECTING: | |
1128 state = "CONNECTING"; | |
1129 break; | |
1130 case FS_STREAM_STATE_CONNECTED: | |
1131 state = "CONNECTED"; | |
1132 break; | |
1133 case FS_STREAM_STATE_READY: | |
1134 state = "READY"; | |
1135 break; | |
1136 default: | |
1137 state = "UNKNOWN"; | |
1138 break; | |
1139 } | |
1140 purple_debug_info("media", "farsight-component-state-changed: component: %u state: %s\n", component, state); | |
1141 } else if (gst_structure_has_name(msg->structure, | |
1142 "farsight-send-codec-changed")) { | |
1143 FsCodec *codec = g_value_get_boxed(gst_structure_get_value(msg->structure, "codec")); | |
1144 gchar *codec_str = fs_codec_to_string(codec); | |
1145 purple_debug_info("media", "farsight-send-codec-changed: codec: %s\n", codec_str); | |
1146 g_free(codec_str); | |
1147 } else if (gst_structure_has_name(msg->structure, | |
1148 "farsight-codecs-changed")) { | |
1149 GList *sessions = g_hash_table_get_values(PURPLE_MEDIA(media)->priv->sessions); | |
1150 FsSession *fssession = g_value_get_object(gst_structure_get_value(msg->structure, "session")); | |
1151 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
1152 PurpleMediaSession *session = sessions->data; | |
1153 if (session->session == fssession) { | |
1154 gchar *session_id = g_strdup(session->id); | |
1155 g_signal_emit(media, purple_media_signals[CODECS_CHANGED], 0, session_id); | |
1156 g_free(session_id); | |
1157 g_list_free(sessions); | |
1158 break; | |
1159 } | |
1160 } | |
1161 } | |
1162 break; | |
1163 } | |
1164 case GST_MESSAGE_ERROR: { | |
1165 GstElement *element = GST_ELEMENT(GST_MESSAGE_SRC(msg)); | |
1166 GstElement *lastElement = NULL; | |
1167 while (!GST_IS_PIPELINE(element)) { | |
1168 if (element == media->priv->confbin) { | |
1169 purple_media_error(media, _("Conference error")); | |
1170 purple_media_end(media, NULL, NULL); | |
1171 break; | |
1172 } | |
1173 lastElement = element; | |
1174 element = GST_ELEMENT_PARENT(element); | |
1175 } | |
1176 if (GST_IS_PIPELINE(element)) { | |
1177 GList *sessions = g_hash_table_get_values(media->priv->sessions); | |
1178 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
1179 PurpleMediaSession *session = sessions->data; | |
1180 | |
1181 if (session->src == lastElement) { | |
1182 if (session->type & PURPLE_MEDIA_AUDIO) | |
1183 purple_media_error(media, _("Error with your microphone")); | |
1184 else | |
1185 purple_media_error(media, _("Error with your webcam")); | |
1186 purple_media_end(media, NULL, NULL); | |
1187 break; | |
1188 } | |
1189 } | |
1190 g_list_free(sessions); | |
1191 } | |
1192 } | |
1193 default: | |
1194 break; | |
1195 } | |
1196 | |
1197 return TRUE; | |
1198 } | |
1199 #endif | |
1200 | |
1201 PurpleAccount * | |
1202 purple_media_get_account(PurpleMedia *media) | |
1203 { | |
1204 #ifdef USE_VV | |
1205 PurpleAccount *account; | |
1206 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1207 g_object_get(G_OBJECT(media), "account", &account, NULL); | |
1208 return account; | |
1209 #else | |
1210 return NULL; | |
1211 #endif | |
1212 } | |
1213 | |
1214 gpointer | |
1215 purple_media_get_prpl_data(PurpleMedia *media) | |
1216 { | |
1217 #ifdef USE_VV | |
1218 gpointer prpl_data; | |
1219 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1220 g_object_get(G_OBJECT(media), "prpl-data", &prpl_data, NULL); | |
1221 return prpl_data; | |
1222 #else | |
1223 return NULL; | |
1224 #endif | |
1225 } | |
1226 | |
1227 void | |
1228 purple_media_set_prpl_data(PurpleMedia *media, gpointer prpl_data) | |
1229 { | |
1230 #ifdef USE_VV | |
1231 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1232 g_object_set(G_OBJECT(media), "prpl-data", prpl_data, NULL); | |
1233 #endif | |
1234 } | |
1235 | |
1236 void | |
1237 purple_media_error(PurpleMedia *media, const gchar *error, ...) | |
1238 { | |
1239 #ifdef USE_VV | |
1240 va_list args; | |
1241 gchar *message; | |
1242 | |
1243 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1244 | |
1245 va_start(args, error); | |
1246 message = g_strdup_vprintf(error, args); | |
1247 va_end(args); | |
1248 | |
1249 purple_debug_error("media", "%s\n", message); | |
1250 g_signal_emit(media, purple_media_signals[S_ERROR], 0, message); | |
1251 | |
1252 g_free(message); | |
1253 #endif | |
1254 } | |
1255 | |
1256 void | |
1257 purple_media_end(PurpleMedia *media, | |
1258 const gchar *session_id, const gchar *participant) | |
1259 { | |
1260 #ifdef USE_VV | |
1261 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1262 if (session_id == NULL && participant == NULL) { | |
1263 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1264 0, PURPLE_MEDIA_STATE_END, | |
1265 NULL, NULL); | |
1266 g_object_unref(media); | |
1267 } | |
1268 #endif | |
1269 } | |
1270 | |
1271 void | |
1272 purple_media_stream_info(PurpleMedia *media, PurpleMediaInfoType type, | |
1273 const gchar *session_id, const gchar *participant, | |
1274 gboolean local) | |
1275 { | |
1276 #ifdef USE_VV | |
1277 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1278 | |
1279 if (type == PURPLE_MEDIA_INFO_ACCEPT) { | |
1280 GList *streams; | |
1281 | |
1282 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1283 | |
1284 streams = purple_media_get_streams(media, | |
1285 session_id, participant); | |
1286 | |
1287 for (; streams; streams = | |
1288 g_list_delete_link(streams, streams)) { | |
1289 PurpleMediaStream *stream = streams->data; | |
1290 g_object_set(G_OBJECT(stream->stream), "direction", | |
1291 purple_media_to_fs_stream_direction( | |
1292 stream->session->type), NULL); | |
1293 stream->accepted = TRUE; | |
1294 | |
1295 if (stream->remote_candidates != NULL) { | |
1296 GError *err = NULL; | |
1297 fs_stream_set_remote_candidates(stream->stream, | |
1298 stream->remote_candidates, &err); | |
1299 | |
1300 if (err) { | |
1301 purple_debug_error("media", "Error adding remote" | |
1302 " candidates: %s\n", err->message); | |
1303 g_error_free(err); | |
1304 } | |
1305 } | |
1306 } | |
1307 } else if (local == TRUE && (type == PURPLE_MEDIA_INFO_MUTE || | |
1308 type == PURPLE_MEDIA_INFO_UNMUTE)) { | |
1309 GList *sessions; | |
1310 gboolean active = (type == PURPLE_MEDIA_INFO_MUTE); | |
1311 | |
1312 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1313 | |
1314 if (session_id == NULL) | |
1315 sessions = g_hash_table_get_values( | |
1316 media->priv->sessions); | |
1317 else | |
1318 sessions = g_list_prepend(NULL, | |
1319 purple_media_get_session( | |
1320 media, session_id)); | |
1321 | |
1322 purple_debug_info("media", "Turning mute %s\n", | |
1323 active ? "on" : "off"); | |
1324 | |
1325 for (; sessions; sessions = g_list_delete_link( | |
1326 sessions, sessions)) { | |
1327 PurpleMediaSession *session = sessions->data; | |
1328 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
1329 gchar *name = g_strdup_printf("volume_%s", | |
1330 session->id); | |
1331 GstElement *volume = gst_bin_get_by_name( | |
1332 GST_BIN(session->media-> | |
1333 priv->confbin), name); | |
1334 g_free(name); | |
1335 g_object_set(volume, "mute", active, NULL); | |
1336 } | |
1337 } | |
1338 } else if (local == TRUE && (type == PURPLE_MEDIA_INFO_PAUSE || | |
1339 type == PURPLE_MEDIA_INFO_UNPAUSE)) { | |
1340 gboolean active = (type == PURPLE_MEDIA_INFO_PAUSE); | |
1341 GList *streams = purple_media_get_streams(media, | |
1342 session_id, participant); | |
1343 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
1344 PurpleMediaStream *stream = streams->data; | |
1345 if (stream->session->type & PURPLE_MEDIA_SEND_VIDEO) { | |
1346 g_object_set(stream->stream, "direction", | |
1347 purple_media_to_fs_stream_direction( | |
1348 stream->session->type & ((active) ? | |
1349 ~PURPLE_MEDIA_SEND_VIDEO : | |
1350 PURPLE_MEDIA_VIDEO)), NULL); | |
1351 } | |
1352 } | |
1353 } | |
1354 | |
1355 g_signal_emit(media, purple_media_signals[STREAM_INFO], | |
1356 0, type, session_id, participant, local); | |
1357 | |
1358 if (type == PURPLE_MEDIA_INFO_HANGUP || | |
1359 type == PURPLE_MEDIA_INFO_REJECT) { | |
1360 purple_media_end(media, session_id, participant); | |
1361 } | |
1362 #endif | |
1363 } | |
1364 | |
1365 #ifdef USE_VV | |
1366 static void | |
1367 purple_media_new_local_candidate_cb(FsStream *stream, | |
1368 FsCandidate *local_candidate, | |
1369 PurpleMediaSession *session) | |
1370 { | |
1371 gchar *name; | |
1372 FsParticipant *participant; | |
1373 PurpleMediaCandidate *candidate; | |
1374 | |
1375 g_return_if_fail(FS_IS_STREAM(stream)); | |
1376 g_return_if_fail(session != NULL); | |
1377 | |
1378 purple_debug_info("media", "got new local candidate: %s\n", local_candidate->foundation); | |
1379 g_object_get(stream, "participant", &participant, NULL); | |
1380 g_object_get(participant, "cname", &name, NULL); | |
1381 g_object_unref(participant); | |
1382 | |
1383 purple_media_insert_local_candidate(session, name, fs_candidate_copy(local_candidate)); | |
1384 | |
1385 candidate = purple_media_candidate_from_fs(local_candidate); | |
1386 g_signal_emit(session->media, purple_media_signals[NEW_CANDIDATE], | |
1387 0, session->id, name, candidate); | |
1388 g_object_unref(candidate); | |
1389 | |
1390 g_free(name); | |
1391 } | |
1392 | |
1393 static void | |
1394 purple_media_candidates_prepared_cb(FsStream *stream, PurpleMediaSession *session) | |
1395 { | |
1396 gchar *name; | |
1397 FsParticipant *participant; | |
1398 PurpleMediaStream *stream_data; | |
1399 | |
1400 g_return_if_fail(FS_IS_STREAM(stream)); | |
1401 g_return_if_fail(session != NULL); | |
1402 | |
1403 g_object_get(stream, "participant", &participant, NULL); | |
1404 g_object_get(participant, "cname", &name, NULL); | |
1405 g_object_unref(participant); | |
1406 | |
1407 stream_data = purple_media_get_stream(session->media, session->id, name); | |
1408 stream_data->candidates_prepared = TRUE; | |
1409 | |
1410 g_signal_emit(session->media, | |
1411 purple_media_signals[CANDIDATES_PREPARED], | |
1412 0, session->id, name); | |
1413 | |
1414 g_free(name); | |
1415 } | |
1416 | |
1417 /* callback called when a pair of transport candidates (local and remote) | |
1418 * has been established */ | |
1419 static void | |
1420 purple_media_candidate_pair_established_cb(FsStream *fsstream, | |
1421 FsCandidate *native_candidate, | |
1422 FsCandidate *remote_candidate, | |
1423 PurpleMediaSession *session) | |
1424 { | |
1425 gchar *name; | |
1426 FsParticipant *participant; | |
1427 PurpleMediaStream *stream; | |
1428 GList *iter; | |
1429 | |
1430 g_return_if_fail(FS_IS_STREAM(fsstream)); | |
1431 g_return_if_fail(session != NULL); | |
1432 | |
1433 g_object_get(fsstream, "participant", &participant, NULL); | |
1434 g_object_get(participant, "cname", &name, NULL); | |
1435 g_object_unref(participant); | |
1436 | |
1437 stream = purple_media_get_stream(session->media, session->id, name); | |
1438 | |
1439 iter = stream->active_local_candidates; | |
1440 for(; iter; iter = g_list_next(iter)) { | |
1441 FsCandidate *c = iter->data; | |
1442 if (native_candidate->component_id == c->component_id) { | |
1443 fs_candidate_destroy(c); | |
1444 stream->active_local_candidates = | |
1445 g_list_delete_link(iter, iter); | |
1446 stream->active_local_candidates = g_list_prepend( | |
1447 stream->active_local_candidates, | |
1448 fs_candidate_copy(native_candidate)); | |
1449 break; | |
1450 } | |
1451 } | |
1452 if (iter == NULL) | |
1453 stream->active_local_candidates = g_list_prepend( | |
1454 stream->active_local_candidates, | |
1455 fs_candidate_copy(native_candidate)); | |
1456 | |
1457 iter = stream->active_remote_candidates; | |
1458 for(; iter; iter = g_list_next(iter)) { | |
1459 FsCandidate *c = iter->data; | |
1460 if (native_candidate->component_id == c->component_id) { | |
1461 fs_candidate_destroy(c); | |
1462 stream->active_remote_candidates = | |
1463 g_list_delete_link(iter, iter); | |
1464 stream->active_remote_candidates = g_list_prepend( | |
1465 stream->active_remote_candidates, | |
1466 fs_candidate_copy(remote_candidate)); | |
1467 break; | |
1468 } | |
1469 } | |
1470 if (iter == NULL) | |
1471 stream->active_remote_candidates = g_list_prepend( | |
1472 stream->active_remote_candidates, | |
1473 fs_candidate_copy(remote_candidate)); | |
1474 | |
1475 purple_debug_info("media", "candidate pair established\n"); | |
1476 } | |
1477 | |
1478 static gboolean | |
1479 purple_media_connected_cb(PurpleMediaStream *stream) | |
1480 { | |
1481 g_return_val_if_fail(stream != NULL, FALSE); | |
1482 | |
1483 stream->connected_cb_id = 0; | |
1484 | |
1485 purple_media_manager_create_output_window( | |
1486 stream->session->media->priv->manager, | |
1487 stream->session->media, | |
1488 stream->session->id, stream->participant); | |
1489 | |
1490 g_signal_emit(stream->session->media, | |
1491 purple_media_signals[STATE_CHANGED], | |
1492 0, PURPLE_MEDIA_STATE_CONNECTED, | |
1493 stream->session->id, stream->participant); | |
1494 return FALSE; | |
1495 } | |
1496 | |
1497 static void | |
1498 purple_media_src_pad_added_cb(FsStream *fsstream, GstPad *srcpad, | |
1499 FsCodec *codec, PurpleMediaStream *stream) | |
1500 { | |
1501 PurpleMediaPrivate *priv; | |
1502 GstPad *sinkpad; | |
1503 | |
1504 g_return_if_fail(FS_IS_STREAM(fsstream)); | |
1505 g_return_if_fail(stream != NULL); | |
1506 | |
1507 priv = stream->session->media->priv; | |
1508 | |
1509 if (stream->src == NULL) { | |
1510 GstElement *sink = NULL; | |
1511 | |
1512 if (codec->media_type == FS_MEDIA_TYPE_AUDIO) { | |
1513 GstElement *queue = NULL; | |
1514 double output_volume = purple_prefs_get_int( | |
1515 "/purple/media/audio/volume/output")/10.0; | |
1516 /* | |
1517 * Should this instead be: | |
1518 * audioconvert ! audioresample ! liveadder ! | |
1519 * audioresample ! audioconvert ! realsink | |
1520 */ | |
1521 queue = gst_element_factory_make("queue", NULL); | |
1522 stream->volume = gst_element_factory_make( | |
1523 "volume", NULL); | |
1524 g_object_set(stream->volume, "volume", | |
1525 output_volume, NULL); | |
1526 stream->level = gst_element_factory_make( | |
1527 "level", NULL); | |
1528 stream->src = gst_element_factory_make( | |
1529 "liveadder", NULL); | |
1530 sink = purple_media_manager_get_element(priv->manager, | |
1531 PURPLE_MEDIA_RECV_AUDIO, | |
1532 stream->session->media, | |
1533 stream->session->id, | |
1534 stream->participant); | |
1535 gst_bin_add(GST_BIN(priv->confbin), queue); | |
1536 gst_bin_add(GST_BIN(priv->confbin), stream->volume); | |
1537 gst_bin_add(GST_BIN(priv->confbin), stream->level); | |
1538 gst_bin_add(GST_BIN(priv->confbin), sink); | |
1539 gst_element_set_state(sink, GST_STATE_PLAYING); | |
1540 gst_element_set_state(stream->level, GST_STATE_PLAYING); | |
1541 gst_element_set_state(stream->volume, GST_STATE_PLAYING); | |
1542 gst_element_set_state(queue, GST_STATE_PLAYING); | |
1543 gst_element_link(stream->level, sink); | |
1544 gst_element_link(stream->volume, stream->level); | |
1545 gst_element_link(queue, stream->volume); | |
1546 sink = queue; | |
1547 } else if (codec->media_type == FS_MEDIA_TYPE_VIDEO) { | |
1548 stream->src = gst_element_factory_make( | |
1549 "fsfunnel", NULL); | |
1550 sink = gst_element_factory_make( | |
1551 "fakesink", NULL); | |
1552 g_object_set(G_OBJECT(sink), "async", FALSE, NULL); | |
1553 gst_bin_add(GST_BIN(priv->confbin), sink); | |
1554 gst_element_set_state(sink, GST_STATE_PLAYING); | |
1555 } | |
1556 stream->tee = gst_element_factory_make("tee", NULL); | |
1557 gst_bin_add_many(GST_BIN(priv->confbin), | |
1558 stream->src, stream->tee, NULL); | |
1559 gst_element_set_state(stream->tee, GST_STATE_PLAYING); | |
1560 gst_element_set_state(stream->src, GST_STATE_PLAYING); | |
1561 gst_element_link_many(stream->src, stream->tee, sink, NULL); | |
1562 } | |
1563 | |
1564 sinkpad = gst_element_get_request_pad(stream->src, "sink%d"); | |
1565 gst_pad_link(srcpad, sinkpad); | |
1566 gst_object_unref(sinkpad); | |
1567 | |
1568 stream->connected_cb_id = purple_timeout_add(0, | |
1569 (GSourceFunc)purple_media_connected_cb, stream); | |
1570 } | |
1571 | |
1572 static void | |
1573 purple_media_element_added_cb(FsElementAddedNotifier *self, | |
1574 GstBin *bin, GstElement *element, gpointer user_data) | |
1575 { | |
1576 /* | |
1577 * Hack to make H264 work with Gmail video. | |
1578 */ | |
1579 if (!strncmp(GST_ELEMENT_NAME(element), "x264", 4)) { | |
1580 g_object_set(GST_OBJECT(element), "cabac", FALSE, NULL); | |
1581 } | |
1582 } | |
1583 #endif /* USE_VV */ | |
1584 | |
1585 gboolean | |
1586 purple_media_add_stream(PurpleMedia *media, const gchar *sess_id, | |
1587 const gchar *who, PurpleMediaSessionType type, | |
1588 gboolean initiator, const gchar *transmitter, | |
1589 guint num_params, GParameter *params) | |
1590 { | |
1591 #ifdef USE_VV | |
1592 PurpleMediaSession *session; | |
1593 FsParticipant *participant = NULL; | |
1594 PurpleMediaStream *stream = NULL; | |
1595 FsMediaType media_type = purple_media_to_fs_media_type(type); | |
1596 FsStreamDirection type_direction = | |
1597 purple_media_to_fs_stream_direction(type); | |
1598 gboolean is_nice = !strcmp(transmitter, "nice"); | |
1599 | |
1600 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1601 | |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1602 if (!purple_media_backend_add_stream(media->priv->backend, |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1603 sess_id, who, type, initiator, transmitter, |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1604 num_params, params)) { |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1605 purple_debug_error("media", "Error adding stream.\n"); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1606 return FALSE; |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1607 } |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1608 |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1609 /* XXX: Temporary call while integrating with backend */ |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1610 if (media->priv->conference == NULL) { |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1611 GstBus *bus; |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1612 media->priv->conference = |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1613 purple_media_backend_fs2_get_conference( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1614 PURPLE_MEDIA_BACKEND_FS2( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1615 media->priv->backend)); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1616 media->priv->confbin = GST_ELEMENT_PARENT( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1617 media->priv->conference); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1618 bus = gst_pipeline_get_bus(GST_PIPELINE( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1619 purple_media_manager_get_pipeline( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1620 purple_media_manager_get()))); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1621 g_signal_connect(G_OBJECT(bus), "message", |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1622 G_CALLBACK(media_bus_call), media); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1623 gst_object_unref(bus); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1624 } |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1625 |
29534 | 1626 session = purple_media_get_session(media, sess_id); |
1627 | |
1628 if (!session) { | |
1629 GError *err = NULL; | |
1630 GList *codec_conf = NULL, *iter = NULL; | |
1631 gchar *filename = NULL; | |
1632 PurpleMediaSessionType session_type; | |
1633 GstElement *src = NULL; | |
1634 | |
1635 session = g_new0(PurpleMediaSession, 1); | |
1636 | |
1637 session->session = fs_conference_new_session( | |
1638 media->priv->conference, media_type, &err); | |
1639 | |
1640 if (err != NULL) { | |
1641 purple_media_error(media, _("Error creating session: %s"), err->message); | |
1642 g_error_free(err); | |
1643 g_free(session); | |
1644 return FALSE; | |
1645 } | |
1646 | |
1647 filename = g_build_filename(purple_user_dir(), "fs-codec.conf", NULL); | |
1648 codec_conf = fs_codec_list_from_keyfile(filename, &err); | |
1649 g_free(filename); | |
1650 | |
1651 if (err != NULL) { | |
1652 if (err->code == 4) | |
1653 purple_debug_info("media", "Couldn't read " | |
1654 "fs-codec.conf: %s\n", | |
1655 err->message); | |
1656 else | |
1657 purple_debug_error("media", "Error reading " | |
1658 "fs-codec.conf: %s\n", | |
1659 err->message); | |
1660 g_error_free(err); | |
1661 } | |
1662 | |
1663 /* | |
1664 * Add SPEEX if the configuration file doesn't exist or | |
1665 * there isn't a speex entry. | |
1666 */ | |
1667 for (iter = codec_conf; iter; iter = g_list_next(iter)) { | |
1668 FsCodec *codec = iter->data; | |
1669 if (!g_ascii_strcasecmp(codec->encoding_name, "speex")) | |
1670 break; | |
1671 } | |
1672 | |
1673 if (iter == NULL) { | |
1674 codec_conf = g_list_prepend(codec_conf, | |
1675 fs_codec_new(FS_CODEC_ID_ANY, | |
1676 "SPEEX", FS_MEDIA_TYPE_AUDIO, 8000)); | |
1677 codec_conf = g_list_prepend(codec_conf, | |
1678 fs_codec_new(FS_CODEC_ID_ANY, | |
1679 "SPEEX", FS_MEDIA_TYPE_AUDIO, 16000)); | |
1680 } | |
1681 | |
1682 fs_session_set_codec_preferences(session->session, codec_conf, NULL); | |
1683 | |
1684 /* | |
1685 * Removes a 5-7 second delay before | |
1686 * receiving the src-pad-added signal. | |
1687 * Only works for non-multicast FsRtpSessions. | |
1688 */ | |
1689 if (is_nice || !strcmp(transmitter, "rawudp")) | |
1690 g_object_set(G_OBJECT(session->session), | |
1691 "no-rtcp-timeout", 0, NULL); | |
1692 | |
1693 /* | |
1694 * Hack to make x264 work with Gmail video. | |
1695 */ | |
1696 if (is_nice && !strcmp(sess_id, "google-video")) { | |
1697 FsElementAddedNotifier *notifier = | |
1698 fs_element_added_notifier_new(); | |
1699 g_signal_connect(G_OBJECT(notifier), "element-added", | |
1700 G_CALLBACK(purple_media_element_added_cb), | |
1701 stream); | |
1702 fs_element_added_notifier_add(notifier, | |
1703 GST_BIN(media->priv->conference)); | |
1704 } | |
1705 | |
1706 fs_codec_list_destroy(codec_conf); | |
1707 | |
1708 session->id = g_strdup(sess_id); | |
1709 session->media = media; | |
1710 session->type = type; | |
1711 session->initiator = initiator; | |
1712 | |
1713 purple_media_add_session(media, session); | |
1714 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1715 0, PURPLE_MEDIA_STATE_NEW, | |
1716 session->id, NULL); | |
1717 | |
1718 if (type_direction & FS_DIRECTION_SEND) { | |
1719 session_type = purple_media_from_fs(media_type, | |
1720 FS_DIRECTION_SEND); | |
1721 src = purple_media_manager_get_element( | |
1722 media->priv->manager, session_type, | |
1723 media, session->id, who); | |
1724 if (!GST_IS_ELEMENT(src)) { | |
1725 purple_debug_error("media", | |
1726 "Error creating src for session %s\n", | |
1727 session->id); | |
1728 purple_media_end(media, session->id, NULL); | |
1729 return FALSE; | |
1730 } | |
1731 | |
1732 purple_media_set_src(media, session->id, src); | |
1733 gst_element_set_state(session->src, GST_STATE_PLAYING); | |
1734 purple_media_manager_create_output_window( | |
1735 media->priv->manager, | |
1736 session->media, | |
1737 session->id, NULL); | |
1738 } | |
1739 } | |
1740 | |
1741 if (!(participant = purple_media_add_participant(media, who))) { | |
1742 purple_media_remove_session(media, session); | |
1743 g_free(session); | |
1744 return FALSE; | |
1745 } else { | |
1746 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1747 0, PURPLE_MEDIA_STATE_NEW, | |
1748 NULL, who); | |
1749 } | |
1750 | |
1751 stream = purple_media_get_stream(media, sess_id, who); | |
1752 | |
1753 if (!stream) { | |
1754 GError *err = NULL; | |
1755 FsStream *fsstream = NULL; | |
1756 const gchar *stun_ip = purple_network_get_stun_ip(); | |
1757 const gchar *turn_ip = purple_network_get_turn_ip(); | |
1758 | |
1759 if (stun_ip || turn_ip) { | |
1760 guint new_num_params = | |
1761 (stun_ip && is_nice) && turn_ip ? | |
1762 num_params + 2 : num_params + 1; | |
1763 guint next_param_index = num_params; | |
1764 GParameter *param = g_new0(GParameter, new_num_params); | |
1765 memcpy(param, params, sizeof(GParameter) * num_params); | |
1766 | |
1767 if (stun_ip) { | |
1768 purple_debug_info("media", | |
1769 "setting property stun-ip on new stream: %s\n", stun_ip); | |
1770 | |
1771 param[next_param_index].name = "stun-ip"; | |
1772 g_value_init(¶m[next_param_index].value, G_TYPE_STRING); | |
1773 g_value_set_string(¶m[next_param_index].value, stun_ip); | |
1774 next_param_index++; | |
1775 } | |
1776 | |
1777 if (turn_ip && is_nice) { | |
1778 GValueArray *relay_info = g_value_array_new(0); | |
1779 GValue value; | |
1780 gint turn_port = | |
1781 purple_prefs_get_int("/purple/network/turn_port"); | |
1782 const gchar *username = | |
1783 purple_prefs_get_string("/purple/network/turn_username"); | |
1784 const gchar *password = | |
1785 purple_prefs_get_string("/purple/network/turn_password"); | |
1786 GstStructure *turn_setup = gst_structure_new("relay-info", | |
1787 "ip", G_TYPE_STRING, turn_ip, | |
1788 "port", G_TYPE_UINT, turn_port, | |
1789 "username", G_TYPE_STRING, username, | |
1790 "password", G_TYPE_STRING, password, | |
1791 NULL); | |
1792 | |
1793 if (turn_setup) { | |
1794 memset(&value, 0, sizeof(GValue)); | |
1795 g_value_init(&value, GST_TYPE_STRUCTURE); | |
1796 gst_value_set_structure(&value, turn_setup); | |
1797 relay_info = g_value_array_append(relay_info, &value); | |
1798 gst_structure_free(turn_setup); | |
1799 | |
1800 purple_debug_info("media", | |
1801 "setting property relay-info on new stream\n"); | |
1802 param[next_param_index].name = "relay-info"; | |
1803 g_value_init(¶m[next_param_index].value, | |
1804 G_TYPE_VALUE_ARRAY); | |
1805 g_value_set_boxed(¶m[next_param_index].value, | |
1806 relay_info); | |
1807 g_value_array_free(relay_info); | |
1808 } else { | |
1809 purple_debug_error("media", "Error relay info"); | |
1810 g_object_unref(participant); | |
1811 g_hash_table_remove(media->priv->participants, who); | |
1812 purple_media_remove_session(media, session); | |
1813 g_free(session); | |
1814 return FALSE; | |
1815 } | |
1816 } | |
1817 | |
1818 fsstream = fs_session_new_stream(session->session, | |
1819 participant, type_direction & | |
1820 FS_DIRECTION_RECV, transmitter, | |
1821 new_num_params, param, &err); | |
1822 g_free(param); | |
1823 } else { | |
1824 fsstream = fs_session_new_stream(session->session, | |
1825 participant, type_direction & | |
1826 FS_DIRECTION_RECV, transmitter, | |
1827 num_params, params, &err); | |
1828 } | |
1829 | |
1830 if (fsstream == NULL) { | |
1831 purple_debug_error("media", | |
1832 "Error creating stream: %s\n", | |
1833 err && err->message ? | |
1834 err->message : "NULL"); | |
1835 if (err) | |
1836 g_error_free(err); | |
1837 g_object_unref(participant); | |
1838 g_hash_table_remove(media->priv->participants, who); | |
1839 purple_media_remove_session(media, session); | |
1840 g_free(session); | |
1841 return FALSE; | |
1842 } | |
1843 | |
1844 stream = purple_media_insert_stream(session, who, fsstream); | |
1845 stream->initiator = initiator; | |
1846 | |
1847 /* callback for source pad added (new stream source ready) */ | |
1848 g_signal_connect(G_OBJECT(fsstream), | |
1849 "src-pad-added", G_CALLBACK(purple_media_src_pad_added_cb), stream); | |
1850 | |
1851 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1852 0, PURPLE_MEDIA_STATE_NEW, | |
1853 session->id, who); | |
1854 } else { | |
1855 if (purple_media_to_fs_stream_direction(stream->session->type) | |
1856 != type_direction) { | |
1857 /* change direction */ | |
1858 g_object_set(stream->stream, "direction", | |
1859 type_direction, NULL); | |
1860 } | |
1861 } | |
1862 | |
1863 return TRUE; | |
1864 #else | |
1865 return FALSE; | |
1866 #endif /* USE_VV */ | |
1867 } | |
1868 | |
1869 PurpleMediaManager * | |
1870 purple_media_get_manager(PurpleMedia *media) | |
1871 { | |
1872 PurpleMediaManager *ret; | |
1873 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1874 g_object_get(media, "manager", &ret, NULL); | |
1875 return ret; | |
1876 } | |
1877 | |
1878 PurpleMediaSessionType | |
1879 purple_media_get_session_type(PurpleMedia *media, const gchar *sess_id) | |
1880 { | |
1881 #ifdef USE_VV | |
1882 PurpleMediaSession *session; | |
1883 g_return_val_if_fail(PURPLE_IS_MEDIA(media), PURPLE_MEDIA_NONE); | |
1884 session = purple_media_get_session(media, sess_id); | |
1885 return session->type; | |
1886 #else | |
1887 return PURPLE_MEDIA_NONE; | |
1888 #endif | |
1889 } | |
1890 /* XXX: Should wait until codecs-ready is TRUE before using this function */ | |
1891 GList * | |
1892 purple_media_get_codecs(PurpleMedia *media, const gchar *sess_id) | |
1893 { | |
1894 #ifdef USE_VV | |
1895 GList *fscodecs; | |
1896 GList *codecs; | |
1897 PurpleMediaSession *session; | |
1898 | |
1899 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1900 | |
1901 session = purple_media_get_session(media, sess_id); | |
1902 | |
1903 if (session == NULL) | |
1904 return NULL; | |
1905 | |
1906 g_object_get(G_OBJECT(session->session), | |
1907 "codecs", &fscodecs, NULL); | |
1908 codecs = purple_media_codec_list_from_fs(fscodecs); | |
1909 fs_codec_list_destroy(fscodecs); | |
1910 return codecs; | |
1911 #else | |
1912 return NULL; | |
1913 #endif | |
1914 } | |
1915 | |
1916 GList * | |
1917 purple_media_get_local_candidates(PurpleMedia *media, const gchar *sess_id, | |
1918 const gchar *participant) | |
1919 { | |
1920 #ifdef USE_VV | |
1921 PurpleMediaStream *stream; | |
1922 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1923 stream = purple_media_get_stream(media, sess_id, participant); | |
1924 return stream ? purple_media_candidate_list_from_fs( | |
1925 stream->local_candidates) : NULL; | |
1926 #else | |
1927 return NULL; | |
1928 #endif | |
1929 } | |
1930 | |
1931 void | |
1932 purple_media_add_remote_candidates(PurpleMedia *media, const gchar *sess_id, | |
1933 const gchar *participant, | |
1934 GList *remote_candidates) | |
1935 { | |
1936 #ifdef USE_VV | |
1937 PurpleMediaStream *stream; | |
1938 GError *err = NULL; | |
1939 | |
1940 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1941 stream = purple_media_get_stream(media, sess_id, participant); | |
1942 | |
1943 if (stream == NULL) { | |
1944 purple_debug_error("media", | |
1945 "purple_media_add_remote_candidates: " | |
1946 "couldn't find stream %s %s.\n", | |
1947 sess_id ? sess_id : "(null)", | |
1948 participant ? participant : "(null)"); | |
1949 return; | |
1950 } | |
1951 | |
1952 stream->remote_candidates = g_list_concat(stream->remote_candidates, | |
1953 purple_media_candidate_list_to_fs(remote_candidates)); | |
1954 | |
1955 if (stream->accepted == TRUE) { | |
1956 fs_stream_set_remote_candidates(stream->stream, | |
1957 stream->remote_candidates, &err); | |
1958 | |
1959 if (err) { | |
1960 purple_debug_error("media", "Error adding remote" | |
1961 " candidates: %s\n", err->message); | |
1962 g_error_free(err); | |
1963 } | |
1964 } | |
1965 #endif | |
1966 } | |
1967 | |
1968 #if 0 | |
1969 /* | |
1970 * These two functions aren't being used and I'd rather not lock in the API | |
1971 * until they are needed. If they ever are. | |
1972 */ | |
1973 | |
1974 GList * | |
1975 purple_media_get_active_local_candidates(PurpleMedia *media, | |
1976 const gchar *sess_id, const gchar *participant) | |
1977 { | |
1978 #ifdef USE_VV | |
1979 PurpleMediaStream *stream; | |
1980 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1981 stream = purple_media_get_stream(media, sess_id, participant); | |
1982 return purple_media_candidate_list_from_fs( | |
1983 stream->active_local_candidates); | |
1984 #else | |
1985 return NULL; | |
1986 #endif | |
1987 } | |
1988 | |
1989 GList * | |
1990 purple_media_get_active_remote_candidates(PurpleMedia *media, | |
1991 const gchar *sess_id, const gchar *participant) | |
1992 { | |
1993 #ifdef USE_VV | |
1994 PurpleMediaStream *stream; | |
1995 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1996 stream = purple_media_get_stream(media, sess_id, participant); | |
1997 return purple_media_candidate_list_from_fs( | |
1998 stream->active_remote_candidates); | |
1999 #else | |
2000 return NULL; | |
2001 #endif | |
2002 } | |
2003 #endif | |
2004 | |
2005 gboolean | |
2006 purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, | |
2007 const gchar *participant, GList *codecs) | |
2008 { | |
2009 #ifdef USE_VV | |
2010 PurpleMediaStream *stream; | |
2011 FsStream *fsstream; | |
2012 GList *fscodecs; | |
2013 GError *err = NULL; | |
2014 | |
2015 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2016 stream = purple_media_get_stream(media, sess_id, participant); | |
2017 | |
2018 if (stream == NULL) | |
2019 return FALSE; | |
2020 | |
2021 fsstream = stream->stream; | |
2022 fscodecs = purple_media_codec_list_to_fs(codecs); | |
2023 fs_stream_set_remote_codecs(fsstream, fscodecs, &err); | |
2024 fs_codec_list_destroy(fscodecs); | |
2025 | |
2026 if (err) { | |
2027 purple_debug_error("media", "Error setting remote codecs: %s\n", | |
2028 err->message); | |
2029 g_error_free(err); | |
2030 return FALSE; | |
2031 } | |
2032 return TRUE; | |
2033 #else | |
2034 return FALSE; | |
2035 #endif | |
2036 } | |
2037 | |
2038 gboolean | |
2039 purple_media_candidates_prepared(PurpleMedia *media, | |
2040 const gchar *session_id, const gchar *participant) | |
2041 { | |
2042 #ifdef USE_VV | |
2043 GList *streams; | |
2044 gboolean prepared = TRUE; | |
2045 | |
2046 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2047 | |
2048 streams = purple_media_get_streams(media, session_id, participant); | |
2049 | |
2050 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
2051 PurpleMediaStream *stream = streams->data; | |
2052 if (stream->candidates_prepared == FALSE) { | |
2053 g_list_free(streams); | |
2054 prepared = FALSE; | |
2055 break; | |
2056 } | |
2057 } | |
2058 | |
2059 return prepared; | |
2060 #else | |
2061 return FALSE; | |
2062 #endif | |
2063 } | |
2064 | |
2065 gboolean | |
2066 purple_media_set_send_codec(PurpleMedia *media, const gchar *sess_id, PurpleMediaCodec *codec) | |
2067 { | |
2068 #ifdef USE_VV | |
2069 PurpleMediaSession *session; | |
2070 FsCodec *fscodec; | |
2071 GError *err = NULL; | |
2072 | |
2073 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2074 | |
2075 session = purple_media_get_session(media, sess_id); | |
2076 | |
2077 if (session != NULL) | |
2078 return FALSE; | |
2079 | |
2080 fscodec = purple_media_codec_to_fs(codec); | |
2081 fs_session_set_send_codec(session->session, fscodec, &err); | |
2082 fs_codec_destroy(fscodec); | |
2083 | |
2084 if (err) { | |
2085 purple_debug_error("media", "Error setting send codec\n"); | |
2086 g_error_free(err); | |
2087 return FALSE; | |
2088 } | |
2089 return TRUE; | |
2090 #else | |
2091 return FALSE; | |
2092 #endif | |
2093 } | |
2094 | |
2095 gboolean | |
2096 purple_media_codecs_ready(PurpleMedia *media, const gchar *sess_id) | |
2097 { | |
2098 #ifdef USE_VV | |
2099 gboolean ret; | |
2100 | |
2101 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2102 | |
2103 if (sess_id != NULL) { | |
2104 PurpleMediaSession *session; | |
2105 session = purple_media_get_session(media, sess_id); | |
2106 | |
2107 if (session == NULL) | |
2108 return FALSE; | |
2109 if (session->type & (PURPLE_MEDIA_SEND_AUDIO | | |
2110 PURPLE_MEDIA_SEND_VIDEO)) | |
2111 g_object_get(session->session, | |
2112 "codecs-ready", &ret, NULL); | |
2113 else | |
2114 ret = TRUE; | |
2115 } else { | |
2116 GList *values = g_hash_table_get_values(media->priv->sessions); | |
2117 for (; values; values = g_list_delete_link(values, values)) { | |
2118 PurpleMediaSession *session = values->data; | |
2119 if (session->type & (PURPLE_MEDIA_SEND_AUDIO | | |
2120 PURPLE_MEDIA_SEND_VIDEO)) | |
2121 g_object_get(session->session, | |
2122 "codecs-ready", &ret, NULL); | |
2123 else | |
2124 ret = TRUE; | |
2125 | |
2126 if (ret == FALSE) | |
2127 break; | |
2128 } | |
2129 if (values != NULL) | |
2130 g_list_free(values); | |
2131 } | |
2132 return ret; | |
2133 #else | |
2134 return FALSE; | |
2135 #endif | |
2136 } | |
2137 | |
2138 gboolean | |
2139 purple_media_is_initiator(PurpleMedia *media, | |
2140 const gchar *sess_id, const gchar *participant) | |
2141 { | |
2142 #ifdef USE_VV | |
2143 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2144 | |
2145 if (sess_id == NULL && participant == NULL) | |
2146 return media->priv->initiator; | |
2147 else if (sess_id != NULL && participant == NULL) { | |
2148 PurpleMediaSession *session = | |
2149 purple_media_get_session(media, sess_id); | |
2150 return session != NULL ? session->initiator : FALSE; | |
2151 } else if (sess_id != NULL && participant != NULL) { | |
2152 PurpleMediaStream *stream = purple_media_get_stream( | |
2153 media, sess_id, participant); | |
2154 return stream != NULL ? stream->initiator : FALSE; | |
2155 } | |
2156 #endif | |
2157 return FALSE; | |
2158 } | |
2159 | |
2160 gboolean | |
2161 purple_media_accepted(PurpleMedia *media, const gchar *sess_id, | |
2162 const gchar *participant) | |
2163 { | |
2164 #ifdef USE_VV | |
2165 gboolean accepted = TRUE; | |
2166 | |
2167 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2168 | |
2169 if (sess_id == NULL && participant == NULL) { | |
2170 GList *streams = media->priv->streams; | |
2171 | |
2172 for (; streams; streams = g_list_next(streams)) { | |
2173 PurpleMediaStream *stream = streams->data; | |
2174 if (stream->accepted == FALSE) { | |
2175 accepted = FALSE; | |
2176 break; | |
2177 } | |
2178 } | |
2179 } else if (sess_id != NULL && participant == NULL) { | |
2180 GList *streams = purple_media_get_streams( | |
2181 media, sess_id, NULL); | |
2182 for (; streams; streams = | |
2183 g_list_delete_link(streams, streams)) { | |
2184 PurpleMediaStream *stream = streams->data; | |
2185 if (stream->accepted == FALSE) { | |
2186 g_list_free(streams); | |
2187 accepted = FALSE; | |
2188 break; | |
2189 } | |
2190 } | |
2191 } else if (sess_id != NULL && participant != NULL) { | |
2192 PurpleMediaStream *stream = purple_media_get_stream( | |
2193 media, sess_id, participant); | |
2194 if (stream == NULL || stream->accepted == FALSE) | |
2195 accepted = FALSE; | |
2196 } | |
2197 | |
2198 return accepted; | |
2199 #else | |
2200 return FALSE; | |
2201 #endif | |
2202 } | |
2203 | |
2204 void purple_media_set_input_volume(PurpleMedia *media, | |
2205 const gchar *session_id, double level) | |
2206 { | |
2207 #ifdef USE_VV | |
2208 GList *sessions; | |
2209 | |
2210 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
2211 | |
2212 purple_prefs_set_int("/purple/media/audio/volume/input", level); | |
2213 | |
2214 if (session_id == NULL) | |
2215 sessions = g_hash_table_get_values(media->priv->sessions); | |
2216 else | |
2217 sessions = g_list_append(NULL, | |
2218 purple_media_get_session(media, session_id)); | |
2219 | |
2220 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
2221 PurpleMediaSession *session = sessions->data; | |
2222 | |
2223 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
2224 gchar *name = g_strdup_printf("volume_%s", | |
2225 session->id); | |
2226 GstElement *volume = gst_bin_get_by_name( | |
2227 GST_BIN(session->media->priv->confbin), | |
2228 name); | |
2229 g_free(name); | |
2230 g_object_set(volume, "volume", level/10.0, NULL); | |
2231 } | |
2232 } | |
2233 #endif | |
2234 } | |
2235 | |
2236 void purple_media_set_output_volume(PurpleMedia *media, | |
2237 const gchar *session_id, const gchar *participant, | |
2238 double level) | |
2239 { | |
2240 #ifdef USE_VV | |
2241 GList *streams; | |
2242 | |
2243 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
2244 | |
2245 purple_prefs_set_int("/purple/media/audio/volume/output", level); | |
2246 | |
2247 streams = purple_media_get_streams(media, | |
2248 session_id, participant); | |
2249 | |
2250 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
2251 PurpleMediaStream *stream = streams->data; | |
2252 | |
2253 if (stream->session->type & PURPLE_MEDIA_RECV_AUDIO | |
2254 && GST_IS_ELEMENT(stream->volume)) { | |
2255 g_object_set(stream->volume, "volume", level/10.0, NULL); | |
2256 } | |
2257 } | |
2258 #endif | |
2259 } | |
2260 | |
2261 gulong | |
2262 purple_media_set_output_window(PurpleMedia *media, const gchar *session_id, | |
2263 const gchar *participant, gulong window_id) | |
2264 { | |
2265 #ifdef USE_VV | |
2266 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
2267 | |
2268 return purple_media_manager_set_output_window(media->priv->manager, | |
2269 media, session_id, participant, window_id); | |
2270 #else | |
2271 return 0; | |
2272 #endif | |
2273 } | |
2274 | |
2275 void | |
2276 purple_media_remove_output_windows(PurpleMedia *media) | |
2277 { | |
2278 #ifdef USE_VV | |
2279 GList *iter = media->priv->streams; | |
2280 for (; iter; iter = g_list_next(iter)) { | |
2281 PurpleMediaStream *stream = iter->data; | |
2282 purple_media_manager_remove_output_windows( | |
2283 media->priv->manager, media, | |
2284 stream->session->id, stream->participant); | |
2285 } | |
2286 | |
2287 iter = purple_media_get_session_ids(media); | |
2288 for (; iter; iter = g_list_delete_link(iter, iter)) { | |
2289 gchar *session_name = iter->data; | |
2290 purple_media_manager_remove_output_windows( | |
2291 media->priv->manager, media, | |
2292 session_name, NULL); | |
2293 } | |
2294 #endif | |
2295 } | |
2296 | |
2297 #ifdef USE_GSTREAMER | |
2298 GstElement * | |
2299 purple_media_get_tee(PurpleMedia *media, | |
2300 const gchar *session_id, const gchar *participant) | |
2301 { | |
2302 #ifdef USE_VV | |
2303 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
2304 | |
2305 if (session_id != NULL && participant == NULL) { | |
2306 PurpleMediaSession *session = | |
2307 purple_media_get_session(media, session_id); | |
2308 return (session != NULL) ? session->tee : NULL; | |
2309 } else if (session_id != NULL && participant != NULL) { | |
2310 PurpleMediaStream *stream = | |
2311 purple_media_get_stream(media, | |
2312 session_id, participant); | |
2313 return (stream != NULL) ? stream->tee : NULL; | |
2314 } | |
2315 g_return_val_if_reached(NULL); | |
2316 #else | |
2317 return NULL; | |
2318 #endif | |
2319 } | |
2320 #endif /* USE_GSTREAMER */ | |
2321 |