extern int mmd_mutex;
extern struct misc_meta_data *mmd;
-extern struct sender senders[];
int send_afs_status(struct command_context *cc, int parser_friendly);
static void dummy(__a_unused int s)
return ret;
}
arg = lls_input(0, lpr);
- for (i = 0; senders[i].name; i++)
- if (!strcmp(senders[i].name, arg))
+ FOR_EACH_SENDER(i)
+ if (strcmp(senders[i]->name, arg) == 0)
break;
- if (!senders[i].name)
+ if (!senders[i])
return -E_COMMAND_SYNTAX;
scd->sender_num = i;
arg = lls_input(1, lpr);
if (i == NUM_SENDER_CMDS)
return -E_COMMAND_SYNTAX;
scd->cmd_num = i;
- if (!senders[scd->sender_num].client_cmds[scd->cmd_num])
+ if (!senders[scd->sender_num]->client_cmds[scd->cmd_num])
return -E_SENDER_CMD;
switch (scd->cmd_num) {
case SENDER_on:
struct sender_command_data scd;
if (lls_num_inputs(lpr) == 0) {
- for (i = 0; senders[i].name; i++) {
+ FOR_EACH_SENDER(i) {
char *tmp;
ret = xasprintf(&tmp, "%s%s\n", msg? msg : "",
- senders[i].name);
+ senders[i]->name);
free(msg);
msg = tmp;
}
if (scd.sender_num < 0)
return ret;
if (strcmp(lls_input(1, lpr), "status") == 0)
- msg = senders[scd.sender_num].status();
+ msg = senders[scd.sender_num]->status();
else
- msg = senders[scd.sender_num].help();
+ msg = senders[scd.sender_num]->help();
return send_sb(&cc->scc, msg, strlen(msg), SBD_OUTPUT, false);
}
switch (scd.cmd_num) {
case SENDER_add:
case SENDER_delete:
- assert(senders[scd.sender_num].resolve_target);
- ret = senders[scd.sender_num].resolve_target(lls_input(2, lpr),
+ assert(senders[scd.sender_num]->resolve_target);
+ ret = senders[scd.sender_num]->resolve_target(lls_input(2, lpr),
&scd);
if (ret < 0)
return ret;
return result;
}
-/**
- * The init function of the dccp sender.
- *
- * \param s pointer to the dccp sender struct.
- *
- * It initializes all function pointers of \a s and starts
- * listening on the given port.
+/*
+ * Initialize the client list and the access control list and listen on the
+ * dccp port.
*/
-void dccp_send_init(struct sender *s)
+static void dccp_send_init(void)
{
int ret;
- s->status = dccp_status;
- s->send = NULL;
- s->pre_select = dccp_pre_select;
- s->post_select = dccp_post_select;
- s->shutdown_clients = dccp_shutdown_clients;
- s->resolve_target = NULL;
- s->help = generic_sender_help;
- s->client_cmds[SENDER_on] = dccp_com_on;
- s->client_cmds[SENDER_off] = dccp_com_off;
- s->client_cmds[SENDER_deny] = dccp_com_deny;
- s->client_cmds[SENDER_allow] = dccp_com_allow;
- s->client_cmds[SENDER_add] = NULL;
- s->client_cmds[SENDER_delete] = NULL;
-
init_sender_status(dss, OPT_RESULT(DCCP_ACCESS),
OPT_UINT32_VAL(DCCP_PORT), OPT_UINT32_VAL(DCCP_MAX_CLIENTS),
OPT_GIVEN(DCCP_DEFAULT_DENY));
if (ret < 0)
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
}
+
+/**
+ * The DCCP sender.
+ *
+ * This sender offers congestion control not available in plain TCP. Most
+ * methods of the sender structure are implemented as simple wrappers for the
+ * generic functions defined in \ref send_common.c. Like UDP streams, DCCP
+ * streams are sent FEC-encoded.
+ */
+const struct sender dccp_sender = {
+ .name = "dccp",
+ .init = dccp_send_init,
+ .pre_select = dccp_pre_select,
+ .post_select = dccp_post_select,
+ .shutdown_clients = dccp_shutdown_clients,
+ .client_cmds = {
+ [SENDER_on] = dccp_com_on,
+ [SENDER_off] = dccp_com_off,
+ [SENDER_deny] = dccp_com_deny,
+ [SENDER_allow] = dccp_com_allow,
+ },
+ .help = generic_sender_help,
+ .status = dccp_status,
+};
return generic_sender_status(hss, "http");
}
-/**
- * The init function of the http sender.
- *
- * \param s Pointer to the http sender struct.
- *
- * It initializes all function pointers of \a s, the client list and the access
- * control list. If the autostart option was given, the tcp port is opened.
+/*
+ * Initialize the client list and the access control list, and optionally
+ * listen on the tcp port.
*/
-void http_send_init(struct sender *s)
+static void http_send_init(void)
{
int ret;
- s->status = http_status;
- s->send = http_send;
- s->pre_select = http_pre_select;
- s->post_select = http_post_select;
- s->shutdown_clients = http_shutdown_clients;
- s->resolve_target = NULL;
- s->help = generic_sender_help;
- s->client_cmds[SENDER_on] = http_com_on;
- s->client_cmds[SENDER_off] = http_com_off;
- s->client_cmds[SENDER_deny] = http_com_deny;
- s->client_cmds[SENDER_allow] = http_com_allow;
- s->client_cmds[SENDER_add] = NULL;
- s->client_cmds[SENDER_delete] = NULL;
init_sender_status(hss, OPT_RESULT(HTTP_ACCESS),
OPT_UINT32_VAL(HTTP_PORT), OPT_UINT32_VAL(HTTP_MAX_CLIENTS),
if (ret < 0)
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
}
+
+/**
+ * The HTTP sender.
+ *
+ * This is the only sender which does not FEC-encode the stream. This is not
+ * necessary because HTTP sits on top of TCP, a reliable transport which
+ * retransmits lost packets automatically. The sender employs per-client queues
+ * which queue chunks of audio data if they can not be sent immediately because
+ * the write operation would block. Most methods of the sender are implemented
+ * as wrappers for the generic functions defined in \ref send_common.c.
+ */
+const struct sender http_sender = {
+ .name = "http",
+ .init = http_send_init,
+ .pre_select = http_pre_select,
+ .post_select = http_post_select,
+ .send = http_send,
+ .shutdown_clients = http_shutdown_clients,
+ .client_cmds = {
+ [SENDER_on] = http_com_on,
+ [SENDER_off] = http_com_off,
+ [SENDER_deny] = http_com_deny,
+ [SENDER_allow] = http_com_allow,
+ },
+ .help = generic_sender_help,
+ .status = http_status,
+};
/** The name of the sender. */
const char *name;
/**
- * The init function of this sender.
- *
- * It must fill in all function pointers of \a s as well as the \a
- * client_cmds array, see below. It should also do all necessary
- * preparations to init this sending facility, for example it could
- * open a tcp port.
+ * Parse the command line options and initialize this sender (e.g.,
+ * initialize target or access control lists, listen on a network
+ * socket, etc.).
*/
- void (*init)(struct sender *s);
+ void (*init)(void);
/**
* Return the help text of this sender.
*
int (*resolve_target)(const char *, struct sender_command_data *);
};
+/** NULL-terminated list, defined in \ref vss.c. */
+extern const struct sender * const senders[];
+/** Iterate over all senders. */
+#define FOR_EACH_SENDER(_i) for ((_i) = 0; senders[(_i)]; (_i)++)
+
/** Describes one client, connected to a paraslash sender. */
struct sender_client {
/** The file descriptor of the client. */
);
}
-/**
- * The init function of para_server's udp sender.
- *
- * \param s Pointer to the udp sender struct.
- *
- * It initializes all function pointers of \a s and the list of udp targets.
- */
-void udp_send_init(struct sender *s)
+/* Initialize the list of udp targets. */
+static void udp_send_init(void)
{
INIT_LIST_HEAD(&targets);
- s->status = udp_status;
- s->help = udp_help;
- s->send = NULL;
- s->pre_select = NULL;
- s->post_select = NULL;
- s->shutdown_clients = udp_shutdown_targets;
- s->resolve_target = udp_resolve_target;
- s->client_cmds[SENDER_on] = udp_com_on;
- s->client_cmds[SENDER_off] = udp_com_off;
- s->client_cmds[SENDER_deny] = NULL;
- s->client_cmds[SENDER_allow] = NULL;
- s->client_cmds[SENDER_add] = udp_com_add;
- s->client_cmds[SENDER_delete] = udp_com_delete;
sender_status = SENDER_off;
udp_init_target_list();
if (!OPT_GIVEN(UDP_NO_AUTOSTART))
sender_status = SENDER_on;
PARA_DEBUG_LOG("udp sender init complete\n");
}
+
+/**
+ * The UDP sender.
+ *
+ * In contrast to the other senders the UDP sender is active in the sense that
+ * it initiates the network connection according to its list of targets rather
+ * than passively waiting for clients to connect. Like DCCP streams, UDP
+ * streams are always sent FEC-encoded. The UDP sender is the only sender which
+ * supports IP multicasting.
+ */
+const struct sender udp_sender = {
+ .name = "udp",
+ .init = udp_send_init,
+ .shutdown_clients = udp_shutdown_targets,
+ .resolve_target = udp_resolve_target,
+ .client_cmds = {
+ [SENDER_on] = udp_com_on,
+ [SENDER_off] = udp_com_off,
+ [SENDER_add] = udp_com_add,
+ [SENDER_delete] = udp_com_delete,
+ },
+ .help = udp_help,
+ .status = udp_status,
+};
extern void http_send_init(struct sender *);
extern void udp_send_init(struct sender *);
-/** The list of supported senders. */
-struct sender senders[] = {
- {
- .name = "http",
- .init = http_send_init,
- },
- {
- .name = "dccp",
- .init = dccp_send_init,
- },
- {
- .name = "udp",
- .init = udp_send_init,
- },
- {
- .name = NULL,
- }
-};
+extern const struct sender udp_sender, dccp_sender, http_sender;
+const struct sender * const senders[] = {
+ &http_sender, &dccp_sender, &udp_sender, NULL};
/** The possible states of the afs socket. */
enum afs_socket_status {
vsst->afsss = AFS_SOCKET_CHECK_FOR_WRITE;
} else
para_fd_set(vsst->afs_socket, &s->rfds, &s->max_fileno);
- for (i = 0; senders[i].name; i++) {
- if (!senders[i].pre_select)
+ FOR_EACH_SENDER(i) {
+ if (!senders[i]->pre_select)
continue;
- senders[i].pre_select(&s->max_fileno, &s->rfds, &s->wfds);
+ senders[i]->pre_select(&s->max_fileno, &s->rfds, &s->wfds);
}
vss_compute_timeout(s, vsst);
}
* We call ->send() even if len is zero because senders might
* have data queued which can be sent now.
*/
- for (i = 0; senders[i].name; i++) {
- if (!senders[i].send)
+ FOR_EACH_SENDER(i) {
+ if (!senders[i]->send)
continue;
- senders[i].send(mmd->current_chunk, mmd->chunks_sent,
+ senders[i]->send(mmd->current_chunk, mmd->chunks_sent,
buf, len, vsst->header_buf, vsst->header_len);
}
}
if (!vsst->map || vss_next() || vss_paused() || vss_repos()) {
/* shut down senders and fec clients */
struct fec_client *fc, *tmp;
- for (i = 0; senders[i].name; i++)
- if (senders[i].shutdown_clients)
- senders[i].shutdown_clients();
+ FOR_EACH_SENDER(i)
+ if (senders[i]->shutdown_clients)
+ senders[i]->shutdown_clients();
list_for_each_entry_safe(fc, tmp, &fec_client_list, node)
fc->state = FEC_STATE_NONE;
mmd->stream_start.tv_sec = 0;
int num = mmd->sender_cmd_data.cmd_num,
sender_num = mmd->sender_cmd_data.sender_num;
- if (senders[sender_num].client_cmds[num]) {
- ret = senders[sender_num].client_cmds[num]
+ if (senders[sender_num]->client_cmds[num]) {
+ ret = senders[sender_num]->client_cmds[num]
(&mmd->sender_cmd_data);
if (ret < 0)
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
else
vsst->afsss = AFS_SOCKET_AFD_PENDING;
}
- for (i = 0; senders[i].name; i++) {
- if (!senders[i].post_select)
+ FOR_EACH_SENDER(i) {
+ if (!senders[i]->post_select)
continue;
- senders[i].post_select(&s->rfds, &s->wfds);
+ senders[i]->post_select(&s->rfds, &s->wfds);
}
if ((vss_playing() && !(mmd->vss_status_flags & VSS_PLAYING)) ||
(vss_next() && vss_playing()))
ms2tv(announce_time, &vsst->announce_tv);
PARA_INFO_LOG("announce timeval: %lums\n", tv2ms(&vsst->announce_tv));
INIT_LIST_HEAD(&fec_client_list);
- for (i = 0; senders[i].name; i++) {
- PARA_NOTICE_LOG("initializing %s sender\n", senders[i].name);
- senders[i].init(&senders[i]);
+ FOR_EACH_SENDER(i) {
+ PARA_NOTICE_LOG("initializing %s sender\n", senders[i]->name);
+ senders[i]->init();
}
mmd->sender_cmd_data.cmd_num = -1;
if (OPT_GIVEN(AUTOPLAY)) {