diff options
author | Christian Pointner <equinox@spreadspace.org> | 2014-10-01 01:42:23 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2014-10-01 01:42:23 +0200 |
commit | 97c1c6af16683c2e99bf1897af2d26aea089589c (patch) | |
tree | d3a63959b9ca755bd9821dba20cefcc2de569a4f /src | |
parent | resolving remote rtp works now (diff) |
sending keep alives works now
Diffstat (limited to 'src')
-rw-r--r-- | src/datatypes.h | 1 | ||||
-rw-r--r-- | src/sydra.c | 2 | ||||
-rw-r--r-- | src/udp.c | 39 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/datatypes.h b/src/datatypes.h index 2ff5e12..7ecd997 100644 --- a/src/datatypes.h +++ b/src/datatypes.h @@ -77,6 +77,7 @@ struct udp_sources { GstElement* rtcp_audio_; int keepalive_interval_; GInetAddress* remote_addr_; + guint port_base_; }; #endif diff --git a/src/sydra.c b/src/sydra.c index f94610c..a4d2d05 100644 --- a/src/sydra.c +++ b/src/sydra.c @@ -169,7 +169,7 @@ int main_loop(options_t* opt) struct udp_sinks sinks = { { NULL, NULL }, { NULL, NULL }, { NULL, NULL }, { NULL, NULL }, opt->timeout_ }; - struct udp_sources sources = { NULL, NULL, NULL, NULL, opt->keepalive_int_, NULL }; + struct udp_sources sources = { NULL, NULL, NULL, NULL, opt->keepalive_int_, NULL , opt->rtp_port_base_ }; GstElement *pipeline = opt->mode_ == SENDER ? create_sender_pipeline(opt, &sinks) : create_receiver_pipeline(opt, &sources); if(!pipeline) { @@ -230,7 +230,7 @@ gboolean attach_udpsinks(struct udp_sinks *sinks) return TRUE; } -static gboolean send_keepalive(GstElement* source, const char* name, GInetAddress* remote) +static gboolean send_keepalive(GstElement* source, const char* name, GInetAddress* remote, guint port) { if(!remote) { log_printf(WARNING, "keepalives are enabled but no remote address is set... disabling keep alives"); @@ -241,17 +241,44 @@ static gboolean send_keepalive(GstElement* source, const char* name, GInetAddres g_object_get(G_OBJECT(source), "used-socket", &sock, NULL); int fd = g_socket_get_fd(sock); - log_printf(WARNING, "if implemented keep alives would be sent out to fd: %d", fd); + struct sockaddr_storage addr; + socklen_t addrlen = sizeof(struct sockaddr_storage); + memset(&addr, 0, addrlen); + switch(g_inet_address_get_family(remote)) { + case G_SOCKET_FAMILY_IPV4: { + addrlen = sizeof(struct sockaddr_in); + size_t len = g_inet_address_get_native_size(remote); + if(len > sizeof(struct in_addr)) len = sizeof(struct in_addr); + memcpy(&(((struct sockaddr_in*)(&addr))->sin_addr), g_inet_address_to_bytes(remote), len); + ((struct sockaddr_in*)&addr)->sin_port = htons(port); + break; + } + case G_SOCKET_FAMILY_IPV6: { + addrlen = sizeof(struct sockaddr_in6); + size_t len = g_inet_address_get_native_size(remote); + if(len > sizeof(struct in6_addr)) len = sizeof(struct in6_addr); + memcpy(&(((struct sockaddr_in6*)&addr)->sin6_addr), g_inet_address_to_bytes(remote), len); + ((struct sockaddr_in6*)&addr)->sin6_port = htons(port); + break; + } + default: log_printf(ERROR, "remote address has unsupported protocol family - disabling keep alives"); return FALSE; + } + + log_printf(DEBUG, "sending keep-alive out on to %s %d - %s (fd=%d)", g_inet_address_to_string(remote), port, name, fd); + gchar buf[] = UDP_PROTO_MAGIC UDP_PROTO_CMD_ADD_CLIENT; + sendto(fd, buf, UDP_PROTO_MAGIC_LEN+UDP_PROTO_CMD_ADD_CLIENT_LEN, 0, (struct sockaddr *)&(addr), addrlen); + return TRUE; } static gboolean send_keepalives(gpointer user_data) { struct udp_sources* sources = (struct udp_sources*)user_data; - if(!send_keepalive(sources->rtp_video_, "RTP(video)", sources->remote_addr_) || - !send_keepalive(sources->rtcp_video_, "RTCP(video)", sources->remote_addr_) || - !send_keepalive(sources->rtp_audio_, "RTP(audio)", sources->remote_addr_) || - !send_keepalive(sources->rtcp_audio_, "RTCP(audio)", sources->remote_addr_)) { + guint port = sources->port_base_; + if(!send_keepalive(sources->rtp_video_, "RTP(video)", sources->remote_addr_, port++) || + !send_keepalive(sources->rtcp_video_, "RTCP(video)", sources->remote_addr_, port++) || + !send_keepalive(sources->rtp_audio_, "RTP(audio)", sources->remote_addr_, port++) || + !send_keepalive(sources->rtcp_audio_, "RTCP(audio)", sources->remote_addr_, port++)) { return FALSE; } |