webrtc_internal: Revise parameter of webrtc_media_source_set[get]_payload_type() 42/314142/2
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 5 Jul 2024 23:56:20 +0000 (08:56 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Mon, 8 Jul 2024 01:33:18 +0000 (10:33 +0900)
webrtc_test has been fixed to comply with the changes.

[Version] 1.1.9
[Issue Type] Internal API

Change-Id: I530e8210aa838e6dd4651cf0dc0b5a5631117ff1
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_internal.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
test/webrtc_test.c
test/webrtc_test_menu.c

index 9f881d2b58db037f92f503177c41aed8dae4043d..1ff986e807ddc082a28ca41b134011a5eecdf469 100644 (file)
@@ -293,39 +293,45 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i
 
 /**
  * @internal
- * @brief Sets the payload type to the media source.
+ * @brief Sets the RTP 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.\n
  *          #WEBRTC_ERROR_INVALID_STATE will no longer occur. (Since 9.0)
  * @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
+ * @param[in] codec       The transceiver codec
+ * @param[in] pt          The RTP 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_get_payload_type()
+ * @see webrtc_media_source_get_transceiver_codec()
+ * @see webrtc_media_source_set_transceiver_codec()
+ * @see webrtc_media_source_foreach_supported_transceiver_codec()
  */
-int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt);
+int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int pt);
 
 /**
  * @internal
- * @brief Gets the payload type of the media source.
+ * @brief Gets the RTP 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
+ * @param[in] codec       The transceiver codec
+ * @param[out] pt         The RTP 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()
+ * @see webrtc_media_source_get_transceiver_codec()
+ * @see webrtc_media_source_set_transceiver_codec()
+ * @see webrtc_media_source_foreach_supported_transceiver_codec()
  */
