[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[]) { |
---|
| 46 | int rate = ROAR_RATE_DEFAULT; |
---|
| 47 | int bits = ROAR_BITS_DEFAULT; |
---|
| 48 | int channels = ROAR_CHANNELS_DEFAULT; |
---|
[4664] | 49 | int codec = -1; |
---|
[1279] | 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; |
---|
[4664] | 57 | const char * content_type; |
---|
[1279] | 58 | |
---|
| 59 | if ( roar_vio_open_fh(&file, ROAR_STDIN) == -1 ) |
---|
| 60 | return 1; |
---|
| 61 | |
---|
[1344] | 62 | if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) |
---|
| 63 | return 1; |
---|
| 64 | |
---|
[1279] | 65 | for (i = 1; i < argc; i++) { |
---|
| 66 | k = argv[i]; |
---|
| 67 | |
---|
| 68 | if ( !strcmp(k, "--server") || !strcmp(k, "-s") ) { |
---|
| 69 | server = argv[++i]; |
---|
| 70 | } else if ( !strcmp(k, "-n") ) { |
---|
| 71 | name = argv[++i]; |
---|
| 72 | } else if ( !strcmp(k, "--rate") || !strcmp(k, "-r") ) { |
---|
| 73 | rate = atoi(argv[++i]); |
---|
| 74 | } else if ( !strcmp(k, "--bits") ) { |
---|
| 75 | bits = atoi(argv[++i]); |
---|
| 76 | } else if ( !strcmp(k, "-b") ) { |
---|
| 77 | bits = 8; |
---|
| 78 | } else if ( !strcmp(k, "--channels") || !strcmp(k, "--chans") ) { |
---|
| 79 | channels = atoi(argv[++i]); |
---|
| 80 | } else if ( !strcmp(k, "-m") ) { |
---|
| 81 | channels = 1; |
---|
| 82 | } else if ( !strcmp(k, "--codec") ) { |
---|
| 83 | codec = roar_str2codec(argv[++i]); |
---|
| 84 | } else if ( !strcmp(k, "--help") ) { |
---|
| 85 | usage(); |
---|
| 86 | return 0; |
---|
| 87 | } else if ( !file_opened ) { |
---|
| 88 | file_opened = 1; |
---|
[1344] | 89 | if ( roar_vio_open_dstr(&file, k, &def, 1) == -1 ) { |
---|
[1279] | 90 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 91 | return 1; |
---|
| 92 | } |
---|
[4664] | 93 | |
---|
| 94 | if ( codec == -1 ) { |
---|
| 95 | if ( roar_vio_ctl(&file, ROAR_VIO_CTL_GET_MIMETYPE, &content_type) != -1 ) { |
---|
| 96 | codec = roar_mime2codec(content_type); |
---|
| 97 | } |
---|
| 98 | } |
---|
[1279] | 99 | } else { |
---|
| 100 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 101 | usage(); |
---|
| 102 | return 1; |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
[4664] | 106 | if ( codec == -1 ) |
---|
| 107 | codec = ROAR_CODEC_DEFAULT; |
---|
| 108 | |
---|
[1279] | 109 | if ( roar_vio_simple_stream(&stream, rate, channels, bits, codec, server, ROAR_DIR_PLAY, name) == -1 ) { |
---|
| 110 | fprintf(stderr, "Error: can not start playback\n"); |
---|
| 111 | return 1; |
---|
| 112 | } |
---|
| 113 | |
---|
[1344] | 114 | roar_vio_copy_data(&stream, &file); |
---|
[1279] | 115 | |
---|
[1344] | 116 | roar_vio_close(&file); |
---|
[1279] | 117 | roar_vio_close(&stream); |
---|
| 118 | |
---|
| 119 | return 0; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | //ll |
---|