From 0499a1ec7db7911569b53a854eb7eae1b7d7882e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 9 Jul 2013 14:33:43 +0200 Subject: [PATCH] media: make it possible to set permissions Make it possible to set permissions on media and media factory objects --- gst/rtsp-server/rtsp-media-factory.c | 52 ++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-media-factory.h | 48 ++++++++++++++----------- gst/rtsp-server/rtsp-media.c | 52 ++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-media.h | 6 +++- 4 files changed, 136 insertions(+), 22 deletions(-) diff --git a/gst/rtsp-server/rtsp-media-factory.c b/gst/rtsp-server/rtsp-media-factory.c index b6fa8c033f..d210d5f8c7 100644 --- a/gst/rtsp-server/rtsp-media-factory.c +++ b/gst/rtsp-server/rtsp-media-factory.c @@ -29,6 +29,7 @@ struct _GstRTSPMediaFactoryPrivate { GMutex lock; /* protects everything but medias */ + GstRTSPPermissions *permissions; gchar *launch; gboolean shared; gboolean eos_shutdown; @@ -274,6 +275,57 @@ gst_rtsp_media_factory_new (void) return result; } +/** + * gst_rtsp_media_factory_set_permissions: + * @factory: a #GstRTSPMediaFactory + * @permissions: a #GstRTSPPermissions + * + * Set @permissions on @factory. + */ +void +gst_rtsp_media_factory_set_permissions (GstRTSPMediaFactory * factory, + GstRTSPPermissions * permissions) +{ + GstRTSPMediaFactoryPrivate *priv; + + g_return_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory)); + + priv = factory->priv; + + GST_RTSP_MEDIA_FACTORY_LOCK (factory); + if (priv->permissions) + gst_rtsp_permissions_unref (priv->permissions); + if ((priv->permissions = permissions)) + gst_rtsp_permissions_ref (permissions); + GST_RTSP_MEDIA_FACTORY_UNLOCK (factory); +} + +/** + * gst_rtsp_media_factory_get_permissions: + * @factory: a #GstRTSPMediaFactory + * + * Get the permissions object from @factory. + * + * Returns: (transfer full): a #GstRTSPPermissions object, unref after usage. + */ +GstRTSPPermissions * +gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory * factory) +{ + GstRTSPMediaFactoryPrivate *priv; + GstRTSPPermissions *result; + + g_return_val_if_fail (GST_IS_RTSP_MEDIA_FACTORY (factory), NULL); + + priv = factory->priv; + + GST_RTSP_MEDIA_FACTORY_LOCK (factory); + if ((result = priv->permissions)) + gst_rtsp_permissions_ref (result); + GST_RTSP_MEDIA_FACTORY_UNLOCK (factory); + + return result; +} + /** * gst_rtsp_media_factory_set_launch: * @factory: a #GstRTSPMediaFactory diff --git a/gst/rtsp-server/rtsp-media-factory.h b/gst/rtsp-server/rtsp-media-factory.h index a492422e38..896261a13b 100644 --- a/gst/rtsp-server/rtsp-media-factory.h +++ b/gst/rtsp-server/rtsp-media-factory.h @@ -21,7 +21,7 @@ #include #include "rtsp-media.h" -#include "rtsp-auth.h" +#include "rtsp-permissions.h" #include "rtsp-address-pool.h" #ifndef __GST_RTSP_MEDIA_FACTORY_H__ @@ -99,34 +99,40 @@ GType gst_rtsp_media_factory_get_type (void); GstRTSPMediaFactory * gst_rtsp_media_factory_new (void); /* configuring the factory */ -void gst_rtsp_media_factory_set_launch (GstRTSPMediaFactory *factory, - const gchar *launch); -gchar * gst_rtsp_media_factory_get_launch (GstRTSPMediaFactory *factory); +void gst_rtsp_media_factory_set_permissions (GstRTSPMediaFactory *factory, + GstRTSPPermissions *permissions); +GstRTSPPermissions * gst_rtsp_media_factory_get_permissions (GstRTSPMediaFactory *factory); -void gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory *factory, - gboolean shared); -gboolean gst_rtsp_media_factory_is_shared (GstRTSPMediaFactory *factory); +void gst_rtsp_media_factory_set_launch (GstRTSPMediaFactory *factory, + const gchar *launch); +gchar * gst_rtsp_media_factory_get_launch (GstRTSPMediaFactory *factory); -void gst_rtsp_media_factory_set_eos_shutdown (GstRTSPMediaFactory *factory, - gboolean eos_shutdown); -gboolean gst_rtsp_media_factory_is_eos_shutdown (GstRTSPMediaFactory *factory); +void gst_rtsp_media_factory_set_shared (GstRTSPMediaFactory *factory, + gboolean shared); +gboolean gst_rtsp_media_factory_is_shared (GstRTSPMediaFactory *factory); -void gst_rtsp_media_factory_set_protocols (GstRTSPMediaFactory *factory, GstRTSPLowerTrans protocols); -GstRTSPLowerTrans gst_rtsp_media_factory_get_protocols (GstRTSPMediaFactory *factory); +void gst_rtsp_media_factory_set_eos_shutdown (GstRTSPMediaFactory *factory, + gboolean eos_shutdown); +gboolean gst_rtsp_media_factory_is_eos_shutdown (GstRTSPMediaFactory *factory); -void gst_rtsp_media_factory_set_address_pool (GstRTSPMediaFactory * factory, - GstRTSPAddressPool * pool); -GstRTSPAddressPool * gst_rtsp_media_factory_get_address_pool (GstRTSPMediaFactory * factory); +void gst_rtsp_media_factory_set_protocols (GstRTSPMediaFactory *factory, + GstRTSPLowerTrans protocols); +GstRTSPLowerTrans gst_rtsp_media_factory_get_protocols (GstRTSPMediaFactory *factory); -void gst_rtsp_media_factory_set_buffer_size (GstRTSPMediaFactory * factory, guint size); -guint gst_rtsp_media_factory_get_buffer_size (GstRTSPMediaFactory * factory); +void gst_rtsp_media_factory_set_address_pool (GstRTSPMediaFactory * factory, + GstRTSPAddressPool * pool); +GstRTSPAddressPool * gst_rtsp_media_factory_get_address_pool (GstRTSPMediaFactory * factory); + +void gst_rtsp_media_factory_set_buffer_size (GstRTSPMediaFactory * factory, + guint size); +guint gst_rtsp_media_factory_get_buffer_size (GstRTSPMediaFactory * factory); /* creating the media from the factory and a url */ -GstRTSPMedia * gst_rtsp_media_factory_construct (GstRTSPMediaFactory *factory, - const GstRTSPUrl *url); +GstRTSPMedia * gst_rtsp_media_factory_construct (GstRTSPMediaFactory *factory, + const GstRTSPUrl *url); -GstElement * gst_rtsp_media_factory_create_element (GstRTSPMediaFactory *factory, - const GstRTSPUrl *url); +GstElement * gst_rtsp_media_factory_create_element (GstRTSPMediaFactory *factory, + const GstRTSPUrl *url); G_END_DECLS diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c index 2a875b37f9..777a27f93d 100644 --- a/gst/rtsp-server/rtsp-media.c +++ b/gst/rtsp-server/rtsp-media.c @@ -34,6 +34,7 @@ struct _GstRTSPMediaPrivate GCond cond; /* protected by lock */ + GstRTSPPermissions *permissions; gboolean shared; gboolean reusable; GstRTSPLowerTrans protocols; @@ -496,6 +497,57 @@ gst_rtsp_media_take_pipeline (GstRTSPMedia * media, GstPipeline * pipeline) gst_bin_add (GST_BIN_CAST (pipeline), priv->element); } +/** + * gst_rtsp_media_set_permissions: + * @media: a #GstRTSPMedia + * @permissions: a #GstRTSPPermissions + * + * Set @permissions on @media. + */ +void +gst_rtsp_media_set_permissions (GstRTSPMedia * media, + GstRTSPPermissions * permissions) +{ + GstRTSPMediaPrivate *priv; + + g_return_if_fail (GST_IS_RTSP_MEDIA (media)); + + priv = media->priv; + + g_mutex_lock (&priv->lock); + if (priv->permissions) + gst_rtsp_permissions_unref (priv->permissions); + if ((priv->permissions = permissions)) + gst_rtsp_permissions_ref (permissions); + g_mutex_unlock (&priv->lock); +} + +/** + * gst_rtsp_media_get_permissions: + * @media: a #GstRTSPMedia + * + * Get the permissions object from @media. + * + * Returns: (transfer full): a #GstRTSPPermissions object, unref after usage. + */ +GstRTSPPermissions * +gst_rtsp_media_get_permissions (GstRTSPMedia * media) +{ + GstRTSPMediaPrivate *priv; + GstRTSPPermissions *result; + + g_return_val_if_fail (GST_IS_RTSP_MEDIA (media), NULL); + + priv = media->priv; + + g_mutex_lock (&priv->lock); + if ((result = priv->permissions)) + gst_rtsp_permissions_ref (result); + g_mutex_unlock (&priv->lock); + + return result; +} + /** * gst_rtsp_media_set_shared: * @media: a #GstRTSPMedia diff --git a/gst/rtsp-server/rtsp-media.h b/gst/rtsp-server/rtsp-media.h index f76a6ddcd5..8158891ee2 100644 --- a/gst/rtsp-server/rtsp-media.h +++ b/gst/rtsp-server/rtsp-media.h @@ -42,7 +42,7 @@ typedef struct _GstRTSPMediaClass GstRTSPMediaClass; typedef struct _GstRTSPMediaPrivate GstRTSPMediaPrivate; #include "rtsp-stream.h" -#include "rtsp-auth.h" +#include "rtsp-permissions.h" #include "rtsp-address-pool.h" /** @@ -125,6 +125,10 @@ void gst_rtsp_media_take_pipeline (GstRTSPMedia *media, GstP GstRTSPMediaStatus gst_rtsp_media_get_status (GstRTSPMedia *media); +void gst_rtsp_media_set_permissions (GstRTSPMedia *media, + GstRTSPPermissions *permissions); +GstRTSPPermissions * gst_rtsp_media_get_permissions (GstRTSPMedia *media); + void gst_rtsp_media_set_shared (GstRTSPMedia *media, gboolean shared); gboolean gst_rtsp_media_is_shared (GstRTSPMedia *media);