simplify writer node group
[paraslash.git] / write.h
1 /*
2 * Copyright (C) 2006 Andre Noll <maan@systemlinux.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
17 */
18
19 /** \file write.h writer-related structures */
20
21 /** the list of supported writers */
22 enum writer_enum {WRITER_ENUM};
23
24 /**
25 * decbribes one running instance of a writer
26 */
27 struct writer_node {
28 /** points to the writer structure associated with this node */
29 struct writer *writer; /* FIXME: Should better be only the number */
30 /** writer-specific data */
31 void *private_data;
32 /** send that many bytes in one go */
33 int chunk_bytes;
34 struct writer_node_group *wng;
35 /** the writer-specific configuration of this node */
36 void *conf;
37 };
38
39 /** describes one supported writer */
40 struct writer {
41 /**
42 * the init function of the writer
43 *
44 * It must fill in all other function pointers of the given
45 * writer structure.
46 *
47 */
48 void (*init)(struct writer *w);
49 /**
50 *
51 *
52 * the command line parser of the writer
53 *
54 * It should check whether the command line options given by \a options are
55 * valid. On success, it should return a pointer to the writer-specific
56 * configuration data determined by \a options. Note that this might be called
57 * more than once with different values of \a options.
58 *
59 */
60 void * (*parse_config)(char *options);
61 /**
62 *
63 * open one instance of this writer
64 *
65 * This function should perform any work necessary to write the incoming
66 * stream. If To this aim, it may allocate its private data structure and store
67 * a pointer to that structure via the given writer_node paramenter.
68 */
69 int (*open)(struct writer_node *);
70 /**
71 *
72 * write a chunk of audio data
73 *
74 * This is called from the driving application whenever a data block of \a
75 * chunk_bytes is available. It must return the number of bytes consumed from
76 * \a data on success, and negative on errors.
77 *
78 */
79 int (*write)(char *data, size_t nbytes, struct writer_node *);
80 int (*pre_select)(struct sched *s, struct writer_node *wn);
81 int (*post_select)(struct sched *s, struct writer_node *wn);
82 /**
83 * close one instance of the writer
84 *
85 * This function is assumed to succeed.
86 */
87 void (*close)(struct writer_node *);
88 /**
89 * shutdown the writer
90 *
91 * This is a optional function pointer used for cleaning
92 * up.
93 */
94 void (*shutdown)(struct writer_node *);
95 };
96
97 /**
98 * describes a set of writer nodes that all write the same stream.
99 */
100 struct writer_node_group {
101 /** number of nodes belonging to this group */
102 unsigned num_writers;
103 /** array of pointers to the corresponding writer nodes */
104 struct writer_node *writer_nodes;
105 /** keeps track of how many bytes have been written by each node */
106 int *written;
107 /** the maximum of the chunk_bytes values of the writer nodes in this group */
108 size_t max_chunk_bytes;
109 /** non-zero if end of file was encountered */
110 int *input_eof;
111 int eof;
112 char *buf;
113 unsigned int *channels;
114 unsigned int *samplerate;
115 size_t *loaded;
116 struct task task;
117 };
118
119 /** loop over each writer node in a writer group */
120 #define FOR_EACH_WRITER_NODE(i, wng) for (i = 0; i < (wng)->num_writers; i++)
121 /** loop over each supported writer */
122 #define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)
123
124 /** declare the init functions of all supported writers */
125 DECLARE_WRITER_INITS;
126
127 /** array containing the name of each writer */
128 extern const char *writer_names[];
129
130 /** the writer structure for each supported writer */
131 extern struct writer writers[NUM_SUPPORTED_WRITERS];