From 1abc79e1972dcad8ae6d40aaef40db584c635fc3 Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Tue, 28 Jun 2022 09:29:00 +0900 Subject: [PATCH] fixup! webrtc_source: Postpone the time of linking source with webrtcbin 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 --- include/webrtc_private.h | 2 ++ src/webrtc_source.c | 44 ++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 9ae746f3..8121393e 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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 { diff --git a/src/webrtc_source.c b/src/webrtc_source.c index ce32dbeb..60d1ff0c 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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); -- 2.34.1