Mercurial > pidgin.yaz
comparison libpurple/media/backend-fs2.c @ 29554:2460e6774e08
Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.
author | maiku@pidgin.im |
---|---|
date | Fri, 23 Oct 2009 22:20:45 +0000 |
parents | efeb21092ed2 |
children | cc978a1a4bd1 |
comparison
equal
deleted
inserted
replaced
29553:efeb21092ed2 | 29554:2460e6774e08 |
---|---|
47 PURPLE_TYPE_MEDIA_BACKEND_FS2, PurpleMediaBackendFs2Private)) | 47 PURPLE_TYPE_MEDIA_BACKEND_FS2, PurpleMediaBackendFs2Private)) |
48 | 48 |
49 static void purple_media_backend_iface_init(PurpleMediaBackendIface *iface); | 49 static void purple_media_backend_iface_init(PurpleMediaBackendIface *iface); |
50 | 50 |
51 static gboolean | 51 static gboolean |
52 _gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackend *self); | 52 _gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackendFs2 *self); |
53 static void | 53 static void |
54 _state_changed_cb(PurpleMedia *media, PurpleMediaState state, | 54 _state_changed_cb(PurpleMedia *media, PurpleMediaState state, |
55 gchar *sid, gchar *name, PurpleMediaBackendFs2 *self); | 55 gchar *sid, gchar *name, PurpleMediaBackendFs2 *self); |
56 static void | 56 static void |
57 _stream_info_cb(PurpleMedia *media, PurpleMediaInfoType type, | 57 _stream_info_cb(PurpleMedia *media, PurpleMediaInfoType type, |
345 if (direction & FS_DIRECTION_RECV) | 345 if (direction & FS_DIRECTION_RECV) |
346 result |= PURPLE_MEDIA_RECV_VIDEO; | 346 result |= PURPLE_MEDIA_RECV_VIDEO; |
347 } | 347 } |
348 return result; | 348 return result; |
349 } | 349 } |
350 | |
351 static FsCandidate * | |
352 purple_media_candidate_to_fs(PurpleMediaCandidate *candidate) | |
353 { | |
354 FsCandidate *fscandidate; | |
355 gchar *foundation; | |
356 guint component_id; | |
357 gchar *ip; | |
358 guint port; | |
359 gchar *base_ip; | |
360 guint base_port; | |
361 PurpleMediaNetworkProtocol proto; | |
362 guint32 priority; | |
363 PurpleMediaCandidateType type; | |
364 gchar *username; | |
365 gchar *password; | |
366 guint ttl; | |
367 | |
368 if (candidate == NULL) | |
369 return NULL; | |
370 | |
371 g_object_get(G_OBJECT(candidate), | |
372 "foundation", &foundation, | |
373 "component-id", &component_id, | |
374 "ip", &ip, | |
375 "port", &port, | |
376 "base-ip", &base_ip, | |
377 "base-port", &base_port, | |
378 "protocol", &proto, | |
379 "priority", &priority, | |
380 "type", &type, | |
381 "username", &username, | |
382 "password", &password, | |
383 "ttl", &ttl, | |
384 NULL); | |
385 | |
386 fscandidate = fs_candidate_new(foundation, | |
387 component_id, type, | |
388 proto, ip, port); | |
389 | |
390 fscandidate->base_ip = base_ip; | |
391 fscandidate->base_port = base_port; | |
392 fscandidate->priority = priority; | |
393 fscandidate->username = username; | |
394 fscandidate->password = password; | |
395 fscandidate->ttl = ttl; | |
396 | |
397 g_free(foundation); | |
398 g_free(ip); | |
399 return fscandidate; | |
400 } | |
350 #endif | 401 #endif |
402 | |
403 static PurpleMediaCandidate * | |
404 purple_media_candidate_from_fs(FsCandidate *fscandidate) | |
405 { | |
406 PurpleMediaCandidate *candidate; | |
407 | |
408 if (fscandidate == NULL) | |
409 return NULL; | |
410 | |
411 candidate = purple_media_candidate_new(fscandidate->foundation, | |
412 fscandidate->component_id, fscandidate->type, | |
413 fscandidate->proto, fscandidate->ip, fscandidate->port); | |
414 g_object_set(candidate, | |
415 "base-ip", fscandidate->base_ip, | |
416 "base-port", fscandidate->base_port, | |
417 "priority", fscandidate->priority, | |
418 "username", fscandidate->username, | |
419 "password", fscandidate->password, | |
420 "ttl", fscandidate->ttl, NULL); | |
421 return candidate; | |
422 } | |
351 | 423 |
352 static PurpleMediaBackendFs2Session * | 424 static PurpleMediaBackendFs2Session * |
353 _get_session(PurpleMediaBackendFs2 *self, const gchar *sess_id) | 425 _get_session(PurpleMediaBackendFs2 *self, const gchar *sess_id) |
354 { | 426 { |
355 PurpleMediaBackendFs2Private *priv; | 427 PurpleMediaBackendFs2Private *priv; |
363 session = g_hash_table_lookup(priv->sessions, sess_id); | 435 session = g_hash_table_lookup(priv->sessions, sess_id); |
364 | 436 |
365 return session; | 437 return session; |
366 } | 438 } |
367 | 439 |
440 static PurpleMediaBackendFs2Session * | |
441 _get_session_from_fs_stream(PurpleMediaBackendFs2 *self, FsStream *stream) | |
442 { | |
443 PurpleMediaBackendFs2Private *priv = | |
444 PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self); | |
445 FsSession *fssession; | |
446 GList *values; | |
447 | |
448 g_return_val_if_fail(PURPLE_IS_MEDIA_BACKEND_FS2(self), NULL); | |
449 g_return_val_if_fail(FS_IS_STREAM(stream), NULL); | |
450 | |
451 g_object_get(stream, "session", &fssession, NULL); | |
452 | |
453 values = g_hash_table_get_values(priv->sessions); | |
454 | |
455 for (; values; values = g_list_delete_link(values, values)) { | |
456 PurpleMediaBackendFs2Session *session = values->data; | |
457 | |
458 if (session->session == fssession) { | |
459 g_list_free(values); | |
460 g_object_unref(fssession); | |
461 return session; | |
462 } | |
463 } | |
464 | |
465 g_object_unref(fssession); | |
466 return NULL; | |
467 } | |
468 | |
368 static void | 469 static void |
369 _gst_handle_message_element(GstBus *bus, GstMessage *msg, | 470 _gst_handle_message_element(GstBus *bus, GstMessage *msg, |
370 PurpleMediaBackend *self) | 471 PurpleMediaBackendFs2 *self) |
371 { | 472 { |
372 PurpleMediaBackendFs2Private *priv = | 473 PurpleMediaBackendFs2Private *priv = |
373 PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self); | 474 PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self); |
374 GstElement *src = GST_ELEMENT(GST_MESSAGE_SRC(msg)); | 475 GstElement *src = GST_ELEMENT(GST_MESSAGE_SRC(msg)); |
375 | 476 |
422 } else if (gst_structure_has_name(msg->structure, | 523 } else if (gst_structure_has_name(msg->structure, |
423 "farsight-new-local-candidate")) { | 524 "farsight-new-local-candidate")) { |
424 const GValue *value; | 525 const GValue *value; |
425 FsStream *stream; | 526 FsStream *stream; |
426 FsCandidate *local_candidate; | 527 FsCandidate *local_candidate; |
427 #if 0 | 528 PurpleMediaCandidate *candidate; |
428 PurpleMediaSession *session; | 529 FsParticipant *participant; |
429 #endif | 530 PurpleMediaBackendFs2Session *session; |
531 gchar *name; | |
430 | 532 |
431 value = gst_structure_get_value(msg->structure, "stream"); | 533 value = gst_structure_get_value(msg->structure, "stream"); |
432 stream = g_value_get_object(value); | 534 stream = g_value_get_object(value); |
433 value = gst_structure_get_value(msg->structure, "candidate"); | 535 value = gst_structure_get_value(msg->structure, "candidate"); |
434 local_candidate = g_value_get_boxed(value); | 536 local_candidate = g_value_get_boxed(value); |
537 | |
538 session = _get_session_from_fs_stream(self, stream); | |
539 | |
540 purple_debug_info("backend-fs2", | |
541 "got new local candidate: %s\n", | |
542 local_candidate->foundation); | |
543 | |
544 g_object_get(stream, "participant", &participant, NULL); | |
545 g_object_get(participant, "cname", &name, NULL); | |
546 g_object_unref(participant); | |
547 | |
435 #if 0 | 548 #if 0 |
436 session = purple_media_session_from_fs_stream(media, stream); | 549 purple_media_insert_local_candidate(session, name, |
437 _new_local_candidate_cb(stream, local_candidate, session); | 550 fs_candidate_copy(local_candidate)); |
438 #endif | 551 #endif |
552 | |
553 candidate = purple_media_candidate_from_fs(local_candidate); | |
554 g_signal_emit_by_name(self, "new-candidate", | |
555 session->id, name, candidate); | |
556 g_object_unref(candidate); | |
439 } else if (gst_structure_has_name(msg->structure, | 557 } else if (gst_structure_has_name(msg->structure, |
440 "farsight-local-candidates-prepared")) { | 558 "farsight-local-candidates-prepared")) { |
441 const GValue *value; | 559 const GValue *value; |
442 FsStream *stream; | 560 FsStream *stream; |
443 #if 0 | 561 #if 0 |
574 } | 692 } |
575 } | 693 } |
576 | 694 |
577 static void | 695 static void |
578 _gst_handle_message_error(GstBus *bus, GstMessage *msg, | 696 _gst_handle_message_error(GstBus *bus, GstMessage *msg, |
579 PurpleMediaBackend *self) | 697 PurpleMediaBackendFs2 *self) |
580 { | 698 { |
581 PurpleMediaBackendFs2Private *priv = | 699 PurpleMediaBackendFs2Private *priv = |
582 PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self); | 700 PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self); |
583 GstElement *element = GST_ELEMENT(GST_MESSAGE_SRC(msg)); | 701 GstElement *element = GST_ELEMENT(GST_MESSAGE_SRC(msg)); |
584 GstElement *lastElement = NULL; | 702 GstElement *lastElement = NULL; |
618 purple_media_error(priv->media, _("Conference error")); | 736 purple_media_error(priv->media, _("Conference error")); |
619 purple_media_end(priv->media, NULL, NULL); | 737 purple_media_end(priv->media, NULL, NULL); |
620 } | 738 } |
621 | 739 |
622 static gboolean | 740 static gboolean |
623 _gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackend *self) | 741 _gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackendFs2 *self) |
624 { | 742 { |
625 switch(GST_MESSAGE_TYPE(msg)) { | 743 switch(GST_MESSAGE_TYPE(msg)) { |
626 case GST_MESSAGE_ELEMENT: | 744 case GST_MESSAGE_ELEMENT: |
627 _gst_handle_message_element(bus, msg, self); | 745 _gst_handle_message_element(bus, msg, self); |
628 break; | 746 break; |