1 | //roarcatplay.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 | |
---|
30 | void usage (void) { |
---|
31 | printf("roarcatplay [OPTIONS]... [FILE]\n"); |
---|
32 | |
---|
33 | printf("\nOptions:\n\n"); |
---|
34 | |
---|
35 | printf(" --server SERVER - Set server hostname\n" |
---|
36 | " --simple - Use the simple interface (default)\n" |
---|
37 | " --verbose - Use verbose output\n" |
---|
38 | " --rate -R RATE - Set sample rate\n" |
---|
39 | " --bits -B BITS - Set bits per sample\n" |
---|
40 | " --chans -C CHANNELS - Set number of channels\n" |
---|
41 | " --codec -E CODEC - Set the codec\n" |
---|
42 | " --aiprofile PROFILE - Set audio profile\n" |
---|
43 | " --help - Show this help\n" |
---|
44 | ); |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | int main (int argc, char * argv[]) { |
---|
49 | struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, |
---|
50 | .bits = ROAR_BITS_DEFAULT, |
---|
51 | .channels = ROAR_CHANNELS_DEFAULT, |
---|
52 | .codec = ROAR_AUDIO_INFO_INVALID}; |
---|
53 | int auinfo_changed = 0; |
---|
54 | const char * server = NULL; |
---|
55 | const char * file = NULL; |
---|
56 | const char * k; |
---|
57 | int i; |
---|
58 | int verbose = 0; |
---|
59 | roar_vs_t * vss; |
---|
60 | int err; |
---|
61 | |
---|
62 | for (i = 1; i < argc; i++) { |
---|
63 | k = argv[i]; |
---|
64 | |
---|
65 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
66 | ROAR_CKHAVEARGS(1); |
---|
67 | server = argv[++i]; |
---|
68 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
69 | /* no op */ |
---|
70 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
71 | verbose++; |
---|
72 | } else if ( strcmp(k, "-n") == 0 ) { |
---|
73 | ROAR_CKHAVEARGS(1); |
---|
74 | i++; |
---|
75 | roar_debug_option_obsolete(argv[0], "-n", NULL, "Will ignore it for now."); |
---|
76 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-R") ) { |
---|
77 | ROAR_CKHAVEARGS(1); |
---|
78 | info.rate = roar_str2rate(argv[++i]); |
---|
79 | auinfo_changed = 1; |
---|
80 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
81 | ROAR_CKHAVEARGS(1); |
---|
82 | info.bits = roar_str2bits(argv[++i]); |
---|
83 | auinfo_changed = 1; |
---|
84 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
85 | ROAR_CKHAVEARGS(1); |
---|
86 | info.channels = roar_str2channels(argv[++i]); |
---|
87 | auinfo_changed = 1; |
---|
88 | } else if ( !strcmp(k, "--codec") || !strcmp(k, "-E") ) { |
---|
89 | ROAR_CKHAVEARGS(1); |
---|
90 | info.codec = roar_str2codec(argv[++i]); |
---|
91 | auinfo_changed = 1; |
---|
92 | } else if ( !strcmp(k, "--aiprofile") ) { |
---|
93 | ROAR_CKHAVEARGS(1); |
---|
94 | if ( roar_profile2info(&info, argv[++i]) == -1 ) { |
---|
95 | fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error)); |
---|
96 | return 1; |
---|
97 | } |
---|
98 | auinfo_changed = 1; |
---|
99 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
100 | usage(); |
---|
101 | return 0; |
---|
102 | } else if ( file == NULL ) { |
---|
103 | file = argv[i]; |
---|
104 | } else { |
---|
105 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
106 | usage(); |
---|
107 | return 1; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | if ( file == NULL ) |
---|
112 | file = "fh:stdin"; |
---|
113 | |
---|
114 | if ( info.codec == ROAR_AUDIO_INFO_INVALID ) |
---|
115 | info.codec = ROAR_CODEC_DEFAULT; |
---|
116 | |
---|
117 | if ( (vss = roar_vs_new(server, "roarcatplay", &err)) == NULL ) { |
---|
118 | fprintf(stderr, "Error: can not connect to server: %s: %s\n", |
---|
119 | server == NULL ? "(default)" : server, roar_error2str(err)); |
---|
120 | return 10; |
---|
121 | } |
---|
122 | |
---|
123 | if ( auinfo_changed ) { |
---|
124 | if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) { |
---|
125 | fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err)); |
---|
126 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
127 | return 10; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | if ( roar_vs_file_simple(vss, file, &err) == -1 ) { |
---|
132 | fprintf(stderr, "Error: can not open file: %s: %s\n", file, roar_error2str(err)); |
---|
133 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
134 | return 10; |
---|
135 | } |
---|
136 | |
---|
137 | roar_vs_run(vss, NULL); |
---|
138 | roar_vs_sync(vss, ROAR_VS_WAIT, NULL); |
---|
139 | roar_vs_close(vss, ROAR_VS_FALSE, NULL); |
---|
140 | |
---|
141 | return 0; |
---|
142 | } |
---|
143 | |
---|
144 | //ll |
---|