fixup! webrtc_source: Postpone the time of linking source with webrtcbin 07/276907/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 28 Jun 2022 00:29:00 +0000 (09:29 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 28 Jun 2022 00:30:33 +0000 (09:30 +0900)
g_hash_table_foreach() invokes a callback not in order of source id.
It affects media attribute order in offer description.

It is fixed to keep the same order before the patch above is applied.

Change-Id: Ie7c2ae7a0d1fac5f582e53c48a87f29f4254b403
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_private.h
src/webrtc_source.c

index 9ae746f3268d34306fa3ac6478e64b7cc7adad25..8121393efdcda3e26c3df502be8bf073a0ba129a 100644 (file)
@@ -242,6 +242,7 @@ do { \
 #define PAYLOAD_TYPE_BITS               32 /* 96 ~ 127 */
 #define TRACK_ID_THRESHOLD_OF_LOOPBACK  100
 #define MAX_MLINE_NUM                   16
+#define MAX_SOURCE_NUM                  32
 
 /* See webrtc_transceiver_codec_e */
 #define CODEC_TYPE_AUDIO                0x00000100
@@ -405,6 +406,7 @@ typedef struct _webrtc_gst_s {
        guint bus_watcher;
        GHashTable *source_slots;
        GHashTable *sink_slots;
+       void *sources[MAX_SOURCE_NUM];
 } webrtc_gst_s;
 
 typedef struct _webrtc_data_recovery_type_s {
index ce32dbebe54c782def4ea67e8b68173c674b0b7c..60d1ff0c51573606f73c5764cb01e318592d9261 100644 (file)
@@ -1735,29 +1735,27 @@ exit:
        return WEBRTC_ERROR_INVALID_OPERATION;
 }
 
-static void __complete_source_foreach_cb(gpointer key, gpointer value, gpointer user_data)
-{
-       webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)value;
-       webrtc_s *webrtc = (webrtc_s *)user_data;
-
-       if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE ||
-               source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET ||
-               source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL)
-               return;
-
-       LOG_DEBUG("source[%s, id:%u, type:%d]", (gchar *)key, source->id, source->type);
-
-       if (source->media_types == MEDIA_TYPE_AUDIO)
-               __complete_rest_of_audiosrc(webrtc, source);
-       else
-               __complete_rest_of_videosrc(webrtc, source);
-}
-
 int _complete_sources(webrtc_s *webrtc)
 {
+       int i;
+       webrtc_gst_slot_s *source;
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
 
-       g_hash_table_foreach(webrtc->gst.source_slots, __complete_source_foreach_cb, webrtc);
+       for (i = 0; i < MAX_SOURCE_NUM; i++) {
+               if (!(source = webrtc->gst.sources[i]))
+                       continue;
+               if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_FILE ||
+                       source->type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET ||
+                       source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL)
+                       continue;
+
+               LOG_DEBUG("source[id:%u, type:%d, media_types:0x%x]", source->id, source->type, source->media_types);
+
+               if (source->media_types == MEDIA_TYPE_AUDIO)
+                       __complete_rest_of_audiosrc(webrtc, source);
+               else
+                       __complete_rest_of_videosrc(webrtc, source);
+       }
 
        return WEBRTC_ERROR_NONE;
 }
@@ -2717,7 +2715,7 @@ static unsigned int __get_unoccupied_id(GHashTable *slots)
 
        /* 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 < 33; i++) {
+       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);
@@ -2763,6 +2761,11 @@ void _source_slot_destroy_cb(gpointer data)
                source->bin ? GST_ELEMENT_NAME(source->bin) : "null", source->id, source->media_types,
                source->av[AV_IDX_AUDIO].transceiver, source->av[AV_IDX_VIDEO].transceiver);
 
+       for (i = 0; i < MAX_SOURCE_NUM; i++) {
+               if (source->webrtc->gst.sources[i] == source)
+                       source->webrtc->gst.sources[i] = NULL;
+       }
+
        if (source->bin)
                gst_element_foreach_src_pad(GST_ELEMENT(source->bin), __foreach_src_pad_cb, source);
 
@@ -2942,6 +2945,7 @@ static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_i
        }
 
        *source_id = source->id;
+       webrtc->gst.sources[*source_id - 1] = source;
 
        LOG_INFO("webrtc[%p] source[%p, name:%s, id:%u]", webrtc, source, bin_name, *source_id);