Add webrtc_media_source_set_payload_type() and webrtc_media_source_get_payload_type() 89/315889/1
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 9 Aug 2024 02:04:54 +0000 (11:04 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 9 Aug 2024 02:04:54 +0000 (11:04 +0900)
[Version] 1.1.24
[Issue Type] API

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

index de8d44900f165258ac48507ad571fda4f8716130..bfbd8bb84a99713bcbe395dc9177ce30a4dc626c 100644 (file)
@@ -1227,6 +1227,45 @@ int webrtc_media_source_set_transceiver_codec(webrtc_h webrtc, unsigned int sour
  */
 int webrtc_media_source_get_transceiver_codec(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_codec_e *codec);
 
+/**
+ * @brief Sets the RTP payload type to the media source.
+ * @since_tizen 9.0
+ * @remarks This function would be used to set a specific payload type of a codec complying with a remote peer's offer description.
+ * @param[in] webrtc      WebRTC handle
+ * @param[in] source_id   The media source id
+ * @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_transceiver_codec_e codec, unsigned int pt);
+
+/**
+ * @brief Gets the RTP payload type of the media source.
+ * @since_tizen 9.0
+ * @param[in] webrtc      WebRTC handle
+ * @param[in] source_id   The media source id
+ * @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_transceiver_codec_e codec, unsigned int *pt);
+
 /**
  * @brief Sets pause to the media source.
  * @since_tizen 6.5
index 5a8e63d746b9416403293725a4cb521f15addbad..ec4b09025fad375e37e7008c8eba0efcdef67979 100644 (file)
@@ -283,48 +283,6 @@ 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 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] 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_transceiver_codec_e codec, unsigned int pt);
-
-/**
- * @internal
- * @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] 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_transceiver_codec_e codec, unsigned int *pt);
-
 /**
  * @internal
  * @brief Adds the transceiver encoding option to the media source.
index f8ad2136ca80e609aef8ed2438087f042607e828..6f0a92923fe26a3aa6d6e6c940f67c93a87ce029 100644 (file)
@@ -824,6 +824,8 @@ const char *_get_video_media_type(const char *codec_name);
 void _source_slot_destroy_cb(gpointer data);
 int _add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id);
 int _add_media_source_internal(webrtc_s *webrtc, int type, unsigned int *source_id);
+int _set_manual_payload_type(webrtc_s *webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int pt);
+int _get_manual_payload_type(webrtc_s *webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int *pt);
 int _start_media_source(webrtc_s *webrtc, unsigned int source_id);
 int _remove_media_source(webrtc_s *webrtc, unsigned int source_id);
 bool _check_if_codec_is_set_to_null_sources(webrtc_s *webrtc);
index 09c3e7528f864c648ba1ac90fb7f4264ad161db4..e73837b62f1fe2523b06cca33e388b1cb5a53f2d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    1.1.23
+Version:    1.1.24
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index e90425649fb1f36e1a78ea9185c43ed9d3dbfa05..53a4fa7cbdc0ebe3a818ea407a1f80a2b1560036 100644 (file)
@@ -466,6 +466,33 @@ int webrtc_media_source_get_transceiver_codec(webrtc_h webrtc, unsigned int sour
        return _get_transceiver_codec(webrtc, source_id, media_type, codec);
 }
 
+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;
+       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");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       return _set_manual_payload_type(_webrtc, source_id, codec, 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;
+       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");
+
+       locker = g_mutex_locker_new(&_webrtc->mutex);
+
+       return _get_manual_payload_type(_webrtc, source_id, codec, pt);
+}
+
 int webrtc_media_source_set_pause(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool pause)
 {
        g_autoptr(GMutexLocker) locker = NULL;
index a4f5d71b507fe6c8647d6aaacf20c4eab316cf42..c0b3a8ea94af7912f054f07ae4f5114ba44af82f 100644 (file)
@@ -144,171 +144,6 @@ int webrtc_add_media_source_internal(webrtc_h webrtc, webrtc_media_source_type_i
        return _add_media_source_internal(webrtc, type, source_id);
 }
 
-static bool __match_codec_with_media_type(webrtc_transceiver_codec_e codec, const char *media_type)
-{
-       RET_VAL_IF(media_type == NULL, false, "media_type is NULL");
-
-       switch (codec) {
-       case WEBRTC_TRANSCEIVER_CODEC_PCMU:
-               if (g_strrstr(media_type, "mulaw") || g_strrstr(media_type, "MULAW"))
-                       return true;
-               break;
-       case WEBRTC_TRANSCEIVER_CODEC_PCMA:
-               if (g_strrstr(media_type, "alaw") || g_strrstr(media_type, "ALAW"))
-                       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(codec & CODEC_TYPE_AUDIO);
-       int mc_idx = -1;
-       int i;
-
-       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");
-
-       if (source->av[av_idx].num_of_codecs > 0) {
-               for (i = 0; i < source->av[av_idx].num_of_codecs; i++) {
-                       const char *codec_str = source->av[av_idx].multiple_codecs[i].codec;
-                       _media_type = (codec & CODEC_TYPE_AUDIO) ?
-                               _get_audio_media_type(codec_str) : _get_video_media_type(codec_str);
-                       if (__match_codec_with_media_type(codec, _media_type)) {
-                               mc_idx = i;
-                               break;
-                       }
-               }
-               RET_VAL_IF(mc_idx == -1, WEBRTC_ERROR_INVALID_PARAMETER, "matched codec is not found");
-
-       } else {
-               _media_type = (codec & CODEC_TYPE_AUDIO) ?
-                       _get_audio_media_type(source->av[av_idx].codec) : _get_video_media_type(source->av[av_idx].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) {
-               LOG_ERROR("this media_type[%s] only allows fixed payload type[%d]", _media_type, _pt);
-               return WEBRTC_ERROR_INVALID_PARAMETER;
-       }
-
-       if (mc_idx != -1 && pt == source->av[av_idx].multiple_codecs[mc_idx].pt) {
-               if (!source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api)
-                       _return_payload_type(_webrtc, source->av[av_idx].multiple_codecs[mc_idx].pt);
-               source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api = true;
-               LOG_INFO("already payload type[%u] was set", source->av[av_idx].multiple_codecs[mc_idx].pt);
-               return WEBRTC_ERROR_NONE;
-
-       } else if (pt == source->av[av_idx].pt) {
-               if (!source->av[av_idx].pt_set_by_api)
-                       _return_payload_type(_webrtc, source->av[av_idx].pt);
-               source->av[av_idx].pt_set_by_api = true;
-               LOG_INFO("already payload type[%u] was set", source->av[av_idx].pt);
-               return WEBRTC_ERROR_NONE;
-
-       } else if (pt < 96 || pt > 127) {
-               LOG_ERROR("invalid value[%u] for dynamic payload type (96 ~ 127)", pt);
-               return WEBRTC_ERROR_INVALID_PARAMETER;
-       }
-
-       /* release the previous pt */
-       if (mc_idx != -1) {
-               if (!source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api &&
-                       source->av[av_idx].multiple_codecs[mc_idx].pt > 0)
-                       _return_payload_type(_webrtc, source->av[av_idx].multiple_codecs[mc_idx].pt);
-
-               source->av[av_idx].multiple_codecs[mc_idx].pt = pt;
-               source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api = true;
-       } else {
-               if (!source->av[av_idx].pt_set_by_api && source->av[av_idx].pt > 0)
-                       _return_payload_type(_webrtc, source->av[av_idx].pt);
-
-               source->av[av_idx].pt = pt;
-               source->av[av_idx].pt_set_by_api = true;
-       }
-
-       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_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 av_idx = GET_AV_IDX(codec & CODEC_TYPE_AUDIO);
-       int i;
-
-       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");
-
-       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");
-
-       if (source->av[av_idx].num_of_codecs > 0) {
-               for (i = 0; i < source->av[av_idx].num_of_codecs; i++) {
-                       const char *codec_str = source->av[av_idx].multiple_codecs[i].codec;
-                       _media_type = (codec & CODEC_TYPE_AUDIO) ?
-                               _get_audio_media_type(codec_str) : _get_video_media_type(codec_str);
-                       if (__match_codec_with_media_type(codec, _media_type)) {
-                               *pt = source->av[av_idx].multiple_codecs[i].pt;
-
-                               LOG_INFO("webrtc[%p] source_id[%u] codec[0x%x] payload type[%u]", _webrtc, source_id, codec, *pt);
-                               return WEBRTC_ERROR_NONE;
-                       }
-               }
-               LOG_ERROR("could not find matched codec[0x%x]", codec);
-               return WEBRTC_ERROR_INVALID_PARAMETER;
-       }
-
-       _media_type = (codec & CODEC_TYPE_AUDIO) ?
-               _get_audio_media_type(source->av[av_idx].codec) : _get_video_media_type(source->av[av_idx].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] codec[0x%x] payload type[%u]", _webrtc, source_id, codec, *pt);
-
-       return WEBRTC_ERROR_NONE;
-}
-
 int webrtc_media_source_add_transceiver_encoding(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, const char *rid, int target_bitrate, int width, int height, int *ssrc)
 {
        g_autoptr(GMutexLocker) locker = NULL;
index 27c46f142eb2a79ec2ef718a0109fb04e13a8be3..b7364f3300c56da01bb12f9ca1d4833b1adfefba 100644 (file)
@@ -882,6 +882,165 @@ int _remove_media_source(webrtc_s *webrtc, unsigned int source_id)
        return ret;
 }
 
+static bool __match_codec_with_media_type(webrtc_transceiver_codec_e codec, const char *media_type)
+{
+       RET_VAL_IF(media_type == NULL, false, "media_type is NULL");
+
+       switch (codec) {
+       case WEBRTC_TRANSCEIVER_CODEC_PCMU:
+               if (g_strrstr(media_type, "mulaw") || g_strrstr(media_type, "MULAW"))
+                       return true;
+               break;
+       case WEBRTC_TRANSCEIVER_CODEC_PCMA:
+               if (g_strrstr(media_type, "alaw") || g_strrstr(media_type, "ALAW"))
+                       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 _set_manual_payload_type(webrtc_s *webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int pt)
+{
+       webrtc_gst_slot_s *source;
+       g_autoptr(GMutexLocker) locker = NULL;
+       const char *_media_type;
+       int _pt;
+       int av_idx = GET_AV_IDX(codec & CODEC_TYPE_AUDIO);
+       int mc_idx = -1;
+       int i;
+
+       ASSERT(webrtc);
+       ASSERT(source_id != 0);
+
+       RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL,
+               WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+
+       if (source->av[av_idx].num_of_codecs > 0) {
+               for (i = 0; i < source->av[av_idx].num_of_codecs; i++) {
+                       const char *codec_str = source->av[av_idx].multiple_codecs[i].codec;
+                       _media_type = (codec & CODEC_TYPE_AUDIO) ?
+                               _get_audio_media_type(codec_str) : _get_video_media_type(codec_str);
+                       if (__match_codec_with_media_type(codec, _media_type)) {
+                               mc_idx = i;
+                               break;
+                       }
+               }
+               RET_VAL_IF(mc_idx == -1, WEBRTC_ERROR_INVALID_PARAMETER, "matched codec is not found");
+
+       } else {
+               _media_type = (codec & CODEC_TYPE_AUDIO) ?
+                       _get_audio_media_type(source->av[av_idx].codec) : _get_video_media_type(source->av[av_idx].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) {
+               LOG_ERROR("this media_type[%s] only allows fixed payload type[%d]", _media_type, _pt);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       if (mc_idx != -1 && pt == source->av[av_idx].multiple_codecs[mc_idx].pt) {
+               if (!source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api)
+                       _return_payload_type(webrtc, source->av[av_idx].multiple_codecs[mc_idx].pt);
+               source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api = true;
+               LOG_INFO("already payload type[%u] was set", source->av[av_idx].multiple_codecs[mc_idx].pt);
+               return WEBRTC_ERROR_NONE;
+
+       } else if (pt == source->av[av_idx].pt) {
+               if (!source->av[av_idx].pt_set_by_api)
+                       _return_payload_type(webrtc, source->av[av_idx].pt);
+               source->av[av_idx].pt_set_by_api = true;
+               LOG_INFO("already payload type[%u] was set", source->av[av_idx].pt);
+               return WEBRTC_ERROR_NONE;
+
+       } else if (pt < 96 || pt > 127) {
+               LOG_ERROR("invalid value[%u] for dynamic payload type (96 ~ 127)", pt);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       /* release the previous pt */
+       if (mc_idx != -1) {
+               if (!source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api &&
+                       source->av[av_idx].multiple_codecs[mc_idx].pt > 0)
+                       _return_payload_type(webrtc, source->av[av_idx].multiple_codecs[mc_idx].pt);
+
+               source->av[av_idx].multiple_codecs[mc_idx].pt = pt;
+               source->av[av_idx].multiple_codecs[mc_idx].pt_set_by_api = true;
+       } else {
+               if (!source->av[av_idx].pt_set_by_api && source->av[av_idx].pt > 0)
+                       _return_payload_type(webrtc, source->av[av_idx].pt);
+
+               source->av[av_idx].pt = pt;
+               source->av[av_idx].pt_set_by_api = true;
+       }
+
+       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 _get_manual_payload_type(webrtc_s *webrtc, unsigned int source_id, webrtc_transceiver_codec_e codec, unsigned int *pt)
+{
+       webrtc_gst_slot_s *source;
+       g_autoptr(GMutexLocker) locker = NULL;
+       const char *_media_type;
+       int av_idx = GET_AV_IDX(codec & CODEC_TYPE_AUDIO);
+       int i;
+
+       ASSERT(webrtc);
+       ASSERT(source_id != 0);
+       ASSERT(pt);
+
+       RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL,
+               WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+
+       if (source->av[av_idx].num_of_codecs > 0) {
+               for (i = 0; i < source->av[av_idx].num_of_codecs; i++) {
+                       const char *codec_str = source->av[av_idx].multiple_codecs[i].codec;
+                       _media_type = (codec & CODEC_TYPE_AUDIO) ?
+                               _get_audio_media_type(codec_str) : _get_video_media_type(codec_str);
+                       if (__match_codec_with_media_type(codec, _media_type)) {
+                               *pt = source->av[av_idx].multiple_codecs[i].pt;
+
+                               LOG_INFO("webrtc[%p] source_id[%u] codec[0x%x] payload type[%u]", webrtc, source_id, codec, *pt);
+                               return WEBRTC_ERROR_NONE;
+                       }
+               }
+               LOG_ERROR("could not find matched codec[0x%x]", codec);
+               return WEBRTC_ERROR_INVALID_PARAMETER;
+       }
+
+       _media_type = (codec & CODEC_TYPE_AUDIO) ?
+               _get_audio_media_type(source->av[av_idx].codec) : _get_video_media_type(source->av[av_idx].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] codec[0x%x] payload type[%u]", webrtc, source_id, codec, *pt);
+
+       return WEBRTC_ERROR_NONE;
+}
+
 int _set_pause(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool pause)
 {
        webrtc_gst_slot_s *source;
index d4769826821da6883a758a74edf6fe8b0b79f20a..97574d7573fdc5da3b3d1c5da36304a2f8f630ff 100644 (file)
@@ -247,8 +247,8 @@ void display_menu_main(void)
        g_print("fc. Get supported transceiver codecs\t");
        g_print("tc. Set transceiver codec\t");
        g_print("gc. Get transceiver codec\n");
-       g_print("spt. *Set payload type\t");
-       g_print("gpt. *Get payload type\n");
+       g_print("spt. Set payload type\t");
+       g_print("gpt. Get payload type\n");
        g_print("nsm. *Set media type to null source\t");
        g_print("pa. Set media path to file source\n");
        g_print("sfl. Set file source looping\t");