1 | //roarbidir.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("roarbidir [OPTIONS]... [IN_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 | " --help - Show this help\n" |
---|
42 | ); |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | int main (int argc, char * argv[]) { |
---|
47 | struct roar_audio_info info; |
---|
48 | const char * server = NULL; |
---|
49 | const char * k; |
---|
50 | int i; |
---|
51 | struct roar_vio_defaults def; |
---|
52 | struct roar_vio_calls in_store; |
---|
53 | struct roar_vio_calls * in = NULL, * out = NULL; |
---|
54 | struct roar_vio_calls * vss_vio = NULL; |
---|
55 | roar_vs_t * vss; |
---|
56 | struct roar_vio_select vios[2]; |
---|
57 | char buf[BUFSIZE]; |
---|
58 | int err; |
---|
59 | ssize_t ret; |
---|
60 | |
---|
61 | if ( roar_profile2info(&info, "default") == -1 ) |
---|
62 | return 1; |
---|
63 | |
---|
64 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
65 | return 1; |
---|
66 | |
---|
67 | for (i = 1; i < argc; i++) { |
---|
68 | k = argv[i]; |
---|
69 | |
---|
70 | if ( strcmp(k, "--server") == 0 ) { |
---|
71 | server = argv[++i]; |
---|
72 | } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 ) { |
---|
73 | info.rate = roar_str2rate(argv[++i]); |
---|
74 | } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) { |
---|
75 | info.bits = roar_str2bits(argv[++i]); |
---|
76 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) { |
---|
77 | info.channels = roar_str2channels(argv[++i]); |
---|
78 | } else if ( strcmp(k, "--codec") == 0 || strcmp(k, "-E") == 0 ) { |
---|
79 | info.codec = roar_str2codec(argv[++i]); |
---|
80 | } else if ( !strcmp(k, "--aiprofile") ) { |
---|
81 | if ( roar_profile2info(&info, argv[++i]) == -1 ) { |
---|
82 | fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error)); |
---|
83 | return 1; |
---|
84 | } |
---|
85 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
86 | usage(); |
---|
87 | return 0; |
---|
88 | } else if ( in == NULL ) { |
---|
89 | if ( roar_vio_open_dstr(&in_store, k, &def, 1) == -1 ) { |
---|
90 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, roar_error2str(roar_error)); |
---|
91 | return 1; |
---|
92 | } |
---|
93 | in = &in_store; |
---|
94 | } else { |
---|
95 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
96 | usage(); |
---|
97 | return 1; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | if ( (vss = roar_vs_new_simple(server, "roarbidir", |
---|
102 | info.rate, info.channels, info.codec, info.bits, |
---|
103 | ROAR_DIR_BIDIR, &err)) == NULL ) { |
---|
104 | fprintf(stderr, "Error: can not start playback: %s\n", roar_error2str(err)); |
---|
105 | if ( in != NULL ) |
---|
106 | roar_vio_close(in); |
---|
107 | return 1; |
---|
108 | } |
---|
109 | |
---|
110 | if ( in == NULL ) |
---|
111 | in = roar_stdin; |
---|
112 | if ( out == NULL ) |
---|
113 | out = roar_stdout; |
---|
114 | |
---|
115 | vss_vio = roar_vs_vio_obj(vss, NULL); |
---|
116 | |
---|
117 | while (1) { |
---|
118 | memset(vios, 0, sizeof(vios)); |
---|
119 | |
---|
120 | ROAR_VIO_SELECT_SETVIO(&(vios[0]), vss_vio, ROAR_VIO_SELECT_READ); |
---|
121 | ROAR_VIO_SELECT_SETVIO(&(vios[1]), in, ROAR_VIO_SELECT_READ); |
---|
122 | |
---|
123 | if ( (ret = roar_vio_select(vios, 2, NULL, NULL)) == -1 ) |
---|
124 | break; |
---|
125 | |
---|
126 | if ( ret < 0 ) |
---|
127 | continue; |
---|
128 | |
---|
129 | if ( vios[0].eventsa & ROAR_VIO_SELECT_READ ) { |
---|
130 | if ( (ret = roar_vs_read(vss, buf, sizeof(buf), NULL)) == -1 ) |
---|
131 | break; |
---|
132 | if ( roar_vio_write(out, buf, ret) != ret ) |
---|
133 | break; |
---|
134 | } |
---|
135 | if ( vios[1].eventsa & ROAR_VIO_SELECT_READ ) { |
---|
136 | if ( (ret = roar_vio_read(in, buf, sizeof(buf))) == -1 ) |
---|
137 | break; |
---|
138 | if ( roar_vs_write(vss, buf, ret, NULL) != ret ) |
---|
139 | break; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
144 | |
---|
145 | roar_vio_close(in); |
---|
146 | |
---|
147 | return 0; |
---|
148 | } |
---|
149 | |
---|
150 | //ll |
---|