From: Sangchul Lee Date: Thu, 29 Feb 2024 07:29:56 +0000 (+0900) Subject: webrtc_internal: Add function to strip session description X-Git-Tag: accepted/tizen/8.0/unified/20240308.173324~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77b8fceb46bfdf0d9062f5d29869297adabf8ee7;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add function to strip session description 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 --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 8c72075f..c9fb1faa 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -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. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 65e25200..213c2133 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -37,6 +37,7 @@ #ifdef TIZEN_FEATURE_DNS #include #endif +#include #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 } diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 82e389b4..aeddab2f 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 8cbd8df2..7e8ad385 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -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; diff --git a/src/webrtc_private.c b/src/webrtc_private.c index 8dcb4d6d..36e35221 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -16,7 +16,6 @@ #include "webrtc.h" #include "webrtc_private.h" -#include #include #include @@ -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);