summaryrefslogtreecommitdiff
path: root/recv.h
blob: 278deb1bd4526e54606ef7f348f284fa451fc784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* SPDX-License-Identifier: GPL-2.0 */

/** \file recv.h Receiver API
 *
 * Receivers are part of para_audiod(1), para_recv(1) and para_play(1). Each
 * receiver is implemented in a separate file which defines a non-static a \ref
 * receiver structure. An instance of the receiver, a \ref receiver_node,
 * is created by calling \ref receiver::open. The receiver node is set
 * up by making it the root of a buffer tree and registering it to the
 * scheduler. Once scheduling is started the receiver node performs I/O as
 * long as there is input available and space left in the output buffer.
 *
 * The few functions declared here are defined in \ref recv_common.c.
 */

/**
 * Describes one instance of a receiver.
 */
struct receiver_node {
	/** Points to the corresponding receiver. */
	const struct receiver *receiver;
	/** Receiver-specific data. */
	void *private_data;
	/** The parsed command line options for this instance. */
	struct lls_parse_result *lpr;
	/** The task associated with this instance. */
	struct task *task;
	/** The receiver node is always the root of the buffer tree. */
	struct btr_node *btrn;
	/** Each receiver node maintains a buffer pool for the received data. */
	struct btr_pool *btrp;
	/**
	 * The file descriptor to receive the stream.
	 *
	 * The pre_monitor function of the receiver adds this file descriptor to
	 * the set of file descriptors which are watched for readability or
	 * writability, depending on the state of the connection (if any).
	 *
	 * If the file descriptor is readable, the post_monitor function of the
	 * receiver reads data from this descriptor into the buffer pool area.
	 *
	 * \sa \ref receiver.
	 */
	int fd;
};

/**
 * Describes a possible data source for audio streams.
 *
 * A paraslash receiver is a modular piece of software which is capable of
 * receiving an audio data stream from a data source. Received audio data is
 * fed to consumers through the buffer tree mechanism.
 *
 * This structure contains the methods which have to be implemented by each
 * receiver.
 *
 * \sa \ref http_recv.c, \ref udp_recv.c, \ref afh_recv.c, struct \ref
 * receiver_node, struct \ref filter, struct \ref writer.
 */
struct receiver {
	/**
	 * Open one instance of the receiver.
	 *
	 * This should allocate the output buffer of the given receiver node
	 * and prepare it for retrieving the audio stream according to the
	 * configuration stored in rn->lpr.
	 */
	int (*open)(struct receiver_node *rn);
	/**
	 * Close this instance of the receiver.
	 *
	 * It should free all resources associated with given receiver node
	 * that were allocated during the corresponding open call.
	 *
	 * \sa \ref receiver_node.
	 */
	void (*close)(struct receiver_node *rn);
	/** Ask the scheduler to monitor receive fds. */
	void (*pre_monitor)(struct sched *s, void *context);
	/** Receive data and make it available to consumers. */
	int (*post_monitor)(struct sched *s, void *context);
	/**
	 * Answer a buffer tree query.
	 *
	 * This optional function pointer allows for inter node communication
	 * of the buffer tree nodes. See \ref btr_command_handler for details.
	 */
	btr_command_handler execute;
};

/** \cond doxygen_ignore */
#define RECV_CMD(_num) (lls_cmd(_num, recv_cmd_suite))

#define RECV_CMD_OPT_RESULT(_recv, _opt, _lpr) \
	(lls_opt_result(LSG_RECV_CMD_ ## _recv ## _OPT_ ## _opt, _lpr))
#define RECV_CMD_OPT_GIVEN(_recv, _opt, _lpr) \
	(lls_opt_given(RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
#define RECV_CMD_OPT_STRING_VAL(_recv, _opt, _lpr) \
	(lls_string_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
#define RECV_CMD_OPT_UINT32_VAL(_recv, _opt, _lpr) \
	(lls_uint32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
#define RECV_CMD_OPT_INT32_VAL(_recv, _opt, _lpr) \
	(lls_int32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
/** \endcond */

int check_receiver_arg(const char *ra, struct lls_parse_result **lprp);
void print_receiver_helps(bool detailed);
int generic_recv_pre_monitor(struct sched *s, struct receiver_node *rn);