- memset(&player->capture, 0x00, sizeof(MMPlayerVideoCapture));
-
- gst_structure_get_int(structure, "width", &src_width);
- gst_structure_get_int(structure, "height", &src_height);
-
- GstVideoInfo video_info;
- gst_video_info_from_caps(&video_info, caps);
-
- /* check rgb or yuv */
- if (gst_structure_has_name(structure, "video/x-raw")) {
- /* NV12T */
- const gchar *gst_format = gst_structure_get_string(structure, "format");
-
- if (!g_strcmp0(gst_format, "ST12"))
- player->video_cs = MM_PLAYER_COLORSPACE_NV12_TILED;
- else if (!g_strcmp0(gst_format, "S420"))
- player->video_cs = MM_PLAYER_COLORSPACE_I420;
- else if (!g_strcmp0(gst_format, "SN12"))
- player->video_cs = MM_PLAYER_COLORSPACE_NV12;
- else if (!g_strcmp0(gst_format, "BGRx"))
- player->video_cs = MM_PLAYER_COLORSPACE_BGRx;
- else
- player->video_cs = MM_PLAYER_COLORSPACE_MAX;
-
- LOGI("captured format is %s\n", gst_format);
-
- if (!g_strcmp0(gst_format, "ST12") || !g_strcmp0(gst_format, "SN12")
- || !g_strcmp0(gst_format, "S420")) {
- GstVideoFrame vframe;
- GstVideoFormat format;
- const GstVideoFormatInfo *finfo;
-
- /* get video frame info from proved buffer */
- format = gst_video_format_from_string(gst_format);
- finfo = gst_video_format_get_info(format);
-
- if (gst_video_frame_map(&vframe, &video_info, buffer, GST_MAP_READ)) {
- for (i = 0; i < GST_VIDEO_FORMAT_INFO_N_PLANES(finfo); i++) {
- player->captured.width[i] = GST_VIDEO_FRAME_PLANE_STRIDE(&vframe, i);
- player->captured.height[i] = GST_VIDEO_FRAME_COMP_HEIGHT(&vframe, i);
- player->captured.stride_width[i] = GST_VIDEO_FRAME_PLANE_STRIDE(&vframe, i);
- player->captured.stride_height[i] = GST_VIDEO_FRAME_COMP_HEIGHT(&vframe, i);
- size = player->captured.stride_width[i] * player->captured.stride_height[i];
- guint8 *pixels = GST_VIDEO_FRAME_PLANE_DATA(&vframe, i);
-
- player->captured.data[i] = g_try_malloc(size);
- if (!player->captured.data[i]) {
- gst_video_frame_unmap(&vframe);
- LOGE("no free space\n");
- ret = MM_ERROR_PLAYER_NO_FREE_SPACE;
- goto ERROR;
- }
- memcpy(player->captured.data[i], pixels, size);
- }
- player->captured.handle_num = GST_VIDEO_FRAME_N_PLANES(&vframe);
- gst_video_frame_unmap(&vframe);
- }
- goto DONE;
- } else {
- player->captured.width[0] = src_width;
- player->captured.height[0] = src_height;
- player->captured.stride_width[0] = MM_ALIGN(src_width, 4);
- player->captured.stride_height[0] = src_height;
- switch (GST_VIDEO_INFO_FORMAT(&video_info)) {
- case GST_VIDEO_FORMAT_I420:
- src_fmt = MM_UTIL_COLOR_I420;
- player->captured.width[1] = player->captured.width[2] = src_width>>1;
- player->captured.height[1] = player->captured.width[2] = src_height>>1;
- player->captured.stride_width[1] = player->captured.stride_width[2] = MM_ALIGN(player->captured.width[1], 4);
- player->captured.stride_height[1] = player->captured.stride_height[2] = src_height>>1;
- break;
- case GST_VIDEO_FORMAT_BGRA:
- src_fmt = MM_UTIL_COLOR_BGRA;
- break;
- case GST_VIDEO_FORMAT_BGRx:
- src_fmt = MM_UTIL_COLOR_BGRX;
- break;
- default:
- LOGE("unknown format to capture\n");
- ret = MM_ERROR_PLAYER_INTERNAL;
- goto ERROR;
- break;
- }
- player->captured.handle_num = 1;
- }
- } else {
- LOGE("unknown format to capture\n");
- ret = MM_ERROR_PLAYER_INTERNAL;
- goto ERROR;
- }