1 | //roarinterconnect.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
5 | * |
---|
6 | * This file is part of roarclients 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 <roaraudio.h> |
---|
26 | |
---|
27 | #ifdef ROAR_HAVE_ESD |
---|
28 | #include <esd.h> |
---|
29 | #endif |
---|
30 | |
---|
31 | #define MT_NULL 0x00 |
---|
32 | #define MT_MASK 0xF0 |
---|
33 | #define MT_ROAR 0x10 |
---|
34 | #define MT_ESD 0x20 |
---|
35 | #define MT_DEFAULT MT_ROAR |
---|
36 | |
---|
37 | #define ST_NONE 0x00 |
---|
38 | #define ST_MASK 0x0F |
---|
39 | #define ST_BIDIR 0x01 |
---|
40 | #define ST_FILTER 0x02 |
---|
41 | // no default here as the default depend on the server type |
---|
42 | |
---|
43 | void usage (void) { |
---|
44 | printf("roarinterconnect [OPTIONS]...\n"); |
---|
45 | |
---|
46 | printf("\nOptions:\n\n"); |
---|
47 | |
---|
48 | printf(" --server SERVER - Set server hostname\n" |
---|
49 | " --remote SERVER - Set remote server\n" |
---|
50 | " --type TYPE - Set type of remote server\n" |
---|
51 | " --rate RATE - Set sample rate\n" |
---|
52 | " --bits BITS - Set bits per sample\n" |
---|
53 | " --chans CHANNELS - Set number of channels\n" |
---|
54 | " --codec CODEC - Set the codec\n" |
---|
55 | " --help - Show this help\n" |
---|
56 | ); |
---|
57 | |
---|
58 | } |
---|
59 | |
---|
60 | int parse_type (char * type) { |
---|
61 | int ret = 0; |
---|
62 | |
---|
63 | if ( type != NULL ) { |
---|
64 | } |
---|
65 | |
---|
66 | if ( (ret & MT_MASK) == MT_NONE ) |
---|
67 | ret |= MT_DEFAULT; |
---|
68 | |
---|
69 | if ( (ret & ST_MASK) == ST_NONE ) { |
---|
70 | switch (ret & MT_MASK) { |
---|
71 | case MT_ROAR: ret |= ST_BIDIR; break; |
---|
72 | case MT_ESD: ret |= ST_FILTER; break; |
---|
73 | default: |
---|
74 | return MT_NONE|ST_NONE; // error case |
---|
75 | break; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | return ret; |
---|
80 | } |
---|
81 | |
---|
82 | int main (int argc, char * argv[]) { |
---|
83 | struct roar_connection con[1]; |
---|
84 | struct roar_stream stream[1]; |
---|
85 | int rate = 44100; |
---|
86 | int bits = 16; |
---|
87 | int channels = 2; |
---|
88 | int codec = ROAR_CODEC_DEFAULT; |
---|
89 | int type = parse_type(NULL); |
---|
90 | int tmp; |
---|
91 | char * server = NULL; |
---|
92 | char * remote = NULL; |
---|
93 | char * k; |
---|
94 | int rfh; |
---|
95 | int i; |
---|
96 | |
---|
97 | for (i = 1; i < argc; i++) { |
---|
98 | k = argv[i]; |
---|
99 | |
---|
100 | if ( strcmp(k, "--server") == 0 ) { |
---|
101 | server = argv[++i]; |
---|
102 | } else if ( strcmp(k, "--remote") == 0 ) { |
---|
103 | remote = argv[++i]; |
---|
104 | } else if ( strcmp(k, "--type") == 0 ) { |
---|
105 | type = parse_type(argv[++i]); |
---|
106 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
107 | rate = atoi(argv[++i]); |
---|
108 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
109 | bits = atoi(argv[++i]); |
---|
110 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
111 | channels = atoi(argv[++i]); |
---|
112 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
113 | codec = roar_str2codec(argv[++i]); |
---|
114 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
115 | usage(); |
---|
116 | return 0; |
---|
117 | } else { |
---|
118 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
119 | usage(); |
---|
120 | return 1; |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | switch (type & MT_MASK) { |
---|
125 | case MT_ROAR: |
---|
126 | switch (type & ST_MASK) { |
---|
127 | case ST_BIDIR: |
---|
128 | tmp = ROAR_DIR_BIDIR; |
---|
129 | break; |
---|
130 | case ST_FILTER: |
---|
131 | tmp = ROAR_DIR_FILTER; |
---|
132 | break; |
---|
133 | default: |
---|
134 | fprintf(stderr, "Error: unknown stream type\n"); |
---|
135 | return 2; |
---|
136 | } |
---|
137 | rfh = roar_simple_stream(rate, channels, bits, codec, remote, tmp, "roarinterconnect"); |
---|
138 | break; |
---|
139 | #ifdef ROAR_HAVE_ESD |
---|
140 | case MT_ESD: |
---|
141 | if ( (type & ST_MASK) != ST_FILTER ) { |
---|
142 | fprintf(stderr, "Error: server type only supports stream type filter\n"); |
---|
143 | return 2; |
---|
144 | } |
---|
145 | |
---|
146 | tmp = ESD_STREAM|ESD_PLAY; |
---|
147 | |
---|
148 | switch (bits) { |
---|
149 | case 8: tmp |= ESD_BITS8; break; |
---|
150 | case 16: tmp |= ESD_BITS16; break; |
---|
151 | default: |
---|
152 | fprintf(stderr, "Error: EsounD only supports 8 and 16 bit streams\n"); |
---|
153 | return 2; |
---|
154 | } |
---|
155 | |
---|
156 | switch (channels) { |
---|
157 | case 1: tmp |= ESD_MONO; break; |
---|
158 | case 2: tmp |= ESD_STEREO; break; |
---|
159 | default: |
---|
160 | fprintf(stderr, "Error: EsounD only supports mono and stereo streams\n"); |
---|
161 | return 2; |
---|
162 | } |
---|
163 | |
---|
164 | rfh = esd_filter_stream(tmp, rate, remote, "roarinterconnect"); |
---|
165 | break; |
---|
166 | #endif |
---|
167 | default: |
---|
168 | fprintf(stderr, "Error: unknown/not supported server type\n"); |
---|
169 | return 2; |
---|
170 | } |
---|
171 | |
---|
172 | if ( rfh == -1 ) { |
---|
173 | fprintf(stderr, "Error: can not connect to remote server\n"); |
---|
174 | return 10; |
---|
175 | } |
---|
176 | |
---|
177 | if ( roar_simple_connect(con, server, "roarinterconnect") == -1 ) { |
---|
178 | fprintf(stderr, "Can not connect to local server\n"); |
---|
179 | return 20; |
---|
180 | } |
---|
181 | |
---|
182 | if ( roar_stream_new(stream, rate, channels, bits, codec) == -1 ) { |
---|
183 | roar_disconnect(con); |
---|
184 | return 21; |
---|
185 | } |
---|
186 | |
---|
187 | if ( roar_stream_connect(con, stream, ROAR_DIR_BIDIR) == -1 ) { |
---|
188 | roar_disconnect(con); |
---|
189 | return 22; |
---|
190 | } |
---|
191 | |
---|
192 | if ( roar_stream_passfh(con, stream, rfh) == -1 ) { |
---|
193 | roar_disconnect(con); |
---|
194 | return 23; |
---|
195 | } |
---|
196 | |
---|
197 | roar_simple_close(rfh); |
---|
198 | |
---|
199 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
200 | fprintf(stderr, "Can not attach remote stream to local server\n"); |
---|
201 | } |
---|
202 | |
---|
203 | roar_disconnect(con); |
---|
204 | |
---|
205 | return 0; |
---|
206 | } |
---|
207 | |
---|
208 | //ll |
---|