waylandsink: Use handle num and plane num of MMVideoBuffer 42/154242/4 submit/tizen/20171010.100015
authorHyunil <hyunil46.park@samsung.com>
Tue, 10 Oct 2017 01:53:42 +0000 (10:53 +0900)
committerHyunil <hyunil46.park@samsung.com>
Tue, 10 Oct 2017 07:19:26 +0000 (16:19 +0900)
Change-Id: If2e5296125fa2e5a17f198ccb00b8796914e5729
Signed-off-by: Hyunil <hyunil46.park@samsung.com>
ext/wayland/gstwaylandsink.c
ext/wayland/wlbuffer.c
ext/wayland/wldisplay.h
ext/wayland/wlshmallocator.c
ext/wayland/wlshmallocator.h

index fe0eed6..41da309 100755 (executable)
@@ -684,7 +684,7 @@ gst_wayland_sink_make_flush_buffer (GstWlDisplay * display,
       wayland_tbm_client_get_bufmgr (display->tbm_client);
   g_return_val_if_fail (display->flush_tbm_bufmgr != NULL, FALSE);
 
-  for (i = 0; i < NV_BUF_PLANE_NUM; i++) {
+  for (i = 0; i < display->tbm_bo_num; i++) {
     if (mm_video_buf->handle.bo[i] != NULL) {
       tbm_bo_handle src;
       tbm_bo_handle dst;
@@ -740,10 +740,12 @@ gst_wayland_sink_copy_mm_video_buf_info_to_flush_buffer (GstWlDisplay * display,
   g_return_val_if_fail (mm_video_buf != NULL, FALSE);
   FUNCTION;
 
+  display->plane_num = mm_video_buf->plane_num;
+  display->tbm_bo_num = mm_video_buf->handle_num;
   ret = gst_wayland_sink_make_flush_buffer (display, mm_video_buf);
   if (ret) {
     int i;
-    for (i = 0; i < NV_BUF_PLANE_NUM; i++) {
+    for (i = 0; i < display->plane_num; i++) {
       if (display->flush_buffer->bo[i] != NULL) {
         display->bo[i] = display->flush_buffer->bo[i];
         GST_LOG ("bo %p", display->bo[i]);
@@ -778,7 +780,9 @@ gst_wayland_sink_add_mm_video_buf_info (GstWlDisplay * display,
   g_return_if_fail (mm_video_buf != NULL);
   FUNCTION;
 
-  for (i = 0; i < NV_BUF_PLANE_NUM; i++) {
+  display->plane_num = mm_video_buf->plane_num;
+  display->tbm_bo_num = mm_video_buf->handle_num;
+  for (i = 0; i < display->plane_num; i++) {
     if (mm_video_buf->handle.bo[i] != NULL) {
       display->bo[i] = mm_video_buf->handle.bo[i];
     } else {
@@ -823,9 +827,11 @@ gst_wayland_sink_get_mm_video_buf (GstBuffer * buffer)
     GST_ERROR ("Buffer type is not TBM");
     return NULL;
   }
-  GST_DEBUG ("TBM: handle.bo[0]:%p, handle.bo[1]:%p",
-      mm_video_buf->handle.bo[0], mm_video_buf->handle.bo[1]);
-
+  GST_DEBUG ("TBM bo: handle.bo[0]:%p, handle.bo[1]:%p, handle.bo[2]:%p",
+      mm_video_buf->handle.bo[0], mm_video_buf->handle.bo[1],
+      mm_video_buf->handle.bo[2]);
+  GST_DEBUG ("Number of TBM bo is %d", mm_video_buf->handle_num);
+  GST_DEBUG ("Number of plane is %d", mm_video_buf->plane_num);
   return mm_video_buf;
 }
 
index 9ba1815..c37e61e 100644 (file)
@@ -77,7 +77,6 @@
  */
 
 #include "wlbuffer.h"
-#define NV_BUF_PLANE_NUM    2   /*SN12 or ST12 has 2 plane */
 
 GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
 #define GST_CAT_DEFAULT gstwayland_debug
@@ -128,9 +127,9 @@ gst_wl_buffer_finalize (GObject * gobject)
     if (self->is_flush_request) {
       self->display->flush_tbm_bufmgr = NULL;
       if (self->display->flush_buffer) {
-        for (i = 0; i < NV_BUF_PLANE_NUM; i++) {
+        for (i = 0; i < self->display->tbm_bo_num; i++) {
           if (self->display->flush_buffer->bo[i]) {
-            GST_LOG ("tbm_bo_unref (bo@%p)",
+            GST_LOG ("flush buffer: tbm_bo_unref (bo@%p)",
                 self->display->flush_buffer->bo[i]);
             tbm_bo_unref (self->display->flush_buffer->bo[i]);
             self->display->flush_buffer->bo[i] = NULL;
index c7647c9..c3e4481 100644 (file)
 #include <wayland-client.h>
 #include "scaler-client-protocol.h"
 #ifdef TIZEN_FEATURE_WLSINK_ENHANCEMENT
+#include <gst/video/video.h>
 #include <tbm_bufmgr.h>
 #include <wayland-tbm-client.h>
 #include <tizen-extension-client-protocol.h>
-#define NV_BUF_PLANE_NUM    2   /*SN12 or ST12 has 2 plane */
 #define USE_WL_FLUSH_BUFFER
 #endif
 
@@ -44,7 +44,7 @@ G_BEGIN_DECLS
 #ifdef USE_WL_FLUSH_BUFFER
 typedef struct
 {
-  void *bo[NV_BUF_PLANE_NUM];
+  void *bo[GST_VIDEO_MAX_PLANES];
 } GstWlFlushBuffer;
 #endif
 
@@ -86,29 +86,31 @@ struct _GstWlDisplay
   struct wayland_tbm_client *tbm_client;
   tbm_bufmgr tbm_bufmgr;
   tbm_bo tbm_bo[TBM_BO_NUM];
-  int tbm_bo_idx;
+  gint tbm_bo_idx;
   tbm_surface_h tsurface;
   gboolean USE_TBM;
 
 #ifdef USE_WL_FLUSH_BUFFER
   GstWlFlushBuffer *flush_buffer;
   tbm_bufmgr flush_tbm_bufmgr;
-  int flush_request;
+  gint flush_request;
 #endif
   gboolean dump_video;
   guint total_dump;
   guint dump_count;
 
-  gboolean is_native_format;    /*SN12, ST12 */
-  void *bo[NV_BUF_PLANE_NUM];
-  int plane_size[NV_BUF_PLANE_NUM];
-  int stride_width[NV_BUF_PLANE_NUM];
-  int stride_height[NV_BUF_PLANE_NUM];
-  int width[NV_BUF_PLANE_NUM];
-  int height[NV_BUF_PLANE_NUM];
-  int native_video_size;
-  unsigned int wl_surface_id;
-  int buffer_width, buffer_height;
+  gboolean is_native_format;    /*SN12, ST12, SR32, S420 */
+  gpointer bo[GST_VIDEO_MAX_PLANES];
+  gint plane_size[GST_VIDEO_MAX_PLANES];
+  gint stride_width[GST_VIDEO_MAX_PLANES];
+  gint stride_height[GST_VIDEO_MAX_PLANES];
+  gint width[GST_VIDEO_MAX_PLANES];
+  gint height[GST_VIDEO_MAX_PLANES];
+  gint native_video_size;
+  guint wl_surface_id;
+  gint buffer_width, buffer_height;
+  gint plane_num;
+  gint tbm_bo_num;
 #endif
 
 #if 1
index 91ead3b..81e2cfd 100644 (file)
@@ -355,7 +355,7 @@ gst_wl_shm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
     const GstVideoInfo * info)
 {
   GstWlShmMemory *shm_mem = (GstWlShmMemory *) mem;
-  gint width, height, stride, offset;
+  gint width, height, stride;
   gsize size;
   gint plane_size[GST_VIDEO_MAX_PLANES], n_planes, i;
   enum wl_shm_format format;
@@ -366,7 +366,7 @@ gst_wl_shm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
 #ifdef TIZEN_FEATURE_WLSINK_ENHANCEMENT
   if (display->USE_TBM) {
     tbm_surface_info_s ts_info;
-    int num_bo;
+    int offset[GST_VIDEO_MAX_PLANES];
 
     if (display->is_native_format == TRUE) {
       /* In case of native format, use MMVideoBuffer data instead of GstVideoInfo */
@@ -376,34 +376,47 @@ gst_wl_shm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
       width = display->width[0];
       height = display->height[0];
       format = gst_video_format_to_wl_tbm_format (GST_VIDEO_INFO_FORMAT (info));
-      offset = display->stride_width[0] * display->stride_height[0];
       ts_info.width = width;
       ts_info.height = height;
       ts_info.format = format;
       ts_info.bpp = tbm_surface_internal_get_bpp (ts_info.format);
       ts_info.num_planes = tbm_surface_internal_get_num_planes (ts_info.format);
-      ts_info.planes[0].size = display->plane_size[0];
-      ts_info.planes[1].size = display->plane_size[1];
-      ts_info.planes[0].stride = display->stride_width[0];
-      ts_info.planes[1].stride = display->stride_width[1];
-      ts_info.planes[0].offset = 0;
-      ts_info.planes[1].offset = (display->bo[1]) ? 0 : offset;
+
+      for (i = 0; i < display->plane_num; i++) {
+        ts_info.planes[i].size = display->plane_size[i];
+        ts_info.planes[i].stride = display->stride_width[i];
+        offset[i] = display->stride_width[i] * display->stride_height[i];
+      }
+
+      if (display->tbm_bo_num == 1) {
+        ts_info.planes[0].offset = 0;
+        ts_info.planes[1].offset = offset[0];
+        if (display->plane_num == 3)
+          ts_info.planes[2].offset = offset[0] + offset[1];
+      } else if (display->tbm_bo_num == 2) {
+        ts_info.planes[0].offset = 0;
+        ts_info.planes[1].offset = 0;
+        if (display->plane_num == 3)
+          ts_info.planes[2].offset = offset[1];
+      } else if (display->tbm_bo_num == 3) {
+        ts_info.planes[0].offset = 0;
+        ts_info.planes[1].offset = 0;
+        ts_info.planes[2].offset = 0;
+      }
 
       GST_LOG
           ("set tbm_surface_info_s: width(%d) height(%d) format(%s) bpp(%d) num_planes(%d)",
           ts_info.width, ts_info.height, gst_wl_tbm_format_to_string (format),
           ts_info.bpp, ts_info.num_planes);
       GST_LOG
-          ("set tbm_surface_info_s: planse[0].stride(%d) planes[1].stride(%d) planes[0].offset(%d) planes[1].offset(%d)",
+          ("set tbm_surface_info_s: planse[0].stride(%d) planes[1].stride(%d) planes[2].stride(%d) planes[0].offset(%d) planes[1].offset(%d) planes[2].offset(%d)",
           ts_info.planes[0].stride, ts_info.planes[1].stride,
-          ts_info.planes[0].offset, ts_info.planes[1].offset);
-
-      num_bo = (display->bo[1]) ? 2 : 1;
-      GST_LOG ("num_bo(%d)", num_bo);
+          ts_info.planes[2].stride, ts_info.planes[0].offset,
+          ts_info.planes[1].offset, ts_info.planes[2].offset);
 
       display->tsurface =
           tbm_surface_internal_create_with_bos (&ts_info,
-          (tbm_bo *) display->bo, num_bo);
+          (tbm_bo *) display->bo, display->tbm_bo_num);
       GST_LOG ("create tbm surface(%p)", display->tsurface);
       wbuffer =
           wayland_tbm_client_create_buffer (display->tbm_client,
index c06b182..9f111d3 100644 (file)
@@ -23,7 +23,6 @@
 #ifndef __GST_WL_SHM_ALLOCATOR_H__
 #define __GST_WL_SHM_ALLOCATOR_H__
 
-#include <gst/video/video.h>
 #include <wayland-client-protocol.h>
 #include "wldisplay.h"