Blame gst-libs/gst/app/gstappsink.c

Packit 0652a1
/* GStreamer
Packit 0652a1
 * Copyright (C) 2007 David Schleef <ds@schleef.org>
Packit 0652a1
 *           (C) 2008 Wim Taymans <wim.taymans@gmail.com>
Packit 0652a1
 *
Packit 0652a1
 * This library is free software; you can redistribute it and/or
Packit 0652a1
 * modify it under the terms of the GNU Library General Public
Packit 0652a1
 * License as published by the Free Software Foundation; either
Packit 0652a1
 * version 2 of the License, or (at your option) any later version.
Packit 0652a1
 *
Packit 0652a1
 * This library is distributed in the hope that it will be useful,
Packit 0652a1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0652a1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0652a1
 * Library General Public License for more details.
Packit 0652a1
 *
Packit 0652a1
 * You should have received a copy of the GNU Library General Public
Packit 0652a1
 * License along with this library; if not, write to the
Packit 0652a1
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 0652a1
 * Boston, MA 02110-1301, USA.
Packit 0652a1
 */
Packit 0652a1
/**
Packit 0652a1
 * SECTION:gstappsink
Packit 0652a1
 * @title: GstAppSink
Packit 0652a1
 * @short_description: Easy way for applications to extract samples from a
Packit 0652a1
 *     pipeline
Packit 0652a1
 * @see_also: #GstSample, #GstBaseSink, appsrc
Packit 0652a1
 *
Packit 0652a1
 * Appsink is a sink plugin that supports many different methods for making
Packit 0652a1
 * the application get a handle on the GStreamer data in a pipeline. Unlike
Packit 0652a1
 * most GStreamer elements, Appsink provides external API functions.
Packit 0652a1
 *
Packit 0652a1
 * appsink can be used by linking to the gstappsink.h header file to access the
Packit 0652a1
 * methods or by using the appsink action signals and properties.
Packit 0652a1
 *
Packit 0652a1
 * The normal way of retrieving samples from appsink is by using the
Packit 0652a1
 * gst_app_sink_pull_sample() and gst_app_sink_pull_preroll() methods.
Packit 0652a1
 * These methods block until a sample becomes available in the sink or when the
Packit 0652a1
 * sink is shut down or reaches EOS. There are also timed variants of these
Packit 0652a1
 * methods, gst_app_sink_try_pull_sample() and gst_app_sink_try_pull_preroll(),
Packit 0652a1
 * which accept a timeout parameter to limit the amount of time to wait.
Packit 0652a1
 *
Packit 0652a1
 * Appsink will internally use a queue to collect buffers from the streaming
Packit 0652a1
 * thread. If the application is not pulling samples fast enough, this queue
Packit 0652a1
 * will consume a lot of memory over time. The "max-buffers" property can be
Packit 0652a1
 * used to limit the queue size. The "drop" property controls whether the
Packit 0652a1
 * streaming thread blocks or if older buffers are dropped when the maximum
Packit 0652a1
 * queue size is reached. Note that blocking the streaming thread can negatively
Packit 0652a1
 * affect real-time performance and should be avoided.
Packit 0652a1
 *
Packit 0652a1
 * If a blocking behaviour is not desirable, setting the "emit-signals" property
Packit 0652a1
 * to %TRUE will make appsink emit the "new-sample" and "new-preroll" signals
Packit 0652a1
 * when a sample can be pulled without blocking.
Packit 0652a1
 *
Packit 0652a1
 * The "caps" property on appsink can be used to control the formats that
Packit 0652a1
 * appsink can receive. This property can contain non-fixed caps, the format of
Packit 0652a1
 * the pulled samples can be obtained by getting the sample caps.
Packit 0652a1
 *
Packit 0652a1
 * If one of the pull-preroll or pull-sample methods return %NULL, the appsink
Packit 0652a1
 * is stopped or in the EOS state. You can check for the EOS state with the
Packit 0652a1
 * "eos" property or with the gst_app_sink_is_eos() method.
Packit 0652a1
 *
Packit 0652a1
 * The eos signal can also be used to be informed when the EOS state is reached
Packit 0652a1
 * to avoid polling.
Packit 0652a1
 */
