Merge topic branch t/ff-compat into master
[paraslash.git] / recv.h
1 /* Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
2
3 /** \file recv.h Receiver-related structures and exported symbols of recv_common.c. */
4
5 /**
6 * Describes one instance of a receiver.
7 */
8 struct receiver_node {
9 /** Points to the corresponding receiver. */
10 const struct receiver *receiver;
11 /** Receiver-specific data. */
12 void *private_data;
13 /** The parsed command line options for this instance. */
14 struct lls_parse_result *lpr;
15 /** The task associated with this instance. */
16 struct task *task;
17 /** The receiver node is always the root of the buffer tree. */
18 struct btr_node *btrn;
19 /** Each receiver node maintains a buffer pool for the received data. */
20 struct btr_pool *btrp;
21 /**
22 * The file descriptor to receive the stream.
23 *
24 * The pre_monitor function of the receiver adds this file descriptor to
25 * the set of file descriptors which are watched for readability or
26 * writability, depending on the state of the connection (if any).
27 *
28 * If \a fd is readable, the post_monitor function of the receiver reads
29 * data from this fd into the buffer pool area of \a btrp.
30 *
31 * \sa \ref receiver.
32 */
33 int fd;
34 };
35
36 /**
37 * Describes a possible data source for audio streams.
38 *
39 * A paraslash receiver is a modular piece of software which is capable of
40 * receiving an audio data stream from a data source. Received audio data is
41 * fed to consumers through the buffer tree mechanism.
42 *
43 * This structure contains the methods which have to be implemented by each
44 * receiver.
45 *
46 * \sa \ref http_recv.c, \ref udp_recv.c, \ref dccp_recv.c, \ref afh_recv.c,
47 * struct \ref receiver_node, struct \ref filter, struct \ref writer, struct
48 * \ref sched.
49 */
50 struct receiver {
51 /**
52 * Open one instance of the receiver.
53 *
54 * This should allocate the output buffer of the given receiver node
55 * and prepare it for retrieving the audio stream according to the
56 * configuration stored in rn->lpr.
57 */
58 int (*open)(struct receiver_node *rn);
59 /**
60 * Close this instance of the receiver.
61 *
62 * It should free all resources associated with given receiver node
63 * that were allocated during the corresponding open call.
64 *
65 * \sa \ref receiver_node.
66 */
67 void (*close)(struct receiver_node *rn);
68 /** Ask the scheduler to monitor receive fds. */
69 void (*pre_monitor)(struct sched *s, void *context);
70 /** Receive data and make it available to consumers. */
71 int (*post_monitor)(struct sched *s, void *context);
72 /**
73 * Answer a buffer tree query.
74 *
75 * This optional function pointer allows for inter node communication
76 * of the buffer tree nodes. See \ref btr_command_handler for details.
77 */
78 btr_command_handler execute;
79 };
80
81 #define RECV_CMD(_num) (lls_cmd(_num, recv_cmd_suite))
82
83 #define RECV_CMD_OPT_RESULT(_recv, _opt, _lpr) \
84 (lls_opt_result(LSG_RECV_CMD_ ## _recv ## _OPT_ ## _opt, _lpr))
85 #define RECV_CMD_OPT_GIVEN(_recv, _opt, _lpr) \
86 (lls_opt_given(RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
87 #define RECV_CMD_OPT_STRING_VAL(_recv, _opt, _lpr) \
88 (lls_string_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
89 #define RECV_CMD_OPT_UINT32_VAL(_recv, _opt, _lpr) \
90 (lls_uint32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
91 #define RECV_CMD_OPT_INT32_VAL(_recv, _opt, _lpr) \
92 (lls_int32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
93
94 /** Iterate over all available receivers. */
95 #define FOR_EACH_RECEIVER(i) for (i = 1; lls_cmd(i, recv_cmd_suite); i++)
96
97 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp);
98 void print_receiver_helps(bool detailed);
99 int generic_recv_pre_monitor(struct sched *s, struct receiver_node *rn);