From 83c55b4530f3c618b1564b9f609dbddb068758c5 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Fri, 9 Aug 2024 11:04:54 +0900 Subject: [PATCH] Add webrtc_media_source_set_payload_type() and webrtc_media_source_get_payload_type() [Version] 1.1.24 [Issue Type] API Change-Id: I9d28bff26198e2239783e4f28467e8b98a124876 Signed-off-by: Sangchul Lee --- include/webrtc.h | 39 ++++++++ include/webrtc_internal.h | 42 -------- include/webrtc_private.h | 2 + packaging/capi-media-webrtc.spec | 2 +- src/webrtc.c | 27 +++++ src/webrtc_internal.c | 165 ------------------------------- src/webrtc_source.c | 159 +++++++++++++++++++++++++++++ test/webrtc_test_menu.c | 4 +- 8 files changed, 230 insertions(+), 210 deletions(-) diff --git a/include/webrtc.h b/include/webrtc.h index de8d4490..bfbd8bb8 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -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 diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 5a8e63d7..ec4b0902 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -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. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index f8ad2136..6f0a9292 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 09c3e752..e73837b6 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: 1.1.23 +Version: 1.1.24 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index e9042564..53a4fa7c 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -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; diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index a4f5d71b..c0b3a8ea 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -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; diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 27c46f14..b7364f33 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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; diff --git a/test/webrtc_test_menu.c b/test/webrtc_test_menu.c index d4769826..97574d75 100644 --- a/test/webrtc_test_menu.c +++ b/test/webrtc_test_menu.c @@ -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"); -- 2.34.1