[1279] | 1 | //roarcatvio.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[1279] | 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. |
---|
[1279] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
| 30 | void usage (void) { |
---|
[2230] | 31 | printf("roarcatvio [OPTIONS]... [FILE]\n"); |
---|
[1279] | 32 | |
---|
| 33 | printf("\nOptions:\n\n"); |
---|
| 34 | |
---|
| 35 | printf(" --server SERVER - Set server hostname\n" |
---|
| 36 | " --rate RATE - Set sample rate\n" |
---|
| 37 | " --bits BITS - Set bits per sample\n" |
---|
| 38 | " --chans CHANNELS - Set number of channels\n" |
---|
| 39 | " --codec CODEC - Set the codec\n" |
---|
| 40 | " --help - Show this help\n" |
---|
| 41 | ); |
---|
| 42 | |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int main (int argc, char * argv[]) { |
---|
[5022] | 46 | struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, .bits = ROAR_BITS_DEFAULT, .channels = ROAR_CHANNELS_DEFAULT}; |
---|
[4664] | 47 | int codec = -1; |
---|
[5022] | 48 | int auinfo_changed = 0; |
---|
[1279] | 49 | char * server = NULL; |
---|
| 50 | char * k; |
---|
| 51 | int i; |
---|
[2292] | 52 | char * name = "roarcatvio"; |
---|
[5022] | 53 | roar_vs_t * vss; |
---|
| 54 | char * filename = NULL; |
---|
| 55 | int err; |
---|
[1344] | 56 | |
---|
[1279] | 57 | for (i = 1; i < argc; i++) { |
---|
| 58 | k = argv[i]; |
---|
| 59 | |
---|
| 60 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
| 61 | server = argv[++i]; |
---|
| 62 | } else if ( !strcmp(k, "-n") ) { |
---|
| 63 | name = argv[++i]; |
---|
| 64 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) { |
---|
[5022] | 65 | info.rate = roar_str2rate(argv[++i]); |
---|
| 66 | auinfo_changed = 1; |
---|
[1279] | 67 | } else if ( !strcmp(k, "--bits") ) { |
---|
[5022] | 68 | info.bits = roar_str2bits(argv[++i]); |
---|
| 69 | auinfo_changed = 1; |
---|
[1279] | 70 | } else if ( !strcmp(k, "-b") ) { |
---|
[5022] | 71 | info.bits = 8; |
---|
| 72 | auinfo_changed = 1; |
---|
[1279] | 73 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) { |
---|
[5022] | 74 | info.channels = roar_str2channels(argv[++i]); |
---|
| 75 | auinfo_changed = 1; |
---|
[1279] | 76 | } else if ( !strcmp(k, "-m") ) { |
---|
[5022] | 77 | info.channels = 1; |
---|
| 78 | auinfo_changed = 1; |
---|
[1279] | 79 | } else if ( !strcmp(k, "--codec") ) { |
---|
| 80 | codec = roar_str2codec(argv[++i]); |
---|
[5022] | 81 | auinfo_changed = 1; |
---|
[1279] | 82 | } else if ( !strcmp(k, "--help") ) { |
---|
| 83 | usage(); |
---|
| 84 | return 0; |
---|
[5022] | 85 | } else if ( filename == NULL ) { |
---|
| 86 | filename = k; |
---|
[1279] | 87 | } else { |
---|
| 88 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 89 | usage(); |
---|
| 90 | return 1; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
[4664] | 94 | if ( codec == -1 ) |
---|
| 95 | codec = ROAR_CODEC_DEFAULT; |
---|
| 96 | |
---|
[5022] | 97 | info.codec = codec; |
---|
| 98 | |
---|
| 99 | if ( (vss = roar_vs_new(server, name, &err)) == NULL ) { |
---|
| 100 | fprintf(stderr, "Error: can not connect to server: %s: %s\n", |
---|
| 101 | server == NULL ? "(default)" : server, roar_error2str(err)); |
---|
| 102 | return 10; |
---|
[1279] | 103 | } |
---|
| 104 | |
---|
[5022] | 105 | if ( auinfo_changed ) { |
---|
| 106 | if ( roar_vs_stream(vss, &info, ROAR_DIR_PLAY, &err) == -1 ) { |
---|
| 107 | fprintf(stderr, "Error: can not create new stream: %s\n", roar_error2str(err)); |
---|
| 108 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
| 109 | return 10; |
---|
| 110 | } |
---|
| 111 | } |
---|
[1279] | 112 | |
---|
[5022] | 113 | if ( roar_vs_file_simple(vss, filename, &err) == -1 ) { |
---|
| 114 | fprintf(stderr, "Error: can not open file: %s: %s\n", filename, roar_error2str(err)); |
---|
| 115 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
| 116 | return 10; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | roar_vs_run(vss, NULL); |
---|
| 120 | |
---|
| 121 | roar_vs_sync(vss, ROAR_VS_WAIT, NULL); |
---|
| 122 | roar_vs_close(vss, ROAR_VS_FALSE, NULL); |
---|
[1279] | 123 | |
---|
| 124 | return 0; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | //ll |
---|