## multifdsink

multifdsink — Send data to multiple filedescriptors

## Synopsis

    struct              GstMultiFdSink;
    enum                GstRecoverPolicy;
    enum                GstSyncMethod;
    enum                GstClientStatus;
    enum                GstTCPProtocol;
    enum                GstTCPUnitType;

## Object Hierarchy

      GObject
       +----GstObject
             +----GstElement
                   +----GstBaseSink
                         +----GstMultiFdSink
                               +----GstTCPServerSink

## Properties

      "buffers-max"              gint                  : Read / Write
      "buffers-queued"           guint                 : Read
      "buffers-soft-max"         gint                  : Read / Write
      "bytes-served"             guint64               : Read
      "bytes-to-serve"           guint64               : Read
      "mode"                     GstFDSetMode          : Read / Write
      "protocol"                 GstTCPProtocol        : Read / Write
      "recover-policy"           GstRecoverPolicy      : Read / Write
      "sync-clients"             gboolean              : Read / Write
      "sync-method"              GstSyncMethod         : Read / Write
      "timeout"                  guint64               : Read / Write
      "buffers-min"              gint                  : Read / Write
      "burst-unit"               GstTCPUnitType        : Read / Write
      "burst-value"              guint64               : Read / Write
      "bytes-min"                gint                  : Read / Write
      "time-min"                 gint64                : Read / Write
      "unit-type"                GstTCPUnitType        : Read / Write
      "units-max"                gint64                : Read / Write
      "units-soft-max"           gint64                : Read / Write
      "qos-dscp"                 gint                  : Read / Write
      "handle-read"              gboolean              : Read / Write
      "resend-streamheader"      gboolean              : Read / Write
      "num-fds"                  guint                 : Read

## Signals

      "add"                                            : Action
      "clear"                                          : Action
      "client-added"                                   : Run Last
      "client-removed"                                 : Run Last
      "get-stats"                                      : Action
      "remove"                                         : Action
      "client-fd-removed"                              : Run Last
      "add-full"                                       : Action
      "remove-flush"                                   : Action

## Description

This plugin writes incoming data to a set of file descriptors. The file descriptors can be added to multifdsink by emitting the "add" signal. For each descriptor added, the "client-added" signal will be called.

As of version 0.10.8, a client can also be added with the "add-full" signal that allows for more control over what and how much data a client initially receives.

Clients can be removed from multifdsink by emitting the "remove" signal. For each descriptor removed, the "client-removed" signal will be called. The "client-removed" signal can also be fired when multifdsink 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, multifdsink will never close a file descriptor itself. The user of multifdsink is responsible for closing all file descriptors. This can for example be done in response to the "client-fd-removed" signal. Note that multifdsink still has a reference to the file descriptor when the "client-removed" signal is emitted, so that "get-stats" can be performed on the descriptor; it is therefore not safe to close the file descriptor in the "client-removed" signal handler, and you should use the "client-fd-removed" signal to safely close the fd.

Multifdsink 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 multifdsink, 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 multifdsink (which can take some time depending on the keyframe rate), or the last received keyframe (which will cause a simple burst-on-connect). Multifdsink will always keep at least one keyframe in its internal buffers when the sync-mode is set to latest-keyframe.

As of version 0.10.8, 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.

Multifdsink 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 "add-full" 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 multifdsink receives data. If the client is reading too fast, no data will be send to the client until multifdsink receives more data. If the client, however, reads too slowly, data for that client will be queued up in multifdsink. Two properties control the amount of data (buffers) that is queued in multifdsink: "buffers-max" and "buffers-soft-max". A client that falls behind by "buffers-max" is removed from multifdsink 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.

multifdsink 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. Multifdsink will by default not do QoS and will never drop late buffers.

Last reviewed on 2006-09-12 (0.10.10)

## Synopsis

### Element Information

plugin | tcp
author | Thomas Vander Stichele <thomas at apestaart dot org>, Wim Taymans <wim@fluendo.com>
class | Sink/Network

### Element Pads

name | sink
direction | sink
presence | always
details | ANY

## Details

### struct GstMultiFdSink

    struct GstMultiFdSink;

The multifdsink object structure.

### enum GstRecoverPolicy

    typedef enum {
      GST_RECOVER_POLICY_NONE,
      GST_RECOVER_POLICY_RESYNC_LATEST,
      GST_RECOVER_POLICY_RESYNC_SOFT_LIMIT,
      GST_RECOVER_POLICY_RESYNC_KEYFRAME
    } GstRecoverPolicy;

Possible values for the recovery procedure to use when a client consumes data too slow and has a backlag of more that soft-limit buffers.

`GST_RECOVER_POLICY_NONE` | no recovering is done
`GST_RECOVER_POLICY_RESYNC_LATEST` | client is moved to last buffer
`GST_RECOVER_POLICY_RESYNC_SOFT_LIMIT` | client is moved to the soft limit
`GST_RECOVER_POLICY_RESYNC_KEYFRAME` | client is moved to latest keyframe

