+
+ return GST_FLOW_OK;
+}
+
+static gboolean
+gst_video_crop_decide_allocation (GstBaseTransform * trans, GstQuery * query)
+{
+ GstVideoCrop *crop = GST_VIDEO_CROP (trans);
+ gboolean use_crop_meta;
+
+ use_crop_meta = (gst_query_find_allocation_meta (query,
+ GST_VIDEO_CROP_META_API_TYPE, NULL) &&
+ gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL));
+
+ if ((crop->crop_left | crop->crop_right | crop->crop_top | crop->
+ crop_bottom) == 0) {
+ GST_INFO_OBJECT (crop, "we are using passthrough");
+ gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), TRUE);
+ gst_base_transform_set_in_place (GST_BASE_TRANSFORM (crop), FALSE);
+ } else if (use_crop_meta) {
+ GST_INFO_OBJECT (crop, "we are doing in-place transform using crop meta");
+ gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), FALSE);
+ gst_base_transform_set_in_place (GST_BASE_TRANSFORM (crop), TRUE);
+ } else {
+ GST_INFO_OBJECT (crop, "we are not using passthrough");
+ gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (crop), FALSE);
+ gst_base_transform_set_in_place (GST_BASE_TRANSFORM (crop), FALSE);
+ }
+
+ return GST_BASE_TRANSFORM_CLASS (parent_class)->decide_allocation (trans,
+ query);
+}
+
+static gboolean
+gst_video_crop_propose_allocation (GstBaseTransform * trans,
+ GstQuery * decide_query, GstQuery * query)
+{
+ /* if we are not passthrough, we can handle video meta and crop meta */
+ if (decide_query) {
+ GST_DEBUG_OBJECT (trans, "Advertising video meta and crop meta support");
+ gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL);
+ gst_query_add_allocation_meta (query, GST_VIDEO_CROP_META_API_TYPE, NULL);
+ }
+
+ return GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
+ decide_query, query);
+}
+
+static GstFlowReturn
+gst_video_crop_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
+{
+ GstVideoCrop *vcrop = GST_VIDEO_CROP (trans);
+ GstVideoFilter *vfilter = GST_VIDEO_FILTER (trans);
+ GstVideoMeta *video_meta;
+ GstVideoCropMeta *crop_meta;
+
+ GST_LOG_OBJECT (trans, "Transforming in-place");
+
+ if (G_UNLIKELY (vcrop->need_update)) {
+ if (!gst_video_crop_set_info (vfilter, NULL, &vcrop->in_info, NULL,
+ &vcrop->out_info)) {
+ return GST_FLOW_ERROR;
+ }
+ }
+
+ /* The video meta is required since we are going to make the caps
+ * width/height smaller, which would not result in a usable GstVideoInfo for
+ * mapping the buffer. */
+ video_meta = gst_buffer_get_video_meta (buf);
+ if (!video_meta) {
+ video_meta = gst_buffer_add_video_meta (buf, GST_VIDEO_FRAME_FLAG_NONE,
+ GST_VIDEO_INFO_FORMAT (&vcrop->in_info), vcrop->in_info.width,
+ vcrop->in_info.height);
+ }
+
+ crop_meta = gst_buffer_get_video_crop_meta (buf);
+ if (!crop_meta) {
+ crop_meta = gst_buffer_add_video_crop_meta (buf);
+ crop_meta->width = vcrop->in_info.width;
+ crop_meta->height = vcrop->in_info.height;
+ }
+
+ crop_meta->x += vcrop->crop_left;
+ crop_meta->y += vcrop->crop_top;
+ crop_meta->width = GST_VIDEO_INFO_WIDTH (&vcrop->out_info);
+ crop_meta->height = GST_VIDEO_INFO_HEIGHT (&vcrop->out_info);