webrtc_source: Specify payload type to transceiver codec only in case of offer 41/279941/2
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 19 Aug 2022 06:30:32 +0000 (15:30 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 23 Aug 2022 07:21:19 +0000 (16:21 +0900)
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 <sc11.lee@samsung.com>
include/webrtc_private.h
include/webrtc_source_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_source.c
src/webrtc_source_private.c

index 8445de0c832ae6b89acbe3df541fd96194373c34..4ea4bce42778180b4ffed2bbbb43e19bdfc4fc96 100644 (file)
@@ -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);
index 1104466486658ca746188758bad834b3f304a7ef..e93037362ff905f8bc90d26aa9891b0c791866a0 100644 (file)
@@ -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);
index e418211177d67602c744ef0d6dc500ea204c5038..1a10a8010f08a5dc107f289cf908946faab6fb2c 100644 (file)
@@ -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
index c92e2e3ced208d220b48dc1a31ead369f973d98f..4fd7f43bb84fcaeaf45c392b2dc2e9e802bb5b58 100644 (file)
@@ -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);
 }
index e8417976515f54a591fa666a52a05b362865aac9..b161cacf07626fcecbe488ec93cd07686345852e 100644 (file)
@@ -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;
index 58110a504f77866e76527f306739f2f26fbc64f9..a34ef513f590ff3114df0d7e90ee20c3238b79d5 100644 (file)
@@ -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;