source: roaraudio/roard/container_framework.c @ 2676:dc2543783ed8

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

wrote cont_fw_cf_ctl()

File size: 6.3 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 *inst = self;
52 return 0;
53}
54
55int     cont_fw_delete  (struct cont_fw_parent_inst  * inst) {
56 int i;
57
58 if ( inst == NULL )
59  return -1;
60
61 // check if there are streams to close...
62 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
63  if ( inst->child[i] != NULL ) {
64   return -1;
65  }
66 }
67
68 if ( inst->pcb.close != NULL )
69  inst->pcb.close(inst);
70
71 free(inst);
72
73 return 0;
74}
75
76int     cont_fw_set_uinst(struct cont_fw_parent_inst  * inst, void  * u_inst) {
77 if ( inst == NULL )
78  return -1;
79
80 inst->u_inst = u_inst;
81
82 return 0;
83}
84
85int     cont_fw_get_uinst(struct cont_fw_parent_inst  * inst, void ** u_inst) {
86 if ( inst == NULL || u_inst == NULL )
87  return -1;
88
89 *u_inst = inst->u_inst;
90
91 return 0;
92}
93
94// VIOs:
95int     cont_fw_new_child(struct cont_fw_parent_inst  * inst, int id) {
96 struct cont_fw_child_vio_inst * self;
97 struct roar_stream_server     * ss;
98 int i;
99 int cid = -1;
100
101 if ( inst == NULL || id == -1 )
102  return -1;
103
104 if ( streams_get(id, &ss) == -1 )
105  return -1;
106
107 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
108  if ( inst->child[i] == NULL ) {
109   cid = i;
110   break;
111  }
112 }
113
114 if ( cid == -1 )
115  return -1;
116
117 if ( (self = malloc(sizeof(struct cont_fw_child_vio_inst))) == NULL )
118  return -1;
119
120 memset(self, 0, sizeof(struct cont_fw_child_vio_inst));
121
122 self->parent = inst;
123 self->child  = id;
124 self->u_inst = NULL;
125
126 inst->child[i] = self;
127
128 if ( inst->pcb.new_child != NULL ) {
129  if ( inst->pcb.new_child(inst, self) == -1 ) {
130   inst->child[i] = NULL;
131   free(self);
132   return -1;
133  }
134 }
135
136 // no error possible here.
137 cont_fw_init_vio(&(ss->vio), self);
138
139 streams_set_fh(id, -1); // update some internal structures
140
141 return 0;
142}
143
144int     cont_fw_init_vio(struct roar_vio_calls * vio, void * inst) {
145 if ( vio == NULL )
146  return -1;
147
148 memset(vio, 0, sizeof(struct roar_vio_calls));
149 vio->inst = inst;
150
151 vio->read  = cont_fw_read;
152 vio->write = cont_fw_write;
153 vio->sync  = cont_fw_sync;
154 vio->close = cont_fw_close;
155
156 return 0;
157}
158
159ssize_t cont_fw_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
160 _BASIC();
161
162 if ( inst->parent->ccb.read != NULL )
163  return inst->parent->ccb.read(inst->parent, inst, buf, count);
164
165 return -1;
166}
167
168ssize_t cont_fw_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
169 _BASIC();
170
171 if ( inst->parent->ccb.write != NULL )
172  return inst->parent->ccb.write(inst->parent, inst, buf, count);
173
174 return -1;
175}
176
177off_t   cont_fw_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
178int     cont_fw_nonblock(struct roar_vio_calls * vio, int state);
179
180int     cont_fw_sync    (struct roar_vio_calls * vio) {
181 _BASIC();
182
183 if ( inst->parent->ccb.flush != NULL )
184  return inst->parent->ccb.flush(inst->parent, inst);
185
186 return 0;
187}
188
189int     cont_fw_close   (struct roar_vio_calls * vio) {
190 _DECL();
191 int r = 0;
192 int i;
193
194 _PREP();
195
196 if ( cont_fw_sync(vio) == -1 )
197  r = -1;
198
199 if ( inst->parent->ccb.close != NULL )
200  return inst->parent->ccb.close(inst->parent, inst);
201
202 for (i = 0; i < CONT_FW_MAX_CHILDS; i++) {
203  if ( inst->parent->child[i] == inst ) {
204   inst->parent->child[i] = NULL;
205  }
206 }
207
208 free(inst);
209
210 return  r;
211}
212
213int     cont_fw_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
214
215// CF:
216int cont_fw_cf_open(CODECFILTER_USERDATA_T * inst, int codec,
217                                             struct roar_stream_server * info,
218                                             struct roar_codecfilter   * filter);
219
220int cont_fw_cf_close(CODECFILTER_USERDATA_T   inst) {
221 return cont_fw_delete(inst);
222}
223
224int cont_fw_cf_pause(CODECFILTER_USERDATA_T   inst, int newstate);
225
226
227// no direct read or writing...
228int cont_fw_cf_write(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
229 return -1;
230}
231
232int cont_fw_cf_read (CODECFILTER_USERDATA_T   inst, char * buf, int len) {
233 return -1;
234}
235
236int cont_fw_cf_flush(CODECFILTER_USERDATA_T   inst) {
237 struct cont_fw_parent_inst * self = (void*)inst;
238
239 if ( self->pcb.flush != NULL )
240  return self->pcb.flush(self);
241
242 return 0;
243}
244
245int cont_fw_cf_delay(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay);
246
247int cont_fw_cf_ctl  (CODECFILTER_USERDATA_T   inst, int cmd, void * data) {
248 struct cont_fw_parent_inst * self = (void*)inst;
249 int_least32_t type = cmd & ROAR_STREAM_CTL_TYPEMASK;
250
251 cmd -= type;
252
253 ROAR_DBG("cont_fw_cf_ctl(*): command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
254                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
255
256 if ( data == NULL && type != ROAR_STREAM_CTL_TYPE_VOID )
257  return -1;
258
259 switch (cmd) {
260  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_DELETE):
261    return 0;
262   break;
263  case ROAR_CODECFILTER_CTL2CMD(ROAR_CODECFILTER_CTL_VIRTUAL_NEW):
264    if ( type != ROAR_STREAM_CTL_TYPE_INT )
265     return -1;
266
267    return cont_fw_new_child(self, *(int*)data);
268   break;
269  default:
270    ROAR_DBG("cont_fw_cf_ctl(*): Unknown command: cmd=0x%.8x, type=0x%.8x, pcmd=0x%.8x",
271                    cmd, type, ROAR_CODECFILTER_CTL2CMD(cmd));
272    return -1;
273 }
274
275 return -1;
276}
277
278//ll
Note: See TracBrowser for help on using the repository browser.