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