1 /*  shout.h
2  *
3  *  API for libshout, the streaming library for icecast
4  *
5  *  Copyright (C) 2002-2003 the Icecast team <team@icecast.org>
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Library General Public
9  *  License as published by the Free Software Foundation; either
10  *  version 2 of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Library General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Library General Public
18  *  License along with this library; if not, write to the Free
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 #ifndef __LIBSHOUT_SHOUT_H__
22 #define __LIBSHOUT_SHOUT_H__
23 
24 #include <sys/types.h>
25 #ifdef WIN32
26 #include <os.h>
27 # ifdef _MSC_VER
28 #  undef inline
29 #  define inline __inline
30 #if (_MSC_VER >= 1400)			// VC8+
31 #ifndef _CRT_SECURE_NO_DEPRECATE
32 #define _CRT_SECURE_NO_DEPRECATE
33 #endif
34 #ifndef _CRT_NONSTDC_NO_DEPRECATE
35 #define _CRT_NONSTDC_NO_DEPRECATE
36 #endif
37 #endif // VC8+
38 # endif
39 #if  !defined(__MINGW32__) && (!defined(_MSC_VER) || _MSC_VER < 1900)
40 #define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list))
41 #endif
42 
43 #endif
44 
45 #define SHOUTERR_SUCCESS	(0)
46 #define SHOUTERR_INSANE		(-1)
47 #define SHOUTERR_NOCONNECT	(-2)
48 #define SHOUTERR_NOLOGIN	(-3)
49 #define SHOUTERR_SOCKET		(-4)
50 #define SHOUTERR_MALLOC		(-5)
51 #define SHOUTERR_METADATA	(-6)
52 #define SHOUTERR_CONNECTED	(-7)
53 #define SHOUTERR_UNCONNECTED	(-8)
54 #define SHOUTERR_UNSUPPORTED	(-9)
55 
56 #define SHOUTERR_BUSY		(-10)
57 
58 #define SHOUT_FORMAT_OGG	(0)
59 #define SHOUT_FORMAT_MP3	(1)
60 /* backward-compatibility alias */
61 #define SHOUT_FORMAT_VORBIS	SHOUT_FORMAT_OGG
62 
63 #define SHOUT_PROTOCOL_HTTP		(0)
64 #define SHOUT_PROTOCOL_XAUDIOCAST	(1)
65 #define SHOUT_PROTOCOL_ICY		(2)
66 
67 #define SHOUT_AI_BITRATE	"bitrate"
68 #define SHOUT_AI_SAMPLERATE	"samplerate"
69 #define SHOUT_AI_CHANNELS	"channels"
70 #define SHOUT_AI_QUALITY	"quality"
71 
72 typedef struct shout shout_t;
73 typedef struct _util_dict shout_metadata_t;
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 /* initializes the shout library. Must be called before anything else */
80 void shout_init(void);
81 
82 /* shuts down the shout library, deallocating any global storage. Don't call
83  * anything afterwards */
84 void shout_shutdown(void);
85 
86 /* returns a static version string.  Non-null parameters will be set to the
87  * value of the library major, minor, and patch levels, respectively */
88 const char *shout_version(int *major, int *minor, int *patch);
89 
90 /* Allocates and sets up a new shout_t.  Returns NULL if it can't get enough
91  * memory.  The returns shout_t must be disposed of with shout_free. */
92 shout_t *shout_new(void);
93 
94 /* Free all memory allocated by a shout_t */
95 void shout_free(shout_t *self);
96 
97 /* Returns a statically allocated string describing the last shout error
98  * to occur.  Only valid until the next libshout call on this shout_t */
99 const char *shout_get_error(shout_t *self);
100 
101 /* Return the error code (e.g. SHOUTERR_SOCKET) for this shout instance */
102 int shout_get_errno(shout_t *self);
103 
104 /* returns SHOUTERR_CONNECTED or SHOUTERR_UNCONNECTED */
105 int shout_get_connected(shout_t *self);
106 
107 /* Parameter manipulation functions.  libshout makes copies of all parameters,
108  * the caller may free its copies after giving them to libshout.  May return
109  * SHOUTERR_MALLOC */
110 
111 int shout_set_host(shout_t *self, const char *host);
112 const char *shout_get_host(shout_t *self);
113 
114 int shout_set_port(shout_t *self, unsigned short port);
115 unsigned short shout_get_port(shout_t *self);
116 
117 int shout_set_password(shout_t *, const char *password);
118 const char *shout_get_password(shout_t *self);
119 
120 int shout_set_mount(shout_t *self, const char *mount);
121 const char *shout_get_mount(shout_t *self);
122 
123 int shout_set_name(shout_t *self, const char *name);
124 const char *shout_get_name(shout_t *self);
125 
126 int shout_set_url(shout_t *self, const char *url);
127 const char *shout_get_url(shout_t *self);
128 
129 int shout_set_genre(shout_t *self, const char *genre);
130 const char *shout_get_genre(shout_t *self);
131 
132 int shout_set_user(shout_t *self, const char *username);
133 const char *shout_get_user(shout_t *self);
134 
135 int shout_set_agent(shout_t *self, const char *username);
136 const char *shout_get_agent(shout_t *self);
137 
138 int shout_set_description(shout_t *self, const char *description);
139 const char *shout_get_description(shout_t *self);
140 
141 int shout_set_dumpfile(shout_t *self, const char *dumpfile);
142 const char *shout_get_dumpfile(shout_t *self);
143 
144 int shout_set_audio_info(shout_t *self, const char *name, const char *value);
145 const char *shout_get_audio_info(shout_t *self, const char *name);
146 
147 int shout_set_public(shout_t *self, unsigned int make_public);
148 unsigned int shout_get_public(shout_t *self);
149 
150 /* takes a SHOUT_FORMAT_xxxx argument */
151 int shout_set_format(shout_t *self, unsigned int format);
152 unsigned int shout_get_format(shout_t *self);
153 
154 /* takes a SHOUT_PROTOCOL_xxxxx argument */
155 int shout_set_protocol(shout_t *self, unsigned int protocol);
156 unsigned int shout_get_protocol(shout_t *self);
157 
158 /* Instructs libshout to use nonblocking I/O. Must be called before
159  * shout_open (no switching back and forth midstream at the moment). */
160 int shout_set_nonblocking(shout_t* self, unsigned int nonblocking);
161 unsigned int shout_get_nonblocking(shout_t *self);
162 
163 /* Opens a connection to the server.  All parameters must already be set */
164 int shout_open(shout_t *self);
165 
166 /* Closes a connection to the server */
167 int shout_close(shout_t *self);
168 
169 /* Send data to the server, parsing it for format specific timing info */
170 int shout_send(shout_t *self, const unsigned char *data, size_t len);
171 
172 /* Send unparsed data to the server.  Do not use this unless you know
173  * what you are doing.
174  * Returns the number of bytes written, or < 0 on error.
175  */
176 ssize_t shout_send_raw(shout_t *self, const unsigned char *data, size_t len);
177 
178 /* return the number of bytes currently on the write queue (only makes sense in
179  * nonblocking mode). */
180 ssize_t shout_queuelen(shout_t *self);
181 
182 /* Puts caller to sleep until it is time to send more data to the server */
183 void shout_sync(shout_t *self);
184 
185 /* Amount of time in ms caller should wait before sending again */
186 int shout_delay(shout_t *self);
187 
188 /* Sets MP3 metadata.
189  * Returns:
190  *   SHOUTERR_SUCCESS
191  *   SHOUTERR_UNSUPPORTED if format isn't MP3
192  *   SHOUTERR_MALLOC
193  *   SHOUTERR_INSANE
194  *   SHOUTERR_NOCONNECT
195  *   SHOUTERR_SOCKET
196  */
197 int shout_set_metadata(shout_t *self, shout_metadata_t *metadata);
198 
199 /* Allocates a new metadata structure.  Must be freed by shout_metadata_free. */
200 shout_metadata_t *shout_metadata_new(void);
201 
202 /* Free resources allocated by shout_metadata_t */
203 void shout_metadata_free(shout_metadata_t *self);
204 
205 /* Add a parameter to the metadata structure.
206  * Returns:
207  *   SHOUTERR_SUCCESS on success
208  *   SHOUTERR_INSANE if self isn't a valid shout_metadata_t* or name is null
209  *   SHOUTERR_MALLOC if memory can't be allocated */
210 int shout_metadata_add(shout_metadata_t *self, const char *name, const char *value);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 /* --- Compiled features --- */
217 
218 #define SHOUT_THREADSAFE @SHOUT_THREADSAFE@
219 
220 #endif /* __LIBSHOUT_SHOUT_H__ */
221