[4668] | 1 | //driver_shout.c: |
---|
[950] | 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[950] | 5 | * |
---|
| 6 | * This file is part of roard 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. |
---|
[950] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
| 28 | |
---|
| 29 | int _driver_shout_usage_counter = 0; |
---|
| 30 | |
---|
[2367] | 31 | int driver_shout_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[950] | 32 | char * s_server = NULL; |
---|
| 33 | char * s_mount = NULL; |
---|
[953] | 34 | char * s_user = NULL; |
---|
[950] | 35 | char * s_pw = NULL; |
---|
| 36 | int s_port = -1; |
---|
| 37 | char * s_desc = NULL; |
---|
| 38 | char * s_genre = NULL; |
---|
| 39 | char * s_name = NULL; |
---|
| 40 | char * s_url = NULL; |
---|
| 41 | int s_public = 0; |
---|
[955] | 42 | char * a; |
---|
[950] | 43 | shout_t * shout; |
---|
| 44 | |
---|
[957] | 45 | switch (info->codec) { |
---|
| 46 | case ROAR_CODEC_DEFAULT: |
---|
| 47 | info->codec = ROAR_CODEC_OGG_VORBIS; |
---|
| 48 | break; |
---|
| 49 | case ROAR_CODEC_OGG_VORBIS: |
---|
| 50 | case ROAR_CODEC_OGG_SPEEX: |
---|
| 51 | case ROAR_CODEC_OGG_FLAC: |
---|
| 52 | case ROAR_CODEC_OGG_GENERAL: |
---|
| 53 | // ok, no errors here |
---|
| 54 | break; |
---|
| 55 | default: |
---|
[3589] | 56 | ROAR_ERR("This driver only supports Ogg/* (most common is Ogg/Vorbis), current codec is %s", roar_codec2str(info->codec)); |
---|
[957] | 57 | return -1; |
---|
| 58 | break; |
---|
| 59 | } |
---|
[950] | 60 | |
---|
[953] | 61 | if ( device != NULL ) { |
---|
| 62 | // device sould be an URL in this form: |
---|
| 63 | // [http[s]://][user[:pw]@]host[:port][/mp.ogg] |
---|
| 64 | |
---|
| 65 | if ( (a = strstr(device, "://")) != NULL ) { |
---|
| 66 | *a = 0; |
---|
| 67 | if ( strcmp(device, "http") ) { |
---|
| 68 | return -1; |
---|
| 69 | } |
---|
| 70 | device = a + 3; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | // [user[:pw]@]host[:port][/mp.ogg] |
---|
| 74 | |
---|
| 75 | if ( (a = strstr(device, "@")) != NULL ) { |
---|
| 76 | *a = 0; |
---|
| 77 | s_user = device; |
---|
| 78 | device = a + 1; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | if ( s_user != NULL ) { |
---|
| 82 | if ( (a = strstr(s_user, ":")) != NULL ) { |
---|
| 83 | *a = 0; |
---|
| 84 | s_pw = a+1; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if ( s_user != NULL && ! *s_user ) |
---|
| 89 | s_user = NULL; |
---|
| 90 | |
---|
| 91 | if ( s_pw != NULL && ! *s_pw ) |
---|
| 92 | s_pw = NULL; |
---|
| 93 | |
---|
| 94 | // host[:port][/mp.ogg] |
---|
| 95 | |
---|
| 96 | if ( (a = strstr(device, "/")) != NULL ) { |
---|
| 97 | *a = 0; |
---|
| 98 | s_server = device; |
---|
| 99 | device = a + 1; |
---|
| 100 | } else { |
---|
| 101 | s_server = device; |
---|
| 102 | device += strlen(device); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | if ( (a = strstr(s_server, ":")) != NULL ) { |
---|
| 106 | *a = 0; |
---|
| 107 | s_port = atoi(a+1); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | if ( ! *s_server ) |
---|
| 111 | s_server = NULL; |
---|
| 112 | |
---|
| 113 | // [/mp.ogg] |
---|
| 114 | |
---|
| 115 | if ( *device ) { |
---|
| 116 | s_mount = device; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | ROAR_DBG("driver_shout_open_vio(*): user='%s', pw='%s', server='%s', port=%i, mount='%s'", |
---|
| 121 | s_user, s_pw, s_server, s_port, s_mount); |
---|
| 122 | |
---|
[950] | 123 | if ( s_server == NULL ) |
---|
| 124 | s_server = "localhost"; |
---|
| 125 | |
---|
| 126 | if ( s_mount == NULL ) |
---|
| 127 | s_mount = "/roar.ogg"; |
---|
| 128 | |
---|
| 129 | if ( s_pw == NULL ) |
---|
| 130 | s_pw = "hackme"; |
---|
| 131 | |
---|
[953] | 132 | if ( s_user == NULL ) |
---|
| 133 | s_user = "source"; |
---|
| 134 | |
---|
[950] | 135 | if ( s_port == -1 ) |
---|
| 136 | s_port = 8000; |
---|
| 137 | |
---|
| 138 | if ( _driver_shout_usage_counter++ == 0 ) |
---|
| 139 | shout_init(); |
---|
| 140 | |
---|
| 141 | if (!(shout = shout_new())) { |
---|
| 142 | ROAR_ERR("Can not clreate shout object"); |
---|
| 143 | return 1; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) { |
---|
| 147 | ROAR_ERR("Error setting hostname: %s", shout_get_error(shout)); |
---|
| 148 | return 1; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { |
---|
| 152 | ROAR_ERR("Error setting protocol: %s", shout_get_error(shout)); |
---|
| 153 | return 1; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) { |
---|
| 157 | ROAR_ERR("Error setting port: %s", shout_get_error(shout)); |
---|
| 158 | return 1; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) { |
---|
| 162 | ROAR_ERR("Error setting password: %s", shout_get_error(shout)); |
---|
| 163 | return 1; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) { |
---|
| 167 | ROAR_ERR("Error setting mount: %s", shout_get_error(shout)); |
---|
| 168 | return 1; |
---|
| 169 | } |
---|
| 170 | |
---|
[953] | 171 | if (shout_set_user(shout, s_user) != SHOUTERR_SUCCESS) { |
---|
[950] | 172 | ROAR_ERR("Error setting user: %s", shout_get_error(shout)); |
---|
| 173 | return 1; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) { |
---|
| 177 | ROAR_ERR("Error setting format: %s", shout_get_error(shout)); |
---|
| 178 | return 1; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | shout_set_public(shout, s_public); |
---|
| 182 | |
---|
| 183 | if (s_desc != NULL) |
---|
| 184 | shout_set_description(shout, s_desc); |
---|
| 185 | |
---|
| 186 | if (s_genre != NULL) |
---|
| 187 | shout_set_genre(shout, s_genre); |
---|
| 188 | |
---|
| 189 | if (s_name != NULL) |
---|
| 190 | shout_set_name(shout, s_name); |
---|
| 191 | |
---|
| 192 | if (s_url != NULL) |
---|
| 193 | shout_set_url(shout, s_url); |
---|
| 194 | |
---|
| 195 | if (shout_open(shout) != SHOUTERR_SUCCESS) { |
---|
| 196 | ROAR_ERR("Can not open connection via libshout!"); |
---|
| 197 | return -1; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 201 | inst->inst = (void*)shout; |
---|
| 202 | inst->write = driver_shout_write; |
---|
[3589] | 203 | inst->close = driver_shout_close; |
---|
[950] | 204 | |
---|
| 205 | return 0; |
---|
| 206 | } |
---|
| 207 | |
---|
[3589] | 208 | int driver_shout_close(struct roar_vio_calls * vio) { |
---|
[950] | 209 | |
---|
[3589] | 210 | shout_close((shout_t *)vio->inst); |
---|
[950] | 211 | |
---|
| 212 | if ( _driver_shout_usage_counter-- == 1 ) |
---|
| 213 | shout_shutdown(); |
---|
| 214 | |
---|
| 215 | return 0; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | ssize_t driver_shout_write(struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 219 | if (shout_send((shout_t *)vio->inst, (unsigned char*)buf, count) != SHOUTERR_SUCCESS) |
---|
| 220 | return -1; |
---|
| 221 | |
---|
| 222 | return count; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | #endif |
---|
| 226 | //ll |
---|