# Module Shout

    module Shout: sig .. end

Libshout 2 bindings for OCaml.

- Author(s): Samuel Mimram

## Types and exceptions.

    type shout

A shout connection.

    exception Insane

Bad parameters, either nonsense or not applicable due to the current state of the connection.

    exception No_connect

A connection with the server could not be established.

    exception No_login

The server refused to accept a login attemp (bad user name or password?).

    exception Socket

An error occured while sending or receiving data.

    exception Malloc

A problem occured while trying to allocate memory (no more memory left?). This exception could be raised by most of the functions.

    exception Metadata

An error occured while updating the metadatas on the server.

    exception Connected

We are connected to a server.

    exception Unconnected

We are not connected to a server.

    exception Unsupported

The operation is not supported.

    exception Send_error

An error occured while sending data.

    type data_format =

`|` | `Format_vorbis` | `(*` | ogg / vorbis | `*)`
`|` | `Format_mp3` | `(*` | mp3 | `*)`

Format of audio data.

    type protocol =

`|` | `Protocol_http` | `(*` | http | `*)`
`|` | `Protocol_xaudiocast` | `(*` | audiocast | `*)`
`|` | `Protocol_icy` | `(*` | shoutcast | `*)`

Kind of protocol to use.

## Initialization and creation functions.

    val init : unit -> unit

Initialize the shout library. Must be called before anything else.

    val shutdown : unit -> unit

Shut down the shout library, deallocating any global storage. Don't call anything afterwards. This function should be called after having finished to use the shout library.

    val version : unit -> string * int * int * int

Get a version string as well as the value of the library major, minor, and patch levels, respectively.

    val get_error : shout -> string

Get a string describing the last shout error to occur. Only valid until the next call to a `Shout` function.

    val get_errno : shout -> int

Get the number of the last error.

    val new_shout : unit -> shout

Create a new `shout` value.

    val is_connected : shout -> bool

Am I connected to a shoutcast server?

## Setting and retrieving preliminary parameters.

The following parameters may be set only before calling `open_shout`. They might raise the `Malloc` exception or the `Connected` exception when attempting to change a connection attribute while the connection is open.

### Connection parameters

    val set_host : shout -> string -> unit

Set the server's hostname or ip address (default: localhost).

    val get_host : shout -> string

Retrieve the server's hostname or ip address.

    val set_port : shout -> int -> unit

Set the server's port (default: 8000).

    val get_port : shout -> int

Retrieve the server's port.

    val set_user : shout -> string -> unit

Set the user to authenticate as (default: source).

    val get_user : shout -> string

Retrieve the user to authenticate as.

    val set_password : shout -> string -> unit

Set the password to authenticate the server with.

    val get_password : shout -> string

Retrieve the server's password.

    val set_protocol : shout -> protocol -> unit

Set the protocol to connect to the server with (default: Protocol_http).

    val get_protocol : shout -> protocol

Retrieve the protocol used to connect to the server.

    val set_format : shout -> data_format -> unit

Set the stream's audio format (default: Format_vorbis).

    val get_format : shout -> data_format

Retrieve the stream's audio format.

    val set_mount : shout -> string -> unit

Set the the mountpoint (not supported by the `Protocol_icy` protocol).

    val get_mount : shout -> string

Retrieve the mountpoint.

    val set_dumpfile : shout -> string -> unit

Request that your stream be archived on the server under the specified name.

    val get_dumpfile : shout -> string

Retrieve the dumpfile name.

    val set_agent : shout -> string -> unit

Set the user agent header (default: libshout/VERSION).

    val get_agent : shout -> string

Retrieve the user agent header.

### Directory parameters (optionnal)

    val set_public : shout -> bool -> unit

Should we ask the server to list the stream in any directories it knows about (default: `false`)?

    val get_public : shout -> bool

Should we ask the server to list the stream in any directories it knows about?

    val set_name : shout -> string -> unit

Set the name of the stream.

    val get_name : shout -> string

Retrieve the name of the stream.

    val set_url : shout -> string -> unit

Set the url of a site about this stream.

    val get_url : shout -> string

Retrieve the url of a site about this stream.

    val set_genre : shout -> string -> unit

Set the stream genre.

    val get_genre : shout -> string

Retrieve the stream genre.

    val set_description : shout -> string -> unit

Set the stream description.

    val get_description : shout -> string

Retrieve the stream description.

    val set_audio_info : shout -> string -> string -> unit

`set_audio_info shout name value` sets the stream audio parameter `name` to the value `value`.

    val get_audio_info : shout -> string -> string

Retrieve a stream audio parameter.

### Multicasting

    val set_multicast_ip : shout -> string -> unit

Set the ip for multicasting the stream.

    val get_multicast_ip : shout -> string

Retrieve the ip for multicasting the stream.

## Managing the connection and sending data.

    val open_shout : shout -> unit

Open a connection to the server. All parameters must already be set.

- Raises
  - `Insane` if host, port or password is unset.
  - `Connected` if the connection has already been opened.
  - `Unsupported` if the protocol / format combination is unsupported (e.g. ogg / vobis may only be sent via the http protocol).
  - `No_connect` if a connection to the server could not be established.
  - `Socket` if an error occured while talking to the server.
  - `No_login` if the server refused login (authentication failed).

    val close : shout -> unit

Close a connection to the server.

- Raises `Unconnected` if the `shout` value is not currently connected.

    val send : shout -> string -> unit

Send data to the server, parsing it for format specific timing info.

- Raises
  - `Unconnected` if the `shout` value is not currently connected.
  - `Socket` if an error occured while talking to the server.

    val send_raw : shout -> string -> int

Deprecated. Send unparsed data to the server. Do not use this unless you know what you are doing.

- Raises
  - `Unconnected` if the `shout` value is not currently connected.
  - `Socket` if an error occured while talking to the server.
- Returns the number of bytes written.

    val sync : shout -> unit

Put caller to sleep until it is time to send more data to the server. Should be called before every call to `send` (the function `delay` could also be used to determine the amout of time the caller should wait before sendig data).

    val delay : shout -> int

Amount of time in miliseconds caller should wait before sending again.

    val set_metadata : shout -> (string * string) array -> unit

Set metadata for mp3 streams.

- Raises
  - `No_connect` if the server refused the connection attempt.
  - `No_login` if the server did not accept your authorization credentials.
  - `Socket` if an error occured talking to the server.
  - `Unsupported` if the format is not mp3.
  - `Metadata` if an other error happened (e.g. bad mount point).