#include <gst/rtsp-server/rtsp-server.h>
/* define this if you want the resource to only be available when using
- * user/admin as the password */
+ * user/password as the password */
#undef WITH_AUTH
-/* define this if you want the server to use TLS */
+/* define this if you want the server to use TLS (it will also need WITH_AUTH
+ * to be defined) */
#undef WITH_TLS
/* this timeout is periodically run to clean up the expired sessions from the
* pool. This needs to be run explicitly currently but might be done
* automatically as part of the mainloop. */
static gboolean
-timeout (GstRTSPServer * server, gboolean ignored)
+timeout (GstRTSPServer * server)
{
GstRTSPSessionPool *pool;
GstRTSPMediaFactory *factory;
#ifdef WITH_AUTH
GstRTSPAuth *auth;
+ GstRTSPToken *token;
gchar *basic;
+ GstRTSPPermissions *permissions;
#endif
#ifdef WITH_TLS
GTlsCertificate *cert;
+ GError *error = NULL;
#endif
gst_init (&argc, &argv);
/* create a server instance */
server = gst_rtsp_server_new ();
+
+#ifdef WITH_AUTH
+ /* make a new authentication manager. it can be added to control access to all
+ * the factories on the server or on individual factories. */
+ auth = gst_rtsp_auth_new ();
#ifdef WITH_TLS
cert = g_tls_certificate_new_from_pem ("-----BEGIN CERTIFICATE-----"
"MIICJjCCAY+gAwIBAgIBBzANBgkqhkiG9w0BAQUFADCBhjETMBEGCgmSJomT8ixk"
"tTdPbW829BoUtIeH64cCIQDggG5i48v7HPacPBIH1RaSVhXl8qHCpQD3qrIw3FMw"
"DwIga8PqH5Sf5sHedy2+CiK0V4MRfoU4c3zQ6kArI+bEgSkCIQCLA1vXBiE31B5s"
"bdHoYa1BXebfZVd+1Hd95IfEM5mbRwIgSkDuQwV55BBlvWph3U8wVIMIb4GStaH8"
- "W535W8UBbEg=" "-----END PRIVATE KEY-----", -1, NULL);
- gst_rtsp_server_set_tls_certificate (server, cert);
+ "W535W8UBbEg=" "-----END PRIVATE KEY-----", -1, &error);
+ if (cert == NULL) {
+ g_printerr ("failed to parse PEM: %s\n", error->message);
+ return -1;
+ }
+ gst_rtsp_auth_set_tls_certificate (auth, cert);
g_object_unref (cert);
#endif
- /* get the mount points for this server, every server has a default object
- * that be used to map uri mount points to media factories */
- mounts = gst_rtsp_server_get_mount_points (server);
-
-#ifdef WITH_AUTH
- /* make a new authentication manager. it can be added to control access to all
- * the factories on the server or on individual factories. */
- auth = gst_rtsp_auth_new ();
- basic = gst_rtsp_auth_make_basic ("user", "admin");
- gst_rtsp_auth_set_basic (auth, basic);
+ /* make user token */
+ token =
+ gst_rtsp_token_new (GST_RTSP_TOKEN_MEDIA_FACTORY_ROLE, G_TYPE_STRING,
+ "user", NULL);
+ basic = gst_rtsp_auth_make_basic ("user", "password");
+ gst_rtsp_auth_add_basic (auth, basic, token);
g_free (basic);
+ gst_rtsp_token_unref (token);
+
/* configure in the server */
gst_rtsp_server_set_auth (server, auth);
#endif
+ /* get the mount points for this server, every server has a default object
+ * that be used to map uri mount points to media factories */
+ mounts = gst_rtsp_server_get_mount_points (server);
+
/* make a media factory for a test stream. The default media factory can use
- * gst-launch syntax to create pipelines.
+ * gst-launch syntax to create pipelines.
* any launch line works as long as it contains elements named pay%d. Each
* element with pay%d names will be a stream */
factory = gst_rtsp_media_factory_new ();
"x264enc ! rtph264pay name=pay0 pt=96 "
"audiotestsrc ! audio/x-raw,rate=8000 ! "
"alawenc ! rtppcmapay name=pay1 pt=97 " ")");
+#ifdef WITH_AUTH
+ /* add permissions for the user media role */
+ permissions = gst_rtsp_permissions_new ();
+ gst_rtsp_permissions_add_role (permissions, "user",
+ GST_RTSP_PERM_MEDIA_FACTORY_ACCESS, G_TYPE_BOOLEAN, TRUE,
+ GST_RTSP_PERM_MEDIA_FACTORY_CONSTRUCT, G_TYPE_BOOLEAN, TRUE, NULL);
+ gst_rtsp_media_factory_set_permissions (factory, permissions);
+ gst_rtsp_permissions_unref (permissions);
+#ifdef WITH_TLS
+ gst_rtsp_media_factory_set_profiles (factory, GST_RTSP_PROFILE_SAVP);
+#endif
+#endif
/* attach the test factory to the /test url */
gst_rtsp_mount_points_add_factory (mounts, "/test", factory);