From 72c1a9b7b10602bc34a0b64ee80c91b5e9cebebb Mon Sep 17 00:00:00 2001 From: hj kim Date: Fri, 1 Jul 2022 15:55:14 +0900 Subject: [PATCH] webrtc_source: Fix to return previous payload type before getting new one [Version] 0.3.141 [Issue Type] Bug fix Change-Id: I1680cac9e845da25102c88bcab8365d1df450b5c --- packaging/capi-media-webrtc.spec | 2 +- src/webrtc_source.c | 62 +++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 3ac7b139..49308471 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.140 +Version: 0.3.141 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 60d1ff0c..c3b04717 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -63,6 +63,9 @@ #define ELEMENT_NAME_AUDIO_APPSRC "audioAppsrc" #define ELEMENT_NAME_VIDEO_APPSRC "videoAppsrc" +#define MIN_DYNAMIC_PAYLOAD_TYPE 96 +#define MAX_DYNAMIC_PAYLOAD_TYPE 127 + #define APPEND_ELEMENT(x_list, x_element) \ do { \ if (!(x_element)) \ @@ -774,7 +777,7 @@ static unsigned int __get_available_payload_type(webrtc_s *webrtc) } webrtc->payload_types |= bitmask; LOG_DEBUG("found available payload type[%d]", count + 95); - return count + 95; /* 96 ~ 127 */ + return count + (MIN_DYNAMIC_PAYLOAD_TYPE - 1); /* 96 ~ 127 */ } LOG_ERROR("could not assign payload type"); @@ -787,9 +790,10 @@ static void __return_payload_type(webrtc_s *webrtc, unsigned int payload_type) int bitmask = 0x1; RET_IF(webrtc == NULL, "webrtc is NULL"); - RET_IF(payload_type < 96 || payload_type > 127, "invalid payload_type(%u)", payload_type); + RET_IF(payload_type < MIN_DYNAMIC_PAYLOAD_TYPE || payload_type > MAX_DYNAMIC_PAYLOAD_TYPE, "invalid payload_type(%u)", payload_type); + + i = payload_type - MIN_DYNAMIC_PAYLOAD_TYPE; - i = payload_type - 96; while (i-- > 0) bitmask <<= 1; @@ -1735,6 +1739,34 @@ exit: return WEBRTC_ERROR_INVALID_OPERATION; } +static 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; + 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); + PRINT_CAPS(caps, "transceiver"); + + if (!source->av[av_idx].transceiver) { + g_signal_emit_by_name(source->webrtc->gst.webrtcbin, "add-transceiver", + GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_RECVONLY, caps, &trans, NULL); + gst_object_unref(trans); + } else { + 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; +} + int _complete_sources(webrtc_s *webrtc) { int i; @@ -2713,7 +2745,7 @@ static unsigned int __get_unoccupied_id(GHashTable *slots) RET_VAL_IF(slots == NULL, 0, "slot is NULL"); - /* Payload identifiers 96–127 are used for payloads defined dynamically during a session, + /* Payload identifiers 96 ~ 127 are used for payloads defined dynamically during a session, * hence the id range is limited here to 1-32. */ for (i = 1; i < MAX_SOURCE_NUM + 1; i++) { key = g_strdup_printf("media_source_%u", i); @@ -3294,29 +3326,19 @@ int _set_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi source->av[av_idx].codec = payload_info->encoding_name; if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL) { - GstWebRTCRTPTransceiver *trans = NULL; - GstCaps *caps; int payload_type; + if (source->av[av_idx].pt >= MIN_DYNAMIC_PAYLOAD_TYPE) + __return_payload_type(webrtc, source->av[av_idx].pt); + if ((payload_type = __get_fixed_payload_type(payload_info->gst_media_type)) == -1) if ((payload_type = __get_available_payload_type(webrtc)) == 0) return WEBRTC_ERROR_NONE; - source->av[av_idx].pt = payload_type; - - caps = __make_transceiver_caps(payload_info, payload_type); - PRINT_CAPS(caps, "transceiver"); - if (!source->av[av_idx].transceiver) { - g_signal_emit_by_name(webrtc->gst.webrtcbin, "add-transceiver", - GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_RECVONLY, caps, &trans, NULL); - gst_object_unref(trans); - } else { - g_object_set(G_OBJECT(source->av[av_idx].transceiver), "codec-preferences", caps, NULL); - } - LOG_DEBUG("webrtc[%p] source_id[%u] [%s] transceiver[%p] codec[%s]", - webrtc, source_id, payload_info->media_type, source->av[av_idx].transceiver, payload_info->encoding_name); + source->av[av_idx].pt = payload_type; - gst_caps_unref(caps); + ret = __add_transceiver(source, media_type, payload_info); + RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __add_transceiver"); } /* FIXME: to utilize 'codec-preferences' of trans object, we need to re-create and re-link elements again */ -- 2.34.1