Mercurial > pidgin
changeset 24962:aa50b1f05145
Added PurpleMediaStream to wrap FsStream.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Sun, 16 Nov 2008 04:23:36 +0000 |
parents | 403453f8b643 |
children | 33fa549f2399 |
files | libpurple/media.c libpurple/media.h |
diffstat | 2 files changed, 81 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/media.c Thu Nov 13 04:00:29 2008 +0000 +++ b/libpurple/media.c Sun Nov 16 04:23:36 2008 +0000 @@ -40,6 +40,11 @@ #include <gst/interfaces/propertyprobe.h> #include <gst/farsight/fs-conference-iface.h> +/** @copydoc _PurpleMediaSession */ +typedef struct _PurpleMediaSession PurpleMediaSession; +/** @copydoc _PurpleMediaStream */ +typedef struct _PurpleMediaStream PurpleMediaStream; + struct _PurpleMediaSession { gchar *id; @@ -47,8 +52,7 @@ GstElement *src; GstElement *sink; FsSession *session; - /* FsStream table. Mapped by participant's name */ - GHashTable *streams; + PurpleMediaSessionType type; /* GList of FsCandidates table. Mapped by participant's name */ GHashTable *local_candidates; @@ -61,6 +65,20 @@ FsCandidate *remote_candidate; }; +struct _PurpleMediaStream +{ + PurpleMediaSession *session; + gchar *participant; + FsStream *stream; + + GList *local_candidates; + + gboolean candidates_prepared; + + FsCandidate *local_candidate; + FsCandidate *remote_candidate; +}; + struct _PurpleMediaPrivate { FsConference *conference; @@ -71,7 +89,10 @@ GHashTable *sessions; /* PurpleMediaSession table */ GHashTable *participants; /* FsParticipant table */ + GList *streams; /* PurpleMediaStream table */ + GstElement *pipeline; + }; #define PURPLE_MEDIA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_MEDIA, PurpleMediaPrivate)) @@ -233,6 +254,44 @@ } static void +purple_media_stream_free(PurpleMediaStream *stream) +{ + g_free(stream->participant); + g_object_unref(stream->stream); + + if (stream->local_candidates) + fs_candidate_list_destroy(stream->local_candidates); + + if (stream->local_candidate) + fs_candidate_destroy(stream->local_candidate); + if (stream->remote_candidate) + fs_candidate_destroy(stream->remote_candidate); + + g_free(stream); +} + +static void +purple_media_session_free(PurpleMediaSession *session) +{ + g_free(session->id); + + if (session->local_candidates) { + GList *candidates = g_hash_table_get_values(session->local_candidates); + for (; candidates; candidates = + g_list_delete_link(candidates, candidates)) + fs_candidate_list_destroy(candidates->data); + g_hash_table_destroy(session->local_candidates); + } + + if (session->local_candidate) + fs_candidate_destroy(session->local_candidate); + if (session->remote_candidate) + fs_candidate_destroy(session->remote_candidate); + + g_free(session); +} + +static void purple_media_finalize (GObject *media) { PurpleMediaPrivate *priv = PURPLE_MEDIA_GET_PRIVATE(media); @@ -246,34 +305,14 @@ if (priv->sessions) { GList *sessions = g_hash_table_get_values(priv->sessions); for (; sessions; sessions = g_list_delete_link(sessions, sessions)) { - PurpleMediaSession *session = sessions->data; - g_free(session->id); - - if (session->streams) { - GList *streams = g_hash_table_get_values(session->streams); - for (; streams; streams = g_list_delete_link(streams, streams)) - g_object_unref(streams->data); - g_hash_table_destroy(session->streams); - } - - if (session->local_candidates) { - GList *candidates = g_hash_table_get_values(session->local_candidates); - for (; candidates; candidates = - g_list_delete_link(candidates, candidates)) - fs_candidate_list_destroy(candidates->data); - g_hash_table_destroy(session->local_candidates); - } - - if (session->local_candidate) - fs_candidate_destroy(session->local_candidate); - if (session->remote_candidate) - fs_candidate_destroy(session->remote_candidate); - - g_free(session); + purple_media_session_free(sessions->data); } g_hash_table_destroy(priv->sessions); } + for (; priv->streams; priv->streams = g_list_delete_link(priv->streams, priv->streams)) + purple_media_stream_free(priv->streams->data); + if (priv->participants) { GList *participants = g_hash_table_get_values(priv->participants); for (; participants; participants = g_list_delete_link(participants, participants)) @@ -423,8 +462,16 @@ static FsStream* purple_media_session_get_stream(PurpleMediaSession *session, const gchar *name) { - return (FsStream*) (session->streams) ? - g_hash_table_lookup(session->streams, name) : NULL; + GList *streams = session->media->priv->streams; + + for (; streams; streams = g_list_next(streams)) { + PurpleMediaStream *stream = streams->data; + if (session == stream->session && + !strcmp(stream->participant, name)) + return stream->stream; + } + + return NULL; } static GList* @@ -483,13 +530,13 @@ static void purple_media_insert_stream(PurpleMediaSession *session, const gchar *name, FsStream *stream) { - if (!session->streams) { - purple_debug_info("media", "Creating hash table for streams\n"); - session->streams = g_hash_table_new_full(g_str_hash, - g_str_equal, g_free, NULL); - } + PurpleMediaStream *media_stream = g_new0(PurpleMediaStream, 1); + media_stream->stream = stream; + media_stream->participant = g_strdup(name); + media_stream->session = session; - g_hash_table_insert(session->streams, g_strdup(name), stream); + session->media->priv->streams = + g_list_append(session->media->priv->streams, media_stream); } static void
--- a/libpurple/media.h Thu Nov 13 04:00:29 2008 +0000 +++ b/libpurple/media.h Sun Nov 16 04:23:36 2008 +0000 @@ -51,8 +51,6 @@ typedef struct _PurpleMediaClass PurpleMediaClass; /** @copydoc _PurpleMediaPrivate */ typedef struct _PurpleMediaPrivate PurpleMediaPrivate; -/** @copydoc _PurpleMediaSession */ -typedef struct _PurpleMediaSession PurpleMediaSession; #else