Add to check privilege and feature for WebRTC node 30/236030/6
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 12 Jun 2020 05:54:58 +0000 (14:54 +0900)
committerHyunil <hyunil46.park@samsung.com>
Mon, 15 Jun 2020 08:37:45 +0000 (17:37 +0900)
 - internet privilege is needed to create WebRTC node.
 - At least, one of wifi, telephony, ethernet feature should be enabled.
 - The return value of MEDIA_STREAMER_ERROR_PERMISSION_DENIED,
   MEDIA_STREAMER_ERROR_NOT_SUPPORTED are added to media_streamer_node_create().

[Version] 0.1.61
[Issue Type] Privilege/Feature

Change-Id: I10daa928b2310b8ac194e5aa6b3762672e3a2933
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/media_streamer.h
packaging/capi-media-streamer.spec
src/media_streamer_node.c

index 93022fe..9b824a1 100644 (file)
@@ -1058,6 +1058,7 @@ int media_streamer_node_pull_packet(media_streamer_node_h sink, media_packet_h *
  * @since_tizen 3.0
  * @remarks The node type should not be #MEDIA_STREAMER_NODE_TYPE_SRC and #MEDIA_STREAMER_NODE_TYPE_SINK.
  *          To create source / sink type node, media_streamer_node_create_src() / media_streamer_node_create_sink() should be called.
+ *          The internet privilege(%http://tizen.org/privilege/internet) should be added if #MEDIA_STREAMER_NODE_TYPE_WEBRTC is set.
  *          You can release @a node using media_streamer_node_destroy().
  * @param[in]  type      Created node type
  * @param[in]  in_fmt    Media format handle for input data
@@ -1068,6 +1069,8 @@ int media_streamer_node_pull_packet(media_streamer_node_h sink, media_packet_h *
  * @retval #MEDIA_STREAMER_ERROR_NONE Successful
  * @retval #MEDIA_STREAMER_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MEDIA_STREAMER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #MEDIA_STREAMER_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #MEDIA_STREAMER_ERROR_NOT_SUPPORTED Not supported
  * @see #media_streamer_node_type_e
  * @see #media_format_h
  * @see media_streamer_node_destroy()
index 76bb9ef..4c8584e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-streamer
 Summary:    A Media Streamer API
-Version:    0.1.60
+Version:    0.1.61
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 82ccef7..53f4c37 100644 (file)
@@ -398,85 +398,6 @@ static int __ms_webrtc_node_is_offerer(media_streamer_node_s *node, gboolean *is
        return MEDIA_STREAMER_ERROR_NONE;
 }
 
-int ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_format_h out_fmt)
-{
-       int ret = MEDIA_STREAMER_ERROR_NONE;
-       GstCaps *sink_caps = NULL;
-       GstCaps *src_caps = NULL;
-
-       ms_debug_fenter();
-
-       ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
-
-       sink_caps = in_fmt ? ms_create_caps_from_fmt(in_fmt) : NULL;
-       src_caps = out_fmt ? ms_create_caps_from_fmt(out_fmt) : NULL;
-
-       node_plug_s plug_info = {&(nodes_info[node->type]), src_caps, sink_caps, NULL};
-
-       ms_info("Creating node with info: klass_name[%s]; default[%s]",
-                       plug_info.info->klass_name, plug_info.info->default_name);
-
-       node->gst_element = ms_node_element_create(&plug_info, node->type);
-       if (node->gst_element)
-               node->name = gst_element_get_name(node->gst_element);
-       else
-               return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
-
-       if (src_caps)
-                       gst_caps_unref(src_caps);
-
-       if (sink_caps)
-                       gst_caps_unref(sink_caps);
-
-       ms_debug_fleave();
-
-       return ret;
-}
-
-/* This signal callback is called when appsrc needs data, we add an idle handler
- * to the mainloop to start pushing data into the appsrc */
-static void __ms_src_start_feed_cb(GstElement *pipeline, guint size, gpointer data)
-{
-       media_streamer_node_s *ms_src = (media_streamer_node_s *) data;
-       media_streamer_callback_s *src_callback = NULL;
-       media_streamer_custom_buffer_status_cb buffer_status_cb = NULL;
-
-       ms_debug_fenter();
-
-       ms_retm_if(ms_src == NULL, "data is NULL");
-       ms_retm_if(pipeline == NULL, "pipeline is NULL");
-
-       if (ms_src->callbacks_structure != NULL) {
-               src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure;
-               buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback;
-               buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_UNDERRUN, src_callback->user_data);
-       }
-
-       ms_debug_fleave();
-}
-
-/* This callback is called when appsrc has enough data and we can stop sending.
- * We remove the idle handler from the mainloop */
-static void __ms_src_stop_feed_cb(GstElement *pipeline, gpointer data)
-{
-       media_streamer_node_s *ms_src = (media_streamer_node_s *) data;
-       media_streamer_callback_s *src_callback = NULL;
-       media_streamer_custom_buffer_status_cb buffer_status_cb = NULL;
-
-       ms_debug_fenter();
-
-       ms_retm_if(ms_src == NULL, "data is NULL");
-       ms_retm_if(pipeline == NULL, "pipeline is NULL");
-
-       if (ms_src->callbacks_structure != NULL) {
-               src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure;
-               buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback;
-               buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_OVERFLOW, src_callback->user_data);
-       }
-
-       ms_debug_fleave();
-}
-
 static int __ms_node_check_privileges(media_streamer_node_s *node)
 {
        int ret = MEDIA_STREAMER_ERROR_NONE;
@@ -525,6 +446,9 @@ static int __ms_node_check_privileges(media_streamer_node_s *node)
                }
        }
 
