[farsight2/master] Make the msn conference enforce a single participant and a single session
Olivier Crête
olivier.crete at collabora.co.uk
Tue Jul 14 09:50:32 PDT 2009
---
gst/fsmsnconference/fs-msn-conference.c | 179 +++++++++++--------------------
gst/fsmsnconference/fs-msn-conference.h | 1 -
2 files changed, 63 insertions(+), 117 deletions(-)
diff --git a/gst/fsmsnconference/fs-msn-conference.c b/gst/fsmsnconference/fs-msn-conference.c
index 020005f..53b4809 100644
--- a/gst/fsmsnconference/fs-msn-conference.c
+++ b/gst/fsmsnconference/fs-msn-conference.c
@@ -40,8 +40,6 @@
#include "fs-msn-stream.h"
#include "fs-msn-participant.h"
-#include <string.h>
-
GST_DEBUG_CATEGORY (fsmsnconference_debug);
#define GST_CAT_DEFAULT fsmsnconference_debug
@@ -81,7 +79,6 @@ static GstStaticPadTemplate fs_msn_conference_src_template =
GST_PAD_SOMETIMES,
GST_STATIC_CAPS_ANY);
-
#define FS_MSN_CONFERENCE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), FS_TYPE_MSN_CONFERENCE, \
FsMsnConferencePrivate))
@@ -89,11 +86,11 @@ static GstStaticPadTemplate fs_msn_conference_src_template =
struct _FsMsnConferencePrivate
{
gboolean disposed;
- gchar *local_address;
/* Protected by GST_OBJECT_LOCK */
- GList *sessions;
- guint max_session_id;
- GList *participants;
+ gchar *local_address;
+
+ FsMsnParticipant *participant;
+ FsMsnSession *session;
};
static void fs_msn_conference_do_init (GType type);
@@ -122,9 +119,6 @@ static FsParticipant *fs_msn_conference_new_participant (FsBaseConference *conf,
gchar *cname,
GError **error);
-static FsMsnSession *fs_msn_conference_get_session_by_id_locked (
- FsMsnConference *self, guint session_id);
-
static void _remove_session (gpointer user_data,
GObject *where_the_object_was);
static void _remove_participant (gpointer user_data,
@@ -141,25 +135,19 @@ static void
fs_msn_conference_dispose (GObject * object)
{
FsMsnConference *self = FS_MSN_CONFERENCE (object);
- GList *item;
if (self->priv->disposed)
return;
GST_OBJECT_LOCK (object);
- for (item = g_list_first (self->priv->sessions);
- item;
- item = g_list_next (item))
- g_object_weak_unref (G_OBJECT (item->data), _remove_session, self);
- g_list_free (self->priv->sessions);
- self->priv->sessions = NULL;
-
- for (item = g_list_first (self->priv->participants);
- item;
- item = g_list_next (item))
- g_object_weak_unref (G_OBJECT (item->data), _remove_participant, self);
- g_list_free (self->priv->participants);
- self->priv->participants = NULL;
+ if (self->priv->session)
+ g_object_weak_unref (G_OBJECT (self->priv->session), _remove_session, self);
+ self->priv->session = NULL;
+
+ if (self->priv->participant)
+ g_object_weak_unref (G_OBJECT (self->priv->participant),
+ _remove_participant, self);
+ self->priv->participant = NULL;
GST_OBJECT_UNLOCK (object);
self->priv->disposed = TRUE;
@@ -171,6 +159,10 @@ fs_msn_conference_dispose (GObject * object)
static void
fs_msn_conference_finalize (GObject * object)
{
+ FsMsnConference *self = FS_MSN_CONFERENCE (object);
+
+ g_free (self->priv->local_address);
+ self->priv->local_address = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -223,9 +215,6 @@ fs_msn_conference_init (FsMsnConference *conf,
GST_DEBUG_OBJECT (conf, "fs_msn_conference_init");
conf->priv = FS_MSN_CONFERENCE_GET_PRIVATE (conf);
-
- conf->priv->disposed = FALSE;
- conf->priv->max_session_id = 1;
}
static void
@@ -239,7 +228,9 @@ fs_msn_conference_get_property (GObject *object,
switch (prop_id)
{
case PROP_LOCAL_MSNADD:
+ GST_OBJECT_LOCK (self);
g_value_set_string (value,self->priv->local_address);
+ GST_OBJECT_UNLOCK (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -257,7 +248,10 @@ fs_msn_conference_set_property (GObject *object,
switch (prop_id)
{
case PROP_LOCAL_MSNADD:
+ GST_OBJECT_LOCK (self);
+ g_free (self->priv->local_address);
self->priv->local_address = g_value_dup_string (value);
+ GST_OBJECT_UNLOCK (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -265,42 +259,6 @@ fs_msn_conference_set_property (GObject *object,
}
}
-
-/**
- * fs_msn_conference_get_session_by_id_locked
- * @self: The #FsMsnConference
- * @session_id: The session id
- *
- * Gets the #FsMsnSession from a list of sessions or NULL if it doesnt exist
- * You have to hold the GST_OBJECT_LOCK to call this function.
- *
- * Return value: A #FsMsnSession (unref after use) or NULL if it doesn't exist
- */
-static FsMsnSession *
-fs_msn_conference_get_session_by_id_locked (FsMsnConference *self,
- guint session_id)
-{
- GList *item = NULL;
-
- for (item = g_list_first (self->priv->sessions);
- item;
- item = g_list_next (item))
- {
- FsMsnSession *session = item->data;
-
- if (session->id == session_id)
- {
- g_object_ref (session);
- break;
- }
- }
-
- if (item)
- return FS_MSN_SESSION (item->data);
- else
- return NULL;
-}
-
static void
_remove_session (gpointer user_data,
GObject *where_the_object_was)
@@ -308,8 +266,8 @@ _remove_session (gpointer user_data,
FsMsnConference *self = FS_MSN_CONFERENCE (user_data);
GST_OBJECT_LOCK (self);
- self->priv->sessions =
- g_list_remove_all (self->priv->sessions, where_the_object_was);
+ if (self->priv->session == (FsMsnSession *) where_the_object_was)
+ self->priv->session = NULL;
GST_OBJECT_UNLOCK (self);
}
@@ -320,9 +278,9 @@ _remove_participant (gpointer user_data,
FsMsnConference *self = FS_MSN_CONFERENCE (user_data);
GST_OBJECT_LOCK (self);
- self->priv->participants =
- g_list_remove_all (self->priv->participants, where_the_object_was);
- GST_OBJECT_UNLOCK (self);
+ if (self->priv->participant == (FsMsnParticipant *) where_the_object_was)
+ self->priv->participant = NULL;
+ GST_OBJECT_UNLOCK (self);
}
@@ -332,32 +290,39 @@ fs_msn_conference_new_session (FsBaseConference *conf,
GError **error)
{
FsMsnConference *self = FS_MSN_CONFERENCE (conf);
- FsSession *new_session = NULL;
- guint id;
+ FsMsnSession *new_session = NULL;
- GST_OBJECT_LOCK (self);
- do
+ if (media_type != FS_MEDIA_TYPE_VIDEO)
{
- id = self->priv->max_session_id++;
+ g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+ "Only video supported for msn webcam");
}
- while (fs_msn_conference_get_session_by_id_locked (self, id));
- GST_OBJECT_UNLOCK (self);
- new_session = FS_SESSION_CAST (fs_msn_session_new (media_type, self, id,
- error));
-
- if (!new_session)
+ GST_OBJECT_LOCK (self);
+ if (self->priv->session)
{
+ GST_OBJECT_UNLOCK (self);
+ g_set_error (error, FS_ERROR, FS_ERROR_ALREADY_EXISTS,
+ "There already is a session");
return NULL;
}
- GST_OBJECT_LOCK (self);
- self->priv->sessions = g_list_append (self->priv->sessions, new_session);
GST_OBJECT_UNLOCK (self);
- g_object_weak_ref (G_OBJECT (new_session), _remove_session, self);
+ new_session = fs_msn_session_new (media_type, self, 1, error);
+
+ if (new_session)
+ g_object_weak_ref (G_OBJECT (new_session), _remove_session, self);
- return new_session;
+ GST_OBJECT_LOCK (self);
+ if (new_session)
+ {
+ self->priv->session = new_session;
+ g_object_weak_ref (G_OBJECT (new_session), _remove_session, self);
+ }
+ GST_OBJECT_UNLOCK (self);
+
+ return FS_SESSION (new_session);
}
@@ -367,52 +332,34 @@ fs_msn_conference_new_participant (FsBaseConference *conf,
GError **error)
{
FsMsnConference *self = FS_MSN_CONFERENCE (conf);
- FsParticipant *new_participant = NULL;
- GList *item = NULL;
-
- if (!cname)
- {
- g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
- "Invalid NULL cname");
- return NULL;
- }
+ FsMsnParticipant *new_participant = NULL;
GST_OBJECT_LOCK (self);
- for (item = g_list_first (self->priv->participants);
- item;
- item = g_list_next (item))
+ if (self->priv->participant)
{
- gchar *lcname;
-
- g_object_get (item->data, "cname", &lcname, NULL);
- if (!strcmp (lcname, cname))
- {
- g_free (lcname);
- break;
- }
- g_free (lcname);
- }
- GST_OBJECT_UNLOCK (self);
-
- if (item)
- {
- g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
- "There is already a participant with this cname");
+ GST_OBJECT_UNLOCK (self);
+ g_set_error (error, FS_ERROR, FS_ERROR_ALREADY_EXISTS,
+ "There already is a participant");
return NULL;
}
+ GST_OBJECT_UNLOCK (self);
- new_participant = FS_PARTICIPANT_CAST (fs_msn_participant_new (cname));
+ new_participant = fs_msn_participant_new (cname);
+ if (new_participant)
+ g_object_weak_ref (G_OBJECT (new_participant), _remove_participant, self);
GST_OBJECT_LOCK (self);
- self->priv->participants = g_list_append (self->priv->participants,
- new_participant);
+ if (new_participant)
+ {
+ self->priv->participant = new_participant;
+ g_object_weak_ref (G_OBJECT (new_participant), _remove_participant, self);
+ }
GST_OBJECT_UNLOCK (self);
- g_object_weak_ref (G_OBJECT (new_participant), _remove_participant, self);
+ return FS_PARTICIPANT (new_participant);
- return new_participant;
}
diff --git a/gst/fsmsnconference/fs-msn-conference.h b/gst/fsmsnconference/fs-msn-conference.h
index 6ab7232..84636f8 100644
--- a/gst/fsmsnconference/fs-msn-conference.h
+++ b/gst/fsmsnconference/fs-msn-conference.h
@@ -43,7 +43,6 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_INSTANCE_TYPE((obj),FS_TYPE_MSN_CONFERENCE))
#define FS_IS_MSN_CONFERENCE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),FS_TYPE_MSN_CONFERENCE))
-/* since 0.10.4 */
#define FS_MSN_CONFERENCE_CAST(obj) \
((FsMsnConference *)(obj))
--
1.5.6.5
More information about the farsight-commits
mailing list