source: roaraudio/roard/container_framework.c @ 2713:0b9af3059649

Last change on this file since 2713:0b9af3059649 was 2713:0b9af3059649, checked in by phi, 15 years ago

new debug lions, fixed bug with CCB for close

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