## GstAppSink GstAppSink — Easy way for applications to extract samples from a pipeline |

## Functions

void | gst_app_sink_set_caps ()
GstCaps * | gst_app_sink_get_caps ()
gboolean | gst_app_sink_is_eos ()
void | gst_app_sink_set_emit_signals ()
gboolean | gst_app_sink_get_emit_signals ()
void | gst_app_sink_set_max_buffers ()
guint | gst_app_sink_get_max_buffers ()
void | gst_app_sink_set_drop ()
gboolean | gst_app_sink_get_drop ()
GstSample * | gst_app_sink_pull_preroll ()
GstSample * | gst_app_sink_pull_sample ()
GstSample * | gst_app_sink_try_pull_preroll ()
GstSample * | gst_app_sink_try_pull_sample ()
gboolean | gst_app_sink_get_buffer_list_support ()
void | gst_app_sink_set_buffer_list_support ()
gboolean | gst_app_sink_get_wait_on_eos ()
void | gst_app_sink_set_wait_on_eos ()
void | gst_app_sink_set_callbacks ()

## Properties

gboolean | buffer-list | Read / Write
GstCaps * | caps | Read / Write
gboolean | drop | Read / Write
gboolean | emit-signals | Read / Write
gboolean | eos | Read
guint | max-buffers | Read / Write
gboolean | wait-on-eos | Read / Write

## Signals

void | eos | Run Last
GstFlowReturn | new-preroll | Run Last
GstFlowReturn | new-sample | Run Last
GstSample* | pull-preroll | Action
GstSample* | pull-sample | Action
GstSample* | try-pull-preroll | Action
GstSample* | try-pull-sample | Action

## Types and Values

| GstAppSinkCallbacks

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GstObject
                ╰── GstElement
                    ╰── GstBaseSink
                        ╰── GstAppSink

## Includes

    #include <gst/app/app.h>

## Description

Appsink is a sink plugin that supports many different methods for making the application get a handle on the GStreamer data in a pipeline. Unlike most GStreamer elements, Appsink provides external API functions.

appsink can be used by linking to the gstappsink.h header file to access the methods or by using the appsink action signals and properties.

The normal way of retrieving samples from appsink is by using the `gst_app_sink_pull_sample()` and `gst_app_sink_pull_preroll()` methods. These methods block until a sample becomes available in the sink or when the sink is shut down or reaches EOS. There are also timed variants of these methods, `gst_app_sink_try_pull_sample()` and `gst_app_sink_try_pull_preroll()`, which accept a timeout parameter to limit the amount of time to wait.

Appsink will internally use a queue to collect buffers from the streaming thread. If the application is not pulling samples fast enough, this queue will consume a lot of memory over time. The "max-buffers" property can be used to limit the queue size. The "drop" property controls whether the streaming thread blocks or if older buffers are dropped when the maximum queue size is reached. Note that blocking the streaming thread can negatively affect real-time performance and should be avoided.

If a blocking behaviour is not desirable, setting the "emit-signals" property to `TRUE` will make appsink emit the "new-sample" and "new-preroll" signals when a sample can be pulled without blocking.

The "caps" property on appsink can be used to control the formats that appsink can receive. This property can contain non-fixed caps, the format of the pulled samples can be obtained by getting the sample caps.

If one of the pull-preroll or pull-sample methods return `NULL`, the appsink is stopped or in the EOS state. You can check for the EOS state with the "eos" property or with the `gst_app_sink_is_eos()` method.

The eos signal can also be used to be informed when the EOS state is reached to avoid polling.

## Functions

### gst_app_sink_set_caps ()

    void
    gst_app_sink_set_caps (GstAppSink *appsink,
                           const GstCaps *caps);

Set the capabilities on the appsink element. This function takes a copy of the caps structure. After calling this method, the sink will only accept caps that match `caps` . If `caps` is non-fixed, or incomplete, you must check the caps on the samples to get the actual used caps.

#### Parameters

appsink | a GstAppSink |
caps | caps to set |

### gst_app_sink_get_caps ()

    GstCaps *
    gst_app_sink_get_caps (GstAppSink *appsink);

Get the configured caps on `appsink` .

#### Parameters

appsink | a GstAppSink |

#### Returns

