summaryrefslogtreecommitdiff
path: root/write.h
blob: be5f7454532c77899af4957668d0c809bff96668 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
 *
 * Licensed under the GPL v2. For licencing details see COPYING.
 */

/** \file write.h writer-related structures */

/** the list of supported writers */
enum writer_enum {WRITER_ENUM};

/**
 * decbribes one running instance of a writer
 */
struct writer_node {
	/** points to the writer structure associated with this node */
	struct writer *writer; /* FIXME: Should better be only the number */
	/** writer-specific data */
	void *private_data;
	/** send that many bytes in one go */
	int chunk_bytes;
	/** pointer to the group this node belongs to */
	struct writer_node_group *wng;
	/** the writer-specific configuration of this node */
	void *conf;
	/** how much of the wng's buffer is already written */
	size_t written;
};

/** describes one supported writer */
struct writer {
	/**
	 * the init function of the writer
	 *
	 * It must fill in all other function pointers of the given
	 * writer structure.
	 *
	 */
	void (*init)(struct writer *w);
	/**
	 *
	 *
	 * the command line parser of the writer
	 *
	 * It should check whether the command line options given by \a options are
	 * valid.  On success, it should return a pointer to the writer-specific
	 * configuration data determined by \a options.  Note that this might be called
	 * more than once with different values of \a options.
	 *
	 */
		void * (*parse_config)(const char *options);
	/**
	 *
	 * open one instance of this writer
	 *
	 * This function should perform any work necessary to write the incoming
	 * stream. If To this aim, it may allocate its private data structure and store
	 * a pointer to that structure via the given writer_node paramenter.
	 */
	int (*open)(struct writer_node *);
	/**
	 *
	 * write a chunk of audio data
	 *
	 * This is called from the writer node group task's pre_select(). It
	 * may use the sched pointer to add any file descriptors or to decrease
	 * the select timeout. It must return positive on success and negative
	 * on errors.
	 */
	int (*pre_select)(struct sched *s, struct writer_node *wn);
	/**
	 * Called from the post_select function of the wng task. It must keep
	 * track of the the number of bytes consumed from the wng's buffer via
	 * the wn->written variable (which may be modified by the wng handling
	 * functions). This function must return positive on success and
	 * negative on errors.
	 */
	int (*post_select)(struct sched *s, struct writer_node *wn);
	/**
	 * close one instance of the writer
	 *
	 * This function is assumed to succeed.
	 */
	void (*close)(struct writer_node *);
	/**
	 * shutdown the writer
	 *
	 * This is a optional function pointer used for cleaning
	 * up.
	 */
	void (*shutdown)(struct writer_node *);
};

/**
 * describes a set of writer nodes that all write the same stream.
 */
struct writer_node_group {
	/** number of nodes belonging to this group */
	unsigned num_writers;
	/** array of pointers to the corresponding writer nodes */
	struct writer_node *writer_nodes;
	/** the maximum of the chunk_bytes values of the writer nodes in this group */
	size_t max_chunk_bytes;
	/** non-zero if end of file was encountered by the feeding task */
	int *input_eof;
	/** non-zero if end of file was encountered */
	int eof;
	/** current output buffer */
	char *buf;
	/** number of bytes loaded in the output buffer */
	size_t *loaded;
	/** number of audio channels of the current stream */
	unsigned int *channels;
	/** sample rate of the current stream */
	unsigned int *samplerate;
	/** the task associated to this group */
	struct task task;
};

/** loop over each writer node in a writer group */
#define FOR_EACH_WRITER_NODE(i, wng) for (i = 0; i < (wng)->num_writers; i++)
/** loop over each supported writer */
#define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)

/** declare the init functions of all supported writers */
DECLARE_WRITER_INITS;

/** array containing the name of each writer */
extern const char *writer_names[];

/** the writer structure for each supported writer */
extern struct writer writers[NUM_SUPPORTED_WRITERS];