2023-09-04 12:21:37 +02:00
|
|
|
/* Node type: rtp.
|
2018-11-16 16:07:47 +01:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2019-01-25 17:26:08 +01:00
|
|
|
* Author: Marvin Klimke <marvin.klimke@rwth-aachen.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-11-16 16:07:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-12-07 15:15:24 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2019-03-29 09:50:47 +01:00
|
|
|
#include <fstream>
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/dsp/pid.hpp>
|
|
|
|
#include <villas/format.hpp>
|
|
|
|
#include <villas/hooks/decimate.hpp>
|
|
|
|
#include <villas/hooks/limit_rate.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/list.hpp>
|
2019-03-29 09:50:27 +01:00
|
|
|
#include <villas/log.hpp>
|
2019-01-07 15:22:38 +01:00
|
|
|
#include <villas/queue_signalled.h>
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2019-04-23 00:12:31 +02:00
|
|
|
extern "C" {
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <re/re_sa.h>
|
|
|
|
#include <re/re_rtp.h>
|
2019-04-23 00:12:31 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
class NodeCompat;
|
|
|
|
class SuperNode;
|
|
|
|
|
2019-01-25 17:26:08 +01:00
|
|
|
// The maximum length of a packet which contains rtp data.
|
2018-11-28 18:12:06 +01:00
|
|
|
#define RTP_INITIAL_BUFFER_LEN 1500
|
2019-01-28 10:53:01 +01:00
|
|
|
#define RTP_PACKET_TYPE 21
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
enum class RTPHookType { DISABLED, DECIMATE, LIMIT_RATE };
|
2018-11-16 16:07:47 +01:00
|
|
|
|
|
|
|
struct rtp {
|
2023-09-07 11:46:39 +02:00
|
|
|
struct rtp_sock *rs; // RTP socket
|
2018-11-22 07:18:27 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct {
|
|
|
|
struct sa saddr_rtp; // Local/Remote address of the RTP socket
|
|
|
|
struct sa saddr_rtcp; // Local/Remote address of the RTCP socket
|
|
|
|
} in, out;
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Format *formatter;
|
2018-11-22 17:53:07 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct {
|
|
|
|
int enabled;
|
2019-01-21 12:12:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int num_rrs;
|
|
|
|
} rtcp;
|
2019-01-21 12:12:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct {
|
|
|
|
double a;
|
|
|
|
double b;
|
2019-01-21 12:12:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
enum RTPHookType rate_hook_type;
|
2019-04-14 19:22:33 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
LimitHook::Ptr rate_hook;
|
|
|
|
dsp::PID rate_pid;
|
2019-04-14 19:22:33 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
// PID parameters for rate controller
|
|
|
|
double Kp, Ki, Kd;
|
|
|
|
double rate_min;
|
2019-04-14 19:22:33 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
double rate;
|
|
|
|
double rate_source; // Sample rate of source
|
2019-01-28 12:30:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
std::ofstream *log;
|
|
|
|
char *log_filename;
|
|
|
|
} aimd; // AIMD state
|
2018-12-07 15:15:24 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct CQueueSignalled recv_queue;
|
|
|
|
struct mbuf *send_mb;
|
2018-11-16 16:07:47 +01:00
|
|
|
};
|
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *rtp_print(NodeCompat *n);
|
2021-08-10 10:12:48 -04:00
|
|
|
|
|
|
|
int rtp_parse(NodeCompat *n, json_t *json);
|
|
|
|
|
|
|
|
int rtp_init(NodeCompat *n);
|
|
|
|
|
|
|
|
int rtp_destroy(NodeCompat *n);
|
|
|
|
|
|
|
|
int rtp_reverse(NodeCompat *n);
|
|
|
|
|
|
|
|
int rtp_type_start(SuperNode *sn);
|
|
|
|
|
|
|
|
int rtp_type_stop();
|
|
|
|
|
|
|
|
int rtp_start(NodeCompat *n);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int rtp_stop(NodeCompat *n);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int rtp_netem_fds(NodeCompat *n, int fds[]);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int rtp_poll_fds(NodeCompat *n, int fds[]);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int rtp_read(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int rtp_write(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2018-11-16 16:07:47 +01:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|