source: roaraudio/roarclients/roarbidir.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: 4.4 KB
Line 
1//roarbidir.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("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
46int 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   ROAR_CKHAVEARGS(1);
72   server = argv[++i];
73  } else if ( strcmp(k, "--rate") == 0 || strcmp(k, "-R") == 0 ) {
74   ROAR_CKHAVEARGS(1);
75   info.rate = roar_str2rate(argv[++i]);
76  } else if ( strcmp(k, "--bits") == 0 || strcmp(k, "-B") == 0 ) {
77   ROAR_CKHAVEARGS(1);
78   info.bits = roar_str2bits(argv[++i]);
79  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 || strcmp(k, "-C") == 0 ) {
80   ROAR_CKHAVEARGS(1);
81   info.channels = roar_str2channels(argv[++i]);
82  } else if ( strcmp(k, "--codec") == 0 || strcmp(k, "-E") == 0 ) {
83   ROAR_CKHAVEARGS(1);
84   info.codec = roar_str2codec(argv[++i]);
85  } else if ( !strcmp(k, "--aiprofile") ) {
86   ROAR_CKHAVEARGS(1);
87   if ( roar_profile2info(&info, argv[++i]) == -1 ) {
88    fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error));
89    return 1;
90   }
91  } else if ( strcmp(k, "--help") == 0 ) {
92   usage();
93   return 0;
94  } else if ( in == NULL ) {
95   if ( roar_vio_open_dstr(&in_store, k, &def, 1) == -1 ) {
96    fprintf(stderr, "Error: can not open file: %s: %s\n", k, roar_error2str(roar_error));
97    return 1;
98   }
99   in = &in_store;
100  } else {
101   fprintf(stderr, "Error: unknown argument: %s\n", k);
102   usage();
103   return 1;
104  }
105 }
106
107 if ( (vss = roar_vs_new_simple(server, "roarbidir",
108                                info.rate, info.channels, info.codec, info.bits,
109                                ROAR_DIR_BIDIR, &err)) == NULL ) {
110  fprintf(stderr, "Error: can not start playback: %s\n", roar_error2str(err));
111  if ( in != NULL )
112   roar_vio_close(in);
113  return 1;
114 }
115
116 if ( in  == NULL )
117  in  = roar_stdin;
118 if ( out == NULL )
119  out = roar_stdout;
120
121 vss_vio = roar_vs_vio_obj(vss, NULL);
122
123 while (1) {
124  memset(vios, 0, sizeof(vios));
125
126  ROAR_VIO_SELECT_SETVIO(&(vios[0]), vss_vio, ROAR_VIO_SELECT_READ);
127  ROAR_VIO_SELECT_SETVIO(&(vios[1]), in, ROAR_VIO_SELECT_READ);
128
129  if ( (ret = roar_vio_select(vios, 2, NULL, NULL)) == -1 )
130   break;
131
132  if ( ret < 0 )
133   continue;
134
135  if ( vios[0].eventsa & ROAR_VIO_SELECT_READ ) {
136   if ( (ret = roar_vs_read(vss, buf, sizeof(buf), NULL)) == -1 )
137    break;
138   if ( roar_vio_write(out, buf, ret) != ret )
139    break;
140  }
141  if ( vios[1].eventsa & ROAR_VIO_SELECT_READ ) {
142   if ( (ret = roar_vio_read(in, buf, sizeof(buf))) == -1 )
143    break;
144   if ( roar_vs_write(vss, buf, ret, NULL) != ret )
145    break;
146  }
147 }
148
149 roar_vs_close(vss, ROAR_VS_TRUE, NULL);
150
151 roar_vio_close(in);
152
153 return 0;
154}
155
156//ll
Note: See TracBrowser for help on using the repository browser.