source: roaraudio/roarclients/roarcatvio.c @ 4708:c9d40761088a

Last change on this file since 4708:c9d40761088a was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 3.3 KB
Line 
1//roarcatvio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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 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[]) {
46 int    rate     = ROAR_RATE_DEFAULT;
47 int    bits     = ROAR_BITS_DEFAULT;
48 int    channels = ROAR_CHANNELS_DEFAULT;
49 int    codec    = -1;
50 char * server   = NULL;
51 char * k;
52 int    i;
53 char * name = "roarcatvio";
54 struct roar_vio_calls file, stream;
55 struct roar_vio_defaults def;
56 int file_opened = 0;
57 const char * content_type;
58
59 if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 )
60  return 1;
61
62 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 )
63  return 1;
64
65 for (i = 1; i < argc; i++) {
66  k = argv[i];
67
68  if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) {
69   server = argv[++i];
70  } else if ( !strcmp(k, "-n") ) {
71   name = argv[++i];
72  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) {
73   rate = atoi(argv[++i]);
74  } else if ( !strcmp(k, "--bits") ) {
75   bits = atoi(argv[++i]);
76  } else if ( !strcmp(k, "-b") ) {
77   bits = 8;
78  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) {
79   channels = atoi(argv[++i]);
80  } else if ( !strcmp(k, "-m") ) {
81   channels = 1;
82  } else if ( !strcmp(k, "--codec") ) {
83   codec = roar_str2codec(argv[++i]);
84  } else if ( !strcmp(k, "--help") ) {
85   usage();
86   return 0;
87  } else if ( !file_opened ) {
88   file_opened = 1;
89   if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) {
90    fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno));
91    return 1;
92   }
93
94   if ( codec == -1 ) {
95    if ( roar_vio_ctl(&file, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) != -1 ) {
96     codec = roar_mime2codec(content_type);
97    }
98   }
99  } else {
100   fprintf(stderr, "Error: unknown argument: %s\n", k);
101   usage();
102   return 1;
103  }
104 }
105
106 if ( codec == -1 )
107  codec = ROAR_CODEC_DEFAULT;
108
109 if ( roar_vio_simple_stream(&stream, rate, channels, bits, codec, server, ROAR_DIR_PLAY, name) == -1 ) {
110  fprintf(stderr, "Error: can not start playback\n");
111  return 1;
112 }
113
114 roar_vio_copy_data(&stream, &file);
115
116 roar_vio_close(&file);
117 roar_vio_close(&stream);
118
119 return 0;
120}
121
122//ll
Note: See TracBrowser for help on using the repository browser.