From: Sangchul Lee Date: Thu, 3 Feb 2022 09:15:39 +0000 (+0900) Subject: webrtc_source: Use transceiver pointer instead of mline variable X-Git-Tag: submit/tizen/20220207.073953^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d2070bfc479eb207bb31fa644ed065e2889e1c0;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Use transceiver pointer instead of mline variable Since gst 1.19.x version, at this point in 'on-new-transceiver' signal callback of webrtcbin, the transceiver mline index could be set to -1. Therefore, it is changed to refer the transceiver object itself. [Version] 0.3.52 [Issue Type] Refactoring Change-Id: I3b1b1eab5309362374df40dd96d89b1fff32257a Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 575f63ce..e5ea597d 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -198,8 +198,6 @@ do { \ x_slot = g_new0(webrtc_gst_slot_s, 1); \ x_slot->id = x_id; \ x_slot->bin = GST_BIN(gst_bin_new(x_bin_name)); \ - x_slot->av[AV_IDX_AUDIO].mline = -1; \ - x_slot->av[AV_IDX_VIDEO].mline = -1; \ x_slot->webrtc = x_webrtc; \ } while (0) @@ -493,7 +491,7 @@ typedef struct _webrtc_gst_slot_s { int type; int media_types; /* values of media_type_e combined with bitwise 'or' */ struct { - int mline; + GstWebRTCRTPTransceiver *transceiver; GstPad *src_pad; gulong src_pad_probe_id; bool pause; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 8e13935a..a3ea7bb2 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.51 +Version: 0.3.52 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_private.c b/src/webrtc_private.c index c464d43d..9c711978 100644 --- a/src/webrtc_private.c +++ b/src/webrtc_private.c @@ -1420,12 +1420,13 @@ static void __webrtcbin_on_new_transceiver_cb(GstElement *webrtcbin, GstWebRTCRT for (i = AV_IDX_AUDIO; i < AV_IDX_MAX; i++) { if (!(source->media_types & (i == AV_IDX_AUDIO ? MEDIA_TYPE_AUDIO : MEDIA_TYPE_VIDEO))) continue; - if (source->av[i].mline == -1) { - source->av[i].mline = transceiver->mline; - LOG_DEBUG("source[%s, id:%u, mline:%d for %s]", - (gchar *)key, source->id, source->av[i].mline, i == AV_IDX_AUDIO ? "AUDIO" : "VIDEO"); - return; - } + if (source->av[i].transceiver) + continue; + + source->av[i].transceiver = gst_object_ref(transceiver); + LOG_DEBUG("source[%s, id:%u, transceiver:%p for %s]", + (gchar *)key, source->id, source->av[i].transceiver, i == AV_IDX_AUDIO ? "AUDIO" : "VIDEO"); + return; } } } @@ -1447,15 +1448,9 @@ void _update_transceivers_fec(webrtc_s *webrtc, bool is_offer) for (i = AV_IDX_AUDIO; i < AV_IDX_MAX; i++) { if (!(source->media_types & (i == AV_IDX_AUDIO ? MEDIA_TYPE_AUDIO : MEDIA_TYPE_VIDEO))) continue; - if (source->av[i].mline == -1) + if (!(transceiver = source->av[i].transceiver)) continue; - g_signal_emit_by_name(G_OBJECT(webrtc->gst.webrtcbin), "get-transceiver", source->av[i].mline, &transceiver); - if (!transceiver) { - LOG_ERROR("transceiver of mline[%u] is NULL", source->av[i].mline); - continue; - } - ini_source = _ini_get_source_by_type(&webrtc->ini, source->type); if (ini_source == NULL) ini_source = &(webrtc->ini.media_source); diff --git a/src/webrtc_source.c b/src/webrtc_source.c index f81483f2..8cc07cd6 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -2656,8 +2656,9 @@ void _source_slot_destroy_cb(gpointer data) RET_IF(source == NULL, "source is NULL"); - LOG_DEBUG("[%s, id:%u, media_types:0x%x, [AUDIO]mline:%d, [VIDEO]mline:%d] is removed", - GST_ELEMENT_NAME(source->bin), source->id, source->media_types, source->av[AV_IDX_AUDIO].mline, source->av[AV_IDX_VIDEO].mline); + LOG_DEBUG("[%s, id:%u, media_types:0x%x, [AUDIO]transceiver:%p, [VIDEO]transceiver:%p] is removed", + GST_ELEMENT_NAME(source->bin), source->id, source->media_types, + source->av[AV_IDX_AUDIO].transceiver, source->av[AV_IDX_VIDEO].transceiver); gst_element_foreach_src_pad(GST_ELEMENT(source->bin), __foreach_src_pad_cb, source); @@ -2672,6 +2673,9 @@ void _source_slot_destroy_cb(gpointer data) gst_element_set_state(source->av[i].render.pipeline, GST_STATE_NULL); SAFE_GST_OBJECT_UNREF(source->av[i].render.pipeline); } + + if (source->av[i].transceiver) + gst_object_unref(source->av[i].transceiver); } gst_bin_remove(GST_BIN(gst_element_get_parent(source->bin)), GST_ELEMENT(source->bin)); @@ -2902,12 +2906,8 @@ static int __convert_direction(GstWebRTCRTPTransceiverDirection gst_direction, w int _set_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e direction) { - int ret = WEBRTC_ERROR_INVALID_OPERATION; webrtc_gst_slot_s *source; GstWebRTCRTPTransceiver *trans; - GArray *transceivers; - int mline; - guint i; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(direction > WEBRTC_TRANSCEIVER_DIRECTION_SENDRECV, WEBRTC_ERROR_INVALID_PARAMETER, "invalid direction"); @@ -2916,44 +2916,29 @@ int _set_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_ RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); if (media_type == WEBRTC_MEDIA_TYPE_AUDIO && source->media_types & MEDIA_TYPE_AUDIO) { - mline = source->av[AV_IDX_AUDIO].mline; + trans = source->av[AV_IDX_AUDIO].transceiver; } else if (media_type == WEBRTC_MEDIA_TYPE_VIDEO && source->media_types & MEDIA_TYPE_VIDEO) { - mline = source->av[AV_IDX_VIDEO].mline; + trans = source->av[AV_IDX_VIDEO].transceiver; } else { LOG_ERROR("invalid media_type[%d] for source[media_types:0x%x, id:%u]", media_type, source->media_types, source_id); return WEBRTC_ERROR_INVALID_PARAMETER; } - g_signal_emit_by_name(webrtc->gst.webrtcbin, "get-transceivers", &transceivers); - for (i = 0; i < transceivers->len; i++) { - trans = g_array_index(transceivers, GstWebRTCRTPTransceiver *, i); - if ((int)trans->mline == mline) { - trans->direction = __direction_info[direction].gst; - LOG_DEBUG("Set direction to transceiver[%p, index:%d, mline:%u, direction:%s]", - trans, i, trans->mline, __direction_info[direction].str); - ret = WEBRTC_ERROR_NONE; - goto end; - } - } - - LOG_ERROR("could not find a transceiver with mline[%d]", mline); + RET_VAL_IF(trans == NULL, WEBRTC_ERROR_INVALID_OPERATION, "transceiver of source[media_type:%d, id:%u] is NULL", media_type, source_id); -end: - g_array_unref(transceivers); + trans->direction = __direction_info[direction].gst; + LOG_DEBUG("Set direction to transceiver[%p, mline:%u, direction:%s]", trans, trans->mline, __direction_info[direction].str); - return ret; + return WEBRTC_ERROR_NONE; } int _get_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e *direction) { - int ret = WEBRTC_ERROR_INVALID_OPERATION; + int ret; webrtc_gst_slot_s *source; GstWebRTCRTPTransceiver *trans; - GArray *transceivers; - int mline; - guint i; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(direction == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "direction is NULL"); @@ -2962,32 +2947,21 @@ int _get_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_ RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); if (media_type == WEBRTC_MEDIA_TYPE_AUDIO && source->media_types & MEDIA_TYPE_AUDIO) { - mline = source->av[AV_IDX_AUDIO].mline; + trans = source->av[AV_IDX_AUDIO].transceiver; } else if (media_type == WEBRTC_MEDIA_TYPE_VIDEO && source->media_types & MEDIA_TYPE_VIDEO) { - mline = source->av[AV_IDX_VIDEO].mline; + trans = source->av[AV_IDX_VIDEO].transceiver; } else { LOG_ERROR("invalid media_type[%d] for source[media_types:0x%x, id:%u]", media_type, source->media_types, source_id); return WEBRTC_ERROR_INVALID_PARAMETER; } - g_signal_emit_by_name(webrtc->gst.webrtcbin, "get-transceivers", &transceivers); - for (i = 0; i < transceivers->len; i++) { - trans = g_array_index(transceivers, GstWebRTCRTPTransceiver *, i); - if ((int)trans->mline == mline) { - ret = __convert_direction(trans->direction, direction); - if (ret == WEBRTC_ERROR_NONE) - LOG_DEBUG("found transceiver[%p, index:%d, mline:%u, mid:%s, direction:%s]", - trans, i, trans->mline, trans->mid, __direction_info[*direction].str); - goto end; - } - } + RET_VAL_IF(trans == NULL, WEBRTC_ERROR_INVALID_OPERATION, "transceiver of source[media_type:%d, id:%u] is NULL", media_type, source_id); - LOG_ERROR("could not find a transceiver with mline[%d]", mline); - -end: - g_array_unref(transceivers); + ret = __convert_direction(trans->direction, direction); + if (ret == WEBRTC_ERROR_NONE) + LOG_DEBUG("transceiver[%p, mline:%u, mid:%s, direction:%s]", trans, trans->mline, trans->mid, __direction_info[*direction].str); return ret; }