[2292] | 1 | //roarcatplay.c: |
---|
[212] | 2 | |
---|
[669] | 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[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 | |
---|
[5949] | 35 | printf(" --server SERVER - Set server hostname\n" |
---|
| 36 | " --simple - Use the simple interface (default)\n" |
---|
| 37 | " --verbose - Use verbose output\n" |
---|
| 38 | " --rate -R RATE - Set sample rate\n" |
---|
| 39 | " --bits -B BITS - Set bits per sample\n" |
---|
| 40 | " --chans -C CHANNELS - Set number of channels\n" |
---|
| 41 | " --codec -E CODEC - Set the codec\n" |
---|
| 42 | " --aiprofile PROFILE - Set audio profile\n" |
---|
| 43 | " --help - Show this help\n" |
---|
[212] | 44 | ); |
---|
| 45 | |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | int main (int argc, char * argv[]) { |
---|
[5949] | 49 | struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, |
---|
| 50 | .bits = ROAR_BITS_DEFAULT, |
---|
| 51 | .channels = ROAR_CHANNELS_DEFAULT, |
---|
| 52 | .codec = ROAR_AUDIO_INFO_INVALID}; |
---|
| 53 | int auinfo_changed = 0; |
---|
[5534] | 54 | const char * server = NULL; |
---|
[5949] | 55 | const char * file = NULL; |
---|
[5534] | 56 | const char * k; |
---|
[212] | 57 | int i; |
---|
[999] | 58 | int verbose = 0; |
---|
[5022] | 59 | roar_vs_t * vss; |
---|
| 60 | int err; |
---|
[212] | 61 | |
---|
| 62 | for (i = 1; i < argc; i++) { |
---|
| 63 | k = argv[i]; |
---|
| 64 | |
---|
[1635] | 65 | if ( strcmp(k, "--server") == 0 || strcmp(k, "-s") == 0 ) { |
---|
[5950] | 66 | ROAR_CKHAVEARGS(1); |
---|
[212] | 67 | server = argv[++i]; |
---|
[765] | 68 | } else if ( strcmp(k, "--simple") == 0 ) { |
---|
[5221] | 69 | /* no op */ |
---|
[999] | 70 | } else if ( strcmp(k, "--verbose") == 0 || strcmp(k, "-v") == 0 ) { |
---|
| 71 | verbose++; |
---|
[5949] | 72 | } else if ( strcmp(k, "-n") == 0 ) { |
---|
[5950] | 73 | ROAR_CKHAVEARGS(1); |
---|
| 74 | i++; |
---|
[5949] | 75 | roar_debug_option_obsolete(argv[0], "-n", NULL, "Will ignore it for now."); |
---|
| 76 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-R") ) { |
---|
[5950] | 77 | ROAR_CKHAVEARGS(1); |
---|
[5949] | 78 | info.rate = roar_str2rate(argv[++i]); |
---|
| 79 | auinfo_changed = 1; |
---|
| 80 | } else if ( !strcmp(k, "--bits") || !strcmp(k, "-B") ) { |
---|
[5950] | 81 | ROAR_CKHAVEARGS(1); |
---|
[5949] | 82 | info.bits = roar_str2bits(argv[++i]); |
---|
| 83 | auinfo_changed = 1; |
---|
| 84 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") || !strcmp(k, "-C") ) { |
---|
[5950] | 85 | ROAR_CKHAVEARGS(1); |
---|
[5949] | 86 | info.channels = roar_str2channels(argv[++i]); |
---|
| 87 | auinfo_changed = 1; |
---|
| 88 | } else if ( !strcmp(k, "--codec") || !strcmp(k, "-E") ) { |
---|
[5950] | 89 | ROAR_CKHAVEARGS(1); |
---|
[5949] | 90 | info.codec = roar_str2codec(argv[++i]); |
---|
| 91 | auinfo_changed = 1; |
---|
| 92 | } else if ( !strcmp(k, "--aiprofile") ) { |
---|
[5950] | 93 | ROAR_CKHAVEARGS(1); |
---|
[5949] | 94 | if ( roar_profile2info(&info, argv[++i]) == -1 ) { |
---|
| 95 | fprintf(stderr, "Error: Can not load audio profile: %s: %s\n", argv[i], roar_error2str(roar_error)); |
---|
| 96 | return 1; |
---|
| 97 | } |
---|
| 98 | auinfo_changed = 1; |
---|
[1635] | 99 | } else if ( strcmp(k, "--help") == 0 || strcmp(k, "-h") == 0 ) { |
---|
[212] | 100 | usage(); |
---|
| 101 | return 0; |
---|
[214] | 102 | } else if ( file == NULL ) { |
---|
| 103 | file = argv[i]; |
---|
[212] | 104 | } else { |
---|
| 105 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 106 | usage(); |
---|
| 107 | return 1; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
[214] | 111 | if ( file == NULL ) |
---|
[5813] | 112 | file = "fh:stdin"; |
---|
[212] | 113 | |
---|
[5949] | 114 | if ( info.codec == ROAR_AUDIO_INFO_INVALID ) |
---|
| 115 | info.codec = ROAR_CODEC_DEFAULT; |
---|
| 116 | |
---|
| 117 | if ( (vss = roar_vs_new(server, "roarcatplay", &err)) == NULL ) { |
---|
| 118 | fprintf(stderr, "Error: can not connect to server: %s: %s\n", |
---|
| 119 | server == NULL ? "(default)" : server, roar_error2str(err)); |
---|
| 120 | return 10; |
---|
[765] | 121 | } |
---|
[5949] | 122 | |
---|
| 123 | if ( auinfo_changed ) { |
---|
| 124 | if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) { |
---|
| 125 | fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err)); |
---|
| 126 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
| 127 | return 10; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | if ( roar_vs_file_simple(vss, file, &err) == -1 ) { |
---|
| 132 | fprintf(stderr, "Error: can not open file: %s: %s\n", file, roar_error2str(err)); |
---|
| 133 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
| 134 | return 10; |
---|
| 135 | } |
---|
| 136 | |
---|
[5221] | 137 | roar_vs_run(vss, NULL); |
---|
| 138 | roar_vs_sync(vss, ROAR_VS_WAIT, NULL); |
---|
| 139 | roar_vs_close(vss, ROAR_VS_FALSE, NULL); |
---|
[212] | 140 | |
---|
| 141 | return 0; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | //ll |
---|