Move afh_init() call from vss.c to server.c.
[paraslash.git] / write.h
1 /*
2  * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file write.h writer-related structures */
8
9 /** the list of supported writers */
10 enum writer_enum {WRITER_ENUM};
11
12 /**
13  * decbribes one running instance of a writer
14  */
15 struct writer_node {
16         /** points to the writer structure associated with this node */
17         struct writer *writer; /* FIXME: Should better be only the number */
18         /** writer-specific data */
19         void *private_data;
20         /** send that many bytes in one go */
21         int chunk_bytes;
22         /** pointer to the group this node belongs to */
23         struct writer_node_group *wng;
24         /** the writer-specific configuration of this node */
25         void *conf;
26         /** how much of the wng's buffer is already written */
27         size_t written;
28 };
29
30 /** describes one supported writer */
31 struct writer {
32         /**
33          * the init function of the writer
34          *
35          * It must fill in all other function pointers of the given
36          * writer structure.
37          *
38          */
39         void (*init)(struct writer *w);
40         /**
41          *
42          *
43          * the command line parser of the writer
44          *
45          * It should check whether the command line options given by \a options are
46          * valid.  On success, it should return a pointer to the writer-specific
47          * configuration data determined by \a options.  Note that this might be called
48          * more than once with different values of \a options.
49          *
50          */
51                 void * (*parse_config)(const char *options);
52         /**
53          *
54          * open one instance of this writer
55          *
56          * This function should perform any work necessary to write the incoming
57          * stream. If To this aim, it may allocate its private data structure and store
58          * a pointer to that structure via the given writer_node paramenter.
59          */
60         int (*open)(struct writer_node *);
61         /**
62          *
63          * write a chunk of audio data
64          *
65          * This is called from the writer node group task's pre_select(). It
66          * may use the sched pointer to add any file descriptors or to decrease
67          * the select timeout. It must return positive on success and negative
68          * on errors.
69          */
70         int (*pre_select)(struct sched *s, struct writer_node *wn);
71         /**
72          * Called from the post_select function of the wng task. It must keep
73          * track of the the number of bytes consumed from the wng's buffer via
74          * the wn->written variable (which may be modified by the wng handling
75          * functions). This function must return positive on success and
76          * negative on errors.
77          */
78         int (*post_select)(struct sched *s, struct writer_node *wn);
79         /**
80          * close one instance of the writer
81          *
82          * This function is assumed to succeed.
83          */
84         void (*close)(struct writer_node *);
85         /**
86          * shutdown the writer
87          *
88          * This is a optional function pointer used for cleaning
89          * up.
90          */
91         void (*shutdown)(struct writer_node *);
92 };
93
94 /**
95  * describes a set of writer nodes that all write the same stream.
96  */
97 struct writer_node_group {
98         /** number of nodes belonging to this group */
99         unsigned num_writers;
100         /** array of pointers to the corresponding writer nodes */
101         struct writer_node *writer_nodes;
102         /** the maximum of the chunk_bytes values of the writer nodes in this group */
103         size_t max_chunk_bytes;
104         /** non-zero if end of file was encountered by the feeding task */
105         int *input_eof;
106         /** non-zero if end of file was encountered */
107         int eof;
108         /** current output buffer */
109         char *buf;
110         /** number of bytes loaded in the output buffer */
111         size_t *loaded;
112         /** number of audio channels of the current stream */
113         unsigned int *channels;
114         /** sample rate of the current stream */
115         unsigned int *samplerate;
116         /** the task associated to this group */
117         struct task task;
118 };
119
120 /** loop over each writer node in a writer group */
121 #define FOR_EACH_WRITER_NODE(i, wng) for (i = 0; i < (wng)->num_writers; i++)
122 /** loop over each supported writer */
123 #define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)
124
125 /** declare the init functions of all supported writers */
126 DECLARE_WRITER_INITS;
127
128 /** array containing the name of each writer */
129 extern const char *writer_names[];
130
131 /** the writer structure for each supported writer */
132 extern struct writer writers[NUM_SUPPORTED_WRITERS];