diff --git a/daemon/call.c b/daemon/call.c index 6e8a2adbb..7db3e8f7b 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2603,8 +2603,10 @@ void update_init_subscribers(struct call_monologue *ml, enum call_opmode opmode) } } -__attribute__((nonnull(1, 2))) -static void __call_monologue_init_from_flags(struct call_monologue *ml, sdp_ng_flags *flags) { +__attribute__((nonnull(1, 3))) +static void __call_monologue_init_from_flags(struct call_monologue *ml, struct call_monologue *other_ml, + sdp_ng_flags *flags) +{ call_t *call = ml->call; call->last_signal = rtpe_now.tv_sec; @@ -2617,6 +2619,10 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, sdp_ng_f /* consume sdp session parts */ { + /* for cases with origin replacements, keep the very first used origin */ + if (other_ml && !other_ml->session_last_sdp_orig && flags->session_sdp_orig.parsed) + other_ml->session_last_sdp_orig = sdp_orig_dup(&flags->session_sdp_orig); + /* origin (name, version etc.) */ if (!ml->session_sdp_orig && flags->session_sdp_orig.parsed) ml->session_sdp_orig = sdp_orig_dup(&flags->session_sdp_orig); @@ -2914,7 +2920,7 @@ int monologue_offer_answer(struct call_monologue *monologues[2], sdp_streams_q * return -1; } - __call_monologue_init_from_flags(other_ml, flags); + __call_monologue_init_from_flags(other_ml, monologue, flags); if (flags->exclude_recording) { ML_SET(monologue, NO_RECORDING); @@ -3285,7 +3291,7 @@ struct media_subscription *call_get_top_media_subscription(struct call_monologue /* called with call->master_lock held in W */ __attribute__((nonnull(1, 2, 3))) int monologue_publish(struct call_monologue *ml, sdp_streams_q *streams, sdp_ng_flags *flags) { - __call_monologue_init_from_flags(ml, flags); + __call_monologue_init_from_flags(ml, NULL, flags); if (flags->exclude_recording) ML_SET(ml, NO_RECORDING); @@ -3428,7 +3434,7 @@ int monologue_subscribe_request(const subscription_q *srms, struct call_monologu unsigned int index = 1; /* running counter for output/dst medias */ __unsubscribe_medias_from_all(dst_ml); - __call_monologue_init_from_flags(dst_ml, flags); + __call_monologue_init_from_flags(dst_ml, NULL, flags); g_auto(GQueue) mls = G_QUEUE_INIT; /* to avoid duplications */ for (auto_iter(sl, srms->head); sl; sl = sl->next) diff --git a/daemon/sdp.c b/daemon/sdp.c index 4a0ed5896..cf7be7adc 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1839,7 +1839,10 @@ int sdp_streams(const sdp_sessions_q *sessions, sdp_streams_q *streams, sdp_ng_f * in `sdp_create()` */ sdp_attr_append_other(&flags->session_attributes, &session->attributes); - flags->session_sdp_orig = session->origin; + /* set only for the first SDP session, to be able to re-use versioning + * for all the rest SDP sessions during replacements. See `sdp_version_check()` */ + if (!flags->session_sdp_orig.parsed) + flags->session_sdp_orig = session->origin; flags->session_sdp_name = session->session_name; flags->session_rr = session->rr; flags->session_rs = session->rs; @@ -3269,12 +3272,10 @@ int sdp_replace(struct sdp_chopper *chop, sdp_sessions_q *sessions, err = "error while processing o= line"; - /* for cases with origin replacements, keep the very first used origin */ - if (!monologue->session_last_sdp_orig) - monologue->session_last_sdp_orig = sdp_orig_dup(&session->origin); - /* replace username */ - if (flags->replace_username || flags->replace_origin_full) { + if (monologue->session_last_sdp_orig && + (flags->replace_username || flags->replace_origin_full)) + { /* make sure the username field in the o= line always remains the same * in all SDPs going to a particular endpoint */ if (copy_up_to(chop, &session->origin.username)) @@ -3285,7 +3286,7 @@ int sdp_replace(struct sdp_chopper *chop, sdp_sessions_q *sessions, } /* replace session id */ - if (flags->replace_origin_full) { + if (monologue->session_last_sdp_orig && flags->replace_origin_full) { if (copy_up_to(chop, &session->origin.session_id)) goto error; chopper_append_str(chop, &monologue->session_last_sdp_orig->session_id); @@ -3299,8 +3300,11 @@ int sdp_replace(struct sdp_chopper *chop, sdp_sessions_q *sessions, /* record position of o= line and init SDP version */ session->origin.version_output_pos = chop->output->len; /* TODO: should we just go to 128bit length? */ - if (monologue->session_last_sdp_orig->version_num == ULLONG_MAX) + if (monologue->session_last_sdp_orig && + monologue->session_last_sdp_orig->version_num == ULLONG_MAX) + { monologue->session_last_sdp_orig->version_num = (unsigned int)ssl_random(); + } /* replace origin's network addr */ if ((flags->replace_origin || flags->replace_origin_full) &&