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 | " --help - Show this help\n" |
---|
39 | ); |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | #define MODE_SIMPLE 1 |
---|
44 | #define MODE_PASSIVE 2 |
---|
45 | |
---|
46 | int main (int argc, char * argv[]) { |
---|
47 | char * server = NULL; |
---|
48 | char * k; |
---|
49 | int i; |
---|
50 | char * file = NULL; |
---|
51 | int mode = MODE_SIMPLE; |
---|
52 | int bg = 0; |
---|
53 | struct roar_connection con[1]; |
---|
54 | struct roar_stream stream[1]; |
---|
55 | |
---|
56 | for (i = 1; i < argc; i++) { |
---|
57 | k = argv[i]; |
---|
58 | |
---|
59 | if ( strcmp(k, "--server") == 0 ) { |
---|
60 | server = argv[++i]; |
---|
61 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
62 | mode = MODE_SIMPLE; |
---|
63 | } else if ( strcmp(k, "--passive") == 0 ) { |
---|
64 | mode = MODE_PASSIVE; |
---|
65 | } else if ( strcmp(k, "--background") == 0 ) { |
---|
66 | bg = 1; |
---|
67 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
68 | usage(); |
---|
69 | return 0; |
---|
70 | } else if ( file == NULL ) { |
---|
71 | file = argv[i]; |
---|
72 | } else { |
---|
73 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
74 | usage(); |
---|
75 | return 1; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | if ( bg ) |
---|
80 | mode = MODE_PASSIVE; |
---|
81 | |
---|
82 | if ( file == NULL ) |
---|
83 | file = "/dev/stdin"; |
---|
84 | |
---|
85 | if ( mode == MODE_PASSIVE ) { |
---|
86 | if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) { |
---|
87 | ROAR_ERR("Can not connect to server"); |
---|
88 | return 0; |
---|
89 | } |
---|
90 | |
---|
91 | if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) { |
---|
92 | ROAR_ERR("Can not start playback"); |
---|
93 | return 1; |
---|
94 | } |
---|
95 | |
---|
96 | if ( bg ) { |
---|
97 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
98 | ROAR_ERR("Can not attach stream to server"); |
---|
99 | } |
---|
100 | } else { |
---|
101 | sleep(10); |
---|
102 | } |
---|
103 | |
---|
104 | roar_disconnect(con); |
---|
105 | |
---|
106 | } else { // MODE_SIMPLE |
---|
107 | if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) { |
---|
108 | ROAR_ERR("Can not start playback"); |
---|
109 | return 1; |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | return 0; |
---|
114 | } |
---|
115 | |
---|
116 | //ll |
---|