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