From: Sangchul Lee Date: Fri, 19 Aug 2022 06:30:32 +0000 (+0900) Subject: webrtc_source: Specify payload type to transceiver codec only in case of offer X-Git-Tag: submit/tizen/20220825.024408~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F279941%2F2;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Specify payload type to transceiver codec only in case of offer This patch is only for WEBRTC_MEDIA_SOURCE_TYPE_NULL. This fixes a compatibility issue in case of chrome(offerer) - tizen native API(answerer) [Version] 0.3.208 [Issue Type] Compatibility Change-Id: Ib367e5142b4082bac02acf95329c9f3fb3eafa55 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 8445de0c..4ea4bce4 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -693,6 +693,7 @@ int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id); /* source */ int _complete_sources(webrtc_s *webrtc); +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); int _add_media_source_internal(webrtc_s *webrtc, int type, unsigned int *source_id); diff --git a/include/webrtc_source_private.h b/include/webrtc_source_private.h index 11044664..e9303736 100644 --- a/include/webrtc_source_private.h +++ b/include/webrtc_source_private.h @@ -106,6 +106,7 @@ void _remove_probe_from_pad_for_render(webrtc_gst_slot_s *source, unsigned int i rtp_payload_info_s * _get_payload_info(webrtc_transceiver_codec_e codec); rtp_payload_info_s * _get_payload_info_by_encoding_name(const char *encoding_name); int _add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, rtp_payload_info_s *payload_info); +int _update_transceiver_with_pt(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, rtp_payload_info_s *payload_info); int _link_source_with_webrtcbin(webrtc_gst_slot_s *source, GstElement *webrtcbin); int _create_rest_of_elements(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool need_capsfilter, GList **element_list, bool is_audio); int _set_encoder_element_bitrate(GstElement *encoder, int target_bitrate); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index e4182111..1a10a801 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.207 +Version: 0.3.208 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index c92e2e3c..4fd7f43b 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -1517,6 +1517,7 @@ int webrtc_create_offer(webrtc_h webrtc, bundle *options, char **offer) LOG_INFO("webrtc[%p] offer[%p]", webrtc, offer); _update_transceivers_fec(webrtc, true); + _update_transceivers_for_offer(webrtc); return _webrtcbin_create_session_description(webrtc, true, offer); } diff --git a/src/webrtc_source.c b/src/webrtc_source.c index e8417976..b161cacf 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -533,18 +533,52 @@ static void __check_and_add_recvonly_transceiver(webrtc_gst_slot_s *source) RET_IF(source == NULL, "source is NULL"); if (source->av[AV_IDX_AUDIO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_AUDIO].codec) { - payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_AUDIO].codec); - if (payload_info) + if ((payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_AUDIO].codec))) _add_transceiver(source, WEBRTC_MEDIA_TYPE_AUDIO, payload_info); } if (source->av[AV_IDX_VIDEO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_VIDEO].codec) { - payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_VIDEO].codec); - if (payload_info) + if ((payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_VIDEO].codec))) _add_transceiver(source, WEBRTC_MEDIA_TYPE_VIDEO, payload_info); } } +static void __check_and_update_transceiver(webrtc_gst_slot_s *source) +{ + rtp_payload_info_s *payload_info = NULL; + + RET_IF(source == NULL, "source is NULL"); + + if (source->av[AV_IDX_AUDIO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_AUDIO].codec) { + if ((payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_AUDIO].codec))) + _update_transceiver_with_pt(source, WEBRTC_MEDIA_TYPE_AUDIO, payload_info); + } + + if (source->av[AV_IDX_VIDEO].direction == WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY && source->av[AV_IDX_VIDEO].codec) { + if ((payload_info = _get_payload_info_by_encoding_name(source->av[AV_IDX_VIDEO].codec))) + _update_transceiver_with_pt(source, WEBRTC_MEDIA_TYPE_VIDEO, payload_info); + } +} + +void _update_transceivers_for_offer(webrtc_s *webrtc) +{ + int i; + webrtc_gst_slot_s *source; + RET_IF(webrtc == NULL, "webrtc is NULL"); + + for (i = 0; i < MAX_SOURCE_NUM; i++) { + if (!(source = webrtc->gst.sources[i])) + continue; + + if (source->type != WEBRTC_MEDIA_SOURCE_TYPE_NULL) + continue; + + LOG_DEBUG("source[id:%u, type:%d, media_types:0x%x]", source->id, source->type, source->media_types); + + __check_and_update_transceiver(source); + } +} + int _complete_sources(webrtc_s *webrtc) { int i; diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index 58110a50..a34ef513 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -608,7 +608,18 @@ rtp_payload_info_s * _get_payload_info_by_encoding_name(const char *encoding_nam return NULL; } -static GstCaps *__make_transceiver_caps(rtp_payload_info_s *payload_info, int payload_type) +static GstCaps *__make_transceiver_caps(rtp_payload_info_s *payload_info) +{ + RET_VAL_IF(payload_info == NULL, NULL, "payload_info is NULL"); + + return gst_caps_new_simple("application/x-rtp", + "media", G_TYPE_STRING, payload_info->media_type, + "encoding-name", G_TYPE_STRING, payload_info->encoding_name, + "clock-rate", G_TYPE_INT, payload_info->clock_rate, + NULL); +} + +static GstCaps *__make_transceiver_caps_with_pt(rtp_payload_info_s *payload_info, int payload_type) { RET_VAL_IF(payload_info == NULL, NULL, "payload_info is NULL"); @@ -622,14 +633,14 @@ static GstCaps *__make_transceiver_caps(rtp_payload_info_s *payload_info, int pa int _add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, rtp_payload_info_s *payload_info) { - GstWebRTCRTPTransceiver *trans = NULL; - GstCaps *caps = NULL; + GstWebRTCRTPTransceiver *trans; + GstCaps *caps; int av_idx = (media_type == WEBRTC_MEDIA_TYPE_AUDIO) ? AV_IDX_AUDIO : AV_IDX_VIDEO; RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(payload_info == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "payload_info is NULL"); - caps = __make_transceiver_caps(payload_info, source->av[av_idx].pt); + caps = __make_transceiver_caps(payload_info); PRINT_CAPS(caps, "transceiver"); if (!source->av[av_idx].transceiver) { @@ -648,6 +659,28 @@ int _add_transceiver(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, return WEBRTC_ERROR_NONE; } +int _update_transceiver_with_pt(webrtc_gst_slot_s *source, webrtc_media_type_e media_type, rtp_payload_info_s *payload_info) +{ + GstCaps *caps; + int av_idx = (media_type == WEBRTC_MEDIA_TYPE_AUDIO) ? AV_IDX_AUDIO : AV_IDX_VIDEO; + + RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(payload_info == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "payload_info is NULL"); + RET_VAL_IF(source->av[av_idx].transceiver == NULL, WEBRTC_ERROR_INVALID_OPERATION, "transceiver is NULL"); + + caps = __make_transceiver_caps_with_pt(payload_info, source->av[av_idx].pt); + PRINT_CAPS(caps, "transceiver"); + + g_object_set(G_OBJECT(source->av[av_idx].transceiver), "codec-preferences", caps, NULL); + + gst_caps_unref(caps); + + LOG_DEBUG("webrtc[%p] source_id[%u] [%s] transceiver[%p] codec[%s]", + source->webrtc, source->id, payload_info->media_type, source->av[av_idx].transceiver, payload_info->encoding_name); + + return WEBRTC_ERROR_NONE; +} + static bool __is_linked_pad(webrtc_gst_slot_s *source, const char *pad_name) { GstIterator *iter = NULL;