1 | //roarcat.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
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 | |
---|
29 | void 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 | |
---|
47 | int 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 | struct roar_connection con[1]; |
---|
56 | struct roar_stream stream[1]; |
---|
57 | |
---|
58 | for (i = 1; i < argc; i++) { |
---|
59 | k = argv[i]; |
---|
60 | |
---|
61 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
62 | server = argv[++i]; |
---|
63 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
64 | mode = MODE_SIMPLE; |
---|
65 | } else if ( strcmp(k, "--passive") == 0 ) { |
---|
66 | mode = MODE_PASSIVE; |
---|
67 | } else if ( strcmp(k, "--background") == 0 ) { |
---|
68 | bg = 1; |
---|
69 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
70 | verbose++; |
---|
71 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
72 | usage(); |
---|
73 | return 0; |
---|
74 | } else if ( file == NULL ) { |
---|
75 | file = argv[i]; |
---|
76 | } else { |
---|
77 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
78 | usage(); |
---|
79 | return 1; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | if ( bg ) |
---|
84 | mode = MODE_PASSIVE; |
---|
85 | |
---|
86 | if ( file == NULL ) |
---|
87 | file = "/dev/stdin"; |
---|
88 | |
---|
89 | if ( mode == MODE_PASSIVE ) { |
---|
90 | if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) { |
---|
91 | ROAR_ERR("Can not connect to server"); |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) { |
---|
96 | ROAR_ERR("Can not start playback"); |
---|
97 | return 1; |
---|
98 | } |
---|
99 | |
---|
100 | if ( bg ) { |
---|
101 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
102 | ROAR_ERR("Can not attach stream to server"); |
---|
103 | } |
---|
104 | } else { |
---|
105 | sleep(10); |
---|
106 | } |
---|
107 | |
---|
108 | roar_disconnect(con); |
---|
109 | |
---|
110 | } else { // MODE_SIMPLE |
---|
111 | if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) { |
---|
112 | ROAR_ERR("Can not start playback"); |
---|
113 | return 1; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | return 0; |
---|
118 | } |
---|
119 | |
---|
120 | //ll |
---|