Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vspfilter: implement hflip and vflip #2

Open
wants to merge 1 commit into
base: RCAR-GEN3/1.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions gst/vspfilter/gstvspfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ enum
PROP_VSP_DEVFILE_OUTPUT,
PROP_INPUT_IO_MODE,
PROP_OUTPUT_IO_MODE,
PROP_VFLIP,
PROP_HFLIP,
};

#define CSP_VIDEO_CAPS \
Expand Down Expand Up @@ -155,6 +157,7 @@ gst_vsp_filter_is_caps_format_supported_for_vsp (GstVspFilter * space,
GstVideoFormat in_fmt, out_fmt;
guint in_v4l2pix, out_v4l2pix;
struct v4l2_format v4l2fmt;
struct v4l2_control ctrl;
gint ret;

vsp_info = space->vsp_info;
Expand Down Expand Up @@ -230,6 +233,46 @@ gst_vsp_filter_is_caps_format_supported_for_vsp (GstVspFilter * space,
return FALSE;
}

if (space->vflip) {
ctrl.id = V4L2_CID_VFLIP;
ctrl.value = 1;
ret = xioctl(vsp_info->v4lsub_fd[CAP], VIDIOC_S_CTRL, &ctrl);
if (ret < 0) {
GST_ERROR_OBJECT (space,
"VIDIOC_S_CTRL failed. could not set vflip");
return FALSE;
}
} else { /* reset the flip value back to original, if not set*/
ctrl.id = V4L2_CID_VFLIP;
ctrl.value = 0;
ret = xioctl(vsp_info->v4lsub_fd[CAP], VIDIOC_S_CTRL, &ctrl);
if (ret < 0) {
GST_ERROR_OBJECT (space,
"VIDIOC_S_CTRL failed. could not re-set vflip");
return FALSE;
}
}

if (space->hflip) {
ctrl.id = V4L2_CID_HFLIP;
ctrl.value = 1;
ret = xioctl(vsp_info->v4lsub_fd[CAP], VIDIOC_S_CTRL, &ctrl);
if (ret < 0) {
GST_ERROR_OBJECT (space,
"VIDIOC_S_CTRL failed. could not set hflip");
return FALSE;
}
} else {
ctrl.id = V4L2_CID_HFLIP;
ctrl.value = 0;
ret = xioctl(vsp_info->v4lsub_fd[CAP], VIDIOC_S_CTRL, &ctrl);
if (ret < 0) {
GST_ERROR_OBJECT (space,
"VIDIOC_S_CTRL failed. could not re-set hflip");
return FALSE;
}
}

return TRUE;
}

Expand Down Expand Up @@ -600,6 +643,7 @@ init_entity_pad (GstVspFilter * space, gint fd, gint index, guint pad,
sfmt.format.field = V4L2_FIELD_NONE;
sfmt.format.colorspace = V4L2_COLORSPACE_SRGB;


if (-1 == xioctl (fd, VIDIOC_SUBDEV_S_FMT, &sfmt)) {
GST_ERROR_OBJECT (space, "VIDIOC_SUBDEV_S_FMT for %s failed.",
space->vsp_info->entity_name[index]);
Expand Down Expand Up @@ -1667,6 +1711,16 @@ gst_vsp_filter_class_init (GstVspFilterClass * klass)
GST_TYPE_VSPFILTER_IO_MODE, DEFAULT_PROP_IO_MODE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

g_object_class_install_property (gobject_class, PROP_VFLIP,
g_param_spec_boolean("vflip", "vflip",
"Perform vertical flip (around X axis)",
DEFAULT_VFLIP, G_PARAM_READWRITE));

g_object_class_install_property (gobject_class, PROP_HFLIP,
g_param_spec_boolean("hflip", "hflip",
"Perform horizontal flip (around Y axis)",
DEFAULT_HFLIP, G_PARAM_READWRITE));

gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_vsp_filter_src_template));
gst_element_class_add_pad_template (gstelement_class,
Expand Down Expand Up @@ -1751,6 +1805,12 @@ gst_vsp_filter_set_property (GObject * object, guint property_id,
case PROP_OUTPUT_IO_MODE:
space->prop_out_mode = g_value_get_enum (value);
break;
case PROP_VFLIP:
space->vflip = g_value_get_boolean(value);
break;
case PROP_HFLIP:
space->hflip = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down Expand Up @@ -1780,6 +1840,12 @@ gst_vsp_filter_get_property (GObject * object, guint property_id,
case PROP_OUTPUT_IO_MODE:
g_value_set_enum (value, space->prop_out_mode);
break;
case PROP_VFLIP:
g_value_set_boolean(value, space->vflip);
break;
case PROP_HFLIP:
g_value_set_boolean(value, space->hflip);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
Expand Down
5 changes: 5 additions & 0 deletions gst/vspfilter/gstvspfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ G_BEGIN_DECLS
#define DEFAULT_PROP_VSP_DEVFILE_INPUT "/dev/video0"
#define DEFAULT_PROP_VSP_DEVFILE_OUTPUT "/dev/video1"

#define DEFAULT_VFLIP FALSE
#define DEFAULT_HFLIP FALSE

typedef enum {
GST_VSPFILTER_IO_AUTO = 0, /* dmabuf or mmap */
GST_VSPFILTER_IO_USERPTR,
Expand Down Expand Up @@ -131,6 +134,8 @@ struct _GstVspFilter {
GstBufferPool *out_pool;
GstVspfilterIOMode prop_in_mode;
GstVspfilterIOMode prop_out_mode;
gboolean vflip;
gboolean hflip;
};

struct _GstVspFilterClass
Expand Down