Mercurial > pidgin.yaz
annotate libpurple/media/media.c @ 29571:f0966e90ec44
Move get_local_candidates functionality over to the Fs2 media backend.
author | maiku@pidgin.im |
---|---|
date | Mon, 26 Oct 2009 22:50:23 +0000 |
parents | 9c1810122f21 |
children | a39696686dd6 |
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 | |
29568 | 777 #if 0 |
29534 | 778 static gboolean |
779 purple_media_remove_session(PurpleMedia *media, PurpleMediaSession *session) | |
780 { | |
781 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
782 return g_hash_table_remove(media->priv->sessions, session->id); | |
783 } | |
29568 | 784 #endif |
29534 | 785 |
786 static PurpleMediaStream * | |
787 purple_media_insert_stream(PurpleMediaSession *session, const gchar *name, FsStream *stream) | |
788 { | |
789 PurpleMediaStream *media_stream; | |
790 | |
791 g_return_val_if_fail(session != NULL, NULL); | |
792 | |
793 media_stream = g_new0(PurpleMediaStream, 1); | |
794 media_stream->stream = stream; | |
795 media_stream->participant = g_strdup(name); | |
796 media_stream->session = session; | |
797 | |
798 session->media->priv->streams = | |
799 g_list_append(session->media->priv->streams, media_stream); | |
800 | |
801 return media_stream; | |
802 } | |
803 | |
804 static void | |
805 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
|
806 PurpleMediaCandidate *candidate) |
29534 | 807 { |
808 PurpleMediaStream *stream; | |
809 | |
810 g_return_if_fail(session != NULL); | |
811 | |
812 stream = purple_media_get_stream(session->media, session->id, name); | |
813 stream->local_candidates = g_list_append(stream->local_candidates, candidate); | |
814 } | |
815 #endif | |
816 | |
817 GList * | |
818 purple_media_get_session_ids(PurpleMedia *media) | |
819 { | |
820 #ifdef USE_VV | |
821 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
822 return media->priv->sessions != NULL ? | |
823 g_hash_table_get_keys(media->priv->sessions) : NULL; | |
824 #else | |
825 return NULL; | |
826 #endif | |
827 } | |
828 | |
829 #ifdef USE_VV | |
830 static void | |
831 purple_media_set_src(PurpleMedia *media, const gchar *sess_id, GstElement *src) | |
832 { | |
833 PurpleMediaSession *session; | |
834 GstPad *sinkpad; | |
835 GstPad *srcpad; | |
836 | |
837 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
838 g_return_if_fail(GST_IS_ELEMENT(src)); | |
839 | |
840 session = purple_media_get_session(media, sess_id); | |
841 | |
842 if (session == NULL) { | |
843 purple_debug_warning("media", "purple_media_set_src: trying" | |
844 " to set src on non-existent session\n"); | |
845 return; | |
846 } | |
847 | |
848 if (session->src) | |
849 gst_object_unref(session->src); | |
850 session->src = src; | |
851 gst_element_set_locked_state(session->src, TRUE); | |
852 | |
853 session->tee = gst_element_factory_make("tee", NULL); | |
854 gst_bin_add(GST_BIN(session->media->priv->confbin), session->tee); | |
855 | |
856 /* This supposedly isn't necessary, but it silences some warnings */ | |
857 if (GST_ELEMENT_PARENT(session->media->priv->confbin) | |
858 == GST_ELEMENT_PARENT(session->src)) { | |
859 GstPad *pad = gst_element_get_static_pad(session->tee, "sink"); | |
860 GstPad *ghost = gst_ghost_pad_new(NULL, pad); | |
861 gst_object_unref(pad); | |
862 gst_pad_set_active(ghost, TRUE); | |
863 gst_element_add_pad(session->media->priv->confbin, ghost); | |
864 } | |
865 | |
866 gst_element_set_state(session->tee, GST_STATE_PLAYING); | |
867 gst_element_link(session->src, session->media->priv->confbin); | |
868 | |
869 g_object_get(session->session, "sink-pad", &sinkpad, NULL); | |
870 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
871 gchar *name = g_strdup_printf("volume_%s", session->id); | |
872 GstElement *level; | |
873 GstElement *volume = gst_element_factory_make("volume", name); | |
874 double input_volume = purple_prefs_get_int( | |
875 "/purple/media/audio/volume/input")/10.0; | |
876 g_free(name); | |
877 name = g_strdup_printf("sendlevel_%s", session->id); | |
878 level = gst_element_factory_make("level", name); | |
879 g_free(name); | |
880 gst_bin_add(GST_BIN(session->media->priv->confbin), volume); | |
881 gst_bin_add(GST_BIN(session->media->priv->confbin), level); | |
882 gst_element_set_state(level, GST_STATE_PLAYING); | |
883 gst_element_set_state(volume, GST_STATE_PLAYING); | |
884 gst_element_link(volume, level); | |
885 gst_element_link(session->tee, volume); | |
886 srcpad = gst_element_get_static_pad(level, "src"); | |
887 g_object_set(volume, "volume", input_volume, NULL); | |
888 } else { | |
889 srcpad = gst_element_get_request_pad(session->tee, "src%d"); | |
890 } | |
891 purple_debug_info("media", "connecting pad: %s\n", | |
892 gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK | |
893 ? "success" : "failure"); | |
894 gst_element_set_locked_state(session->src, FALSE); | |
895 gst_object_unref(session->src); | |
896 } | |
897 #endif | |
898 | |
899 #ifdef USE_GSTREAMER | |
900 GstElement * | |
901 purple_media_get_src(PurpleMedia *media, const gchar *sess_id) | |
902 { | |
903 #ifdef USE_VV | |
904 PurpleMediaSession *session; | |
905 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
906 session = purple_media_get_session(media, sess_id); | |
907 return (session != NULL) ? session->src : NULL; | |
908 #else | |
909 return NULL; | |
910 #endif | |
911 } | |
912 #endif /* USE_GSTREAMER */ | |
913 | |
914 #ifdef USE_VV | |
915 static gboolean | |
916 media_bus_call(GstBus *bus, GstMessage *msg, PurpleMedia *media) | |
917 { | |
918 switch(GST_MESSAGE_TYPE(msg)) { | |
919 case GST_MESSAGE_ELEMENT: { | |
920 if (g_signal_has_handler_pending(media, | |
921 purple_media_signals[LEVEL], 0, FALSE) | |
922 && gst_structure_has_name( | |
923 gst_message_get_structure(msg), "level")) { | |
924 GstElement *src = GST_ELEMENT(GST_MESSAGE_SRC(msg)); | |
925 gchar *name; | |
926 gchar *participant = NULL; | |
927 PurpleMediaSession *session = NULL; | |
928 gdouble rms_db; | |
929 gdouble percent; | |
930 const GValue *list; | |
931 const GValue *value; | |
932 | |
933 if (!PURPLE_IS_MEDIA(media) || | |
934 GST_ELEMENT_PARENT(src) != | |
935 media->priv->confbin) | |
936 break; | |
937 | |
938 name = gst_element_get_name(src); | |
939 if (!strncmp(name, "sendlevel_", 10)) { | |
940 session = purple_media_get_session( | |
941 media, name+10); | |
942 } else { | |
943 GList *iter = media->priv->streams; | |
944 for (; iter; iter = g_list_next(iter)) { | |
945 PurpleMediaStream *stream = iter->data; | |
946 if (stream->level == src) { | |
947 session = stream->session; | |
948 participant = stream->participant; | |
949 break; | |
950 } | |
951 } | |
952 } | |
953 g_free(name); | |
954 if (!session) | |
955 break; | |
956 | |
957 list = gst_structure_get_value( | |
958 gst_message_get_structure(msg), "rms"); | |
959 value = gst_value_list_get_value(list, 0); | |
960 rms_db = g_value_get_double(value); | |
961 percent = pow(10, rms_db / 20) * 5; | |
962 if(percent > 1.0) | |
963 percent = 1.0; | |
964 | |
965 g_signal_emit(media, purple_media_signals[LEVEL], | |
966 0, session->id, participant, percent); | |
967 break; | |
968 } | |
969 break; | |
970 } | |
971 default: | |
972 break; | |
973 } | |
974 | |
975 return TRUE; | |
976 } | |
977 #endif | |
978 | |
979 PurpleAccount * | |
980 purple_media_get_account(PurpleMedia *media) | |
981 { | |
982 #ifdef USE_VV | |
983 PurpleAccount *account; | |
984 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
985 g_object_get(G_OBJECT(media), "account", &account, NULL); | |
986 return account; | |
987 #else | |
988 return NULL; | |
989 #endif | |
990 } | |
991 | |
992 gpointer | |
993 purple_media_get_prpl_data(PurpleMedia *media) | |
994 { | |
995 #ifdef USE_VV | |
996 gpointer prpl_data; | |
997 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
998 g_object_get(G_OBJECT(media), "prpl-data", &prpl_data, NULL); | |
999 return prpl_data; | |
1000 #else | |
1001 return NULL; | |
1002 #endif | |
1003 } | |
1004 | |
1005 void | |
1006 purple_media_set_prpl_data(PurpleMedia *media, gpointer prpl_data) | |
1007 { | |
1008 #ifdef USE_VV | |
1009 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1010 g_object_set(G_OBJECT(media), "prpl-data", prpl_data, NULL); | |
1011 #endif | |
1012 } | |
1013 | |
1014 void | |
1015 purple_media_error(PurpleMedia *media, const gchar *error, ...) | |
1016 { | |
1017 #ifdef USE_VV | |
1018 va_list args; | |
1019 gchar *message; | |
1020 | |
1021 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1022 | |
1023 va_start(args, error); | |
1024 message = g_strdup_vprintf(error, args); | |
1025 va_end(args); | |
1026 | |
1027 purple_debug_error("media", "%s\n", message); | |
1028 g_signal_emit(media, purple_media_signals[S_ERROR], 0, message); | |
1029 | |
1030 g_free(message); | |
1031 #endif | |
1032 } | |
1033 | |
1034 void | |
1035 purple_media_end(PurpleMedia *media, | |
1036 const gchar *session_id, const gchar *participant) | |
1037 { | |
1038 #ifdef USE_VV | |
1039 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1040 if (session_id == NULL && participant == NULL) { | |
1041 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1042 0, PURPLE_MEDIA_STATE_END, | |
1043 NULL, NULL); | |
1044 g_object_unref(media); | |
1045 } | |
1046 #endif | |
1047 } | |
1048 | |
1049 void | |
1050 purple_media_stream_info(PurpleMedia *media, PurpleMediaInfoType type, | |
1051 const gchar *session_id, const gchar *participant, | |
1052 gboolean local) | |
1053 { | |
1054 #ifdef USE_VV | |
1055 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1056 | |
1057 if (type == PURPLE_MEDIA_INFO_ACCEPT) { | |
1058 GList *streams; | |
1059 | |
1060 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1061 | |
1062 streams = purple_media_get_streams(media, | |
1063 session_id, participant); | |
1064 | |
1065 for (; streams; streams = | |
1066 g_list_delete_link(streams, streams)) { | |
1067 PurpleMediaStream *stream = streams->data; | |
1068 g_object_set(G_OBJECT(stream->stream), "direction", | |
1069 purple_media_to_fs_stream_direction( | |
1070 stream->session->type), NULL); | |
1071 stream->accepted = TRUE; | |
1072 | |
1073 if (stream->remote_candidates != NULL) { | |
1074 GError *err = NULL; | |
29560
18571ea6e44a
Store remote_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29559
diff
changeset
|
1075 GList *candidates; |
18571ea6e44a
Store remote_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29559
diff
changeset
|
1076 |
18571ea6e44a
Store remote_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29559
diff
changeset
|
1077 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
|
1078 stream->remote_candidates); |
29534 | 1079 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
|
1080 candidates, &err); |
18571ea6e44a
Store remote_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29559
diff
changeset
|
1081 fs_candidate_list_destroy(candidates); |
29534 | 1082 |
1083 if (err) { | |
1084 purple_debug_error("media", "Error adding remote" | |
1085 " candidates: %s\n", err->message); | |
1086 g_error_free(err); | |
1087 } | |
1088 } | |
1089 } | |
1090 } else if (local == TRUE && (type == PURPLE_MEDIA_INFO_MUTE || | |
1091 type == PURPLE_MEDIA_INFO_UNMUTE)) { | |
1092 GList *sessions; | |
1093 gboolean active = (type == PURPLE_MEDIA_INFO_MUTE); | |
1094 | |
1095 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1096 | |
1097 if (session_id == NULL) | |
1098 sessions = g_hash_table_get_values( | |
1099 media->priv->sessions); | |
1100 else | |
1101 sessions = g_list_prepend(NULL, | |
1102 purple_media_get_session( | |
1103 media, session_id)); | |
1104 | |
1105 purple_debug_info("media", "Turning mute %s\n", | |
1106 active ? "on" : "off"); | |
1107 | |
1108 for (; sessions; sessions = g_list_delete_link( | |
1109 sessions, sessions)) { | |
1110 PurpleMediaSession *session = sessions->data; | |
1111 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
1112 gchar *name = g_strdup_printf("volume_%s", | |
1113 session->id); | |
1114 GstElement *volume = gst_bin_get_by_name( | |
1115 GST_BIN(session->media-> | |
1116 priv->confbin), name); | |
1117 g_free(name); | |
1118 g_object_set(volume, "mute", active, NULL); | |
1119 } | |
1120 } | |
1121 } else if (local == TRUE && (type == PURPLE_MEDIA_INFO_PAUSE || | |
1122 type == PURPLE_MEDIA_INFO_UNPAUSE)) { | |
1123 gboolean active = (type == PURPLE_MEDIA_INFO_PAUSE); | |
1124 GList *streams = purple_media_get_streams(media, | |
1125 session_id, participant); | |
1126 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
1127 PurpleMediaStream *stream = streams->data; | |
1128 if (stream->session->type & PURPLE_MEDIA_SEND_VIDEO) { | |
1129 g_object_set(stream->stream, "direction", | |
1130 purple_media_to_fs_stream_direction( | |
1131 stream->session->type & ((active) ? | |
1132 ~PURPLE_MEDIA_SEND_VIDEO : | |
1133 PURPLE_MEDIA_VIDEO)), NULL); | |
1134 } | |
1135 } | |
1136 } | |
1137 | |
1138 g_signal_emit(media, purple_media_signals[STREAM_INFO], | |
1139 0, type, session_id, participant, local); | |
1140 | |
1141 if (type == PURPLE_MEDIA_INFO_HANGUP || | |
1142 type == PURPLE_MEDIA_INFO_REJECT) { | |
1143 purple_media_end(media, session_id, participant); | |
1144 } | |
1145 #endif | |
1146 } | |
1147 | |
1148 #ifdef USE_VV | |
1149 static void | |
29554
2460e6774e08
Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.
maiku@pidgin.im
parents:
29553
diff
changeset
|
1150 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
|
1151 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
|
1152 PurpleMediaCandidate *candidate, PurpleMedia *media) |
29534 | 1153 { |
29554
2460e6774e08
Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.
maiku@pidgin.im
parents:
29553
diff
changeset
|
1154 PurpleMediaSession *session = |
2460e6774e08
Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.
maiku@pidgin.im
parents:
29553
diff
changeset
|
1155 purple_media_get_session(media, sess_id); |
29534 | 1156 |
29554
2460e6774e08
Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.
maiku@pidgin.im
parents:
29553
diff
changeset
|
1157 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
|
1158 purple_media_candidate_copy(candidate)); |
29534 | 1159 |
1160 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
|
1161 0, session->id, participant, candidate); |
29534 | 1162 } |
1163 | |
1164 static void | |
29557
1fdc75c94c22
Move Farsight 2's local-candidates-prepared signal to the Fs2 media backend.
maiku@pidgin.im
parents:
29556
diff
changeset
|
1165 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
|
1166 const gchar *sess_id, const gchar *name, PurpleMedia *media) |
29534 | 1167 { |
1168 PurpleMediaStream *stream_data; | |
1169 | |
29557
1fdc75c94c22
Move Farsight 2's local-candidates-prepared signal to the Fs2 media backend.
maiku@pidgin.im
parents:
29556
diff
changeset
|
1170 g_return_if_fail(PURPLE_IS_MEDIA(media)); |
29534 | 1171 |
29557
1fdc75c94c22
Move Farsight 2's local-candidates-prepared signal to the Fs2 media backend.
maiku@pidgin.im
parents:
29556
diff
changeset
|
1172 stream_data = purple_media_get_stream(media, sess_id, name); |
29534 | 1173 stream_data->candidates_prepared = TRUE; |
1174 | |
29557
1fdc75c94c22
Move Farsight 2's local-candidates-prepared signal to the Fs2 media backend.
maiku@pidgin.im
parents:
29556
diff
changeset
|
1175 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
|
1176 0, sess_id, name); |
29534 | 1177 } |
1178 | |
1179 /* callback called when a pair of transport candidates (local and remote) | |
1180 * has been established */ | |
1181 static void | |
29556
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1182 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
|
1183 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
|
1184 PurpleMediaCandidate *local_candidate, |
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1185 PurpleMediaCandidate *remote_candidate, |
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1186 PurpleMedia *media) |
29534 | 1187 { |
1188 PurpleMediaStream *stream; | |
1189 GList *iter; | |
29556
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1190 guint id; |
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 g_return_if_fail(PURPLE_IS_MEDIA(media)); |
29534 | 1193 |
29556
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1194 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
|
1195 id = purple_media_candidate_get_component_id(local_candidate); |
29534 | 1196 |
1197 iter = stream->active_local_candidates; | |
1198 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
|
1199 PurpleMediaCandidate *c = iter->data; |
7713312c4ab0
Store active_local_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29560
diff
changeset
|
1200 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
|
1201 g_object_unref(c); |
29534 | 1202 stream->active_local_candidates = |
1203 g_list_delete_link(iter, iter); | |
1204 stream->active_local_candidates = g_list_prepend( | |
1205 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
|
1206 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
|
1207 local_candidate)); |
29534 | 1208 break; |
1209 } | |
1210 } | |
1211 if (iter == NULL) | |
1212 stream->active_local_candidates = g_list_prepend( | |
1213 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
|
1214 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
|
1215 local_candidate)); |
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1216 |
74e75fc3481e
Move Farsight 2's new-active-candidate-pair into the Fs2 media backend.
maiku@pidgin.im
parents:
29555
diff
changeset
|
1217 id = purple_media_candidate_get_component_id(local_candidate); |
29534 | 1218 |
1219 iter = stream->active_remote_candidates; | |
1220 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
|
1221 PurpleMediaCandidate *c = iter->data; |
1156bf88b4d3
Store active_remote_candidates in PurpleMedia as a GList of PurpleMediaCandidate's.
maiku@pidgin.im
parents:
29561
diff
changeset
|
1222 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
|
1223 g_object_unref(c); |
29534 | 1224 stream->active_remote_candidates = |
1225 g_list_delete_link(iter, iter); | |
1226 stream->active_remote_candidates = g_list_prepend( | |
1227 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
|
1228 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
|
1229 remote_candidate)); |
29534 | 1230 break; |
1231 } | |
1232 } | |
1233 if (iter == NULL) | |
1234 stream->active_remote_candidates = g_list_prepend( | |
1235 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
|
1236 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
|
1237 remote_candidate)); |
29534 | 1238 |
1239 purple_debug_info("media", "candidate pair established\n"); | |
1240 } | |
1241 | |
29555
cc978a1a4bd1
Move handling Farsight 2's codecs-changed signal into the Fs2 media backend.
maiku@pidgin.im
parents:
29554
diff
changeset
|
1242 static void |
cc978a1a4bd1
Move handling Farsight 2's codecs-changed signal into the Fs2 media backend.
maiku@pidgin.im
parents:
29554
diff
changeset
|
1243 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
|
1244 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
|
1245 { |
cc978a1a4bd1
Move handling Farsight 2's codecs-changed signal into the Fs2 media backend.
maiku@pidgin.im
parents:
29554
diff
changeset
|
1246 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
|
1247 } |
cc978a1a4bd1
Move handling Farsight 2's codecs-changed signal into the Fs2 media backend.
maiku@pidgin.im
parents:
29554
diff
changeset
|
1248 |
29534 | 1249 static gboolean |
1250 purple_media_connected_cb(PurpleMediaStream *stream) | |
1251 { | |
1252 g_return_val_if_fail(stream != NULL, FALSE); | |
1253 | |
1254 stream->connected_cb_id = 0; | |
1255 | |
1256 purple_media_manager_create_output_window( | |
1257 stream->session->media->priv->manager, | |
1258 stream->session->media, | |
1259 stream->session->id, stream->participant); | |
1260 | |
1261 g_signal_emit(stream->session->media, | |
1262 purple_media_signals[STATE_CHANGED], | |
1263 0, PURPLE_MEDIA_STATE_CONNECTED, | |
1264 stream->session->id, stream->participant); | |
1265 return FALSE; | |
1266 } | |
1267 | |
1268 static void | |
1269 purple_media_src_pad_added_cb(FsStream *fsstream, GstPad *srcpad, | |
1270 FsCodec *codec, PurpleMediaStream *stream) | |
1271 { | |
1272 PurpleMediaPrivate *priv; | |
1273 GstPad *sinkpad; | |
1274 | |
1275 g_return_if_fail(FS_IS_STREAM(fsstream)); | |
1276 g_return_if_fail(stream != NULL); | |
1277 | |
1278 priv = stream->session->media->priv; | |
1279 | |
1280 if (stream->src == NULL) { | |
1281 GstElement *sink = NULL; | |
1282 | |
1283 if (codec->media_type == FS_MEDIA_TYPE_AUDIO) { | |
1284 GstElement *queue = NULL; | |
1285 double output_volume = purple_prefs_get_int( | |
1286 "/purple/media/audio/volume/output")/10.0; | |
1287 /* | |
1288 * Should this instead be: | |
1289 * audioconvert ! audioresample ! liveadder ! | |
1290 * audioresample ! audioconvert ! realsink | |
1291 */ | |
1292 queue = gst_element_factory_make("queue", NULL); | |
1293 stream->volume = gst_element_factory_make( | |
1294 "volume", NULL); | |
1295 g_object_set(stream->volume, "volume", | |
1296 output_volume, NULL); | |
1297 stream->level = gst_element_factory_make( | |
1298 "level", NULL); | |
1299 stream->src = gst_element_factory_make( | |
1300 "liveadder", NULL); | |
1301 sink = purple_media_manager_get_element(priv->manager, | |
1302 PURPLE_MEDIA_RECV_AUDIO, | |
1303 stream->session->media, | |
1304 stream->session->id, | |
1305 stream->participant); | |
1306 gst_bin_add(GST_BIN(priv->confbin), queue); | |
1307 gst_bin_add(GST_BIN(priv->confbin), stream->volume); | |
1308 gst_bin_add(GST_BIN(priv->confbin), stream->level); | |
1309 gst_bin_add(GST_BIN(priv->confbin), sink); | |
1310 gst_element_set_state(sink, GST_STATE_PLAYING); | |
1311 gst_element_set_state(stream->level, GST_STATE_PLAYING); | |
1312 gst_element_set_state(stream->volume, GST_STATE_PLAYING); | |
1313 gst_element_set_state(queue, GST_STATE_PLAYING); | |
1314 gst_element_link(stream->level, sink); | |
1315 gst_element_link(stream->volume, stream->level); | |
1316 gst_element_link(queue, stream->volume); | |
1317 sink = queue; | |
1318 } else if (codec->media_type == FS_MEDIA_TYPE_VIDEO) { | |
1319 stream->src = gst_element_factory_make( | |
1320 "fsfunnel", NULL); | |
1321 sink = gst_element_factory_make( | |
1322 "fakesink", NULL); | |
1323 g_object_set(G_OBJECT(sink), "async", FALSE, NULL); | |
1324 gst_bin_add(GST_BIN(priv->confbin), sink); | |
1325 gst_element_set_state(sink, GST_STATE_PLAYING); | |
1326 } | |
1327 stream->tee = gst_element_factory_make("tee", NULL); | |
1328 gst_bin_add_many(GST_BIN(priv->confbin), | |
1329 stream->src, stream->tee, NULL); | |
1330 gst_element_set_state(stream->tee, GST_STATE_PLAYING); | |
1331 gst_element_set_state(stream->src, GST_STATE_PLAYING); | |
1332 gst_element_link_many(stream->src, stream->tee, sink, NULL); | |
1333 } | |
1334 | |
1335 sinkpad = gst_element_get_request_pad(stream->src, "sink%d"); | |
1336 gst_pad_link(srcpad, sinkpad); | |
1337 gst_object_unref(sinkpad); | |
1338 | |
1339 stream->connected_cb_id = purple_timeout_add(0, | |
1340 (GSourceFunc)purple_media_connected_cb, stream); | |
1341 } | |
1342 #endif /* USE_VV */ | |
1343 | |
1344 gboolean | |
1345 purple_media_add_stream(PurpleMedia *media, const gchar *sess_id, | |
1346 const gchar *who, PurpleMediaSessionType type, | |
1347 gboolean initiator, const gchar *transmitter, | |
1348 guint num_params, GParameter *params) | |
1349 { | |
1350 #ifdef USE_VV | |
1351 PurpleMediaSession *session; | |
1352 FsParticipant *participant = NULL; | |
1353 PurpleMediaStream *stream = NULL; | |
1354 FsMediaType media_type = purple_media_to_fs_media_type(type); | |
1355 FsStreamDirection type_direction = | |
1356 purple_media_to_fs_stream_direction(type); | |
1357 | |
1358 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1359 | |
29551
e85df0170905
Decouple the media_bus_call from the backend. It will still be needed even
maiku@pidgin.im
parents:
29550
diff
changeset
|
1360 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
|
1361 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
|
1362 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
|
1363 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
|
1364 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
|
1365 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
|
1366 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
|
1367 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
|
1368 } |
e85df0170905
Decouple the media_bus_call from the backend. It will still be needed even
maiku@pidgin.im
parents:
29550
diff
changeset
|
1369 |
29549
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1370 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
|
1371 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
|
1372 num_params, params)) { |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1373 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
|
1374 return FALSE; |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1375 } |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1376 |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1377 /* 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
|
1378 if (media->priv->conference == NULL) { |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1379 media->priv->conference = |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1380 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
|
1381 PURPLE_MEDIA_BACKEND_FS2( |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1382 media->priv->backend)); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1383 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
|
1384 media->priv->conference); |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1385 } |
41ae97b7e97e
Start to use the media backend code in PurpleMedia and PurpleMediaManager.
maiku@pidgin.im
parents:
29545
diff
changeset
|
1386 |
29534 | 1387 session = purple_media_get_session(media, sess_id); |
1388 | |
1389 if (!session) { | |
1390 PurpleMediaSessionType session_type; | |
1391 GstElement *src = NULL; | |
1392 | |
1393 session = g_new0(PurpleMediaSession, 1); | |
29553
efeb21092ed2
Begin transferring FsSession over to the Farsight 2 media backend.
maiku@pidgin.im
parents:
29552
diff
changeset
|
1394 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
|
1395 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
|
1396 sess_id); |
29534 | 1397 session->id = g_strdup(sess_id); |
1398 session->media = media; | |
1399 session->type = type; | |
1400 session->initiator = initiator; | |
1401 | |
1402 purple_media_add_session(media, session); | |
1403 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1404 0, PURPLE_MEDIA_STATE_NEW, | |
1405 session->id, NULL); | |
1406 | |
1407 if (type_direction & FS_DIRECTION_SEND) { | |
1408 session_type = purple_media_from_fs(media_type, | |
1409 FS_DIRECTION_SEND); | |
1410 src = purple_media_manager_get_element( | |
1411 media->priv->manager, session_type, | |
1412 media, session->id, who); | |
1413 if (!GST_IS_ELEMENT(src)) { | |
1414 purple_debug_error("media", | |
1415 "Error creating src for session %s\n", | |
1416 session->id); | |
1417 purple_media_end(media, session->id, NULL); | |
1418 return FALSE; | |
1419 } | |
1420 | |
1421 purple_media_set_src(media, session->id, src); | |
1422 gst_element_set_state(session->src, GST_STATE_PLAYING); | |
1423 purple_media_manager_create_output_window( | |
1424 media->priv->manager, | |
1425 session->media, | |
1426 session->id, NULL); | |
1427 } | |
1428 } | |
1429 | |
29565
eef5ec04a5bf
Remove the list of participants from PurpleMedia and use the Fs2 backend's.
maiku@pidgin.im
parents:
29562
diff
changeset
|
1430 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
|
1431 PURPLE_MEDIA_BACKEND_FS2(media->priv->backend), who); |
29534 | 1432 |
1433 stream = purple_media_get_stream(media, sess_id, who); | |
1434 | |
1435 if (!stream) { | |
1436 FsStream *fsstream = NULL; | |
1437 | |
29566
f600903f7811
Transfer creating Farsight 2 streams to the Fs2 media backend.
maiku@pidgin.im
parents:
29565
diff
changeset
|
1438 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
|
1439 PURPLE_MEDIA_BACKEND_FS2( |
f600903f7811
Transfer creating Farsight 2 streams to the Fs2 media backend.
maiku@pidgin.im
parents:
29565
diff
changeset
|
1440 media->priv->backend), sess_id, who); |
29534 | 1441 |
1442 stream = purple_media_insert_stream(session, who, fsstream); | |
1443 stream->initiator = initiator; | |
1444 | |
1445 /* callback for source pad added (new stream source ready) */ | |
1446 g_signal_connect(G_OBJECT(fsstream), | |
1447 "src-pad-added", G_CALLBACK(purple_media_src_pad_added_cb), stream); | |
1448 | |
1449 g_signal_emit(media, purple_media_signals[STATE_CHANGED], | |
1450 0, PURPLE_MEDIA_STATE_NEW, | |
1451 session->id, who); | |
1452 } else { | |
1453 if (purple_media_to_fs_stream_direction(stream->session->type) | |
1454 != type_direction) { | |
1455 /* change direction */ | |
1456 g_object_set(stream->stream, "direction", | |
1457 type_direction, NULL); | |
1458 } | |
1459 } | |
1460 | |
1461 return TRUE; | |
1462 #else | |
1463 return FALSE; | |
1464 #endif /* USE_VV */ | |
1465 } | |
1466 | |
1467 PurpleMediaManager * | |
1468 purple_media_get_manager(PurpleMedia *media) | |
1469 { | |
1470 PurpleMediaManager *ret; | |
1471 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1472 g_object_get(media, "manager", &ret, NULL); | |
1473 return ret; | |
1474 } | |
1475 | |
1476 PurpleMediaSessionType | |
1477 purple_media_get_session_type(PurpleMedia *media, const gchar *sess_id) | |
1478 { | |
1479 #ifdef USE_VV | |
1480 PurpleMediaSession *session; | |
1481 g_return_val_if_fail(PURPLE_IS_MEDIA(media), PURPLE_MEDIA_NONE); | |
1482 session = purple_media_get_session(media, sess_id); | |
1483 return session->type; | |
1484 #else | |
1485 return PURPLE_MEDIA_NONE; | |
1486 #endif | |
1487 } | |
1488 /* XXX: Should wait until codecs-ready is TRUE before using this function */ | |
1489 GList * | |
1490 purple_media_get_codecs(PurpleMedia *media, const gchar *sess_id) | |
1491 { | |
1492 #ifdef USE_VV | |
1493 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1494 | |
29569
9c1810122f21
Transfer get_codecs functionality to the Fs2 media backend.
maiku@pidgin.im
parents:
29568
diff
changeset
|
1495 return purple_media_backend_get_codecs(media->priv->backend, sess_id); |
29534 | 1496 #else |
1497 return NULL; | |
1498 #endif | |
1499 } | |
1500 | |
1501 GList * | |
1502 purple_media_get_local_candidates(PurpleMedia *media, const gchar *sess_id, | |
1503 const gchar *participant) | |
1504 { | |
1505 #ifdef USE_VV | |
1506 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
29571
f0966e90ec44
Move get_local_candidates functionality over to the Fs2 media backend.
maiku@pidgin.im
parents:
29569
diff
changeset
|
1507 |
f0966e90ec44
Move get_local_candidates functionality over to the Fs2 media backend.
maiku@pidgin.im
parents:
29569
diff
changeset
|
1508 return purple_media_backend_get_local_candidates(media->priv->backend, |
f0966e90ec44
Move get_local_candidates functionality over to the Fs2 media backend.
maiku@pidgin.im
parents:
29569
diff
changeset
|
1509 sess_id, participant); |
29534 | 1510 #else |
1511 return NULL; | |
1512 #endif | |
1513 } | |
1514 | |
1515 void | |
1516 purple_media_add_remote_candidates(PurpleMedia *media, const gchar *sess_id, | |
1517 const gchar *participant, | |
1518 GList *remote_candidates) | |
1519 { | |
1520 #ifdef USE_VV | |
1521 PurpleMediaStream *stream; | |
1522 | |
1523 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1524 stream = purple_media_get_stream(media, sess_id, participant); | |
1525 | |
1526 if (stream == NULL) { | |
1527 purple_debug_error("media", | |
1528 "purple_media_add_remote_candidates: " | |
1529 "couldn't find stream %s %s.\n", | |
1530 sess_id ? sess_id : "(null)", | |
1531 participant ? participant : "(null)"); | |
1532 return; | |
1533 } | |
1534 | |
1535 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
|
1536 purple_media_candidate_list_copy(remote_candidates)); |
29534 | 1537 |
1538 if (stream->accepted == TRUE) { | |
29567
983af0970bb2
Transfer setting Farsight 2's remote candidates to the Fs2 media backend.
maiku@pidgin.im
parents:
29566
diff
changeset
|
1539 purple_media_backend_add_remote_candidates( |
983af0970bb2
Transfer setting Farsight 2's remote candidates to the Fs2 media backend.
maiku@pidgin.im
parents:
29566
diff
changeset
|
1540 media->priv->backend, sess_id, participant, |
983af0970bb2
Transfer setting Farsight 2's remote candidates to the Fs2 media backend.
maiku@pidgin.im
parents:
29566
diff
changeset
|
1541 remote_candidates); |
29534 | 1542 } |
1543 #endif | |
1544 } | |
1545 | |
1546 #if 0 | |
1547 /* | |
1548 * These two functions aren't being used and I'd rather not lock in the API | |
1549 * until they are needed. If they ever are. | |
1550 */ | |
1551 | |
1552 GList * | |
1553 purple_media_get_active_local_candidates(PurpleMedia *media, | |
1554 const gchar *sess_id, const gchar *participant) | |
1555 { | |
1556 #ifdef USE_VV | |
1557 PurpleMediaStream *stream; | |
1558 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1559 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
|
1560 return purple_media_candidate_list_copy( |
29534 | 1561 stream->active_local_candidates); |
1562 #else | |
1563 return NULL; | |
1564 #endif | |
1565 } | |
1566 | |
1567 GList * | |
1568 purple_media_get_active_remote_candidates(PurpleMedia *media, | |
1569 const gchar *sess_id, const gchar *participant) | |
1570 { | |
1571 #ifdef USE_VV | |
1572 PurpleMediaStream *stream; | |
1573 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1574 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
|
1575 return purple_media_candidate_list_copy( |
29534 | 1576 stream->active_remote_candidates); |
1577 #else | |
1578 return NULL; | |
1579 #endif | |
1580 } | |
1581 #endif | |
1582 | |
1583 gboolean | |
1584 purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, | |
1585 const gchar *participant, GList *codecs) | |
1586 { | |
1587 #ifdef USE_VV | |
1588 PurpleMediaStream *stream; | |
1589 FsStream *fsstream; | |
1590 GList *fscodecs; | |
1591 GError *err = NULL; | |
1592 | |
1593 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1594 stream = purple_media_get_stream(media, sess_id, participant); | |
1595 | |
1596 if (stream == NULL) | |
1597 return FALSE; | |
1598 | |
1599 fsstream = stream->stream; | |
1600 fscodecs = purple_media_codec_list_to_fs(codecs); | |
1601 fs_stream_set_remote_codecs(fsstream, fscodecs, &err); | |
1602 fs_codec_list_destroy(fscodecs); | |
1603 | |
1604 if (err) { | |
1605 purple_debug_error("media", "Error setting remote codecs: %s\n", | |
1606 err->message); | |
1607 g_error_free(err); | |
1608 return FALSE; | |
1609 } | |
1610 return TRUE; | |
1611 #else | |
1612 return FALSE; | |
1613 #endif | |
1614 } | |
1615 | |
1616 gboolean | |
1617 purple_media_candidates_prepared(PurpleMedia *media, | |
1618 const gchar *session_id, const gchar *participant) | |
1619 { | |
1620 #ifdef USE_VV | |
1621 GList *streams; | |
1622 gboolean prepared = TRUE; | |
1623 | |
1624 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1625 | |
1626 streams = purple_media_get_streams(media, session_id, participant); | |
1627 | |
1628 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
1629 PurpleMediaStream *stream = streams->data; | |
1630 if (stream->candidates_prepared == FALSE) { | |
1631 g_list_free(streams); | |
1632 prepared = FALSE; | |
1633 break; | |
1634 } | |
1635 } | |
1636 | |
1637 return prepared; | |
1638 #else | |
1639 return FALSE; | |
1640 #endif | |
1641 } | |
1642 | |
1643 gboolean | |
1644 purple_media_set_send_codec(PurpleMedia *media, const gchar *sess_id, PurpleMediaCodec *codec) | |
1645 { | |
1646 #ifdef USE_VV | |
1647 PurpleMediaSession *session; | |
1648 FsCodec *fscodec; | |
1649 GError *err = NULL; | |
1650 | |
1651 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1652 | |
1653 session = purple_media_get_session(media, sess_id); | |
1654 | |
1655 if (session != NULL) | |
1656 return FALSE; | |
1657 | |
1658 fscodec = purple_media_codec_to_fs(codec); | |
1659 fs_session_set_send_codec(session->session, fscodec, &err); | |
1660 fs_codec_destroy(fscodec); | |
1661 | |
1662 if (err) { | |
1663 purple_debug_error("media", "Error setting send codec\n"); | |
1664 g_error_free(err); | |
1665 return FALSE; | |
1666 } | |
1667 return TRUE; | |
1668 #else | |
1669 return FALSE; | |
1670 #endif | |
1671 } | |
1672 | |
1673 gboolean | |
1674 purple_media_codecs_ready(PurpleMedia *media, const gchar *sess_id) | |
1675 { | |
1676 #ifdef USE_VV | |
1677 gboolean ret; | |
1678 | |
1679 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1680 | |
1681 if (sess_id != NULL) { | |
1682 PurpleMediaSession *session; | |
1683 session = purple_media_get_session(media, sess_id); | |
1684 | |
1685 if (session == NULL) | |
1686 return FALSE; | |
1687 if (session->type & (PURPLE_MEDIA_SEND_AUDIO | | |
1688 PURPLE_MEDIA_SEND_VIDEO)) | |
1689 g_object_get(session->session, | |
1690 "codecs-ready", &ret, NULL); | |
1691 else | |
1692 ret = TRUE; | |
1693 } else { | |
1694 GList *values = g_hash_table_get_values(media->priv->sessions); | |
1695 for (; values; values = g_list_delete_link(values, values)) { | |
1696 PurpleMediaSession *session = values->data; | |
1697 if (session->type & (PURPLE_MEDIA_SEND_AUDIO | | |
1698 PURPLE_MEDIA_SEND_VIDEO)) | |
1699 g_object_get(session->session, | |
1700 "codecs-ready", &ret, NULL); | |
1701 else | |
1702 ret = TRUE; | |
1703 | |
1704 if (ret == FALSE) | |
1705 break; | |
1706 } | |
1707 if (values != NULL) | |
1708 g_list_free(values); | |
1709 } | |
1710 return ret; | |
1711 #else | |
1712 return FALSE; | |
1713 #endif | |
1714 } | |
1715 | |
1716 gboolean | |
1717 purple_media_is_initiator(PurpleMedia *media, | |
1718 const gchar *sess_id, const gchar *participant) | |
1719 { | |
1720 #ifdef USE_VV | |
1721 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1722 | |
1723 if (sess_id == NULL && participant == NULL) | |
1724 return media->priv->initiator; | |
1725 else if (sess_id != NULL && participant == NULL) { | |
1726 PurpleMediaSession *session = | |
1727 purple_media_get_session(media, sess_id); | |
1728 return session != NULL ? session->initiator : FALSE; | |
1729 } else if (sess_id != NULL && participant != NULL) { | |
1730 PurpleMediaStream *stream = purple_media_get_stream( | |
1731 media, sess_id, participant); | |
1732 return stream != NULL ? stream->initiator : FALSE; | |
1733 } | |
1734 #endif | |
1735 return FALSE; | |
1736 } | |
1737 | |
1738 gboolean | |
1739 purple_media_accepted(PurpleMedia *media, const gchar *sess_id, | |
1740 const gchar *participant) | |
1741 { | |
1742 #ifdef USE_VV | |
1743 gboolean accepted = TRUE; | |
1744 | |
1745 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1746 | |
1747 if (sess_id == NULL && participant == NULL) { | |
1748 GList *streams = media->priv->streams; | |
1749 | |
1750 for (; streams; streams = g_list_next(streams)) { | |
1751 PurpleMediaStream *stream = streams->data; | |
1752 if (stream->accepted == FALSE) { | |
1753 accepted = FALSE; | |
1754 break; | |
1755 } | |
1756 } | |
1757 } else if (sess_id != NULL && participant == NULL) { | |
1758 GList *streams = purple_media_get_streams( | |
1759 media, sess_id, NULL); | |
1760 for (; streams; streams = | |
1761 g_list_delete_link(streams, streams)) { | |
1762 PurpleMediaStream *stream = streams->data; | |
1763 if (stream->accepted == FALSE) { | |
1764 g_list_free(streams); | |
1765 accepted = FALSE; | |
1766 break; | |
1767 } | |
1768 } | |
1769 } else if (sess_id != NULL && participant != NULL) { | |
1770 PurpleMediaStream *stream = purple_media_get_stream( | |
1771 media, sess_id, participant); | |
1772 if (stream == NULL || stream->accepted == FALSE) | |
1773 accepted = FALSE; | |
1774 } | |
1775 | |
1776 return accepted; | |
1777 #else | |
1778 return FALSE; | |
1779 #endif | |
1780 } | |
1781 | |
1782 void purple_media_set_input_volume(PurpleMedia *media, | |
1783 const gchar *session_id, double level) | |
1784 { | |
1785 #ifdef USE_VV | |
1786 GList *sessions; | |
1787 | |
1788 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1789 | |
1790 purple_prefs_set_int("/purple/media/audio/volume/input", level); | |
1791 | |
1792 if (session_id == NULL) | |
1793 sessions = g_hash_table_get_values(media->priv->sessions); | |
1794 else | |
1795 sessions = g_list_append(NULL, | |
1796 purple_media_get_session(media, session_id)); | |
1797 | |
1798 for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { | |
1799 PurpleMediaSession *session = sessions->data; | |
1800 | |
1801 if (session->type & PURPLE_MEDIA_SEND_AUDIO) { | |
1802 gchar *name = g_strdup_printf("volume_%s", | |
1803 session->id); | |
1804 GstElement *volume = gst_bin_get_by_name( | |
1805 GST_BIN(session->media->priv->confbin), | |
1806 name); | |
1807 g_free(name); | |
1808 g_object_set(volume, "volume", level/10.0, NULL); | |
1809 } | |
1810 } | |
1811 #endif | |
1812 } | |
1813 | |
1814 void purple_media_set_output_volume(PurpleMedia *media, | |
1815 const gchar *session_id, const gchar *participant, | |
1816 double level) | |
1817 { | |
1818 #ifdef USE_VV | |
1819 GList *streams; | |
1820 | |
1821 g_return_if_fail(PURPLE_IS_MEDIA(media)); | |
1822 | |
1823 purple_prefs_set_int("/purple/media/audio/volume/output", level); | |
1824 | |
1825 streams = purple_media_get_streams(media, | |
1826 session_id, participant); | |
1827 | |
1828 for (; streams; streams = g_list_delete_link(streams, streams)) { | |
1829 PurpleMediaStream *stream = streams->data; | |
1830 | |
1831 if (stream->session->type & PURPLE_MEDIA_RECV_AUDIO | |
1832 && GST_IS_ELEMENT(stream->volume)) { | |
1833 g_object_set(stream->volume, "volume", level/10.0, NULL); | |
1834 } | |
1835 } | |
1836 #endif | |
1837 } | |
1838 | |
1839 gulong | |
1840 purple_media_set_output_window(PurpleMedia *media, const gchar *session_id, | |
1841 const gchar *participant, gulong window_id) | |
1842 { | |
1843 #ifdef USE_VV | |
1844 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); | |
1845 | |
1846 return purple_media_manager_set_output_window(media->priv->manager, | |
1847 media, session_id, participant, window_id); | |
1848 #else | |
1849 return 0; | |
1850 #endif | |
1851 } | |
1852 | |
1853 void | |
1854 purple_media_remove_output_windows(PurpleMedia *media) | |
1855 { | |
1856 #ifdef USE_VV | |
1857 GList *iter = media->priv->streams; | |
1858 for (; iter; iter = g_list_next(iter)) { | |
1859 PurpleMediaStream *stream = iter->data; | |
1860 purple_media_manager_remove_output_windows( | |
1861 media->priv->manager, media, | |
1862 stream->session->id, stream->participant); | |
1863 } | |
1864 | |
1865 iter = purple_media_get_session_ids(media); | |
1866 for (; iter; iter = g_list_delete_link(iter, iter)) { | |
1867 gchar *session_name = iter->data; | |
1868 purple_media_manager_remove_output_windows( | |
1869 media->priv->manager, media, | |
1870 session_name, NULL); | |
1871 } | |
1872 #endif | |
1873 } | |
1874 | |
1875 #ifdef USE_GSTREAMER | |
1876 GstElement * | |
1877 purple_media_get_tee(PurpleMedia *media, | |
1878 const gchar *session_id, const gchar *participant) | |
1879 { | |
1880 #ifdef USE_VV | |
1881 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); | |
1882 | |
1883 if (session_id != NULL && participant == NULL) { | |
1884 PurpleMediaSession *session = | |
1885 purple_media_get_session(media, session_id); | |
1886 return (session != NULL) ? session->tee : NULL; | |
1887 } else if (session_id != NULL && participant != NULL) { | |
1888 PurpleMediaStream *stream = | |
1889 purple_media_get_stream(media, | |
1890 session_id, participant); | |
1891 return (stream != NULL) ? stream->tee : NULL; | |
1892 } | |
1893 g_return_val_if_reached(NULL); | |
1894 #else | |
1895 return NULL; | |
1896 #endif | |
1897 } | |
1898 #endif /* USE_GSTREAMER */ | |
1899 |