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