diff --git a/daemon/call.c b/daemon/call.c index 6412eee28..87a48885f 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1208,7 +1208,7 @@ static void release_port(struct udp_fd *r, struct callmaster *m) { r->localport = 0; } -static int __get_consecutive_ports(struct udp_fd *array, int array_len, int wanted_start_port, struct call *c) { +int __get_consecutive_ports(struct udp_fd *array, int array_len, int wanted_start_port, struct call *c) { int i, j, cycle = 0; struct udp_fd *it; u_int16_t port; @@ -1312,6 +1312,27 @@ static void stream_fd_free(void *p) { obj_put(f->call); } +struct stream_fd *__stream_fd_new(struct udp_fd *fd, struct call *call) { + struct stream_fd *sfd; + struct poller_item pi; + struct poller *po = call->callmaster->poller; + + sfd = obj_alloc0("stream_fd", sizeof(*sfd), stream_fd_free); + sfd->fd = *fd; + sfd->call = obj_get(call); + call->stream_fds = g_slist_prepend(call->stream_fds, sfd); /* hand over ref */ + + ZERO(pi); + pi.fd = sfd->fd.fd; + pi.obj = &sfd->obj; + pi.readable = stream_fd_readable; + pi.closed = stream_fd_closed; + + poller_add_item(po, &pi); + + return sfd; +} + static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigned int num_ports, const struct endpoint *ep) { @@ -1321,8 +1342,6 @@ static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigne unsigned int i; struct stream_fd *sfd; struct call *call = media->call; - struct poller_item pi; - struct poller *po = call->callmaster->poller; for (l = media->endpoint_maps; l; l = l->next) { em = l->data; @@ -1364,19 +1383,8 @@ alloc: __C_DBG("allocating stream_fds for %u ports", num_ports); for (i = 0; i < num_ports; i++) { - sfd = obj_alloc0("stream_fd", sizeof(*sfd), stream_fd_free); - sfd->fd = fd_arr[i]; - sfd->call = obj_get(call); + sfd = __stream_fd_new(&fd_arr[i], call); g_queue_push_tail(&em->sfds, sfd); /* not referenced */ - call->stream_fds = g_slist_prepend(call->stream_fds, sfd); /* hand over ref */ - - ZERO(pi); - pi.fd = sfd->fd.fd; - pi.obj = &sfd->obj; - pi.readable = stream_fd_readable; - pi.closed = stream_fd_closed; - - poller_add_item(po, &pi); } return em; @@ -1409,6 +1417,19 @@ static int __wildcard_endpoint_map(struct call_media *media, unsigned int num_po return 0; } +struct packet_stream *__packet_stream_new(struct call *call) { + struct packet_stream *stream; + + stream = g_slice_alloc0(sizeof(*stream)); + mutex_init(&stream->in_lock); + mutex_init(&stream->out_lock); + stream->call = call; + stream->last_packet = poller_now; + call->streams = g_slist_prepend(call->streams, stream); + + return stream; +} + static int __num_media_streams(struct call_media *media, unsigned int num_ports) { struct packet_stream *stream; struct call *call = media->call; @@ -1416,14 +1437,9 @@ static int __num_media_streams(struct call_media *media, unsigned int num_ports) __C_DBG("allocating %i new packet_streams", num_ports - media->streams.length); while (media->streams.length < num_ports) { - stream = g_slice_alloc0(sizeof(*stream)); - mutex_init(&stream->in_lock); - mutex_init(&stream->out_lock); - stream->call = call; + stream = __packet_stream_new(call); stream->media = media; - stream->last_packet = poller_now; g_queue_push_tail(&media->streams, stream); - call->streams = g_slist_prepend(call->streams, stream); ret++; } @@ -2163,7 +2179,7 @@ struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_ } /* must be called with call->master_lock held in W */ -static struct call_monologue *__monologue_create(struct call *call) { +struct call_monologue *__monologue_create(struct call *call) { struct call_monologue *ret; __C_DBG("creating new monologue"); @@ -2180,7 +2196,7 @@ static struct call_monologue *__monologue_create(struct call *call) { } /* must be called with call->master_lock held in W */ -static void __monologue_tag(struct call_monologue *ml, const str *tag) { +void __monologue_tag(struct call_monologue *ml, const str *tag) { struct call *call = ml->call; __C_DBG("tagging monologue with '"STR_FORMAT"'", STR_FMT(tag)); diff --git a/daemon/call.h b/daemon/call.h index 38ae6ebc0..eab535e05 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -350,6 +350,12 @@ const char *call_query_ng(bencode_item_t *, struct callmaster *, bencode_item_t void calls_dump_redis(struct callmaster *); +struct call_monologue *__monologue_create(struct call *call); +void __monologue_tag(struct call_monologue *ml, const str *tag); +struct stream_fd *__stream_fd_new(struct udp_fd *fd, struct call *call); +int __get_consecutive_ports(struct udp_fd *array, int array_len, int wanted_start_port, struct call *c); +struct packet_stream *__packet_stream_new(struct call *call); + struct call *call_get_or_create(const str *callid, struct callmaster *m); struct call *call_get_opmode(const str *callid, struct callmaster *m, enum call_opmode opmode);