[2124] | 1 | //roarbidir.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> |
---|
[2126] | 26 | #include "driver.h" |
---|
[2124] | 27 | |
---|
| 28 | #define BUFSIZE 1024 |
---|
| 29 | |
---|
[2125] | 30 | #define DRIVER "oss" |
---|
| 31 | |
---|
[2124] | 32 | void usage (void) { |
---|
| 33 | printf("roarcat [OPTIONS]...\n"); |
---|
| 34 | |
---|
| 35 | printf("\nOptions:\n\n"); |
---|
| 36 | |
---|
| 37 | printf(" --server SERVER - Set server hostname\n" |
---|
| 38 | " --rate RATE - Set sample rate\n" |
---|
| 39 | " --bits BITS - Set bits per sample\n" |
---|
| 40 | " --chans CHANNELS - Set number of channels\n" |
---|
| 41 | " --codec CODEC - Set the codec\n" |
---|
[2127] | 42 | " --driver DRIVER - Set the driver\n" |
---|
| 43 | " --device DEVICE - Set the device\n" |
---|
[2124] | 44 | " --help - Show this help\n" |
---|
| 45 | ); |
---|
| 46 | |
---|
| 47 | } |
---|
| 48 | |
---|
[2128] | 49 | int open_stream (struct roar_vio_calls * vio, char * server, struct roar_audio_info * info) { |
---|
| 50 | return roar_vio_simple_stream(vio, |
---|
| 51 | info->rate, info->channels, info->bits, info->codec, |
---|
| 52 | server, |
---|
| 53 | ROAR_DIR_BIDIR, |
---|
| 54 | "roarphone"); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | int run_stream (struct roar_vio_calls * s0, struct roar_vio_calls * s1, struct roar_audio_info * info) { |
---|
[2129] | 58 | size_t len; |
---|
| 59 | char * buf; |
---|
| 60 | ssize_t l; |
---|
| 61 | |
---|
| 62 | len = (info->rate / 100) * info->channels * info->bits / 8; |
---|
| 63 | |
---|
| 64 | if ( (buf = malloc(len)) == NULL ) |
---|
| 65 | return -1; |
---|
| 66 | |
---|
| 67 | while (1) { |
---|
| 68 | if ( (l = roar_vio_read(s0, buf, len)) <= 0 ) |
---|
| 69 | break; |
---|
| 70 | if ( roar_vio_write(s1, buf, l) != l ) |
---|
| 71 | break; |
---|
| 72 | if ( (l = roar_vio_read(s1, buf, len)) <= 0 ) |
---|
| 73 | break; |
---|
| 74 | if ( roar_vio_write(s0, buf, l) != l ) |
---|
| 75 | break; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | free(buf); |
---|
| 79 | |
---|
| 80 | return 0; |
---|
[2128] | 81 | } |
---|
| 82 | |
---|
[2124] | 83 | int main (int argc, char * argv[]) { |
---|
[2125] | 84 | struct roar_audio_info info = {.rate = ROAR_RATE_DEFAULT, |
---|
| 85 | .bits = ROAR_BITS_DEFAULT, |
---|
| 86 | .channels = ROAR_CHANNELS_DEFAULT, |
---|
| 87 | .codec = ROAR_CODEC_DEFAULT |
---|
| 88 | }; |
---|
[2128] | 89 | struct roar_vio_calls dvio, svio; |
---|
[2126] | 90 | char * driver = DRIVER; |
---|
| 91 | char * device = NULL; |
---|
[2124] | 92 | char * server = NULL; |
---|
| 93 | char * k; |
---|
| 94 | int i; |
---|
| 95 | |
---|
| 96 | for (i = 1; i < argc; i++) { |
---|
| 97 | k = argv[i]; |
---|
| 98 | |
---|
| 99 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 100 | server = argv[++i]; |
---|
| 101 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
[2125] | 102 | info.rate = atoi(argv[++i]); |
---|
[2124] | 103 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
[2125] | 104 | info.bits = atoi(argv[++i]); |
---|
[2124] | 105 | } else if ( strcmp(k, "--channels") == 0 || strcmp(k, "--chans") == 0 ) { |
---|
[2125] | 106 | info.channels = atoi(argv[++i]); |
---|
[2124] | 107 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
[2125] | 108 | info.codec = roar_str2codec(argv[++i]); |
---|
[2127] | 109 | } else if ( strcmp(k, "--driver") == 0 ) { |
---|
| 110 | driver = argv[++i]; |
---|
| 111 | } else if ( strcmp(k, "--device") == 0 ) { |
---|
| 112 | device = argv[++i]; |
---|
[2124] | 113 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 114 | usage(); |
---|
| 115 | return 0; |
---|
| 116 | } else { |
---|
| 117 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 118 | usage(); |
---|
| 119 | return 1; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
[2126] | 123 | if ( roar_cdriver_open(&dvio, driver, device, &info, ROAR_DIR_BIDIR) == -1 ) { |
---|
| 124 | return 1; |
---|
| 125 | } |
---|
| 126 | |
---|
[2128] | 127 | if ( open_stream(&svio, server, &info) == -1 ) { |
---|
| 128 | roar_vio_close(&dvio); |
---|
| 129 | return 2; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | run_stream(&svio, &dvio, &info); |
---|
| 133 | |
---|
| 134 | roar_vio_close(&svio); |
---|
[2126] | 135 | roar_vio_close(&dvio); |
---|
| 136 | |
---|
[2124] | 137 | return 0; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | //ll |
---|