fixup! webrtc_source: Fix source id allocation 56/278856/1 submit/tizen/20220727.071902
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 27 Jul 2022 03:46:47 +0000 (12:46 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 27 Jul 2022 03:51:26 +0000 (12:51 +0900)
It is fixed due to the some UTCs fail.

Change-Id: I7ff6034dfb6e66aacadccf6b11b2dad07ae6ad47

include/webrtc_private.h
src/webrtc_source.c

index 7e9886816c60116ab22b2d04b3a1c50cf9e7a7e2..ba02efc3489e1b258dbe8d61c81d3efc7e98e780 100644 (file)
@@ -465,6 +465,7 @@ typedef struct _webrtc_s {
 
        webrtc_gst_s gst;
        unsigned int payload_types;
+       unsigned int cur_max_source_id;
 
        webrtc_bundle_policy_e bundle_policy;
 
index 77dede39859fb74b5cc93d216dfae9fff542c3e7..851bb5706988f40b5b5446fde2c7c05c2c43f79e 100644 (file)
@@ -837,19 +837,18 @@ void _source_slot_destroy_cb(gpointer data)
 
 static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **source, gchar **name)
 {
-       static unsigned int id = 1;
-
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
        RET_VAL_IF(name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "name is NULL");
        RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL");
-       RET_VAL_IF(id >= MAX_SOURCE_NUM + 1, WEBRTC_ERROR_INVALID_OPERATION, "id exceeds %d", MAX_SOURCE_NUM);
+       RET_VAL_IF(g_hash_table_size(webrtc->gst.source_slots) >= MAX_SOURCE_NUM, WEBRTC_ERROR_INVALID_OPERATION,
+               "number of sources reached %d", MAX_SOURCE_NUM);
 
        /* name/source will be freed by function which is set to g_hash_table_new_full() */
-       *name = g_strdup_printf("media_source_%u", id);
+       *name = g_strdup_printf("media_source_%u", ++webrtc->cur_max_source_id);
 
        *source = g_new0(webrtc_gst_slot_s, 1);
-       (*source)->id = id;
+       (*source)->id = webrtc->cur_max_source_id;
        if (type != WEBRTC_MEDIA_SOURCE_TYPE_NULL)
                (*source)->bin = GST_BIN(gst_bin_new(*name));
        (*source)->type = type;
@@ -857,7 +856,7 @@ static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **s
        (*source)->av[AV_IDX_AUDIO].direction = (type == WEBRTC_MEDIA_SOURCE_TYPE_NULL) ? WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY : WEBRTC_TRANSCEIVER_DIRECTION_SENDRECV;
        (*source)->av[AV_IDX_VIDEO].direction = (type == WEBRTC_MEDIA_SOURCE_TYPE_NULL) ? WEBRTC_TRANSCEIVER_DIRECTION_RECVONLY : WEBRTC_TRANSCEIVER_DIRECTION_SENDRECV;
 
-       LOG_DEBUG("webrtc[%p] source[%p, id:%u, type:%d, name:%s]", webrtc, *source, id++, type, *name);
+       LOG_DEBUG("webrtc[%p] source[%p, id:%u, type:%d, name:%s]", webrtc, *source, webrtc->cur_max_source_id, type, *name);
 
        return WEBRTC_ERROR_NONE;
 }