Programming With Libshout 2Xiph.org$Id: libshout.xml,v 1.5 2003/07/10 01:46:24 brendan Exp $09 September 2015Overview
libshout is a library for streaming audio to icecast or shoutcast-compatible
servers. Currently it supports three formats and three protocols.
Audio FormatsOgg (audio any video with different codecs)WebM (audio and video)MP3ProtocolsHTTPRoarAudioAudiocastShoutCastReferenceFunctionsGlobal 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.int shout_get_connectedshout_t *self
Returns the connection status of the given shout_t object.
Return ValuesSHOUTERR_INSANEself is not a valid shout_t
object.SHOUTERR_UNCONNECTEDself is not currently connected.SHOUTERR_CONNECTEDself is 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.
ssize_t shout_queuelenshout_t *self
Returns the number of bytes currently on the write queue.
This is only useful in non-blocking mode.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_nonblockingshout_t *selfunsigned int nonblocking
Sets non-blocking mode. The default is 0.
unsigned int shout_get_nonblockingshout_t *self
Returns non-blocking mode or 0 in case of error.
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 *selfunsigned short port
Sets the server port. The default is 8000.
unsigned short 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_passwordshout_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_passwordshout_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_OGG.
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.
int shout_set_tlsshout_t *selfint mode
This function sets the TLS (Transport Layer Security) mode to use.
mode is a TLS mode.
This is SHOUT_TLS_AUTO by default.
To force TLS on you should use SHOUT_TLS_AUTO_NO_PLAIN and
SHOUT_TLS_DISABLED to force TLS off.While SHOUT_TLS_AUTO may connect via TLS this is not a
secure mode as everybody can do a man in the middle kind of attack and downgrade the
connection to plain.int shout_get_tlsshout_t *self
Returns the currently used TLS mode.
int shout_set_ca_directoryshout_t *selfconst char *directory
This sets the CA directory used by libshout to verify server certificates.
Defaults to system defaults.
const char *shout_get_ca_directoryshout_t *self
Returns the currently used CA directory.
int shout_set_ca_fileshout_t *selfconst char *file
Sets a file with CA certificates used to verify server certificates.
Defaults to system defaults. The file must be in PEM format.
You can use this for self signed server certificates.
In this case you point this to the server certificate in PEM format.
Keep in mind that this will allow self-signed certificates but other
checks such as hostname still needs to verify correctly.const char *shout_get_ca_fileshout_t *self
Returns the currently used CA file.
int shout_set_allowed_ciphersshout_t *selfconst char *ciphers
This sets the list of currently allowed ciphers in OpenSSL format.
Defaults to a list of ciphers considerd secure as of day of release.
Setting this to a insecure list may render encryption and authentication useless.Any application using this call must expose this list to the user.
If the user can not alter this list your application will harm security badly by
preventing the user to get to a save value by setting it manually or upgrading
libshout.
Do not use this call if you don't know what you are doing.const char *shout_get_allowed_ciphersshout_t *self
Returns the currently used list of allowed ciphers.
int shout_set_client_certificateshout_t *selfconst char *certificate
This sets the client certificate to be used. Defaults to none.
The file must be in PEM format and must contain both the certificate as well as the
private key for that certificate.
const char *shout_get_client_certificateshout_t *self
Returns the currently used client certificate.
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_metashout_t *selfconst char *nameconst char *value
This function sets the meta data for the stream.
const char *shout_get_metashout_t *selfconst char *name
This function gets the meta data for the stream.
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).Obsolate metadata Interface
All those functions have been replaced by shout_set_meta and
shout_get_meta. They may be removed by newer versions of this library.
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.
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.SHOUTERR_BUSYIndicates that the socket is busy. The funtion returning this should be
called again later. This is likely to happen in non-blocking mode but may also happen
in blocking mode.SHOUTERR_NOTLSTLS (Transport Layer Security) was requested via shout_set_tls
but is not supported by the server.SHOUTERR_TLSBADCERTA TLS (Transport Layer Security) connection has been established but the server
returned a certificate which failed the check. The certificate may be invalid or
is not signed by a trusted CA. See shout_set_tls.SHOUTERR_RETRYThe caller should retry this call later.FormatsSHOUT_FORMAT_OGGThe Ogg Format. Vorbis or any codec may be used. This is the default format.SHOUT_FORMAT_WEBMThe WebM format.SHOUT_FORMAT_WEBMAUDIOThe WebM format, audio only streams.SHOUT_FORMAT_VORBISThis is deprecated. It is an alias to SHOUT_FORMAT_OGG.
Please migrate your code.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_ROARAUDIOThe RoarAudio protocol. This is the native protocol for
RoarAudio servers.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.Stream Metadata ParametersSHOUT_META_NAMESets stream name.SHOUT_META_URLSets stream URL.SHOUT_META_GENRESets stream genre.SHOUT_META_DESCRIPTIONSets stream description.SHOUT_META_IRCSets IRC contact information for stream.SHOUT_META_AIMSets AIM contact information for stream.SHOUT_META_ICQSets ICQ contact information for stream.TLS modesSHOUT_TLS_DISABLEDTLS (Transport Layer Security) is disabled.
Passwords and data will be sent unencrypted.SHOUT_TLS_AUTOTLS (Transport Layer Security) support by the server will be autodetected. This is the default.
In this mode TLS is used if supported by the server.
Please note that this is not a secure mode as it will
not prevent any downgrade attacks. SHOUT_TLS_AUTO_NO_PLAIN is a more secure version of
this mode.SHOUT_TLS_AUTO_NO_PLAINTLS (Transport Layer Security) is used. Autodetection is used to find out about which modes
are supported by the server. This mode should be used for secure connections.SHOUT_TLS_RFC2818TLS (Transport Layer Security) is used as defined by RFC2818.
In this mode libshout expects a TLS socket on the server side and will begin with a TLS handshake
prior to any other communication.
SHOUT_TLS_RFC2817TLS (Transport Layer Security) is used as defined by RFC2817.
In this mode libshout will use HTTP/1.1's Upgrade:-process to switch to TLS.
This allows to use TLS on a non-TLS socket of the server.