diff --git a/daemon/call.c b/daemon/call.c index 55716b6fc..0b24ac81b 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -3375,6 +3375,42 @@ static void monologue_bundle_check_heads(struct call_monologue *ml) { } } +// assigns sockets to be shared +__attribute__((nonnull(1))) +static void monologue_bundle_set_fds(struct call_monologue *ml) { + for (unsigned int i = 0; i < ml->medias->len; i++) { + __auto_type media = ml->medias->pdata[i]; + if (!media) + continue; + if (!media->bundle) + continue; + if (!MEDIA_ISSET(media, BUNDLE_ONLY)) + continue; + __auto_type bundle = media->bundle; + if (bundle == media) + continue; + + __auto_type msl = media->streams.head; + __auto_type bsl = bundle->streams.head; + + while (msl) { + __auto_type ms = msl->data; + __auto_type bs = bsl->data; + + // XXX close sockets that are not needed? + t_queue_clear(&ms->sfds); + + for (__auto_type sl = bs->sfds.head; sl; sl = sl->next) + t_queue_push_tail(&ms->sfds, sl->data); + + ms->selected_sfd = bs->selected_sfd; + + msl = msl->next; + bsl = bsl->next; + } + } +} + __attribute__((nonnull(1, 2))) static void monologue_bundle_accept(struct call_monologue *ml, sdp_ng_flags *flags) { if (!ML_ISSET(ml, BUNDLE)) @@ -3412,11 +3448,15 @@ static void monologue_bundle_accept(struct call_monologue *ml, sdp_ng_flags *fla continue; } + // remember as accepted + MEDIA_SET(media, BUNDLE_ONLY); + track_bundle_media_pt(media, exclude_pt); } monologue_bundle_check_consistency(ml); monologue_bundle_check_heads(ml); + monologue_bundle_set_fds(ml); } /* called with call->master_lock held in W */ @@ -3661,6 +3701,7 @@ int monologue_offer_answer(struct call_monologue *monologues[2], sdp_streams_q * } monologue_bundle_accept(sender_ml, flags); + monologue_bundle_set_fds(receiver_ml); // set ipv4/ipv6/mixed media stats if (flags->opmode == OP_OFFER || flags->opmode == OP_ANSWER) { diff --git a/include/call.h b/include/call.h index 5a6f9b814..b7fbc0685 100644 --- a/include/call.h +++ b/include/call.h @@ -219,6 +219,7 @@ enum { #define MEDIA_FLAG_RECRYPT (1LL << 37) #define MEDIA_FLAG_PUBLIC (1LL << 38) #define MEDIA_FLAG_EXTMAP_SHORT SHARED_FLAG_EXTMAP_SHORT +#define MEDIA_FLAG_BUNDLE_ONLY (1LL << 40) /* struct call_monologue */ #define ML_FLAG_REC_FORWARDING (1LL << 16) diff --git a/t/auto-daemon-tests-bundle.pl b/t/auto-daemon-tests-bundle.pl index 5a96e9ff4..d1c944ae2 100755 --- a/t/auto-daemon-tests-bundle.pl +++ b/t/auto-daemon-tests-bundle.pl @@ -416,7 +416,7 @@ isnt($port_a, $port_c, 'different ports'); isnt($port_a, $port_d, 'different ports'); isnt($port_b, $port_c, 'different ports'); isnt($port_b, $port_d, 'different ports'); -isnt($port_c, $port_d, 'different ports'); +is($port_c, $port_d, 'same ports'); snd($sock_a, $port_c, rtp(0, 2000, 6000, 0x1234, "\x44" x 160)); rcv($sock_c, $port_a, rtpm(0, 2000, 6000, 0x1234, "\x44" x 160)); @@ -529,7 +529,7 @@ isnt($port_a, $port_c, 'different ports'); isnt($port_a, $port_d, 'different ports'); isnt($port_b, $port_c, 'different ports'); isnt($port_b, $port_d, 'different ports'); -isnt($port_c, $port_d, 'different ports'); +is($port_c, $port_d, 'same ports'); snd($sock_a, $port_c, rtp(0, 2000, 6000, 0x1234, "\x44" x 160)); rcv($sock_c, $port_a, rtpm(0, 2000, 6000, 0x1234, "\x44" x 160));