source: roaraudio/roarclients/roarmon.c @ 6052:d48765b2475e

Last change on this file since 6052:d48765b2475e was 6052:d48765b2475e, checked in by phi, 9 years ago

updated copyright headers

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