### enum GstSyncMethod

    typedef enum {
      GST_SYNC_METHOD_LATEST,
      GST_SYNC_METHOD_NEXT_KEYFRAME,
      GST_SYNC_METHOD_LATEST_KEYFRAME,
      GST_SYNC_METHOD_BURST,
      GST_SYNC_METHOD_BURST_KEYFRAME,
      GST_SYNC_METHOD_BURST_WITH_KEYFRAME
    } GstSyncMethod;

This enum defines the selection of the first buffer that is sent to a new client.

`GST_SYNC_METHOD_LATEST` | client receives most recent buffer
`GST_SYNC_METHOD_NEXT_KEYFRAME` | client receives next keyframe
`GST_SYNC_METHOD_LATEST_KEYFRAME` | client receives latest keyframe (burst)
`GST_SYNC_METHOD_BURST` | client receives specific amount of data
`GST_SYNC_METHOD_BURST_KEYFRAME` | client receives specific amount of data starting from latest keyframe
`GST_SYNC_METHOD_BURST_WITH_KEYFRAME` | client receives specific amount of data from a keyframe, or if there is not enough data after the keyframe, starting before the keyframe

### enum GstClientStatus

    typedef enum {
      GST_CLIENT_STATUS_OK          = 0,
      GST_CLIENT_STATUS_CLOSED      = 1,
      GST_CLIENT_STATUS_REMOVED     = 2,
      GST_CLIENT_STATUS_SLOW        = 3,
      GST_CLIENT_STATUS_ERROR       = 4,
      GST_CLIENT_STATUS_DUPLICATE   = 5,
      GST_CLIENT_STATUS_FLUSHING    = 6
    } GstClientStatus;

This specifies the reason why a client was removed from multifdsink and is received in the "client-removed" signal.

`GST_CLIENT_STATUS_OK` | client is ok
`GST_CLIENT_STATUS_CLOSED` | client closed the socket
`GST_CLIENT_STATUS_REMOVED` | client is removed
`GST_CLIENT_STATUS_SLOW` | client is too slow
`GST_CLIENT_STATUS_ERROR` | client is in error
`GST_CLIENT_STATUS_DUPLICATE` | same client added twice
`GST_CLIENT_STATUS_FLUSHING` | client is flushing out the remaining buffers.

### enum GstTCPProtocol

    typedef enum {
      GST_TCP_PROTOCOL_NONE,
      GST_TCP_PROTOCOL_GDP
    } GstTCPProtocol;

This enum is provided by the tcp/multifd elements to configure the format of data transmission/reception.

The GDP protocol wraps data buffers in a header that also carries format information and timestamps. The None value indicates the data is sent/received as-is. In that case, format information and timestamping must be transmitted separately, or implicit in the bytestream itself.

`GST_TCP_PROTOCOL_NONE` | Raw data transmission
`GST_TCP_PROTOCOL_GDP` | GstBuffers are wrapped and sent/received using the GDP protocol.

### enum GstTCPUnitType

    typedef enum {
      GST_TCP_UNIT_TYPE_UNDEFINED,
      GST_TCP_UNIT_TYPE_BUFFERS,
      GST_TCP_UNIT_TYPE_TIME,
      GST_TCP_UNIT_TYPE_BYTES
    } GstTCPUnitType;

The units used to specify limits.

`GST_TCP_UNIT_TYPE_UNDEFINED` | undefined
`GST_TCP_UNIT_TYPE_BUFFERS` | buffers
`GST_TCP_UNIT_TYPE_TIME` | timeunits (in nanoseconds)
`GST_TCP_UNIT_TYPE_BYTES` | bytes

## Property Details

### The `"buffers-max"` property

      "buffers-max"              gint                  : Read / Write

max number of buffers to queue for a client (-1 = no limit).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"buffers-queued"` property

      "buffers-queued"           guint                 : Read

Number of buffers currently queued.

Default value: 0

### The `"buffers-soft-max"` property

      "buffers-soft-max"         gint                  : Read / Write

Recover client when going over this limit (-1 = no limit).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"bytes-served"` property

      "bytes-served"             guint64               : Read

Total number of bytes send to all clients.

Default value: 0

### The `"bytes-to-serve"` property

      "bytes-to-serve"           guint64               : Read

Number of bytes received to serve to clients.

Default value: 0

### The `"mode"` property

      "mode"                     GstFDSetMode          : Read / Write

The mode for selecting activity on the fds (deprecated).

Default value: Poll

### The `"protocol"` property

      "protocol"                 GstTCPProtocol        : Read / Write

The protocol to wrap data in. GDP protocol here is deprecated. Please use gdppay element.

Default value: GST_TCP_PROTOCOL_NONE

### The `"recover-policy"` property

      "recover-policy"           GstRecoverPolicy      : Read / Write

How to recover when client reaches the soft max.

Default value: Do not try to recover

### The `"sync-clients"` property

      "sync-clients"             gboolean              : Read / Write

(DEPRECATED) Sync clients to a keyframe.

Default value: FALSE

### The `"sync-method"` property

      "sync-method"              GstSyncMethod         : Read / Write

How to sync new clients to the stream.

Default value: Serve starting from the latest buffer

### The `"timeout"` property

      "timeout"                  guint64               : Read / Write

