- /* video stream callback */
- if (hcamcorder->vstream_cb && buffer) {
- int state = MM_CAMCORDER_STATE_NULL;
- int num_bos = 0;
- unsigned int fourcc = 0;
- const gchar *string_format = NULL;
-
- MMCamcorderVideoStreamDataType stream;
- tbm_surface_h t_surface = NULL;
- tbm_surface_info_s t_info;
-
- GstCaps *caps = NULL;
- GstStructure *structure = NULL;
- GstMemory *memory = NULL;
- GstMapInfo mapinfo;
-
- state = _mmcamcorder_get_state((MMHandleType)hcamcorder);
- if (state < MM_CAMCORDER_STATE_PREPARE) {
- _mmcam_dbg_warn("Not ready for stream callback");
- return GST_PAD_PROBE_OK;
- }
-
- caps = gst_pad_get_current_caps(pad);
- if (caps == NULL) {
- _mmcam_dbg_warn("Caps is NULL.");
- return GST_PAD_PROBE_OK;
- }
-
- /* clear data structure */
- memset(&mapinfo, 0x0, sizeof(GstMapInfo));
- memset(&stream, 0x0, sizeof(MMCamcorderVideoStreamDataType));
-
- structure = gst_caps_get_structure(caps, 0);
- gst_structure_get_int(structure, "width", &(stream.width));
- gst_structure_get_int(structure, "height", &(stream.height));
-
- if (sc->info_image->preview_format == MM_PIXEL_FORMAT_ENCODED_H264) {
- stream.format = MM_PIXEL_FORMAT_ENCODED_H264;
- } else {
- string_format = gst_structure_get_string(structure, "format");
- if (string_format == NULL) {
- gst_caps_unref(caps);
- caps = NULL;
- _mmcam_dbg_warn("get string error!!");
- return GST_PAD_PROBE_OK;
- }
-
- fourcc = _mmcamcorder_convert_fourcc_string_to_value(string_format);
- stream.format = _mmcamcorder_get_pixtype(fourcc);
- }
-
- gst_caps_unref(caps);
- caps = NULL;
-
- /*
- _mmcam_dbg_log("Call video steramCb, data[%p], Width[%d],Height[%d], Format[%d]",
- GST_BUFFER_DATA(buffer), stream.width, stream.height, stream.format);
- */
-
- if (stream.width == 0 || stream.height == 0) {
- _mmcam_dbg_warn("Wrong condition!!");
- return GST_PAD_PROBE_OK;
- }
-
- /* set size and timestamp */
- memory = gst_buffer_peek_memory(buffer, 0);
- if (!memory) {
- _mmcam_dbg_err("GstMemory get failed from buffer %p", buffer);
- return GST_PAD_PROBE_OK;
- }
-
- if (hcamcorder->use_zero_copy_format) {
- t_surface = (tbm_surface_h)gst_tizen_memory_get_surface(memory);
-
- if (tbm_surface_get_info(t_surface, &t_info) != TBM_SURFACE_ERROR_NONE) {
- _mmcam_dbg_err("failed to get tbm surface[%p] info", t_surface);
- return GST_PAD_PROBE_OK;
- }
-
- stream.length_total = t_info.size;
-
- /* set bo, stride and elevation */
- num_bos = gst_tizen_memory_get_num_bos(memory);
- for (i = 0 ; i < num_bos ; i++)
- stream.bo[i] = gst_tizen_memory_get_bos(memory, i);
-
- for (i = 0 ; i < t_info.num_planes ; i++) {
- stream.stride[i] = t_info.planes[i].stride;
- stream.elevation[i] = t_info.planes[i].size / t_info.planes[i].stride;
- /*_mmcam_dbg_log("[%d] %dx%d", i, stream.stride[i], stream.elevation[i]);*/
- }
-
- /* set gst buffer */
- stream.internal_buffer = buffer;
- } else {
- stream.length_total = gst_memory_get_sizes(memory, NULL, NULL);
- }
-
- stream.timestamp = (unsigned int)(GST_BUFFER_PTS(buffer)/1000000); /* nano sec -> mili sec */
-
- /* set data pointers */
- if (stream.format == MM_PIXEL_FORMAT_NV12 ||
- stream.format == MM_PIXEL_FORMAT_NV21 ||
- stream.format == MM_PIXEL_FORMAT_I420) {
- if (hcamcorder->use_zero_copy_format) {
- if (stream.format == MM_PIXEL_FORMAT_NV12 ||
- stream.format == MM_PIXEL_FORMAT_NV21) {
- stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
- stream.num_planes = 2;
- stream.data.yuv420sp.y = t_info.planes[0].ptr;
- stream.data.yuv420sp.length_y = t_info.planes[0].size;
- stream.data.yuv420sp.uv = t_info.planes[1].ptr;
- stream.data.yuv420sp.length_uv = t_info.planes[1].size;
- /*
- _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
- stream.format, stream.num_planes,
- stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
- stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
- */
- } else {
- stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
- stream.num_planes = 3;
- stream.data.yuv420p.y = t_info.planes[0].ptr;
- stream.data.yuv420p.length_y = t_info.planes[0].size;
- stream.data.yuv420p.u = t_info.planes[1].ptr;
- stream.data.yuv420p.length_u = t_info.planes[1].size;
- stream.data.yuv420p.v = t_info.planes[2].ptr;
- stream.data.yuv420p.length_v = t_info.planes[2].size;
- /*
- _mmcam_dbg_log("S420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
- stream.num_planes,
- stream.data.yuv420p.y, stream.data.yuv420p.length_y,
- stream.data.yuv420p.u, stream.data.yuv420p.length_u,
- stream.data.yuv420p.v, stream.data.yuv420p.length_v);
- */
- }
- } else {
- gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
- if (stream.format == MM_PIXEL_FORMAT_NV12 ||
- stream.format == MM_PIXEL_FORMAT_NV21) {
- stream.data_type = MM_CAM_STREAM_DATA_YUV420SP;
- stream.num_planes = 2;
- stream.data.yuv420sp.y = mapinfo.data;
- stream.data.yuv420sp.length_y = stream.width * stream.height;
- stream.data.yuv420sp.uv = stream.data.yuv420sp.y + stream.data.yuv420sp.length_y;
- stream.data.yuv420sp.length_uv = stream.data.yuv420sp.length_y >> 1;
- stream.stride[0] = stream.width;
- stream.elevation[0] = stream.height;
- stream.stride[1] = stream.width;
- stream.elevation[1] = stream.height >> 1;
- /*
- _mmcam_dbg_log("format[%d][num_planes:%d] [Y]p:%p,size:%d [UV]p:%p,size:%d",
- stream.format, stream.num_planes,
- stream.data.yuv420sp.y, stream.data.yuv420sp.length_y,
- stream.data.yuv420sp.uv, stream.data.yuv420sp.length_uv);
- */
- } else {
- stream.data_type = MM_CAM_STREAM_DATA_YUV420P;
- stream.num_planes = 3;
- stream.data.yuv420p.y = mapinfo.data;
- stream.data.yuv420p.length_y = stream.width * stream.height;
- stream.data.yuv420p.u = stream.data.yuv420p.y + stream.data.yuv420p.length_y;
- stream.data.yuv420p.length_u = stream.data.yuv420p.length_y >> 2;
- stream.data.yuv420p.v = stream.data.yuv420p.u + stream.data.yuv420p.length_u;
- stream.data.yuv420p.length_v = stream.data.yuv420p.length_u;
- stream.stride[0] = stream.width;
- stream.elevation[0] = stream.height;
- stream.stride[1] = stream.width >> 1;
- stream.elevation[1] = stream.height >> 1;
- stream.stride[2] = stream.width >> 1;
- stream.elevation[2] = stream.height >> 1;
- /*
- _mmcam_dbg_log("I420[num_planes:%d] [Y]p:%p,size:%d [U]p:%p,size:%d [V]p:%p,size:%d",
- stream.num_planes,
- stream.data.yuv420p.y, stream.data.yuv420p.length_y,
- stream.data.yuv420p.u, stream.data.yuv420p.length_u,
- stream.data.yuv420p.v, stream.data.yuv420p.length_v);
- */
- }
- }
- } else {
- gst_memory_map(memory, &mapinfo, GST_MAP_READWRITE);
-
- switch (stream.format) {
- case MM_PIXEL_FORMAT_YUYV:
- case MM_PIXEL_FORMAT_UYVY:
- case MM_PIXEL_FORMAT_422P:
- case MM_PIXEL_FORMAT_ITLV_JPEG_UYVY:
- stream.data_type = MM_CAM_STREAM_DATA_YUV422;
- stream.data.yuv422.yuv = mapinfo.data;
- stream.data.yuv422.length_yuv = stream.length_total;
- stream.stride[0] = stream.width << 1;
- stream.elevation[0] = stream.height;
- break;
- case MM_PIXEL_FORMAT_ENCODED_H264:
- stream.data_type = MM_CAM_STREAM_DATA_ENCODED;
- stream.data.encoded.data = mapinfo.data;
- stream.data.encoded.length_data = stream.length_total;
- /*
- _mmcam_dbg_log("H264[num_planes:%d] [0]p:%p,size:%d",
- stream.num_planes, stream.data.encoded.data, stream.data.encoded.length_data);
- */
- break;
- case MM_PIXEL_FORMAT_INVZ:
- stream.data_type = MM_CAM_STREAM_DATA_DEPTH;
- stream.data.depth.data = mapinfo.data;
- stream.data.depth.length_data = stream.length_total;
- stream.stride[0] = stream.width << 1;
- stream.elevation[0] = stream.height;
- break;
- case MM_PIXEL_FORMAT_RGBA:
- case MM_PIXEL_FORMAT_ARGB:
- stream.data_type = MM_CAM_STREAM_DATA_RGB;
- stream.data.rgb.data = mapinfo.data;
- stream.data.rgb.length_data = stream.length_total;
- stream.stride[0] = stream.width << 2;
- stream.elevation[0] = stream.height;
- break;
- default:
- stream.data_type = MM_CAM_STREAM_DATA_YUV420;
- stream.data.yuv420.yuv = mapinfo.data;
- stream.data.yuv420.length_yuv = stream.length_total;
- stream.stride[0] = (stream.width * 3) >> 1;
- stream.elevation[0] = stream.height;
- break;
- }
-
- stream.num_planes = 1;
- /*
- _mmcam_dbg_log("%c%c%c%c[num_planes:%d] [0]p:%p,size:%d",
- fourcc, fourcc>>8, fourcc>>16, fourcc>>24,
- stream.num_planes, stream.data.yuv420.yuv, stream.data.yuv420.length_yuv);
- */
- }
-
- /* call application callback */
- _MMCAMCORDER_LOCK_VSTREAM_CALLBACK(hcamcorder);
- if (hcamcorder->vstream_cb) {
- hcamcorder->vstream_cb(&stream, hcamcorder->vstream_cb_param);
-
- for (i = 0 ; i < TBM_SURF_PLANE_MAX && stream.bo[i] ; i++) {
- tbm_bo_map(stream.bo[i], TBM_DEVICE_CPU, TBM_OPTION_READ|TBM_OPTION_WRITE);
- tbm_bo_unmap(stream.bo[i]);
- }
- }
-
- _MMCAMCORDER_UNLOCK_VSTREAM_CALLBACK(hcamcorder);
-
- /* unmap memory */
- if (mapinfo.data)
- gst_memory_unmap(memory, &mapinfo);