Improve help/man page of para_write.
[paraslash.git] / write.h
1 /*
2  * Copyright (C) 2006-2008 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         /** 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         void (*init)(struct writer *w);
39         /**
40          * The command line parser of the writer.
41          *
42          * It should check whether the command line options given by \a options are
43          * valid.  On success, it should return a pointer to the writer-specific
44          * configuration data determined by \a options.  Note that this might be called
45          * more than once with different values of \a options.
46          */
47         void *(*parse_config)(const char *options);
48         /**
49          * Open one instance of this writer.
50          *
51          * This function should perform any work necessary to write the incoming
52          * stream. If To this aim, it may allocate its private data structure and store
53          * a pointer to that structure via the given writer_node parameter.
54          */
55         int (*open)(struct writer_node *);
56         /**
57          * Prepare the fd sets for select.
58          *
59          * This is called from the writer node group task's pre_select(). It
60          * may use the sched pointer to add any file descriptors or to decrease
61          * the select timeout. It must return positive on success and negative
62          * on errors.
63          */
64         int (*pre_select)(struct sched *s, struct writer_node *wn);
65         /**
66          * Write audio data.
67          *
68          * Called from the post_select function of the wng task. It must keep
69          * track of the number of bytes consumed from the wng's buffer via
70          * the \p wn->written variable (which may be modified by the wng handling
71          * functions). This function must return positive on success and
72          * negative on errors.
73          */
74         int (*post_select)(struct sched *s, struct writer_node *wn);
75         /**
76          * Close one instance of the writer.
77          *
78          * This function is assumed to succeed.
79          */
80         void (*close)(struct writer_node *);
81         /**
82          * Shutdown the writer
83          *
84          * This is a optional function pointer used for cleaning up.
85          */
86         void (*shutdown)(struct writer_node *);
87         struct ggo_help help;
88 };
89
90 /**
91  * Describes a set of writer nodes that all write the same stream.
92  */
93 struct writer_node_group {
94         /** Number of nodes belonging to this group. */
95         unsigned num_writers;
96         /** Array of pointers to the corresponding writer nodes. */
97         struct writer_node *writer_nodes;
98         /** The maximum of the chunk_bytes values of the writer nodes in this group. */
99         int max_chunk_bytes;
100         /** Non-zero if an error or end of file was encountered by the feeding task. */
101         int *input_error;
102         /** Current output buffer. */
103         char *buf;
104         /** Number of bytes loaded in the output buffer. */
105         size_t *loaded;
106         /** Number of audio channels of the current stream. */
107         unsigned int *channels;
108         /** Sample rate of the current stream. */
109         unsigned int *samplerate;
110         /** The task associated to this group. */
111         struct task task;
112         /** Whether the group is open, i.e. wng_open() was called. */
113         int open;
114 };
115
116 /** Loop over each writer node in a writer group. */
117 #define FOR_EACH_WRITER_NODE(i, wng) for (i = 0; i < (wng)->num_writers; i++)
118 /** Loop over each supported writer. */
119 #define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)
120
121 /** Declare the init functions of all supported writers. */
122 DECLARE_WRITER_INITS;
123
124 /** Array containing the name of each writer. */
125 extern const char *writer_names[];
126
127 /** The writer structure for each supported writer. */
128 extern struct writer writers[NUM_SUPPORTED_WRITERS];