Maximum inactivity timeout in nanoseconds for a client (0 = no limit).

Default value: 0

### The `"buffers-min"` property

      "buffers-min"              gint                  : Read / Write

min number of buffers to queue (-1 = as few as possible).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"burst-unit"` property

      "burst-unit"               GstTCPUnitType        : Read / Write

The format of the burst units (when sync-method is burst[[-with]-keyframe]).

Default value: Undefined

### The `"burst-value"` property

      "burst-value"              guint64               : Read / Write

The amount of burst expressed in burst-unit.

Default value: 0

### The `"bytes-min"` property

      "bytes-min"                gint                  : Read / Write

min number of bytes to queue (-1 = as little as possible).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"time-min"` property

      "time-min"                 gint64                : Read / Write

min number of time to queue (-1 = as little as possible).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"unit-type"` property

      "unit-type"                GstTCPUnitType        : Read / Write

The unit to measure the max/soft-max/queued properties.

Default value: Buffers

### The `"units-max"` property

      "units-max"                gint64                : Read / Write

max number of units to queue (-1 = no limit).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"units-soft-max"` property

      "units-soft-max"           gint64                : Read / Write

Recover client when going over this limit (-1 = no limit).

Allowed values: >= G_MAXULONG

Default value: -1

### The `"qos-dscp"` property

      "qos-dscp"                 gint                  : Read / Write

Quality of Service, differentiated services code point (-1 default).

Allowed values: [G_MAXULONG,63]

Default value: -1

### The `"handle-read"` property

      "handle-read"              gboolean              : Read / Write

Handle client reads and discard the data.

Default value: TRUE

### The `"resend-streamheader"` property

      "resend-streamheader"      gboolean              : Read / Write

Resend the streamheader if it changes in the caps.

Default value: TRUE

### The `"num-fds"` property

      "num-fds"                  guint                 : Read

The current number of client file descriptors.

Default value: 0

## Signal Details

### The `"add"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Action

Hand the given open file descriptor to multifdsink to write to.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`fd` : | the file descriptor to add to multifdsink
`user_data` : | user data set when the signal handler was connected.

### The `"clear"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gpointer        user_data)           : Action

Remove all file descriptors from multifdsink. Since multifdsink did not open fd's itself, it does not explicitly close the fd. The application should do so by connecting to the client-fd-removed callback.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`user_data` : | user data set when the signal handler was connected.

### The `"client-added"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Run Last

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

`gstmultifdsink` : | the multifdsink element that emitted this signal
`fd` : | the file descriptor that was added to multifdsink
`user_data` : | user data set when the signal handler was connected.

### The `"client-removed"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            GstClientStatus status,
                                                            gpointer        user_data)           : Run Last

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

`gstmultifdsink` still holds a handle to `fd` 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 `fd` in this callback.

`gstmultifdsink` : | the multifdsink element that emitted this signal
`fd` : | the file descriptor that is to be removed from multifdsink
`status` : | the reason why the client was removed
`user_data` : | user data set when the signal handler was connected.

### The `"get-stats"` signal

    GValueArray*        user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Action

Get statistics about `fd`. This function returns a GValueArray to ease automatic wrapping for bindings.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`fd` : | the file descriptor to get stats of from multifdsink
`user_data` : | user data set when the signal handler was connected.

Returns :

a GValueArray with the statistics. The array contains guint64 values that represent respectively: 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). The array can be 0-length if the client was not found.

### The `"remove"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Action

Remove the given open file descriptor from multifdsink.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`fd` : | the file descriptor to remove from multifdsink
`user_data` : | user data set when the signal handler was connected.

### The `"client-fd-removed"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Run Last

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

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

`gstmultifdsink` : | the multifdsink element that emitted this signal
`fd` : | the file descriptor that was removed from multifdsink
`user_data` : | user data set when the signal handler was connected.

Since 0.10.7

### The `"add-full"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            GstSyncMethod   sync,
                                                            GstTCPUnitType  unit_type_min,
                                                            guint64         value_min,
                                                            GstTCPUnitType  unit_type_max,
                                                            guint64         value_max,
                                                            gpointer        user_data)           : Action

Hand the given open file descriptor to multifdsink to write to and specify the burst parameters for the new connection.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`fd` : | the file descriptor to add to multifdsink
`sync` : | the sync method to use
`unit_type_min` : | the unit-type of `value_min`
`value_min` : | the minimum amount of data to burst expressed in `unit_type_min` units.
`unit_type_max` : | the unit-type of `value_max`
`value_max` : | the maximum amount of data to burst expressed in `unit_type_max` units.
`user_data` : | user data set when the signal handler was connected.

### The `"remove-flush"` signal

    void                user_function                      (GstMultiFdSink *gstmultifdsink,
                                                            gint            fd,
                                                            gpointer        user_data)           : Action

Remove the given open file descriptor from multifdsink after flushing all the pending data to the fd.

`gstmultifdsink` : | the multifdsink element to emit this signal on
`fd` : | the file descriptor to remove from multifdsink
`user_data` : | user data set when the signal handler was connected.

## See Also

tcpserversink