webrtc_internal: Add function to strip session description 70/307470/1
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 29 Feb 2024 07:29:56 +0000 (16:29 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 11 Mar 2024 01:25:12 +0000 (01:25 +0000)
webrtc_util_strip_description() has been added to only get the
string member of sdp object in the original description.

[Version] 0.4.47
[Issue Type] Internal API

Change-Id: Ib8c81c26a4924680c8d042fd73027badb7c7c201
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
(cherry picked from commit 77b8fceb46bfdf0d9062f5d29869297adabf8ee7)

include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_private.c

index 8c72075f5419e94521193c49ebbcf7e7767dc523..c9fb1faaa21966dc62f4591d26fc86e4a087ef6f 100644 (file)
@@ -508,10 +508,28 @@ int webrtc_get_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float *
  * @pre @a webrtc state must be set to #WEBRTC_STATE_IDLE.
  * @post @a webrtc state is #WEBRTC_STATE_NEGOTIATING.
  * @see webrtc_create()
+ * @see webrtc_start()
  * @see webrtc_stop()
  */
 int webrtc_start_sync(webrtc_h webrtc);
 
+/**
+ * @internal
+ * @brief Strips the session description.
+ * @since_tizen 8.0
+ * @remarks @a origin_description is a JSON string. It should be {"sdp":{"type":"offer or answer","sdp":"..."}}.\n
+ *          @a description will be {"..."} the string member of "sdp" object in @a origin_description.\n
+ *          The @a description should be released using free().
+ * @param[in] origin_description The original session description
+ * @param[out] description       The stripped session description
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WEBRTC_ERROR_NONE    Successful
+ * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ */
+int webrtc_util_strip_description(const char *origin_description, char **description);
+
 /**
  * @internal
  * @brief Creates a signaling server for private network.
index 65e252004865a8417317dab38d9896a9d8695133..213c2133f986e383bbfd0f211e024913c0100017 100644 (file)
@@ -37,6 +37,7 @@
 #ifdef TIZEN_FEATURE_DNS
 #include <dns_sd.h>
 #endif
+#include <json-glib/json-glib.h>
 
 #include "webrtc_internal.h"
 
@@ -974,6 +975,7 @@ int _set_ghost_pad_target(GstPad *ghost_pad, GstElement *target_element, bool is
 void _generate_dot(GstElement *pipeline, const gchar *name);
 bool _stun_url_has_valid_prefix(const char *url);
 gchar *_check_and_encode_turn_url(const char *url);
+gchar *_get_string_from_json_object(JsonObject *object);
 
 #ifdef __cplusplus
 }
index 82e389b4b180131d3707e6efd103e5276dec7b52..aeddab2fc4971d21fa0cafef762e707a578df328 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.46
+Version:    0.4.47
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 8cbd8df2a4d94209df5d38fcb72cf97327d5628e..7e8ad38569de70c619797cec876555c4f5d635ad 100644 (file)
@@ -360,6 +360,50 @@ int webrtc_get_remote_description(webrtc_h webrtc, char **description)
        return WEBRTC_ERROR_NONE;
 }
 
+int webrtc_util_strip_description(const char *origin_description, char **description)
+{
+       g_autoptr(JsonParser) parser = NULL;
+       JsonNode *root;
+       JsonObject *object;
+       const gchar *member_sdp;
+
+       RET_VAL_IF(origin_description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "origin_description is NULL");
+       RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL");
+
+       parser = json_parser_new();
+       if (!JSON_IS_PARSER(parser))
+               return WEBRTC_ERROR_INVALID_OPERATION;
+
+       if (!json_parser_load_from_data(parser, origin_description, -1, NULL)) {
+               LOG_ERROR("unknown description: %s", origin_description);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       root = json_parser_get_root(parser);
+       if (!JSON_NODE_HOLDS_OBJECT(root)) {
+               LOG_ERROR("it does not contain a JsonObject: %s", origin_description);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       object = json_node_get_object(root);
+       if (!json_object_has_member(object, "sdp")) {
+               LOG_ERROR("it does not contain 'sdp' member: %s", origin_description);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       member_sdp = json_object_get_string_member(json_object_get_object_member(object, "sdp"), "sdp");
+       if (!member_sdp) {
+               LOG_ERROR("could not find sdb member: %s", origin_description);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       *description = strdup(member_sdp);
+
+       LOG_INFO("description:\n%s", *description);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int webrtc_set_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float probability)
 {
        webrtc_s *_webrtc = (webrtc_s *)webrtc;
index 8dcb4d6dfeaefab959636ce855294696cafa9f44..36e35221d7f58da5b92477c0b460b9cf26bdbb4d 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "webrtc.h"
 #include "webrtc_private.h"
-#include <json-glib/json-glib.h>
 #include <pulse/proplist.h>
 #include <sound_manager_internal.h>
 
@@ -192,7 +191,7 @@ gchar *_check_and_encode_turn_url(const char *url)
 }
 
 /* Use g_free() to release the return value. */
-static gchar *__get_string_from_json_object(JsonObject *object)
+gchar *_get_string_from_json_object(JsonObject *object)
 {
        JsonNode *root;
        JsonGenerator *generator;
@@ -237,7 +236,7 @@ static gchar *__make_sdp_message(GstWebRTCSessionDescription *desc)
        msg = json_object_new();
        json_object_set_object_member(msg, "sdp", sdp);
 
-       text = __get_string_from_json_object(msg);
+       text = _get_string_from_json_object(msg);
 
        json_object_unref(msg);
 
@@ -262,7 +261,7 @@ static gchar *__make_ice_candidate_message(guint mlineindex, gchar *candidate)
        msg = json_object_new();
        json_object_set_object_member(msg, "ice", ice);
 
-       text = __get_string_from_json_object(msg);
+       text = _get_string_from_json_object(msg);
 
        json_object_unref(msg);