client: add vmethod to configure media and streams
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-client.c
index c82d4a2..0822727 100644 (file)
@@ -127,12 +127,16 @@ static void client_session_finalized (GstRTSPClient * client,
     GstRTSPSession * session);
 static void unlink_session_transports (GstRTSPClient * client,
     GstRTSPSession * session, GstRTSPSessionMedia * sessmedia);
+static gboolean default_configure_client_media (GstRTSPClient * client,
+    GstRTSPMedia * media, GstRTSPStream * stream, GstRTSPContext * ctx);
 static gboolean default_configure_client_transport (GstRTSPClient * client,
     GstRTSPContext * ctx, GstRTSPTransport * ct);
 static GstRTSPResult default_params_set (GstRTSPClient * client,
     GstRTSPContext * ctx);
 static GstRTSPResult default_params_get (GstRTSPClient * client,
     GstRTSPContext * ctx);
+static gchar *default_make_path_from_uri (GstRTSPClient * client,
+    const GstRTSPUrl * uri);
 
 G_DEFINE_TYPE (GstRTSPClient, gst_rtsp_client, G_TYPE_OBJECT);
 
@@ -150,9 +154,11 @@ gst_rtsp_client_class_init (GstRTSPClientClass * klass)
   gobject_class->finalize = gst_rtsp_client_finalize;
 
   klass->create_sdp = create_sdp;
+  klass->configure_client_media = default_configure_client_media;
   klass->configure_client_transport = default_configure_client_transport;
   klass->params_set = default_params_set;
   klass->params_get = default_params_get;
+  klass->make_path_from_uri = default_make_path_from_uri;
 
   g_object_class_install_property (gobject_class, PROP_SESSION_POOL,
       g_param_spec_object ("session-pool", "Session Pool",
@@ -480,20 +486,14 @@ paths_are_equal (const gchar * path1, const gchar * path2, gint len2)
  * but is cached for when the same client (without breaking the connection) is
  * doing a setup for the exact same url. */
 static GstRTSPMedia *
-find_media (GstRTSPClient * client, GstRTSPContext * ctx, gint * matched)
+find_media (GstRTSPClient * client, GstRTSPContext * ctx, gchar * path,
+    gint * matched)
 {
   GstRTSPClientPrivate *priv = client->priv;
   GstRTSPMediaFactory *factory;
   GstRTSPMedia *media;
-  gchar *path;
   gint path_len;
 
-  if (!priv->mount_points)
-    goto no_mount_points;
-
-  if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
-    goto no_path;
-
   /* find the longest matching factory for the uri first */
   if (!(factory = gst_rtsp_mount_points_match (priv->mount_points,
               path, matched)))
@@ -553,7 +553,6 @@ find_media (GstRTSPClient * client, GstRTSPContext * ctx, gint * matched)
 
   g_object_unref (factory);
   ctx->factory = NULL;
-  g_free (path);
 
   if (media)
     g_object_ref (media);
@@ -561,44 +560,31 @@ find_media (GstRTSPClient * client, GstRTSPContext * ctx, gint * matched)
   return media;
 
   /* ERRORS */
-no_mount_points:
-  {
-    GST_ERROR ("client %p: no mount points configured", client);
-    send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
-    return NULL;
-  }
-no_path:
-  {
-    GST_ERROR ("client %p: can't find path for url", client);
-    send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
-    return NULL;
-  }
 no_factory:
   {
-    GST_ERROR ("client %p: no factory for uri %s", client, path);
-    g_free (path);
+    GST_ERROR ("client %p: no factory for path %s", client, path);
     send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
     return NULL;
   }
 no_factory_access:
   {
-    GST_ERROR ("client %p: not authorized to see factory uri %s", client, path);
-    g_free (path);
+    GST_ERROR ("client %p: not authorized to see factory path %s", client,
+        path);
+    /* error reply is already sent */
     return NULL;
   }
 not_authorized:
   {
-    GST_ERROR ("client %p: not authorized for factory uri %s", client, path);
-    g_free (path);
+    GST_ERROR ("client %p: not authorized for factory path %s", client, path);
+    /* error reply is already sent */
     return NULL;
   }
 no_media:
   {
     GST_ERROR ("client %p: can't create media", client);
-    send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
+    send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
     g_object_unref (factory);
     ctx->factory = NULL;
-    g_free (path);
     return NULL;
   }
 no_thread:
@@ -609,7 +595,6 @@ no_thread:
     ctx->media = NULL;
     g_object_unref (factory);
     ctx->factory = NULL;
-    g_free (path);
     return NULL;
   }
 no_prepare:
@@ -620,7 +605,6 @@ no_prepare:
     ctx->media = NULL;
     g_object_unref (factory);
     ctx->factory = NULL;
-    g_free (path);
     return NULL;
   }
 }
