[1016] | 1 | //roarmonhttp.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include <roaraudio.h> |
---|
| 26 | |
---|
| 27 | #define BUFSIZE 1024 |
---|
| 28 | |
---|
| 29 | int main (int argc, char * argv[]) { |
---|
| 30 | int rate = 44100; |
---|
| 31 | int bits = 16; |
---|
| 32 | int channels = 2; |
---|
| 33 | int codec = ROAR_CODEC_OGG_VORBIS; |
---|
| 34 | char * server = NULL; |
---|
| 35 | char * k; |
---|
| 36 | int fh; |
---|
| 37 | int i; |
---|
| 38 | int out = -1; |
---|
| 39 | char buf[BUFSIZE]; |
---|
| 40 | |
---|
| 41 | for (i = 1; i < argc; i++) { |
---|
| 42 | k = argv[i]; |
---|
| 43 | |
---|
| 44 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 45 | server = argv[++i]; |
---|
| 46 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 47 | rate = atoi(argv[++i]); |
---|
| 48 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 49 | bits = atoi(argv[++i]); |
---|
| 50 | } else if ( strcmp(k, "--channels") == 0 ) { |
---|
| 51 | channels = atoi(argv[++i]); |
---|
| 52 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
| 53 | codec = roar_str2codec(argv[++i]); |
---|
| 54 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 55 | return 0; |
---|
| 56 | } else if ( out == -1 ) { |
---|
| 57 | if ( (out = open(k, O_CREAT|O_TRUNC|O_WRONLY, 0644)) == -1 ) { |
---|
| 58 | fprintf(stderr, "Error: can not open file: %s: %s\n", k, strerror(errno)); |
---|
| 59 | return 1; |
---|
| 60 | } |
---|
| 61 | } else { |
---|
| 62 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 63 | return 1; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | if ( out == -1 ) |
---|
| 68 | out = ROAR_STDOUT; |
---|
| 69 | |
---|
| 70 | if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarmon")) == -1 ) { |
---|
| 71 | fprintf(stderr, "Error: can not start monitoring\n"); |
---|
| 72 | return 1; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | while((i = read(fh, buf, BUFSIZE))) |
---|
| 76 | if (write(out, buf, i) != i) |
---|
| 77 | break; |
---|
| 78 | |
---|
| 79 | roar_simple_close(fh); |
---|
| 80 | |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | //ll |
---|