# multisocketsink

This plugin writes incoming data to a set of sockets. The sockets can be added to multisocketsink by emitting the signal. For each descriptor added, the signal will be called.

A client can also be added with the signal that allows for more control over what and how much data a client initially receives.

Clients can be removed from multisocketsink by emitting the signal. For each descriptor removed, the signal will be called. The signal can also be fired when multisocketsink decides that a client is not active anymore or, depending on the value of the recover-policy property, if the client is reading too slowly. In all cases, multisocketsink will never close a socket itself. The user of multisocketsink is responsible for closing all sockets. This can for example be done in response to the signal. Note that multisocketsink still has a reference to the socket when the signal is emitted, so that "get-stats" can be performed on the descriptor; it is therefore not safe to close the socket in the signal handler, and you should use the signal to safely close the socket.

Multisocketsink internally keeps a queue of the incoming buffers and uses a separate thread to send the buffers to the clients. This ensures that no client write can block the pipeline and that clients can read with different speeds.

When adding a client to multisocketsink, the sync-method property will define which buffer in the queued buffers will be sent first to the client. Clients can be sent the most recent buffer (which might not be decodable by the client if it is not a keyframe), the next keyframe received in multisocketsink (which can take some time depending on the keyframe rate), or the last received keyframe (which will cause a simple burst-on-connect). Multisocketsink will always keep at least one keyframe in its internal buffers when the sync-mode is set to latest-keyframe.

There are additional values for the sync-method property to allow finer control over burst-on-connect behaviour. By selecting the 'burst' method a minimum burst size can be chosen, 'burst-keyframe' additionally requires that the burst begin with a keyframe, and 'burst-with-keyframe' attempts to burst beginning with a keyframe, but will prefer a minimum burst size even if it requires not starting with a keyframe.

Multisocketsink can be instructed to keep at least a minimum amount of data expressed in time or byte units in its internal queues with the time-min and bytes-min properties respectively. These properties are useful if the application adds clients with the signal to make sure that a burst connect can actually be honored.

When streaming data, clients are allowed to read at a different rate than the rate at which multisocketsink receives data. If the client is reading too fast, no data will be send to the client until multisocketsink receives more data. If the client, however, reads too slowly, data for that client will be queued up in multisocketsink. Two properties control the amount of data (buffers) that is queued in multisocketsink: buffers-max and buffers-soft-max. A client that falls behind by buffers-max is removed from multisocketsink forcibly.

A client with a lag of at least buffers-soft-max enters the recovery procedure which is controlled with the recover-policy property. A recover policy of NONE will do nothing, RESYNC_LATEST will send the most recently received buffer as the next buffer for the client, RESYNC_SOFT_LIMIT positions the client to the soft limit in the buffer queue and RESYNC_KEYFRAME positions the client at the most recent keyframe in the buffer queue.

multisocketsink will by default synchronize on the clock before serving the buffers to the clients. This behaviour can be disabled by setting the sync property to FALSE. Multisocketsink will by default not do QoS and will never drop late buffers.

## Hierarchy

    GObject
        ╰──GInitiallyUnowned
            ╰──GstObject
                ╰──GstElement
                    ╰──GstBaseSink
                        ╰──GstMultiHandleSink
                            ╰──multisocketsink

## Factory details

Authors: – Thomas Vander Stichele , Wim Taymans , Sebastian Dröge

Classification: – `Sink/Network`

Rank – none

Plugin – tcp

Package – GStreamer Base Plug-ins

## Pad Templates

### `sink`

    ANY

Presence – always

Direction – sink

Object type – GstPad

## Signals

### client-added

    client_added_callback (GstElement * gstmultisocketsink,
                           GObject * socket,
                           gpointer udata)

    def client_added_callback (gstmultisocketsink, socket, udata):
        #python callback for the 'client-added' signal

    function client_added_callback(gstmultisocketsink: GstElement * gstmultisocketsink, socket: GObject * socket, udata: gpointer udata): {
        // javascript callback for the 'client-added' signal
    }

The given socket was added to multisocketsink. This signal will be emitted from the streaming thread so application should be prepared for that.

Parameters:

`gstmultisocketsink` –

the multisocketsink element that emitted this signal

`socket` –

the socket that was added to multisocketsink

`udata` –
No description available

Flags: Run Last

### client-removed

    client_removed_callback (GstElement * gstmultisocketsink,
                             GSocket * socket,
                             GstMultiHandleSinkClientStatus * status,
                             gpointer udata)

    def client_removed_callback (gstmultisocketsink, socket, status, udata):
        #python callback for the 'client-removed' signal

    function client_removed_callback(gstmultisocketsink: GstElement * gstmultisocketsink, socket: GSocket * socket, status: GstMultiHandleSinkClientStatus * status, udata: gpointer udata): {
        // javascript callback for the 'client-removed' signal
    }

The given socket is about to be removed from multisocketsink. This signal will be emitted from the streaming thread so applications should be prepared for that.

gstmultisocketsink still holds a handle to socket so it is possible to call the get-stats signal from this callback. For the same reason it is not safe to `close()` and reuse socket in this callback.

Parameters:

`gstmultisocketsink` –

the multisocketsink element that emitted this signal

`socket` –

the socket that is to be removed from multisocketsink

`status` –

the reason why the client was removed

`udata` –
No description available

