source: roaraudio/roarclients/roarmon.c @ 5439:7950543cabbc

Last change on this file since 5439:7950543cabbc was 5381:430b1d26e12d, checked in by phi, 12 years ago

updated copyright years

File size: 7.4 KB
Line 
1//roarmon.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include <roaraudio.h>
27
28#define BUFSIZE 1024
29
30void usage (void) {
31 printf("roarmon [OPTIONS]... [FILE]\n");
32
33 printf("\nOptions:\n\n");
34
35 printf("  --server   SERVER    - Set server hostname\n"
36        "  --rate  -R RATE      - Set sample rate\n"
37        "  --bits  -B BITS      - Set bits per sample\n"
38        "  --chans -C CHANNELS  - Set number of channels\n"
39        "  --codec    CODEC     - Set the codec\n"
40        "  --record             - Run in record mode (Wave Audio only)\n"
41        "  --wave               - Output Wave Audio (PCM)\n"
42        "  --midi               - Output MIDI Audio\n"
43        "  --light              - Output light control\n"
44        "  --raw                - Output raw data\n"
45        "  --complex            - Output complex data\n"
46        "  --rdtcs              - Output Radio Data and Transmitter Control System data\n"
47        "  --thru               - Output copy of other stream\n"
48        "  --prethru            - Sets prethru flag on stream\n"
49        "  --rel-id ID          - Set ID of relative stream\n"
50        "  --help               - Show this help\n"
51       );
52
53}
54
55int main (int argc, char * argv[]) {
56 int    rate     = -1;
57 int    bits     = -1;
58 int    channels = -1;
59 int    codec    = -1;
60 int    dir      = ROAR_DIR_MONITOR;
61 int    rel_id   = -1;
62 char * server   = NULL;
63 char * k;
64 int    i;
65 int    prethru  = 0;
66 struct roar_connection    con;
67 struct roar_stream        s;
68 struct roar_vio_calls     file, * stream;
69 struct roar_vio_defaults  def;
70 int file_opened = 0;
71
72 if ( roar_vio_open_fh(&file, ROAR_STDOUT) == -1 )
73  return 1;
74
75 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_CREAT|O_TRUNC|O_WRONLY, 0644) == -1 )
76  return 1;
77
78 for (i = 1; i < argc; i++) {
79  k = argv[i];
80
81 //         esdmon [-s server ][-b] [-m] [-r freq] < file
82
83  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
84   server = argv[++i];
85  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
86   rate = roar_str2rate(argv[++i]);
87  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
88   bits = roar_str2bits(argv[++i]);
89  } else if ( !strcmp(k, "-b") ) {
90   bits = 8;
91  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
92   channels = roar_str2channels(argv[++i]);
93  } else if ( !strcmp(k, "-m") ) {
94   channels = 1;
95  } else if ( !strcmp(k, "--codec") ) {
96   if ( (codec = roar_str2codec(argv[++i])) == -1 ) {
97    fprintf(stderr, "Error: Unknown codec: %s\n", argv[i]);
98    return 1;
99   }
100
101  } else if ( !strcmp(k, "--wave") ) {
102   dir   = ROAR_DIR_MONITOR;
103  } else if ( !strcmp(k, "--record") ) {
104   dir   = ROAR_DIR_RECORD;
105  } else if ( !strcmp(k, "--midi") ) {
106   dir      = ROAR_DIR_MIDI_OUT;
107  } else if ( !strcmp(k, "--light") ) {
108   dir   = ROAR_DIR_LIGHT_OUT;
109  } else if ( !strcmp(k, "--raw") ) {
110   dir   = ROAR_DIR_RAW_OUT;
111  } else if ( !strcmp(k, "--complex") ) {
112   dir   = ROAR_DIR_COMPLEX_OUT;
113  } else if ( !strcmp(k, "--rdtcs") ) {
114   dir   = ROAR_DIR_RDTCS_OUT;
115  } else if ( !strcmp(k, "--thru") ) {
116   dir   = ROAR_DIR_THRU;
117  } else if ( !strcmp(k, "--rel-id") ) {
118   rel_id = atoi(argv[++i]);
119
120  } else if ( !strcmp(k, "--prethru") ) {
121   prethru = 1;
122
123  } else if ( !strcmp(k, "--help") || !strcmp(k, "-h") ) {
124   usage();
125   return 0;
126  } else if ( !file_opened ) {
127   file_opened = 1;
128   if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) {
129    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
130    return 1;
131   }
132  } else {
133   fprintf(stderr, "Error: unknown argument: %s\n", k);
134   usage();
135   return 1;
136  }
137 }
138
139 switch (dir) {
140  case ROAR_DIR_MONITOR:
141  case ROAR_DIR_RECORD:
142    if ( rate     == -1 ) rate     = ROAR_RATE_DEFAULT;
143    if ( bits     == -1 ) bits     = ROAR_BITS_DEFAULT;
144    if ( channels == -1 ) channels = ROAR_CHANNELS_DEFAULT;
145    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT;
146   break;
147  case ROAR_DIR_MIDI_OUT:
148    if ( rate     == -1 ) rate     = 0;
149    if ( bits     == -1 ) bits     = ROAR_MIDI_BITS;
150    if ( channels == -1 ) channels = ROAR_MIDI_CHANNELS_DEFAULT;
151    if ( codec    == -1 ) codec    = ROAR_CODEC_MIDI;
152   break;
153  case ROAR_DIR_LIGHT_OUT:
154    if ( rate     == -1 ) rate     = 0;
155    if ( bits     == -1 ) bits     = ROAR_LIGHT_BITS;
156    if ( channels == -1 ) channels = 0;
157    if ( codec    == -1 ) codec    = ROAR_CODEC_DMX512;
158   break;
159  case ROAR_DIR_COMPLEX_OUT:
160    if ( rate     == -1 ) rate     = ROAR_COMPLEX_RATE;
161    if ( bits     == -1 ) bits     = ROAR_COMPLEX_BITS;
162    if ( channels == -1 ) channels = ROAR_COMPLEX_CHANNELS;
163    if ( codec    == -1 ) codec    = ROAR_COMPLEX_CODEC;
164   break;
165  case ROAR_DIR_RDTCS_OUT:
166    if ( rate     == -1 ) rate     = ROAR_RDTCS_RATE;
167    if ( bits     == -1 ) bits     = ROAR_RDTCS_BITS;
168    if ( channels == -1 ) channels = ROAR_RDTCS_CHANNELS;
169    if ( codec    == -1 ) codec    = ROAR_RDTCS_CODEC;
170   break;
171  case ROAR_DIR_RAW_OUT:
172  case ROAR_DIR_THRU:
173  default:
174    if ( rate     == -1 ) rate     = 0;
175    if ( bits     == -1 ) bits     = 0;
176    if ( channels == -1 ) channels = 0;
177    if ( codec    == -1 ) codec    = ROAR_CODEC_DEFAULT;
178   break;
179 }
180
181 if ( roar_simple_connect(&con, server, "roarmon") == -1 ) {
182  fprintf(stderr, "Error: can not connect to server\n");
183  return 10;
184 }
185
186 if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) {
187  fprintf(stderr, "Error: can not create stream\n");
188  roar_disconnect(&con);
189  return 20;
190 }
191
192 if ( rel_id != -1 ) {
193  if ( roar_stream_set_rel_id(&s, rel_id) ) {
194   fprintf(stderr, "Error: can not set id or realative stream\n");
195   roar_disconnect(&con);
196   return 21;
197  }
198 }
199
200 if ( roar_stream_connect(&con, &s, dir, -1) == -1 ) {
201  fprintf(stderr, "Error: can not connect stream to server\n");
202  roar_disconnect(&con);
203  return 11;
204 }
205
206 if ( prethru ) {
207  if ( roar_stream_set_flags(&con, &s, ROAR_FLAG_PRETHRU, ROAR_SET_FLAG) == -1 ) {
208   fprintf(stderr, "Error: can not set prethru flag on stream\n");
209   roar_disconnect(&con);
210   return 14;
211  }
212 }
213
214 if ( roar_stream_exec(&con, &s) == -1 ) {
215  fprintf(stderr, "Error: can not exec stream\n");
216  roar_disconnect(&con);
217  return 12;
218 }
219
220 if ( (stream = roar_get_connection_vio2(&con)) == NULL ) {
221  fprintf(stderr, "Error: can not get stream vio\n");
222  roar_disconnect(&con);
223  return 13;
224 }
225
226// TODO: FIXME:
227// ROAR_SHUTDOWN(fh, SHUT_WR); // we need to have something do do shutdowns here...
228
229 if ( roar_vio_copy_data(&file, stream) == -1 ) {
230  fprintf(stderr, "Error: can not copy data from stream to destination\n");
231  roar_vio_close(stream);
232  roar_vio_close(&file);
233  return 14;
234 }
235
236 roar_vio_close(stream);
237 roar_vio_close(&file);
238
239 return 0;
240}
241
242//ll
Note: See TracBrowser for help on using the repository browser.