-int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt);
+int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int *pt);
 
 /**
  * @internal
index 397c4ff621ec734dbf0e569dafe3c8ca74fa1d09..dcd697cc73e345027ee78df1bed8680cb5066401 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    1.1.8
+Version:    1.1.9
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index bd9cb7b14f0d7a3f16e0db02d67ccabe9ef7250b..4b319a76f60d7c751117b271a7443214aaaef6db 100644 (file)
@@ -143,14 +143,50 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i
        return _add_media_source_internal(webrtc, type, source_id);
 }
 
-int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int pt)
+static bool __match_codec_with_media_type(webrtc_transceiver_codec_e codec, const char *media_type)
+{
+       ASSERT(media_type);
+
+       switch (codec) {
+       case WEBRTC_TRANSCEIVER_CODEC_PCMU:
+               if (g_strrstr(media_type, "pcmu") || g_strrstr(media_type, "PCMU"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_PCMA:
+               if (g_strrstr(media_type, "pcma") || g_strrstr(media_type, "PCMA"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_OPUS:
+               if (g_strrstr(media_type, "opus") || g_strrstr(media_type, "OPUS"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_VP8:
+               if (g_strrstr(media_type, "vp8") || g_strrstr(media_type, "VP8"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_VP9:
+               if (g_strrstr(media_type, "vp9") || g_strrstr(media_type, "VP9"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_H264:
+               if (g_strrstr(media_type, "h264") || g_strrstr(media_type, "H264"))
+                       return true;
+               break;
+       default:
+               LOG_ERROR("not supported codec[0x%x]", codec);
+       }
+
+       return false;
+}
+
+int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int pt)
 {
        webrtc_s *_webrtc = (webrtc_s *)webrtc;
        webrtc_gst_slot_s *source;
        g_autoptr(GMutexLocker) locker = NULL;
        const char *_media_type;
        int _pt;
-       int av_idx = GET_AV_IDX(media_type == WEBRTC_MEDIA_TYPE_AUDIO);
+       int av_idx = GET_AV_IDX(codec & CODEC_TYPE_AUDIO);
 
        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");
@@ -160,11 +196,12 @@ int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id
        RET_VAL_IF((source = _get_slot_by_id(_webrtc->gst.source_slots, source_id)) == NULL,
                WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
 
-       if (media_type == WEBRTC_MEDIA_TYPE_AUDIO)
+       if (codec & CODEC_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(!__match_codec_with_media_type(codec, _media_type), WEBRTC_ERROR_INVALID_PARAMETER, "codec does not match with media_type");
 
        _pt = _get_fixed_payload_type(_media_type);
        if (_pt != -1 && (unsigned int)_pt != pt) {
@@ -190,20 +227,20 @@ int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id
        source->av[av_idx].pt = pt;
        source->av[av_idx].pt_set_by_api = true;
 
-       LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, pt);
+       LOG_INFO("webrtc[%p] source_id[%u] codec[0x%x] payload type[%u]", _webrtc, source_id, codec, pt);
 
        return _update_pt_if_media_packet_source(webrtc, source);
 }
 
-int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt)
+int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int *pt)
 {
        webrtc_s *_webrtc = (webrtc_s *)webrtc;
        webrtc_gst_slot_s *source;
        g_autoptr(GMutexLocker) locker = NULL;
+       const char *_media_type;
 
        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(media_type > WEBRTC_MEDIA_TYPE_VIDEO, WEBRTC_ERROR_INVALID_PARAMETER, "invalid media type");
        RET_VAL_IF(pt == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "pt is NULL");
 
        locker = g_mutex_locker_new(&_webrtc->mutex);
@@ -211,9 +248,15 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
        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;
+       if (codec & CODEC_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(!__match_codec_with_media_type(codec, _media_type), WEBRTC_ERROR_INVALID_PARAMETER, "codec does not match with media_type");
+
+       *pt = source->av[GET_AV_IDX(codec & CODEC_TYPE_AUDIO)].pt;
 
-       LOG_INFO("webrtc[%p] source_id[%u] media_type[%u] payload type[%u]", _webrtc, source_id, media_type, *pt);
+       LOG_INFO("webrtc[%p] source_id[%u] codec[0x%x] payload type[%u]", _webrtc, source_id, codec, *pt);
 
        return WEBRTC_ERROR_NONE;
 }
index 7b0ff265a732d14750161ec8da5b0193a09280cf..42d2cfd72e81628e48fbcd8382878d620529e524 100644 (file)
@@ -1191,23 +1191,23 @@ static void _webrtc_screen_source_unset_crop(int index, unsigned int source_id)
                g_print("failed to webrtc_screen_source_unset_crop(), source_id[%d], ret[0x%x]\n", source_id, ret);
 }
 
-static void _webrtc_media_source_get_payload_type(int index, unsigned int source_id, webrtc_media_type_e media_type)
+static void _webrtc_media_source_get_payload_type(int index, unsigned int source_id, webrtc_transceiver_codec_e codec)
 {
        unsigned int pt;
-       int ret = webrtc_media_source_get_payload_type(g_ad.conns[index].webrtc, source_id, media_type, &pt);
+       int ret = webrtc_media_source_get_payload_type(g_ad.conns[index].webrtc, source_id, codec, &pt);
        RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
 
-       g_print("webrtc_media_source_get_payload_type() success, source_id[%u], media_type[%s], pt[%u]\n",
-               source_id, g_webrtc_media_type_str[media_type], pt);
+       g_print("webrtc_media_source_get_payload_type() success, source_id[%u], codec[0x%x], pt[%u]\n",
+               source_id, codec, pt);
 }
 
-static void _webrtc_media_source_set_payload_type(int index, unsigned int source_id, webrtc_media_type_e media_type, int value)
+static void _webrtc_media_source_set_payload_type(int index, unsigned int source_id, webrtc_transceiver_codec_e codec, int value)
 {
-       int ret = webrtc_media_source_set_payload_type(g_ad.conns[index].webrtc, source_id, media_type, (unsigned int)value);
+       int ret = webrtc_media_source_set_payload_type(g_ad.conns[index].webrtc, source_id, codec, (unsigned int)value);
        RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
 
-       g_print("webrtc_media_source_set_payload_type() success, source_id[%u], media_type[%s], pt[%u]\n",
-               source_id, g_webrtc_media_type_str[media_type], value);
+       g_print("webrtc_media_source_set_payload_type() success, source_id[%u], codec[0x%x], pt[%u]\n",
+               source_id, codec, value);
 }
 
 static void _webrtc_media_source_add_transceiver_encoding(int index, unsigned int source_id, webrtc_media_type_e media_type, const char *rid, int target_bitrate, int w, int h)
@@ -3628,7 +3628,7 @@ static void test_webrtc_media_source(char *cmd)
                break;
        case CURRENT_STATUS_MEDIA_SOURCE_SET_PAYLOAD_TYPE: {
                static unsigned int id;
-               static unsigned int media_type;
+               static int codec_selected;
 
                switch (g_ad.input_count) {
                case 0:
@@ -3636,33 +3636,71 @@ static void test_webrtc_media_source(char *cmd)
                        g_ad.input_count++;
                        return;
                case 1:
-                       media_type = value - 1;
+                       if (value < 1 || value > 6) {
+                               g_printerr("invalid codec selection\n");
+                               id = g_ad.input_count = 0;
+                               break;
+                       }
+                       codec_selected = value;
                        g_ad.input_count++;
                        return;
-               case 2:
-                       _webrtc_media_source_set_payload_type(0, id, media_type, value);
-                       id = media_type = 0;
+               case 2: {
+                       webrtc_transceiver_codec_e codec = WEBRTC_TRANSCEIVER_CODEC_PCMU;
+                       if (codec_selected == 1)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_PCMU;
+                       else if (codec_selected == 2)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_PCMA;
+                       else if (codec_selected == 3)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_OPUS;
+                       else if (codec_selected == 4)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_VP8;
+                       else if (codec_selected == 5)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_VP9;
+                       else if (codec_selected == 6)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_H264;
+
+                       _webrtc_media_source_set_payload_type(0, id, codec, value);
+                       id = codec_selected = 0;
                        g_ad.input_count = 0;
                        break;
                }
+               }
                break;
        }
        case CURRENT_STATUS_MEDIA_SOURCE_GET_PAYLOAD_TYPE: {
                static unsigned int id;
-               static unsigned int media_type;
 
                switch (g_ad.input_count) {
                case 0:
                        id = value;
                        g_ad.input_count++;
                        return;
-               case 1:
-                       media_type = value - 1;
-                       _webrtc_media_source_get_payload_type(0, id, media_type);
-                       id = media_type = 0;
+               case 1: {
+                       webrtc_transceiver_codec_e codec;
+                       if (value < 1 || value > 6) {
+                               g_printerr("invalid codec selection\n");
+                               id = g_ad.input_count = 0;
+                               break;
+                       }
+                       if (value == 1)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_PCMU;
+                       else if (value == 2)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_PCMA;
+                       else if (value == 3)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_OPUS;
+                       else if (value == 4)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_VP8;
+                       else if (value == 5)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_VP9;
+                       else if (value == 6)
+                               codec = WEBRTC_TRANSCEIVER_CODEC_H264;
+
+                       _webrtc_media_source_get_payload_type(0, id, codec);
+                       id = 0;
                        g_ad.input_count = 0;
                        break;
                }
+               }
                break;
        }
        case CURRENT_STATUS_MEDIA_SOURCE_ADD_TRANSCEIVER_ENCODING: {
index 7b214b2fed158dd5150c12994bb091a47735c44b..f07126371fee8272520d6df9e2885a6d72dec935 100644 (file)
@@ -496,7 +496,7 @@ void display_menu_webrtc_media_source(void)
                if (get_appdata()->input_count == 0)
                        g_print("*** input source id.\n");
                else if (get_appdata()->input_count == 1)
-                       g_print("*** input media type.(1:audio 2:video)\n");
+                       g_print("*** input transceiver codec.(1:PCMU 2:PCMA 3:OPUS 4:VP8 5:VP9 6:H264)\n");
                else if (get_appdata()->input_count == 2)
                        g_print("*** input payload type.\n");
                break;
@@ -504,7 +504,7 @@ void display_menu_webrtc_media_source(void)
                if (get_appdata()->input_count == 0)
                        g_print("*** input source id.\n");
                else if (get_appdata()->input_count == 1)
-                       g_print("*** input media type.(1:audio 2:video)\n");
+                       g_print("*** input transceiver codec.(1:PCMU 2:PCMA 3:OPUS 4:VP8 5:VP9 6:H264)\n");
                break;
        case CURRENT_STATUS_MEDIA_SOURCE_ADD_TRANSCEIVER_ENCODING:
                if (get_appdata()->input_count == 0)