source: roaraudio/roarclients/roarbidir.c @ 5439:7950543cabbc

Last change on this file since 5439:7950543cabbc was 5381:430b1d26e12d, checked in by phi, 12 years ago

updated copyright years

File size: 3.9 KB
RevLine 
[826]1//roarbidir.c:
2
3/*
[5381]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
[826]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[826]23 *
24 */
25
26#include <roaraudio.h>
27
28#define BUFSIZE 1024
29
30void usage (void) {
[2230]31 printf("roarbidir [OPTIONS]... [IN_FILE]\n");
[826]32
33 printf("\nOptions:\n\n");
34
35 printf("  --server SERVER    - Set server hostname\n"
36        "  --rate   RATE      - Set sample rate\n"
37        "  --bits   BITS      - Set bits per sample\n"
38        "  --chans  CHANNELS  - Set number of channels\n"
39        "  --codec  CODEC     - Set the codec\n"
40        "  --help             - Show this help\n"
41       );
42
43}
44
45int main (int argc, char * argv[]) {
[4883]46 int    rate     = ROAR_RATE_DEFAULT;
47 int    bits     = ROAR_BITS_DEFAULT;
48 int    channels = ROAR_CHANNELS_DEFAULT;
[826]49 int    codec    = ROAR_CODEC_DEFAULT;
50 char * server   = NULL;
51 char * k;
52 int    i;
[5022]53 struct roar_vio_defaults  def;
54 struct roar_vio_calls in_store;
55 struct roar_vio_calls * in = NULL, * out = NULL;
56 struct roar_vio_calls * vss_vio = NULL;
57 roar_vs_t * vss;
58 struct roar_vio_select vios[2];
[826]59 char buf[BUFSIZE];
[5022]60 int err;
61 ssize_t ret;
62
63 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 )
64  return 1;
[826]65
66 for (i = 1; i < argc; i++) {
67  k = argv[i];
68
69  if ( strcmp(k, "--server") == 0 ) {
70   server = argv[++i];
71  } else if ( strcmp(k, "--rate") == 0 ) {
[4883]72   rate = roar_str2rate(argv[++i]);
[826]73  } else if ( strcmp(k, "--bits") == 0 ) {
[4883]74   bits = roar_str2bits(argv[++i]);
[826]75  } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) {
[4883]76   channels = roar_str2channels(argv[++i]);
[826]77  } else if ( strcmp(k, "--codec") == 0 ) {
78   codec = roar_str2codec(argv[++i]);
79  } else if ( strcmp(k, "--help") == 0 ) {
80   usage();
81   return 0;
[5022]82  } else if ( in == NULL ) {
83   if ( roar_vio_open_dstr(&in_store, k, &def, 1) == -1 ) {
84    fprintf(stderr, "Error: can not open file: %s: %s\n", k, roar_error2str(roar_error));
[826]85    return 1;
86   }
[5022]87   in = &in_store;
[826]88  } else {
89   fprintf(stderr, "Error: unknown argument: %s\n", k);
90   usage();
91   return 1;
92  }
93 }
94
[5022]95 if ( (vss = roar_vs_new_simple(server, "roarbidir", rate, channels, codec, bits, ROAR_DIR_BIDIR, &err)) == NULL ) {
96  fprintf(stderr, "Error: can not start playback: %s\n", roar_error2str(err));
97  if ( in != NULL )
98   roar_vio_close(in);
[826]99  return 1;
100 }
101
[5022]102 if ( in  == NULL )
103  in  = roar_stdin;
104 if ( out == NULL )
105  out = roar_stdout;
[826]106
[5022]107 vss_vio = roar_vs_vio_obj(vss, NULL);
[826]108
[5022]109 while (1) {
110  memset(vios, 0, sizeof(vios));
111
112  ROAR_VIO_SELECT_SETVIO(&(vios[0]), vss_vio, ROAR_VIO_SELECT_READ);
113  ROAR_VIO_SELECT_SETVIO(&(vios[1]), in, ROAR_VIO_SELECT_READ);
[826]114
[5022]115  if ( (ret = roar_vio_select(vios, 2, NULL, NULL)) == -1 )
116   break;
117
118  if ( ret < 0 )
119   continue;
[826]120
[5022]121  if ( vios[0].eventsa & ROAR_VIO_SELECT_READ ) {
122   if ( (ret = roar_vs_read(vss, buf, sizeof(buf), NULL)) == -1 )
123    break;
124   if ( roar_vio_write(out, buf, ret) != ret )
125    break;
126  }
127  if ( vios[1].eventsa & ROAR_VIO_SELECT_READ ) {
128   if ( (ret = roar_vio_read(in, buf, sizeof(buf))) == -1 )
129    break;
130   if ( roar_vs_write(vss, buf, ret, NULL) != ret )
131    break;
[826]132  }
133 }
134
[5022]135 roar_vs_close(vss, ROAR_VS_TRUE, NULL);
[826]136
[5022]137 roar_vio_close(in);
[826]138
139 return 0;
140}
141
142//ll
Note: See TracBrowser for help on using the repository browser.