1 | //codecfilter_raum.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 | #ifdef ROAR_HAVE_LIBRAUM |
---|
28 | #include <raum.h> |
---|
29 | |
---|
30 | // PCBs: |
---|
31 | int cf_raum_pcb_open (struct cont_fw_parent_inst * self, |
---|
32 | int codec, |
---|
33 | struct roar_stream_server * stream, |
---|
34 | struct roar_codecfilter * filter) { |
---|
35 | struct roar_stream * s = ROAR_STREAM(stream); |
---|
36 | RAUMState * state; |
---|
37 | int flags = 0; |
---|
38 | |
---|
39 | ROAR_DBG("cf_raum_pcb_open(*) = ?"); |
---|
40 | |
---|
41 | if ( stream == NULL ) |
---|
42 | return -1; |
---|
43 | |
---|
44 | switch (s->dir) { |
---|
45 | case ROAR_DIR_COMPLEX_IN: |
---|
46 | case ROAR_DIR_PLAY: |
---|
47 | flags = O_RDONLY; |
---|
48 | break; |
---|
49 | case ROAR_DIR_COMPLEX_OUT: |
---|
50 | case ROAR_DIR_MONITOR: |
---|
51 | case ROAR_DIR_OUTPUT: |
---|
52 | flags = O_WRONLY; |
---|
53 | break; |
---|
54 | default: |
---|
55 | return -1; |
---|
56 | } |
---|
57 | |
---|
58 | state = RAUMOpenVIO(&(self->vio), flags); |
---|
59 | |
---|
60 | if ( state == NULL ) |
---|
61 | return -1; |
---|
62 | |
---|
63 | cont_fw_set_uinst(self, state); |
---|
64 | |
---|
65 | ROAR_DBG("cf_raum_pcb_open(*) = 0"); |
---|
66 | return 0; |
---|
67 | } |
---|
68 | |
---|
69 | int cf_raum_pcb_close (struct cont_fw_parent_inst * self) { |
---|
70 | void * state; |
---|
71 | |
---|
72 | ROAR_DBG("cf_raum_pcb_close(*) = ?"); |
---|
73 | |
---|
74 | if ( cont_fw_get_uinst(self, &state) == -1 ) |
---|
75 | return -1; |
---|
76 | |
---|
77 | ROAR_DBG("cf_raum_pcb_close(*) = ?"); |
---|
78 | return RAUMClose(state); |
---|
79 | } |
---|
80 | |
---|
81 | int cf_raum_pcb_new_child(struct cont_fw_parent_inst * self, struct cont_fw_child_vio_inst * child) { |
---|
82 | struct roar_stream_server * ss; |
---|
83 | struct roar_stream * s; |
---|
84 | void * ps; |
---|
85 | RAUMStream * stream; |
---|
86 | int dir = ROAR_DIR_PLAY; |
---|
87 | |
---|
88 | ROAR_DBG("cf_raum_pcb_new_child(self=%p, child=%p) = ?", self, child); |
---|
89 | |
---|
90 | if ( streams_get(child->child, &ss) == -1 ) |
---|
91 | return -1; |
---|
92 | |
---|
93 | if ( (s = ROAR_STREAM(ss)) == NULL ) |
---|
94 | return -1; |
---|
95 | |
---|
96 | if ( cont_fw_get_uinst(self, &ps) == -1 ) |
---|
97 | return -1; |
---|
98 | |
---|
99 | if ( ps == NULL ) |
---|
100 | return -1; |
---|
101 | |
---|
102 | if ( (stream = RAUMStreamNewSimple(s->info.rate, s->info.channels, s->info.bits, s->info.codec, dir)) == NULL ) |
---|
103 | return -1; |
---|
104 | |
---|
105 | if ( RAUMAddStream(ps, stream) == -1 ) { |
---|
106 | RAUMStreamClose(stream); |
---|
107 | return -1; |
---|
108 | } |
---|
109 | |
---|
110 | child->u_inst = stream; |
---|
111 | |
---|
112 | ROAR_DBG("cf_raum_pcb_new_child(self=%p, child=%p) = 0", self, child); |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | // CCBs: |
---|
117 | ssize_t cf_raum_ccb_read (struct cont_fw_parent_inst * self, struct cont_fw_child_vio_inst * child, void *buf, size_t len) { |
---|
118 | ROAR_DBG("cf_raum_ccb_read(self=%p, child=%p, buf=%p, len=%lu) = ?", self, child, buf, (unsigned long)len); |
---|
119 | return RAUMStreamRead(child->u_inst, buf, len); |
---|
120 | } |
---|
121 | ssize_t cf_raum_ccb_write(struct cont_fw_parent_inst * self, struct cont_fw_child_vio_inst * child, void *buf, size_t len) { |
---|
122 | ROAR_DBG("cf_raum_ccb_write(self=%p, child=%p, buf=%p, len=%lu) = ?", self, child, buf, (unsigned long)len); |
---|
123 | return RAUMStreamWrite(child->u_inst, buf, len); |
---|
124 | } |
---|
125 | int cf_raum_ccb_close(struct cont_fw_parent_inst * self, struct cont_fw_child_vio_inst * child) { |
---|
126 | ROAR_DBG("cf_raum_ccb_close(self=%p, child=%p) = ?", self, child); |
---|
127 | return RAUMStreamClose(child->u_inst); |
---|
128 | } |
---|
129 | |
---|
130 | // SETUP: |
---|
131 | CONT_FW_SETUP_TYPE(cf_raum_setup) { |
---|
132 | ROAR_DBG("cf_raum_setup(*) = ?"); |
---|
133 | |
---|
134 | // PCBs: |
---|
135 | self->pcb.open = cf_raum_pcb_open; |
---|
136 | self->pcb.close = cf_raum_pcb_close; |
---|
137 | self->pcb.new_child = cf_raum_pcb_new_child; |
---|
138 | |
---|
139 | // CCBs: |
---|
140 | self->ccb.read = cf_raum_ccb_read; |
---|
141 | self->ccb.write = cf_raum_ccb_write; |
---|
142 | self->ccb.close = cf_raum_ccb_close; |
---|
143 | |
---|
144 | ROAR_DBG("cf_raum_setup(*) = 0"); |
---|
145 | return 0; |
---|
146 | } |
---|
147 | |
---|
148 | #endif |
---|
149 | |
---|
150 | //ll |
---|