source: roaraudio/roarclients/roarcatvio.c @ 5908:66940b2023ee

Last change on this file since 5908:66940b2023ee was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

File size: 4.1 KB
Line 
1//roarcatvio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013
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("roarcatvio [OPTIONS]... [FILE]\n");
32
33 printf("\nOptions:\n\n");
34
35 printf("  --server -s 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        "  --help                - Show this help\n"
42       );
43
44}
45
46int main (int argc, char * argv[]) {
47 struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT,
48                                .bits = ROAR_BITS_DEFAULT,
49                                .channels = ROAR_CHANNELS_DEFAULT,
50                                .codec = ROAR_AUDIO_INFO_INVALID};
51 int    auinfo_changed = 0;
52 const char * server   = NULL;
53 const char * k;
54 int    i;
55 const char * name = "roarcatvio";
56 roar_vs_t * vss;
57 const char * filename = NULL;
58 int err;
59
60 for (i = 1; i < argc; i++) {
61  k = argv[i];
62
63  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
64   server = argv[++i];
65  } else if ( !strcmp(k, "-n") ) {
66   name = argv[++i];
67  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") || !strcmp(k, "-R") ) {
68   info.rate = roar_str2rate(argv[++i]);
69   auinfo_changed = 1;
70  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
71   info.bits = roar_str2bits(argv[++i]);
72   auinfo_changed = 1;
73  } else if ( !strcmp(k, "-b") ) {
74   info.bits = 8;
75   auinfo_changed = 1;
76  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
77   info.channels = roar_str2channels(argv[++i]);
78   auinfo_changed = 1;
79  } else if ( !strcmp(k, "-m") ) {
80   info.channels = 1;
81   auinfo_changed = 1;
82  } else if ( !strcmp(k, "--codec") || !strcmp(k, "-E") ) {
83   info.codec = roar_str2codec(argv[++i]);
84   auinfo_changed = 1;
85  } else if ( !strcmp(k, "--aiprofile") ) {
86   if ( roar_profile2info(&info, argv[++i]) == -1 ) {
87    fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error));
88    return 1;
89   }
90   auinfo_changed = 1;
91  } else if ( !strcmp(k, "--help") ) {
92   usage();
93   return 0;
94  } else if ( filename == NULL ) {
95   filename    = k;
96  } else {
97   fprintf(stderr, "Error: unknown argument: %s\n", k);
98   usage();
99   return 1;
100  }
101 }
102
103 if ( info.codec == ROAR_AUDIO_INFO_INVALID )
104  info.codec = ROAR_CODEC_DEFAULT;
105
106 if ( (vss = roar_vs_new(server, name, &err)) == NULL ) {
107  fprintf(stderr, "Error: can not connect to server: %s: %s\n",
108   server == NULL ? "(default)" : server, roar_error2str(err));
109  return 10;
110 }
111
112 if ( auinfo_changed ) {
113  if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) {
114   fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err));
115   roar_vs_close(vss, ROAR_VS_TRUE, NULL);
116   return 10;
117  }
118 }
119
120 if ( roar_vs_file_simple(vss, filename, &err) == -1 ) {
121  fprintf(stderr, "Error: can not open file: %s: %s\n", filename, roar_error2str(err));
122  roar_vs_close(vss, ROAR_VS_TRUE, NULL);
123  return 10;
124 }
125
126 roar_vs_run(vss, NULL);
127
128 roar_vs_sync(vss, ROAR_VS_WAIT, NULL);
129 roar_vs_close(vss, ROAR_VS_FALSE, NULL);
130
131 return 0;
132}
133
134//ll
Note: See TracBrowser for help on using the repository browser.