From: Sangchul Lee Date: Wed, 7 Feb 2024 07:31:43 +0000 (+0900) Subject: webrtc_internal: Add functions to get local/remote description X-Git-Tag: accepted/tizen/unified/20240215.130027^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=23e7af22279728cc493ffe2b52aee841d84a2c3d;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add functions to get local/remote description Functions have been added as below. - webrtc_get_local_description() - webrtc_get_remote_description() [Version] 0.4.43 [Issue Type] Internal API Change-Id: Ifb481b4b005a40145e959d31e3d2ccc3bb6c23f1 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 2ea49a2f..7186ae9a 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -385,6 +385,42 @@ int webrtc_media_source_remove_transceiver_encoding(webrtc_h webrtc, unsigned in */ int webrtc_media_source_active_transceiver_encoding(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, const char *rid, bool active); +/** + * @internal + * @brief Gets the local session description. + * @since_tizen 9.0 + * @remarks @a description is a JSON string.\n + * It will be {"sdp":{"type":"offer or answer","sdp":"..."}}.\n + * The @a description should be released using free() if the value is not NULL. + * @param[in] webrtc WebRTC handle + * @param[out] description The local 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_set_local_description() + */ +int webrtc_get_local_description(webrtc_h webrtc, char **description); + +/** + * @internal + * @brief Gets the remote session description. + * @since_tizen 9.0 + * @remarks @a description is a JSON string.\n + * It should be {"sdp":{"type":"offer or answer","sdp":"..."}}.\n + * The @a description should be released using free() if the value is not NULL. + * @param[in] webrtc WebRTC handle + * @param[out] description The remote 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_set_remote_description() + */ +int webrtc_get_remote_description(webrtc_h webrtc, char **description); + /** * @internal * @brief Sets the probability of RTP packet dropping. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 83ba7b50..4fd339a3 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -519,6 +519,8 @@ typedef struct _webrtc_s { gchar *desc_offer; gchar *desc_answer; + gchar *local_desc; + gchar *remote_desc; webrtc_data_recovery_type_s data_recovery_types[MAX_MLINE_NUM]; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 5d73a051..d10c2a7b 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.42 +Version: 0.4.43 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index b3247ac6..eb505749 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -272,6 +272,46 @@ int webrtc_media_source_active_transceiver_encoding(webrtc_h webrtc, unsigned in return _active_transceiver_encoding(webrtc, source_id, media_type, rid, active); } +int webrtc_get_local_description(webrtc_h webrtc, char **description) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + if (_webrtc->local_desc) + *description = strdup(_webrtc->local_desc); + else + *description = NULL; + + LOG_INFO("webrtc[%p] description: %s", _webrtc, *description); + + return WEBRTC_ERROR_NONE; +} + +int webrtc_get_remote_description(webrtc_h webrtc, char **description) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(description == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "description is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + if (_webrtc->remote_desc) + *description = strdup(_webrtc->remote_desc); + else + *description = NULL; + + LOG_INFO("webrtc[%p] description: %s", _webrtc, *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 eefbddb0..36981e63 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1642,6 +1642,14 @@ void _gst_destroy_pipeline(webrtc_s *webrtc) g_free(webrtc->desc_answer); webrtc->desc_answer = NULL; } + if (webrtc->local_desc) { + g_free(webrtc->local_desc); + webrtc->local_desc = NULL; + } + if (webrtc->remote_desc) { + g_free(webrtc->remote_desc); + webrtc->remote_desc = NULL; + } } int _gst_pipeline_set_state(webrtc_s *webrtc, GstState state) @@ -2038,6 +2046,13 @@ int _webrtcbin_set_session_description(webrtc_s *webrtc, const char *description LOG_DEBUG("[%s] signal is emitted", is_remote ? "set-remote-description" : "set-local-description"); + if (is_remote) { + g_free(webrtc->remote_desc); + webrtc->remote_desc = g_strdup(description); + } else { + g_free(webrtc->local_desc); + webrtc->local_desc = g_strdup(description); + } end: g_free(sdp); g_free(type);