From: Sangchul Lee Date: Tue, 23 Aug 2022 03:34:28 +0000 (+0900) Subject: webrtc_internal: Add APIs to set/get payload type X-Git-Tag: submit/tizen/20220825.024408~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F53%2F280053%2F2;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add APIs to set/get payload type Functions below are added : webrtc_media_source_set_payload_type() : webrtc_media_source_get_payload_type() [Version] 0.3.209 [Issue Type] Internal API Change-Id: I69c20167d1a6d07a6f12ac784c3e921e929fc0f1 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index a09fda00..41f1f6c0 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -152,6 +152,43 @@ int webrtc_media_source_set_video_loopback_to_ecore_wl(webrtc_h webrtc, unsigned */ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_internal_e type, unsigned int *source_id); +/** + * @internal + * @brief Sets the payload type to the media source. + * @since_tizen 7.0 + * @remarks This function would be useful when @a webrtc is operated as an answerer and a remote peer is using another implementation, not this API. + * @param[in] webrtc WebRTC handle + * @param[in] source_id The media source id + * @param[in] media_type The media type + * @param[in] pt The payload type + * @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_STATE Invalid state + * @pre Add media source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @pre @a webrtc state must be set to #WEBRTC_STATE_IDLE. + * @see webrtc_media_source_get_payload_type() + */ +int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt); + +/** + * @internal + * @brief Gets the payload type of the media source. + * @since_tizen 7.0 + * @param[in] webrtc WebRTC handle + * @param[in] source_id The media source id + * @param[in] media_type The media type + * @param[out] pt The payload type + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @pre Add media source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @see webrtc_media_source_set_payload_type() + */ +int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt); + /** * @internal * @brief Sets the crop coordinates of screen source. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 4ea4bce4..cca62f22 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -545,6 +545,7 @@ typedef struct _webrtc_gst_slot_s { bool inbandfec; int packet_loss_percentage; unsigned int pt; + bool pt_set_by_api; struct { unsigned int track_id; bool need_decoding; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 1a10a801..08faf486 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.3.208 +Version: 0.3.209 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 9845d644..95cfd99e 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -79,6 +79,50 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i return ret; } +int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt) +{ + webrtc_s *_webrtc = (webrtc_s *)webrtc; + webrtc_gst_slot_s *source; + g_autoptr(GMutexLocker) locker = NULL; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL, + WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); + + source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt = pt; + source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt_set_by_api = true; + + LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, pt); + + return WEBRTC_ERROR_NONE; +} + +int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt) +{ + webrtc_s *_webrtc = (webrtc_s *)webrtc; + webrtc_gst_slot_s *source; + g_autoptr(GMutexLocker) locker = NULL; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); + RET_VAL_IF(pt == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "pt is NULL"); + RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL, + WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + *pt = source->av[GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO)].pt; + + LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, *pt); + + return WEBRTC_ERROR_NONE; +} + int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height) { g_autoptr(GMutexLocker) locker = NULL; diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index a34ef513..737d8d73 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -417,6 +417,11 @@ int _set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, c RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + if (source->av[av_idx].pt_set_by_api) { + LOG_INFO("current pt[%u] might be set by api, skip it", source->av[av_idx].pt); + return WEBRTC_ERROR_NONE; + } + if (media_type) if ((payload_type = __get_fixed_payload_type(media_type)) != -1) goto out;