webrtc_internal: Add function to create session description from sdp string 36/307136/2
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 5 Mar 2024 08:26:53 +0000 (17:26 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 7 Mar 2024 02:54:24 +0000 (11:54 +0900)
webrtc_util_create_description() has been added.

[Version] 0.4.49
[Issue Type] Internal API

Change-Id: I3718e504f37c165a9bc5d39c83ec976f2a111bde
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_internal.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c

index c9fb1faaa21966dc62f4591d26fc86e4a087ef6f..40c1772cf62e9906b04efd2b9801925f152d15dd 100644 (file)
@@ -518,7 +518,7 @@ int webrtc_start_sync(webrtc_h webrtc);
  * @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
+ *          @a description will be the string member of the "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
@@ -527,9 +527,29 @@ int webrtc_start_sync(webrtc_h webrtc);
  * @retval #WEBRTC_ERROR_NONE    Successful
  * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation
+ * @see webrtc_util_create_description()
  */
 int webrtc_util_strip_description(const char *origin_description, char **description);
 
+/**
+ * @internal
+ * @brief Create the session description from sdp string.
+ * @since_tizen 8.0
+ * @remarks @a sdp should be a string that follows the sdp format like "v=0\r\no=- 1832017678083131571 0 IN IP4 0.0.0.0\r\ns=-\r\n...".\n
+ *          @a description is a JSON string. It will be {"sdp":{"type":"offer or answer","sdp":"..."}}.\n
+ *          The @a description should be released using free().
+ * @param[in] offer         SDP type (@c true = offer, @c false = answer)
+ * @param[in] sdp           SDP string
+ * @param[out] description  The 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
+ * @see webrtc_util_strip_description()
+ */
+int webrtc_util_create_description(bool is_offer, const char *sdp, char **description);
+
 /**
  * @internal
  * @brief Creates a signaling server for private network.
index b4ccab3d7fe09a0bf8a946b2343afb1f751d0d57..71fea89becb8489df763e94e1e9394f25dc1ec73 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.4.48
+Version:    0.4.49
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 208375a68c4656aa44b93d4eb4375912d5ae8cca..d23234bd224f0da8871db58628c5fde75c1af4fe 100644 (file)
@@ -405,6 +405,32 @@ int webrtc_util_strip_description(const char *origin_description, char **descrip
        return WEBRTC_ERROR_NONE;
 }
 
+int webrtc_util_create_description(bool is_offer, const char *sdp, char **description)
+{
+       JsonObject *desc, *sdp_desc;
+       gchar *result;
+
+       RET_VAL_IF(sdp == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sdp is NULL");
+       RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL");
+
+       sdp_desc = json_object_new();
+       json_object_set_string_member(sdp_desc, "type", is_offer ? "offer": "answer");
+       json_object_set_string_member(sdp_desc, "sdp", sdp);
+
+       desc = json_object_new();
+       json_object_set_object_member(desc, "sdp", sdp_desc);
+
+       result = _get_string_from_json_object(desc);
+       json_object_unref(desc);
+
+       *description = strdup(result);
+       g_free(result);
+
+       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;