source: roaraudio/roard/container_framework.c @ 2701:56507267e81b

Last change on this file since 2701:56507267e81b was 2696:26ceae3107d4, checked in by phi, 15 years ago

get basics working together with RAUM

File size: 7.5 KB
Line 
1//container_framework.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27#define _DECL()  struct cont_fw_child_vio_inst * inst
28#define _CHECK() if ( vio == NULL ) \
29                 return -1
30#define _CINST() if ( (inst = vio->inst) == NULL ) \
31                  return -1
32#define _PREP()  _CHECK(); \
33                 _CINST()
34#define _BASIC() _DECL();  \
35                 _PREP()
36
37// Parent:
38int     cont_fw_new     (struct cont_fw_parent_inst ** inst) {
39 struct cont_fw_parent_inst * self;
40
41 if ( inst == NULL )
42  return -1;
43
44 if ( (self = malloc(sizeof(struct cont_fw_parent_inst))) == NULL ) {
45  *inst = NULL;
46  return -1;
47 }
48
49 memset(self, 0, sizeof(struct cont_fw_parent_inst));
50
51 self->stream.id = -1;
52 self->state     = ROAR_STREAMSTATE_INITING;
53
54 *inst = self;
55 return 0;
56}
57
58int     cont_fw_delete  (struct cont_fw_parent_inst  * inst) {
59 int i;
60
61 if ( inst == NULL )
62  return -1;
63
64 // check if there are streams to close...
65 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
66  if ( inst->child[i] != NULL ) {
67   return -1;
68  }
69 }
70
71 if ( inst->pcb.close != NULL )
72  inst->pcb.close(inst);
73
74 free(inst);
75
76 return 0;
77}
78
79int     cont_fw_set_uinst(struct cont_fw_parent_inst  * inst, void  * u_inst) {
80 if ( inst == NULL )
81  return -1;
82
83 inst->u_inst = u_inst;
84
85 return 0;
86}
87
88int     cont_fw_get_uinst(struct cont_fw_parent_inst  * inst, void ** u_inst) {
89 if ( inst == NULL || u_inst == NULL )
90  return -1;
91
92 *u_inst = inst->u_inst;
93
94 return 0;
95}
96
97// VIOs:
98int     cont_fw_new_child(struct cont_fw_parent_inst  * inst, int id) {
99 struct cont_fw_child_vio_inst * self;
100 struct roar_stream_server     * ss;
101 int i;
102 int cid = -1;
103
104 if ( inst == NULL || id == -1 )
105  return -1;
106
107 if ( streams_get(id, &ss) == -1 )
108  return -1;
109
110 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
111  if ( inst->child[i] == NULL ) {
112   cid = i;
113   break;
114  }
115 }
116
117 if ( cid == -1 )
118  return -1;
119
120 if ( (self = malloc(sizeof(struct cont_fw_child_vio_inst))) == NULL )
121  return -1;
122
123 memset(self, 0, sizeof(struct cont_fw_child_vio_inst));
124
125 self->parent = inst;
126 self->child  = id;
127 self->u_inst = NULL;
128
129 inst->child[i] = self;
130
131 if ( inst->pcb.new_child != NULL ) {
132  if ( inst->pcb.new_child(inst, self) == -1 ) {
133   inst->child[i] = NULL;
134   free(self);
135   return -1;
136  }
137 }
138
139 // no error possible here.
140 cont_fw_init_vio(&(ss->vio), self);
141
142 streams_set_fh(id, -1); // update some internal structures
143
144 return 0;
145}
146
147int     cont_fw_init_vio(struct roar_vio_calls * vio, void * inst) {
148 if ( vio == NULL )
149  return -1;
150
151 memset(vio, 0, sizeof(struct roar_vio_calls));
152 vio->inst = inst;
153
154 vio->read  = cont_fw_read;
155 vio->write = cont_fw_write;
156 vio->sync  = cont_fw_sync;
157 vio->close = cont_fw_close;
158
159 return 0;
160}
161
162ssize_t cont_fw_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
163 _BASIC();
164
165 if ( inst->parent->ccb.read != NULL )
166  return inst->parent->ccb.read(inst->parent, inst, buf, count);
167
168 return -1;
169}
170
171ssize_t cont_fw_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
172 _BASIC();
173
174 if ( inst->parent->ccb.write != NULL )
175  return inst->parent->ccb.write(inst->parent, inst, buf, count);
176
177 return -1;
178}
179
180off_t   cont_fw_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
181int     cont_fw_nonblock(struct roar_vio_calls * vio, int state);
182
183int     cont_fw_sync    (struct roar_vio_calls * vio) {
184 _BASIC();
185
186 if ( inst->parent->ccb.flush != NULL )
187  return inst->parent->ccb.flush(inst->parent, inst);
188
189 return 0;
190}
191
192int     cont_fw_close   (struct roar_vio_calls * vio) {
193 _DECL();
194 int r = 0;
195 int i;
196
197 _PREP();
198
199 if ( cont_fw_sync(vio) == -1 )
200  r = -1;
201
202 if ( inst->parent->ccb.close != NULL )
203  return inst->parent->ccb.close(inst->parent, inst);
204
205 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
206  if ( inst->parent->child[i] == inst ) {
207   inst->parent->child[i] = NULL;
208  }
209 }
210
211 free(inst);
212
213 return  r;
214}
215
216int     cont_fw_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
217
218// CF:
219int cont_fw_cf_open(CODECFILTER_USERDATA_T * inst, int codec,
220                                             struct roar_stream_server * info,
221                                             struct roar_codecfilter   * filter) {
222 struct cont_fw_parent_inst * self;
223 CONT_FW_SETUP_TYPE((*setup));
224
225 ROAR_DBG("cont_fw_cf_open(*) = ?");
226
227 if ( cont_fw_new(&self) == -1 )
228  return -1;
229
230 self->stream.codec  = codec;
231 self->stream.id     = ROAR_STREAM(info)->id;
232 self->stream.stream = info;
233 self->stream.filter = filter;
234
235 ROAR_DBG("cont_fw_cf_open(*) = ?");
236
237 if ( (setup = filter->setup) != NULL ) {
238  if ( setup(self, codec, filter) == -1 ) {
239   cont_fw_delete(self);
240   return -1;
241  }
242 }
243
244 ROAR_DBG("cont_fw_cf_open(*) = ?");
245
246 *inst = self;
247
248 ROAR_DBG("cont_fw_cf_open(*) = 0");
249 return 0;
250}
251
252int cont_fw_cf_close(CODECFILTER_USERDATA_T   inst) {
253 ROAR_DBG("cont_fw_cf_close(*) = ?");
254 return cont_fw_delete(inst);
255}
256
257int cont_fw_cf_pause(CODECFILTER_USERDATA_T   inst, int newstate);
258
259
260// no direct read or writing...
261int cont_fw_cf_write(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
262 struct cont_fw_parent_inst * self = (void*)inst;
263
264 ROAR_DBG("cont_fw_cf_write(*) = ?");
265
266 if ( self->state == ROAR_STREAMSTATE_INITING ) {
267  if ( self->pcb.open != NULL ) {
268   if ( self->pcb.open(self, self->stream.codec, self->stream.stream, self->stream.filter) == -1 ) {
269    return -1;
270   }
271  }
272  self->state = ROAR_STREAMSTATE_NEW;
273
274  ROAR_DBG("cont_fw_cf_write(*) = 0");
275  return 0;
276 } else {
277  ROAR_DBG("cont_fw_cf_write(*) = -1");
278  return -1;
279 }
280}
281
282int cont_fw_cf_read (CODECFILTER_USERDATA_T   inst, char * buf, int len) {
283 ROAR_DBG("cont_fw_cf_read(*) = -1");
284 return -1;
285}
286
287int cont_fw_cf_flush(CODECFILTER_USERDATA_T   inst) {
288 struct cont_fw_parent_inst * self = (void*)inst;
289
290 ROAR_DBG("cont_fw_cf_flush(*) = ?");
291
292 if ( self->pcb.flush != NULL )
293  return self->pcb.flush(self);
294
295 return 0;
296}
297
298int cont_fw_cf_delay(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay);
299
300int cont_fw_cf_ctl  (CODECFILTER_USERDATA_T   inst, int cmd, void * data) {
301 struct cont_fw_parent_inst * self = (void*)inst;
302 int_least32_t type = cmd & ROAR_STREAM_CTL_TYPEMASK;
303
304 ROAR_DBG("cont_fw_cf_ctl(*) = ?");
305
306 cmd -= type;
307
308 ROAR_DBG("cont_fw_cf_ctl(*): command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
309                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
310
311 if ( data == NULL && type != ROAR_STREAM_CTL_TYPE_VOID )
312  return -1;
313
314 switch (cmd) {
315  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_DELETE):
316    return 0;
317   break;
318  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_NEW):
319    if ( type != ROAR_STREAM_CTL_TYPE_INT )
320     return -1;
321
322    return cont_fw_new_child(self, *(int*)data);
323   break;
324  default:
325    ROAR_DBG("cont_fw_cf_ctl(*): Unknown command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
326                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
327    return -1;
328 }
329
330 return -1;
331}
332
333//ll
Note: See TracBrowser for help on using the repository browser.