appsink: Patch to support wait-on-eos property
authorjuan82.liu <juan82.liu@samsung.com>
Wed, 1 Mar 2017 01:03:41 +0000 (09:03 +0800)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 17 Mar 2017 03:22:10 +0000 (12:22 +0900)
pipeline state change blocked by appsink

Change-Id: I0d0ac5ecaf959edabf641637a5d14fc41957f8f0

gst-libs/gst/app/gstappsink.c [changed mode: 0644->0755]
gst-libs/gst/app/gstappsink.h [changed mode: 0644->0755]
packaging/gst-plugins-base.spec [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 9a7fcb4..c5ce731
@@ -79,6 +79,9 @@ struct _GstAppSinkPrivate
   guint num_buffers;
   guint max_buffers;
   gboolean drop;
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+  gboolean wait_on_eos;
+#endif
 
   GCond cond;
   GMutex mutex;
@@ -119,6 +122,9 @@ enum
 #define DEFAULT_PROP_EMIT_SIGNALS      FALSE
 #define DEFAULT_PROP_MAX_BUFFERS       0
 #define DEFAULT_PROP_DROP              FALSE
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+#define DEFAULT_PROP_WAIT_ON_EOS       TRUE
+#endif
 
 enum
 {
@@ -128,6 +134,9 @@ enum
   PROP_EMIT_SIGNALS,
   PROP_MAX_BUFFERS,
   PROP_DROP,
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+  PROP_WAIT_ON_EOS,
+#endif
   PROP_LAST
 };
 
@@ -210,6 +219,24 @@ gst_app_sink_class_init (GstAppSinkClass * klass)
           "Drop old buffers when the buffer queue is filled", DEFAULT_PROP_DROP,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+  /**
+   * GstAppSink::wait-on-eos:
+   *
+   * Wait for all buffers to be processed after receiving an EOS.
+   *
+   * In cases where it is uncertain if an @appsink will have a consumer for its buffers
+   * when it receives an EOS, set to %FALSE to ensure that the @appsink will not hang.
+   *
+   * Since: 1.8
+   */
+  g_object_class_install_property (gobject_class, PROP_WAIT_ON_EOS,
+      g_param_spec_boolean ("wait-on-eos", "Wait on EOS",
+          "Wait for all buffers to be processed after receiving an EOS",
+          DEFAULT_PROP_WAIT_ON_EOS,
+          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+#endif
+
   /**
    * GstAppSink::eos:
    * @appsink: the appsink element that emitted the signal
@@ -359,6 +386,9 @@ gst_app_sink_init (GstAppSink * appsink)
   priv->emit_signals = DEFAULT_PROP_EMIT_SIGNALS;
   priv->max_buffers = DEFAULT_PROP_MAX_BUFFERS;
   priv->drop = DEFAULT_PROP_DROP;
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+  priv->wait_on_eos = DEFAULT_PROP_WAIT_ON_EOS;
+#endif
 }
 
 static void
@@ -424,6 +454,11 @@ gst_app_sink_set_property (GObject * object, guint prop_id,
     case PROP_DROP:
       gst_app_sink_set_drop (appsink, g_value_get_boolean (value));
       break;
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+    case PROP_WAIT_ON_EOS:
+      gst_app_sink_set_wait_on_eos (appsink, g_value_get_boolean (value));
+      break;
+#endif
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -459,6 +494,11 @@ gst_app_sink_get_property (GObject * object, guint prop_id, GValue * value,
     case PROP_DROP:
       g_value_set_boolean (value, gst_app_sink_get_drop (appsink));
       break;
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+    case PROP_WAIT_ON_EOS:
+      g_value_set_boolean (value, gst_app_sink_get_wait_on_eos (appsink));
+      break;
+#endif
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -593,7 +633,11 @@ gst_app_sink_event (GstBaseSink * sink, GstEvent * event)
        * Otherwise we might signal EOS before all buffers are
        * consumed, which is a bit confusing for the application
        */
+#ifndef TIZEN_FEATURE_GST_UPSTREAM
       while (priv->num_buffers > 0 && !priv->flushing)
+#else
+      while (priv->num_buffers > 0 && !priv->flushing && priv->wait_on_eos)
+#endif
         g_cond_wait (&priv->cond, &priv->mutex);
       if (priv->flushing)
         emit = FALSE;
@@ -1096,6 +1140,61 @@ gst_app_sink_get_drop (GstAppSink * appsink)
   return result;
 }
 
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+/**
+ * gst_app_sink_set_wait_on_eos:
+ * @appsink: a #GstAppSink
+ * @wait: the new state
+ *
+ * Instruct @appsink to wait for all buffers to be consumed when an EOS is received.
+ *
+ */
+void
+gst_app_sink_set_wait_on_eos (GstAppSink * appsink, gboolean wait)
+{
+  GstAppSinkPrivate *priv;
+
+  g_return_if_fail (GST_IS_APP_SINK (appsink));
+
+  priv = appsink->priv;
+
+  g_mutex_lock (&priv->mutex);
+  if (priv->wait_on_eos != wait) {
+    priv->wait_on_eos = wait;
+    /* signal the change */
+    g_cond_signal (&priv->cond);
+  }
+  g_mutex_unlock (&priv->mutex);
+}
+
+/**
+ * gst_app_sink_get_wait_on_eos:
+ * @appsink: a #GstAppSink
+ *
+ * Check if @appsink will wait for all buffers to be consumed when an EOS is
+ * received.
+ *
+ * Returns: %TRUE if @appsink will wait for all buffers to be consumed when an
+ * EOS is received.
+ */
+gboolean
+gst_app_sink_get_wait_on_eos (GstAppSink * appsink)
+{
+  gboolean result;
+  GstAppSinkPrivate *priv;
+
+  g_return_val_if_fail (GST_IS_APP_SINK (appsink), FALSE);
+
+  priv = appsink->priv;
+
+  g_mutex_lock (&priv->mutex);
+  result = priv->wait_on_eos;
+  g_mutex_unlock (&priv->mutex);
+
+  return result;
+}
+#endif
+
 /**
  * gst_app_sink_pull_preroll:
  * @appsink: a #GstAppSink
old mode 100644 (file)
new mode 100755 (executable)
index 4e84858..a42eb1f
@@ -115,6 +115,11 @@ guint           gst_app_sink_get_max_buffers  (GstAppSink *appsink);
 void            gst_app_sink_set_drop         (GstAppSink *appsink, gboolean drop);
 gboolean        gst_app_sink_get_drop         (GstAppSink *appsink);
 
+#ifdef TIZEN_FEATURE_GST_UPSTREAM
+void            gst_app_sink_set_wait_on_eos  (GstAppSink *appsink, gboolean wait);
+gboolean        gst_app_sink_get_wait_on_eos  (GstAppSink *appsink);
+#endif
+
 GstSample *     gst_app_sink_pull_preroll     (GstAppSink *appsink);
 GstSample *     gst_app_sink_pull_sample      (GstAppSink *appsink);
 
old mode 100644 (file)
new mode 100755 (executable)
index 86de260..0b93e58
@@ -89,6 +89,7 @@ export CFLAGS="%{optflags} -fno-strict-aliasing\
  -DTIZEN_FEATURE_VIDEO_MODIFICATION\
  -DTIZEN_FEATURE_SUBPARSE_MODIFICATION\
  -DTIZEN_FEATURE_VOLUME_MODIFICATION\
+ -DTIZEN_FEATURE_GST_UPSTREAM\
 %if "%{TIZEN_PRODUCT_TV}" == "1"
  -DTIZEN_PROFILE_TV\
  -DTIZEN_FEATURE_TRUSTZONE\