source: roaraudio/roard/driver_shout.c @ 957:96860770977c

Last change on this file since 957:96860770977c was 957:96860770977c, checked in by phi, 15 years ago

improved codec check

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