[farsight2/master] msn: Implement ths ToS property
Olivier Crête
olivier.crete at collabora.co.uk
Sat Jul 25 12:04:23 PDT 2009
---
docs/plugins/farsight2-plugins-sections.txt | 1 +
gst/fsmsnconference/fs-msn-session.c | 23 ++++++++++++++++++++-
gst/fsmsnconference/fs-msn-stream.c | 29 +++++++++++++++++++++++++++
gst/fsmsnconference/fs-msn-stream.h | 2 +
tests/check/msn/conference.c | 5 ++++
5 files changed, 59 insertions(+), 1 deletions(-)
diff --git a/docs/plugins/farsight2-plugins-sections.txt b/docs/plugins/farsight2-plugins-sections.txt
index 2f2d5e3..cd07305 100644
--- a/docs/plugins/farsight2-plugins-sections.txt
+++ b/docs/plugins/farsight2-plugins-sections.txt
@@ -313,6 +313,7 @@ FsMsnStreamPrivate
fs_msn_stream_get_type
<SUBSECTION Private>
fs_msn_stream_new
+fs_msn_stream_set_tos_locked
</SECTION>
diff --git a/gst/fsmsnconference/fs-msn-session.c b/gst/fsmsnconference/fs-msn-session.c
index 6738da9..c1be018 100644
--- a/gst/fsmsnconference/fs-msn-session.c
+++ b/gst/fsmsnconference/fs-msn-session.c
@@ -74,7 +74,8 @@ enum
PROP_CODECS_WITHOUT_CONFIG,
PROP_CURRENT_SEND_CODEC,
PROP_CODECS_READY,
- PROP_CONFERENCE
+ PROP_CONFERENCE,
+ PROP_TOS
};
@@ -90,6 +91,8 @@ struct _FsMsnSessionPrivate
GstPad *media_sink_pad;
+ guint tos; /* Protected by conf lock */
+
GMutex *mutex; /* protects the conference */
};
@@ -161,6 +164,8 @@ fs_msn_session_class_init (FsMsnSessionClass *klass)
PROP_CURRENT_SEND_CODEC, "current-send-codec");
g_object_class_override_property (gobject_class,
PROP_CODECS_READY, "codecs-ready");
+ g_object_class_override_property (gobject_class,
+ PROP_TOS, "tos");
g_object_class_install_property (gobject_class,
PROP_CONFERENCE,
@@ -312,6 +317,11 @@ fs_msn_session_get_property (GObject *object,
g_value_take_boxed (value, send_codec);
break;
}
+ case PROP_TOS:
+ GST_OBJECT_LOCK (conference);
+ g_value_set_uint (value, self->priv->tos);
+ GST_OBJECT_UNLOCK (conference);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -343,6 +353,13 @@ fs_msn_session_set_property (GObject *object,
case PROP_CONFERENCE:
self->priv->conference = FS_MSN_CONFERENCE (g_value_dup_object (value));
break;
+ case PROP_TOS:
+ GST_OBJECT_LOCK (conference);
+ self->priv->tos = g_value_get_uint (value);
+ if (self->priv->stream)
+ fs_msn_stream_set_tos_locked (self->priv->stream, self->priv->tos);
+ GST_OBJECT_UNLOCK (conference);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -483,10 +500,14 @@ fs_msn_session_new_stream (FsSession *session,
}
self->priv->stream = (FsMsnStream *) new_stream;
g_object_weak_ref (G_OBJECT (new_stream), _remove_stream, self);
+
+ if (self->priv->tos)
+ fs_msn_stream_set_tos_locked (self->priv->stream, self->priv->tos);
GST_OBJECT_UNLOCK (conference);
}
gst_object_unref (conference);
+
return new_stream;
already_have_stream:
diff --git a/gst/fsmsnconference/fs-msn-stream.c b/gst/fsmsnconference/fs-msn-stream.c
index 5e43552..8e5283f 100644
--- a/gst/fsmsnconference/fs-msn-stream.c
+++ b/gst/fsmsnconference/fs-msn-stream.c
@@ -96,6 +96,9 @@ struct _FsMsnStreamPrivate
guint session_id;
guint initial_port;
+ gint fd;
+ gint tos;
+
GMutex *mutex; /* protects the conference */
};
@@ -202,6 +205,7 @@ fs_msn_stream_init (FsMsnStream *self)
self->priv->session = NULL;
self->priv->participant = NULL;
+ self->priv->fd = -1;
self->priv->direction = FS_DIRECTION_NONE;
@@ -605,6 +609,7 @@ _connected (
goto error;
}
+
if (self->priv->conference->max_direction == FS_DIRECTION_RECV)
pad = gst_element_get_static_pad (codecbin, "src");
else
@@ -628,6 +633,7 @@ _connected (
}
GST_OBJECT_LOCK (conference);
+ self->priv->fd = fd;
self->priv->codecbin = gst_object_ref (codecbin);
GST_OBJECT_UNLOCK (conference);
@@ -731,6 +737,7 @@ _connected (
if (self->priv->conference->max_direction == FS_DIRECTION_SEND)
{
GST_OBJECT_LOCK (conference);
+ fs_msn_stream_set_tos_locked (self, self->priv->tos);
drop = !(self->priv->direction & FS_DIRECTION_SEND);
GST_OBJECT_UNLOCK (conference);
g_object_set (send_valve, "drop", drop, NULL);
@@ -756,6 +763,10 @@ _connection_failed (FsMsnConnection *connection, FsMsnStream *self)
if (!conference)
return;
+ GST_OBJECT_LOCK (conference);
+ self->priv->fd = -1;
+ GST_OBJECT_UNLOCK (conference);
+
gst_element_post_message (GST_ELEMENT (conference),
gst_message_new_element (GST_OBJECT (conference),
gst_structure_new ("farsight-component-state-changed",
@@ -871,3 +882,21 @@ fs_msn_stream_new (FsMsnSession *session,
return self;
}
+void
+fs_msn_stream_set_tos_locked (FsMsnStream *self, gint tos)
+{
+ self->priv->tos = tos;
+
+ if (self->priv->fd < 0)
+ return;
+
+ if (setsockopt (self->priv->fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0)
+ GST_WARNING ( "could not set socket ToS: %s", g_strerror (errno));
+
+#ifdef IPV6_TCLASS
+ if (setsockopt (self->priv->fd, IPPROTO_IPV6, IPV6_TCLASS,
+ &tos, sizeof (tos)) < 0)
+ GST_WARNING ("could not set TCLASS: %s", g_strerror (errno));
+#endif
+}
+
diff --git a/gst/fsmsnconference/fs-msn-stream.h b/gst/fsmsnconference/fs-msn-stream.h
index 4030b41..5818c67 100644
--- a/gst/fsmsnconference/fs-msn-stream.h
+++ b/gst/fsmsnconference/fs-msn-stream.h
@@ -81,6 +81,8 @@ FsMsnStream *fs_msn_stream_new (FsMsnSession *session,
GParameter *parameters,
GError **error);
+void fs_msn_stream_set_tos_locked (FsMsnStream *self, gint tos);
+
G_END_DECLS
diff --git a/tests/check/msn/conference.c b/tests/check/msn/conference.c
index 22abd56..ce8c020 100644
--- a/tests/check/msn/conference.c
+++ b/tests/check/msn/conference.c
@@ -210,6 +210,7 @@ setup_conference (FsStreamDirection dir, struct SimpleMsnConference *target)
GstBus *bus;
GParameter param = {NULL, {0}};
gint n_params = 0;
+ guint tos;
dat->target = target;
dat->direction = dir;
@@ -241,6 +242,10 @@ setup_conference (FsStreamDirection dir, struct SimpleMsnConference *target)
error ? error->message : "No GError");
ts_fail_unless (error == NULL);
+ g_object_set (dat->session, "tos", 2, NULL);
+ g_object_get (dat->session, "tos", &tos, NULL);
+ ts_fail_unless (tos == 2);
+
if (dir == FS_DIRECTION_SEND)
{
GstPad *sinkpad, *srcpad;
--
1.5.6.5
More information about the farsight-commits
mailing list