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