@@ -733,14 +717,28 @@ close_connection (GstRTSPClient * client)
   gst_rtsp_connection_close (priv->connection);
 }
 
+static gchar *
+default_make_path_from_uri (GstRTSPClient * client, const GstRTSPUrl * uri)
+{
+  gchar *path;
+
+  if (uri->query)
+    path = g_strconcat (uri->abspath, "?", uri->query, NULL);
+  else
+    path = g_strdup (uri->abspath);
+
+  return path;
+}
+
 static gboolean
 handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
 {
   GstRTSPClientPrivate *priv = client->priv;
+  GstRTSPClientClass *klass;
   GstRTSPSession *session;
   GstRTSPSessionMedia *sessmedia;
   GstRTSPStatusCode code;
-  const gchar *path;
+  gchar *path;
   gint matched;
 
   if (!ctx->session)
@@ -751,7 +749,8 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
   if (!ctx->uri)
     goto no_uri;
 
-  path = ctx->uri->abspath;
+  klass = GST_RTSP_CLIENT_GET_CLASS (client);
+  path = klass->make_path_from_uri (client, ctx->uri);
 
   /* get a handle to the configuration of the media in the session */
   sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@@ -762,6 +761,8 @@ handle_teardown_request (GstRTSPClient * client, GstRTSPContext * ctx)
   if (path[matched] != '\0')
     goto no_aggregate;
 
+  g_free (path);
+
   ctx->sessmedia = sessmedia;
 
   /* we emit the signal before closing the connection */
@@ -808,6 +809,7 @@ not_found:
   {
     GST_ERROR ("client %p: no media for uri", client);
     send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    g_free (path);
     return FALSE;
   }
 no_aggregate:
@@ -815,6 +817,7 @@ no_aggregate:
     GST_ERROR ("client %p: no aggregate path %s", client, path);
     send_generic_response (client,
         GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
+    g_free (path);
     return FALSE;
   }
 }
@@ -917,10 +920,11 @@ static gboolean
 handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
 {
   GstRTSPSession *session;
+  GstRTSPClientClass *klass;
   GstRTSPSessionMedia *sessmedia;
   GstRTSPStatusCode code;
   GstRTSPState rtspstate;
-  const gchar *path;
+  gchar *path;
   gint matched;
 
   if (!(session = ctx->session))
@@ -929,7 +933,8 @@ handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
   if (!ctx->uri)
     goto no_uri;
 
-  path = ctx->uri->abspath;
+  klass = GST_RTSP_CLIENT_GET_CLASS (client);
+  path = klass->make_path_from_uri (client, ctx->uri);
 
   /* get a handle to the configuration of the media in the session */
   sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@@ -939,6 +944,8 @@ handle_pause_request (GstRTSPClient * client, GstRTSPContext * ctx)
   if (path[matched] != '\0')
     goto no_aggregate;
 
+  g_free (path);
+
   ctx->sessmedia = sessmedia;
 
   rtspstate = gst_rtsp_session_media_get_rtsp_state (sessmedia);
@@ -984,6 +991,7 @@ not_found:
   {
     GST_ERROR ("client %p: no media for uri", client);
     send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    g_free (path);
     return FALSE;
   }
 no_aggregate:
@@ -991,6 +999,7 @@ no_aggregate:
     GST_ERROR ("client %p: no aggregate path %s", client, path);
     send_generic_response (client,
         GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
+    g_free (path);
     return FALSE;
   }
 invalid_state:
@@ -1002,13 +1011,37 @@ invalid_state:
   }
 }
 
