2 * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file send.h Sender-related defines and structures. */
9 #define SENDER_SUBCOMMANDS \
10 SENDER_SUBCOMMAND(add) /**< Add a target (udp only). */ \
11 SENDER_SUBCOMMAND(delete) /**< Delete a target (udp only). */ \
12 SENDER_SUBCOMMAND(allow) /**< Allow connections from given IP address(es). */ \
13 SENDER_SUBCOMMAND(deny) /**< Deny connections from given IP address(es). */ \
14 SENDER_SUBCOMMAND(on) /**< Activate the sender. */ \
15 SENDER_SUBCOMMAND(off) /**< Deactivate the sender. */ \
17 #define SENDER_SUBCOMMAND(_name) SENDER_ ## _name,
18 enum sender_subcommand {
20 NUM_SENDER_CMDS /**< Used as array size in struct \ref sender. */
22 #undef SENDER_SUBCOMMAND
23 #define SENDER_SUBCOMMAND(_name) #_name,
26 * Describes one supported sender of para_server.
28 * \sa http_send.c udp_send.c, dccp_send.c.
31 /** The name of the sender. */
34 * The init function of this sender.
36 * It must fill in all function pointers of \a s as well as the \a
37 * client_cmds array, see below. It should also do all necessary
38 * preparations to init this sending facility, for example it could
41 void (*init)(struct sender *s);
43 * Return the help text of this sender.
45 * The result must be dynamically allocated and is freed by the caller.
49 * Return current status info about this sender.
51 * The result must be dynamically allocated and is freed by the caller.
53 char* (*status)(void);
57 * It gets called whenever para_server is playing and the current
58 * audio format handler indicates that another chunk of data should
59 * be sent now. The two parameters \a current_chunk and \a chunks_sent
60 * only differ if the stream was repositioned by the \a ff or \a jmp
61 * command. Of course, \a buf is a pointer to the chunk of data which
62 * should be sent, and \a len is the length of this buffer.
64 void (*send)(long unsigned current_chunk, long unsigned chunks_sent,
65 const char *buf, size_t len, const char *header_buf,
68 * Add file descriptors to fd_sets.
70 * The pre_select function of each supported sender is called just before
71 * para_server enters its main select loop. Each sender may add its own
72 * file descriptors to the \a rfds or the \a wfds set.
74 * If a file descriptor was added, \a max_fileno must be increased by
75 * this function, if necessary.
79 void (*pre_select)(int *max_fileno, fd_set *rfds, fd_set *wfds);
81 * Handle the file descriptors which are ready for I/O.
83 * If the pre_select hook added one ore more file descriptors to the
84 * read or write set, this is the hook to check the result and do any
85 * I/O on those descriptors which are ready for reading/writing.
87 void (*post_select)(fd_set *rfds, fd_set *wfds);
89 * Terminate all connected clients.
91 * This is called e.g. if the stop command was executed. It should make
92 * the clients aware of the end-of-file condition.
94 void (*shutdown_clients)(void);
96 * Array of function pointers for the sender subcommands.
98 * Each sender may implement any subset of the sender commands by
99 * filling in the appropriate function pointer in the array. A \p NULL
100 * pointer means this command is not implemented by this sender.
102 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
104 * Resolve target-specific URL string
106 * This method must be defined if the sender supports the add/delete
107 * subcommands. It interprets a string specifying a target URL in a
108 * sender-specific fashion (e.g. embedded FEC string). It can also
109 * fill in sender-specific defaults if necessary.
111 int (*resolve_target)(const char *, struct sender_command_data *);
114 /** Describes one client, connected to a paraslash sender. */
115 struct sender_client {
116 /** The file descriptor of the client. */
118 /** The socket "name" of the client. */
120 /** The position of this client in the client list. */
121 struct list_head node;
122 /** Non-zero if audio file header has been sent. */
124 /** The list of pending chunks for this client. */
125 struct chunk_queue *cq;
126 /** Data specific to the particular sender. */
131 * Each paraslash sender may register arbitrary many clients to the virtual
132 * streaming system, possibly with varying fec parameters. In order to do so,
133 * it must allocate a \a fec_client_parms structure and pass it to \ref
134 * vss_add_fec_client.
136 * Clients are automatically removed from that list by the vss if an error
137 * occurs, or if the sender requests deletion of a client by calling \ref
138 * vss_del_fec_client().
141 /** FEC parameters requested by FEC clients. */
142 struct fec_client_parms {
143 /** Number of data slices plus redundant slices. */
144 uint8_t slices_per_group;
145 /** Number of slices minus number of redundant slices. */
146 uint8_t data_slices_per_group;
147 /** Whether the header must be sent periodically. */
148 bool need_periodic_header;
150 * Transport-layer initialisation for FEC support.
152 * This optional function serves (a) to make the transport layer
153 * ready to send FEC slices and (b) to determine the Maximum
154 * Packet Size (MPS) supported by the connection. The MPS value
155 * determines the largest payload size. This value is used to
156 * send FEC slices that are not larger than the path MTU, to avoid
157 * fragmentation and to maximize packet utilization. The user can
158 * alternatively specify a slice size of up to this value.
160 int (*init_fec)(struct sender_client *sc);
161 /** Push out FEC-encoded packets */
162 void (*send_fec)(struct sender_client *sc, char *buf, size_t len);
165 /** Describes the current status of one paraslash sender. */
166 struct sender_status {
167 /** The file descriptor of the socket this sender is listening on. */
169 /** The TCP/DCCP port used by this sender. */
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 void shutdown_client(struct sender_client *sc, struct sender_status *ss);
184 void shutdown_clients(struct sender_status *ss);
185 void init_sender_status(struct sender_status *ss,
186 const struct lls_opt_result *acl_opt_result, int port,
187 int max_clients, int default_deny);
188 char *generic_sender_status(struct sender_status *ss, const char *name);
189 void generic_com_allow(struct sender_command_data *scd,
190 struct sender_status *ss);
191 void generic_com_deny(struct sender_command_data *scd,
192 struct sender_status *ss);
193 int generic_com_on(struct sender_status *ss, unsigned protocol);
194 void generic_com_off(struct sender_status *ss);
195 char *generic_sender_help(void);
196 struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds);
197 int send_queued_chunks(int fd, struct chunk_queue *cq);
198 int parse_fec_url(const char *arg, struct sender_command_data *scd);