Waylandsink : Add handling displaying buffer 29/47629/5 accepted/tizen/mobile/20150908.074003 accepted/tizen/tv/20150908.074027 accepted/tizen/wearable/20150908.074017 submit/tizen/20150908.043219
authorHyunil <hyunil46.park@samsung.com>
Mon, 7 Sep 2015 08:04:47 +0000 (17:04 +0900)
committerHyunil <hyunil46.park@samsung.com>
Mon, 7 Sep 2015 08:22:33 +0000 (17:22 +0900)
Change-Id: I953a830e746f4b0769ce2a81dab6449b51ce92e3
Signed-off-by: Hyunil <hyunil46.park@samsung.com>
ext/wayland/gstwaylandsink.c
ext/wayland/waylandpool.c
ext/wayland/waylandpool.h

index 5d3eca6..34cd0f5 100755 (executable)
@@ -345,7 +345,7 @@ gst_wayland_sink_set_property (GObject * object,
       }
       sink->video_info_changed = TRUE;
       if (GST_STATE (sink) == GST_STATE_PAUSED) {
-        /*need to render current buffer*/
+        /*need to render current buffer */
       }
       break;
     case PROP_DISPLAY_GEOMETRY_METHOD:
@@ -353,11 +353,12 @@ gst_wayland_sink_set_property (GObject * object,
       GST_INFO_OBJECT (sink, "Display geometry method is set (%d)",
           sink->display_geometry_method);
       if (sink->window) {
-        gst_wl_window_set_disp_geo_method (sink->window, sink->display_geometry_method);
+        gst_wl_window_set_disp_geo_method (sink->window,
+            sink->display_geometry_method);
       }
       sink->video_info_changed = TRUE;
       if (GST_STATE (sink) == GST_STATE_PAUSED) {
-        /*need to render current buffer*/
+        /*need to render current buffer */
       }
       break;
     case PROP_ORIENTATION:
@@ -368,7 +369,7 @@ gst_wayland_sink_set_property (GObject * object,
       }
       sink->video_info_changed = TRUE;
       if (GST_STATE (sink) == GST_STATE_PAUSED) {
-        /*need to render current buffer*/
+        /*need to render current buffer */
       }
       break;
     case PROP_FLIP:
@@ -379,7 +380,7 @@ gst_wayland_sink_set_property (GObject * object,
       }
       sink->video_info_changed = TRUE;
       if (GST_STATE (sink) == GST_STATE_PAUSED) {
-        /*need to render current buffer*/
+        /*need to render current buffer */
       }
       break;
 #endif
@@ -1070,6 +1071,12 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
       if (ret != GST_FLOW_OK)
         goto no_buffer;
 
+
+      /*add displaying buffer */
+      GstWlMeta *meta;
+      meta = gst_buffer_get_wl_meta (to_render);
+      gst_wayland_buffer_pool_add_displaying_buffer (sink->pool, meta, buffer);
+
     } else {
       /*in case of normal video format and pool is not our pool */
 
@@ -1087,7 +1094,6 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
       gst_buffer_fill (to_render, 0, src.data, src.size);
       gst_buffer_unmap (buffer, &src);
     }
-
 #else
     if (!sink->pool)
       goto no_pool;
@@ -1215,7 +1221,8 @@ gst_wayland_sink_update_window_geometry (GstWaylandSink * sink)
     return;
 
   gst_wl_window_set_rotate_angle (sink->window, sink->rotate_angle);
-  gst_wl_window_set_disp_geo_method (sink->window, sink->display_geometry_method);
+  gst_wl_window_set_disp_geo_method (sink->window,
+      sink->display_geometry_method);
   gst_wl_window_set_orientation (sink->window, sink->orientation);
   gst_wl_window_set_flip (sink->window, sink->flip);
 }
index 1d33332..67dfca2 100755 (executable)
@@ -104,6 +104,9 @@ static gboolean gst_wayland_tizen_buffer_pool_start (GstBufferPool * pool);
 static gboolean gst_wayland_tizen_buffer_pool_stop (GstBufferPool * pool);
 static GstFlowReturn gst_wayland_tizen_buffer_pool_alloc (GstBufferPool * pool,
     GstBuffer ** buffer, GstBufferPoolAcquireParams * params);
+void gst_wayland_buffer_pool_remove_displaying_buffer (GstWaylandBufferPool *
+    self, GstWlMeta * meta, struct wl_buffer *wl_buffer);
+
 #endif
 
 #define gst_wayland_buffer_pool_parent_class parent_class
@@ -139,6 +142,10 @@ gst_wayland_buffer_pool_init (GstWaylandBufferPool * self)
   gst_video_info_init (&self->info);
   g_mutex_init (&self->buffers_map_mutex);
   self->buffers_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+  g_mutex_init (&self->displaying_buffers_map_mutex);
+  self->displaying_buffers_map =
+      g_hash_table_new (g_direct_hash, g_direct_equal);
 }
 
 static void
@@ -154,6 +161,9 @@ gst_wayland_buffer_pool_finalize (GObject * object)
   g_mutex_clear (&pool->buffers_map_mutex);
   g_hash_table_unref (pool->buffers_map);
 
+  g_mutex_clear (&pool->displaying_buffers_map_mutex);
+  g_hash_table_unref (pool->displaying_buffers_map);
+
   g_object_unref (pool->display);
 
   G_OBJECT_CLASS (gst_wayland_buffer_pool_parent_class)->finalize (object);
@@ -169,6 +179,10 @@ buffer_release (void *data, struct wl_buffer *wl_buffer)
   GstWlMeta *meta;
 
   g_mutex_lock (&self->buffers_map_mutex);
