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; |
---|
33 | char * s_pw = NULL; |
---|
34 | int s_port = -1; |
---|
35 | char * s_desc = NULL; |
---|
36 | char * s_genre = NULL; |
---|
37 | char * s_name = NULL; |
---|
38 | char * s_url = NULL; |
---|
39 | int s_public = 0; |
---|
40 | shout_t * shout; |
---|
41 | |
---|
42 | if ( info->codec == ROAR_CODEC_DEFAULT ) |
---|
43 | info->codec = ROAR_CODEC_OGG_VORBIS; |
---|
44 | |
---|
45 | if ( info->codec != ROAR_CODEC_OGG_VORBIS ) { |
---|
46 | ROAR_ERR("This driver only supports Ogg/Vorbis, current codec is %s", roar_codec2str(info->codec)); |
---|
47 | return -1; |
---|
48 | } |
---|
49 | |
---|
50 | if ( s_server == NULL ) |
---|
51 | s_server = "localhost"; |
---|
52 | |
---|
53 | if ( s_mount == NULL ) |
---|
54 | s_mount = "/roar.ogg"; |
---|
55 | |
---|
56 | if ( s_pw == NULL ) |
---|
57 | s_pw = "hackme"; |
---|
58 | |
---|
59 | if ( s_port == -1 ) |
---|
60 | s_port = 8000; |
---|
61 | |
---|
62 | if ( _driver_shout_usage_counter++ == 0 ) |
---|
63 | shout_init(); |
---|
64 | |
---|
65 | if (!(shout = shout_new())) { |
---|
66 | ROAR_ERR("Can not clreate shout object"); |
---|
67 | return 1; |
---|
68 | } |
---|
69 | |
---|
70 | if (shout_set_host(shout, s_server) != SHOUTERR_SUCCESS) { |
---|
71 | ROAR_ERR("Error setting hostname: %s", shout_get_error(shout)); |
---|
72 | return 1; |
---|
73 | } |
---|
74 | |
---|
75 | if (shout_set_protocol(shout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { |
---|
76 | ROAR_ERR("Error setting protocol: %s", shout_get_error(shout)); |
---|
77 | return 1; |
---|
78 | } |
---|
79 | |
---|
80 | if (shout_set_port(shout, s_port) != SHOUTERR_SUCCESS) { |
---|
81 | ROAR_ERR("Error setting port: %s", shout_get_error(shout)); |
---|
82 | return 1; |
---|
83 | } |
---|
84 | |
---|
85 | if (shout_set_password(shout, s_pw) != SHOUTERR_SUCCESS) { |
---|
86 | ROAR_ERR("Error setting password: %s", shout_get_error(shout)); |
---|
87 | return 1; |
---|
88 | } |
---|
89 | |
---|
90 | if (shout_set_mount(shout, s_mount) != SHOUTERR_SUCCESS) { |
---|
91 | ROAR_ERR("Error setting mount: %s", shout_get_error(shout)); |
---|
92 | return 1; |
---|
93 | } |
---|
94 | |
---|
95 | if (shout_set_user(shout, "source") != SHOUTERR_SUCCESS) { |
---|
96 | ROAR_ERR("Error setting user: %s", shout_get_error(shout)); |
---|
97 | return 1; |
---|
98 | } |
---|
99 | |
---|
100 | if (shout_set_format(shout, SHOUT_FORMAT_OGG) != SHOUTERR_SUCCESS) { |
---|
101 | ROAR_ERR("Error setting format: %s", shout_get_error(shout)); |
---|
102 | return 1; |
---|
103 | } |
---|
104 | |
---|
105 | shout_set_public(shout, s_public); |
---|
106 | |
---|
107 | if (s_desc != NULL) |
---|
108 | shout_set_description(shout, s_desc); |
---|
109 | |
---|
110 | if (s_genre != NULL) |
---|
111 | shout_set_genre(shout, s_genre); |
---|
112 | |
---|
113 | if (s_name != NULL) |
---|
114 | shout_set_name(shout, s_name); |
---|
115 | |
---|
116 | if (s_url != NULL) |
---|
117 | shout_set_url(shout, s_url); |
---|
118 | |
---|
119 | if (shout_open(shout) != SHOUTERR_SUCCESS) { |
---|
120 | ROAR_ERR("Can not open connection via libshout!"); |
---|
121 | return -1; |
---|
122 | } |
---|
123 | |
---|
124 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
125 | inst->inst = (void*)shout; |
---|
126 | inst->write = driver_shout_write; |
---|
127 | |
---|
128 | return 0; |
---|
129 | } |
---|
130 | |
---|
131 | int driver_shout_close(DRIVER_USERDATA_T inst) { |
---|
132 | |
---|
133 | shout_close((shout_t *)((struct roar_vio_calls *)inst)->inst); |
---|
134 | |
---|
135 | if ( _driver_shout_usage_counter-- == 1 ) |
---|
136 | shout_shutdown(); |
---|
137 | |
---|
138 | return 0; |
---|
139 | } |
---|
140 | |
---|
141 | ssize_t driver_shout_write(struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
142 | if (shout_send((shout_t *)vio->inst, (unsigned char*)buf, count) != SHOUTERR_SUCCESS) |
---|
143 | return -1; |
---|
144 | |
---|
145 | return count; |
---|
146 | } |
---|
147 | |
---|
148 | #endif |
---|
149 | //ll |
---|