comparison libpurple/media.c @ 26099:dcff28a0415c

Handle having multiple active candidates.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Thu, 05 Feb 2009 10:25:28 +0000
parents 58071d9f10b1
children f06eb6e7d907
comparison
equal deleted inserted replaced
26098:4a245ffb4051 26099:dcff28a0415c
73 GList *local_candidates; 73 GList *local_candidates;
74 GList *remote_candidates; 74 GList *remote_candidates;
75 75
76 gboolean candidates_prepared; 76 gboolean candidates_prepared;
77 77
78 FsCandidate *local_candidate; 78 GList *active_local_candidates;
79 FsCandidate *remote_candidate; 79 GList *active_remote_candidates;
80 80
81 gulong window_id; 81 gulong window_id;
82 }; 82 };
83 83
84 struct _PurpleMediaPrivate 84 struct _PurpleMediaPrivate
248 if (stream->local_candidates) 248 if (stream->local_candidates)
249 fs_candidate_list_destroy(stream->local_candidates); 249 fs_candidate_list_destroy(stream->local_candidates);
250 if (stream->remote_candidates) 250 if (stream->remote_candidates)
251 fs_candidate_list_destroy(stream->remote_candidates); 251 fs_candidate_list_destroy(stream->remote_candidates);
252 252
253 if (stream->local_candidate) 253 if (stream->active_local_candidates)
254 fs_candidate_destroy(stream->local_candidate); 254 fs_candidate_list_destroy(stream->active_local_candidates);
255 if (stream->remote_candidate) 255 if (stream->active_remote_candidates)
256 fs_candidate_destroy(stream->remote_candidate); 256 fs_candidate_list_destroy(stream->active_remote_candidates);
257 257
258 g_free(stream); 258 g_free(stream);
259 } 259 }
260 260
261 static void 261 static void
1668 PurpleMediaSession *session) 1668 PurpleMediaSession *session)
1669 { 1669 {
1670 gchar *name; 1670 gchar *name;
1671 FsParticipant *participant; 1671 FsParticipant *participant;
1672 PurpleMediaStream *stream; 1672 PurpleMediaStream *stream;
1673 GList *iter;
1673 1674
1674 g_return_if_fail(FS_IS_STREAM(fsstream)); 1675 g_return_if_fail(FS_IS_STREAM(fsstream));
1675 g_return_if_fail(session != NULL); 1676 g_return_if_fail(session != NULL);
1676 1677
1677 g_object_get(fsstream, "participant", &participant, NULL); 1678 g_object_get(fsstream, "participant", &participant, NULL);
1678 g_object_get(participant, "cname", &name, NULL); 1679 g_object_get(participant, "cname", &name, NULL);
1679 g_object_unref(participant); 1680 g_object_unref(participant);
1680 1681
1681 stream = purple_media_get_stream(session->media, session->id, name); 1682 stream = purple_media_get_stream(session->media, session->id, name);
1682 1683
1683 stream->local_candidate = fs_candidate_copy(native_candidate); 1684 iter = stream->active_local_candidates;
1684 stream->remote_candidate = fs_candidate_copy(remote_candidate); 1685 for(; iter; iter = g_list_next(iter)) {
1686 FsCandidate *c = iter->data;
1687 if (native_candidate->component_id == c->component_id) {
1688 fs_candidate_destroy(c);
1689 stream->active_local_candidates =
1690 g_list_delete_link(iter, iter);
1691 stream->active_local_candidates = g_list_prepend(
1692 stream->active_local_candidates,
1693 fs_candidate_copy(native_candidate));
1694 break;
1695 }
1696 }
1697 if (iter == NULL)
1698 stream->active_local_candidates = g_list_prepend(
1699 stream->active_local_candidates,
1700 fs_candidate_copy(native_candidate));
1701
1702 iter = stream->active_remote_candidates;
1703 for(; iter; iter = g_list_next(iter)) {
1704 FsCandidate *c = iter->data;
1705 if (native_candidate->component_id == c->component_id) {
1706 fs_candidate_destroy(c);
1707 stream->active_remote_candidates =
1708 g_list_delete_link(iter, iter);
1709 stream->active_remote_candidates = g_list_prepend(
1710 stream->active_remote_candidates,
1711 fs_candidate_copy(remote_candidate));
1712 break;
1713 }
1714 }
1715 if (iter == NULL)
1716 stream->active_remote_candidates = g_list_prepend(
1717 stream->active_remote_candidates,
1718 fs_candidate_copy(remote_candidate));
1685 1719
1686 purple_debug_info("media", "candidate pair established\n"); 1720 purple_debug_info("media", "candidate pair established\n");
1687 } 1721 }
1688 1722
1689 static gboolean 1723 static gboolean
2021 " candidates: %s\n", err->message); 2055 " candidates: %s\n", err->message);
2022 g_error_free(err); 2056 g_error_free(err);
2023 } 2057 }
2024 } 2058 }
2025 2059
2026 PurpleMediaCandidate * 2060 GList *
2027 purple_media_get_local_candidate(PurpleMedia *media, const gchar *sess_id, const gchar *name) 2061 purple_media_get_active_local_candidates(PurpleMedia *media,
2062 const gchar *sess_id, const gchar *name)
2028 { 2063 {
2029 PurpleMediaStream *stream; 2064 PurpleMediaStream *stream;
2030 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); 2065 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL);
2031 stream = purple_media_get_stream(media, sess_id, name); 2066 stream = purple_media_get_stream(media, sess_id, name);
2032 return purple_media_candidate_from_fs(stream->local_candidate); 2067 return purple_media_candidate_list_from_fs(
2033 } 2068 stream->active_local_candidates);
2034 2069 }
2035 PurpleMediaCandidate * 2070
2036 purple_media_get_remote_candidate(PurpleMedia *media, const gchar *sess_id, const gchar *name) 2071 GList *
2072 purple_media_get_active_remote_candidates(PurpleMedia *media,
2073 const gchar *sess_id, const gchar *name)
2037 { 2074 {
2038 PurpleMediaStream *stream; 2075 PurpleMediaStream *stream;
2039 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL); 2076 g_return_val_if_fail(PURPLE_IS_MEDIA(media), NULL);
2040 stream = purple_media_get_stream(media, sess_id, name); 2077 stream = purple_media_get_stream(media, sess_id, name);
2041 return purple_media_candidate_from_fs(stream->remote_candidate); 2078 return purple_media_candidate_list_from_fs(
2079 stream->active_remote_candidates);
2042 } 2080 }
2043 2081
2044 gboolean 2082 gboolean
2045 purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, const gchar *name, GList *codecs) 2083 purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, const gchar *name, GList *codecs)
2046 { 2084 {
2078 2116
2079 sessions = purple_media_get_session_names(media); 2117 sessions = purple_media_get_session_names(media);
2080 2118
2081 for (; sessions; sessions = sessions->next) { 2119 for (; sessions; sessions = sessions->next) {
2082 const gchar *session = sessions->data; 2120 const gchar *session = sessions->data;
2083 if (!purple_media_get_local_candidate(media, session, name) || 2121 GList *local = purple_media_get_active_local_candidates(
2084 !purple_media_get_remote_candidate(media, session, name)) 2122 media, session, name);
2123 GList *remote = purple_media_get_active_remote_candidates(
2124 media, session, name);
2125 gboolean result = (local == NULL || remote == NULL);
2126 purple_media_candidate_list_free(local);
2127 purple_media_candidate_list_free(remote);
2128 if (!result)
2085 return FALSE; 2129 return FALSE;
2086 } 2130 }
2087 2131
2088 return TRUE; 2132 return TRUE;
2089 } 2133 }