[2292] | 1 | //roarcatsendfile.c: |
---|
[209] | 2 | |
---|
[669] | 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013 |
---|
[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 | |
---|
[209] | 26 | #include <roaraudio.h> |
---|
| 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
| 30 | void usage (void) { |
---|
[210] | 31 | printf("roarcatsendfile [OPTIONS]... [FILE]\n"); |
---|
[209] | 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 = 44100; |
---|
| 47 | int bits = 16; |
---|
| 48 | int channels = 2; |
---|
| 49 | int codec = ROAR_CODEC_DEFAULT; |
---|
[5534] | 50 | const char * server = NULL; |
---|
| 51 | const char * k; |
---|
[209] | 52 | int fh; |
---|
| 53 | int i; |
---|
| 54 | int in = -1; |
---|
| 55 | |
---|
[5109] | 56 | roar_debug_bin_obsolete(argv[0], "roarcat", NULL); |
---|
| 57 | |
---|
[209] | 58 | for (i = 1; i < argc; i++) { |
---|
| 59 | k = argv[i]; |
---|
| 60 | |
---|
| 61 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 62 | server = argv[++i]; |
---|
| 63 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 64 | rate = atoi(argv[++i]); |
---|
| 65 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 66 | bits = atoi(argv[++i]); |
---|
| 67 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
| 68 | channels = atoi(argv[++i]); |
---|
| 69 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
| 70 | codec = atoi(argv[++i]); |
---|
| 71 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 72 | usage(); |
---|
| 73 | return 0; |
---|
| 74 | } else if ( in == -1 ) { |
---|
| 75 | if ( (in = open(k, O_RDONLY, 0644)) == -1 ) { |
---|
| 76 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 77 | return 1; |
---|
| 78 | } |
---|
| 79 | } else { |
---|
| 80 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 81 | usage(); |
---|
| 82 | return 1; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[2292] | 86 | if ( (fh = roar_simple_play(rate, channels, bits, codec, server, "roarcatsendfile")) == -1 ) { |
---|
[209] | 87 | fprintf(stderr, "Error: can not start playback\n"); |
---|
| 88 | return 1; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | if ( in == -1 ) |
---|
| 92 | in = ROAR_STDIN; |
---|
| 93 | |
---|
| 94 | roar_file_send_raw(fh, in); |
---|
| 95 | |
---|
| 96 | roar_simple_close(fh); |
---|
| 97 | |
---|
[211] | 98 | close(in); |
---|
| 99 | |
---|
[209] | 100 | return 0; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | //ll |
---|