diff --git a/daemon/call.c b/daemon/call.c index 285f9ca8c..bdac5215e 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2997,8 +2997,8 @@ static void __unsubscribe_from_all(struct call_monologue *ml) { l = next; } } -void __add_subscription(struct call_monologue *which, struct call_monologue *to, bool offer_answer, - unsigned int offset, bool rtcp_only, bool egress, const struct sink_attrs *attrs) +void __add_subscription(struct call_monologue *which, struct call_monologue *to, + unsigned int offset, const struct sink_attrs *attrs) { if (g_hash_table_lookup(which->subscriptions_ht, to)) { ilog(LOG_DEBUG, "Tag '" STR_FORMAT_M "' is already subscribed to '" STR_FORMAT_M "'", @@ -3020,11 +3020,8 @@ void __add_subscription(struct call_monologue *which, struct call_monologue *to, which_cs->attrs = *attrs; to_rev_cs->attrs = *attrs; } - // override some attributes explicitly - which_cs->attrs.rtcp_only = rtcp_only ? 1 : 0; - to_rev_cs->attrs.rtcp_only = rtcp_only ? 1 : 0; // keep offer-answer subscriptions first in the list - if (!offer_answer) { + if (!attrs || !attrs->offer_answer) { g_queue_push_tail(&which->subscriptions, which_cs); g_queue_push_tail(&to->subscribers, to_rev_cs); which_cs->link = to->subscribers.tail; @@ -3036,10 +3033,6 @@ void __add_subscription(struct call_monologue *which, struct call_monologue *to, which_cs->link = to->subscribers.head; to_rev_cs->link = which->subscriptions.head; } - which_cs->attrs.offer_answer = offer_answer ? 1 : 0; - to_rev_cs->attrs.offer_answer = which_cs->attrs.offer_answer; - which_cs->attrs.egress = egress ? 1 : 0; - to_rev_cs->attrs.egress = which_cs->attrs.egress; g_hash_table_insert(which->subscriptions_ht, to, to_rev_cs->link); g_hash_table_insert(to->subscribers_ht, which, which_cs->link); } @@ -3048,22 +3041,22 @@ static void __subscribe_offer_answer_both_ways(struct call_monologue *a, struct struct call_subscription *a_cs = call_get_call_subscription(a->subscriptions_ht, b); struct call_subscription *b_cs = call_get_call_subscription(b->subscriptions_ht, a); // copy out attributes - struct sink_attrs a_attrs = {0,}, *a_attrs_p = NULL; - struct sink_attrs b_attrs = {0,}, *b_attrs_p = NULL; - if (a_cs) { + struct sink_attrs a_attrs = {0,}; + struct sink_attrs b_attrs = {0,}; + if (a_cs) a_attrs = a_cs->attrs; - a_attrs_p = &a_attrs; - } - if (b_cs) { + if (b_cs) b_attrs = b_cs->attrs; - b_attrs_p = &b_attrs; - } + // override/reset some attributes + a_attrs.offer_answer = b_attrs.offer_answer = true; + a_attrs.egress = b_attrs.egress = false; + a_attrs.rtcp_only = b_attrs.rtcp_only = false; // delete existing subscriptions __unsubscribe_all_offer_answer_subscribers(a); __unsubscribe_all_offer_answer_subscribers(b); // (re)create, preserving existing attributes if there were any - __add_subscription(a, b, true, 0, false, false, a_attrs_p); - __add_subscription(b, a, true, 0, false, false, b_attrs_p); + __add_subscription(a, b, 0, &a_attrs); + __add_subscription(b, a, 0, &b_attrs); } @@ -3200,9 +3193,10 @@ static int monologue_subscribe_request1(struct call_monologue *src_ml, struct ca return -1; } - __add_subscription(dst_ml, src_ml, false, idx_diff, false, flags->egress ? true : false, NULL); + __add_subscription(dst_ml, src_ml, idx_diff, &(struct sink_attrs) { .egress = !!flags->egress }); if (flags->rtcp_mirror) - __add_subscription(src_ml, dst_ml, false, rev_idx_diff, true, flags->egress ? true : false, NULL); + __add_subscription(src_ml, dst_ml, rev_idx_diff, + &(struct sink_attrs) { .egress = !!flags->egress, .rtcp_only = true }); __update_init_subscribers(src_ml, NULL, NULL, flags->opmode); __update_init_subscribers(dst_ml, NULL, NULL, flags->opmode); diff --git a/daemon/redis.c b/daemon/redis.c index 22e37048c..e8d109cae 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1658,7 +1658,11 @@ static int rbl_subs_cb(str *s, GQueue *q, struct redis_list *list, void *ptr) { if (!other_ml) return -1; - __add_subscription(ml, other_ml, offer_answer, media_offset, rtcp_only, egress, NULL); + __add_subscription(ml, other_ml, media_offset, &(struct sink_attrs) { + .offer_answer = offer_answer, + .rtcp_only = rtcp_only, + .egress = egress, + }); return 0; } @@ -1683,7 +1687,8 @@ static int json_link_tags(struct call *c, struct redis_list *tags, struct redis_ other_ml = l->data; if (!other_ml) return -1; - __add_subscription(ml, other_ml, true, 0, false, false, NULL); + __add_subscription(ml, other_ml, 0, + &(struct sink_attrs) { .offer_answer = true }); } g_queue_clear(&q); @@ -1693,7 +1698,7 @@ static int json_link_tags(struct call *c, struct redis_list *tags, struct redis_ other_ml = l->data; if (!other_ml) return -1; - __add_subscription(ml, other_ml, false, 0, false, false, NULL); + __add_subscription(ml, other_ml, 0, NULL); } g_queue_clear(&q); } @@ -1702,7 +1707,8 @@ static int json_link_tags(struct call *c, struct redis_list *tags, struct redis_ if (!ml->subscriptions.length) { other_ml = redis_list_get_ptr(tags, &tags->rh[i], "active"); if (other_ml) - __add_subscription(ml, other_ml, true, 0, false, false, NULL); + __add_subscription(ml, other_ml, 0, + &(struct sink_attrs) { .offer_answer = true }); } if (json_build_list(&q, c, "other_tags", i, tags, root_reader)) diff --git a/include/call.h b/include/call.h index 19027b87b..92dcbfab4 100644 --- a/include/call.h +++ b/include/call.h @@ -646,8 +646,8 @@ struct call_monologue *__monologue_create(struct call *call); void __monologue_tag(struct call_monologue *ml, const str *tag); void __monologue_viabranch(struct call_monologue *ml, const str *viabranch); struct packet_stream *__packet_stream_new(struct call *call); -void __add_subscription(struct call_monologue *ml, struct call_monologue *other, bool offer_answer, - unsigned int media_offset, bool rtcp_only, bool egress, const struct sink_attrs *); +void __add_subscription(struct call_monologue *ml, struct call_monologue *other, + unsigned int media_offset, const struct sink_attrs *); struct call_subscription *call_get_call_subscription(GHashTable *ht, struct call_monologue *ml); void free_sink_handler(void *); void __add_sink_handler(GQueue *, struct packet_stream *, const struct sink_attrs *);