webrtc_source: Fix source id allocation 39/276939/4 submit/tizen/20220726.122258
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 28 Jun 2022 03:20:39 +0000 (12:20 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 26 Jul 2022 06:44:16 +0000 (15:44 +0900)
It is changed to allocate source id with a way of increasing number.
Removing and adding a source could occur an issue inside of gstwebrtcbin
when creating description. Media attributes order in the description did
not match the order of source ids. It is now fixed.

[Version] 0.3.174
[Issue Type] Improvement

Change-Id: I2c062ed3261f95da8a69a94dfed00f3a86cb9583
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
src/webrtc_source.c

index 16ababe30d13ab2786346b29a5a1deffdb9e2fed..07777d4f29ab12aea08c70ff41b7415345c30df2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.173
+Version:    0.3.174
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index a7671be9efeb8bc33919448618b2f760f610c1c9..0b3915b25d68cae6b2b226897e53072343d812b1 100644 (file)
@@ -1069,30 +1069,6 @@ static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        return WEBRTC_ERROR_NONE;
 }
 
-static unsigned int __get_unoccupied_id(GHashTable *slots)
-{
-       int i;
-       gchar *key;
-
-       RET_VAL_IF(slots == NULL, 0, "slot is NULL");
-
-       /* 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);
-               if (g_hash_table_contains(slots, key)) {
-                       g_free(key);
-                       continue;
-               }
-               g_free(key);
-               return i;
-       }
-
-       LOG_ERROR("all slots are occupied(1-32)");
-
-       return 0;
-}
-
 static gboolean __foreach_src_pad_cb(GstElement *element, GstPad *pad, gpointer user_data)
 {
        webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)user_data;
@@ -1178,17 +1154,15 @@ void _source_slot_destroy_cb(gpointer data)
 
 static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **source, gchar **name)
 {
-       unsigned int id;
+       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);
 
        /* name/source will be freed by function which is set to g_hash_table_new_full() */
-       id = __get_unoccupied_id(webrtc->gst.source_slots);
-       RET_VAL_IF(id == 0, WEBRTC_ERROR_INVALID_OPERATION, "source_slots are full");
-
        *name = g_strdup_printf("media_source_%u", id);
 
        *source = g_new0(webrtc_gst_slot_s, 1);
@@ -1200,7 +1174,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, id++, type, *name);
 
        return WEBRTC_ERROR_NONE;
 }