+
+  /*remove displaying buffer */
+  gst_wayland_buffer_pool_remove_displaying_buffer (self, meta, wl_buffer);
+
   buffer = g_hash_table_lookup (self->buffers_map, wl_buffer);
 
   GST_LOG_OBJECT (self, "wl_buffer::release (GstBuffer: %p)", buffer);
@@ -180,8 +194,6 @@ buffer_release (void *data, struct wl_buffer *wl_buffer)
       /* unlock before unref because stop() may be called from here */
       GST_LOG_OBJECT (self, "Decrease ref count of buffer");
       gst_buffer_unref (buffer);
-      g_mutex_unlock (&self->buffers_map_mutex);
-      return;
     }
   }
   g_mutex_unlock (&self->buffers_map_mutex);
@@ -519,6 +531,10 @@ gst_wayland_tizen_buffer_pool_stop (GstBufferPool * pool)
   g_hash_table_remove_all (self->buffers_map);
   g_mutex_unlock (&self->buffers_map_mutex);
 
+  g_mutex_lock (&self->displaying_buffers_map_mutex);
+  g_hash_table_remove_all (self->displaying_buffers_map);
+  g_mutex_unlock (&self->displaying_buffers_map_mutex);
+
   return GST_BUFFER_POOL_CLASS (parent_class)->stop (pool);
 }
 
@@ -590,9 +606,9 @@ gst_wayland_tizen_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
     }
 
     meta->wbuffer =
-        tizen_buffer_pool_create_planar_buffer (self->
-        display->tizen_buffer_pool, width, height, format, name[0], offset[0],
-        stride[0], name[1], offset[1], stride[1], 0, 0, 0);
+        tizen_buffer_pool_create_planar_buffer (self->display->
+        tizen_buffer_pool, width, height, format, name[0], offset[0], stride[0],
+        name[1], offset[1], stride[1], 0, 0, 0);
     meta->used_by_compositor = FALSE;
 
     GST_DEBUG ("tizen_buffer_pool_create_planar_buffer create wl_buffer %p",
@@ -670,11 +686,54 @@ gst_wayland_tizen_buffer_pool_finalize (GObject * object)
   g_mutex_clear (&pool->buffers_map_mutex);
   g_hash_table_unref (pool->buffers_map);
 
+  g_mutex_clear (&pool->displaying_buffers_map_mutex);
+  g_hash_table_unref (pool->displaying_buffers_map);
+
   g_object_unref (pool->display);
 
   G_OBJECT_CLASS (gst_wayland_buffer_pool_parent_class)->finalize (object);
 }
 
+void
+gst_wayland_buffer_pool_add_displaying_buffer (GstBufferPool * pool,
+    GstWlMeta * meta, GstBuffer * buffer)
+{
+  FUNCTION_ENTER ();
+  g_return_val_if_fail (pool, NULL);
+  g_return_val_if_fail (meta, NULL);
+  g_return_val_if_fail (buffer, NULL);
+
+  GstWaylandBufferPool *self = GST_WAYLAND_BUFFER_POOL_CAST (pool);
+
+  g_mutex_lock (&self->displaying_buffers_map_mutex);
+
+  GST_LOG_OBJECT (self, "key value is meta->wbuffer(%p)", meta->wbuffer);
+  GST_LOG_OBJECT (self, "Increase ref count of buffer(%p) from omx", buffer);
+  gst_buffer_ref (buffer);
+  g_hash_table_insert (self->displaying_buffers_map, meta->wbuffer, buffer);
+
+  g_mutex_unlock (&self->displaying_buffers_map_mutex);
+}
+
+void
+gst_wayland_buffer_pool_remove_displaying_buffer (GstWaylandBufferPool * self,
+    GstWlMeta * meta, struct wl_buffer *wl_buffer)
+{
+  FUNCTION_ENTER ();
+  g_return_val_if_fail (self, NULL);
+  g_return_val_if_fail (meta, NULL);
+  g_return_val_if_fail (wl_buffer, NULL);
+
+  GstBuffer *buffer;
+  g_mutex_lock (&self->displaying_buffers_map_mutex);
+  buffer = g_hash_table_lookup (self->displaying_buffers_map, wl_buffer);
+  if (buffer) {
+    GST_LOG_OBJECT (self, "Decrease ref count of buffer(%p) from omx", buffer);
+    g_hash_table_remove (self->displaying_buffers_map, meta->wbuffer);
+    gst_buffer_unref (buffer);
+  }
+  g_mutex_unlock (&self->displaying_buffers_map_mutex);
+}
 #endif
 #ifdef DUMP_BUFFER
 int
index ef198f8..0698e6b 100755 (executable)
@@ -80,6 +80,10 @@ struct _GstWaylandBufferPool
 
   GMutex buffers_map_mutex;
   GHashTable *buffers_map;
+#ifdef GST_WLSINK_ENHANCEMENT
+  GMutex displaying_buffers_map_mutex;
+  GHashTable *displaying_buffers_map;
+#endif
 };
 
 struct _GstWaylandBufferPoolClass
@@ -95,6 +99,8 @@ GstBufferPool *gst_wayland_buffer_pool_new (GstWlDisplay * display);
 void gst_wayland_compositor_acquire_buffer (GstWaylandBufferPool * self,
     GstBuffer * buffer);
 void gst_wayland_compositor_release_all_buffers (GstWaylandBufferPool * self);
+void gst_wayland_buffer_pool_add_displaying_buffer (GstBufferPool * pool,
+    GstWlMeta * meta, GstBuffer * buffer);
 
 G_END_DECLS
 #endif /*__GST_WAYLAND_BUFFER_POOL_H__*/