Implement pipeline forcing
authorMikko Rasa <mikko.rasa@movial.fi>
Wed, 22 Oct 2008 10:05:50 +0000 (13:05 +0300)
committerMikko Rasa <mikko.rasa@movial.fi>
Wed, 22 Oct 2008 10:05:50 +0000 (13:05 +0300)
src/octopus-backend-gst.c
src/octopus-dbus.xml
src/octopus-route.c
src/octopus-route.h
src/octopus-server.c
src/octopus-server.h

index cd3f9d1..59a2409 100644 (file)
@@ -521,33 +521,53 @@ route_mapping_changed(OctopusRoute *route,
   OctopusComponent *component;
   gchar            **sources;
   gchar            **sinks;
+  gchar            *pipeline_desc;
   unsigned         i;
 
   g_debug("Route mapping changed");
 
   g_object_get(G_OBJECT(route), "backend", &backend,
                                 "sources", &sources,
-                                "sinks", &sinks, NULL);
+                                "sinks", &sinks,
+                                "pipeline-description", &pipeline_desc, NULL);
   g_assert(OCTOPUS_IS_BACKEND_GST(backend));
 
-  for(i = 0; sources[i]; ++i) {
-    GSList   *chain = NULL;
-    unsigned j;
+  if(pipeline_desc) {
+    RouteDataGst *data;
+    GError       *err;
 
-    component = octopus_backend_get_component_by_endpoint(backend, sources[i], OCTOPUS_ENDPOINT_SOURCE);
-    if(!component)
-      continue;
+    g_debug("Using forced pipeline description: %s", pipeline_desc);
 
-    for(j = 0; sinks[j]; ++j) {
-      if((chain = octopus_backend_build_component_chain(backend, component, sinks[j]))) {
-        realize_component_chain(backend, route, chain, NULL);
-        g_slist_free(chain);
-        break;
+    data = (RouteDataGst *)g_object_get_data(G_OBJECT(route), "data");
+    if(data->pipeline) {
+      gst_element_set_state(data->pipeline, GST_STATE_NULL);
+      gst_object_unref(data->pipeline);
+    }
+
+    data->pipeline = gst_parse_launch(pipeline_desc, &err);
+    if(data->pipeline)
+      data->ready = TRUE;
+    else
+      g_warning("Pipeline is invalid: %s", err->message);
+
+  } else {
+    for(i = 0; sources[i]; ++i) {
+      GSList   *chain = NULL;
+      unsigned j;
+
+      component = octopus_backend_get_component_by_endpoint(backend, sources[i], OCTOPUS_ENDPOINT_SOURCE);
+      if(!component)
+        continue;
+
+      for(j = 0; sinks[j]; ++j) {
+        if((chain = octopus_backend_build_component_chain(backend, component, sinks[j]))) {
+          realize_component_chain(backend, route, chain, NULL);
+          g_slist_free(chain);
+          break;
+        }
       }
     }
   }
-
-  /* TODO */
 }
 
 static void
index 5ae3ec6..4df4b92 100644 (file)
       <arg type="as" direction="out" name="sources" />
       <arg type="as" direction="out" name="destinations" />
     </method>
+
+    <!-- Special-casing and demo hacking -->
+    <method name="ForcePipeline">
+      <arg type="u" direction="in" name="id" />
+      <arg type="s" direction="in" name="pipline_desc" />
+    </method>
     
     <!-- Set an URI for an endpoint -->
     <method name="SetEndpointUri">
index f03bd63..f05f5b3 100644 (file)
@@ -26,7 +26,8 @@ enum
   PROP_ID = 1,
   PROP_BACKEND,
   PROP_SOURCES,
-  PROP_SINKS
+  PROP_SINKS,
+  PROP_PIPELINE_DESC
 };
 
 enum
@@ -46,6 +47,7 @@ struct _OctopusRoutePrivate
   GHashTable     *endpoints;
   gchar          **sources;
   gchar          **sinks;
+  gchar          *pipeline_desc;
 };
 
 static void
@@ -98,6 +100,10 @@ octopus_route_class_init(OctopusRouteClass *klass)
     g_param_spec_pointer("sinks", "Sinks", "Sink endpoints used for this route",
       G_PARAM_READABLE));
 
+  g_object_class_install_property(gobject_class, PROP_PIPELINE_DESC,
+    g_param_spec_string("pipeline-description", "PipelineDescription", "Forced pipeline description (backend specific)", NULL,
+      G_PARAM_READABLE));
+
   signals[SIGNAL_MAPPING_CHANGED] = 
         g_signal_new ("mapping-changed",
                       G_TYPE_FROM_CLASS(gobject_class),
@@ -222,6 +228,10 @@ get_property(GObject    *object,
   case PROP_SINKS:
     g_value_set_pointer(value, route->priv->sinks);
     break;
+  case PROP_PIPELINE_DESC:
+    if(route->priv->pipeline_desc)
+      g_value_set_string(value, route->priv->pipeline_desc);
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
   }
@@ -294,6 +304,20 @@ octopus_route_set_mapping              (OctopusRoute *route,
 }
 
 gboolean
+octopus_route_set_pipeline_description(OctopusRoute *route,
+                                       const gchar  *desc)
+{
+  OctopusRoutePrivate *priv = route->priv;
+
+  g_free(priv->pipeline_desc);
+  priv->pipeline_desc = g_strdup(desc);
+
+  g_signal_emit(route, signals[SIGNAL_MAPPING_CHANGED], 0);
+
+  return TRUE;
+}
+
+gboolean
 octopus_route_set_endpoint_uri(OctopusRoute *route,
                                const gchar  *ep_name,
                                const gchar  *uri)
index 4ff978a..31c728b 100644 (file)
@@ -74,6 +74,9 @@ octopus_route_set_mapping              (OctopusRoute *route,
                                         const gchar  *const *sources,
                                         const gchar  *const *sinks);
 gboolean
+octopus_route_set_pipeline_description (OctopusRoute *route,
+                                        const gchar  *desc);
+gboolean
 octopus_route_set_endpoint_uri         (OctopusRoute *route,
                                         const gchar  *ep_name,
                                         const gchar  *uri);
index 58ad301..902441c 100644 (file)
@@ -351,6 +351,28 @@ octopus_server_get_mapping(OctopusServer   *server,
 }
 
 gboolean
+octopus_server_force_pipeline  (OctopusServer   *server,
+                                gulong          id,
+                                const gchar     *desc,
+                                GError          **error)
+{
+  OctopusRoute *route;
+
+  g_assert(OCTOPUS_IS_SERVER (server));
+
+  if(!(route = get_route_by_id(server, id, error)))
+    return FALSE;
+
+  if(!octopus_route_set_pipeline_description(route, desc))
+  {
+    g_set_error(error, OCTOPUS_SERVER_ERROR, OCTOPUS_SERVER_ERROR_FAILED, "Could not set pipeline description");
+    return FALSE;
+  }
+
+  return TRUE;
+}
+
+gboolean
 octopus_server_set_endpoint_uri(OctopusServer   *server,
                                 guint32         id,
                                 const gchar     *ep_name,
index 7fd07eb..d29ac97 100644 (file)
@@ -106,6 +106,11 @@ octopus_server_get_mapping     (OctopusServer  *server,
                                 const gchar    ***dsts,
                                 GError         **error);
 gboolean
+octopus_server_force_pipeline  (OctopusServer   *server,
+                                gulong          id,
+                                const gchar     *desc,
+                                GError          **error);
+gboolean
 octopus_server_set_endpoint_uri(OctopusServer   *server,
                                 guint32         id,
                                 const gchar     *ep_name,