summaryrefslogtreecommitdiff
path: root/src/udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udp.c')
-rw-r--r--src/udp.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/src/udp.c b/src/udp.c
index 78b09aa..ee6170c 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -230,21 +230,73 @@ gboolean attach_udpsinks(struct udp_sinks *sinks)
return TRUE;
}
+static gboolean send_keepalive(GstElement* source, const char* name, GInetAddress* remote)
+{
+ if(!remote) {
+ log_printf(WARNING, "keepalives are enabled but no remote address is set... disabling keep alives");
+ return FALSE;
+ }
+
+ GSocket *sock;
+ 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);
+ return TRUE;
+}
+
static gboolean send_keepalives(gpointer user_data)
{
- log_printf(WARNING, "sending keep alives is not yet supporet!");
+ 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_)) {
+ return FALSE;
+ }
+
return TRUE;
}
-gboolean attach_udpsources(struct udp_sources *sources)
+void on_rtphost_resolved(GObject* resolver, GAsyncResult *res, gpointer user_data)
+{
+ struct udp_sources* sources = (struct udp_sources*)user_data;
+ GError *error = NULL;
+ GList* addrs = g_resolver_lookup_by_name_finish ((GResolver *)resolver, res, &error);
+ if(!addrs) {
+ log_printf(ERROR, "Resolving of remote RTP host failed: %s", error ? error->message : "unknown error");
+ g_error_free(error);
+ return;
+ }
+
+ GList *entry;
+ guint idx;
+ log_printf(DEBUG, "Resolving of remote RTP host succeded:");
+ for (entry = addrs, idx = 1; entry != NULL; entry = entry->next, ++idx) {
+ GInetAddress* addr = (GInetAddress*)entry->data;
+ if(!sources->remote_addr_) {
+ sources->remote_addr_ = g_inet_address_new_from_bytes(g_inet_address_to_bytes(addr),
+ g_inet_address_get_family(addr));
+ log_printf(DEBUG, " result %d: %s (selected)", idx, g_inet_address_to_string(addr));
+ } else {
+ log_printf(DEBUG, " result %d: %s", idx, g_inet_address_to_string(addr));
+ }
+ }
+ g_resolver_free_addresses(addrs);
+ log_printf(INFO, "Set address for remote RTP host: %s", g_inet_address_to_string(sources->remote_addr_));
+
+ if(send_keepalives(sources))
+ g_timeout_add_seconds(sources->keepalive_interval_, send_keepalives, sources);
+}
+
+gboolean attach_udpsources(struct udp_sources *sources, gchar* rtphost)
{
if(!sources)
return FALSE;
- if(sources->keepalive_interval_ > 0) {
- send_keepalives(sources);
- if(!g_timeout_add_seconds(sources->keepalive_interval_, send_keepalives, sources))
- return FALSE;
+ if(sources->keepalive_interval_ > 0 && rtphost) {
+ GResolver* resolver = g_resolver_get_default();
+ g_resolver_lookup_by_name_async(resolver, rtphost, NULL, on_rtphost_resolved, sources);
}
return TRUE;