+/* convert @url and @path to a URL used as a content base for the factory
+ * located at @path */
+static gchar *
+make_base_url (GstRTSPClient * client, GstRTSPUrl * url, gchar * path)
+{
+  GstRTSPUrl tmp;
+  gchar *result, *trail;
+
+  /* check for trailing '/' and append one */
+  trail = (path[strlen (path) - 1] != '/' ? "/" : "");
+
+  tmp = *url;
+  tmp.user = NULL;
+  tmp.passwd = NULL;
+  tmp.abspath = g_strdup_printf ("%s%s", path, trail);
+  tmp.query = NULL;
+  result = gst_rtsp_url_get_request_uri (&tmp);
+  g_free (tmp.abspath);
+
+  return result;
+}
+
 static gboolean
 handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
 {
   GstRTSPSession *session;
+  GstRTSPClientClass *klass;
   GstRTSPSessionMedia *sessmedia;
   GstRTSPMedia *media;
   GstRTSPStatusCode code;
+  GstRTSPUrl *uri;
   GString *rtpinfo;
   guint n_streams, i, infocount;
   gchar *str;
@@ -1016,16 +1049,17 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
   GstRTSPResult res;
   GstRTSPState rtspstate;
   GstRTSPRangeUnit unit = GST_RTSP_RANGE_NPT;
-  const gchar *path;
+  gchar *path;
   gint matched;
 
   if (!(session = ctx->session))
     goto no_session;
 
-  if (!ctx->uri)
+  if (!(uri = ctx->uri))
     goto no_uri;
 
-  path = ctx->uri->abspath;
+  klass = GST_RTSP_CLIENT_GET_CLASS (client);
+  path = klass->make_path_from_uri (client, uri);
 
   /* get a handle to the configuration of the media in the session */
   sessmedia = gst_rtsp_session_get_media (session, path, &matched);
@@ -1043,6 +1077,10 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
   if (rtspstate != GST_RTSP_STATE_PLAYING && rtspstate != GST_RTSP_STATE_READY)
     goto invalid_state;
 
+  /* in play we first unsuspend, media could be suspended from SDP or PAUSED */
+  if (!gst_rtsp_media_unsuspend (media))
+    goto unsuspend_failed;
+
   /* parse the range header if we have one */
   res = gst_rtsp_message_get_header (ctx->request, GST_RTSP_HDR_RANGE, &str, 0);
   if (res == GST_RTSP_OK) {
@@ -1062,7 +1100,6 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
     GstRTSPStreamTransport *trans;
     GstRTSPStream *stream;
     const GstRTSPTransport *tr;
-    gchar *uristr;
     guint rtptime, seq;
 
     /* get the transport, if there is no transport configured, skip this stream */
@@ -1080,19 +1117,24 @@ handle_play_request (GstRTSPClient * client, GstRTSPContext * ctx)
 
     stream = gst_rtsp_stream_transport_get_stream (trans);
     if (gst_rtsp_stream_get_rtpinfo (stream, &rtptime, &seq)) {
+      const GstRTSPUrl *url;
+      gchar *url_str;
+
       if (infocount > 0)
         g_string_append (rtpinfo, ", ");
 
-      uristr = gst_rtsp_url_get_request_uri (ctx->uri);
-      g_string_append_printf (rtpinfo, "url=%s/stream=%d;seq=%u;rtptime=%u",
-          uristr, i, seq, rtptime);
-      g_free (uristr);
+      url = gst_rtsp_stream_transport_get_url (trans);
+      url_str = gst_rtsp_url_get_request_uri (url);
+      g_string_append_printf (rtpinfo, "url=%s;seq=%u;rtptime=%u",
+          url_str, seq, rtptime);
+      g_free (url_str);
 
       infocount++;
     } else {
       GST_WARNING ("RTP-Info cannot be determined for stream %d", i);
     }
   }
+  g_free (path);
 
   /* construct the response now */
   code = GST_RTSP_STS_OK;
@@ -1147,6 +1189,7 @@ no_aggregate:
     GST_ERROR ("client %p: no aggregate path %s", client, path);
     send_generic_response (client,
         GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED, ctx);
+    g_free (path);
     return FALSE;
   }
 invalid_state:
