source: roaraudio/roarclients/roarcatplay.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//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#ifdef ROAR_HAVE_UNIX
57 struct roar_connection con[1];
58 struct roar_stream     stream[1];
59#endif
60
61 for (i = 1; i < argc; i++) {
62  k = argv[i];
63
64  if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) {
65   server = argv[++i];
66  } else if ( strcmp(k, "--simple") == 0 ) {
67   mode = MODE_SIMPLE;
68  } else if ( strcmp(k, "--passive") == 0 ) {
69   mode = MODE_PASSIVE;
70  } else if ( strcmp(k, "--background") == 0 ) {
71   bg = 1;
72  } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) {
73   verbose++;
74  } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) {
75   usage();
76   return 0;
77  } else if ( file == NULL ) {
78   file = argv[i];
79  } else {
80   fprintf(stderr, "Error: unknown argument: %s\n", k);
81   usage();
82   return 1;
83  }
84 }
85
86 if ( bg )
87  mode = MODE_PASSIVE;
88
89#ifndef ROAR_HAVE_UNIX
90 if ( mode == MODE_PASSIVE ) {
91  fprintf(stderr, "Error: passive mode is not supported on this system.\n");
92  return 1;
93 }
94#endif
95
96 if ( file == NULL )
97  file = "/dev/stdin";
98
99#ifdef ROAR_HAVE_UNIX
100 if ( mode == MODE_PASSIVE ) {
101  if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) {
102   ROAR_ERR("Can not connect to server");
103   return 0;
104  }
105
106  if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) {
107   ROAR_ERR("Can not start playback");
108   return 1;
109  }
110
111  if ( bg ) {
112   if ( roar_stream_attach_simple(con, stream, 0) == -1 ) {
113    ROAR_ERR("Can not attach stream to server");
114   }
115  } else {
116   sleep(10);
117  }
118
119  roar_disconnect(con);
120
121 } else { // MODE_SIMPLE
122#endif
123  if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) {
124   ROAR_ERR("Can not start playback");
125   return 1;
126  }
127#ifdef ROAR_HAVE_UNIX
128 }
129#endif
130
131 return 0;
132}
133
134//ll
Note: See TracBrowser for help on using the repository browser.