the GstCaps accepted by the sink. `gst_caps_unref()` after usage.

### gst_app_sink_is_eos ()

    gboolean
    gst_app_sink_is_eos (GstAppSink *appsink);

Check if `appsink` is EOS, which is when no more samples can be pulled because an EOS event was received.

This function also returns `TRUE` when the appsink is not in the PAUSED or PLAYING state.

#### Parameters

appsink | a GstAppSink |

#### Returns

`TRUE` if no more samples can be pulled and the appsink is EOS.

### gst_app_sink_set_emit_signals ()

    void
    gst_app_sink_set_emit_signals (GstAppSink *appsink,
                                   gboolean emit);

Make appsink emit the "new-preroll" and "new-sample" signals. This option is by default disabled because signal emission is expensive and unneeded when the application prefers to operate in pull mode.

#### Parameters

appsink | a GstAppSink |
emit | the new state |

### gst_app_sink_get_emit_signals ()

    gboolean
    gst_app_sink_get_emit_signals (GstAppSink *appsink);

Check if appsink will emit the "new-preroll" and "new-sample" signals.

#### Parameters

appsink | a GstAppSink |

#### Returns

`TRUE` if `appsink` is emiting the "new-preroll" and "new-sample" signals.

### gst_app_sink_set_max_buffers ()

    void
    gst_app_sink_set_max_buffers (GstAppSink *appsink,
                                  guint max);

Set the maximum amount of buffers that can be queued in `appsink` . After this amount of buffers are queued in appsink, any more buffers will block upstream elements until a sample is pulled from `appsink` .

#### Parameters

appsink | a GstAppSink |
max | the maximum number of buffers to queue |

### gst_app_sink_get_max_buffers ()

    guint
    gst_app_sink_get_max_buffers (GstAppSink *appsink);

Get the maximum amount of buffers that can be queued in `appsink` .

#### Parameters

appsink | a GstAppSink |

#### Returns

The maximum amount of buffers that can be queued.

### gst_app_sink_set_drop ()

    void
    gst_app_sink_set_drop (GstAppSink *appsink,
                           gboolean drop);

Instruct `appsink` to drop old buffers when the maximum amount of queued buffers is reached.

#### Parameters

appsink | a GstAppSink |
drop | the new state |

### gst_app_sink_get_drop ()

    gboolean
    gst_app_sink_get_drop (GstAppSink *appsink);

Check if `appsink` will drop old buffers when the maximum amount of queued buffers is reached.

#### Parameters

appsink | a GstAppSink |

#### Returns

`TRUE` if `appsink` is dropping old buffers when the queue is filled.

### gst_app_sink_pull_preroll ()

    GstSample *
    gst_app_sink_pull_preroll (GstAppSink *appsink);

Get the last preroll sample in `appsink` . This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling `gst_app_sink_pull_sample()`.

If an EOS event was received before any buffers, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

This function blocks until a preroll sample or EOS is received or the appsink element is set to the READY/NULL state.

#### Parameters

appsink | a GstAppSink |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS. Call `gst_sample_unref()` after usage.

[transfer full]

### gst_app_sink_pull_sample ()

    GstSample *
    gst_app_sink_pull_sample (GstAppSink *appsink);

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

#### Parameters

appsink | a GstAppSink |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS. Call `gst_sample_unref()` after usage.

[transfer full]

### gst_app_sink_try_pull_preroll ()

    GstSample *
    gst_app_sink_try_pull_preroll (GstAppSink *appsink,
                                   GstClockTime timeout);

Get the last preroll sample in `appsink` . This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling `gst_app_sink_pull_sample()`.

If an EOS event was received before any buffers or the timeout expires, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

This function blocks until a preroll sample or EOS is received, the appsink element is set to the READY/NULL state, or the timeout expires.

#### Parameters

appsink | a GstAppSink |
timeout | the maximum amount of time to wait for the preroll sample |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS or the timeout expires. Call `gst_sample_unref()` after usage.

[transfer full]

Since: 1.10

### gst_app_sink_try_pull_sample ()

    GstSample *
    gst_app_sink_try_pull_sample (GstAppSink *appsink,
                                  GstClockTime timeout);

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered buffers will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued buffers could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any buffers or the timeout expires, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

#### Parameters

