[2292] | 1 | //roarcatplay.c: |
---|
[212] | 2 | |
---|
[669] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[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; |
---|
[5022] | 56 | roar_vs_t * vss; |
---|
| 57 | int err; |
---|
[1775] | 58 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 59 | struct roar_connection con[1]; |
---|
[770] | 60 | struct roar_stream stream[1]; |
---|
[1775] | 61 | #endif |
---|
[212] | 62 | |
---|
| 63 | for (i = 1; i < argc; i++) { |
---|
| 64 | k = argv[i]; |
---|
| 65 | |
---|
[1635] | 66 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
[212] | 67 | server = argv[++i]; |
---|
[765] | 68 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
| 69 | mode = MODE_SIMPLE; |
---|
| 70 | } else if ( strcmp(k, "--passive") == 0 ) { |
---|
| 71 | mode = MODE_PASSIVE; |
---|
[770] | 72 | } else if ( strcmp(k, "--background") == 0 ) { |
---|
| 73 | bg = 1; |
---|
[999] | 74 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
| 75 | verbose++; |
---|
[1635] | 76 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
[212] | 77 | usage(); |
---|
| 78 | return 0; |
---|
[214] | 79 | } else if ( file == NULL ) { |
---|
| 80 | file = argv[i]; |
---|
[212] | 81 | } else { |
---|
| 82 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 83 | usage(); |
---|
| 84 | return 1; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
[770] | 88 | if ( bg ) |
---|
| 89 | mode = MODE_PASSIVE; |
---|
[214] | 90 | |
---|
[1770] | 91 | #ifndef ROAR_HAVE_UNIX |
---|
| 92 | if ( mode == MODE_PASSIVE ) { |
---|
[1775] | 93 | fprintf(stderr, "Error: passive mode is not supported on this system.\n"); |
---|
[1770] | 94 | return 1; |
---|
| 95 | } |
---|
| 96 | #endif |
---|
| 97 | |
---|
[5109] | 98 | if ( mode == MODE_PASSIVE ) { |
---|
| 99 | fprintf(stderr, "Warning: passive mode is obsoleted and will be removed soon.\n"); |
---|
| 100 | } |
---|
| 101 | |
---|
[214] | 102 | if ( file == NULL ) |
---|
| 103 | file = "/dev/stdin"; |
---|
[212] | 104 | |
---|
[1774] | 105 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 106 | if ( mode == MODE_PASSIVE ) { |
---|
| 107 | if ( roar_simple_connect(con, server, "roarcatplay") == -1 ) { |
---|
| 108 | ROAR_ERR("Can not connect to server"); |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
[770] | 112 | if ( roar_file_play_full(con, file, 0, 1, stream) == -1 ) { |
---|
[765] | 113 | ROAR_ERR("Can not start playback"); |
---|
| 114 | return 1; |
---|
| 115 | } |
---|
| 116 | |
---|
[770] | 117 | if ( bg ) { |
---|
| 118 | if ( roar_stream_attach_simple(con, stream, 0) == -1 ) { |
---|
| 119 | ROAR_ERR("Can not attach stream to server"); |
---|
| 120 | } |
---|
| 121 | } else { |
---|
[4914] | 122 | roar_sleep(10); |
---|
[770] | 123 | } |
---|
[765] | 124 | |
---|
| 125 | roar_disconnect(con); |
---|
| 126 | |
---|
| 127 | } else { // MODE_SIMPLE |
---|
[1770] | 128 | #endif |
---|
[5022] | 129 | if ( (vss = roar_vs_new_from_file(server, "roarcatplay", file, &err)) == NULL ) { |
---|
| 130 | ROAR_ERR("Can not start playback: %s", roar_error2str(err)); |
---|
[765] | 131 | return 1; |
---|
| 132 | } |
---|
[5022] | 133 | roar_vs_run(vss, NULL); |
---|
| 134 | roar_vs_sync(vss, ROAR_VS_WAIT, NULL); |
---|
| 135 | roar_vs_close(vss, ROAR_VS_FALSE, NULL); |
---|
[1774] | 136 | #ifdef ROAR_HAVE_UNIX |
---|
[765] | 137 | } |
---|
[1770] | 138 | #endif |
---|
[212] | 139 | |
---|
| 140 | return 0; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | //ll |
---|