@@ -1154,6 +1197,14 @@ invalid_state:
     GST_ERROR ("client %p: not PLAYING or READY", client);
     send_generic_response (client, GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
         ctx);
+    g_free (path);
+    return FALSE;
+  }
+unsuspend_failed:
+  {
+    GST_ERROR ("client %p: unsuspend failed", client);
+    send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
+    g_free (path);
     return FALSE;
   }
 }
@@ -1217,11 +1268,11 @@ parse_transport (const char *transport, GstRTSPLowerTrans supported,
 }
 
 static gboolean
-handle_blocksize (GstRTSPMedia * media, GstRTSPStream * stream,
-    GstRTSPMessage * request)
+default_configure_client_media (GstRTSPClient * client, GstRTSPMedia * media,
+    GstRTSPStream * stream, GstRTSPContext * ctx)
 {
+  GstRTSPMessage *request = ctx->request;
   gchar *blocksize_str;
-  gboolean ret = TRUE;
 
   if (gst_rtsp_message_get_header (request, GST_RTSP_HDR_BLOCKSIZE,
           &blocksize_str, 0) == GST_RTSP_OK) {
@@ -1229,21 +1280,29 @@ handle_blocksize (GstRTSPMedia * media, GstRTSPStream * stream,
     gchar *end;
 
     blocksize = g_ascii_strtoull (blocksize_str, &end, 10);
-    if (end == blocksize_str) {
-      GST_ERROR ("failed to parse blocksize");
-      ret = FALSE;
-    } else {
-      /* we don't want to change the mtu when this media
-       * can be shared because it impacts other clients */
-      if (gst_rtsp_media_is_shared (media))
-        return TRUE;
-
-      if (blocksize > G_MAXUINT)
-        blocksize = G_MAXUINT;
-      gst_rtsp_stream_set_mtu (stream, blocksize);
-    }
+    if (end == blocksize_str)
+      goto parse_failed;
+
+    /* we don't want to change the mtu when this media
+     * can be shared because it impacts other clients */
+    if (gst_rtsp_media_is_shared (media))
+      goto done;
+
+    if (blocksize > G_MAXUINT)
+      blocksize = G_MAXUINT;
+
+    gst_rtsp_stream_set_mtu (stream, blocksize);
+  }
+done:
+  return TRUE;
+
+  /* ERRORS */
+parse_failed:
+  {
+    GST_ERROR_OBJECT (client, "failed to parse blocksize");
+    send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
+    return FALSE;
   }
-  return ret;
 }
 
 static gboolean
@@ -1384,7 +1443,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
     goto no_uri;
 
   uri = ctx->uri;
-  path = uri->abspath;
+  klass = GST_RTSP_CLIENT_GET_CLASS (client);
+  path = klass->make_path_from_uri (client, uri);
 
   /* parse the transport */
   res =
@@ -1413,16 +1473,21 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
   /* we have no session media, find one and manage it */
   if (sessmedia == NULL) {
     /* get a handle to the configuration of the media in the session */
-    media = find_media (client, ctx, &matched);
+    media = find_media (client, ctx, path, &matched);
   } else {
     if ((media = gst_rtsp_session_media_get_media (sessmedia)))
       g_object_ref (media);
+    else
+      goto media_not_found;
   }
   /* no media, not found then */
   if (media == NULL)
-    goto media_not_found;
+    goto media_not_found_no_reply;
+
+  if (path[matched] == '\0')
+    goto control_not_found;
 
-  /* path is what matched. We can modify the parsed uri in place */
+  /* path is what matched. */
   path[matched] = '\0';
   /* control is remainder */
   control = &path[matched + 1];
@@ -1464,9 +1529,8 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
 
   ctx->sessmedia = sessmedia;
 
-  /* set blocksize on this stream */
-  if (!handle_blocksize (media, stream, ctx->request))
-    goto invalid_blocksize;
+  if (!klass->configure_client_media (client, media, stream, ctx))
+    goto configure_media_failed_no_reply;
 
   gst_rtsp_transport_new (&ct);
 
@@ -1478,13 +1542,16 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
     goto unsupported_transports;
 
   /* update the client transport */
-  klass = GST_RTSP_CLIENT_GET_CLASS (client);
   if (!klass->configure_client_transport (client, ctx, ct))
     goto unsupported_client_transport;
 
   /* set in the session media transport */
   trans = gst_rtsp_session_media_set_transport (sessmedia, stream, ct);
 
+  /* configure the url used to set this transport, this we will use when
+   * generating the response for the PLAY request */
+  gst_rtsp_stream_transport_set_url (trans, uri);
+
   /* configure keepalive for this transport */
   gst_rtsp_stream_transport_set_keepalive (trans,
       (GstRTSPKeepAliveFunc) do_keepalive, session, NULL);
@@ -1518,6 +1585,7 @@ handle_setup_request (GstRTSPClient * client, GstRTSPContext * ctx)
       break;
   }
   g_object_unref (session);
