[telepathy-sofiasip/master] Implemented ImmutableStreams property on media channels

Mikhail Zabaluev mikhail.zabaluev at nokia.com
Fri Jan 8 10:38:34 PST 2010


It's controlled by the 'immutable-streams' boolean parameter of
the connection manager.
---
 src/media-factory.c          |    6 ++++++
 src/sip-connection-manager.c |    9 +++++++++
 src/sip-connection-private.h |    2 ++
 src/sip-connection.c         |   14 ++++++++++++++
 src/sip-media-channel.c      |   32 +++++++++++++++++++++++++++++++-
 5 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/src/media-factory.c b/src/media-factory.c
index cacd5d5..5ab4aa7 100644
--- a/src/media-factory.c
+++ b/src/media-factory.c
@@ -270,6 +270,7 @@ new_media_channel (TpsipMediaFactory *fac,
   const gchar *nat_traversal = "none";
   gboolean initial_audio;
   gboolean initial_video;
+  gboolean immutable_streams = FALSE;
 
   g_assert (initiator != 0);
 
@@ -284,6 +285,10 @@ new_media_channel (TpsipMediaFactory *fac,
   initial_audio = ((flags & TPSIP_MEDIA_CHANNEL_CREATE_WITH_AUDIO) != 0);
   initial_video = ((flags & TPSIP_MEDIA_CHANNEL_CREATE_WITH_VIDEO) != 0);
 
+  g_object_get (conn,
+      "immutable-streams", &immutable_streams,
+      NULL);
+
   if (priv->stun_server != NULL)
     {
       nat_traversal = "stun";
@@ -296,6 +301,7 @@ new_media_channel (TpsipMediaFactory *fac,
                        "initiator", initiator,
                        "initial-audio", initial_audio,
                        "initial-video", initial_video,
+                       "immutable-streams", immutable_streams,
                        "nat-traversal", nat_traversal,
                        NULL);
 
diff --git a/src/sip-connection-manager.c b/src/sip-connection-manager.c
index 73c57b6..42c2cd4 100644
--- a/src/sip-connection-manager.c
+++ b/src/sip-connection-manager.c
@@ -65,6 +65,7 @@ typedef struct {
     gboolean discover_stun;
     gchar *stun_server;
     guint stun_port;
+    gboolean immutable_streams;
     gchar *local_ip_address;
     guint local_port;
     gchar *extra_auth_user;
@@ -114,6 +115,7 @@ enum {
     TPSIP_CONN_PARAM_DISCOVER_STUN,
     TPSIP_CONN_PARAM_STUN_SERVER,
     TPSIP_CONN_PARAM_STUN_PORT,
+    TPSIP_CONN_PARAM_IMMUTABLE_STREAMS,
     TPSIP_CONN_PARAM_LOCAL_IP_ADDRESS,
     TPSIP_CONN_PARAM_LOCAL_PORT,
     TPSIP_CONN_PARAM_EXTRA_AUTH_USER,
@@ -180,6 +182,10 @@ static const TpCMParamSpec tpsip_params[] = {
       TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
       GUINT_TO_POINTER(TPSIP_DEFAULT_STUN_PORT),
       G_STRUCT_OFFSET (TpsipConnParams, stun_port) },
+    /* If the session content cannot be modified once initially set up */
+    { "immutable-streams", DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN,
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER(FALSE),
+      G_STRUCT_OFFSET (TpsipConnParams, immutable_streams) },
     /* Local IP address to use, workaround purposes only */
     { "local-ip-address", DBUS_TYPE_STRING_AS_STRING, G_TYPE_STRING,
       0, NULL, G_STRUCT_OFFSET (TpsipConnParams, local_ip_address) },
@@ -483,6 +489,9 @@ tpsip_connection_manager_new_connection (TpBaseConnectionManager *base,
   SET_PROPERTY_IF_PARAM_SET ("stun-port", TPSIP_CONN_PARAM_STUN_PORT,
       params->stun_port);
 
+  SET_PROPERTY_IF_PARAM_SET ("immutable-streams", TPSIP_CONN_PARAM_IMMUTABLE_STREAMS,
+      params->immutable_streams);
+
   SET_PROPERTY_IF_PARAM_SET ("keepalive-interval",
       TPSIP_CONN_PARAM_KEEPALIVE_INTERVAL, params->keepalive_interval);
 
diff --git a/src/sip-connection-private.h b/src/sip-connection-private.h
index 23ab575..5ff88b1 100644
--- a/src/sip-connection-private.h
+++ b/src/sip-connection-private.h
@@ -68,6 +68,8 @@ struct _TpsipConnectionPrivate
   gchar *extra_auth_password;
   gboolean loose_routing;
   gboolean discover_binding;
+  gboolean immutable_streams;
+
   gboolean keepalive_interval_specified;
 
   gboolean dispose_has_run;
diff --git a/src/sip-connection.c b/src/sip-connection.c
index 6c35ef9..1205fae 100644
--- a/src/sip-connection.c
+++ b/src/sip-connection.c
@@ -97,6 +97,7 @@ enum
   PROP_STUN_SERVER,        /**< STUN server address (if not set, derived
 			        from public SIP address */
   PROP_STUN_PORT,          /**< STUN port */
+  PROP_IMMUTABLE_STREAMS,  /**< If the session content is immutable once set up */
   PROP_LOCAL_IP_ADDRESS,   /**< Local IP address (normally not needed, chosen by stack) */
   PROP_LOCAL_PORT,         /**< Local port for SIP (normally not needed, chosen by stack) */
   PROP_EXTRA_AUTH_USER,	   /**< User name to use for extra authentication challenges */
@@ -280,6 +281,9 @@ tpsip_connection_set_property (GObject      *object,
     priv->stun_host = g_value_dup_string (value);
     break;
   }
+  case PROP_IMMUTABLE_STREAMS:
+    priv->immutable_streams = g_value_get_boolean (value);
+    break;
   case PROP_LOCAL_IP_ADDRESS: {
     g_free (priv->local_ip_address);
     priv->local_ip_address = g_value_dup_string (value);
@@ -377,6 +381,9 @@ tpsip_connection_get_property (GObject      *object,
     g_value_set_uint (value, priv->stun_port);
     break;
   }
+  case PROP_IMMUTABLE_STREAMS:
+    g_value_set_boolean (value, priv->immutable_streams);
+    break;
   case PROP_LOCAL_IP_ADDRESS: {
     g_value_set_string (value, priv->local_ip_address);
     break;
@@ -545,6 +552,13 @@ tpsip_connection_class_init (TpsipConnectionClass *klass)
       G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
   INST_PROP(PROP_STUN_PORT);
 
+  param_spec = g_param_spec_boolean ("immutable-streams", "Immutable streams",
+      "Set if additional streams cannot be requested on a media channel,"
+      " nor existing streams can be removed",
+      FALSE,
+      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  INST_PROP(PROP_IMMUTABLE_STREAMS);
+
   param_spec = g_param_spec_string ("local-ip-address", "Local IP address",
       "Local IP address to use",
       NULL,
diff --git a/src/sip-media-channel.c b/src/sip-media-channel.c
index ee06e27..927aa80 100644
--- a/src/sip-media-channel.c
+++ b/src/sip-media-channel.c
@@ -106,6 +106,7 @@ enum
   PROP_CHANNEL_PROPERTIES,
   PROP_INITIAL_AUDIO,
   PROP_INITIAL_VIDEO,
+  PROP_IMMUTABLE_STREAMS,
   /* Telepathy properties (see below too) */
   PROP_NAT_TRAVERSAL,
   PROP_STUN_SERVER,
@@ -143,6 +144,7 @@ struct _TpsipMediaChannelPrivate
 
   gboolean initial_audio;
   gboolean initial_video;
+  gboolean immutable_streams;
   gboolean closed;
   gboolean dispose_has_run;
 };
@@ -260,6 +262,7 @@ tpsip_media_channel_class_init (TpsipMediaChannelClass *klass)
   static TpDBusPropertiesMixinPropImpl streamed_media_props[] = {
       { "InitialAudio", "initial-audio", NULL },
       { "InitialVideo", "initial-video", NULL },
+      { "ImmutableStreams", "immutable-streams", NULL },
       { NULL }
   };
 
@@ -370,6 +373,13 @@ tpsip_media_channel_class_init (TpsipMediaChannelClass *klass)
   g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
       param_spec);
 
+  param_spec = g_param_spec_boolean ("immutable-streams", "ImmutableStreams",
+      "Whether the set of streams on this channel are fixed once requested",
+      FALSE,
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class, PROP_IMMUTABLE_STREAMS,
+      param_spec);
+
   tp_properties_mixin_class_init (object_class,
       G_STRUCT_OFFSET (TpsipMediaChannelClass, properties_class),
       media_channel_property_signatures, NUM_TP_PROPS, NULL);
@@ -461,6 +471,7 @@ tpsip_media_channel_get_property (GObject    *object,
               TP_IFACE_CHANNEL, "Interfaces",
               TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, "InitialAudio",
               TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, "InitialVideo",
+              TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, "ImmutableStreams",
               NULL));
       break;
     case PROP_INITIAL_AUDIO:
@@ -469,6 +480,9 @@ tpsip_media_channel_get_property (GObject    *object,
     case PROP_INITIAL_VIDEO:
       g_value_set_boolean (value, priv->initial_video);
       break;
+    case PROP_IMMUTABLE_STREAMS:
+      g_value_set_boolean (value, priv->immutable_streams);
+      break;
     default:
       /* Some properties live in the mixin */
       {
@@ -535,6 +549,9 @@ tpsip_media_channel_set_property (GObject     *object,
     case PROP_INITIAL_VIDEO:
       priv->initial_video = g_value_get_boolean (value);
       break;
+    case PROP_IMMUTABLE_STREAMS:
+      priv->immutable_streams = g_value_get_boolean (value);
+      break;
     default:
       /* some properties live in the mixin */
       {
@@ -812,7 +829,12 @@ tpsip_media_channel_remove_streams (TpSvcChannelTypeStreamedMedia *iface,
 
   priv = TPSIP_MEDIA_CHANNEL_GET_PRIVATE (self);
 
-  if (priv->session != NULL)
+  if (priv->immutable_streams)
+    {
+      error = g_error_new (TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+          "Cannot remove streams from the existing channel");
+    }
+  else if (priv->session != NULL)
     {
        tpsip_media_session_remove_streams(priv->session,
                                         streams,
@@ -899,6 +921,14 @@ tpsip_media_channel_request_streams (TpSvcChannelTypeStreamedMedia *iface,
 
   priv = TPSIP_MEDIA_CHANNEL_GET_PRIVATE (self);
 
+  if (priv->immutable_streams)
+    {
+      GError e = { TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED,
+          "Cannot add streams to the existing channel" };
+      dbus_g_method_return_error (context, &e);
+      return;
+    }
+
   contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *)(priv->conn), TP_HANDLE_TYPE_CONTACT);
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list