TT#189201 refactor sink/handler attributes

Create a dedicated struct to hold certain attributes shared by both sink
handlers and media subscriptions, as a preparation to simplify handling
these attributs.

Change-Id: I866159c33ed6d6a2873d2cf68c4906ea705d253e
pull/1546/head
Richard Fuchs 3 years ago
parent ba56e37bc0
commit 7be1d0aef1

@ -1368,8 +1368,8 @@ void __add_sink_handler(GQueue *q, struct packet_stream *sink, bool rtcp_only, b
struct sink_handler *sh = g_slice_alloc0(sizeof(*sh)); struct sink_handler *sh = g_slice_alloc0(sizeof(*sh));
sh->sink = sink; sh->sink = sink;
sh->kernel_output_idx = -1; sh->kernel_output_idx = -1;
sh->rtcp_only = rtcp_only ? 1 : 0; sh->attrs.rtcp_only = rtcp_only ? 1 : 0;
sh->transcoding = transcoding ? 1 : 0; sh->attrs.transcoding = transcoding ? 1 : 0;
g_queue_push_tail(q, sh); g_queue_push_tail(q, sh);
} }
@ -2410,7 +2410,7 @@ static void set_transcoding_flag(struct call_monologue *ml, struct call_monologu
struct call_subscription *cs = find_subscription(ml, sub); struct call_subscription *cs = find_subscription(ml, sub);
if (!cs) if (!cs)
return; return;
cs->transcoding = flag ? 1 : 0; cs->attrs.transcoding = flag ? 1 : 0;
} }
void codecs_offer_answer(struct call_media *media, struct call_media *other_media, void codecs_offer_answer(struct call_media *media, struct call_media *other_media,
@ -2549,9 +2549,9 @@ static void __update_init_subscribers(struct call_monologue *ml, GQueue *streams
// skip into correct media section for multi-ml subscriptions // skip into correct media section for multi-ml subscriptions
for (unsigned int offset = cs->media_offset; offset && sub_medias[num_subs]; offset--) for (unsigned int offset = cs->media_offset; offset && sub_medias[num_subs]; offset--)
sub_medias[num_subs] = sub_medias[num_subs]->next; sub_medias[num_subs] = sub_medias[num_subs]->next;
subs_rtcp_only[num_subs] = cs->rtcp_only ? true : false; subs_rtcp_only[num_subs] = cs->attrs.rtcp_only ? true : false;
subs_tc[num_subs] = cs->transcoding ? true : false; subs_tc[num_subs] = cs->attrs.transcoding ? true : false;
subs_egress[num_subs] = cs->egress ? true : false; subs_egress[num_subs] = cs->attrs.egress ? true : false;
num_subs++; num_subs++;
} }
// keep num_subs as shortcut to ml->subscribers.length // keep num_subs as shortcut to ml->subscribers.length
@ -2987,7 +2987,7 @@ static bool __unsubscribe_one(struct call_monologue *which, struct call_monologu
static void __unsubscribe_all_offer_answer_subscribers(struct call_monologue *ml) { static void __unsubscribe_all_offer_answer_subscribers(struct call_monologue *ml) {
for (GList *l = ml->subscribers.head; l; ) { for (GList *l = ml->subscribers.head; l; ) {
struct call_subscription *cs = l->data; struct call_subscription *cs = l->data;
if (!cs->offer_answer) { if (!cs->attrs.offer_answer) {
l = l->next; l = l->next;
continue; continue;
} }
@ -3021,8 +3021,8 @@ void __add_subscription(struct call_monologue *which, struct call_monologue *to,
to_rev_cs->monologue = which; to_rev_cs->monologue = which;
which_cs->media_offset = offset; which_cs->media_offset = offset;
to_rev_cs->media_offset = offset; to_rev_cs->media_offset = offset;
which_cs->rtcp_only = rtcp_only ? 1 : 0; which_cs->attrs.rtcp_only = rtcp_only ? 1 : 0;
to_rev_cs->rtcp_only = rtcp_only ? 1 : 0; to_rev_cs->attrs.rtcp_only = rtcp_only ? 1 : 0;
// keep offer-answer subscriptions first in the list // keep offer-answer subscriptions first in the list
if (!offer_answer) { if (!offer_answer) {
g_queue_push_tail(&which->subscriptions, which_cs); g_queue_push_tail(&which->subscriptions, which_cs);
@ -3036,10 +3036,10 @@ void __add_subscription(struct call_monologue *which, struct call_monologue *to,
which_cs->link = to->subscribers.head; which_cs->link = to->subscribers.head;
to_rev_cs->link = which->subscriptions.head; to_rev_cs->link = which->subscriptions.head;
} }
which_cs->offer_answer = offer_answer ? 1 : 0; which_cs->attrs.offer_answer = offer_answer ? 1 : 0;
to_rev_cs->offer_answer = which_cs->offer_answer; to_rev_cs->attrs.offer_answer = which_cs->attrs.offer_answer;
which_cs->egress = egress ? 1 : 0; which_cs->attrs.egress = egress ? 1 : 0;
to_rev_cs->egress = which_cs->egress; 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(which->subscriptions_ht, to, to_rev_cs->link);
g_hash_table_insert(to->subscribers_ht, which, which_cs->link); g_hash_table_insert(to->subscribers_ht, which, which_cs->link);
} }
@ -4112,7 +4112,7 @@ static int call_get_monologue_new(struct call_monologue *dialogue[2], struct cal
if (totag && totag->s) { if (totag && totag->s) {
for (GList *sub = ret->subscribers.head; sub; sub = sub->next) { for (GList *sub = ret->subscribers.head; sub; sub = sub->next) {
struct call_subscription *cs = sub->data; struct call_subscription *cs = sub->data;
if (!cs->offer_answer) if (!cs->attrs.offer_answer)
continue; continue;
struct call_monologue *csm = cs->monologue; struct call_monologue *csm = cs->monologue;
if (str_cmp_str(&csm->tag, totag)) { if (str_cmp_str(&csm->tag, totag)) {
@ -4166,7 +4166,7 @@ new_branch:
ok_check_tag: ok_check_tag:
for (GList *sub = ret->subscriptions.head; sub; sub = sub->next) { for (GList *sub = ret->subscriptions.head; sub; sub = sub->next) {
struct call_subscription *cs = sub->data; struct call_subscription *cs = sub->data;
if (!cs->offer_answer) if (!cs->attrs.offer_answer)
continue; continue;
struct call_monologue *csm = cs->monologue; struct call_monologue *csm = cs->monologue;
if (!os) if (!os)

@ -2044,14 +2044,14 @@ static void ng_stats_monologue(bencode_item_t *dict, const struct call_monologue
struct call_subscription *cs = l->data; struct call_subscription *cs = l->data;
bencode_item_t *sub1 = bencode_list_add_dictionary(subs); bencode_item_t *sub1 = bencode_list_add_dictionary(subs);
bencode_dictionary_add_str(sub1, "tag", &cs->monologue->tag); bencode_dictionary_add_str(sub1, "tag", &cs->monologue->tag);
bencode_dictionary_add_string(sub1, "type", cs->offer_answer ? "offer/answer" : "pub/sub"); bencode_dictionary_add_string(sub1, "type", cs->attrs.offer_answer ? "offer/answer" : "pub/sub");
} }
subs = bencode_dictionary_add_list(sub, "subscribers"); subs = bencode_dictionary_add_list(sub, "subscribers");
for (GList *l = ml->subscribers.head; l; l = l->next) { for (GList *l = ml->subscribers.head; l; l = l->next) {
struct call_subscription *cs = l->data; struct call_subscription *cs = l->data;
bencode_item_t *sub1 = bencode_list_add_dictionary(subs); bencode_item_t *sub1 = bencode_list_add_dictionary(subs);
bencode_dictionary_add_str(sub1, "tag", &cs->monologue->tag); bencode_dictionary_add_str(sub1, "tag", &cs->monologue->tag);
bencode_dictionary_add_string(sub1, "type", cs->offer_answer ? "offer/answer" : "pub/sub"); bencode_dictionary_add_string(sub1, "type", cs->attrs.offer_answer ? "offer/answer" : "pub/sub");
} }
ng_stats_ssrc(ssrc, ml->ssrc_hash); ng_stats_ssrc(ssrc, ml->ssrc_hash);

@ -1453,7 +1453,7 @@ struct codec_handler *codec_handler_get(struct call_media *m, int payload_type,
out: out:
if (ret) if (ret)
return ret; return ret;
if (sh && sh->transcoding) if (sh && sh->attrs.transcoding)
return &codec_handler_stub_ssrc; return &codec_handler_stub_ssrc;
#endif #endif
return &codec_handler_stub; return &codec_handler_stub;

@ -494,7 +494,7 @@ static const char *dtmf_inject_pcm(struct call_media *media, struct call_media *
if (!seq) if (!seq)
continue; continue;
struct ssrc_ctx *ssrc_out = get_ssrc_ctx(sh->transcoding ? struct ssrc_ctx *ssrc_out = get_ssrc_ctx(sh->attrs.transcoding ?
ssrc_in->ssrc_map_out : ssrc_in->parent->h.ssrc, ssrc_in->ssrc_map_out : ssrc_in->parent->h.ssrc,
sink_ml->ssrc_hash, SSRC_DIR_OUTPUT, sink_ml->ssrc_hash, SSRC_DIR_OUTPUT,
monologue); monologue);

@ -1287,7 +1287,7 @@ static const char *kernelize_one(struct rtpengine_target_info *reti, GQueue *out
g_list_free(values); g_list_free(values);
} }
else { else {
if (sink_handler && sink_handler->transcoding) if (sink_handler && sink_handler->attrs.transcoding)
return NULL; return NULL;
} }
@ -1307,7 +1307,7 @@ output:
if (MEDIA_ISSET(media, ECHO)) if (MEDIA_ISSET(media, ECHO))
redi->output.ssrc_subst = 1; redi->output.ssrc_subst = 1;
if (sink_handler && sink_handler->transcoding) { if (sink_handler && sink_handler->attrs.transcoding) {
redi->output.ssrc_subst = 1; redi->output.ssrc_subst = 1;
reti->pt_filter = 1; reti->pt_filter = 1;
} }
@ -1325,7 +1325,7 @@ output:
handler->out->kernel(&redi->output.encrypt, sink); handler->out->kernel(&redi->output.encrypt, sink);
redi->output.rtcp_only = sink_handler ? (sink_handler->rtcp_only ? 1 : 0) : 0; redi->output.rtcp_only = sink_handler ? (sink_handler->attrs.rtcp_only ? 1 : 0) : 0;
mutex_unlock(&sink->out_lock); mutex_unlock(&sink->out_lock);
@ -1649,7 +1649,7 @@ static const struct streamhandler *__determine_handler(struct packet_stream *in,
must_recrypt = true; must_recrypt = true;
else if (MEDIA_ISSET(in->media, DTLS) || (out && MEDIA_ISSET(out->media, DTLS))) else if (MEDIA_ISSET(in->media, DTLS) || (out && MEDIA_ISSET(out->media, DTLS)))
must_recrypt = true; must_recrypt = true;
else if (sh->transcoding) else if (sh->attrs.transcoding)
must_recrypt = true; must_recrypt = true;
else if (in->call->recording) else if (in->call->recording)
must_recrypt = true; must_recrypt = true;
@ -1917,12 +1917,12 @@ static void media_packet_rtp_out(struct packet_handler_ctx *phc, struct sink_han
if (G_LIKELY(!phc->rtcp && phc->mp.rtp)) { if (G_LIKELY(!phc->rtcp && phc->mp.rtp)) {
unkern = __stream_ssrc_out(phc->out_srtp, phc->mp.rtp->ssrc, phc->mp.ssrc_in, unkern = __stream_ssrc_out(phc->out_srtp, phc->mp.rtp->ssrc, phc->mp.ssrc_in,
&phc->mp.ssrc_out, phc->mp.media_out->monologue->ssrc_hash, &phc->mp.ssrc_out, phc->mp.media_out->monologue->ssrc_hash,
sh->transcoding ? true : false); sh->attrs.transcoding ? true : false);
} }
else if (phc->rtcp && phc->mp.rtcp) { else if (phc->rtcp && phc->mp.rtcp) {
unkern = __stream_ssrc_out(phc->out_srtp, phc->mp.rtcp->ssrc, phc->mp.ssrc_in, unkern = __stream_ssrc_out(phc->out_srtp, phc->mp.rtcp->ssrc, phc->mp.ssrc_in,
&phc->mp.ssrc_out, phc->mp.media_out->monologue->ssrc_hash, &phc->mp.ssrc_out, phc->mp.media_out->monologue->ssrc_hash,
sh->transcoding ? true : false); sh->attrs.transcoding ? true : false);
} }
if (unkern) if (unkern)
@ -2466,7 +2466,7 @@ static int stream_packet(struct packet_handler_ctx *phc) {
goto next; goto next;
} }
else { else {
if (sh->rtcp_only) if (sh->attrs.rtcp_only)
goto next; goto next;
} }

@ -1772,9 +1772,9 @@ static int json_link_streams(struct call *c, struct redis_list *streams,
if (!sink) if (!sink)
return -1; return -1;
struct call_subscription *cs = __find_subscriber(ps_ml, sink); struct call_subscription *cs = __find_subscriber(ps_ml, sink);
if (cs && cs->egress) if (cs && cs->attrs.egress)
continue; continue;
__add_sink_handler(&ps->rtp_sinks, sink, cs ? cs->rtcp_only : false, false); __add_sink_handler(&ps->rtp_sinks, sink, cs ? cs->attrs.rtcp_only : false, false);
} }
g_queue_clear(&q); g_queue_clear(&q);
@ -2558,9 +2558,9 @@ char* redis_encode_json(struct call *c) {
JSON_ADD_STRING("%u/%u/%u/%u/%u", JSON_ADD_STRING("%u/%u/%u/%u/%u",
cs->monologue->unique_id, cs->monologue->unique_id,
cs->media_offset, cs->media_offset,
cs->offer_answer, cs->attrs.offer_answer,
cs->rtcp_only, cs->attrs.rtcp_only,
cs->egress); cs->attrs.egress);
} }
json_builder_end_array(builder); json_builder_end_array(builder);
} }

@ -429,10 +429,7 @@ struct call_subscription {
struct call_monologue *monologue; struct call_monologue *monologue;
GList *link; // link into the corresponding opposite list GList *link; // link into the corresponding opposite list
unsigned int media_offset; // 0 if media indexes match up unsigned int media_offset; // 0 if media indexes match up
unsigned int offer_answer:1; // bidirectional, exclusive struct sink_attrs attrs;
unsigned int rtcp_only:1;
unsigned int transcoding:1;
unsigned int egress:1;
}; };
/* half a dialogue */ /* half a dialogue */

@ -127,12 +127,17 @@ struct stream_fd {
int error_strikes; int error_strikes;
struct poller *poller; struct poller *poller;
}; };
struct sink_attrs {
unsigned int offer_answer:1; // bidirectional, exclusive
unsigned int rtcp_only:1;
unsigned int transcoding:1;
unsigned int egress:1;
};
struct sink_handler { struct sink_handler {
struct packet_stream *sink; struct packet_stream *sink;
const struct streamhandler *handler; const struct streamhandler *handler;
int kernel_output_idx; int kernel_output_idx;
unsigned int rtcp_only:1; struct sink_attrs attrs;
unsigned int transcoding:1;
}; };
struct media_packet { struct media_packet {
str raw; str raw;

Loading…
Cancel
Save