static gboolean gst_shape_wipe_mask_sink_setcaps (GstShapeWipe * self, GstCaps * caps) { gboolean ret = TRUE; gint width, height, bpp; GstVideoInfo info; GST_DEBUG_OBJECT (self, "Setting caps: %" GST_PTR_FORMAT, caps); if (!gst_video_info_from_caps (&info, caps)) { ret = FALSE; goto done; } width = GST_VIDEO_INFO_WIDTH (&info); height = GST_VIDEO_INFO_HEIGHT (&info); bpp = GST_VIDEO_INFO_COMP_DEPTH (&info, 0); if ((self->vinfo.width != width || self->vinfo.height != height) && self->vinfo.width > 0 && self->vinfo.height > 0) { GST_ERROR_OBJECT (self, "Mask caps must have the same width/height " "as the video caps"); ret = FALSE; goto done; } self->mask_bpp = bpp; self->minfo = info; done: return ret; }
gboolean gst_niimaqsrc_set_caps (GstBaseSrc * bsrc, GstCaps * caps) { GstNiImaqSrc *src = GST_NIIMAQSRC (bsrc); gboolean res = TRUE; int depth, ncomps; GstVideoInfo vinfo; res = gst_video_info_from_caps (&vinfo, caps); if (!res) { GST_WARNING_OBJECT (src, "Unable to parse video info from caps"); return res; } src->format = GST_VIDEO_INFO_FORMAT (&vinfo); src->width = GST_VIDEO_INFO_WIDTH (&vinfo); src->height = GST_VIDEO_INFO_HEIGHT (&vinfo); /* this will handle byte alignment (i.e. row multiple of 4 bytes) */ src->framesize = GST_VIDEO_INFO_SIZE (&vinfo); gst_base_src_set_blocksize (bsrc, src->framesize); ncomps = GST_VIDEO_INFO_N_COMPONENTS (&vinfo); depth = GST_VIDEO_INFO_COMP_DEPTH (&vinfo, 0); /* use this so NI can give us proper byte alignment */ src->rowpixels = GST_VIDEO_INFO_COMP_STRIDE (&vinfo, 0) / (ncomps * depth / 8); GST_LOG_OBJECT (src, "Caps set, framesize=%d, rowpixels=%d", src->framesize, src->rowpixels); return res; }
gboolean gst_edt_pdv_sink_set_caps (GstBaseSink * basesink, GstCaps * caps) { GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); int buffer_size; gint depth; int taps; GstVideoInfo vinfo; GST_DEBUG_OBJECT (pdvsink, "Caps being set"); gst_video_info_from_caps (&vinfo, caps); depth = GST_VIDEO_INFO_COMP_DEPTH (&vinfo, 0); buffer_size = vinfo.height * pdv_bytes_per_line (vinfo.width, depth); GST_DEBUG_OBJECT (pdvsink, "Configuring EDT ring buffer with %d buffers each of size %d", pdvsink->n_buffers, buffer_size); /* we'll use just two buffers and ping pong between them */ edt_configure_ring_buffers (pdvsink->dev, buffer_size, pdvsink->n_buffers, EDT_WRITE, NULL); pdvsink->buffers = edt_buffer_addresses (pdvsink->dev); taps = pdvsink->dev->dd_p->cls.taps; /* TODO: handle RGB correctly */ if (depth == 24) { taps = 1; depth = 32; } if (taps == 0) { GST_WARNING_OBJECT (pdvsink, "Taps set to 0, changing to 1"); taps = 1; } GST_DEBUG_OBJECT (pdvsink, "Configuring simulator with %d taps", taps); /* configure simulator */ pdv_cls_set_size (pdvsink->dev, taps, depth, vinfo.width, vinfo.height, PDV_CLS_DEFAULT_HGAP, (vinfo.width / taps) + PDV_CLS_DEFAULT_HGAP, // taps=1 PDV_CLS_DEFAULT_VGAP, vinfo.height + PDV_CLS_DEFAULT_VGAP); GST_DEBUG ("Configured simulator"); return TRUE; }
gboolean gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width, gint * height, gint * ipldepth, gint * channels, GError ** err) { GstVideoInfo info; gint i, depth = 0; if (!gst_video_info_from_caps (&info, caps)) { GST_ERROR ("Failed to get the videoinfo from caps"); g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION, "No width/heighti/depth/channels in caps"); return FALSE; } *width = GST_VIDEO_INFO_WIDTH (&info); *height = GST_VIDEO_INFO_HEIGHT (&info); if (GST_VIDEO_INFO_IS_RGB (&info)) *channels = 3; else if (GST_VIDEO_INFO_IS_GRAY (&info)) *channels = 1; else { g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION, "Unsupported caps %s", gst_caps_to_string(caps)); return FALSE; } for (i = 0; i < GST_VIDEO_INFO_N_COMPONENTS (&info); i++) depth += GST_VIDEO_INFO_COMP_DEPTH (&info, i); if (depth / *channels == 8) { /* TODO signdness? */ *ipldepth = IPL_DEPTH_8U; } else if (depth / *channels == 16) { *ipldepth = IPL_DEPTH_16U; } else { g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION, "Unsupported depth/channels %d/%d", depth, *channels); return FALSE; } return TRUE; }
static gdouble gst_compare_ssim (GstCompare * comp, GstBuffer * buf1, GstCaps * caps1, GstBuffer * buf2, GstCaps * caps2) { GstVideoInfo info1, info2; GstVideoFrame frame1, frame2; gint i, comps; gdouble cssim[4], ssim, c[4] = { 1.0, 0.0, 0.0, 0.0 }; if (!caps1) goto invalid_input; if (!gst_video_info_from_caps (&info1, caps1)) goto invalid_input; if (!caps2) goto invalid_input; if (!gst_video_info_from_caps (&info2, caps1)) goto invalid_input; if (GST_VIDEO_INFO_FORMAT (&info1) != GST_VIDEO_INFO_FORMAT (&info2) || GST_VIDEO_INFO_WIDTH (&info1) != GST_VIDEO_INFO_WIDTH (&info2) || GST_VIDEO_INFO_HEIGHT (&info1) != GST_VIDEO_INFO_HEIGHT (&info2)) return comp->threshold + 1; comps = GST_VIDEO_INFO_N_COMPONENTS (&info1); /* note that some are reported both yuv and gray */ for (i = 0; i < comps; ++i) c[i] = 1.0; /* increase luma weight if yuv */ if (GST_VIDEO_INFO_IS_YUV (&info1) && (comps > 1)) c[0] = comps - 1; for (i = 0; i < comps; ++i) c[i] /= (GST_VIDEO_INFO_IS_YUV (&info1) && (comps > 1)) ? 2 * (comps - 1) : comps; gst_video_frame_map (&frame1, &info1, buf1, GST_MAP_READ); gst_video_frame_map (&frame2, &info2, buf2, GST_MAP_READ); for (i = 0; i < comps; i++) { gint cw, ch, step, stride; /* only support most common formats */ if (GST_VIDEO_INFO_COMP_DEPTH (&info1, i) != 8) goto unsupported_input; cw = GST_VIDEO_FRAME_COMP_WIDTH (&frame1, i); ch = GST_VIDEO_FRAME_COMP_HEIGHT (&frame1, i); step = GST_VIDEO_FRAME_COMP_PSTRIDE (&frame1, i); stride = GST_VIDEO_FRAME_COMP_STRIDE (&frame1, i); GST_LOG_OBJECT (comp, "component %d", i); cssim[i] = gst_compare_ssim_component (comp, GST_VIDEO_FRAME_COMP_DATA (&frame1, i), GST_VIDEO_FRAME_COMP_DATA (&frame2, i), cw, ch, step, stride); GST_LOG_OBJECT (comp, "ssim[%d] = %f", i, cssim[i]); } gst_video_frame_unmap (&frame1); gst_video_frame_unmap (&frame2); #ifndef GST_DISABLE_GST_DEBUG for (i = 0; i < 4; i++) { GST_DEBUG_OBJECT (comp, "ssim[%d] = %f, c[%d] = %f", i, cssim[i], i, c[i]); } #endif ssim = cssim[0] * c[0] + cssim[1] * c[1] + cssim[2] * c[2] + cssim[3] * c[3]; return ssim; /* ERRORS */ invalid_input: { GST_ERROR_OBJECT (comp, "ssim method needs raw video input"); return 0; } unsupported_input: { GST_ERROR_OBJECT (comp, "raw video format not supported %" GST_PTR_FORMAT, caps1); return 0; } }