+  g_free (path);
 
   g_signal_emit (client, gst_rtsp_client_signals[SIGNAL_SETUP_REQUEST], 0, ctx);
 
@@ -1534,18 +1602,36 @@ no_transport:
   {
     GST_ERROR ("client %p: no transport", client);
     send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
+    g_free (path);
     return FALSE;
   }
 no_pool:
   {
     GST_ERROR ("client %p: no session pool configured", client);
     send_generic_response (client, GST_RTSP_STS_SESSION_NOT_FOUND, ctx);
+    g_free (path);
+    return FALSE;
+  }
+media_not_found_no_reply:
+  {
+    GST_ERROR ("client %p: media '%s' not found", client, path);
+    g_free (path);
+    /* error reply is already sent */
     return FALSE;
   }
 media_not_found:
   {
     GST_ERROR ("client %p: media '%s' not found", client, path);
     send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    g_free (path);
+    return FALSE;
+  }
+control_not_found:
+  {
+    GST_ERROR ("client %p: no control in path '%s'", client, path);
+    send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    g_object_unref (media);
+    g_free (path);
     return FALSE;
   }
 stream_not_found:
@@ -1553,6 +1639,7 @@ stream_not_found:
     GST_ERROR ("client %p: stream '%s' not found", client, control);
     send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
     g_object_unref (media);
+    g_free (path);
     return FALSE;
   }
 service_unavailable:
@@ -1560,6 +1647,7 @@ service_unavailable:
     GST_ERROR ("client %p: can't create session", client);
     send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
     g_object_unref (media);
+    g_free (path);
     return FALSE;
   }
 sessmedia_unavailable:
@@ -1568,13 +1656,15 @@ sessmedia_unavailable:
     send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
     g_object_unref (media);
     g_object_unref (session);
+    g_free (path);
     return FALSE;
   }
-invalid_blocksize:
+configure_media_failed_no_reply:
   {
-    GST_ERROR ("client %p: invalid blocksize", client);
-    send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
+    GST_ERROR ("client %p: configure_media failed", client);
     g_object_unref (session);
+    g_free (path);
+    /* error reply is already sent */
     return FALSE;
   }
 unsupported_transports:
@@ -1583,6 +1673,7 @@ unsupported_transports:
     send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
     gst_rtsp_transport_free (ct);
     g_object_unref (session);
+    g_free (path);
     return FALSE;
   }
 unsupported_client_transport:
@@ -1591,6 +1682,7 @@ unsupported_client_transport:
     send_generic_response (client, GST_RTSP_STS_UNSUPPORTED_TRANSPORT, ctx);
     gst_rtsp_transport_free (ct);
     g_object_unref (session);
+    g_free (path);
     return FALSE;
   }
 }
