source: roaraudio/roarclients/roarcatplay.c @ 3121:0ed0acfadd4f

Last change on this file since 3121:0ed0acfadd4f was 2292:0e4ee5724202, checked in by phi, 15 years ago

simple patches, mostly by Simon Matter (trivial by german law so no (c) notice)

File size: 3.3 KB
Line 
1//roarcatplay.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <roaraudio.h>
26
27#define BUFSIZE 1024
28
29void usage (void) {
30 printf("roarcatplay [OPTIONS]... [FILE]\n");
31
32 printf("\nOptions:\n\n");
33
34 printf("  --server SERVER    - Set server hostname\n"
35        "  --simple           - Use the simple interface (default)\n"
36        "  --passive          - Use passiv playback (experimental, works only localy)\n"
37        "  --background       - Use background playback, impleys passive mode\n"
38        "  --verbose          - Use verbose output\n"
39        "  --help             - Show this help\n"
40       );
41
42}
43
44#define MODE_SIMPLE  1
45#define MODE_PASSIVE 2
46
47int main (int argc, char * argv[]) {
48 char * server   = NULL;
49 char * k;
50 int    i;
51 char * file    = NULL;
52 int    mode    = MODE_SIMPLE;
53 int    bg      = 0;
54 int    verbose = 0;
55#ifdef ROAR_HAVE_UNIX
56 struct roar_connection con[1];
57 struct roar_stream     stream[1];
58#endif
59
60 for (i = 1; i < argc; i++) {
61  k = argv[i];
62
63  if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) {
64   server = argv[++i];
65  } else if ( strcmp(k, "--simple") == 0 ) {
66   mode = MODE_SIMPLE;
67  } else if ( strcmp(k, "--passive") == 0 ) {
68   mode = MODE_PASSIVE;
69  } else if ( strcmp(k, "--background") == 0 ) {
70   bg = 1;
71  } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) {
72   verbose++;
73  } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) {
74   usage();
75   return 0;
76  } else if ( file == NULL ) {
77   file = argv[i];
78  } else {
79   fprintf(stderr, "Error: unknown argument: %s\n", k);
80   usage();
81   return 1;
82  }
83 }
84
85 if ( bg )
86  mode = MODE_PASSIVE;
87
88#ifndef ROAR_HAVE_UNIX
89 if ( mode == MODE_PASSIVE ) {
90  fprintf(stderr, "Error: passive mode is not supported on this system.\n");
91  return 1;
92 }
93#endif
94
95 if ( file == NULL )
96  file = "/dev/stdin";
97
98#ifdef ROAR_HAVE_UNIX
99 if ( mode == MODE_PASSIVE ) {
100  if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) {
101   ROAR_ERR("Can not connect to server");
102   return 0;
103  }
104
105  if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) {
106   ROAR_ERR("Can not start playback");
107   return 1;
108  }
109
110  if ( bg ) {
111   if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
112    ROAR_ERR("Can not attach stream to server");
113   }
114  } else {
115   sleep(10);
116  }
117
118  roar_disconnect(con);
119
120 } else { // MODE_SIMPLE
121#endif
122  if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) {
123   ROAR_ERR("Can not start playback");
124   return 1;
125  }
126#ifdef ROAR_HAVE_UNIX
127 }
128#endif
129
130 return 0;
131}
132
133//ll
Note: See TracBrowser for help on using the repository browser.