source: roaraudio/roarclients/roarmon.c @ 4045:24979f240e9c

Last change on this file since 4045:24979f240e9c was 4045:24979f240e9c, checked in by phi, 14 years ago

don't use legacy function roar_get_connection_vio()

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