@@ -1645,10 +1737,11 @@ no_sdp:
 static gboolean
 handle_describe_request (GstRTSPClient * client, GstRTSPContext * ctx)
 {
+  GstRTSPClientPrivate *priv = client->priv;
   GstRTSPResult res;
   GstSDPMessage *sdp;
-  guint i, str_len;
-  gchar *str, *str_query, *content_base;
+  guint i;
+  gchar *path, *str;
   GstRTSPMedia *media;
   GstRTSPClientClass *klass;
 
@@ -1672,14 +1765,22 @@ handle_describe_request (GstRTSPClient * client, GstRTSPContext * ctx)
       break;
   }
 
+  if (!priv->mount_points)
+    goto no_mount_points;
+
+  if (!(path = gst_rtsp_mount_points_make_path (priv->mount_points, ctx->uri)))
+    goto no_path;
+
   /* find the media object for the uri */
-  if (!(media = find_media (client, ctx, NULL)))
+  if (!(media = find_media (client, ctx, path, NULL)))
     goto no_media;
 
   /* create an SDP for the media object on this client */
   if (!(sdp = klass->create_sdp (client, media)))
     goto no_sdp;
 
+  /* we suspend after the describe */
+  gst_rtsp_media_suspend (media);
   g_object_unref (media);
 
   gst_rtsp_message_init_response (ctx->response, GST_RTSP_STS_OK,
@@ -1689,32 +1790,11 @@ handle_describe_request (GstRTSPClient * client, GstRTSPContext * ctx)
       "application/sdp");
 
   /* content base for some clients that might screw up creating the setup uri */
-  str = gst_rtsp_url_get_request_uri (ctx->uri);
-  str_len = strlen (str);
-
-  /* check for query part */
-  if (ctx->uri->query != NULL) {
-    str_query = g_strrstr (str, "?");
-    *str_query = '\0';
-    str_len = strlen (str);
-  }
-
-  /* check for trailing '/' and append one */
-  if (str[str_len - 1] != '/') {
-    content_base = g_malloc (str_len + 2);
-    memcpy (content_base, str, str_len);
-    content_base[str_len] = '/';
-    content_base[str_len + 1] = '\0';
-    g_free (str);
-  } else {
-    content_base = str;
-  }
-
-  GST_INFO ("adding content-base: %s", content_base);
+  str = make_base_url (client, ctx->uri, path);
+  g_free (path);
 
-  gst_rtsp_message_add_header (ctx->response, GST_RTSP_HDR_CONTENT_BASE,
-      content_base);
-  g_free (content_base);
+  GST_INFO ("adding content-base: %s", str);
+  gst_rtsp_message_take_header (ctx->response, GST_RTSP_HDR_CONTENT_BASE, str);
 
   /* add SDP to the response body */
   str = gst_sdp_message_as_text (sdp);
@@ -1735,9 +1815,22 @@ no_uri:
     send_generic_response (client, GST_RTSP_STS_BAD_REQUEST, ctx);
     return FALSE;
   }
+no_mount_points:
+  {
+    GST_ERROR ("client %p: no mount points configured", client);
+    send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    return FALSE;
+  }
+no_path:
+  {
+    GST_ERROR ("client %p: can't find path for url", client);
+    send_generic_response (client, GST_RTSP_STS_NOT_FOUND, ctx);
+    return FALSE;
+  }
 no_media:
   {
     GST_ERROR ("client %p: no media", client);
+    g_free (path);
     /* error reply is already sent */
     return FALSE;
   }
@@ -1745,6 +1838,7 @@ no_sdp:
   {
     GST_ERROR ("client %p: can't create SDP", client);
     send_generic_response (client, GST_RTSP_STS_SERVICE_UNAVAILABLE, ctx);
+    g_free (path);
     g_object_unref (media);
     return FALSE;
   }
@@ -1853,10 +1947,12 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
     gst_rtsp_message_dump (request);
   }
 
-  GST_INFO ("client %p: received a request", client);
-
   gst_rtsp_message_parse_request (request, &method, &uristr, &version);
 
