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