appsink | a GstAppSink |
timeout | the maximum amount of time to wait for a sample |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS or the timeout expires. Call `gst_sample_unref()` after usage.

[transfer full]

Since: 1.10

### gst_app_sink_get_buffer_list_support ()

    gboolean
    gst_app_sink_get_buffer_list_support (GstAppSink *appsink);

Check if `appsink` supports buffer lists.

#### Parameters

appsink | a GstAppSink |

#### Returns

`TRUE` if `appsink` supports buffer lists.

Since: 1.12

### gst_app_sink_set_buffer_list_support ()

    void
    gst_app_sink_set_buffer_list_support (GstAppSink *appsink,
                                          gboolean enable_lists);

Instruct `appsink` to enable or disable buffer list support.

For backwards-compatibility reasons applications need to opt in to indicate that they will be able to handle buffer lists.

#### Parameters

appsink | a GstAppSink |
enable_lists | enable or disable buffer list support |

Since: 1.12

### gst_app_sink_get_wait_on_eos ()

    gboolean
    gst_app_sink_get_wait_on_eos (GstAppSink *appsink);

Check if `appsink` will wait for all buffers to be consumed when an EOS is received.

#### Parameters

appsink | a GstAppSink |

#### Returns

`TRUE` if `appsink` will wait for all buffers to be consumed when an EOS is received.

### gst_app_sink_set_wait_on_eos ()

    void
    gst_app_sink_set_wait_on_eos (GstAppSink *appsink,
                                  gboolean wait);

Instruct `appsink` to wait for all buffers to be consumed when an EOS is received.

#### Parameters

appsink | a GstAppSink |
wait | the new state |

### gst_app_sink_set_callbacks ()

    void
    gst_app_sink_set_callbacks (GstAppSink *appsink,
                                GstAppSinkCallbacks *callbacks,
                                gpointer user_data,
                                GDestroyNotify notify);

Set callbacks which will be executed for each new preroll, new sample and eos. This is an alternative to using the signals, it has lower overhead and is thus less expensive, but also less flexible.

If callbacks are installed, no signals will be emitted for performance reasons.

[skip]

#### Parameters

appsink | a GstAppSink |
callbacks | the callbacks |
user_data | a user_data argument for the callbacks |
notify | a destroy notify function |

## Types and Values

### GstAppSinkCallbacks

    typedef struct {
      void          (*eos)              (GstAppSink *appsink, gpointer user_data);
      GstFlowReturn (*new_preroll)      (GstAppSink *appsink, gpointer user_data);
      GstFlowReturn (*new_sample)       (GstAppSink *appsink, gpointer user_data);
    } GstAppSinkCallbacks;

A set of callbacks that can be installed on the appsink with `gst_app_sink_set_callbacks()`.

#### Members

`eos` () | Called when the end-of-stream has been reached. This callback is called from the streaming thread. |
`new_preroll` () | Called when a new preroll sample is available. This callback is called from the streaming thread. The new preroll sample can be retrieved with `gst_app_sink_pull_preroll()` either from this callback or from any other thread. |
`new_sample` () | Called when a new sample is available. This callback is called from the streaming thread. The new sample can be retrieved with `gst_app_sink_pull_sample()` either from this callback or from any other thread. |

## Property Details

### The `“buffer-list”` property

      “buffer-list”              gboolean

Use buffer lists.

Flags: Read / Write

Default value: FALSE

### The `“caps”` property

      “caps”                     GstCaps *

The allowed caps for the sink pad.

Flags: Read / Write

### The `“drop”` property

      “drop”                     gboolean

Drop old buffers when the buffer queue is filled.

Flags: Read / Write

Default value: FALSE

### The `“emit-signals”` property

      “emit-signals”             gboolean

Emit new-preroll and new-sample signals.

Flags: Read / Write

Default value: FALSE

### The `“eos”` property

      “eos”                      gboolean

Check if the sink is EOS or not started.

Flags: Read

Default value: TRUE

### The `“max-buffers”` property

      “max-buffers”              guint

The maximum number of buffers to queue internally (0 = unlimited).

Flags: Read / Write

Default value: 0

### The `“wait-on-eos”` property

      “wait-on-eos”              gboolean

Wait for all buffers to be processed after receiving an EOS.