+  GST_INFO ("client %p: received a request %s %s %s", client,
+      gst_rtsp_method_as_text (method), uristr,
+      gst_rtsp_version_as_text (version));
+
   /* we can only handle 1.0 requests */
   if (version != GST_RTSP_VERSION_1_0)
     goto not_supported;
@@ -1866,8 +1962,35 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request)
   /* we always try to parse the url first */
   if (strcmp (uristr, "*") == 0) {
     /* special case where we have * as uri, keep uri = NULL */
-  } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK)
-    goto bad_request;
+  } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) {
+    /* check if the uristr is an absolute path <=> scheme and host information
+     * is missing */
+    gchar *scheme;
+
+    scheme = g_uri_parse_scheme (uristr);
+    if (scheme == NULL && g_str_has_prefix (uristr, "/")) {
+      gchar *absolute_uristr = NULL;
+
+      GST_WARNING_OBJECT (client, "request doesn't contain absolute url");
+      if (priv->server_ip == NULL) {
+        GST_WARNING_OBJECT (client, "host information missing");
+        goto bad_request;
+      }
+
+      absolute_uristr =
+          g_strdup_printf ("rtsp://%s%s", priv->server_ip, uristr);
+
+      GST_DEBUG_OBJECT (client, "absolute url: %s", absolute_uristr);
+      if (gst_rtsp_url_parse (absolute_uristr, &uri) != GST_RTSP_OK) {
+        g_free (absolute_uristr);
+        goto bad_request;
+      }
+      g_free (absolute_uristr);
+    } else {
+      g_free (scheme);
+      goto bad_request;
+    }
+  }
 
   /* get the session if there is any */
   res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0);
@@ -1967,6 +2090,7 @@ session_not_found:
 not_authorized:
   {
     GST_ERROR ("client %p: not allowed", client);
+    /* error reply is already sent */
     goto done;
   }
 not_implemented:
@@ -2750,7 +2874,7 @@ client_watch_notify (GstRTSPClient * client)
  * @context: (allow-none): a #GMainContext
  *
  * Attaches @client to @context. When the mainloop for @context is run, the
- * client will be dispatched. When @context is NULL, the default context will be
+ * client will be dispatched. When @context is %NULL, the default context will be
  * used).
  *
  * This function should be called when the client properties and urls are fully
@@ -2788,7 +2912,7 @@ gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
 /**
  * gst_rtsp_client_session_filter:
  * @client: a #GstRTSPClient
- * @func: (scope call): a callback
+ * @func: (scope call) (allow-none): a callback
  * @user_data: user data passed to @func
  *
  * Call @func for each session managed by @client. The result value of @func
@@ -2804,6 +2928,8 @@ gst_rtsp_client_attach (GstRTSPClient * client, GMainContext * context)
  * will also be added with an additional ref to the result #GList of this
  * function..
  *
+ * When @func is %NULL, #GST_RTSP_FILTER_REF will be assumed for each session.
+ *
  * Returns: (element-type GstRTSPSession) (transfer full): a #GList with all
  * sessions for which @func returned #GST_RTSP_FILTER_REF. After usage, each
  * element in the #GList should be unreffed before the list is freed.
@@ -2816,7 +2942,6 @@ gst_rtsp_client_session_filter (GstRTSPClient * client,
   GList *result, *walk, *next;
 
   g_return_val_if_fail (GST_IS_RTSP_CLIENT (client), NULL);
-  g_return_val_if_fail (func != NULL, NULL);
 
   priv = client->priv;
 
@@ -2825,10 +2950,16 @@ gst_rtsp_client_session_filter (GstRTSPClient * client,
   g_mutex_lock (&priv->lock);
   for (walk = priv->sessions; walk; walk = next) {
     GstRTSPSession *sess = walk->data;
+    GstRTSPFilterResult res;
 
     next = g_list_next (walk);
 
-    switch (func (client, sess, user_data)) {
+    if (func)
+      res = func (client, sess, user_data);
+    else
+      res = GST_RTSP_FILTER_REF;
+
+    switch (res) {
       case GST_RTSP_FILTER_REMOVE:
         /* stop watching the session and pretent it went away */
         client_cleanup_session (client, sess);