[2292] | 1 | //roarcatplay.c: |
---|
[212] | 2 | |
---|
[669] | 3 | /* |
---|
[3812] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[669] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[669] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[212] | 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
| 30 | void usage (void) { |
---|
| 31 | printf("roarcatplay [OPTIONS]... [FILE]\n"); |
---|
| 32 | |
---|
| 33 | printf("\nOptions:\n\n"); |
---|
| 34 | |
---|
| 35 | printf(" --server SERVER - Set server hostname\n" |
---|
[765] | 36 | " --simple - Use the simple interface (default)\n" |
---|
| 37 | " --passive - Use passiv playback (experimental, works only localy)\n" |
---|
[770] | 38 | " --background - Use background playback, impleys passive mode\n" |
---|
[999] | 39 | " --verbose - Use verbose output\n" |
---|
[212] | 40 | " --help - Show this help\n" |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | } |
---|
| 44 | |
---|
[765] | 45 | #define MODE_SIMPLE 1 |
---|
| 46 | #define MODE_PASSIVE 2 |
---|
| 47 | |
---|
[212] | 48 | int main (int argc, char * argv[]) { |
---|
| 49 | char * server = NULL; |
---|
| 50 | char * k; |
---|
| 51 | int i; |
---|
[999] | 52 | char * file = NULL; |
---|
| 53 | int mode = MODE_SIMPLE; |
---|
| 54 | int bg = 0; |
---|
| 55 | int verbose = 0; |
---|
[1775] | 56 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 57 | struct roar_connection con[1]; |
---|
[770] | 58 | struct roar_stream stream[1]; |
---|
[1775] | 59 | #endif |
---|
[212] | 60 | |
---|
| 61 | for (i = 1; i < argc; i++) { |
---|
| 62 | k = argv[i]; |
---|
| 63 | |
---|
[1635] | 64 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
[212] | 65 | server = argv[++i]; |
---|
[765] | 66 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
| 67 | mode = MODE_SIMPLE; |
---|
| 68 | } else if ( strcmp(k, "--passive") == 0 ) { |
---|
| 69 | mode = MODE_PASSIVE; |
---|
[770] | 70 | } else if ( strcmp(k, "--background") == 0 ) { |
---|
| 71 | bg = 1; |
---|
[999] | 72 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
| 73 | verbose++; |
---|
[1635] | 74 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
[212] | 75 | usage(); |
---|
| 76 | return 0; |
---|
[214] | 77 | } else if ( file == NULL ) { |
---|
| 78 | file = argv[i]; |
---|
[212] | 79 | } else { |
---|
| 80 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 81 | usage(); |
---|
| 82 | return 1; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[770] | 86 | if ( bg ) |
---|
| 87 | mode = MODE_PASSIVE; |
---|
[214] | 88 | |
---|
[1770] | 89 | #ifndef ROAR_HAVE_UNIX |
---|
| 90 | if ( mode == MODE_PASSIVE ) { |
---|
[1775] | 91 | fprintf(stderr, "Error: passive mode is not supported on this system.\n"); |
---|
[1770] | 92 | return 1; |
---|
| 93 | } |
---|
| 94 | #endif |
---|
| 95 | |
---|
[214] | 96 | if ( file == NULL ) |
---|
| 97 | file = "/dev/stdin"; |
---|
[212] | 98 | |
---|
[1774] | 99 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 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 | |
---|
[770] | 106 | if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) { |
---|
[765] | 107 | ROAR_ERR("Can not start playback"); |
---|
| 108 | return 1; |
---|
| 109 | } |
---|
| 110 | |
---|
[770] | 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 | } |
---|
[765] | 118 | |
---|
| 119 | roar_disconnect(con); |
---|
| 120 | |
---|
| 121 | } else { // MODE_SIMPLE |
---|
[1770] | 122 | #endif |
---|
[765] | 123 | if ( roar_simple_play_file(file, server, "roarcatplay") == -1 ) { |
---|
| 124 | ROAR_ERR("Can not start playback"); |
---|
| 125 | return 1; |
---|
| 126 | } |
---|
[1774] | 127 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 128 | } |
---|
[1770] | 129 | #endif |
---|
[212] | 130 | |
---|
| 131 | return 0; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | //ll |
---|