mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
opencvfilter: Properly port to GstVideoFilter
This is a subblass of VideoFilter but yet does not use any of it's features. This also fixes issue in case the incoming images have custom strides as the VideoMeta is no longer ignored. https://bugzilla.gnome.org/show_bug.cgi?id=775288
This commit is contained in:
parent
efbb6d2a13
commit
ed3877655d
1 changed files with 34 additions and 90 deletions
|
@ -67,51 +67,23 @@ enum
|
||||||
PROP_0
|
PROP_0
|
||||||
};
|
};
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
#define parent_class gst_opencv_video_filter_parent_class
|
||||||
|
G_DEFINE_ABSTRACT_TYPE (GstOpencvVideoFilter, gst_opencv_video_filter,
|
||||||
static void gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass *
|
GST_TYPE_VIDEO_FILTER);
|
||||||
klass);
|
|
||||||
static void gst_opencv_video_filter_init (GstOpencvVideoFilter * trans,
|
|
||||||
GstOpencvVideoFilterClass * klass);
|
|
||||||
|
|
||||||
static gboolean gst_opencv_video_filter_set_caps (GstBaseTransform * trans,
|
|
||||||
GstCaps * incaps, GstCaps * outcaps);
|
|
||||||
static GstFlowReturn gst_opencv_video_filter_transform_ip (GstBaseTransform *
|
|
||||||
trans, GstBuffer * buf);
|
|
||||||
static GstFlowReturn gst_opencv_video_filter_transform (GstBaseTransform *
|
|
||||||
trans, GstBuffer * inbuf, GstBuffer * outbuf);
|
|
||||||
|
|
||||||
static void gst_opencv_video_filter_set_property (GObject * object,
|
static void gst_opencv_video_filter_set_property (GObject * object,
|
||||||
guint prop_id, const GValue * value, GParamSpec * pspec);
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_opencv_video_filter_get_property (GObject * object,
|
static void gst_opencv_video_filter_get_property (GObject * object,
|
||||||
guint prop_id, GValue * value, GParamSpec * pspec);
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
||||||
|
|
||||||
GType
|
static GstFlowReturn gst_opencv_video_filter_transform_frame (GstVideoFilter * trans,
|
||||||
gst_opencv_video_filter_get_type (void)
|
GstVideoFrame * inframe, GstVideoFrame * outframe);
|
||||||
{
|
static GstFlowReturn gst_opencv_video_filter_transform_frame_ip (GstVideoFilter * trans,
|
||||||
static volatile gsize opencv_base_transform_type = 0;
|
GstVideoFrame * frame);
|
||||||
|
|
||||||
if (g_once_init_enter (&opencv_base_transform_type)) {
|
static gboolean gst_opencv_video_filter_set_info (GstVideoFilter * trans,
|
||||||
GType _type;
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
||||||
static const GTypeInfo opencv_base_transform_info = {
|
GstVideoInfo * out_info);
|
||||||
sizeof (GstOpencvVideoFilterClass),
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
(GClassInitFunc) gst_opencv_video_filter_class_init,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
sizeof (GstOpencvVideoFilter),
|
|
||||||
0,
|
|
||||||
(GInstanceInitFunc) gst_opencv_video_filter_init,
|
|
||||||
};
|
|
||||||
|
|
||||||
_type = g_type_register_static (GST_TYPE_VIDEO_FILTER,
|
|
||||||
"GstOpencvVideoFilter", &opencv_base_transform_info,
|
|
||||||
G_TYPE_FLAG_ABSTRACT);
|
|
||||||
g_once_init_leave (&opencv_base_transform_type, _type);
|
|
||||||
}
|
|
||||||
return opencv_base_transform_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
static void
|
static void
|
||||||
|
@ -131,11 +103,10 @@ static void
|
||||||
gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass * klass)
|
gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstBaseTransformClass *basetrans_class;
|
GstVideoFilterClass *vfilter_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
basetrans_class = (GstBaseTransformClass *) klass;
|
vfilter_class = (GstVideoFilterClass *) klass;
|
||||||
parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_opencv_video_filter_debug,
|
GST_DEBUG_CATEGORY_INIT (gst_opencv_video_filter_debug,
|
||||||
"opencvbasetransform", 0, "opencvbasetransform element");
|
"opencvbasetransform", 0, "opencvbasetransform element");
|
||||||
|
@ -145,25 +116,22 @@ gst_opencv_video_filter_class_init (GstOpencvVideoFilterClass * klass)
|
||||||
gobject_class->set_property = gst_opencv_video_filter_set_property;
|
gobject_class->set_property = gst_opencv_video_filter_set_property;
|
||||||
gobject_class->get_property = gst_opencv_video_filter_get_property;
|
gobject_class->get_property = gst_opencv_video_filter_get_property;
|
||||||
|
|
||||||
basetrans_class->transform = gst_opencv_video_filter_transform;
|
vfilter_class->transform_frame = gst_opencv_video_filter_transform_frame;
|
||||||
basetrans_class->transform_ip = gst_opencv_video_filter_transform_ip;
|
vfilter_class->transform_frame_ip = gst_opencv_video_filter_transform_frame_ip;
|
||||||
basetrans_class->set_caps = gst_opencv_video_filter_set_caps;
|
vfilter_class->set_info = gst_opencv_video_filter_set_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_opencv_video_filter_init (GstOpencvVideoFilter * transform,
|
gst_opencv_video_filter_init (GstOpencvVideoFilter * transform)
|
||||||
GstOpencvVideoFilterClass * klass)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_opencv_video_filter_transform (GstBaseTransform * trans,
|
gst_opencv_video_filter_transform_frame (GstVideoFilter *trans,
|
||||||
GstBuffer * inbuf, GstBuffer * outbuf)
|
GstVideoFrame *inframe, GstVideoFrame *outframe)
|
||||||
{
|
{
|
||||||
GstOpencvVideoFilter *transform;
|
GstOpencvVideoFilter *transform;
|
||||||
GstOpencvVideoFilterClass *fclass;
|
GstOpencvVideoFilterClass *fclass;
|
||||||
GstMapInfo in_info;
|
|
||||||
GstMapInfo out_info;
|
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
|
|
||||||
transform = GST_OPENCV_VIDEO_FILTER (trans);
|
transform = GST_OPENCV_VIDEO_FILTER (trans);
|
||||||
|
@ -173,42 +141,26 @@ gst_opencv_video_filter_transform (GstBaseTransform * trans,
|
||||||
g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
|
g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
|
||||||
g_return_val_if_fail (transform->out_cvImage != NULL, GST_FLOW_ERROR);
|
g_return_val_if_fail (transform->out_cvImage != NULL, GST_FLOW_ERROR);
|
||||||
|
|
||||||
if (!gst_buffer_map (inbuf, &in_info, GST_MAP_READ))
|
transform->cvImage->imageData = (char *) inframe->data[0];
|
||||||
goto inbuf_map_failed;
|
transform->cvImage->imageSize = inframe->info.size;
|
||||||
|
transform->cvImage->widthStep = inframe->info.stride[0];
|
||||||
|
|
||||||
if (!gst_buffer_map (outbuf, &out_info, GST_MAP_WRITE))
|
transform->out_cvImage->imageData = (char *) outframe->data[0];
|
||||||
goto outbuf_map_failed;
|
transform->out_cvImage->imageSize = outframe->info.size;
|
||||||
|
transform->out_cvImage->widthStep = outframe->info.stride[0];
|
||||||
|
|
||||||
transform->cvImage->imageData = (char *) in_info.data;
|
ret = fclass->cv_trans_func (transform, inframe->buffer, transform->cvImage,
|
||||||
transform->out_cvImage->imageData = (char *) out_info.data;
|
outframe->buffer, transform->out_cvImage);
|
||||||
|
|
||||||
ret = fclass->cv_trans_func (transform, inbuf, transform->cvImage, outbuf,
|
|
||||||
transform->out_cvImage);
|
|
||||||
|
|
||||||
gst_buffer_unmap (inbuf, &in_info);
|
|
||||||
gst_buffer_unmap (outbuf, &out_info);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
inbuf_map_failed:
|
|
||||||
GST_ELEMENT_ERROR (transform, RESOURCE, READ,
|
|
||||||
("Failed to map buffer for reading"), (NULL));
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
|
|
||||||
outbuf_map_failed:
|
|
||||||
GST_ELEMENT_ERROR (transform, RESOURCE, WRITE,
|
|
||||||
("Failed to map buffer for writing"), (NULL));
|
|
||||||
gst_buffer_unmap (inbuf, &in_info);
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_opencv_video_filter_transform_ip (GstBaseTransform * trans,
|
gst_opencv_video_filter_transform_frame_ip (GstVideoFilter * trans,
|
||||||
GstBuffer * buffer)
|
GstVideoFrame * frame)
|
||||||
{
|
{
|
||||||
GstOpencvVideoFilter *transform;
|
GstOpencvVideoFilter *transform;
|
||||||
GstOpencvVideoFilterClass *fclass;
|
GstOpencvVideoFilterClass *fclass;
|
||||||
GstMapInfo info;
|
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
|
|
||||||
transform = GST_OPENCV_VIDEO_FILTER (trans);
|
transform = GST_OPENCV_VIDEO_FILTER (trans);
|
||||||
|
@ -217,26 +169,18 @@ gst_opencv_video_filter_transform_ip (GstBaseTransform * trans,
|
||||||
g_return_val_if_fail (fclass->cv_trans_ip_func != NULL, GST_FLOW_ERROR);
|
g_return_val_if_fail (fclass->cv_trans_ip_func != NULL, GST_FLOW_ERROR);
|
||||||
g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
|
g_return_val_if_fail (transform->cvImage != NULL, GST_FLOW_ERROR);
|
||||||
|
|
||||||
if (!gst_buffer_map (buffer, &info, (GstMapFlags) (GST_MAP_READWRITE)))
|
transform->cvImage->imageData = (char *) frame->data[0];
|
||||||
goto map_failed;
|
transform->cvImage->imageSize = frame->info.size;
|
||||||
|
transform->cvImage->widthStep = frame->info.stride[0];
|
||||||
|
|
||||||
transform->cvImage->imageData = (char *) info.data;
|
ret = fclass->cv_trans_ip_func (transform, frame->buffer, transform->cvImage);
|
||||||
|
|
||||||
ret = fclass->cv_trans_ip_func (transform, buffer, transform->cvImage);
|
|
||||||
|
|
||||||
gst_buffer_unmap (buffer, &info);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
map_failed:
|
|
||||||
GST_ELEMENT_ERROR (transform, RESOURCE, WRITE,
|
|
||||||
("Failed to map buffer for reading and writing"), (NULL));
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_opencv_video_filter_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
gst_opencv_video_filter_set_info (GstVideoFilter * trans, GstCaps * incaps,
|
||||||
GstCaps * outcaps)
|
GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
|
||||||
{
|
{
|
||||||
GstOpencvVideoFilter *transform = GST_OPENCV_VIDEO_FILTER (trans);
|
GstOpencvVideoFilter *transform = GST_OPENCV_VIDEO_FILTER (trans);
|
||||||
GstOpencvVideoFilterClass *klass =
|
GstOpencvVideoFilterClass *klass =
|
||||||
|
|
Loading…
Reference in a new issue