Kill unused struct filter_chain.
[paraslash.git] / write.h
1 /*
2  * Copyright (C) 2006-2009 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  * Describes one running instance of a writer.
14  */
15 struct writer_node {
16         /** The number of this writer. */
17         int writer_num;
18         /** Writer-specific data. */
19         void *private_data;
20         /** Pointer to the group this node belongs to. */
21         struct writer_node_group *wng;
22         /** The writer-specific configuration of this node. */
23         void *conf;
24         /** How much of the wng's buffer is already written. */
25         size_t written;
26         struct btr_node *btrn;
27         struct task task;
28         size_t min_iqs;
29 };
30
31 /** Describes one supported writer. */
32 struct writer {
33         /**
34          * The init function of the writer.
35          *
36          * It must fill in all other function pointers of the given
37          * writer structure.
38          */
39         void (*init)(struct writer *w);
40         /**
41          * The command line parser of the writer.
42          *
43          * It should check whether the command line options given by \a options are
44          * valid.  On success, it should return a pointer to the writer-specific
45          * configuration data determined by \a options.  Note that this might be called
46          * more than once with different values of \a options.
47          */
48         void *(*parse_config)(const char *options);
49         void (*free_config)(void *conf);
50         /**
51          * Open one instance of this writer.
52          *
53          * This function should perform any work necessary to write the incoming
54          * stream. To this aim, it may allocate its private data structure and store
55          * a pointer to that structure via the given writer_node parameter.
56          */
57         int (*open)(struct writer_node *);
58         /**
59          * Prepare the fd sets for select.
60          *
61          * This is called from the writer node group task's pre_select(). It
62          * may use the sched pointer to add any file descriptors or to decrease
63          * the select timeout. It must return positive on success and negative
64          * on errors.
65          */
66         int (*pre_select)(struct sched *s, struct writer_node *wn);
67         void (*pre_select_btr)(struct sched *s, struct task *t);
68         /**
69          * Write audio data.
70          *
71          * Called from the post_select function of the wng task. It must keep
72          * track of the number of bytes consumed from the wng's buffer via
73          * the \p wn->written variable (which may be modified by the wng handling
74          * functions). This function must return positive on success and
75          * negative on errors.
76          */
77         int (*post_select)(struct sched *s, struct writer_node *wn);
78         void (*post_select_btr)(struct sched *s, struct task *t);
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 up.
89          */
90         void (*shutdown)(struct writer_node *);
91         struct ggo_help help;
92         btr_command_handler execute;
93 };
94
95 /**
96  * Describes a set of writer nodes that all write the same stream.
97  */
98 struct writer_node_group {
99         /** Number of nodes belonging to this group. */
100         unsigned num_writers;
101         /** Array of pointers to the corresponding writer nodes. */
102         struct writer_node *writer_nodes;
103         /** Non-zero if an error or end of file was encountered by the feeding task. */
104         int *input_error;
105         /** Current output buffer. */
106         char **bufp;
107         /** Number of bytes loaded in the output buffer. */
108         size_t *loaded;
109         /** Number of audio channels of the current stream. */
110         unsigned int *channels;
111         /** Sample rate of the current stream. */
112         unsigned int *samplerate;
113         /** The task associated to this group. */
114         struct task task;
115         /** Whether the group is open, i.e. wng_open() was called. */
116         int open;
117         /** Max number of bytes written in the previous post_select() call. */
118         int last_written;
119 };
120
121 /** Loop over each writer node in a writer group. */
122 #define FOR_EACH_WRITER_NODE(i, wng) for (i = 0; i < (wng)->num_writers; i++)
123 /** Loop over each supported writer. */
124 #define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)
125
126 /** Declare the init functions of all supported writers. */
127 DECLARE_WRITER_INITS;
128
129 /** Array containing the name of each writer. */
130 extern const char *writer_names[];
131
132 /** The writer structure for each supported writer. */
133 extern struct writer writers[NUM_SUPPORTED_WRITERS];