From: Sangchul Lee Date: Thu, 25 Aug 2022 06:45:51 +0000 (+0900) Subject: webrtc_internal: Add more error conditions to webrtc_media_source_set_payload_type() X-Git-Tag: submit/tizen/20220901.010928^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F280200%2F3;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add more error conditions to webrtc_media_source_set_payload_type() Conditions are added to return WEBRTC_ERROR_INVALID_PARAMETER. 1. check if the media type is valid. 2. check if the codec only allows fixed payload type or not and check the input parameter value. [Version] 0.3.218 [Issue Type] Improvement Change-Id: I711f0d7ffc9d88e634d93656f91e3789e13c928f Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index bd011d67..6fd900b8 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -696,6 +696,9 @@ bool _is_screen_source_cropped(webrtc_gst_slot_s *source); /* source */ int _complete_sources(webrtc_s *webrtc); +const char *_get_audio_media_type(const char *codec_name); +const char *_get_video_media_type(const char *codec_name); +int _get_fixed_payload_type(const gchar *media_type); void _update_transceivers_for_offer(webrtc_s *webrtc); void _source_slot_destroy_cb(gpointer data); int _add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id); diff --git a/include/webrtc_source_private.h b/include/webrtc_source_private.h index 7b6bc1be..7de4fe8a 100644 --- a/include/webrtc_source_private.h +++ b/include/webrtc_source_private.h @@ -87,8 +87,6 @@ const char *_get_video_format_name(media_format_mimetype_e mime_type, bool zeroc const char *_get_source_element(webrtc_s *webrtc, int type); GstElement *_find_element_in_bin(GstBin *bin, const gchar *name); bool _is_hw_encoder_used(webrtc_s *webrtc, webrtc_media_source_type_e source_type, media_type_e media_type); -const char *_get_audio_media_type(const char *codec_name); -const char *_get_video_media_type(const char *codec_name); GstAudioFormat _get_gst_audio_raw_format_from_string(const char *format); bool _is_supported_mime_type(media_format_mimetype_e mime_type); bool _is_encoded_format_supported(webrtc_media_source_type_e type, webrtc_ini_s *ini); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index d7a86f57..d93125af 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.217 +Version: 0.3.218 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 40f7fa6e..45cd57c9 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -84,16 +84,34 @@ int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id webrtc_s *_webrtc = (webrtc_s *)webrtc; webrtc_gst_slot_s *source; g_autoptr(GMutexLocker) locker = NULL; + const char *_media_type; + int _pt; 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"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + 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); + if (media_type == WEBRTC_MEDIA_TYPE_AUDIO) + _media_type = _get_audio_media_type(source->av[AV_IDX_AUDIO].codec); + else + _media_type = _get_video_media_type(source->av[AV_IDX_VIDEO].codec); + RET_VAL_IF(_media_type == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "_media_type is NULL"); RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); + _pt = _get_fixed_payload_type(_media_type); + if (_pt != -1 && (unsigned int)_pt != pt) { + LOG_ERROR("this media_type[%s] only allows fixed payload type[%d]", _media_type, _pt); + return WEBRTC_ERROR_INVALID_PARAMETER; + } else if (pt < 96 || pt > 127) { + LOG_ERROR("invalid value[%u] for dynamic payload type (96 ~ 127)", pt); + return WEBRTC_ERROR_INVALID_PARAMETER; + } + 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; @@ -111,11 +129,12 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id 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); + RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL, + WEBRTC_ERROR_INVALID_PARAMETER, "could not find source"); + *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); diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 4accf041..429aab11 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -580,6 +580,20 @@ void _update_transceivers_for_offer(webrtc_s *webrtc) } } +int _get_fixed_payload_type(const gchar *media_type) +{ + RET_VAL_IF(media_type == NULL, -1, "media_type is NULL"); + + if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_MULAW)) + return 0; + if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_ALAW)) + return 8; + + LOG_DEBUG("%s might need to use dynamic id", media_type); + + return -1; +} + int _complete_sources(webrtc_s *webrtc) { int i; diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index 9c6020cc..31bbdf3a 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -374,20 +374,6 @@ const char *_get_element_name(int av_idx, gst_element_e element) return _av_element_tbl[av_idx][element]; } -static int __get_fixed_payload_type(const gchar *media_type) -{ - RET_VAL_IF(media_type == NULL, -1, "media_type is NULL"); - - if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_MULAW)) - return 0; - if (!g_strcmp0(media_type, MEDIA_TYPE_AUDIO_ALAW)) - return 8; - - LOG_DEBUG("%s might need to use dynamic id", media_type); - - return -1; -} - static int __get_available_payload_type(webrtc_s *webrtc) { int bitmask = 0x1; @@ -423,7 +409,7 @@ int _set_payload_type(webrtc_s *webrtc, webrtc_gst_slot_s *source, int av_idx, c } if (media_type) - if ((payload_type = __get_fixed_payload_type(media_type)) != -1) + if ((payload_type = _get_fixed_payload_type(media_type)) != -1) goto out; if ((payload_type = __get_available_payload_type(webrtc)) == -1)