From 29a24d354e93a1a95616c96a00edbd785619d695 Mon Sep 17 00:00:00 2001 From: Marvin Klimke Date: Thu, 22 Nov 2018 17:53:07 +0100 Subject: [PATCH] implement rtp_print and rtp_reverse also begin of rtp_start add libre rtp socket and flag for rtcp in struct rtp --- include/villas/nodes/rtp.h | 9 ++--- lib/nodes/rtp.c | 71 ++++++++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/include/villas/nodes/rtp.h b/include/villas/nodes/rtp.h index a73994056..1f6fc1591 100644 --- a/include/villas/nodes/rtp.h +++ b/include/villas/nodes/rtp.h @@ -46,18 +46,15 @@ extern "C" { struct format_type; struct rtp { - /* - struct { - int socket; - struct list endpoints; - } in, out; - */ + struct rtp_sock *rs; /**< RTP socket */ struct sa local; /**< Local address of the socket */ struct sa remote; /**< Remote address of the socket */ struct format_type *format; struct io io; + + bool enable_rtcp; }; /** @see node_type::print */ diff --git a/lib/nodes/rtp.c b/lib/nodes/rtp.c index 2576e511f..c6520b293 100644 --- a/lib/nodes/rtp.c +++ b/lib/nodes/rtp.c @@ -30,30 +30,36 @@ #include #include +#include #include #include int rtp_reverse(struct node *n) { - /* struct rtp *m = (struct rtp *) n->_vd; */ + struct rtp *r = (struct rtp *) n->_vd; + struct sa tmp; - /* TODO */ + tmp = r->local; + r->local = r->remote; + r->remote = tmp; - return -1; + return 0; } int rtp_parse(struct node *n, json_t *cfg) { int ret = 0; - struct rtp *sr = (struct rtp *) n->_vd; + struct rtp *r = (struct rtp *) n->_vd; const char *local, *remote; const char *format = "villas.binary"; + bool enable_rtcp = false; json_error_t err; - ret = json_unpack_ex(cfg, &err, 0, "{ s?: s, s: { s: s }, s: { s: s } }", + ret = json_unpack_ex(cfg, &err, 0, "{ s?: s, s?: b, s: { s: s }, s: { s: s } }", "format", &format, + "enable_rtcp", &enable_rtcp, "out", "address", &remote, "in", @@ -63,49 +69,70 @@ int rtp_parse(struct node *n, json_t *cfg) jerror(&err, "Failed to parse configuration of node %s", node_name(n)); /* Format */ - sr->format = format_type_lookup(format); - if(!sr->format) + r->format = format_type_lookup(format); + if(!r->format) error("Invalid format '%s' for node %s", format, node_name(n)); - ret = sa_decode(&sr->remote, remote, strlen(remote)); + /* Enable RTCP */ + r->enable_rtcp = enable_rtcp; + if(enable_rtcp) + error("RTCP is not implemented yet."); + + /* Remote address */ + ret = sa_decode(&r->remote, remote, strlen(remote)); if (ret) { error("Failed to resolve remote address '%s' of node %s: %s", remote, node_name(n), strerror(ret)); } - ret = sa_decode(&sr->local, local, strlen(local)); + /* Local address */ + ret = sa_decode(&r->local, local, strlen(local)); if (ret) { error("Failed to resolve local address '%s' of node %s: %s", local, node_name(n), strerror(ret)); } - info("### MKL ### rtp_parse success\n"); + /** @todo parse * in addresses */ return ret; } char * rtp_print(struct node *n) { - /* struct rtp *m = (struct rtp *) n->_vd; */ - - char *buf = NULL; - + struct rtp *r = (struct rtp *) n->_vd; + char *buf; - /* TODO */ + char *local = socket_print_addr((struct sockaddr *) &r->local.u); + char *remote = socket_print_addr((struct sockaddr *) &r->remote.u); + + buf = strf("format=%s, in.address=%s, out.address=%s", format_type_name(r->format), local, remote); + + free(local); + free(remote); return buf; } int rtp_start(struct node *n) { - /* int ret; - struct rtp *m = (struct rtp *) n->_vd; - */ + struct rtp *r = (struct rtp *) n->_vd; + + /* Initialize IO */ + ret = io_init(&r->io, r->format, &n->signals, SAMPLE_HAS_ALL & ~SAMPLE_HAS_OFFSET); + if (ret) + return ret; + + ret = io_check(&r->io); + if (ret) + return ret; + + uint16_t port = sa_port(&r->local) & ~1; + ret = rtp_listen(&r->rs, IPPROTO_UDP, &r->local, port, port+1, r->enable_rtcp, NULL, NULL, NULL); /* TODO */ - return -1; + return ret; } int rtp_stop(struct node *n) @@ -159,11 +186,9 @@ int rtp_fd(struct node *n) { /* struct rtp *m = (struct rtp *) n->_vd; */ - int fd = -1; + error("No acces to file descriptor."); - /* TODO */ - - return fd; + return -1; } static struct plugin p = {