From fbf666f5694d15d183753126492c4659f72c56fe Mon Sep 17 00:00:00 2001 From: Donat Zenichev Date: Fri, 10 Nov 2023 11:22:46 +0100 Subject: [PATCH] MT#57550 Improve `monologue_stop()`, add subs handling Moving from call subscriptions to media subscriptions. Add a possibility to run `media_stop()` and `__monologue_stop()` for all related to this monologue media subscribers. This is an improvement, which gives the following benefits: - all subscribers are handled inside of the func, less code out of it - the function gets in sync with new media subscriptions concept Change-Id: Ia0b897f53438559a68c8b469c71fec72f0d562af --- daemon/call.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 3454a46ea..9e2b96c3f 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -4817,13 +4817,42 @@ static void media_stop(struct call_media *m) { rtcp_timer_stop(&m->rtcp_timer); mqtt_timer_stop(&m->mqtt_timer); } +/** + * Stops media player of given monologue. + */ static void __monologue_stop(struct call_monologue *ml) { media_player_stop(ml->player); } -static void monologue_stop(struct call_monologue *ml) { +/** + * Stops media player and all medias of given monolgue. + * If asked, stops all media subscribers as well. + */ +static void monologue_stop(struct call_monologue *ml, bool stop_media_subsribers) { + /* monologue itself */ __monologue_stop(ml); for (unsigned int i = 0; i < ml->medias->len; i++) + { media_stop(ml->medias->pdata[i]); + } + /* monologue's subscribers */ + if (stop_media_subsribers) { + AUTO_CLEANUP(GQueue mls, g_queue_clear) = G_QUEUE_INIT; /* to avoid duplications */ + for (unsigned int i = 0; i < ml->medias->len; i++) + { + struct call_media *media = ml->medias->pdata[i]; + if (!media) + continue; + for (GList *l = media->media_subscribers.head; l; l = l->next) + { + struct media_subscription * ms = l->data; + media_stop(ms->media); + if (!g_queue_find(&mls, ms->monologue)) { + __monologue_stop(ms->monologue); + g_queue_push_tail(&mls, ms->monologue); + } + } + } + } } @@ -4890,11 +4919,9 @@ do_delete: if (output) ng_call_stats(c, fromtag, totag, output, NULL); - monologue_stop(ml); - for (GList *l = ml->subscribers.head; l; l = l->next) { - struct call_subscription *cs = l->data; - monologue_stop(cs->monologue); - } + /* stop media player and all medias of ml. + * same for media subscribers */ + monologue_stop(ml, true); /* check, if we have some associated monologues left, which have own associations * which means they need a media to flow */ @@ -4914,7 +4941,7 @@ do_delete: del_all: for (i = c->monologues.head; i; i = i->next) { ml = i->data; - monologue_stop(ml); + monologue_stop(ml, false); } c->destroyed = rtpe_now;