[1279] | 1 | //roarcatvio.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[3812] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[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[]) { |
---|
| 46 | int rate = ROAR_RATE_DEFAULT; |
---|
| 47 | int bits = ROAR_BITS_DEFAULT; |
---|
| 48 | int channels = ROAR_CHANNELS_DEFAULT; |
---|
| 49 | int codec = ROAR_CODEC_DEFAULT; |
---|
| 50 | char * server = NULL; |
---|
| 51 | char * k; |
---|
| 52 | int i; |
---|
[2292] | 53 | char * name = "roarcatvio"; |
---|
[1344] | 54 | struct roar_vio_calls file, stream; |
---|
| 55 | struct roar_vio_defaults def; |
---|
[1279] | 56 | int file_opened = 0; |
---|
| 57 | |
---|
| 58 | if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) |
---|
| 59 | return 1; |
---|
| 60 | |
---|
[1344] | 61 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
| 62 | return 1; |
---|
| 63 | |
---|
[1279] | 64 | for (i = 1; i < argc; i++) { |
---|
| 65 | k = argv[i]; |
---|
| 66 | |
---|
| 67 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
| 68 | server = argv[++i]; |
---|
| 69 | } else if ( !strcmp(k, "-n") ) { |
---|
| 70 | name = argv[++i]; |
---|
| 71 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) { |
---|
| 72 | rate = atoi(argv[++i]); |
---|
| 73 | } else if ( !strcmp(k, "--bits") ) { |
---|
| 74 | bits = atoi(argv[++i]); |
---|
| 75 | } else if ( !strcmp(k, "-b") ) { |
---|
| 76 | bits = 8; |
---|
| 77 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) { |
---|
| 78 | channels = atoi(argv[++i]); |
---|
| 79 | } else if ( !strcmp(k, "-m") ) { |
---|
| 80 | channels = 1; |
---|
| 81 | } else if ( !strcmp(k, "--codec") ) { |
---|
| 82 | codec = roar_str2codec(argv[++i]); |
---|
| 83 | } else if ( !strcmp(k, "--help") ) { |
---|
| 84 | usage(); |
---|
| 85 | return 0; |
---|
| 86 | } else if ( !file_opened ) { |
---|
| 87 | file_opened = 1; |
---|
[1344] | 88 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[1279] | 89 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 90 | return 1; |
---|
| 91 | } |
---|
| 92 | } else { |
---|
| 93 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 94 | usage(); |
---|
| 95 | return 1; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | if ( roar_vio_simple_stream(&stream, rate, channels, bits, codec, server, ROAR_DIR_PLAY, name) == -1 ) { |
---|
| 100 | fprintf(stderr, "Error: can not start playback\n"); |
---|
| 101 | return 1; |
---|
| 102 | } |
---|
| 103 | |
---|
[1344] | 104 | roar_vio_copy_data(&stream, &file); |
---|
[1279] | 105 | |
---|
[1344] | 106 | roar_vio_close(&file); |
---|
[1279] | 107 | roar_vio_close(&stream); |
---|
| 108 | |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | //ll |
---|