source: roaraudio/roarclients/roarinterconnect.c @ 3009:07e6298a0c23

Last change on this file since 3009:07e6298a0c23 was 3009:07e6298a0c23, checked in by phi, 15 years ago

spacing

File size: 6.8 KB
Line 
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_NONE     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#define ST_TRANSMIT 0x03
42#define ST_RECEIVE  0x04
43// no default here as the default depend on the server type
44
45void usage (void) {
46 printf("roarinterconnect [OPTIONS]...\n");
47
48 printf("\nOptions:\n\n");
49
50 printf("  --server SERVER    - Set server hostname\n"
51        "  --remote SERVER    - Set remote server\n"
52        "  --type   TYPE      - Set type of remote server\n"
53        "  --rate   RATE      - Set sample rate\n"
54        "  --bits   BITS      - Set bits per sample\n"
55        "  --chans  CHANNELS  - Set number of channels\n"
56        "  --codec  CODEC     - Set the codec\n"
57        "  --help             - Show this help\n"
58       );
59
60}
61
62int parse_type (char * type) {
63 int ret = MT_NONE|ST_NONE;
64 char * colon;
65
66 if ( type != NULL ) {
67  while (type != NULL && *type) {
68   if ( (colon = strstr(type, ":")) != NULL ) {
69    *colon = 0;
70     colon++;
71   }
72
73   if ( !strcmp(type, "roar") ) {
74    ret -= ret & MT_MASK;
75    ret += MT_ROAR;
76   } else if ( !strcmp(type, "esd") ) {
77    ret -= ret & MT_MASK;
78    ret += MT_ESD;
79   } else if ( !strcmp(type, "bidir") ) {
80    ret -= ret & ST_MASK;
81    ret += ST_BIDIR;
82   } else if ( !strcmp(type, "filter") ) {
83    ret -= ret & ST_MASK;
84    ret += ST_FILTER;
85   } else if ( !strcmp(type, "transmit") ) {
86    ret -= ret & ST_MASK;
87    ret += ST_TRANSMIT;
88   } else if ( !strcmp(type, "receive") ) {
89    ret -= ret & ST_MASK;
90    ret += ST_RECEIVE;
91   } else {
92    return MT_NONE|ST_NONE;
93   }
94
95   type = colon;
96  }
97 }
98
99 if ( (ret & MT_MASK) == MT_NONE )
100  ret |= MT_DEFAULT;
101
102 if ( (ret & ST_MASK) == ST_NONE ) {
103  switch (ret & MT_MASK) {
104   case MT_ROAR: ret |= ST_BIDIR;  break;
105   case MT_ESD:  ret |= ST_FILTER; break;
106   default:
107     return MT_NONE|ST_NONE; // error case
108    break;
109  }
110 }
111
112 return ret;
113}
114
115int main (int argc, char * argv[]) {
116 struct roar_connection con[1];
117 struct roar_stream     stream[1];
118 int    rate     = 44100;
119 int    bits     = 16;
120 int    channels = 2;
121 int    codec    = ROAR_CODEC_DEFAULT;
122 int    type     = parse_type(NULL);
123 int    tmp;
124 char * server   = NULL;
125 char * remote   = NULL;
126 char * k;
127 int    rfh;
128 int    i;
129 int    localdir = ROAR_DIR_BIDIR;
130
131 for (i = 1; i < argc; i++) {
132  k = argv[i];
133
134  if ( strcmp(k, "--server") == 0 ) {
135   server = argv[++i];
136  } else if ( strcmp(k, "--remote") == 0 ) {
137   remote = argv[++i];
138  } else if ( strcmp(k, "--type") == 0 ) {
139   type = parse_type(argv[++i]);
140  } else if ( strcmp(k, "--rate") == 0 ) {
141   rate = atoi(argv[++i]);
142  } else if ( strcmp(k, "--bits") == 0 ) {
143   bits = atoi(argv[++i]);
144  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) {
145   channels = atoi(argv[++i]);
146  } else if ( strcmp(k, "--codec") == 0 ) {
147   codec = roar_str2codec(argv[++i]);
148  } else if ( strcmp(k, "--help") == 0 ) {
149   usage();
150   return 0;
151  } else {
152   fprintf(stderr, "Error: unknown argument: %s\n", k);
153   usage();
154   return 1;
155  }
156 }
157
158 switch (type & MT_MASK) {
159  case MT_ROAR:
160    switch (type & ST_MASK) {
161     case ST_BIDIR:
162       tmp      = ROAR_DIR_BIDIR;
163      break;
164     case ST_FILTER:
165       tmp      = ROAR_DIR_FILTER;
166      break;
167     case ST_TRANSMIT:
168       tmp      = ROAR_DIR_PLAY;
169       localdir = ROAR_DIR_MONITOR;
170      break;
171     case ST_RECEIVE:
172       tmp      = ROAR_DIR_MONITOR;
173       localdir = ROAR_DIR_PLAY;
174      break;
175     default:
176       fprintf(stderr, "Error: unknown stream type\n");
177       return 2;
178    }
179    rfh = roar_simple_stream(rate, channels, bits, codec, remote, tmp, "roarinterconnect");
180   break;
181#ifdef ROAR_HAVE_ESD
182  case MT_ESD:
183    tmp = ESD_STREAM|ESD_PLAY;
184
185    switch (bits) {
186     case  8: tmp |= ESD_BITS8;  break;
187     case 16: tmp |= ESD_BITS16; break;
188     default:
189       fprintf(stderr, "Error: EsounD only supports 8 and 16 bit streams\n");
190       return 2;
191    }
192
193    switch (channels) {
194     case 1: tmp |= ESD_MONO;   break;
195     case 2: tmp |= ESD_STEREO; break;
196     default:
197       fprintf(stderr, "Error: EsounD only supports mono and stereo streams\n");
198       return 2;
199    }
200
201    // this is only true if the esd runs on a LE system,...
202    if ( bits == 8 && codec != ROAR_CODEC_PCM_U_LE ) {
203     fprintf(stderr, "Error: EsounD only supports unsigned PCM in 8 bit mode\n");
204     return 2;
205    } else if ( bits == 16 && codec != ROAR_CODEC_DEFAULT ) {
206     fprintf(stderr, "Error: EsounD only supports signed PCM in 16 bit mode\n");
207     return 2;
208    }
209
210    switch (type & ST_MASK) {
211     case ST_FILTER:
212       rfh = esd_filter_stream(tmp, rate, remote, "roarinterconnect");
213      break;
214     case ST_TRANSMIT:
215       rfh = esd_play_stream(tmp, rate, remote, "roarinterconnect");
216      break;
217     case ST_RECEIVE:
218       rfh = esd_monitor_stream(tmp, rate, remote, "roarinterconnect");
219      break;
220     default:
221       fprintf(stderr, "Error: this type is not supported by EsounD\n");
222       return 2;
223      break;
224    }
225   break;
226#endif
227  default:
228    fprintf(stderr, "Error: unknown/not supported server type\n");
229    return 2;
230 }
231
232 if ( rfh == -1 ) {
233  fprintf(stderr, "Error: can not connect to remote server\n");
234  return 10;
235 }
236
237 if ( roar_simple_connect(con, server, "roarinterconnect") == -1 ) {
238  fprintf(stderr, "Can not connect to local server\n");
239  return 20;
240 }
241
242 if ( roar_stream_new(stream, rate, channels, bits, codec) == -1 ) {
243  roar_disconnect(con);
244  return 21;
245 }
246
247 if ( roar_stream_connect(con, stream, localdir) == -1 ) {
248  roar_disconnect(con);
249  return 22;
250 }
251
252 if ( roar_stream_passfh(con, stream, rfh) == -1 ) {
253  roar_disconnect(con);
254  return 23;
255 }
256
257 roar_simple_close(rfh);
258
259 if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
260  fprintf(stderr, "Can not attach remote stream to local server\n");
261 }
262
263 roar_disconnect(con);
264
265 return 0;
266}
267
268//ll
Note: See TracBrowser for help on using the repository browser.