Flags: Run Last

### client-socket-removed

    client_socket_removed_callback (GstElement * gstmultisocketsink,
                                    GSocket * socket,
                                    gpointer udata)

    def client_socket_removed_callback (gstmultisocketsink, socket, udata):
        #python callback for the 'client-socket-removed' signal

    function client_socket_removed_callback(gstmultisocketsink: GstElement * gstmultisocketsink, socket: GSocket * socket, udata: gpointer udata): {
        // javascript callback for the 'client-socket-removed' signal
    }

The given socket was removed from multisocketsink. This signal will be emitted from the streaming thread so applications should be prepared for that.

In this callback, gstmultisocketsink has removed all the information associated with socket and it is therefore not possible to call get-stats with socket. It is however safe to `close()` and reuse fd in the callback.

Parameters:

`gstmultisocketsink` –

the multisocketsink element that emitted this signal

`socket` –

the socket that was removed from multisocketsink

`udata` –
No description available

Flags: Run Last

## Action Signals

### add

    g_signal_emit_by_name (gstmultisocketsink, "add", socket);

    ret = gstmultisocketsink.emit ("add", socket)

    let ret = gstmultisocketsink.emit ("add", socket);

Hand the given open socket to multisocketsink to write to.

Parameters:

`gstmultisocketsink` (GstElement *) –

the multisocketsink element to emit this signal on

`socket` (GSocket *) –

the socket to add to multisocketsink

Flags: Run Last / Action

### add-full

    g_signal_emit_by_name (gstmultisocketsink, "add-full", socket, sync, format_min, value_min, format_max, value_max);

    ret = gstmultisocketsink.emit ("add-full", socket, sync, format_min, value_min, format_max, value_max)

    let ret = gstmultisocketsink.emit ("add-full", socket, sync, format_min, value_min, format_max, value_max);

Hand the given open socket to multisocketsink to write to and specify the burst parameters for the new connection.

Parameters:

`gstmultisocketsink` (GstElement *) –

the multisocketsink element to emit this signal on

`socket` (GSocket *) –

the socket to add to multisocketsink

`sync` (GstMultiHandleSinkSyncMethod *) –

the sync method to use

`format_min` (GstFormat *) –

the format of value_min

`value_min` (guint64) –

the minimum amount of data to burst expressed in format_min units.

`format_max` (GstFormat *) –

the format of value_max

`value_max` (guint64) –

the maximum amount of data to burst expressed in format_max units.

Flags: Run Last / Action

### get-stats

    g_signal_emit_by_name (gstmultisocketsink, "get-stats", socket, &ret);

    ret = gstmultisocketsink.emit ("get-stats", socket)

    let ret = gstmultisocketsink.emit ("get-stats", socket);

Get statistics about socket. This function returns a GstStructure.

Parameters:

`gstmultisocketsink` (GstElement *) –

the multisocketsink element to emit this signal on

`socket` (GSocket *) –

the socket to get stats of from multisocketsink

Returns (GstStructure *) –

a GstStructure with the statistics. The structure contains values that represent: total number of bytes sent, time when the client was added, time when the client was disconnected/removed, time the client is/was active, last activity time (in epoch seconds), number of buffers dropped. All times are expressed in nanoseconds (GstClockTime).

Flags: Run Last / Action

### remove

    g_signal_emit_by_name (gstmultisocketsink, "remove", socket);

    ret = gstmultisocketsink.emit ("remove", socket)

    let ret = gstmultisocketsink.emit ("remove", socket);

Remove the given open socket from multisocketsink.

Parameters:

`gstmultisocketsink` (GstElement *) –

the multisocketsink element to emit this signal on

`socket` (GSocket *) –

the socket to remove from multisocketsink

Flags: Run Last / Action

### remove-flush

    g_signal_emit_by_name (gstmultisocketsink, "remove-flush", socket);

    ret = gstmultisocketsink.emit ("remove-flush", socket)

    let ret = gstmultisocketsink.emit ("remove-flush", socket);

Remove the given open socket from multisocketsink after flushing all the pending data to the socket.

Parameters:

`gstmultisocketsink` (GstElement *) –

the multisocketsink element to emit this signal on

`socket` (GSocket *) –

the socket to remove from multisocketsink

Flags: Run Last / Action

## Properties

### send-dispatched

    “send-dispatched” gboolean

Sends a GstNetworkMessageDispatched event upstream whenever a buffer is sent to a client. The event is a CUSTOM event name GstNetworkMessageDispatched and contains:

"object" G_TYPE_OBJECT : the object identifying the client "buffer" GST_TYPE_BUFFER : the buffer sent to the client

Flags : Read / Write

Default value : false

### send-messages

    “send-messages” gboolean

Sends a GstNetworkMessage event upstream whenever a buffer is received from a client. The event is a CUSTOM event name GstNetworkMessage and contains:

"object" G_TYPE_OBJECT : the object identifying the client "buffer" GST_TYPE_BUFFER : the buffer with data received from the client

Flags : Read / Write

Default value : false

## Named constants

### GstMultiHandleSinkClientStatus

#### Members

`ok` (0) – ok
`closed` (1) – Closed
`removed` (2) – Removed
`slow` (3) – Too slow
`error` (4) – Error
`duplicate` (5) – Duplicate
`flushing` (6) – Flushing

The results of the search are