Packit 0652a1
Packit 0652a1
#ifdef HAVE_CONFIG_H
Packit 0652a1
#include "config.h"
Packit 0652a1
#endif
Packit 0652a1
Packit 0652a1
#include <gst/gst.h>
Packit 0652a1
#include <gst/base/base.h>
Packit 0652a1
Packit 0652a1
#include <string.h>
Packit 0652a1
Packit 0652a1
#include "gstappsink.h"
Packit 0652a1
Packit 0652a1
typedef enum
Packit 0652a1
{
Packit 0652a1
  NOONE_WAITING = 0,
Packit 0652a1
  STREAM_WAITING = 1 << 0,      /* streaming thread is waiting for application thread */
Packit 0652a1
  APP_WAITING = 1 << 1,         /* application thread is waiting for streaming thread */
Packit 0652a1
} GstAppSinkWaitStatus;
Packit 0652a1
Packit 0652a1
struct _GstAppSinkPrivate
Packit 0652a1
{
Packit 0652a1
  GstCaps *caps;
Packit 0652a1
  gboolean emit_signals;
Packit 0652a1
  guint num_buffers;
Packit 0652a1
  guint max_buffers;
Packit 0652a1
  gboolean drop;
Packit 0652a1
  gboolean wait_on_eos;
Packit 0652a1
  GstAppSinkWaitStatus wait_status;
Packit 0652a1
Packit 0652a1
  GCond cond;
Packit 0652a1
  GMutex mutex;
Packit 0652a1
  GstQueueArray *queue;
Packit 0652a1
  GstBuffer *preroll_buffer;
Packit 0652a1
  GstCaps *preroll_caps;
Packit 0652a1
  GstCaps *last_caps;
Packit 0652a1
  GstSegment preroll_segment;
Packit 0652a1
  GstSegment last_segment;
Packit 0652a1
  gboolean flushing;
Packit 0652a1
  gboolean unlock;
Packit 0652a1
  gboolean started;
Packit 0652a1
  gboolean is_eos;
Packit 0652a1
  gboolean buffer_lists_supported;
Packit 0652a1
Packit 0652a1
  GstAppSinkCallbacks callbacks;
Packit 0652a1
  gpointer user_data;
Packit 0652a1
  GDestroyNotify notify;
Packit 0652a1
Packit 0652a1
  GstSample *sample;
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
GST_DEBUG_CATEGORY_STATIC (app_sink_debug);
Packit 0652a1
#define GST_CAT_DEFAULT app_sink_debug
Packit 0652a1
Packit 0652a1
enum
Packit 0652a1
{
Packit 0652a1
  /* signals */
Packit 0652a1
  SIGNAL_EOS,
Packit 0652a1
  SIGNAL_NEW_PREROLL,
Packit 0652a1
  SIGNAL_NEW_SAMPLE,
Packit 0652a1
Packit 0652a1
  /* actions */
Packit 0652a1
  SIGNAL_PULL_PREROLL,
Packit 0652a1
  SIGNAL_PULL_SAMPLE,
Packit 0652a1
  SIGNAL_TRY_PULL_PREROLL,
Packit 0652a1
  SIGNAL_TRY_PULL_SAMPLE,
Packit 0652a1
Packit 0652a1
  LAST_SIGNAL
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
#define DEFAULT_PROP_EOS		TRUE
Packit 0652a1
#define DEFAULT_PROP_EMIT_SIGNALS	FALSE
Packit 0652a1
#define DEFAULT_PROP_MAX_BUFFERS	0
Packit 0652a1
#define DEFAULT_PROP_DROP		FALSE
Packit 0652a1
#define DEFAULT_PROP_WAIT_ON_EOS	TRUE
Packit 0652a1
#define DEFAULT_PROP_BUFFER_LIST	FALSE
Packit 0652a1
Packit 0652a1
enum
Packit 0652a1
{
Packit 0652a1
  PROP_0,
Packit 0652a1
  PROP_CAPS,
Packit 0652a1
  PROP_EOS,
Packit 0652a1
  PROP_EMIT_SIGNALS,
Packit 0652a1
  PROP_MAX_BUFFERS,
Packit 0652a1
  PROP_DROP,
Packit 0652a1
  PROP_WAIT_ON_EOS,
Packit 0652a1
  PROP_BUFFER_LIST,
Packit 0652a1
  PROP_LAST
Packit 0652a1
};
Packit 0652a1
Packit 0652a1
static GstStaticPadTemplate gst_app_sink_template =
Packit 0652a1
GST_STATIC_PAD_TEMPLATE ("sink",
Packit 0652a1
    GST_PAD_SINK,
Packit 0652a1
    GST_PAD_ALWAYS,
Packit 0652a1
    GST_STATIC_CAPS_ANY);
Packit 0652a1
Packit 0652a1
static void gst_app_sink_uri_handler_init (gpointer g_iface,
Packit 0652a1
    gpointer iface_data);
Packit 0652a1
Packit 0652a1
static void gst_app_sink_dispose (GObject * object);
Packit 0652a1
static void gst_app_sink_finalize (GObject * object);
Packit 0652a1
Packit 0652a1
static void gst_app_sink_set_property (GObject * object, guint prop_id,
Packit 0652a1
    const GValue * value, GParamSpec * pspec);
Packit 0652a1
static void gst_app_sink_get_property (GObject * object, guint prop_id,
Packit 0652a1
    GValue * value, GParamSpec * pspec);
Packit 0652a1
Packit 0652a1
static gboolean gst_app_sink_unlock_start (GstBaseSink * bsink);
Packit 0652a1
static gboolean gst_app_sink_unlock_stop (GstBaseSink * bsink);
Packit 0652a1
static gboolean gst_app_sink_start (GstBaseSink * psink);
Packit 0652a1
static gboolean gst_app_sink_stop (GstBaseSink * psink);
Packit 0652a1
static gboolean gst_app_sink_event (GstBaseSink * sink, GstEvent * event);
Packit 0652a1
static gboolean gst_app_sink_query (GstBaseSink * bsink, GstQuery * query);
Packit 0652a1
static GstFlowReturn gst_app_sink_preroll (GstBaseSink * psink,
Packit 0652a1
    GstBuffer * buffer);
Packit 0652a1
static GstFlowReturn gst_app_sink_render_common (GstBaseSink * psink,
Packit 0652a1
    GstMiniObject * data, gboolean is_list);
Packit 0652a1
static GstFlowReturn gst_app_sink_render (GstBaseSink * psink,
Packit 0652a1
    GstBuffer * buffer);
Packit 0652a1
static GstFlowReturn gst_app_sink_render_list (GstBaseSink * psink,
Packit 0652a1
    GstBufferList * list);
Packit 0652a1
static gboolean gst_app_sink_setcaps (GstBaseSink * sink, GstCaps * caps);
Packit 0652a1
static GstCaps *gst_app_sink_getcaps (GstBaseSink * psink, GstCaps * filter);
Packit 0652a1
Packit 0652a1
static guint gst_app_sink_signals[LAST_SIGNAL] = { 0 };
Packit 0652a1
Packit 0652a1
#define gst_app_sink_parent_class parent_class
Packit 0652a1
G_DEFINE_TYPE_WITH_CODE (GstAppSink, gst_app_sink, GST_TYPE_BASE_SINK,
Packit 0652a1
    G_ADD_PRIVATE (GstAppSink)
Packit 0652a1
    G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
Packit 0652a1
        gst_app_sink_uri_handler_init));
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_class_init (GstAppSinkClass * klass)
Packit 0652a1
{
Packit 0652a1
  GObjectClass *gobject_class = (GObjectClass *) klass;
Packit 0652a1
  GstElementClass *element_class = (GstElementClass *) klass;
Packit 0652a1
  GstBaseSinkClass *basesink_class = (GstBaseSinkClass *) klass;
Packit 0652a1
Packit 0652a1
  GST_DEBUG_CATEGORY_INIT (app_sink_debug, "appsink", 0, "appsink element");
Packit 0652a1
Packit 0652a1
  gobject_class->dispose = gst_app_sink_dispose;
Packit 0652a1
  gobject_class->finalize = gst_app_sink_finalize;
Packit 0652a1
Packit 0652a1
  gobject_class->set_property = gst_app_sink_set_property;
Packit 0652a1
  gobject_class->get_property = gst_app_sink_get_property;
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_CAPS,
Packit 0652a1
      g_param_spec_boxed ("caps", "Caps",
Packit 0652a1
          "The allowed caps for the sink pad", GST_TYPE_CAPS,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_EOS,
Packit 0652a1
      g_param_spec_boolean ("eos", "EOS",
Packit 0652a1
          "Check if the sink is EOS or not started", DEFAULT_PROP_EOS,
Packit 0652a1
          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_EMIT_SIGNALS,
Packit 0652a1
      g_param_spec_boolean ("emit-signals", "Emit signals",
Packit 0652a1
          "Emit new-preroll and new-sample signals",
Packit 0652a1
          DEFAULT_PROP_EMIT_SIGNALS,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_MAX_BUFFERS,
Packit 0652a1
      g_param_spec_uint ("max-buffers", "Max Buffers",
Packit 0652a1
          "The maximum number of buffers to queue internally (0 = unlimited)",
Packit 0652a1
          0, G_MAXUINT, DEFAULT_PROP_MAX_BUFFERS,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_DROP,
Packit 0652a1
      g_param_spec_boolean ("drop", "Drop",
Packit 0652a1
          "Drop old buffers when the buffer queue is filled", DEFAULT_PROP_DROP,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_BUFFER_LIST,
Packit 0652a1
      g_param_spec_boolean ("buffer-list", "Buffer List",
Packit 0652a1
          "Use buffer lists", DEFAULT_PROP_BUFFER_LIST,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::wait-on-eos:
Packit 0652a1
   *
Packit 0652a1
   * Wait for all buffers to be processed after receiving an EOS.
Packit 0652a1
   *
Packit 0652a1
   * In cases where it is uncertain if an @appsink will have a consumer for its buffers
Packit 0652a1
   * when it receives an EOS, set to %FALSE to ensure that the @appsink will not hang.
Packit 0652a1
   *
Packit 0652a1
   * Since: 1.8
Packit 0652a1
   */
Packit 0652a1
  g_object_class_install_property (gobject_class, PROP_WAIT_ON_EOS,
Packit 0652a1
      g_param_spec_boolean ("wait-on-eos", "Wait on EOS",
Packit 0652a1
          "Wait for all buffers to be processed after receiving an EOS",
Packit 0652a1
          DEFAULT_PROP_WAIT_ON_EOS,
Packit 0652a1
          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 0652a1
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::eos:
Packit 0652a1
   * @appsink: the appsink element that emitted the signal
Packit 0652a1
   *
Packit 0652a1
   * Signal that the end-of-stream has been reached. This signal is emitted from
Packit 0652a1
   * the streaming thread.
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_EOS] =
Packit 0652a1
      g_signal_new ("eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
Packit 0652a1
      G_STRUCT_OFFSET (GstAppSinkClass, eos),
Packit 0652a1
      NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE);
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::new-preroll:
Packit 0652a1
   * @appsink: the appsink element that emitted the signal
Packit 0652a1
   *
Packit 0652a1
   * Signal that a new preroll sample is available.
Packit 0652a1
   *
Packit 0652a1
   * This signal is emitted from the streaming thread and only when the
Packit 0652a1
   * "emit-signals" property is %TRUE.
Packit 0652a1
   *
Packit 0652a1
   * The new preroll sample can be retrieved with the "pull-preroll" action
Packit 0652a1
   * signal or gst_app_sink_pull_preroll() either from this signal callback
Packit 0652a1
   * or from any other thread.
Packit 0652a1
   *
Packit 0652a1
   * Note that this signal is only emitted when the "emit-signals" property is
Packit 0652a1
   * set to %TRUE, which it is not by default for performance reasons.
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_NEW_PREROLL] =
Packit 0652a1
      g_signal_new ("new-preroll", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
Packit 0652a1
      G_STRUCT_OFFSET (GstAppSinkClass, new_preroll),
Packit 0652a1
      NULL, NULL, NULL, GST_TYPE_FLOW_RETURN, 0, G_TYPE_NONE);
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::new-sample:
Packit 0652a1
   * @appsink: the appsink element that emitted the signal
Packit 0652a1
   *
Packit 0652a1
   * Signal that a new sample is available.
Packit 0652a1
   *
Packit 0652a1
   * This signal is emitted from the streaming thread and only when the
Packit 0652a1
   * "emit-signals" property is %TRUE.
Packit 0652a1
   *
Packit 0652a1
   * The new sample can be retrieved with the "pull-sample" action
Packit 0652a1
   * signal or gst_app_sink_pull_sample() either from this signal callback
Packit 0652a1
   * or from any other thread.
Packit 0652a1
   *
Packit 0652a1
   * Note that this signal is only emitted when the "emit-signals" property is
Packit 0652a1
   * set to %TRUE, which it is not by default for performance reasons.
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_NEW_SAMPLE] =
Packit 0652a1
      g_signal_new ("new-sample", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
Packit 0652a1
      G_STRUCT_OFFSET (GstAppSinkClass, new_sample),
Packit 0652a1
      NULL, NULL, NULL, GST_TYPE_FLOW_RETURN, 0, G_TYPE_NONE);
Packit 0652a1
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::pull-preroll:
Packit 0652a1
   * @appsink: the appsink element to emit this signal on
Packit 0652a1
   *
Packit 0652a1
   * Get the last preroll sample in @appsink. This was the sample that caused the
Packit 0652a1
   * appsink to preroll in the PAUSED state.
Packit 0652a1
   *
Packit 0652a1
   * This function is typically used when dealing with a pipeline in the PAUSED
Packit 0652a1
   * state. Calling this function after doing a seek will give the sample right
Packit 0652a1
   * after the seek position.
Packit 0652a1
   *
Packit 0652a1
   * Calling this function will clear the internal reference to the preroll
Packit 0652a1
   * buffer.
Packit 0652a1
   *
Packit 0652a1
   * Note that the preroll sample will also be returned as the first sample
Packit 0652a1
   * when calling gst_app_sink_pull_sample() or the "pull-sample" action signal.
Packit 0652a1
   *
Packit 0652a1
   * If an EOS event was received before any buffers, this function returns
Packit 0652a1
   * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
Packit 0652a1
   *
Packit 0652a1
   * This function blocks until a preroll sample or EOS is received or the appsink
Packit 0652a1
   * element is set to the READY/NULL state.
Packit 0652a1
   *
Packit 0652a1
   * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_PULL_PREROLL] =
Packit 0652a1
      g_signal_new ("pull-preroll", G_TYPE_FROM_CLASS (klass),
Packit 0652a1
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSinkClass,
Packit 0652a1
          pull_preroll), NULL, NULL, NULL, GST_TYPE_SAMPLE, 0, G_TYPE_NONE);
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::pull-sample:
Packit 0652a1
   * @appsink: the appsink element to emit this signal on
Packit 0652a1
   *
Packit 0652a1
   * This function blocks until a sample or EOS becomes available or the appsink
Packit 0652a1
   * element is set to the READY/NULL state.
Packit 0652a1
   *
Packit 0652a1
   * This function will only return samples when the appsink is in the PLAYING
Packit 0652a1
   * state. All rendered samples will be put in a queue so that the application
Packit 0652a1
   * can pull samples at its own rate.
Packit 0652a1
   *
Packit 0652a1
   * Note that when the application does not pull samples fast enough, the
Packit 0652a1
   * queued samples could consume a lot of memory, especially when dealing with
Packit 0652a1
   * raw video frames. It's possible to control the behaviour of the queue with
Packit 0652a1
   * the "drop" and "max-buffers" properties.
Packit 0652a1
   *
Packit 0652a1
   * If an EOS event was received before any buffers, this function returns
Packit 0652a1
   * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
Packit 0652a1
   *
Packit 0652a1
   * Returns: a #GstSample or NULL when the appsink is stopped or EOS.
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_PULL_SAMPLE] =
Packit 0652a1
      g_signal_new ("pull-sample", G_TYPE_FROM_CLASS (klass),
Packit 0652a1
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstAppSinkClass,
Packit 0652a1
          pull_sample), NULL, NULL, NULL, GST_TYPE_SAMPLE, 0, G_TYPE_NONE);
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::try-pull-preroll:
Packit 0652a1
   * @appsink: the appsink element to emit this signal on
Packit 0652a1
   * @timeout: the maximum amount of time to wait for the preroll sample
Packit 0652a1
   *
Packit 0652a1
   * Get the last preroll sample in @appsink. This was the sample that caused the
Packit 0652a1
   * appsink to preroll in the PAUSED state.
Packit 0652a1
   *
Packit 0652a1
   * This function is typically used when dealing with a pipeline in the PAUSED
Packit 0652a1
   * state. Calling this function after doing a seek will give the sample right
Packit 0652a1
   * after the seek position.
Packit 0652a1
   *
Packit 0652a1
   * Calling this function will clear the internal reference to the preroll
Packit 0652a1
   * buffer.
Packit 0652a1
   *
Packit 0652a1
   * Note that the preroll sample will also be returned as the first sample
Packit 0652a1
   * when calling gst_app_sink_pull_sample() or the "pull-sample" action signal.
Packit 0652a1
   *
Packit 0652a1
   * If an EOS event was received before any buffers or the timeout expires,
Packit 0652a1
   * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
Packit 0652a1
   * condition.
Packit 0652a1
   *
Packit 0652a1
   * This function blocks until a preroll sample or EOS is received, the appsink
Packit 0652a1
   * element is set to the READY/NULL state, or the timeout expires.
Packit 0652a1
   *
Packit 0652a1
   * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
Packit 0652a1
   *
Packit 0652a1
   * Since: 1.10
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_TRY_PULL_PREROLL] =
Packit 0652a1
      g_signal_new ("try-pull-preroll", G_TYPE_FROM_CLASS (klass),
Packit 0652a1
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
Packit 0652a1
      G_STRUCT_OFFSET (GstAppSinkClass, try_pull_preroll), NULL, NULL, NULL,
Packit 0652a1
      GST_TYPE_SAMPLE, 1, GST_TYPE_CLOCK_TIME);
Packit 0652a1
  /**
Packit 0652a1
   * GstAppSink::try-pull-sample:
Packit 0652a1
   * @appsink: the appsink element to emit this signal on
Packit 0652a1
   * @timeout: the maximum amount of time to wait for a sample
Packit 0652a1
   *
Packit 0652a1
   * This function blocks until a sample or EOS becomes available or the appsink
Packit 0652a1
   * element is set to the READY/NULL state or the timeout expires.
Packit 0652a1
   *
Packit 0652a1
   * This function will only return samples when the appsink is in the PLAYING
Packit 0652a1
   * state. All rendered samples will be put in a queue so that the application
Packit 0652a1
   * can pull samples at its own rate.
Packit 0652a1
   *
Packit 0652a1
   * Note that when the application does not pull samples fast enough, the
Packit 0652a1
   * queued samples could consume a lot of memory, especially when dealing with
Packit 0652a1
   * raw video frames. It's possible to control the behaviour of the queue with
Packit 0652a1
   * the "drop" and "max-buffers" properties.
Packit 0652a1
   *
Packit 0652a1
   * If an EOS event was received before any buffers or the timeout expires,
Packit 0652a1
   * this function returns %NULL. Use gst_app_sink_is_eos () to check
Packit 0652a1
   * for the EOS condition.
Packit 0652a1
   *
Packit 0652a1
   * Returns: a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
Packit 0652a1
   *
Packit 0652a1
   * Since: 1.10
Packit 0652a1
   */
Packit 0652a1
  gst_app_sink_signals[SIGNAL_TRY_PULL_SAMPLE] =
Packit 0652a1
      g_signal_new ("try-pull-sample", G_TYPE_FROM_CLASS (klass),
Packit 0652a1
      G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
Packit 0652a1
      G_STRUCT_OFFSET (GstAppSinkClass, try_pull_sample), NULL, NULL, NULL,
Packit 0652a1
      GST_TYPE_SAMPLE, 1, GST_TYPE_CLOCK_TIME);
Packit 0652a1
Packit 0652a1
  gst_element_class_set_static_metadata (element_class, "AppSink",
Packit 0652a1
      "Generic/Sink", "Allow the application to get access to raw buffer",
Packit 0652a1
      "David Schleef <ds@schleef.org>, Wim Taymans <wim.taymans@gmail.com>");
Packit 0652a1
Packit 0652a1
  gst_element_class_add_static_pad_template (element_class,
Packit 0652a1
      &gst_app_sink_template);
Packit 0652a1
Packit 0652a1
  basesink_class->unlock = gst_app_sink_unlock_start;
Packit 0652a1
  basesink_class->unlock_stop = gst_app_sink_unlock_stop;
Packit 0652a1
  basesink_class->start = gst_app_sink_start;
Packit 0652a1
  basesink_class->stop = gst_app_sink_stop;
Packit 0652a1
  basesink_class->event = gst_app_sink_event;
Packit 0652a1
  basesink_class->preroll = gst_app_sink_preroll;
Packit 0652a1
  basesink_class->render = gst_app_sink_render;
Packit 0652a1
  basesink_class->render_list = gst_app_sink_render_list;
Packit 0652a1
  basesink_class->get_caps = gst_app_sink_getcaps;
Packit 0652a1
  basesink_class->set_caps = gst_app_sink_setcaps;
Packit 0652a1
  basesink_class->query = gst_app_sink_query;
Packit 0652a1
Packit 0652a1
  klass->pull_preroll = gst_app_sink_pull_preroll;
Packit 0652a1
  klass->pull_sample = gst_app_sink_pull_sample;
Packit 0652a1
  klass->try_pull_preroll = gst_app_sink_try_pull_preroll;
Packit 0652a1
  klass->try_pull_sample = gst_app_sink_try_pull_sample;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_init (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  priv = appsink->priv = gst_app_sink_get_instance_private (appsink);
Packit 0652a1
Packit 0652a1
  g_mutex_init (&priv->mutex);
Packit 0652a1
  g_cond_init (&priv->cond);
Packit 0652a1
  priv->queue = gst_queue_array_new (16);
Packit 0652a1
  priv->sample = gst_sample_new (NULL, NULL, NULL, NULL);
Packit 0652a1
Packit 0652a1
  priv->emit_signals = DEFAULT_PROP_EMIT_SIGNALS;
Packit 0652a1
  priv->max_buffers = DEFAULT_PROP_MAX_BUFFERS;
Packit 0652a1
  priv->drop = DEFAULT_PROP_DROP;
Packit 0652a1
  priv->wait_on_eos = DEFAULT_PROP_WAIT_ON_EOS;
Packit 0652a1
  priv->buffer_lists_supported = DEFAULT_PROP_BUFFER_LIST;
Packit 0652a1
  priv->wait_status = NOONE_WAITING;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_dispose (GObject * obj)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (obj);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
  GstMiniObject *queue_obj;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_LOCK (appsink);
Packit 0652a1
  if (priv->caps) {
Packit 0652a1
    gst_caps_unref (priv->caps);
Packit 0652a1
    priv->caps = NULL;
Packit 0652a1
  }
Packit 0652a1
  if (priv->notify) {
Packit 0652a1
    priv->notify (priv->user_data);
Packit 0652a1
  }
Packit 0652a1
  priv->user_data = NULL;
Packit 0652a1
  priv->notify = NULL;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  while ((queue_obj = gst_queue_array_pop_head (priv->queue)))
Packit 0652a1
    gst_mini_object_unref (queue_obj);
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, NULL);
Packit 0652a1
  gst_caps_replace (&priv->preroll_caps, NULL);
Packit 0652a1
  gst_caps_replace (&priv->last_caps, NULL);
Packit 0652a1
  if (priv->sample) {
Packit 0652a1
    gst_sample_unref (priv->sample);
Packit 0652a1
    priv->sample = NULL;
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  G_OBJECT_CLASS (parent_class)->dispose (obj);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_finalize (GObject * obj)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (obj);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_clear (&priv->mutex);
Packit 0652a1
  g_cond_clear (&priv->cond);
Packit 0652a1
  gst_queue_array_free (priv->queue);
Packit 0652a1
Packit 0652a1
  G_OBJECT_CLASS (parent_class)->finalize (obj);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_set_property (GObject * object, guint prop_id,
Packit 0652a1
    const GValue * value, GParamSpec * pspec)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (object);
Packit 0652a1
Packit 0652a1
  switch (prop_id) {
Packit 0652a1
    case PROP_CAPS:
Packit 0652a1
      gst_app_sink_set_caps (appsink, gst_value_get_caps (value));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_EMIT_SIGNALS:
Packit 0652a1
      gst_app_sink_set_emit_signals (appsink, g_value_get_boolean (value));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_MAX_BUFFERS:
Packit 0652a1
      gst_app_sink_set_max_buffers (appsink, g_value_get_uint (value));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_DROP:
Packit 0652a1
      gst_app_sink_set_drop (appsink, g_value_get_boolean (value));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_BUFFER_LIST:
Packit 0652a1
      gst_app_sink_set_buffer_list_support (appsink,
Packit 0652a1
          g_value_get_boolean (value));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_WAIT_ON_EOS:
Packit 0652a1
      gst_app_sink_set_wait_on_eos (appsink, g_value_get_boolean (value));
Packit 0652a1
      break;
Packit 0652a1
    default:
Packit 0652a1
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_get_property (GObject * object, guint prop_id, GValue * value,
Packit 0652a1
    GParamSpec * pspec)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (object);
Packit 0652a1
Packit 0652a1
  switch (prop_id) {
Packit 0652a1
    case PROP_CAPS:
Packit 0652a1
    {
Packit 0652a1
      GstCaps *caps;
Packit 0652a1
Packit 0652a1
      caps = gst_app_sink_get_caps (appsink);
Packit 0652a1
      gst_value_set_caps (value, caps);
Packit 0652a1
      if (caps)
Packit 0652a1
        gst_caps_unref (caps);
Packit 0652a1
      break;
Packit 0652a1
    }
Packit 0652a1
    case PROP_EOS:
Packit 0652a1
      g_value_set_boolean (value, gst_app_sink_is_eos (appsink));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_EMIT_SIGNALS:
Packit 0652a1
      g_value_set_boolean (value, gst_app_sink_get_emit_signals (appsink));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_MAX_BUFFERS:
Packit 0652a1
      g_value_set_uint (value, gst_app_sink_get_max_buffers (appsink));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_DROP:
Packit 0652a1
      g_value_set_boolean (value, gst_app_sink_get_drop (appsink));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_BUFFER_LIST:
Packit 0652a1
      g_value_set_boolean (value,
Packit 0652a1
          gst_app_sink_get_buffer_list_support (appsink));
Packit 0652a1
      break;
Packit 0652a1
    case PROP_WAIT_ON_EOS:
Packit 0652a1
      g_value_set_boolean (value, gst_app_sink_get_wait_on_eos (appsink));
Packit 0652a1
      break;
Packit 0652a1
    default:
Packit 0652a1
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_unlock_start (GstBaseSink * bsink)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (bsink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "unlock start");
Packit 0652a1
  priv->unlock = TRUE;
Packit 0652a1
  g_cond_signal (&priv->cond);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_unlock_stop (GstBaseSink * bsink)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (bsink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "unlock stop");
Packit 0652a1
  priv->unlock = FALSE;
Packit 0652a1
  g_cond_signal (&priv->cond);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_flush_unlocked (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  GstMiniObject *obj;
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "flush stop appsink");
Packit 0652a1
  priv->is_eos = FALSE;
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, NULL);
Packit 0652a1
  while ((obj = gst_queue_array_pop_head (priv->queue)))
Packit 0652a1
    gst_mini_object_unref (obj);
Packit 0652a1
  priv->num_buffers = 0;
Packit 0652a1
  g_cond_signal (&priv->cond);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_start (GstBaseSink * psink)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (psink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "starting");
Packit 0652a1
  priv->wait_status = NOONE_WAITING;
Packit 0652a1
  priv->flushing = FALSE;
Packit 0652a1
  priv->started = TRUE;
Packit 0652a1
  gst_segment_init (&priv->preroll_segment, GST_FORMAT_TIME);
Packit 0652a1
  gst_segment_init (&priv->last_segment, GST_FORMAT_TIME);
Packit 0652a1
  priv->sample = gst_sample_make_writable (priv->sample);
Packit 0652a1
  gst_sample_set_buffer (priv->sample, NULL);
Packit 0652a1
  gst_sample_set_buffer_list (priv->sample, NULL);
Packit 0652a1
  gst_sample_set_caps (priv->sample, NULL);
Packit 0652a1
  gst_sample_set_segment (priv->sample, NULL);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_stop (GstBaseSink * psink)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (psink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "stopping");
Packit 0652a1
  priv->flushing = TRUE;
Packit 0652a1
  priv->started = FALSE;
Packit 0652a1
  priv->wait_status = NOONE_WAITING;
Packit 0652a1
  gst_app_sink_flush_unlocked (appsink);
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, NULL);
Packit 0652a1
  gst_caps_replace (&priv->preroll_caps, NULL);
Packit 0652a1
  gst_caps_replace (&priv->last_caps, NULL);
Packit 0652a1
  gst_segment_init (&priv->preroll_segment, GST_FORMAT_UNDEFINED);
Packit 0652a1
  gst_segment_init (&priv->last_segment, GST_FORMAT_UNDEFINED);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_setcaps (GstBaseSink * sink, GstCaps * caps)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (sink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "receiving CAPS");
Packit 0652a1
  gst_queue_array_push_tail (priv->queue, gst_event_new_caps (caps));
Packit 0652a1
  if (!priv->preroll_buffer)
Packit 0652a1
    gst_caps_replace (&priv->preroll_caps, caps);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_event (GstBaseSink * sink, GstEvent * event)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (sink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  switch (event->type) {
Packit 0652a1
    case GST_EVENT_SEGMENT:
Packit 0652a1
      g_mutex_lock (&priv->mutex);
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "receiving SEGMENT");
Packit 0652a1
      gst_queue_array_push_tail (priv->queue, gst_event_ref (event));
Packit 0652a1
      if (!priv->preroll_buffer)
Packit 0652a1
        gst_event_copy_segment (event, &priv->preroll_segment);
Packit 0652a1
      g_mutex_unlock (&priv->mutex);
Packit 0652a1
      break;
Packit 0652a1
    case GST_EVENT_EOS:{
Packit 0652a1
      gboolean emit = TRUE;
Packit 0652a1
Packit 0652a1
      g_mutex_lock (&priv->mutex);
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "receiving EOS");
Packit 0652a1
      priv->is_eos = TRUE;
Packit 0652a1
      g_cond_signal (&priv->cond);
Packit 0652a1
      g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
      g_mutex_lock (&priv->mutex);
Packit 0652a1
      /* wait until all buffers are consumed or we're flushing.
Packit 0652a1
       * Otherwise we might signal EOS before all buffers are
Packit 0652a1
       * consumed, which is a bit confusing for the application
Packit 0652a1
       */
Packit 0652a1
      while (priv->num_buffers > 0 && !priv->flushing && priv->wait_on_eos) {
Packit 0652a1
        if (priv->unlock) {
Packit 0652a1
          /* we are asked to unlock, call the wait_preroll method */
Packit 0652a1
          g_mutex_unlock (&priv->mutex);
Packit 0652a1
          if (gst_base_sink_wait_preroll (sink) != GST_FLOW_OK) {
Packit 0652a1
            /* Directly go out of here */
Packit 0652a1
            gst_event_unref (event);
Packit 0652a1
            return FALSE;
Packit 0652a1
          }
Packit 0652a1
Packit 0652a1
          /* we are allowed to continue now */
Packit 0652a1
          g_mutex_lock (&priv->mutex);
Packit 0652a1
          continue;
Packit 0652a1
        }
Packit 0652a1
Packit 0652a1
        priv->wait_status |= STREAM_WAITING;
Packit 0652a1
        g_cond_wait (&priv->cond, &priv->mutex);
Packit 0652a1
        priv->wait_status &= ~STREAM_WAITING;
Packit 0652a1
      }
Packit 0652a1
      if (priv->flushing)
Packit 0652a1
        emit = FALSE;
Packit 0652a1
      g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
      if (emit) {
Packit 0652a1
        /* emit EOS now */
Packit 0652a1
        if (priv->callbacks.eos)
Packit 0652a1
          priv->callbacks.eos (appsink, priv->user_data);
Packit 0652a1
        else
Packit 0652a1
          g_signal_emit (appsink, gst_app_sink_signals[SIGNAL_EOS], 0);
Packit 0652a1
      }
Packit 0652a1
Packit 0652a1
      break;
Packit 0652a1
    }
Packit 0652a1
    case GST_EVENT_FLUSH_START:
Packit 0652a1
      /* we don't have to do anything here, the base class will call unlock
Packit 0652a1
       * which will make sure we exit the _render method */
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "received FLUSH_START");
Packit 0652a1
      break;
Packit 0652a1
    case GST_EVENT_FLUSH_STOP:
Packit 0652a1
      g_mutex_lock (&priv->mutex);
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "received FLUSH_STOP");
Packit 0652a1
      gst_app_sink_flush_unlocked (appsink);
Packit 0652a1
      g_mutex_unlock (&priv->mutex);
Packit 0652a1
      break;
Packit 0652a1
    default:
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
  return GST_BASE_SINK_CLASS (parent_class)->event (sink, event);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstFlowReturn
Packit 0652a1
gst_app_sink_preroll (GstBaseSink * psink, GstBuffer * buffer)
Packit 0652a1
{
Packit 0652a1
  GstFlowReturn res;
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (psink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
  gboolean emit;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (priv->flushing)
Packit 0652a1
    goto flushing;
Packit 0652a1
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "setting preroll buffer %p", buffer);
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, buffer);
Packit 0652a1
Packit 0652a1
  if ((priv->wait_status & APP_WAITING))
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
Packit 0652a1
  emit = priv->emit_signals;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  if (priv->callbacks.new_preroll) {
Packit 0652a1
    res = priv->callbacks.new_preroll (appsink, priv->user_data);
Packit 0652a1
  } else {
Packit 0652a1
    res = GST_FLOW_OK;
Packit 0652a1
    if (emit)
Packit 0652a1
      g_signal_emit (appsink, gst_app_sink_signals[SIGNAL_NEW_PREROLL], 0,
Packit 0652a1
          &res;;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return res;
Packit 0652a1
Packit 0652a1
flushing:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are flushing");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return GST_FLOW_FLUSHING;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstMiniObject *
Packit 0652a1
dequeue_buffer (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
  GstMiniObject *obj;
Packit 0652a1
Packit 0652a1
  do {
Packit 0652a1
    obj = gst_queue_array_pop_head (priv->queue);
Packit 0652a1
Packit 0652a1
    if (GST_IS_BUFFER (obj) || GST_IS_BUFFER_LIST (obj)) {
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "dequeued buffer/list %p", obj);
Packit 0652a1
      priv->num_buffers--;
Packit 0652a1
      break;
Packit 0652a1
    } else if (GST_IS_EVENT (obj)) {
Packit 0652a1
      GstEvent *event = GST_EVENT_CAST (obj);
Packit 0652a1
Packit 0652a1
      switch (GST_EVENT_TYPE (obj)) {
Packit 0652a1
        case GST_EVENT_CAPS:
Packit 0652a1
        {
Packit 0652a1
          GstCaps *caps;
Packit 0652a1
Packit 0652a1
          gst_event_parse_caps (event, &caps);
Packit 0652a1
          GST_DEBUG_OBJECT (appsink, "activating caps %" GST_PTR_FORMAT, caps);
Packit 0652a1
          gst_caps_replace (&priv->last_caps, caps);
Packit 0652a1
          priv->sample = gst_sample_make_writable (priv->sample);
Packit 0652a1
          gst_sample_set_caps (priv->sample, priv->last_caps);
Packit 0652a1
          break;
Packit 0652a1
        }
Packit 0652a1
        case GST_EVENT_SEGMENT:
Packit 0652a1
          gst_event_copy_segment (event, &priv->last_segment);
Packit 0652a1
          priv->sample = gst_sample_make_writable (priv->sample);
Packit 0652a1
          gst_sample_set_segment (priv->sample, &priv->last_segment);
Packit 0652a1
          GST_DEBUG_OBJECT (appsink, "activated segment %" GST_SEGMENT_FORMAT,
Packit 0652a1
              &priv->last_segment);
Packit 0652a1
          break;
Packit 0652a1
        default:
Packit 0652a1
          break;
Packit 0652a1
      }
Packit 0652a1
      gst_mini_object_unref (obj);
Packit 0652a1
    }
Packit 0652a1
  } while (TRUE);
Packit 0652a1
Packit 0652a1
  return obj;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstFlowReturn
Packit 0652a1
gst_app_sink_render_common (GstBaseSink * psink, GstMiniObject * data,
Packit 0652a1
    gboolean is_list)
Packit 0652a1
{
Packit 0652a1
  GstFlowReturn ret;
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (psink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
  gboolean emit;
Packit 0652a1
Packit 0652a1
restart:
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (priv->flushing)
Packit 0652a1
    goto flushing;
Packit 0652a1
Packit 0652a1
  /* queue holding caps event might have been FLUSHed,
Packit 0652a1
   * but caps state still present in pad caps */
Packit 0652a1
  if (G_UNLIKELY (!priv->last_caps &&
Packit 0652a1
          gst_pad_has_current_caps (GST_BASE_SINK_PAD (psink)))) {
Packit 0652a1
    priv->last_caps = gst_pad_get_current_caps (GST_BASE_SINK_PAD (psink));
Packit 0652a1
    gst_sample_set_caps (priv->sample, priv->last_caps);
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "activating pad caps %" GST_PTR_FORMAT,
Packit 0652a1
        priv->last_caps);
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "pushing render buffer/list %p on queue (%d)",
Packit 0652a1
      data, priv->num_buffers);
Packit 0652a1
Packit 0652a1
  while (priv->max_buffers > 0 && priv->num_buffers >= priv->max_buffers) {
Packit 0652a1
    if (priv->drop) {
Packit 0652a1
      GstMiniObject *old;
Packit 0652a1
Packit 0652a1
      /* we need to drop the oldest buffer/list and try again */
Packit 0652a1
      if ((old = dequeue_buffer (appsink))) {
Packit 0652a1
        GST_DEBUG_OBJECT (appsink, "dropping old buffer/list %p", old);
Packit 0652a1
        gst_mini_object_unref (old);
Packit 0652a1
      }
Packit 0652a1
    } else {
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "waiting for free space, length %d >= %d",
Packit 0652a1
          priv->num_buffers, priv->max_buffers);
Packit 0652a1
Packit 0652a1
      if (priv->unlock) {
Packit 0652a1
        /* we are asked to unlock, call the wait_preroll method */
Packit 0652a1
        g_mutex_unlock (&priv->mutex);
Packit 0652a1
        if ((ret = gst_base_sink_wait_preroll (psink)) != GST_FLOW_OK)
Packit 0652a1
          goto stopping;
Packit 0652a1
Packit 0652a1
        /* we are allowed to continue now */
Packit 0652a1
        goto restart;
Packit 0652a1
      }
Packit 0652a1
Packit 0652a1
      /* wait for a buffer to be removed or flush */
Packit 0652a1
      priv->wait_status |= STREAM_WAITING;
Packit 0652a1
      g_cond_wait (&priv->cond, &priv->mutex);
Packit 0652a1
      priv->wait_status &= ~STREAM_WAITING;
Packit 0652a1
Packit 0652a1
      if (priv->flushing)
Packit 0652a1
        goto flushing;
Packit 0652a1
    }
Packit 0652a1
  }
Packit 0652a1
  /* we need to ref the buffer/list when pushing it in the queue */
Packit 0652a1
  gst_queue_array_push_tail (priv->queue, gst_mini_object_ref (data));
Packit 0652a1
  priv->num_buffers++;
Packit 0652a1
Packit 0652a1
  if ((priv->wait_status & APP_WAITING))
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
Packit 0652a1
  emit = priv->emit_signals;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  if (priv->callbacks.new_sample) {
Packit 0652a1
    ret = priv->callbacks.new_sample (appsink, priv->user_data);
Packit 0652a1
  } else {
Packit 0652a1
    ret = GST_FLOW_OK;
Packit 0652a1
    if (emit)
Packit 0652a1
      g_signal_emit (appsink, gst_app_sink_signals[SIGNAL_NEW_SAMPLE], 0, &ret;;
Packit 0652a1
  }
Packit 0652a1
  return ret;
Packit 0652a1
Packit 0652a1
flushing:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are flushing");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return GST_FLOW_FLUSHING;
Packit 0652a1
  }
Packit 0652a1
stopping:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are stopping");
Packit 0652a1
    return ret;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstFlowReturn
Packit 0652a1
gst_app_sink_render (GstBaseSink * psink, GstBuffer * buffer)
Packit 0652a1
{
Packit 0652a1
  return gst_app_sink_render_common (psink, GST_MINI_OBJECT_CAST (buffer),
Packit 0652a1
      FALSE);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstFlowReturn
Packit 0652a1
gst_app_sink_render_list (GstBaseSink * sink, GstBufferList * list)
Packit 0652a1
{
Packit 0652a1
  GstFlowReturn flow;
Packit 0652a1
  GstAppSink *appsink;
Packit 0652a1
  GstBuffer *buffer;
Packit 0652a1
  guint i, len;
Packit 0652a1
Packit 0652a1
  appsink = GST_APP_SINK_CAST (sink);
Packit 0652a1
Packit 0652a1
  if (appsink->priv->buffer_lists_supported)
Packit 0652a1
    return gst_app_sink_render_common (sink, GST_MINI_OBJECT_CAST (list), TRUE);
Packit 0652a1
Packit 0652a1
  /* The application doesn't support buffer lists, extract individual buffers
Packit 0652a1
   * then and push them one-by-one */
Packit 0652a1
  GST_INFO_OBJECT (sink, "chaining each group in list as a merged buffer");
Packit 0652a1
Packit 0652a1
  len = gst_buffer_list_length (list);
Packit 0652a1
Packit 0652a1
  flow = GST_FLOW_OK;
Packit 0652a1
  for (i = 0; i < len; i++) {
Packit 0652a1
    buffer = gst_buffer_list_get (list, i);
Packit 0652a1
    flow = gst_app_sink_render (sink, buffer);
Packit 0652a1
    if (flow != GST_FLOW_OK)
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return flow;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static GstCaps *
Packit 0652a1
gst_app_sink_getcaps (GstBaseSink * psink, GstCaps * filter)
Packit 0652a1
{
Packit 0652a1
  GstCaps *caps;
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (psink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_LOCK (appsink);
Packit 0652a1
  if ((caps = priv->caps)) {
Packit 0652a1
    if (filter)
Packit 0652a1
      caps = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
Packit 0652a1
    else
Packit 0652a1
      gst_caps_ref (caps);
Packit 0652a1
  }
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "got caps %" GST_PTR_FORMAT, caps);
Packit 0652a1
  GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
Packit 0652a1
  return caps;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_query (GstBaseSink * bsink, GstQuery * query)
Packit 0652a1
{
Packit 0652a1
  GstAppSink *appsink = GST_APP_SINK_CAST (bsink);
Packit 0652a1
  GstAppSinkPrivate *priv = appsink->priv;
Packit 0652a1
  gboolean ret;
Packit 0652a1
Packit 0652a1
  switch (GST_QUERY_TYPE (query)) {
Packit 0652a1
    case GST_QUERY_DRAIN:
Packit 0652a1
    {
Packit 0652a1
      g_mutex_lock (&priv->mutex);
Packit 0652a1
      GST_DEBUG_OBJECT (appsink, "waiting buffers to be consumed");
Packit 0652a1
      while (priv->num_buffers > 0 || priv->preroll_buffer) {
Packit 0652a1
        if (priv->unlock) {
Packit 0652a1
          /* we are asked to unlock, call the wait_preroll method */
Packit 0652a1
          g_mutex_unlock (&priv->mutex);
Packit 0652a1
          if (gst_base_sink_wait_preroll (bsink) != GST_FLOW_OK) {
Packit 0652a1
            /* Directly go out of here */
Packit 0652a1
            return FALSE;
Packit 0652a1
          }
Packit 0652a1
Packit 0652a1
          /* we are allowed to continue now */
Packit 0652a1
          g_mutex_lock (&priv->mutex);
Packit 0652a1
          continue;
Packit 0652a1
        }
Packit 0652a1
Packit 0652a1
        priv->wait_status |= STREAM_WAITING;
Packit 0652a1
        g_cond_wait (&priv->cond, &priv->mutex);
Packit 0652a1
        priv->wait_status &= ~STREAM_WAITING;
Packit 0652a1
Packit 0652a1
        if (priv->flushing)
Packit 0652a1
          break;
Packit 0652a1
      }
Packit 0652a1
      g_mutex_unlock (&priv->mutex);
Packit 0652a1
      ret = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
Packit 0652a1
      break;
Packit 0652a1
    }
Packit 0652a1
    case GST_QUERY_SEEKING:{
Packit 0652a1
      GstFormat fmt;
Packit 0652a1
Packit 0652a1
      /* we don't supporting seeking */
Packit 0652a1
      gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
Packit 0652a1
      gst_query_set_seeking (query, fmt, FALSE, 0, -1);
Packit 0652a1
      ret = TRUE;
Packit 0652a1
      break;
Packit 0652a1
    }
Packit 0652a1
Packit 0652a1
    default:
Packit 0652a1
      ret = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
Packit 0652a1
      break;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  return ret;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/* external API */
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_caps:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @caps: caps to set
Packit 0652a1
 *
Packit 0652a1
 * Set the capabilities on the appsink element.  This function takes
Packit 0652a1
 * a copy of the caps structure. After calling this method, the sink will only
Packit 0652a1
 * accept caps that match @caps. If @caps is non-fixed, or incomplete,
Packit 0652a1
 * you must check the caps on the samples to get the actual used caps.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_caps (GstAppSink * appsink, const GstCaps * caps)
Packit 0652a1
{
Packit 0652a1
  GstCaps *old;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_LOCK (appsink);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "setting caps to %" GST_PTR_FORMAT, caps);
Packit 0652a1
  if ((old = priv->caps) != caps) {
Packit 0652a1
    if (caps)
Packit 0652a1
      priv->caps = gst_caps_copy (caps);
Packit 0652a1
    else
Packit 0652a1
      priv->caps = NULL;
Packit 0652a1
    if (old)
Packit 0652a1
      gst_caps_unref (old);
Packit 0652a1
  }
Packit 0652a1
  GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_caps:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Get the configured caps on @appsink.
Packit 0652a1
 *
Packit 0652a1
 * Returns: the #GstCaps accepted by the sink. gst_caps_unref() after usage.
Packit 0652a1
 */
Packit 0652a1
GstCaps *
Packit 0652a1
gst_app_sink_get_caps (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  GstCaps *caps;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), NULL);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_LOCK (appsink);
Packit 0652a1
  if ((caps = priv->caps))
Packit 0652a1
    gst_caps_ref (caps);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "getting caps of %" GST_PTR_FORMAT, caps);
Packit 0652a1
  GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
Packit 0652a1
  return caps;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_is_eos:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Check if @appsink is EOS, which is when no more samples can be pulled because
Packit 0652a1
 * an EOS event was received.
Packit 0652a1
 *
Packit 0652a1
 * This function also returns %TRUE when the appsink is not in the PAUSED or
Packit 0652a1
 * PLAYING state.
Packit 0652a1
 *
Packit 0652a1
 * Returns: %TRUE if no more samples can be pulled and the appsink is EOS.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_app_sink_is_eos (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  gboolean ret;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (!priv->started)
Packit 0652a1
    goto not_started;
Packit 0652a1
Packit 0652a1
  if (priv->is_eos && priv->num_buffers == 0) {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are EOS and the queue is empty");
Packit 0652a1
    ret = TRUE;
Packit 0652a1
  } else {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are not yet EOS");
Packit 0652a1
    ret = FALSE;
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return ret;
Packit 0652a1
Packit 0652a1
not_started:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are stopped, return TRUE");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return TRUE;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_emit_signals:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @emit: the new state
Packit 0652a1
 *
Packit 0652a1
 * Make appsink emit the "new-preroll" and "new-sample" signals. This option is
Packit 0652a1
 * by default disabled because signal emission is expensive and unneeded when
Packit 0652a1
 * the application prefers to operate in pull mode.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_emit_signals (GstAppSink * appsink, gboolean emit)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  priv->emit_signals = emit;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_emit_signals:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Check if appsink will emit the "new-preroll" and "new-sample" signals.
Packit 0652a1
 *
Packit 0652a1
 * Returns: %TRUE if @appsink is emiting the "new-preroll" and "new-sample"
Packit 0652a1
 * signals.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_app_sink_get_emit_signals (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  gboolean result;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  result = priv->emit_signals;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return result;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_max_buffers:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @max: the maximum number of buffers to queue
Packit 0652a1
 *
Packit 0652a1
 * Set the maximum amount of buffers that can be queued in @appsink. After this
Packit 0652a1
 * amount of buffers are queued in appsink, any more buffers will block upstream
Packit 0652a1
 * elements until a sample is pulled from @appsink.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_max_buffers (GstAppSink * appsink, guint max)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (max != priv->max_buffers) {
Packit 0652a1
    priv->max_buffers = max;
Packit 0652a1
    /* signal the change */
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_max_buffers:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Get the maximum amount of buffers that can be queued in @appsink.
Packit 0652a1
 *
Packit 0652a1
 * Returns: The maximum amount of buffers that can be queued.
Packit 0652a1
 */
Packit 0652a1
guint
Packit 0652a1
gst_app_sink_get_max_buffers (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  guint result;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), 0);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  result = priv->max_buffers;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return result;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_drop:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @drop: the new state
Packit 0652a1
 *
Packit 0652a1
 * Instruct @appsink to drop old buffers when the maximum amount of queued
Packit 0652a1
 * buffers is reached.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_drop (GstAppSink * appsink, gboolean drop)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (priv->drop != drop) {
Packit 0652a1
    priv->drop = drop;
Packit 0652a1
    /* signal the change */
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_drop:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Check if @appsink will drop old buffers when the maximum amount of queued
Packit 0652a1
 * buffers is reached.
Packit 0652a1
 *
Packit 0652a1
 * Returns: %TRUE if @appsink is dropping old buffers when the queue is
Packit 0652a1
 * filled.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_app_sink_get_drop (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  gboolean result;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  result = priv->drop;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return result;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_buffer_list_support:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @enable_lists: enable or disable buffer list support
Packit 0652a1
 *
Packit 0652a1
 * Instruct @appsink to enable or disable buffer list support.
Packit 0652a1
 *
Packit 0652a1
 * For backwards-compatibility reasons applications need to opt in
Packit 0652a1
 * to indicate that they will be able to handle buffer lists.
Packit 0652a1
 *
Packit 0652a1
 * Since: 1.12
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_buffer_list_support (GstAppSink * appsink,
Packit 0652a1
    gboolean enable_lists)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (priv->buffer_lists_supported != enable_lists) {
Packit 0652a1
    priv->buffer_lists_supported = enable_lists;
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_buffer_list_support:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Check if @appsink supports buffer lists.
Packit 0652a1
 *
Packit 0652a1
 * Returns: %TRUE if @appsink supports buffer lists.
Packit 0652a1
 *
Packit 0652a1
 * Since: 1.12
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_app_sink_get_buffer_list_support (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  gboolean result;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  result = priv->buffer_lists_supported;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return result;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_wait_on_eos:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @wait: the new state
Packit 0652a1
 *
Packit 0652a1
 * Instruct @appsink to wait for all buffers to be consumed when an EOS is received.
Packit 0652a1
 *
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_wait_on_eos (GstAppSink * appsink, gboolean wait)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  if (priv->wait_on_eos != wait) {
Packit 0652a1
    priv->wait_on_eos = wait;
Packit 0652a1
    /* signal the change */
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
  }
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_get_wait_on_eos:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Check if @appsink will wait for all buffers to be consumed when an EOS is
Packit 0652a1
 * received.
Packit 0652a1
 *
Packit 0652a1
 * Returns: %TRUE if @appsink will wait for all buffers to be consumed when an
Packit 0652a1
 * EOS is received.
Packit 0652a1
 */
Packit 0652a1
gboolean
Packit 0652a1
gst_app_sink_get_wait_on_eos (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  gboolean result;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  result = priv->wait_on_eos;
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return result;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_pull_preroll:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * Get the last preroll sample in @appsink. This was the sample that caused the
Packit 0652a1
 * appsink to preroll in the PAUSED state.
Packit 0652a1
 *
Packit 0652a1
 * This function is typically used when dealing with a pipeline in the PAUSED
Packit 0652a1
 * state. Calling this function after doing a seek will give the sample right
Packit 0652a1
 * after the seek position.
Packit 0652a1
 *
Packit 0652a1
 * Calling this function will clear the internal reference to the preroll
Packit 0652a1
 * buffer.
Packit 0652a1
 *
Packit 0652a1
 * Note that the preroll sample will also be returned as the first sample
Packit 0652a1
 * when calling gst_app_sink_pull_sample().
Packit 0652a1
 *
Packit 0652a1
 * If an EOS event was received before any buffers, this function returns
Packit 0652a1
 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
Packit 0652a1
 *
Packit 0652a1
 * This function blocks until a preroll sample or EOS is received or the appsink
Packit 0652a1
 * element is set to the READY/NULL state.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a #GstSample or NULL when the appsink is stopped or EOS.
Packit 0652a1
 *          Call gst_sample_unref() after usage.
Packit 0652a1
 */
Packit 0652a1
GstSample *
Packit 0652a1
gst_app_sink_pull_preroll (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  return gst_app_sink_try_pull_preroll (appsink, GST_CLOCK_TIME_NONE);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_pull_sample:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 *
Packit 0652a1
 * This function blocks until a sample or EOS becomes available or the appsink
Packit 0652a1
 * element is set to the READY/NULL state.
Packit 0652a1
 *
Packit 0652a1
 * This function will only return samples when the appsink is in the PLAYING
Packit 0652a1
 * state. All rendered buffers will be put in a queue so that the application
Packit 0652a1
 * can pull samples at its own rate. Note that when the application does not
Packit 0652a1
 * pull samples fast enough, the queued buffers could consume a lot of memory,
Packit 0652a1
 * especially when dealing with raw video frames.
Packit 0652a1
 *
Packit 0652a1
 * If an EOS event was received before any buffers, this function returns
Packit 0652a1
 * %NULL. Use gst_app_sink_is_eos () to check for the EOS condition.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a #GstSample or NULL when the appsink is stopped or EOS.
Packit 0652a1
 *          Call gst_sample_unref() after usage.
Packit 0652a1
 */
Packit 0652a1
GstSample *
Packit 0652a1
gst_app_sink_pull_sample (GstAppSink * appsink)
Packit 0652a1
{
Packit 0652a1
  return gst_app_sink_try_pull_sample (appsink, GST_CLOCK_TIME_NONE);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_try_pull_preroll:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @timeout: the maximum amount of time to wait for the preroll sample
Packit 0652a1
 *
Packit 0652a1
 * Get the last preroll sample in @appsink. This was the sample that caused the
Packit 0652a1
 * appsink to preroll in the PAUSED state.
Packit 0652a1
 *
Packit 0652a1
 * This function is typically used when dealing with a pipeline in the PAUSED
Packit 0652a1
 * state. Calling this function after doing a seek will give the sample right
Packit 0652a1
 * after the seek position.
Packit 0652a1
 *
Packit 0652a1
 * Calling this function will clear the internal reference to the preroll
Packit 0652a1
 * buffer.
Packit 0652a1
 *
Packit 0652a1
 * Note that the preroll sample will also be returned as the first sample
Packit 0652a1
 * when calling gst_app_sink_pull_sample().
Packit 0652a1
 *
Packit 0652a1
 * If an EOS event was received before any buffers or the timeout expires,
Packit 0652a1
 * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
Packit 0652a1
 * condition.
Packit 0652a1
 *
Packit 0652a1
 * This function blocks until a preroll sample or EOS is received, the appsink
Packit 0652a1
 * element is set to the READY/NULL state, or the timeout expires.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
Packit 0652a1
 *          Call gst_sample_unref() after usage.
Packit 0652a1
 *
Packit 0652a1
 * Since: 1.10
Packit 0652a1
 */
Packit 0652a1
GstSample *
Packit 0652a1
gst_app_sink_try_pull_preroll (GstAppSink * appsink, GstClockTime timeout)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
  GstSample *sample = NULL;
Packit 0652a1
  gboolean timeout_valid;
Packit 0652a1
  gint64 end_time;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), NULL);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  timeout_valid = GST_CLOCK_TIME_IS_VALID (timeout);
Packit 0652a1
Packit 0652a1
  if (timeout_valid)
Packit 0652a1
    end_time =
Packit 0652a1
        g_get_monotonic_time () + timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  while (TRUE) {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "trying to grab a buffer");
Packit 0652a1
    if (!priv->started)
Packit 0652a1
      goto not_started;
Packit 0652a1
Packit 0652a1
    if (priv->preroll_buffer != NULL)
Packit 0652a1
      break;
Packit 0652a1
Packit 0652a1
    if (priv->is_eos)
Packit 0652a1
      goto eos;
Packit 0652a1
Packit 0652a1
    /* nothing to return, wait */
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "waiting for the preroll buffer");
Packit 0652a1
    priv->wait_status |= APP_WAITING;
Packit 0652a1
    if (timeout_valid) {
Packit 0652a1
      if (!g_cond_wait_until (&priv->cond, &priv->mutex, end_time))
Packit 0652a1
        goto expired;
Packit 0652a1
    } else {
Packit 0652a1
      g_cond_wait (&priv->cond, &priv->mutex);
Packit 0652a1
    }
Packit 0652a1
    priv->wait_status &= ~APP_WAITING;
Packit 0652a1
  }
Packit 0652a1
  sample =
Packit 0652a1
      gst_sample_new (priv->preroll_buffer, priv->preroll_caps,
Packit 0652a1
      &priv->preroll_segment, NULL);
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, NULL);
Packit 0652a1
  GST_DEBUG_OBJECT (appsink, "we have the preroll sample %p", sample);
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return sample;
Packit 0652a1
Packit 0652a1
  /* special conditions */
Packit 0652a1
expired:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "timeout expired, return NULL");
Packit 0652a1
    priv->wait_status &= ~APP_WAITING;
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
eos:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are EOS, return NULL");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
not_started:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are stopped, return NULL");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_try_pull_sample:
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @timeout: the maximum amount of time to wait for a sample
Packit 0652a1
 *
Packit 0652a1
 * This function blocks until a sample or EOS becomes available or the appsink
Packit 0652a1
 * element is set to the READY/NULL state or the timeout expires.
Packit 0652a1
 *
Packit 0652a1
 * This function will only return samples when the appsink is in the PLAYING
Packit 0652a1
 * state. All rendered buffers will be put in a queue so that the application
Packit 0652a1
 * can pull samples at its own rate. Note that when the application does not
Packit 0652a1
 * pull samples fast enough, the queued buffers could consume a lot of memory,
Packit 0652a1
 * especially when dealing with raw video frames.
Packit 0652a1
 *
Packit 0652a1
 * If an EOS event was received before any buffers or the timeout expires,
Packit 0652a1
 * this function returns %NULL. Use gst_app_sink_is_eos () to check for the EOS
Packit 0652a1
 * condition.
Packit 0652a1
 *
Packit 0652a1
 * Returns: (transfer full): a #GstSample or NULL when the appsink is stopped or EOS or the timeout expires.
Packit 0652a1
 * Call gst_sample_unref() after usage.
Packit 0652a1
 *
Packit 0652a1
 * Since: 1.10
Packit 0652a1
 */
Packit 0652a1
GstSample *
Packit 0652a1
gst_app_sink_try_pull_sample (GstAppSink * appsink, GstClockTime timeout)
Packit 0652a1
{
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
  GstSample *sample = NULL;
Packit 0652a1
  GstMiniObject *obj;
Packit 0652a1
  gboolean timeout_valid;
Packit 0652a1
  gint64 end_time;
Packit 0652a1
Packit 0652a1
  g_return_val_if_fail (GST_IS_APP_SINK (appsink), NULL);
Packit 0652a1
Packit 0652a1
  timeout_valid = GST_CLOCK_TIME_IS_VALID (timeout);
Packit 0652a1
Packit 0652a1
  if (timeout_valid)
Packit 0652a1
    end_time =
Packit 0652a1
        g_get_monotonic_time () + timeout / (GST_SECOND / G_TIME_SPAN_SECOND);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  g_mutex_lock (&priv->mutex);
Packit 0652a1
  gst_buffer_replace (&priv->preroll_buffer, NULL);
Packit 0652a1
Packit 0652a1
  while (TRUE) {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "trying to grab a buffer");
Packit 0652a1
    if (!priv->started)
Packit 0652a1
      goto not_started;
Packit 0652a1
Packit 0652a1
    if (priv->num_buffers > 0)
Packit 0652a1
      break;
Packit 0652a1
Packit 0652a1
    if (priv->is_eos)
Packit 0652a1
      goto eos;
Packit 0652a1
Packit 0652a1
    /* nothing to return, wait */
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "waiting for a buffer");
Packit 0652a1
    priv->wait_status |= APP_WAITING;
Packit 0652a1
    if (timeout_valid) {
Packit 0652a1
      if (!g_cond_wait_until (&priv->cond, &priv->mutex, end_time))
Packit 0652a1
        goto expired;
Packit 0652a1
    } else {
Packit 0652a1
      g_cond_wait (&priv->cond, &priv->mutex);
Packit 0652a1
    }
Packit 0652a1
    priv->wait_status &= ~APP_WAITING;
Packit 0652a1
  }
Packit 0652a1
Packit 0652a1
  obj = dequeue_buffer (appsink);
Packit 0652a1
  if (GST_IS_BUFFER (obj)) {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we have a buffer %p", obj);
Packit 0652a1
    priv->sample = gst_sample_make_writable (priv->sample);
Packit 0652a1
    gst_sample_set_buffer_list (priv->sample, NULL);
Packit 0652a1
    gst_sample_set_buffer (priv->sample, GST_BUFFER_CAST (obj));
Packit 0652a1
    sample = gst_sample_ref (priv->sample);
Packit 0652a1
  } else {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we have a list %p", obj);
Packit 0652a1
    priv->sample = gst_sample_make_writable (priv->sample);
Packit 0652a1
    gst_sample_set_buffer (priv->sample, NULL);
Packit 0652a1
    gst_sample_set_buffer_list (priv->sample, GST_BUFFER_LIST_CAST (obj));
Packit 0652a1
    sample = gst_sample_ref (priv->sample);
Packit 0652a1
  }
Packit 0652a1
  gst_mini_object_unref (obj);
Packit 0652a1
Packit 0652a1
  if ((priv->wait_status & STREAM_WAITING))
Packit 0652a1
    g_cond_signal (&priv->cond);
Packit 0652a1
Packit 0652a1
  g_mutex_unlock (&priv->mutex);
Packit 0652a1
Packit 0652a1
  return sample;
Packit 0652a1
Packit 0652a1
  /* special conditions */
Packit 0652a1
expired:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "timeout expired, return NULL");
Packit 0652a1
    priv->wait_status &= ~APP_WAITING;
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
eos:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are EOS, return NULL");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
not_started:
Packit 0652a1
  {
Packit 0652a1
    GST_DEBUG_OBJECT (appsink, "we are stopped, return NULL");
Packit 0652a1
    g_mutex_unlock (&priv->mutex);
Packit 0652a1
    return NULL;
Packit 0652a1
  }
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/**
Packit 0652a1
 * gst_app_sink_set_callbacks: (skip)
Packit 0652a1
 * @appsink: a #GstAppSink
Packit 0652a1
 * @callbacks: the callbacks
Packit 0652a1
 * @user_data: a user_data argument for the callbacks
Packit 0652a1
 * @notify: a destroy notify function
Packit 0652a1
 *
Packit 0652a1
 * Set callbacks which will be executed for each new preroll, new sample and eos.
Packit 0652a1
 * This is an alternative to using the signals, it has lower overhead and is thus
Packit 0652a1
 * less expensive, but also less flexible.
Packit 0652a1
 *
Packit 0652a1
 * If callbacks are installed, no signals will be emitted for performance
Packit 0652a1
 * reasons.
Packit 0652a1
 */
Packit 0652a1
void
Packit 0652a1
gst_app_sink_set_callbacks (GstAppSink * appsink,
Packit 0652a1
    GstAppSinkCallbacks * callbacks, gpointer user_data, GDestroyNotify notify)
Packit 0652a1
{
Packit 0652a1
  GDestroyNotify old_notify;
Packit 0652a1
  GstAppSinkPrivate *priv;
Packit 0652a1
Packit 0652a1
  g_return_if_fail (GST_IS_APP_SINK (appsink));
Packit 0652a1
  g_return_if_fail (callbacks != NULL);
Packit 0652a1
Packit 0652a1
  priv = appsink->priv;
Packit 0652a1
Packit 0652a1
  GST_OBJECT_LOCK (appsink);
Packit 0652a1
  old_notify = priv->notify;
Packit 0652a1
Packit 0652a1
  if (old_notify) {
Packit 0652a1
    gpointer old_data;
Packit 0652a1
Packit 0652a1
    old_data = priv->user_data;
Packit 0652a1
Packit 0652a1
    priv->user_data = NULL;
Packit 0652a1
    priv->notify = NULL;
Packit 0652a1
    GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
Packit 0652a1
    old_notify (old_data);
Packit 0652a1
Packit 0652a1
    GST_OBJECT_LOCK (appsink);
Packit 0652a1
  }
Packit 0652a1
  priv->callbacks = *callbacks;
Packit 0652a1
  priv->user_data = user_data;
Packit 0652a1
  priv->notify = notify;
Packit 0652a1
  GST_OBJECT_UNLOCK (appsink);
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
/*** GSTURIHANDLER INTERFACE *************************************************/
Packit 0652a1
Packit 0652a1
static GstURIType
Packit 0652a1
gst_app_sink_uri_get_type (GType type)
Packit 0652a1
{
Packit 0652a1
  return GST_URI_SINK;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static const gchar *const *
Packit 0652a1
gst_app_sink_uri_get_protocols (GType type)
Packit 0652a1
{
Packit 0652a1
  static const gchar *protocols[] = { "appsink", NULL };
Packit 0652a1
Packit 0652a1
  return protocols;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gchar *
Packit 0652a1
gst_app_sink_uri_get_uri (GstURIHandler * handler)
Packit 0652a1
{
Packit 0652a1
  return g_strdup ("appsink");
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static gboolean
Packit 0652a1
gst_app_sink_uri_set_uri (GstURIHandler * handler, const gchar * uri,
Packit 0652a1
    GError ** error)
Packit 0652a1
{
Packit 0652a1
  /* GstURIHandler checks the protocol for us */
Packit 0652a1
  return TRUE;
Packit 0652a1
}
Packit 0652a1
Packit 0652a1
static void
Packit 0652a1
gst_app_sink_uri_handler_init (gpointer g_iface, gpointer iface_data)
Packit 0652a1
{
Packit 0652a1
  GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
Packit 0652a1
Packit 0652a1
  iface->get_type = gst_app_sink_uri_get_type;
Packit 0652a1
  iface->get_protocols = gst_app_sink_uri_get_protocols;
Packit 0652a1
  iface->get_uri = gst_app_sink_uri_get_uri;
Packit 0652a1
  iface->set_uri = gst_app_sink_uri_set_uri;
Packit 0652a1
Packit 0652a1
}