2 * Copyright (C) 2005-2010 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file send.h Sender-related defines and structures. */
9 /** The sender subcommands. */
10 enum {SENDER_ADD
, SENDER_DELETE
, SENDER_ALLOW
, SENDER_DENY
, SENDER_ON
, SENDER_OFF
, NUM_SENDER_CMDS
};
13 * Each paraslash sender may register arbitrary many clients to the virtual
14 * streaming system, possibly with varying fec parameters. In order to do so,
15 * it must allocate a \a fec_client_parms structure and pass it to \ref
18 * Clients are automatically removed from that list by the vss if an error
19 * occurs, or if the sender requests deletion of a client by calling \ref
20 * vss_del_fec_client().
25 /** FEC parameters requested by FEC clients. */
26 struct fec_client_parms
{
27 /** Number of data slices plus redundant slices. */
28 uint8_t slices_per_group
;
29 /** Number of slices minus number of redundant slices. */
30 uint8_t data_slices_per_group
;
31 /** Maximal number of bytes per slice, initially zero. */
32 uint16_t max_slice_bytes
;
34 * Transport-layer initialisation for FEC support.
36 * This optional function serves (a) to make the transport layer
37 * ready to send FEC slices and (b) to determine the Maximum
38 * Packet Size (MPS) supported by the connection. The MPS value
39 * determines the largest payload size. This value is used to
40 * send FEC slices that are not larger than the path MTU, to avoid
41 * fragmentation and to maximize packet utilization. The user can
42 * alternatively specify a slice size of up to this value.
44 int (*init_fec
)(struct sender_client
*sc
);
45 /** Push out FEC-encoded packets */
46 int (*send_fec
)(struct sender_client
*sc
, char *buf
, size_t len
);
50 * Describes one supported sender of para_server.
52 * \sa http_send.c udp_send.c, dccp_send.c.
55 /** The name of the sender. */
58 * The init function of this sender.
60 * It must fill in all function pointers of \a s as well as the \a
61 * client_cmds array, see below. It should also do all necessary
62 * preparations to init this sending facility, for example it could
65 void (*init
)(struct sender
*s
);
67 * Return the help text of this sender.
69 * The result must be dynamically allocated and is freed by the caller.
73 * Return current status info about this sender.
75 * The result must be dynamically allocated and is freed by the caller.
81 * It gets called whenever para_server is playing and the current
82 * audio format handler indicates that another chunk of data should
83 * be sent now. The two parameters \a current_chunk and \a chunks_sent
84 * only differ if the stream was repositioned by the \a ff or \a jmp
85 * command. Of course, \a buf is a pointer to the chunk of data which
86 * should be sent, and \a len is the length of this buffer.
88 void (*send
)(long unsigned current_chunk
, long unsigned chunks_sent
,
89 const char *buf
, size_t len
, const char *header_buf
,
93 * Obtain the FEC parameters of a FEC client.
95 * This is called once by vss.c at the beginning of a stream. Senders
96 * are supposed to set \a fcp to a struct which is suitable for the FEC
97 * client identified by \a private_data.
99 int (*open
)(void *client
, struct fec_client_parms
**fcp
);
101 * Send the next slice to a FEC client.
103 * Called by vss.c when the next slice should be sent to the FEC client
104 * identified by \a private_data, the pointer which was previously
105 * passed to vss_add_fec_target().
107 int (*send_fec
)(char *buf
, size_t num_bytes
, void *private_data
);
109 * Add file descriptors to fd_sets.
111 * The pre_select function of each supported sender is called just before
112 * para_server enters its main select loop. Each sender may add its own
113 * file descriptors to the \a rfds or the \a wfds set.
115 * If a file descriptor was added, \a max_fileno must be increased by
116 * this function, if necessary.
120 void (*pre_select
)(int *max_fileno
, fd_set
*rfds
, fd_set
*wfds
);
122 * Handle the file descriptors which are ready for I/O.
124 * If the pre_select hook added one ore more file descriptors to the
125 * read or write set, this is the hook to check the result and do any
126 * I/O on those descriptors which are ready for reading/writing.
128 void (*post_select
)(fd_set
*rfds
, fd_set
*wfds
);
130 * Terminate all connected clients.
132 * This is called e.g. if the stop command was executed. It should make
133 * the clients aware of the end-of-file condition.
135 void (*shutdown_clients
)(void);
137 * Array of function pointers for the sender subcommands.
139 * Each sender may implement any subset of the sender commands by
140 * filling in the appropriate function pointer in the array. A \p NULL
141 * pointer means this command is not implemented by this sender.
143 int (*client_cmds
[NUM_SENDER_CMDS
])(struct sender_command_data
*);
146 /** Describes one client, connected to a paraslash sender. */
147 struct sender_client
{
148 /** The file descriptor of the client. */
150 /** The socket "name" of the client. */
152 /** The position of this client in the client list. */
153 struct list_head node
;
154 /** Non-zero if audio file header has been sent. */
156 /** The list of pending chunks for this client. */
157 struct chunk_queue
*cq
;
158 /** Data specific to the particular sender. */
162 /** Describes the current status of one paraslash sender. */
163 struct sender_status
{
164 /** The file descriptor of the socket this sender is listening on. */
166 /** The TCP/DCCP port used by this sender. */
168 /** The current number of simultaneous connections. */
170 /** The maximal number of simultaneous connections. */
172 /** Whether the access control list is a whitelist. */
174 /** The whitelist/blacklist. */
175 struct list_head acl
;
176 /** The list of connected clients. */
177 struct list_head client_list
;
180 void shutdown_client(struct sender_client
*sc
, struct sender_status
*ss
);
181 void shutdown_clients(struct sender_status
*ss
);
182 void send_chunk(struct sender_client
*sc
, struct sender_status
*ss
,
183 size_t max_bytes_per_write
, long unsigned current_chunk
,
184 const char *buf
, size_t len
, const char *header_buf
,
186 void init_sender_status(struct sender_status
*ss
, char **access_arg
, int num_access_args
,
187 int port
, int max_clients
, int default_deny
);
188 char *get_sender_info(struct sender_status
*ss
, const char *name
);
190 void generic_com_allow(struct sender_command_data
*scd
,
191 struct sender_status
*ss
);
192 void generic_com_deny(struct sender_command_data
*scd
,
193 struct sender_status
*ss
);
194 int generic_com_on(struct sender_status
*ss
, unsigned protocol
);
195 void generic_com_off(struct sender_status
*ss
);
196 char *generic_sender_help(void);
197 struct sender_client
*accept_sender_client(struct sender_status
*ss
, fd_set
*rfds
);
198 int send_queued_chunks(int fd
, struct chunk_queue
*cq
,
199 size_t max_bytes_per_write
);
200 int parse_fec_url(const char *arg
, struct sender_command_data
*scd
);