source: roaraudio/roarclients/roarcatplay.c @ 5220:df802906cfec

Last change on this file since 5220:df802906cfec was 5109:4f9fc788fe91, checked in by phi, 13 years ago

Started to use compiler attributes (Also see: #130)

File size: 3.6 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 ( mode == MODE_PASSIVE ) {
99  fprintf(stderr, "Warning: passive mode is obsoleted and will be removed soon.\n");
100 }
101
102 if ( file == NULL )
103  file = "/dev/stdin";
104
105#ifdef ROAR_HAVE_UNIX
106 if ( mode == MODE_PASSIVE ) {
107  if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) {
108   ROAR_ERR("Can not connect to server");
109   return 0;
110  }
111
112  if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) {
113   ROAR_ERR("Can not start playback");
114   return 1;
115  }
116
117  if ( bg ) {
118   if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
119    ROAR_ERR("Can not attach stream to server");
120   }
121  } else {
122   roar_sleep(10);
123  }
124
125  roar_disconnect(con);
126
127 } else { // MODE_SIMPLE
128#endif
129  if ( (vss = roar_vs_new_from_file(server, "roarcatplay", file, &err)) == NULL ) {
130   ROAR_ERR("Can not start playback: %s", roar_error2str(err));
131   return 1;
132  }
133  roar_vs_run(vss, NULL);
134  roar_vs_sync(vss, ROAR_VS_WAIT, NULL);
135  roar_vs_close(vss, ROAR_VS_FALSE, NULL);
136#ifdef ROAR_HAVE_UNIX
137 }
138#endif
139
140 return 0;
141}
142
143//ll
Note: See TracBrowser for help on using the repository browser.