Waylandsink : improve flush buffer management.
authorHyunil <hyunil46.park@samsung.com>
Thu, 27 Oct 2016 05:38:24 +0000 (14:38 +0900)
committerHyunil Park <hyunil46.park@samsung.com>
Tue, 8 Nov 2016 05:16:04 +0000 (21:16 -0800)
              1. remove gst_buffer_deep_copy
              2. change making flush buffer

Change-Id: Ie7e4986acc5ceca591929f50de46ba13f22952d5
Signed-off-by: Hyunil <hyunil46.park@samsung.com>
(cherry picked from commit c82d1f55eb5eb5c84fc3baf94065a126f125b218)

ext/wayland/gstwaylandsink.c
ext/wayland/wldisplay.h

index 1b6bf74..6302eb5 100755 (executable)
@@ -756,33 +756,12 @@ static void
 gst_wayland_sink_render_flush_buffer (GstBaseSink * bsink)
 {
   GstWaylandSink *sink;
-  GstBuffer *buffer;
   sink = GST_WAYLAND_SINK (bsink);
   FUNCTION;
   g_return_if_fail (sink != NULL);
   g_return_if_fail (sink->last_buffer != NULL);
 
-  buffer = gst_buffer_copy_deep (sink->last_buffer);
-
-  gst_wayland_sink_render (bsink, buffer);
-  if (buffer)
-    gst_buffer_unref (buffer);
-}
-
-static void
-gst_wayland_sink_gapless_render (GstBaseSink * bsink)
-{
-  g_return_if_fail (bsink != NULL);
-  FUNCTION;
-  gst_wayland_sink_render_flush_buffer (bsink);
-}
-
-static void
-gst_wayland_sink_keep_camera_preview (GstBaseSink * bsink)
-{
-  g_return_if_fail (bsink != NULL);
-  FUNCTION;
-  gst_wayland_sink_render_flush_buffer (bsink);
+  gst_wayland_sink_render (bsink, sink->last_buffer);
 }
 
 #endif
@@ -1166,7 +1145,7 @@ gst_wayland_sink_event (GstBaseSink * bsink, GstEvent * event)
 
       sink->got_costum_event = TRUE;
       if (gst_wayland_sink_check_use_gapless (sink)) {
-        gst_wayland_sink_gapless_render (bsink);
+        gst_wayland_sink_render_flush_buffer (bsink);
         sink->got_costum_event = FALSE;
       }
       sink->got_costum_event = FALSE;
