webrtc_internal: Add more error conditions to webrtc_media_source_set_payload_type() 00/280200/3 accepted/tizen/unified/20220901.125808 submit/tizen/20220901.010928
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 25 Aug 2022 06:45:51 +0000 (15:45 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 30 Aug 2022 03:14:17 +0000 (12:14 +0900)
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 <sc11.lee@samsung.com>
include/webrtc_private.h
include/webrtc_source_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_source.c
src/webrtc_source_private.c

index bd011d67d6177ffc07cf7f6c54595dd149cee781..6fd900b8476576d6a1eedb56d276b1c577820619 100644 (file)
@@ -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);
index 7b6bc1be8ad68162b026b2dc9f27284f963e9152..7de4fe8a2755e723902d3fa4005d8b29dabfe5b4 100644 (file)
@@ -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);
index d7a86f57f1a016060c1e579d59a69468a668d37c..d93125af190f1898c232c3d9a14a3acce68669ea 100644 (file)
@@ -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
index 40f7fa6ed2fd67c06b1bcddc79c53795d74e42c8..45cd57c99185fab624b7475478d1cb029dafbe07 100644 (file)
@@ -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);
index 4accf041f16cad2761fbea2a7f840dd2426780e9..429aab1177390b374b4447c2f88f8a2fdef7c997 100644 (file)
@@ -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;
index 9c6020cc95c506390734f3c8a5ec1451b2227c87..31bbdf3a76c94c71a10a4f39689314255fb33894 100644 (file)
@@ -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)