[212] | 1 | //roarcat.c: |
---|
| 2 | |
---|
[669] | 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 | |
---|
[212] | 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" |
---|
[765] | 35 | " --simple - Use the simple interface (default)\n" |
---|
| 36 | " --passive - Use passiv playback (experimental, works only localy)\n" |
---|
[770] | 37 | " --background - Use background playback, impleys passive mode\n" |
---|
[999] | 38 | " --verbose - Use verbose output\n" |
---|
[212] | 39 | " --help - Show this help\n" |
---|
| 40 | ); |
---|
| 41 | |
---|
| 42 | } |
---|
| 43 | |
---|
[765] | 44 | #define MODE_SIMPLE 1 |
---|
| 45 | #define MODE_PASSIVE 2 |
---|
| 46 | |
---|
[212] | 47 | int main (int argc, char * argv[]) { |
---|
| 48 | char * server = NULL; |
---|
| 49 | char * k; |
---|
| 50 | int i; |
---|
[999] | 51 | char * file = NULL; |
---|
| 52 | int mode = MODE_SIMPLE; |
---|
| 53 | int bg = 0; |
---|
| 54 | int verbose = 0; |
---|
[1775] | 55 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 56 | struct roar_connection con[1]; |
---|
[770] | 57 | struct roar_stream stream[1]; |
---|
[1775] | 58 | #endif |
---|
[212] | 59 | |
---|
| 60 | for (i = 1; i < argc; i++) { |
---|
| 61 | k = argv[i]; |
---|
| 62 | |
---|
[1635] | 63 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
[212] | 64 | server = argv[++i]; |
---|
[765] | 65 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
| 66 | mode = MODE_SIMPLE; |
---|
| 67 | } else if ( strcmp(k, "--passive") == 0 ) { |
---|
| 68 | mode = MODE_PASSIVE; |
---|
[770] | 69 | } else if ( strcmp(k, "--background") == 0 ) { |
---|
| 70 | bg = 1; |
---|
[999] | 71 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
| 72 | verbose++; |
---|
[1635] | 73 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
[212] | 74 | usage(); |
---|
| 75 | return 0; |
---|
[214] | 76 | } else if ( file == NULL ) { |
---|
| 77 | file = argv[i]; |
---|
[212] | 78 | } else { |
---|
| 79 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 80 | usage(); |
---|
| 81 | return 1; |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
[770] | 85 | if ( bg ) |
---|
| 86 | mode = MODE_PASSIVE; |
---|
[214] | 87 | |
---|
[1770] | 88 | #ifndef ROAR_HAVE_UNIX |
---|
| 89 | if ( mode == MODE_PASSIVE ) { |
---|
[1775] | 90 | fprintf(stderr, "Error: passive mode is not supported on this system.\n"); |
---|
[1770] | 91 | return 1; |
---|
| 92 | } |
---|
| 93 | #endif |
---|
| 94 | |
---|
[214] | 95 | if ( file == NULL ) |
---|
| 96 | file = "/dev/stdin"; |
---|
[212] | 97 | |
---|
[1774] | 98 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 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 | |
---|
[770] | 105 | if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) { |
---|
[765] | 106 | ROAR_ERR("Can not start playback"); |
---|
| 107 | return 1; |
---|
| 108 | } |
---|
| 109 | |
---|
[770] | 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 | } |
---|
[765] | 117 | |
---|
| 118 | roar_disconnect(con); |
---|
| 119 | |
---|
| 120 | } else { // MODE_SIMPLE |
---|
[1770] | 121 | #endif |
---|
[765] | 122 | if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) { |
---|
| 123 | ROAR_ERR("Can not start playback"); |
---|
| 124 | return 1; |
---|
| 125 | } |
---|
[1774] | 126 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 127 | } |
---|
[1770] | 128 | #endif |
---|
[212] | 129 | |
---|
| 130 | return 0; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | //ll |
---|