source: roaraudio/roarclients/roarcatplay.c @ 5949:9528e85ba67c

Last change on this file since 5949:9528e85ba67c was 5949:9528e85ba67c, checked in by phi, 11 years ago

Marked roarcatvio as obsolete. Added all unique features to roarcatplay.

File size: 4.3 KB
Line 
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
30void 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
48int 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   server = argv[++i];
67  } else if ( strcmp(k, "--simple") == 0 ) {
68   /* no op */
69  } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) {
70   verbose++;
71  } else if ( strcmp(k, "-n") == 0 ) {
72   roar_debug_option_obsolete(argv[0], "-n", NULL, "Will ignore it for now.");
73  } else if ( !strcmp(k, "--rate") || !strcmp(k, "-R") ) {
74   info.rate = roar_str2rate(argv[++i]);
75   auinfo_changed = 1;
76  } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) {
77   info.bits = roar_str2bits(argv[++i]);
78   auinfo_changed = 1;
79  } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) {
80   info.channels = roar_str2channels(argv[++i]);
81   auinfo_changed = 1;
82  } else if ( !strcmp(k, "--codec") || !strcmp(k, "-E") ) {
83   info.codec = roar_str2codec(argv[++i]);
84   auinfo_changed = 1;
85  } else if ( !strcmp(k, "--aiprofile") ) {
86   if ( roar_profile2info(&info, argv[++i]) == -1 ) {
87    fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error));
88    return 1;
89   }
90   auinfo_changed = 1;
91  } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) {
92   usage();
93   return 0;
94  } else if ( file == NULL ) {
95   file = argv[i];
96  } else {
97   fprintf(stderr, "Error: unknown argument: %s\n", k);
98   usage();
99   return 1;
100  }
101 }
102
103 if ( file == NULL )
104  file = "fh:stdin";
105
106 if ( info.codec == ROAR_AUDIO_INFO_INVALID )
107  info.codec = ROAR_CODEC_DEFAULT;
108
109 if ( (vss = roar_vs_new(server, "roarcatplay", &err)) == NULL ) {
110  fprintf(stderr, "Error: can not connect to server: %s: %s\n",
111   server == NULL ? "(default)" : server, roar_error2str(err));
112  return 10;
113 }
114
115 if ( auinfo_changed ) {
116  if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) {
117   fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err));
118   roar_vs_close(vss, ROAR_VS_TRUE, NULL);
119   return 10;
120  }
121 }
122
123 if ( roar_vs_file_simple(vss, file, &err) == -1 ) {
124  fprintf(stderr, "Error: can not open file: %s: %s\n", file, roar_error2str(err));
125  roar_vs_close(vss, ROAR_VS_TRUE, NULL);
126  return 10;
127 }
128
129 roar_vs_run(vss, NULL);
130 roar_vs_sync(vss, ROAR_VS_WAIT, NULL);
131 roar_vs_close(vss, ROAR_VS_FALSE, NULL);
132
133 return 0;
134}
135
136//ll
Note: See TracBrowser for help on using the repository browser.