1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
From 1381c64fd606d8ab7169eef52386139a4848c439 Mon Sep 17 00:00:00 2001
From: Kiran Nataraju <knataraju@ti.com>
Date: Tue, 21 Sep 2010 06:21:23 +0200
Subject: [PATCH 03/11] v4l2sink: Add flip property.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Kiran Nataraju <knataraju@ti.com>
Signed-off-by: Daniel Díaz <yosoy@danieldiaz.org>
---
sys/v4l2/gstv4l2sink.c | 88 +++++++++++++++++++++++++++++++++++++++++++++--
sys/v4l2/gstv4l2sink.h | 1 +
2 files changed, 85 insertions(+), 4 deletions(-)
diff --git a/sys/v4l2/gstv4l2sink.c b/sys/v4l2/gstv4l2sink.c
index 5abf915..6163747 100644
--- a/sys/v4l2/gstv4l2sink.c
+++ b/sys/v4l2/gstv4l2sink.c
@@ -91,6 +91,7 @@ enum
PROP_CROP_WIDTH,
PROP_CROP_HEIGHT,
PROP_ROTATION,
+ PROP_FLIP,
};
@@ -129,6 +130,34 @@ gst_v4l2sink_iface_supported (GstImplementsInterface * iface, GType iface_type)
return TRUE;
}
+/*
+ * Flip state
+ */
+enum
+{
+ FLIP_NONE = 0,
+ FLIP_HORIZONTAL = 1,
+ FLIP_VERTICAL = 2,
+};
+
+#define GST_TYPE_V4L2_FLIP (gst_v4l2_flip_get_type ())
+static GType
+gst_v4l2_flip_get_type (void)
+{
+ static GType type = 0;
+
+ if (!type) {
+ static GEnumValue vals[] = {
+ {FLIP_NONE, "No Flip", "none"},
+ {FLIP_HORIZONTAL, "Horizontal Flip", "horiz"},
+ {FLIP_VERTICAL, "Vertical Flip", "vert"},
+ {0, NULL, NULL},
+ };
+ type = g_enum_register_static ("GstV4l2SinkFlip", vals);
+ }
+ return type;
+}
+
static void
gst_v4l2sink_interface_init (GstImplementsInterfaceClass * klass)
{
@@ -225,7 +254,7 @@ static GstFlowReturn gst_v4l2sink_buffer_alloc (GstBaseSink * bsink,
guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
static GstFlowReturn gst_v4l2sink_show_frame (GstBaseSink * bsink,
GstBuffer * buf);
-static void gst_v4l2sink_set_rotation (GstV4l2Sink * v4l2sink);
+static void gst_v4l2sink_sync_rotation (GstV4l2Sink * v4l2sink);
static void
gst_v4l2sink_base_init (gpointer g_class)
@@ -317,6 +346,11 @@ gst_v4l2sink_class_init (GstV4l2SinkClass * klass)
"Rotation angle for the image", MIN_ROTATION_ANGLE,
MAX_ROTATION_ANGLE, DEFAULT_ROTATION_ANGLE, G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_FLIP,
+ g_param_spec_enum ("flip", "Flip State",
+ "Flip horizontal/vertical",
+ GST_TYPE_V4L2_FLIP, FLIP_NONE, G_PARAM_READWRITE));
+
basesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_v4l2sink_get_caps);
basesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_v4l2sink_set_caps);
basesink_class->buffer_alloc = GST_DEBUG_FUNCPTR (gst_v4l2sink_buffer_alloc);
@@ -348,8 +382,46 @@ gst_v4l2sink_init (GstV4l2Sink * v4l2sink, GstV4l2SinkClass * klass)
v4l2sink->crop_fields_set = 0;
v4l2sink->state = 0;
v4l2sink->rotation = 0;
+ v4l2sink->flip = FLIP_NONE;
}
+static void
+gst_v4l2sink_sync_flip (GstV4l2Sink * v4l2sink)
+{
+ if (GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
+ struct v4l2_control control;
+ gint fd = v4l2sink->v4l2object->video_fd;
+
+ memset (&control, 0x00, sizeof (struct v4l2_control));
+
+ switch (v4l2sink->flip) {
+ case FLIP_VERTICAL:
+ v4l2sink->rotation = 0;
+ control.value = 1;
+ break;
+ case FLIP_HORIZONTAL:
+ /* Horizontal Flip = Vertical Flip + 180 rotation */
+ v4l2sink->rotation = 180;
+ control.value = 1;
+ break;
+ case FLIP_NONE:
+ /* In the below switch case logic we need to handle FLIP_NONE
+ * case since the v4l2 driver holds on to the last configured
+ * flip value even after the device file is closed.
+ */
+ control.value = 0;
+ break;
+ default:
+ GST_WARNING_OBJECT (v4l2sink, "Invalid flip property");
+ control.value = 0;
+ break;
+ }
+
+ gst_v4l2sink_sync_rotation (v4l2sink);
+ control.id = V4L2_CID_VFLIP;
+ g_return_if_fail (v4l2_ioctl (fd, VIDIOC_S_CTRL, &control) >= 0);
+ }
+}
static void
gst_v4l2sink_dispose (GObject * object)
@@ -488,7 +560,7 @@ gst_v4l2sink_sync_crop_fields (GstV4l2Sink * v4l2sink)
}
static void
-gst_v4l2sink_set_rotation (GstV4l2Sink * v4l2sink)
+gst_v4l2sink_sync_rotation (GstV4l2Sink * v4l2sink)
{
if (GST_V4L2_IS_OPEN (v4l2sink->v4l2object)) {
struct v4l2_control control;
@@ -559,7 +631,11 @@ gst_v4l2sink_set_property (GObject * object,
break;
case PROP_ROTATION:
v4l2sink->rotation = g_value_get_int (value);
- gst_v4l2sink_set_rotation (v4l2sink);
+ gst_v4l2sink_sync_rotation (v4l2sink);
+ break;
+ case PROP_FLIP:
+ v4l2sink->flip = g_value_get_enum (value);
+ gst_v4l2sink_sync_flip (v4l2sink);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -611,6 +687,9 @@ gst_v4l2sink_get_property (GObject * object,
case PROP_ROTATION:
g_value_set_int (value, v4l2sink->rotation);
break;
+ case PROP_FLIP:
+ g_value_set_enum (value, v4l2sink->flip);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -633,7 +712,8 @@ gst_v4l2sink_change_state (GstElement * element, GstStateChange transition)
/* open the device */
if (!gst_v4l2_object_start (v4l2sink->v4l2object))
return GST_STATE_CHANGE_FAILURE;
- gst_v4l2sink_set_rotation (v4l2sink);
+ gst_v4l2sink_sync_rotation (v4l2sink);
+ gst_v4l2sink_sync_flip (v4l2sink);
break;
default:
break;
diff --git a/sys/v4l2/gstv4l2sink.h b/sys/v4l2/gstv4l2sink.h
index 1239621..907973a 100644
--- a/sys/v4l2/gstv4l2sink.h
+++ b/sys/v4l2/gstv4l2sink.h
@@ -76,6 +76,7 @@ struct _GstV4l2Sink {
guint8 state;
gint rotation;
+ gint flip;
};
struct _GstV4l2SinkClass {
--
1.7.1
|