MT#55283 iqueue for endpoint maps

Change-Id: I6776ee4958c41f3e304ed5303723ac0d65b801bf
pull/2171/head
Richard Fuchs 2 months ago
parent c5afd60d28
commit 1b2afd52f1

@ -807,8 +807,7 @@ static struct endpoint_map *__hunt_endpoint_map(struct call_media *media, unsign
return em;
}
for (__auto_type l = media->endpoint_maps.tail; l; l = l->prev) {
struct endpoint_map *em = l->data;
IQUEUE_FOREACH_REV(&media->endpoint_maps, em) {
if (em->logical_intf != media->logical_intf)
continue;
@ -870,14 +869,14 @@ static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigne
}
dbg_int("allocating new %sendpoint map", ep ? "" : "wildcard ");
em = uid_alloc(&media->call->endpoint_maps);
em = iuid_alloc(&media->call->endpoint_maps);
if (ep)
em->endpoint = *ep;
else
em->wildcard = 1;
em->logical_intf = media->logical_intf;
t_queue_init(&em->intf_sfds);
t_queue_push_tail(&media->endpoint_maps, em);
i_queue_push_tail(&media->endpoint_maps, em);
em->num_ports = num_ports;
media->endpoint_map = em;
@ -5431,7 +5430,6 @@ void media_subscription_free(struct media_subscription *p) {
void call_media_free(struct call_media *md) {
crypto_params_sdes_queue_clear(&md->sdes_in);
crypto_params_sdes_queue_clear(&md->sdes_out);
t_queue_clear(&md->endpoint_maps);
codec_store_cleanup(&md->codecs);
codec_store_cleanup(&md->offered_codecs);
t_queue_clear_full(&md->generic_attributes, sdp_attr_free);
@ -5498,8 +5496,7 @@ static void __call_free(call_t *c) {
}
while (c->endpoint_maps.head) {
em = t_queue_pop_head(&c->endpoint_maps);
em = i_queue_pop_head(&c->endpoint_maps);
t_queue_clear_full(&em->intf_sfds, free_sfd_intf_list);
}
@ -5787,11 +5784,11 @@ static bool call_merge(call_t *call, call_t *call2) {
t_queue_push_tail(&call->stream_fds, sfd);
}
last_id = call->endpoint_maps.head->data->unique_id;
last_id = call->endpoint_maps.head->unique_id;
while (call2->endpoint_maps.head) {
__auto_type endpoint_map = t_queue_pop_head(&call2->endpoint_maps);
__auto_type endpoint_map = i_queue_pop_head(&call2->endpoint_maps);
endpoint_map->unique_id = ++last_id;
t_queue_push_tail(&call->endpoint_maps, endpoint_map);
i_queue_push_tail(&call->endpoint_maps, endpoint_map);
}
// redirect hash table entry for old ID. store old ID in new call

@ -40,7 +40,7 @@ typedef union {
medias_arr *ma;
sfd_intf_list_q *siq;
streams_in_media_q *psq;
endpoint_map_q *emq;
endpoints_in_media_q *emq;
} callback_arg_t __attribute__ ((__transparent_union__));
@ -1334,6 +1334,13 @@ static int rbl_cb_ps_list(str *s, streams_in_media_q *q, struct redis_list *list
return 0;
}
static int rbl_cb_em_list(str *s, endpoints_in_media_q *q, struct redis_list *list, void *ptr) {
int j;
j = str_to_i(s, 0);
i_queue_push_tail(q, redis_list_get_idx_ptr(list, (unsigned) j));
return 0;
}
static int rbpa_cb_simple(str *s, medias_arr *pa, struct redis_list *list, void *ptr) {
int j;
j = str_to_i(s, 0);
@ -1353,6 +1360,12 @@ static int json_build_ps_list(callback_arg_t q, call_t *c, const char *key,
return json_build_list_cb(q, c, key, idx, list, rbl_cb_ps_list, NULL, arg);
}
static int json_build_em_list(callback_arg_t q, call_t *c, const char *key,
unsigned int idx, struct redis_list *list, parser_arg arg)
{
return json_build_list_cb(q, c, key, idx, list, rbl_cb_em_list, NULL, arg);
}
static int json_build_ptra(medias_arr *q, call_t *c, const char *key,
unsigned int idx, struct redis_list *list, parser_arg arg)
{
@ -1811,7 +1824,7 @@ static int redis_maps(call_t *c, struct redis_list *maps) {
rh = &maps->rh[i];
/* from call.c:__get_endpoint_map() */
em = uid_alloc(&c->endpoint_maps);
em = iuid_alloc(&c->endpoint_maps);
t_queue_init(&em->intf_sfds);
em->wildcard = redis_hash_get_bool_flag(rh, "wildcard");
@ -2045,7 +2058,7 @@ static int json_link_medias(call_t *c, struct redis_list *medias,
continue;
if (json_build_ps_list(&med->streams, c, "streams", i, streams, arg))
return -1;
if (json_build_list(&med->endpoint_maps, c, "maps", i, maps, arg))
if (json_build_em_list(&med->endpoint_maps, c, "maps", i, maps, arg))
return -1;
if (med->media_id.s)
@ -3042,10 +3055,8 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free,
if (!scope) {
snprintf(tmp, sizeof(tmp), "maps-%u", media->unique_id);
inner = parser->dict_add_list_dup(root, tmp);
for (__auto_type m = media->endpoint_maps.head; m; m = m->next) {
struct endpoint_map *ep = m->data;
IQUEUE_FOREACH(&media->endpoint_maps, ep)
JSON_ADD_LIST_STRING("%u", ep->unique_id);
}
}
snprintf(tmp, sizeof(tmp), "payload_types-%u", media->unique_id);
@ -3079,29 +3090,29 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free,
}
} // --- for medias.head
for (__auto_type l = scope ? NULL : c->endpoint_maps.head; l; l = l->next) {
struct endpoint_map *ep = l->data;
snprintf(tmp, sizeof(tmp), "map-%u", ep->unique_id);
inner = parser->dict_add_dict_dup(root, tmp);
if (!scope) {
IQUEUE_FOREACH(&c->endpoint_maps, ep) {
snprintf(tmp, sizeof(tmp), "map-%u", ep->unique_id);
inner = parser->dict_add_dict_dup(root, tmp);
{
JSON_SET_SIMPLE("wildcard","%i", ep->wildcard);
JSON_SET_SIMPLE("num_ports","%u", ep->num_ports);
JSON_SET_SIMPLE_CSTR("intf_preferred_family", ep->logical_intf->preferred_family->rfc_name);
JSON_SET_SIMPLE_STR("logical_intf", &ep->logical_intf->name);
JSON_SET_SIMPLE_CSTR("endpoint", endpoint_print_buf(&ep->endpoint));
{
JSON_SET_SIMPLE("wildcard","%i", ep->wildcard);
JSON_SET_SIMPLE("num_ports","%u", ep->num_ports);
JSON_SET_SIMPLE_CSTR("intf_preferred_family", ep->logical_intf->preferred_family->rfc_name);
JSON_SET_SIMPLE_STR("logical_intf", &ep->logical_intf->name);
JSON_SET_SIMPLE_CSTR("endpoint", endpoint_print_buf(&ep->endpoint));
}
}
snprintf(tmp, sizeof(tmp), "map_sfds-%u", ep->unique_id);
inner = parser->dict_add_list_dup(root, tmp);
for (__auto_type m = ep->intf_sfds.head; m; m = m->next) {
struct sfd_intf_list *il = m->data;
JSON_ADD_LIST_STRING("loc-%u", il->local_intf->unique_id);
for (__auto_type n = il->list.head; n; n = n->next) {
stream_fd *sfd = n->data;
JSON_ADD_LIST_STRING("%u", sfd->unique_id);
snprintf(tmp, sizeof(tmp), "map_sfds-%u", ep->unique_id);
inner = parser->dict_add_list_dup(root, tmp);
for (__auto_type m = ep->intf_sfds.head; m; m = m->next) {
struct sfd_intf_list *il = m->data;
JSON_ADD_LIST_STRING("loc-%u", il->local_intf->unique_id);
for (__auto_type n = il->list.head; n; n = n->next) {
stream_fd *sfd = n->data;
JSON_ADD_LIST_STRING("%u", sfd->unique_id);
}
}
}
} // --- for c->endpoint_maps.head
@ -3144,8 +3155,7 @@ static stream_fd *snapshot_find_sfd(call_t *c, unsigned int id) {
}
static struct endpoint_map *snapshot_find_map(call_t *c, unsigned int id) {
for (__auto_type l = c->endpoint_maps.head; l; l = l->next) {
struct endpoint_map *map = l->data;
IQUEUE_FOREACH(&c->endpoint_maps, map) {
if (map->unique_id == id)
return map;
}

@ -356,7 +356,6 @@ struct codec_store {
strip_full:1; // set by codec_store_strip
};
TYPED_GQUEUE(endpoint_map, struct endpoint_map)
struct stream_params {
unsigned int index; /* starting with 1 */
@ -391,6 +390,8 @@ struct stream_params {
};
struct endpoint_map {
IQUEUE_LINK media_link;
IQUEUE_LINK call_link;
unsigned int unique_id;
struct endpoint endpoint;
unsigned int num_ports; // per interface
@ -399,6 +400,10 @@ struct endpoint_map {
unsigned int wildcard:1;
};
typedef IQUEUE(struct endpoint_map, media_link) endpoints_in_media_q;
typedef IQUEUE(struct endpoint_map, call_link) endpoints_in_call_q;
struct loop_protector {
unsigned int len;
unsigned char buf[RTP_LOOP_PROTECT];
@ -552,7 +557,7 @@ struct call_media {
streams_in_media_q streams; /* normally RTP + RTCP */
struct endpoint_map *endpoint_map;
endpoint_map_q endpoint_maps;
endpoints_in_media_q endpoint_maps;
struct ssrc_hash ssrc_hash_in;
struct ssrc_hash ssrc_hash_out;
@ -806,7 +811,7 @@ struct call {
fragments_ht sdp_fragments;
streams_in_call_q streams;
stream_fd_q stream_fds; /* stream_fd */
endpoint_map_q endpoint_maps;
endpoints_in_call_q endpoint_maps;
struct dtls_cert *dtls_cert; /* for outgoing */
struct mqtt_timer *mqtt_timer;

@ -138,6 +138,11 @@
var; var = ((__typeof((list)->offset)) var)->link.next)
#define IQUEUE_FOREACH_REV(list, var) \
for (__typeof ( ({ __typeof (*(list)->tail) __t; &__t; }) ) var = (list)->tail; \
var; var = ((__typeof((list)->offset)) var)->link.prev)
#define IQUEUE_FOREACH_SAFE(list, var) \
for (__typeof ( ({ __typeof (*(list)->head) __t; &__t; }) ) var = (list)->head, \
__next ## var = var ? ((__typeof((list)->offset)) var)->link.next : NULL; \

Loading…
Cancel
Save