webrtc_source: Use transceiver pointer instead of mline variable 90/270490/2 accepted/tizen/unified/20220208.011051 submit/tizen/20220207.073953
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 3 Feb 2022 09:15:39 +0000 (18:15 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Fri, 4 Feb 2022 00:34:47 +0000 (09:34 +0900)
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 <sc11.lee@samsung.com>
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_private.c
src/webrtc_source.c

index 575f63ce2bcc1a95a34dfaad8181cb0dae2efe78..e5ea597d11348bc2eabe5f6bf234ef82f838ccb9 100644 (file)
@@ -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;
index 8e13935aa03f224827904fb9a58ab1612a291140..a3ea7bb2b3ed65b0792395b5927c21d944899671 100644 (file)
@@ -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
index c464d43d814f446aa0667adc684c0647e5513735..9c711978334cdd7296f78144c4ea37d819d74a4e 100644 (file)
@@ -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);
index f81483f26d70697cc8220f9484209302778b486a..8cc07cd6afb6443414bbbd91f16f94ff66ed1de9 100644 (file)
@@ -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;
 }