source: roaraudio/roarclients/roarcatplay.c @ 5022:b2a2e896974d

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

Converted most roarclients to to use VS API (See: #87)

File size: 3.5 KB
Line 
1//roarcatplay.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("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        "  --passive          - Use passiv playback (experimental, works only localy)\n"
38        "  --background       - Use background playback, impleys passive mode\n"
39        "  --verbose          - Use verbose output\n"
40        "  --help             - Show this help\n"
41       );
42
43}
44
45#define MODE_SIMPLE  1
46#define MODE_PASSIVE 2
47
48int main (int argc, char * argv[]) {
49 char * server   = NULL;
50 char * k;
51 int    i;
52 char * file    = NULL;
53 int    mode    = MODE_SIMPLE;
54 int    bg      = 0;
55 int    verbose = 0;
56 roar_vs_t * vss;
57 int err;
58#ifdef ROAR_HAVE_UNIX
59 struct roar_connection con[1];
60 struct roar_stream     stream[1];
61#endif
62
63 for (i = 1; i < argc; i++) {
64  k = argv[i];
65
66  if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) {
67   server = argv[++i];
68  } else if ( strcmp(k, "--simple") == 0 ) {
69   mode = MODE_SIMPLE;
70  } else if ( strcmp(k, "--passive") == 0 ) {
71   mode = MODE_PASSIVE;
72  } else if ( strcmp(k, "--background") == 0 ) {
73   bg = 1;
74  } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) {
75   verbose++;
76  } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) {
77   usage();
78   return 0;
79  } else if ( file == NULL ) {
80   file = argv[i];
81  } else {
82   fprintf(stderr, "Error: unknown argument: %s\n", k);
83   usage();
84   return 1;
85  }
86 }
87
88 if ( bg )
89  mode = MODE_PASSIVE;
90
91#ifndef ROAR_HAVE_UNIX
92 if ( mode == MODE_PASSIVE ) {
93  fprintf(stderr, "Error: passive mode is not supported on this system.\n");
94  return 1;
95 }
96#endif
97
98 if ( file == NULL )
99  file = "/dev/stdin";
100
101#ifdef ROAR_HAVE_UNIX
102 if ( mode == MODE_PASSIVE ) {
103  if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) {
104   ROAR_ERR("Can not connect to server");
105   return 0;
106  }
107
108  if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) {
109   ROAR_ERR("Can not start playback");
110   return 1;
111  }
112
113  if ( bg ) {
114   if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
115    ROAR_ERR("Can not attach stream to server");
116   }
117  } else {
118   roar_sleep(10);
119  }
120
121  roar_disconnect(con);
122
123 } else { // MODE_SIMPLE
124#endif
125  if ( (vss = roar_vs_new_from_file(server, "roarcatplay", file, &err)) == NULL ) {
126   ROAR_ERR("Can not start playback: %s", roar_error2str(err));
127   return 1;
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#ifdef ROAR_HAVE_UNIX
133 }
134#endif
135
136 return 0;
137}
138
139//ll
Note: See TracBrowser for help on using the repository browser.