From 6ba60d5b5475180685599afc7b213380b90f98b5 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 28 Feb 2019 14:58:50 -0500 Subject: [PATCH] TT#50652 split out packet dequeuing and sending function Change-Id: I303bcfb8869699554ff7381c68767c56fdcdda87 --- daemon/media_socket.c | 33 ++++++++++++++++++++------------- include/media_socket.h | 2 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 5ac12f3c3..312db95bc 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1572,6 +1572,25 @@ out: } +// appropriate locks must be held +int media_socket_dequeue(struct media_packet *mp, struct packet_stream *sink) { + struct codec_packet *p; + while ((p = g_queue_pop_head(&mp->packets_out))) { + __C_DBG("Forward to sink endpoint: %s:%d", sockaddr_print_buf(&sink->endpoint.address), + sink->endpoint.port); + + int ret = socket_sendto(&sink->selected_sfd->socket, + p->s.s, p->s.len, &sink->endpoint); + + codec_packet_free(p); + + if (ret == -1) + return -1; + } + return 0; +} + + /* called lock-free */ static int stream_packet(struct packet_handler_ctx *phc) { /** @@ -1696,19 +1715,7 @@ static int stream_packet(struct packet_handler_ctx *phc) { goto drop; } - struct codec_packet *p; - ret = 0; - while ((p = g_queue_pop_head(&phc->mp.packets_out))) { - __C_DBG("Forward to sink endpoint: %s:%d", sockaddr_print_buf(&phc->sink->endpoint.address), - phc->sink->endpoint.port); - - ret = socket_sendto(&phc->sink->selected_sfd->socket, p->s.s, p->s.len, &phc->sink->endpoint); - - codec_packet_free(p); - - if (ret == -1) - break; - } + ret = media_socket_dequeue(&phc->mp, phc->sink); mutex_unlock(&phc->sink->out_lock); diff --git a/include/media_socket.h b/include/media_socket.h index b2c4c3a0c..59fc21a59 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -130,6 +130,8 @@ void __unkernelize(struct packet_stream *); void unkernelize(struct packet_stream *); void __stream_unconfirm(struct packet_stream *); +int media_socket_dequeue(struct media_packet *mp, struct packet_stream *sink); + /* XXX shouldn't be necessary */ /* INLINE struct local_intf *get_interface_from_address(const struct logical_intf *lif,