#define DEFAULT_WIDTH 640
#define DEFAULT_HEIGHT 480
-//#define DUMP_BUFFER
-#define USE_MM_VIDEO_BUFFER
+//#define WAYLANDSRC_BUFFER_DUMP
+#define WAYLANDSRC_DUMP_FILE "/tmp/waylandsrc.dump"
#define C(b,m) (char)(((b) >> (m)) & 0xFF)
#define B(c,s) ((((unsigned int)(c)) & 0xff) << (s))
mirror_handle_stop
};
+
+#ifdef WAYLANDSRC_BUFFER_DUMP
+static int dump_cnt;
+
+void save_waylandsrc_buffer (output_buffer * out_buffer)
+{
+ dump_cnt++;
+
+ if (100 < dump_cnt && dump_cnt < 150) {
+ tbm_bo_handle bo_handle;
+ FILE *fp = fopen (WAYLANDSRC_DUMP_FILE, "a");
+ if (fp == NULL) {
+ GST_ERROR_OBJECT (src, "Failed to open file: %s", strerror (errno));
+ return;
+ }
+
+ bo_handle = tbm_bo_map (out_buffer->bo[0], TBM_DEVICE_CPU, TBM_OPTION_READ);
+
+ if (bo_handle.ptr)
+ fwrite ((char *)bo_handle.ptr, tbm_bo_size(out_buffer->bo[0]), 1, fp);
+ else
+ GST_ERROR_OBJECT (src, "Failed to get tbm bo[0]'s handle: %s", strerror (errno));
+
+ tbm_bo_unmap(out_buffer->bo[0]);
+
+ #ifndef TIZEN_FEATURE_PRODUCT_TM1
+ bo_handle = tbm_bo_map (out_buffer->bo[1], TBM_DEVICE_CPU, TBM_OPTION_READ);
+ if (bo_handle.ptr)
+ fwrite ((char *) bo_handle.ptr, tbm_bo_size(out_buffer->bo[1]), 1, fp);
+ else
+ GST_ERROR_OBJECT (src, "Failed to get tbm bo[1]'s handle:: %s", strerror (errno));
+
+ tbm_bo_unmap(out_buffer->bo[1]);
+ #endif
+
+ GST_ERROR_OBJECT (src, "Dump (%d):%d %d\n", dump_cnt, out_buffer->size, tbm_bo_size(out_buffer->bo[0]));
+
+ fclose (fp);
+ }
+}
+#endif
+
int new_calc_plane(int width, int height)
{
int mbX, mbY;
out_buffer->size, 0, out_buffer->size, (gpointer) out_buffer,
gst_wayland_src_gst_buffer_unref));
} else if (src->format == TBM_FORMAT_NV12) {
-#ifndef USE_MM_VIDEO_BUFFER
- out_buffer->gst_buffer = gst_buffer_new ();
- gst_buffer_append_memory (out_buffer->gst_buffer,
- gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
- tbm_bo_map(out_buffer->bo[0], TBM_DEVICE_CPU, TBM_OPTION_READ).ptr,
- tbm_bo_size(out_buffer->bo[0]), 0, tbm_bo_size(out_buffer->bo[0]),
- (gpointer) out_buffer, gst_wayland_src_gst_buffer_unref));
- gst_buffer_append_memory (out_buffer->gst_buffer,
- gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
- tbm_bo_map(out_buffer->bo[1], TBM_DEVICE_CPU, TBM_OPTION_READ).ptr,
- tbm_bo_size(out_buffer->bo[1]), 0, tbm_bo_size(out_buffer->bo[1]),
- (gpointer) out_buffer, NULL));
-#else
- MMVideoBuffer *mm_video_buf = NULL;
- mm_video_buf = (MMVideoBuffer *) malloc (sizeof (MMVideoBuffer));
- if (mm_video_buf == NULL) {
- GST_ERROR_OBJECT (src, "failed to alloc MMVideoBuffer");
+ GstMemory *memory = NULL;
+ GST_WARNING_OBJECT (src, "Creating memory by tizen allocator");
+ memory = gst_tizen_allocator_alloc_surface(src->allocator,
+ &src->video_info,
+ out_buffer->surface,
+ (gpointer)out_buffer,
+ (GDestroyNotify)gst_wayland_src_gst_buffer_unref);
+
+ if (!memory) {
+ GST_ERROR_OBJECT (src, "failed to alloc memory by tizen allocator");
goto FUNC_END;
}
- memset (mm_video_buf, 0x00, sizeof (MMVideoBuffer));
-
- mm_video_buf->type = MM_VIDEO_BUFFER_TYPE_TBM_BO;
- mm_video_buf->handle.bo[0] = out_buffer->bo[0];
- mm_video_buf->handle.bo[1] = out_buffer->bo[1];
- GST_INFO_OBJECT (src, "BO : %p %p", mm_video_buf->handle.bo[0], mm_video_buf->handle.bo[1]);
-#ifndef TIZEN_FEATURE_PRODUCT_TM1
- mm_video_buf->size[0] = gst_calculate_y_size(src->width, src->height); /*(src->width * src->height);*/
- mm_video_buf->size[1] = gst_calculate_uv_size(src->width, src->height); /*(src->width * (src->height >> 1));*/
- GST_INFO_OBJECT (src, "Size : %d %d", mm_video_buf->size[0], mm_video_buf->size[1]);
-
- mm_video_buf->handle.dmabuf_fd[0] = tbm_bo_get_handle(out_buffer->bo[0], TBM_DEVICE_MM).u32;
- mm_video_buf->handle.dmabuf_fd[1] = tbm_bo_get_handle(out_buffer->bo[1], TBM_DEVICE_MM).u32;
-
- mm_video_buf->handle.paddr[0] = (tbm_bo_map(mm_video_buf->handle.bo[0], TBM_DEVICE_CPU, TBM_OPTION_WRITE)).ptr;
- mm_video_buf->handle.paddr[1] = (tbm_bo_map(mm_video_buf->handle.bo[1], TBM_DEVICE_CPU, TBM_OPTION_WRITE)).ptr;
-
- tbm_bo_unmap (mm_video_buf->handle.bo[0]);
- tbm_bo_unmap (mm_video_buf->handle.bo[1]);
-#endif
-
- mm_video_buf->width[0] = src->width;
- mm_video_buf->height[0] = src->height;
- mm_video_buf->format = MM_PIXEL_FORMAT_NV12;
- mm_video_buf->width[1] = src->width;
- mm_video_buf->height[1] = src->height >> 1;
-
- mm_video_buf->stride_width[0] = GST_ROUND_UP_16 (mm_video_buf->width[0]);
- mm_video_buf->stride_height[0] = GST_ROUND_UP_16 (mm_video_buf->height[0]);
- mm_video_buf->stride_width[1] = GST_ROUND_UP_16 (mm_video_buf->width[1]);
- mm_video_buf->stride_height[1] = GST_ROUND_UP_16 (mm_video_buf->height[1]);
- mm_video_buf->is_secured = 0;
-
-#ifdef TIZEN_FEATURE_PRODUCT_TM1
- mm_video_buf->size[0] = mm_video_buf->stride_width[0] * mm_video_buf->stride_height[0];
- mm_video_buf->size[1] = mm_video_buf->stride_width[1] * mm_video_buf->stride_height[1];
- GST_INFO_OBJECT (src, "Size : %d %d", mm_video_buf->size[0], mm_video_buf->size[1]);
-
- mm_video_buf->data[0] = (tbm_bo_map(mm_video_buf->handle.bo[0], TBM_DEVICE_CPU, TBM_OPTION_WRITE)).ptr;
- tbm_bo_unmap (mm_video_buf->handle.bo[0]);
-#endif
-
- out_buffer->gst_buffer = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
- out_buffer, sizeof (out_buffer), 0, sizeof (out_buffer), (gpointer) out_buffer,
- gst_wayland_src_gst_buffer_unref);
-
- gst_buffer_append_memory (out_buffer->gst_buffer,
- gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
- mm_video_buf, sizeof (*mm_video_buf), 0, sizeof (*mm_video_buf),
- mm_video_buf, g_free));
-
-#ifdef DUMP_BUFFER
- static int dump_cnt = 0;
- void *data, *data1;
- FILE *fp;
-
- data = tbm_bo_map (out_buffer->bo[0], TBM_DEVICE_CPU, TBM_OPTION_READ).ptr;
- if (!data) {
- GST_ERROR_OBJECT (src, "get tbm bo handle failed: %s", strerror (errno));
- return;
- }
- data1 = tbm_bo_map (out_buffer->bo[1], TBM_DEVICE_CPU, TBM_OPTION_READ).ptr;
- if (!data1) {
- GST_ERROR_OBJECT (src, "get tbm bo handle failed: %s", strerror (errno));
- return;
- }
-
- fp = fopen ("/root/raw.dump", "a");
- if (fp == NULL)
- return;
-
- if (100 < dump_cnt && dump_cnt < 150) {
- fwrite ((char *) data, tbm_bo_size(out_buffer->bo[0]), 1, fp);
- fwrite ((char *) data1, tbm_bo_size(out_buffer->bo[1]), 1, fp);
- GST_ERROR_OBJECT (src, "Dump :%d\n", out_buffer->size);
- }
-
- dump_cnt++;
- fclose (fp);
-#endif
+ out_buffer->gst_buffer = gst_buffer_new ();
+ gst_buffer_append_memory (out_buffer->gst_buffer, memory);
+#ifdef WAYLANDSRC_BUFFER_DUMP
+ save_waylandsrc_buffer (out_buffer);
#endif
}
} else {
break;
case TBM_FORMAT_NV12:
case TBM_FORMAT_NV21:
- info.width = src->width;
- info.height = src->height;
- info.format = src->format;
- info.bpp = tbm_surface_internal_get_bpp(info.format);
- info.num_planes = 2;
- info.planes[0].stride = info.width;
- info.planes[0].size = gst_calculate_y_size(info.planes[0].stride, info.height);//info.planes[0].stride * info.height
- info.planes[0].offset = 0;
- info.planes[1].stride = info.width;
- info.planes[1].size = gst_calculate_uv_size(info.planes[1].stride, info.height);//info.planes[1].stride * (info.height >> 1);
- info.planes[1].offset = 0;
- info.size = info.planes[0].size + info.planes[1].size;
+
+ GST_WARNING_OBJECT (src, "BO image size : %d %d %d %d", src->ts_info.planes[0].size, src->ts_info.planes[1].size, src->ts_info.num_planes, src->ts_info.size);
#ifdef TIZEN_FEATURE_PRODUCT_TM1
out_buffer->bo[0] =
- tbm_bo_alloc (bufmgr, info.size, TBM_BO_DEFAULT);
+ tbm_bo_alloc (bufmgr, src->ts_info.planes[0].size + src->ts_info.planes[1].size, TBM_BO_DEFAULT);
if (out_buffer->bo[0] == NULL)
goto failed;
bo_num = 1;
#else
out_buffer->bo[0] =
- tbm_bo_alloc (bufmgr, info.planes[0].size, TBM_BO_DEFAULT);
+ tbm_bo_alloc (bufmgr, src->ts_info.planes[0].size, TBM_BO_DEFAULT);
if (out_buffer->bo[0] == NULL)
goto failed;
out_buffer->bo[1] =
- tbm_bo_alloc (bufmgr, info.planes[1].size, TBM_BO_DEFAULT);
+ tbm_bo_alloc (bufmgr, src->ts_info.planes[1].size, TBM_BO_DEFAULT);
if (out_buffer->bo[1] == NULL)
goto failed;
#endif
out_buffer->surface =
- tbm_surface_internal_create_with_bos(&info, out_buffer->bo, bo_num);
+ tbm_surface_internal_create_with_bos(&src->ts_info, out_buffer->bo, bo_num);
if (out_buffer->surface == NULL)
goto failed;
wl_proxy_set_queue ((struct wl_proxy *)out_buffer->wl_buffer, src->queue);
- out_buffer->size = info.size;
+ out_buffer->size = src->ts_info.size;
break;
default:
GST_WARNING_OBJECT (src, "unknown format");
src->height = DEFAULT_HEIGHT;
src->use_tbm = TRUE;
+
+ src->allocator = gst_tizen_allocator_new();
+ GST_WARNING_OBJECT (src, "Allocator: New ptr is %" GST_PTR_FORMAT, src->allocator);
}
static void
if (src->display) {
gst_wayland_src_disconnect (src);
}
+
+ if (src->allocator) {
+ GST_WARNING_OBJECT (src, "Allocator: Unref");
+ gst_object_unref(src->allocator);
+ src->allocator = NULL;
+ }
}
static gboolean
gint height = 0;
gboolean ret = TRUE;
const gchar *media_type = NULL;
+ int tbm_ret = 0;
+ tbm_surface_h t_surface = NULL;
GST_WARNING_OBJECT (src, "set_caps : %" GST_PTR_FORMAT, caps);
if (!src->display)
if (src->use_tbm && src->format == FOURCC_ARGB)
src->format = TBM_FORMAT_ARGB8888;
+ /* get GstVideoInfo */
+ if (!gst_video_info_from_caps(&src->video_info, caps)) {
+ GST_ERROR_OBJECT(src, "get video info failed (caps[%p,%"GST_PTR_FORMAT"])", caps, caps);
+ return FALSE;
+ }
+
+ /* Create tbm_surface_info */
+ t_surface = tbm_surface_create(src->width, src->height, TBM_FORMAT_NV12);
+ if (!t_surface) {
+ GST_ERROR_OBJECT(src, "tbm surface create failed");
+ return FALSE;
+ }
+
+ memset(&src->ts_info, 0x0, sizeof(tbm_surface_info_s));
+
+ tbm_ret = tbm_surface_get_info(t_surface, &src->ts_info);
+ tbm_surface_destroy(t_surface);
+ t_surface = NULL;
+
+ if (tbm_ret != TBM_SURFACE_ERROR_NONE) {
+ GST_ERROR_OBJECT(src, "tbm surface info get failed");
+ return FALSE;
+ }
+
GST_INFO_OBJECT (src, "format:%c%c%c%c, width: %d, height: %d",
FOURCC_STR (src->format), src->width, src->height);
GST_INFO_OBJECT (src, "FPS %d/%d", src->fps_n, src->fps_d);
gst_wayland_src_thread_start (src);
+ GST_WARNING_OBJECT(src, "LEAVED - ret %d", ret);
return TRUE;
}
src->last_frame_no = -1;
+#ifdef WAYLANDSRC_BUFFER_DUMP
+ dump_cnt = 0;
+ remove(WAYLANDSRC_DUMP_FILE);
+#endif
+
return TRUE;
}