@@ -1297,9 +1276,11 @@ gst_wayland_sink_change_state (GstElement * element, GstStateChange transition)
         if (sink->window) {
           if (!gst_wl_window_is_toplevel (sink->window)) {
             GstBaseSink *bsink = GST_BASE_SINK (element);
-            if (sink->USE_TBM) {
+            if (sink->USE_TBM && sink->display->is_native_format
+                && !sink->display->flush_buffer) {
+              /* To avoid duplicate request by App, check flush_buffer by flush_request of MMVideoBuffer */
               sink->request_camera_flush_buf = TRUE;
-              gst_wayland_sink_keep_camera_preview (bsink);
+              gst_wayland_sink_render_flush_buffer (bsink);
               sink->request_camera_flush_buf = FALSE;
             }
             break;
@@ -1798,6 +1779,7 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
 {
   GstWaylandSink *sink = GST_WAYLAND_SINK (bsink);
   GstBuffer *to_render;
+  GstBuffer *flush_gstbuf = NULL;
   GstWlBuffer *wlbuffer;
   GstFlowReturn ret = GST_FLOW_OK;
   FUNCTION;
@@ -1903,15 +1885,20 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
 
         wlbuffer = gst_buffer_get_wl_buffer (buffer);
         /* last_buffer from gaplasee have wlbuffer */
-        if (G_UNLIKELY (!wlbuffer)
-            || (gst_wayland_sink_check_use_gapless (sink))
-            || sink->request_camera_flush_buf) {
+        if (G_UNLIKELY (!wlbuffer) || sink->display->flush_request) {
           wbuf =
               gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
               &sink->video_info);
           if (G_UNLIKELY (!wbuf))
             goto no_wl_buffer;
-          gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
+          if (sink->display->flush_request) {
+            flush_gstbuf = gst_buffer_new ();
+            GST_LOG ("To flush, new gstBuffer(%p)", flush_gstbuf);
+            gst_buffer_add_wl_buffer (flush_gstbuf, wbuf, sink->display);
+
+          } else {
+            gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
+          }
         }
       } else if (sink->USE_TBM && !sink->display->is_native_format) {
 
@@ -1978,26 +1965,38 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
 
   if (sink->USE_TBM && sink->display->is_native_format) {
     if ((G_UNLIKELY (buffer == sink->last_buffer)
-            && !(gst_wayland_sink_check_use_gapless (sink)))
-        || (G_UNLIKELY (buffer == sink->last_buffer)
-            && !sink->request_camera_flush_buf)) {
+            && !(sink->display->flush_request))) {
       GST_LOG_OBJECT (sink, "Buffer already being rendered");
       goto done;
     }
 
-    GST_LOG_OBJECT (sink, "replace last_buffer: (%p) -> (%p)",
-        sink->last_buffer, buffer);
-    gst_buffer_replace (&sink->last_buffer, buffer);
-
-    GST_LOG_OBJECT (sink, "after gst_buffer_replace buffer %p, ref_count(%d)",
-        buffer, GST_OBJECT_REFCOUNT_VALUE (buffer));
-
+    if (flush_gstbuf && sink->display->flush_request) {
+
+      GST_LOG_OBJECT (sink, "replace last_buffer: (%p) -> (%p)",
+          sink->last_buffer, flush_gstbuf);
+      /*  increase ref count of flush_gstbuf
+         decrease  ref count of sink->last_buffer */
+      gst_buffer_replace (&sink->last_buffer, flush_gstbuf);
+      GST_LOG_OBJECT (sink, "after gst_buffer_replace buffer %p, ref_count(%d)",
+          flush_gstbuf, GST_OBJECT_REFCOUNT_VALUE (flush_gstbuf));
+      /* decrease  ref count of flush_buffer */
+      gst_buffer_unref (flush_gstbuf);
+
+    } else {                    //normal case
+
+      GST_LOG_OBJECT (sink, "replace last_buffer: (%p) -> (%p)",
+          sink->last_buffer, buffer);
+      /*  increase ref count of buffer
+         decrease  ref count of sink->last_buffer */
+      gst_buffer_replace (&sink->last_buffer, buffer);
+      GST_LOG_OBJECT (sink, "after gst_buffer_replace buffer %p, ref_count(%d)",
+          buffer, GST_OBJECT_REFCOUNT_VALUE (buffer));
+    }
     if (sink->visible) {
       render_last_buffer (sink);
     } else {
       GST_LOG ("skip rendering");
     }
-
     goto done;
 
   } else {                      /* USE SHM or normal format */
index becd519..68a0996 100644 (file)
@@ -40,8 +40,6 @@ G_BEGIN_DECLS
 #define GST_IS_WL_DISPLAY_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_DISPLAY))
 #define GST_WL_DISPLAY_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
 #define FUNCTION GST_LOG ("<ENTER>")
-typedef struct _GstWlDisplay GstWlDisplay;
-typedef struct _GstWlDisplayClass GstWlDisplayClass;
 
 #ifdef USE_WL_FLUSH_BUFFER
 typedef struct
@@ -119,6 +117,9 @@ struct _GstWlDisplayClass
   GObjectClass parent_class;
 };
 
+typedef struct _GstWlDisplay GstWlDisplay;
+typedef struct _GstWlDisplayClass GstWlDisplayClass;
+
 GType gst_wl_display_get_type (void);
 
 GstWlDisplay *gst_wl_display_new (const gchar * name, GError ** error);