1 /* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file send.h Sender-related defines and structures. */
5 #define SENDER_SUBCOMMANDS \
6 SENDER_SUBCOMMAND(add) /**< Add a target (udp only). */ \
7 SENDER_SUBCOMMAND(delete) /**< Delete a target (udp only). */ \
8 SENDER_SUBCOMMAND(allow) /**< Allow connections from given IP address(es). */ \
9 SENDER_SUBCOMMAND(deny) /**< Deny connections from given IP address(es). */ \
10 SENDER_SUBCOMMAND(on) /**< Activate the sender. */ \
11 SENDER_SUBCOMMAND(off) /**< Deactivate the sender. */ \
13 #define SENDER_SUBCOMMAND(_name) SENDER_ ## _name,
14 enum sender_subcommand {
16 NUM_SENDER_CMDS /**< Used as array size in struct \ref sender. */
18 #undef SENDER_SUBCOMMAND
19 #define SENDER_SUBCOMMAND(_name) #_name,
22 * Describes one supported sender of para_server.
24 * \sa \ref http_send.c \ref udp_send.c, \ref dccp_send.c.
27 /** The name of the sender. */
30 * The init function of this sender.
32 * It must fill in all function pointers of \a s as well as the \a
33 * client_cmds array, see below. It should also do all necessary
34 * preparations to init this sending facility, for example it could
37 void (*init)(struct sender *s);
39 * Return the help text of this sender.
41 * The result must be dynamically allocated and is freed by the caller.
45 * Return current status info about this sender.
47 * The result must be dynamically allocated and is freed by the caller.
49 char* (*status)(void);
53 * It gets called whenever para_server is playing and the current
54 * audio format handler indicates that another chunk of data should
55 * be sent now. The two parameters \a current_chunk and \a chunks_sent
56 * only differ if the stream was repositioned by the \a ff or \a jmp
57 * command. Of course, \a buf is a pointer to the chunk of data which
58 * should be sent, and \a len is the length of this buffer.
60 void (*send)(long unsigned current_chunk, long unsigned chunks_sent,
61 const char *buf, size_t len, const char *header_buf,
64 * Add file descriptors to fd_sets.
66 * The pre_select function of each supported sender is called just before
67 * para_server enters its main select loop. Each sender may add its own
68 * file descriptors to the \a rfds or the \a wfds set.
70 * If a file descriptor was added, \a max_fileno must be increased by
71 * this function, if necessary.
75 void (*pre_select)(int *max_fileno, fd_set *rfds, fd_set *wfds);
77 * Handle the file descriptors which are ready for I/O.
79 * If the pre_select hook added one ore more file descriptors to the
80 * read or write set, this is the hook to check the result and do any
81 * I/O on those descriptors which are ready for reading/writing.
83 void (*post_select)(fd_set *rfds, fd_set *wfds);
85 * Terminate all connected clients.
87 * This is called e.g. if the stop command was executed. It should make
88 * the clients aware of the end-of-file condition.
90 void (*shutdown_clients)(void);
92 * Array of function pointers for the sender subcommands.
94 * Each sender may implement any subset of the sender commands by
95 * filling in the appropriate function pointer in the array. A \p NULL
96 * pointer means this command is not implemented by this sender.
98 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
100 * Resolve target-specific URL string
102 * This method must be defined if the sender supports the add/delete
103 * subcommands. It interprets a string specifying a target URL in a
104 * sender-specific fashion (e.g. embedded FEC string). It can also
105 * fill in sender-specific defaults if necessary.
107 int (*resolve_target)(const char *, struct sender_command_data *);
110 /** Describes one client, connected to a paraslash sender. */
111 struct sender_client {
112 /** The file descriptor of the client. */
114 /** The socket "name" of the client. */
116 /** The position of this client in the client list. */
117 struct list_head node;
118 /** Non-zero if audio file header has been sent. */
120 /** The list of pending chunks for this client. */
121 struct chunk_queue *cq;
122 /** Data specific to the particular sender. */
127 * Each paraslash sender may register arbitrary many clients to the virtual
128 * streaming system, possibly with varying fec parameters. In order to do so,
129 * it must allocate a \a fec_client_parms structure and pass it to \ref
130 * vss_add_fec_client.
132 * Clients are automatically removed from that list by the vss if an error
133 * occurs, or if the sender requests deletion of a client by calling \ref
134 * vss_del_fec_client().
137 /** FEC parameters requested by FEC clients. */
138 struct fec_client_parms {
139 /** Number of data slices plus redundant slices. */
140 uint8_t slices_per_group;
141 /** Number of slices minus number of redundant slices. */
142 uint8_t data_slices_per_group;
143 /** Whether the header must be sent periodically. */
144 bool need_periodic_header;
146 * Transport-layer initialisation for FEC support.
148 * This optional function serves (a) to make the transport layer
149 * ready to send FEC slices and (b) to determine the Maximum
150 * Packet Size (MPS) supported by the connection. The MPS value
151 * determines the largest payload size. This value is used to
152 * send FEC slices that are not larger than the path MTU, to avoid
153 * fragmentation and to maximize packet utilization. The user can
154 * alternatively specify a slice size of up to this value.
156 int (*init_fec)(struct sender_client *sc);
157 /** Push out FEC-encoded packets */
158 void (*send_fec)(struct sender_client *sc, char *buf, size_t len);
161 /** Describes the current status of one paraslash sender. */
162 struct sender_status {
163 /** Number of sockets to listen on, size of the two arrays below. */
164 unsigned num_listen_fds;
165 /** Derived from --http-listen-address and --dccp-listen-address. */
166 char **listen_addresses;
167 /** Default TCP/DCCP port number for addresses w/o port. */
169 /** The socket fd(s) this sender is listening on. */
171 /** The current number of simultaneous connections. */
173 /** The maximal number of simultaneous connections. */
175 /** Whether the access control list is a whitelist. */
177 /** The whitelist/blacklist. */
178 struct list_head acl;
179 /** The list of connected clients. */
180 struct list_head client_list;
183 /** Iterate over all listening addresses of the http/dccp sender. */
184 #define FOR_EACH_LISTEN_FD(_n, _ss) for (_n = 0; _n < (_ss)->num_listen_fds; _n++)
186 void shutdown_client(struct sender_client *sc, struct sender_status *ss);
187 void shutdown_clients(struct sender_status *ss);
188 void init_sender_status(struct sender_status *ss,
189 const struct lls_opt_result *acl_opt_result,
190 const struct lls_opt_result *listen_address_opt_result,
191 int default_port, int max_clients, int default_deny);
192 char *generic_sender_status(struct sender_status *ss, const char *name);
193 void generic_com_allow(struct sender_command_data *scd,
194 struct sender_status *ss);
195 void generic_com_deny(struct sender_command_data *scd,
196 struct sender_status *ss);
197 void generic_com_on(struct sender_status *ss, unsigned protocol);
198 void generic_com_off(struct sender_status *ss);
199 char *generic_sender_help(void);
200 struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds);
201 int send_queued_chunks(int fd, struct chunk_queue *cq);
202 int parse_fec_url(const char *arg, struct sender_command_data *scd);