source: roaraudio/roard/container_framework.c @ 2702:f32db8631c1a

Last change on this file since 2702:f32db8631c1a was 2702:f32db8631c1a, checked in by phi, 15 years ago

new debug lion

File size: 7.6 KB
RevLine 
[2661]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
[2665]37// Parent:
[2663]38int     cont_fw_new     (struct cont_fw_parent_inst ** inst) {
[2664]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
[2696]51 self->stream.id = -1;
52 self->state     = ROAR_STREAMSTATE_INITING;
53
[2664]54 *inst = self;
55 return 0;
[2663]56}
57
58int     cont_fw_delete  (struct cont_fw_parent_inst  * inst) {
[2664]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
[2670]71 if ( inst->pcb.close != NULL )
72  inst->pcb.close(inst);
73
[2664]74 free(inst);
75
76 return 0;
[2663]77}
78
[2665]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:
[2668]98int     cont_fw_new_child(struct cont_fw_parent_inst  * inst, int id) {
[2672]99 struct cont_fw_child_vio_inst * self;
[2673]100 struct roar_stream_server     * ss;
[2672]101 int i;
102 int cid = -1;
103
[2702]104 ROAR_DBG("cont_fw_new_child(inst=%p, id=%i) = ?", inst, id);
105
[2672]106 if ( inst == NULL || id == -1 )
107  return -1;
108
[2673]109 if ( streams_get(id, &ss) == -1 )
110  return -1;
111
[2672]112 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
113  if ( inst->child[i] == NULL ) {
114   cid = i;
115   break;
116  }
117 }
118
119 if ( cid == -1 )
[2668]120  return -1;
121
[2672]122 if ( (self = malloc(sizeof(struct cont_fw_child_vio_inst))) == NULL )
123  return -1;
124
125 memset(self, 0, sizeof(struct cont_fw_child_vio_inst));
126
127 self->parent = inst;
128 self->child  = id;
129 self->u_inst = NULL;
130
131 inst->child[i] = self;
132
133 if ( inst->pcb.new_child != NULL ) {
134  if ( inst->pcb.new_child(inst, self) == -1 ) {
135   inst->child[i] = NULL;
136   free(self);
137   return -1;
138  }
139 }
140
[2673]141 // no error possible here.
142 cont_fw_init_vio(&(ss->vio), self);
143
144 streams_set_fh(id, -1); // update some internal structures
145
[2672]146 return 0;
[2668]147}
[2665]148
[2662]149int     cont_fw_init_vio(struct roar_vio_calls * vio, void * inst) {
150 if ( vio == NULL )
151  return -1;
152
153 memset(vio, 0, sizeof(struct roar_vio_calls));
154 vio->inst = inst;
155
156 vio->read  = cont_fw_read;
157 vio->write = cont_fw_write;
158 vio->sync  = cont_fw_sync;
159 vio->close = cont_fw_close;
160
161 return 0;
162}
163
[2661]164ssize_t cont_fw_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
165 _BASIC();
166
[2667]167 if ( inst->parent->ccb.read != NULL )
[2669]168  return inst->parent->ccb.read(inst->parent, inst, buf, count);
[2661]169
170 return -1;
171}
172
173ssize_t cont_fw_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
174 _BASIC();
175
[2667]176 if ( inst->parent->ccb.write != NULL )
[2669]177  return inst->parent->ccb.write(inst->parent, inst, buf, count);
[2661]178
179 return -1;
180}
181
182off_t   cont_fw_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
183int     cont_fw_nonblock(struct roar_vio_calls * vio, int state);
184
185int     cont_fw_sync    (struct roar_vio_calls * vio) {
186 _BASIC();
187
[2667]188 if ( inst->parent->ccb.flush != NULL )
[2669]189  return inst->parent->ccb.flush(inst->parent, inst);
[2661]190
191 return 0;
192}
193
194int     cont_fw_close   (struct roar_vio_calls * vio) {
195 _DECL();
196 int r = 0;
[2671]197 int i;
[2661]198
199 _PREP();
200
201 if ( cont_fw_sync(vio) == -1 )
202  r = -1;
203
[2667]204 if ( inst->parent->ccb.close != NULL )
[2669]205  return inst->parent->ccb.close(inst->parent, inst);
[2667]206
[2671]207 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
208  if ( inst->parent->child[i] == inst ) {
209   inst->parent->child[i] = NULL;
210  }
211 }
212
213 free(inst);
214
[2661]215 return  r;
216}
217
218int     cont_fw_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
219
[2675]220// CF:
221int cont_fw_cf_open(CODECFILTER_USERDATA_T * inst, int codec,
222                                             struct roar_stream_server * info,
[2677]223                                             struct roar_codecfilter   * filter) {
[2678]224 struct cont_fw_parent_inst * self;
[2683]225 CONT_FW_SETUP_TYPE((*setup));
[2678]226
[2691]227 ROAR_DBG("cont_fw_cf_open(*) = ?");
228
[2678]229 if ( cont_fw_new(&self) == -1 )
230  return -1;
231
[2696]232 self->stream.codec  = codec;
233 self->stream.id     = ROAR_STREAM(info)->id;
234 self->stream.stream = info;
235 self->stream.filter = filter;
236
[2691]237 ROAR_DBG("cont_fw_cf_open(*) = ?");
238
[2683]239 if ( (setup = filter->setup) != NULL ) {
240  if ( setup(self, codec, filter) == -1 ) {
241   cont_fw_delete(self);
242   return -1;
243  }
244 }
245
[2691]246 ROAR_DBG("cont_fw_cf_open(*) = ?");
247
[2678]248 *inst = self;
[2691]249
250 ROAR_DBG("cont_fw_cf_open(*) = 0");
[2678]251 return 0;
[2677]252}
[2675]253
254int cont_fw_cf_close(CODECFILTER_USERDATA_T   inst) {
[2695]255 ROAR_DBG("cont_fw_cf_close(*) = ?");
[2675]256 return cont_fw_delete(inst);
257}
258
259int cont_fw_cf_pause(CODECFILTER_USERDATA_T   inst, int newstate);
260
261
262// no direct read or writing...
263int cont_fw_cf_write(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
[2696]264 struct cont_fw_parent_inst * self = (void*)inst;
265
266 ROAR_DBG("cont_fw_cf_write(*) = ?");
267
268 if ( self->state == ROAR_STREAMSTATE_INITING ) {
269  if ( self->pcb.open != NULL ) {
270   if ( self->pcb.open(self, self->stream.codec, self->stream.stream, self->stream.filter) == -1 ) {
271    return -1;
272   }
273  }
274  self->state = ROAR_STREAMSTATE_NEW;
275
276  ROAR_DBG("cont_fw_cf_write(*) = 0");
277  return 0;
278 } else {
279  ROAR_DBG("cont_fw_cf_write(*) = -1");
280  return -1;
281 }
[2675]282}
283
284int cont_fw_cf_read (CODECFILTER_USERDATA_T   inst, char * buf, int len) {
[2695]285 ROAR_DBG("cont_fw_cf_read(*) = -1");
[2675]286 return -1;
287}
288
289int cont_fw_cf_flush(CODECFILTER_USERDATA_T   inst) {
290 struct cont_fw_parent_inst * self = (void*)inst;
291
[2695]292 ROAR_DBG("cont_fw_cf_flush(*) = ?");
293
[2675]294 if ( self->pcb.flush != NULL )
295  return self->pcb.flush(self);
296
297 return 0;
298}
299
300int cont_fw_cf_delay(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay);
301
302int cont_fw_cf_ctl  (CODECFILTER_USERDATA_T   inst, int cmd, void * data) {
[2676]303 struct cont_fw_parent_inst * self = (void*)inst;
304 int_least32_t type = cmd & ROAR_STREAM_CTL_TYPEMASK;
305
[2695]306 ROAR_DBG("cont_fw_cf_ctl(*) = ?");
307
[2676]308 cmd -= type;
309
310 ROAR_DBG("cont_fw_cf_ctl(*): command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
311                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
312
313 if ( data == NULL && type != ROAR_STREAM_CTL_TYPE_VOID )
314  return -1;
315
316 switch (cmd) {
317  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_DELETE):
318    return 0;
319   break;
320  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_NEW):
321    if ( type != ROAR_STREAM_CTL_TYPE_INT )
322     return -1;
323
324    return cont_fw_new_child(self, *(int*)data);
325   break;
326  default:
327    ROAR_DBG("cont_fw_cf_ctl(*): Unknown command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
328                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
329    return -1;
330 }
331
[2675]332 return -1;
333}
334
[2661]335//ll
Note: See TracBrowser for help on using the repository browser.