[599] | 1 | //roarshout.c: |
---|
| 2 | |
---|
[669] | 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 | |
---|
[599] | 25 | #include <roaraudio.h> |
---|
| 26 | |
---|
[600] | 27 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
[605] | 28 | #include <shout/shout.h> |
---|
[600] | 29 | |
---|
[605] | 30 | #define BUFSIZE 2048 |
---|
[599] | 31 | |
---|
| 32 | void usage (void) { |
---|
| 33 | printf("roarmon [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" |
---|
| 42 | " --help - Show this help\n" |
---|
| 43 | ); |
---|
| 44 | |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | int main (int argc, char * argv[]) { |
---|
| 48 | int rate = 44100; |
---|
| 49 | int bits = 16; |
---|
| 50 | int channels = 2; |
---|
| 51 | int codec = ROAR_CODEC_OGG_VORBIS; |
---|
| 52 | char * server = NULL; |
---|
| 53 | char * k; |
---|
[605] | 54 | char * s_server = "localhost"; |
---|
[599] | 55 | char * s_mount = "/roar.ogg"; |
---|
| 56 | char * s_pw = "hackme"; |
---|
| 57 | int s_port = 8000; |
---|
| 58 | int fh; |
---|
| 59 | int i; |
---|
| 60 | char buf[BUFSIZE]; |
---|
[605] | 61 | shout_t * shout; |
---|
[599] | 62 | |
---|
| 63 | for (i = 1; i < argc; i++) { |
---|
| 64 | k = argv[i]; |
---|
| 65 | |
---|
| 66 | if ( strcmp(k, "--server") == 0 ) { |
---|
| 67 | server = argv[++i]; |
---|
| 68 | } else if ( strcmp(k, "--rate") == 0 ) { |
---|
| 69 | rate = atoi(argv[++i]); |
---|
| 70 | } else if ( strcmp(k, "--bits") == 0 ) { |
---|
| 71 | bits = atoi(argv[++i]); |
---|
| 72 | } else if ( strcmp(k, "--channels") == 0 ) { |
---|
| 73 | channels = atoi(argv[++i]); |
---|
| 74 | } else if ( strcmp(k, "--codec") == 0 ) { |
---|
| 75 | codec = roar_str2codec(argv[++i]); |
---|
| 76 | } else if ( strcmp(k, "--help") == 0 ) { |
---|
| 77 | usage(); |
---|
| 78 | return 0; |
---|
| 79 | } else { |
---|
| 80 | fprintf(stderr, "Error: unknown argument: %s\n", k); |
---|
| 81 | usage(); |
---|
| 82 | return 1; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[605] | 86 | shout_init(); |
---|
| 87 | |
---|
| 88 | if (!(shout = shout_new())) { |
---|
| 89 | ROAR_ERR("Can not clreate shout object"); |
---|
| 90 | return 1; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) { |
---|
| 94 | ROAR_ERR("Error setting hostname: %s", shout_get_error(shout)); |
---|
| 95 | return 1; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { |
---|
| 99 | ROAR_ERR("Error setting protocol: %s", shout_get_error(shout)); |
---|
| 100 | return 1; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) { |
---|
| 104 | ROAR_ERR("Error setting port: %s", shout_get_error(shout)); |
---|
| 105 | return 1; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) { |
---|
| 109 | ROAR_ERR("Error setting password: %s", shout_get_error(shout)); |
---|
| 110 | return 1; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) { |
---|
| 114 | ROAR_ERR("Error setting mount: %s", shout_get_error(shout)); |
---|
| 115 | return 1; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) { |
---|
| 119 | ROAR_ERR("Error setting user: %s", shout_get_error(shout)); |
---|
| 120 | return 1; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) { |
---|
| 124 | ROAR_ERR("Error setting format: %s", shout_get_error(shout)); |
---|
| 125 | return 1; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | if ( (fh = roar_simple_monitor(rate, channels, bits, codec, server, "roarshout")) == -1 ) { |
---|
[599] | 129 | fprintf(stderr, "Error: can not start monetoring\n"); |
---|
| 130 | return 1; |
---|
| 131 | } |
---|
| 132 | |
---|
[605] | 133 | if (shout_open(shout) != SHOUTERR_SUCCESS) { |
---|
| 134 | ROAR_ERR("Can not open connection via libshout!"); |
---|
| 135 | return -1; |
---|
| 136 | } |
---|
| 137 | |
---|
[599] | 138 | while((i = read(fh, buf, BUFSIZE))) |
---|
[605] | 139 | if (shout_send(shout, buf, i) != SHOUTERR_SUCCESS) |
---|
[599] | 140 | break; |
---|
| 141 | |
---|
| 142 | roar_simple_close(fh); |
---|
| 143 | |
---|
[605] | 144 | shout_sync(shout); |
---|
| 145 | |
---|
| 146 | shout_close(shout); |
---|
| 147 | |
---|
| 148 | shout_shutdown(); |
---|
| 149 | |
---|
[599] | 150 | return 0; |
---|
| 151 | } |
---|
| 152 | |
---|
[600] | 153 | #else |
---|
| 154 | int main (void) { |
---|
| 155 | fprintf(stderr, "No libshout support compiled in!\n"); |
---|
| 156 | return 1; |
---|
| 157 | } |
---|
| 158 | #endif |
---|
[599] | 159 | //ll |
---|