diff --git a/daemon/call.c b/daemon/call.c index 0e879c83e..ad08374be 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -38,20 +38,6 @@ -#ifndef PORT_RANDOM_MIN -#define PORT_RANDOM_MIN 6 -#define PORT_RANDOM_MAX 20 -#endif - -#ifndef MAX_RECV_ITERS -#define MAX_RECV_ITERS 50 -#endif - - - - - - /* also serves as array index for callstream->peers[] */ struct iterator_helper { GSList *del_timeout; @@ -785,6 +771,7 @@ static void __assign_stream_fds(struct call_media *media, GQueue *intf_sfds) { if (first) g_queue_clear(&ps->sfds); + sfd->stream = ps; g_queue_push_tail(&ps->sfds, sfd); if (!ps->selected_sfd) diff --git a/daemon/call.h b/daemon/call.h index b824846cf..e8dafccb4 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -451,7 +451,6 @@ void calls_dump_redis(struct callmaster *); 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 stream_fd *__stream_fd_new(socket_t *fd, struct call_media *); struct packet_stream *__packet_stream_new(struct call *call); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 365fa4e89..cccd6273f 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -16,6 +16,20 @@ #include "sdp.h" + + +#ifndef PORT_RANDOM_MIN +#define PORT_RANDOM_MIN 6 +#define PORT_RANDOM_MAX 20 +#endif + +#ifndef MAX_RECV_ITERS +#define MAX_RECV_ITERS 50 +#endif + + + + typedef int (*rewrite_func)(str *, struct packet_stream *); diff --git a/daemon/sdp.c b/daemon/sdp.c index cfcbda274..ef00efa0e 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1435,13 +1435,13 @@ warn: return 0; } -static int insert_ice_address(struct sdp_chopper *chop, struct packet_stream *ps, const struct local_intf *ifa) { +static int insert_ice_address(struct sdp_chopper *chop, struct stream_fd *sfd) { char buf[64]; int len; - call_stream_address46(buf, ps, SAF_ICE, &len, ifa); + call_stream_address46(buf, sfd->stream, SAF_ICE, &len, sfd->local_intf); chopper_append_dup(chop, buf, len); - chopper_append_printf(chop, " %u", ps->selected_sfd->socket.local.port); + chopper_append_printf(chop, " %u", sfd->socket.local.port); return 0; } @@ -1680,17 +1680,21 @@ out: *lprefp = lpref; } -static void insert_candidate(struct sdp_chopper *chop, struct packet_stream *ps, unsigned int component, - unsigned int type_pref, unsigned int local_pref, enum ice_candidate_type type, - const struct local_intf *ifa) +static void insert_candidate(struct sdp_chopper *chop, struct stream_fd *sfd, + unsigned int type_pref, unsigned int local_pref, enum ice_candidate_type type) { unsigned long priority; + struct packet_stream *ps = sfd->stream; + const struct local_intf *ifa = sfd->local_intf; + + if (local_pref == -1) + local_pref = ifa->preference; - priority = ice_priority_pref(type_pref, local_pref, component); + priority = ice_priority_pref(type_pref, local_pref, ps->component); chopper_append_c(chop, "a=candidate:"); chopper_append_str(chop, &ifa->spec->ice_foundation); - chopper_append_printf(chop, " %u UDP %lu ", component, priority); - insert_ice_address(chop, ps, ifa); + chopper_append_printf(chop, " %u UDP %lu ", ps->component, priority); + insert_ice_address(chop, sfd); chopper_append_c(chop, " typ "); chopper_append_c(chop, ice_candidate_type_str(type)); /* raddr and rport are required for non-host candidates: rfc5245 section-15.1 */ @@ -1699,14 +1703,26 @@ static void insert_candidate(struct sdp_chopper *chop, struct packet_stream *ps, chopper_append_c(chop, "\r\n"); } +static void insert_sfd_candidates(struct sdp_chopper *chop, struct packet_stream *ps, + unsigned int type_pref, unsigned int local_pref, enum ice_candidate_type type) +{ + GList *l; + struct stream_fd *sfd; + + for (l = ps->sfds.head; l; l = l->next) { + sfd = l->data; + insert_candidate(chop, sfd, type_pref, local_pref, type); + + if (local_pref != -1) + local_pref++; + } +} + static void insert_candidates(struct sdp_chopper *chop, struct packet_stream *rtp, struct packet_stream *rtcp, struct sdp_ng_flags *flags, struct sdp_media *sdp_media) { - GList *l; const struct local_intf *ifa; - unsigned int pref; struct call_media *media; - const struct logical_intf *lif; struct ice_agent *ag; unsigned int type_pref, local_pref; enum ice_candidate_type cand_type; @@ -1725,13 +1741,12 @@ static void insert_candidates(struct sdp_chopper *chop, struct packet_stream *rt } ag = media->ice_agent; - lif = ag ? ag->logical_intf : media->logical_intf; if (ag && AGENT_ISSET(ag, COMPLETED)) { ifa = rtp->selected_sfd->local_intf; - insert_candidate(chop, rtp, 1, type_pref, ifa->preference, cand_type, ifa); + insert_candidate(chop, rtp->selected_sfd, type_pref, ifa->preference, cand_type); if (rtcp) /* rtcp-mux only possible in answer */ - insert_candidate(chop, rtcp, 2, type_pref, ifa->preference, cand_type, ifa); + insert_candidate(chop, rtcp->selected_sfd, type_pref, ifa->preference, cand_type); if (flags->opmode == OP_OFFER && AGENT_ISSET(ag, CONTROLLING)) { GQueue rc; @@ -1751,18 +1766,10 @@ static void insert_candidates(struct sdp_chopper *chop, struct packet_stream *rt return; } - for (l = lif->list.head; l; l = l->next) { - ifa = l->data; - pref = (local_pref == -1) ? ifa->preference : local_pref; + insert_sfd_candidates(chop, rtp, type_pref, local_pref, cand_type); - insert_candidate(chop, rtp, 1, type_pref, pref, cand_type, ifa); - - if (rtcp) /* rtcp-mux only possible in answer */ - insert_candidate(chop, rtcp, 2, type_pref, pref, cand_type, ifa); - - if (local_pref != -1) - local_pref++; - } + if (rtcp) /* rtcp-mux only possible in answer */ + insert_sfd_candidates(chop, rtcp, type_pref, local_pref, cand_type); } static void insert_dtls(struct call_media *media, struct sdp_chopper *chop) {