source: roaraudio/roard/container_framework.c @ 2704:43b2391e7001

Last change on this file since 2704:43b2391e7001 was 2704:43b2391e7001, checked in by phi, 15 years ago

got first child stream to work

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