source: roaraudio/roarclients/roarinterconnect.c @ 2227:802529aa529d

Last change on this file since 2227:802529aa529d was 2227:802529aa529d, checked in by phi, 15 years ago

added theoretical esd support

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