+       if (node->type == MEDIA_STREAMER_NODE_TYPE_WEBRTC)
+               privilege = "http://tizen.org/privilege/internet";
+
        /* Skip checking for privilege permission in case of other types of Nodes */
        if (privilege == NULL)
                return ret;
@@ -575,6 +499,134 @@ static int __ms_node_check_privileges(media_streamer_node_s *node)
        return ret;
 }
 
+static int __ms_node_check_feature(media_streamer_node_s *node)
+{
+       bool enabled = FALSE;
+
+       ms_debug_fenter();
+
+       ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+
+       switch (node->type) {
+       case MEDIA_STREAMER_NODE_TYPE_WEBRTC:
+               if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_WIFI, &enabled)) {
+                       ms_info("wifi status = %d", enabled);
+                       if (enabled)
+                               return MEDIA_STREAMER_ERROR_NONE;
+               }
+               if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_TELEPHONY, &enabled)) {
+                       ms_info("telephony status = %d", enabled);
+                       if (enabled)
+                               return MEDIA_STREAMER_ERROR_NONE;
+               }
+               if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_bool(_FEATURE_NAME_ETHERNET, &enabled)) {
+                       ms_info("ethernet status = %d", enabled);
+                       if (enabled)
+                               return MEDIA_STREAMER_ERROR_NONE;
+               }
+               ms_error("None of [%s] [%s] [%s] features is enabled", _FEATURE_NAME_WIFI, _FEATURE_NAME_TELEPHONY, _FEATURE_NAME_ETHERNET);
+               return MEDIA_STREAMER_ERROR_NOT_SUPPORTED;
+       default:
+               ms_debug("For current node type[%d], feature is not needed", node->type);
+               break;
+       }
+
+       ms_debug_fleave();
+
+       return MEDIA_STREAMER_ERROR_NONE;
+}
+
+int ms_node_create(media_streamer_node_s *node, media_format_h in_fmt, media_format_h out_fmt)
+{
+       int ret = MEDIA_STREAMER_ERROR_NONE;
+       GstCaps *sink_caps = NULL;
+       GstCaps *src_caps = NULL;
+
+       ms_debug_fenter();
+
+       ms_retvm_if(node == NULL, MEDIA_STREAMER_ERROR_INVALID_PARAMETER, "node is NULL");
+
+       ret = __ms_node_check_privileges(node);
+       if (ret != MEDIA_STREAMER_ERROR_NONE) {
+               ms_error("Failed to get privilege for this node type(%d)", node->type);
+               return ret;
+       }
+
+       ret = __ms_node_check_feature(node);
+       if (ret != MEDIA_STREAMER_ERROR_NONE) {
+               ms_error("Failed to get feature for this node type(%d)", node->type);
+               return ret;
+       }
+
+       sink_caps = in_fmt ? ms_create_caps_from_fmt(in_fmt) : NULL;
+       src_caps = out_fmt ? ms_create_caps_from_fmt(out_fmt) : NULL;
+
+       node_plug_s plug_info = {&(nodes_info[node->type]), src_caps, sink_caps, NULL};
+
+       ms_info("Creating node with info: klass_name[%s]; default[%s]",
+                       plug_info.info->klass_name, plug_info.info->default_name);
+
+       node->gst_element = ms_node_element_create(&plug_info, node->type);
+       if (node->gst_element)
+               node->name = gst_element_get_name(node->gst_element);
+       else
+               return MEDIA_STREAMER_ERROR_INVALID_OPERATION;
+
+       if (src_caps)
+                       gst_caps_unref(src_caps);
+
+       if (sink_caps)
+                       gst_caps_unref(sink_caps);
+
+       ms_debug_fleave();
+
+       return ret;
+}
+
+/* This signal callback is called when appsrc needs data, we add an idle handler
+ * to the mainloop to start pushing data into the appsrc */
+static void __ms_src_start_feed_cb(GstElement *pipeline, guint size, gpointer data)
+{
+       media_streamer_node_s *ms_src = (media_streamer_node_s *) data;
+       media_streamer_callback_s *src_callback = NULL;
+       media_streamer_custom_buffer_status_cb buffer_status_cb = NULL;
+
+       ms_debug_fenter();
+
+       ms_retm_if(ms_src == NULL, "data is NULL");
+       ms_retm_if(pipeline == NULL, "pipeline is NULL");
+
+       if (ms_src->callbacks_structure != NULL) {
+               src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure;
+               buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback;
+               buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_UNDERRUN, src_callback->user_data);
+       }
+
+       ms_debug_fleave();
+}
+
+/* This callback is called when appsrc has enough data and we can stop sending.
+ * We remove the idle handler from the mainloop */
+static void __ms_src_stop_feed_cb(GstElement *pipeline, gpointer data)
+{
+       media_streamer_node_s *ms_src = (media_streamer_node_s *) data;
+       media_streamer_callback_s *src_callback = NULL;
+       media_streamer_custom_buffer_status_cb buffer_status_cb = NULL;
+
+       ms_debug_fenter();
+
+       ms_retm_if(ms_src == NULL, "data is NULL");
+       ms_retm_if(pipeline == NULL, "pipeline is NULL");
+
+       if (ms_src->callbacks_structure != NULL) {
+               src_callback = (media_streamer_callback_s *) ms_src->callbacks_structure;
+               buffer_status_cb = (media_streamer_custom_buffer_status_cb) src_callback->callback;
+               buffer_status_cb((media_streamer_node_h) ms_src, MEDIA_STREAMER_CUSTOM_BUFFER_OVERFLOW, src_callback->user_data);
+       }
+
+       ms_debug_fleave();
+}
+
 static int __ms_src_node_check_feature(media_streamer_node_s *node)
 {
        int ret = MEDIA_STREAMER_ERROR_NONE;