Flags: Read / Write

Default value: TRUE

## Signal Details

### The `“eos”` signal

    void
    user_function (GstAppSink *appsink,
                   gpointer    user_data)

Signal that the end-of-stream has been reached. This signal is emitted from the streaming thread.

#### Parameters

appsink | the appsink element that emitted the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“new-preroll”` signal

    GstFlowReturn
    user_function (GstAppSink *appsink,
                   gpointer    user_data)

Signal that a new preroll sample is available.

This signal is emitted from the streaming thread and only when the "emit-signals" property is `TRUE`.

The new preroll sample can be retrieved with the "pull-preroll" action signal or `gst_app_sink_pull_preroll()` either from this signal callback or from any other thread.

Note that this signal is only emitted when the "emit-signals" property is set to `TRUE`, which it is not by default for performance reasons.

#### Parameters

appsink | the appsink element that emitted the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“new-sample”` signal

    GstFlowReturn
    user_function (GstAppSink *appsink,
                   gpointer    user_data)

Signal that a new sample is available.

This signal is emitted from the streaming thread and only when the "emit-signals" property is `TRUE`.

The new sample can be retrieved with the "pull-sample" action signal or `gst_app_sink_pull_sample()` either from this signal callback or from any other thread.

Note that this signal is only emitted when the "emit-signals" property is set to `TRUE`, which it is not by default for performance reasons.

#### Parameters

appsink | the appsink element that emitted the signal |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“pull-preroll”` signal

    GstSample*
    user_function (GstAppSink *appsink,
                   gpointer    user_data)

Get the last preroll sample in `appsink` . This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling `gst_app_sink_pull_sample()` or the "pull-sample" action signal.

If an EOS event was received before any buffers, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

This function blocks until a preroll sample or EOS is received or the appsink element is set to the READY/NULL state.

#### Parameters

appsink | the appsink element to emit this signal on |
user_data | user data set when the signal handler was connected. |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS.

Flags: Action

### The `“pull-sample”` signal

    GstSample*
    user_function (GstAppSink *appsink,
                   gpointer    user_data)

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state.

This function will only return samples when the appsink is in the PLAYING state. All rendered samples will be put in a queue so that the application can pull samples at its own rate.

Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames. It's possible to control the behaviour of the queue with the "drop" and "max-buffers" properties.

If an EOS event was received before any buffers, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

#### Parameters

appsink | the appsink element to emit this signal on |
user_data | user data set when the signal handler was connected. |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS.

Flags: Action

### The `“try-pull-preroll”` signal

    GstSample*
    user_function (GstAppSink *appsink,
                   guint64     timeout,
                   gpointer    user_data)

Get the last preroll sample in `appsink` . This was the sample that caused the appsink to preroll in the PAUSED state.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Calling this function will clear the internal reference to the preroll buffer.

Note that the preroll sample will also be returned as the first sample when calling `gst_app_sink_pull_sample()` or the "pull-sample" action signal.

If an EOS event was received before any buffers or the timeout expires, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

This function blocks until a preroll sample or EOS is received, the appsink element is set to the READY/NULL state, or the timeout expires.

#### Parameters

appsink | the appsink element to emit this signal on |
timeout | the maximum amount of time to wait for the preroll sample |
user_data | user data set when the signal handler was connected. |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS or the timeout expires.

Flags: Action

Since: 1.10

### The `“try-pull-sample”` signal

    GstSample*
    user_function (GstAppSink *appsink,
                   guint64     timeout,
                   gpointer    user_data)

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state or the timeout expires.

This function will only return samples when the appsink is in the PLAYING state. All rendered samples will be put in a queue so that the application can pull samples at its own rate.

Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames. It's possible to control the behaviour of the queue with the "drop" and "max-buffers" properties.

If an EOS event was received before any buffers or the timeout expires, this function returns `NULL`. Use `gst_app_sink_is_eos()` to check for the EOS condition.

#### Parameters

appsink | the appsink element to emit this signal on |
timeout | the maximum amount of time to wait for a sample |
user_data | user data set when the signal handler was connected. |

#### Returns

a GstSample or NULL when the appsink is stopped or EOS or the timeout expires.

Flags: Action

Since: 1.10

## See Also

GstSample, GstBaseSink, appsrc