Programming With Libshout 2Xiph.org$Id: libshout.xml,v 1.5 2003/07/10 01:46:24 brendan Exp $ 3 Jul 2003Overview
libshout is a library for streaming audio to icecast or shoutcast-compatible
servers. Currently it supports two audio formats and three protocols.
Audio FormatsOgg VorbisMP3ProtocolsHTTPAudiocastShoutCastReferenceFunctionsGlobal functionsvoid shout_init
Initializes the shout library. Currently this initializes the networking
mutexes when the library is built with thread safety. This function must
always be called before any other libshout function.
void shout_shutdown
Releases any resources which may have been allocated by a call to
shout_init. An
application should call this function after it has finished using libshout.
const char *shout_versionint *majorint *minorint *patch
Returns the version of the libshout library, both as a string via the
return value, and as a set of integers corresponding to the major,
minor and patch levels of the library. The application must allocate
the integer parameters. If any parameter is NULL, libshout will not
attempt to set it.
Managing connectionsshout_t *shout_new
Allocates a new shout_t structure. May return NULL if no memory
is available. The result should be disposed of with
shout_free when you are
finished with it.
void shout_freeshout_t *self
Frees a shout_t allocated by
shout_new.
int shout_openshout_t *self
Opens a connection to a server. All connection parameters must have been
set prior to this call.
Return ValuesSHOUTERR_SUCCESSThe connection was successfully opened.SHOUTERR_INSANEself is corrupt or incorrect. Possible reasons
include an unset host, port, or password.SHOUTERR_CONNECTEDThe connection has already been opened.SHOUTERR_UNSUPPORTEDThe protocol/format combination is unsupported. For instance,
Ogg Vorbis may only be sent via the HTTP protocol.SHOUTERR_NOCONNECTA connection to the server could not be established.SHOUTERR_SOCKETAn error occured while talking to the server.SHOUTERR_NOLOGINThe server refused login, probably because authentication
failed.SHOUTERR_MALLOCThere wasn't enough memory to complete the operation.int shout_closeshout_t *self
Closes a connection to the server.
Return ValuesSHOUTERR_SUCCESSThe connection was successfully closed.SHOUTERR_INSANEself is not a valid shout_t
object.SHOUTERR_UNCONNECTEDself is not currently connected.const char *shout_get_errorshout_t *self
Returns a statically allocated string describing the last shout error
that occured in this connection. Only valid until the next call affecting
this connection.
int shout_get_errnoshout_t *self
Returns the shout error code of the last error that occured in this connection.
Sending dataint shout_sendshout_t *selfconst unsigned char *data>size_tlen
Sends len bytes of audio data from the buffer pointed to by
data to the server. The connection must already have been
established by a successful call to
shout_open.
Return ValuesSHOUTERR_SUCCESSThe audio data was sent successfully.SHOUTERR_INSANEself is not a valid shout_t
object.SHOUTERR_UNCONNECTEDself is not currently connected.SHOUTERR_MALLOCThere wasn't enough memory to complete the operation.SHOUTERR_SOCKETAn error occured while talking to the server.ssize_tshout_send_rawshout_t *selfconst unsigned char *data>size_tlen
Sends len bytes of audio data from the buffer pointed to by
data to the server. The data is not parsed for timing
or validity, but sent raw over the connection. The connection must already have been
established by a successful call to
shout_open.
This function should not be used unless you know exactly what you
are doing. Its use is deprecated and it may be removed in a future version of
the library.Return Values>= 0The number of bytes written.SHOUTERR_INSANEself is not a valid shout_t
object.SHOUTERR_UNCONNECTEDself is not currently connected.SHOUTERR_SOCKETAn error occured while talking to the server.void shout_syncshout_t *self
Causes the caller to sleep for the amount of time necessary to play back
audio sent since the last call to shout_sync. Should
be called before every call to
shout_send to
ensure that audio data is sent to the server at the correct speed.
Alternatively, the caller may use
shout_delay to
determine the number of milliseconds to wait and delay itself.
int shout_delayshout_t *self
Returns the number of milliseconds the caller should wait before calling
shout_send again.
This function is provided as an alternative to
shout_sync for
applications that may wish to do other processing in the meantime.
Connection parameters
The following functions are used to get or set attributes of the
shout_t object before calling
shout_open. They all
work the same way: they operate on one attribute of a
shout_t*. The shout_get_* functions
return the value of their associated parameter, or 0 on error (that's
NULL for those functions that return strings). The
shout_set_* functions will return either
SHOUTERR_SUCCESS on success, or one of:
SHOUTERR_INSANE - shout_t
is invalid.SHOUTERR_MALLOC - libshout could not
allocate enough memory to assign the parameter.SHOUTERR_CONNECTED - you are attempting
to change a connection attribute while the connection is open. Since these
parameters are only used when first opening the connection, this operation
would be useless.int shout_set_hostshout_t *selfconst char *host
Sets the server hostname or IP address. The default is localhost.
const char *shout_get_hostshout_t *self
Returns the server hostname or IP address.
int shout_set_portshout_t *selfint port
Sets the server port. The default is 8000.
int shout_get_portshout_t *self
Returns the server port.
int shout_set_usershout_t *selfconst char *user
Sets the user to authenticate as, for protocols that can use this parameter.
The default is source.
const char *shout_get_usershout_t *self
Returns the user name.
int shout_set_passshout_t *selfconst char *pass
Sets the password to authenticate to the server with. This parameter
must be set. There is no default.
const char *shout_get_passshout_t *self
Returns the password.
int shout_set_protocolshout_t *selfint protocol
Set the protocol with which to connect to the server. Supported protocols
are listed in Protocol Constants.
The default is SHOUT_PROTOCOL_HTTP (compatible with
Icecast 2).
int shout_get_protocolshout_t *self
Returns the protocol used to connect to the server.
int shout_set_formatshout_t *selfint format
Sets the audio format of this stream. The currently supported formats
are listed in Format Constants.
The default is SHOUT_FORMAT_VORBIS.
int shout_get_formatshout_t *self
Returns the audio format used by this stream.
int shout_set_mountshout_t *selfconst char *mount
Sets the mount point for this stream, for protocols that support this option
(SHOUT_PROTOCOL_ICY doesn't).
const char *shout_get_mountshout_t *self
Returns the stream mount point.
int shout_set_dumpfileshout_t *selfconst char *dumpfile
If the server supports it, you can request that your stream be archived
on the server under the name dumpfile. This can quickly
eat a lot of disk space, so think twice before setting it.
const char *shout_get_dumpfileshout_t *self
Returns the dump file, if specified.
int shout_set_agentshout_t *selfconst char *agent
Sets the user agent header. This is libshout/VERSION
by default. If you don't know what this function is for, don't use it.
const char *shout_get_agentshout_t *self
Returns the user agent.
Directory parameters
The following parameters are optional. They are used to control whether
and how your stream will be listed in the server's stream directory (if available).
int shout_set_publicshout_t *selfint makepublic
Setting this to 1 asks the server to list the stream in
any directories it knows about. To suppress listing, set this to
0. The default is 0.
int shout_get_publicshout_t *self
Returns whether or not this stream is public.
int shout_set_nameshout_t *selfconst char *name
Sets the name of the stream.
const char *shout_get_nameshout_t *self
Returns the stream name.
int shout_set_urlshout_t *selfconst char *url
Sets the URL of a site about this stream.
const char *shout_get_urlshout_t *self
Returns the stream URL.
int shout_set_genreshout_t *selfconst char *genre
Sets the genre (or genres) of the stream. This is usually a keyword list,
eg "pop rock rap".
const char *shout_get_genreshout_t *self
Returns the stream genre.
int shout_set_descriptionshout_t *selfconst char *description
Sets the description of this stream.
const char *shout_get_descriptionshout_t *self
Returns the stream description.
int shout_set_audio_infoshout_t *selfconst char *nameconst char *value
Sets a stream audio parameter (eg bitrate, samplerate, channels or quality).
The currently defined parameters are listed in the
Audio Info Constants section, but
you are free to add additional fields if your directory server understands them.
const char *shout_get_audio_infoshout_t *selfconst char *name
Returns the value of the audio info field name, if defined.
Metadata
These functions currently only make sense for MP3 streams. Vorbis streams are expected
to embed metadata as vorbis comments in the audio stream.
shout_metadata_t *shout_metadata_new
Allocates a new metadata structure, or returns NULL if no memory is available. The
returned structure should be freed with
shout_metadata_free when you are done with
it.
void shout_metadata_freeshout_metadata_t *self
Frees any resources associated with self.
int shout_metadata_addshout_metadata_t *selfconst char *nameconst char *value
Add metadata value value to self, under the
key name. You'll probably want to set name
to "song", though "url" may also be
useful.
Return ValuesSHOUTERR_SUCCESSThe metadata was copied into self.SHOUTERR_INSANEself is not a valid shout_metadata_t object.SHOUTERR_MALLOCCouldn't allocate enough memory to copy the metadata.int shout_set_metadatashout_t *selfshout_metadata_t *metadata
Sets metadata on the connection self to metadata.
Only MP3 streams support this type of metadata update. You may use this function
on defined but closed connections (this is useful if you simply want to set the
metadata for a stream provided by another process).
Return ValuesSHOUTERR_SUCCESSMetadata was updated successfully.SHOUTERR_INSANEself and/or metadata is invalid.SHOUTERR_MALLOCCouldn't allocate enough memory to complete the operation.SHOUTERR_NOCONNECTThe server refused the connection attempt.SHOUTERR_NOLOGINThe server did not accept your authorization credentials.SHOUTERR_SOCKETAn error occured talking to the server.SHOUTERR_METADATAThe server returned any other error (eg bad mount point).Data Typesshout_tOpaque data type that refers to a single server connection.shout_metadata_tOpaque data type that refers to a set of metadata attributes. Currently
the only defined attribute is song.ConstantsError CodesSHOUTERR_SUCCESSIndicates success.SHOUTERR_INSANEIndicates bad parameters, either nonsense or not applicable due to the current
state of the connection.SHOUTERR_MALLOCIndicates the function could not allocate the memory it required.SHOUTERR_NOCONNECTIndicates a connection with the server could not be established.SHOUTERR_NOLOGINIndicates the server refused to accept a login attempt. This could be caused
by a bad user name or password.SHOUTERR_SOCKETIndicates an error sending or receiving data.SHOUTERR_METADATAIndicates an error updating metadata on the server.SHOUTERR_CONNECTEDIndicates that, while connected, you attempted to call a function which only makes
sense before connection (eg you attempted to set the user name or stream name).SHOUTERR_UNCONNECTEDIndicates that you attempted to use a function that requires an open connection
(for example, shout_send) while you were not connected.SHOUTERR_UNSUPPORTEDIndicates that you attempted to use a function which is unsupported in the
state of your connection. For example, attempting to set metadata while using the
Ogg Vorbis format is unsupported.FormatsSHOUT_FORMAT_VORBISThe Ogg Vorbis format. This is the default format.SHOUT_FORMAT_MP3The MP3 format.ProtocolsSHOUT_PROTOCOL_HTTPThe HTTP protocol. This is the native protocol of the
icecast 2 server, and is the default.SHOUT_PROTOCOL_XAUDIOCASTThe Audiocast format. This is the native protocol of
icecast 1.SHOUT_PROTOCOL_ICYThe ShoutCast format. This is the native protocol of
ShoutCast.Audio ParametersSHOUT_AI_BITRATEUsed to specify the nominal bitrate of the stream.SHOUT_AI_SAMPLERATEUsed to specify the samplerate of the stream.SHOUT_AI_CHANNELSUsed to specify the number of channels (usually one or two).SHOUT_AI_QUALITYUsed to specify the Ogg Vorbis encoding quality of the stream.