3 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@indt.org.br>
6 * gstv4l2object.h: base class for V4L2 elements
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_V4L2_OBJECT_H__
25 #define __GST_V4L2_OBJECT_H__
27 /* Because of some really cool feature in video4linux1, also known as
28 * 'not including sys/types.h and sys/time.h', we had to include it
29 * ourselves. In all their intelligence, these people decided to fix
30 * this in the next version (video4linux2) in such a cool way that it
31 * breaks all compilations of old stuff...
32 * The real problem is actually that linux/time.h doesn't use proper
33 * macro checks before defining types like struct timeval. The proper
34 * fix here is to either fuck the kernel header (which is what we do
35 * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it
36 * upstream, which I'll consider doing later on. If you get compiler
37 * errors here, check your linux/time.h && sys/time.h header setup.
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
42 #include <linux/types.h>
45 #include <linux/videodev2.h>
47 #include <sys/videodev2.h>
51 #include <gst/base/gstpushsrc.h>
52 #include <gst/controller/gstcontroller.h>
54 #include <gst/video/video.h>
55 #include <gst/interfaces/propertyprobe.h>
57 typedef struct _GstV4l2Object GstV4l2Object;
58 typedef struct _GstV4l2ObjectClassHelper GstV4l2ObjectClassHelper;
59 typedef struct _GstV4l2Xv GstV4l2Xv;
61 #include <gstv4l2bufferpool.h>
63 /* size of v4l2 buffer pool in streaming case */
64 #define GST_V4L2_MAX_BUFFERS 16
65 #define GST_V4L2_MIN_BUFFERS 1
67 /* max frame width/height */
68 #define GST_V4L2_MAX_SIZE (1<<15) /* 2^15 == 32768 */
72 #define GST_V4L2_OBJECT(obj) (GstV4l2Object *)(obj)
78 GST_V4L2_IO_USERPTR = 3
81 typedef gboolean (*GstV4l2GetInOutFunction) (GstV4l2Object * v4l2object, gint * input);
82 typedef gboolean (*GstV4l2SetInOutFunction) (GstV4l2Object * v4l2object, gint input);
83 typedef gboolean (*GstV4l2UpdateFpsFunction) (GstV4l2Object * v4l2object);
85 #define GST_V4L2_WIDTH(o) (GST_VIDEO_INFO_WIDTH (&(o)->info))
86 #define GST_V4L2_HEIGHT(o) (GST_VIDEO_INFO_HEIGHT (&(o)->info))
87 #define GST_V4L2_PIXELFORMAT(o) ((o)->fmtdesc->pixelformat)
88 #define GST_V4L2_FPS_N(o) (GST_VIDEO_INFO_FPS_N (&(o)->info))
89 #define GST_V4L2_FPS_D(o) (GST_VIDEO_INFO_FPS_D (&(o)->info))
91 /* simple check whether the device is open */
92 #define GST_V4L2_IS_OPEN(o) ((o)->video_fd > 0)
94 /* check whether the device is 'active' */
95 #define GST_V4L2_IS_ACTIVE(o) ((o)->active)
96 #define GST_V4L2_SET_ACTIVE(o) ((o)->active = TRUE)
97 #define GST_V4L2_SET_INACTIVE(o) ((o)->active = FALSE)
99 struct _GstV4l2Object {
100 GstElement * element;
102 enum v4l2_buf_type type; /* V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_OUTPUT */
104 /* the video device */
107 /* the video-device's file descriptor */
111 gboolean can_poll_device;
116 /* the current format */
117 struct v4l2_fmtdesc *fmtdesc;
120 guint32 bytesperline;
122 GstClockTime duration;
125 GstV4l2IOMode req_mode;
128 gboolean always_copy;
131 /* the video device's capabilities */
132 struct v4l2_capability vcap;
134 /* the video device's window properties */
135 struct v4l2_window vwin;
137 /* some more info about the current input's capabilities */
138 struct v4l2_input vinput;
141 GSList *formats; /* list of available capture formats */
157 GstV4l2GetInOutFunction get_in_out_func;
158 GstV4l2SetInOutFunction set_in_out_func;
159 GstV4l2UpdateFpsFunction update_fps_func;
162 struct _GstV4l2ObjectClassHelper {
167 GType gst_v4l2_object_get_type (void);
169 #define V4L2_STD_OBJECT_PROPS \
182 GstV4l2Object * gst_v4l2_object_new (GstElement * element,
183 enum v4l2_buf_type type,
184 const char *default_device,
185 GstV4l2GetInOutFunction get_in_out_func,
186 GstV4l2SetInOutFunction set_in_out_func,
187 GstV4l2UpdateFpsFunction update_fps_func);
188 void gst_v4l2_object_destroy (GstV4l2Object * v4l2object);
192 void gst_v4l2_object_install_properties_helper (GObjectClass *gobject_class, const char *default_device);
194 gboolean gst_v4l2_object_set_property_helper (GstV4l2Object *v4l2object,
195 guint prop_id, const GValue * value,
197 gboolean gst_v4l2_object_get_property_helper (GstV4l2Object *v4l2object,
198 guint prop_id, GValue * value,
201 gboolean gst_v4l2_object_open (GstV4l2Object *v4l2object);
202 gboolean gst_v4l2_object_close (GstV4l2Object *v4l2object);
205 const GList* gst_v4l2_probe_get_properties (GstPropertyProbe * probe);
207 void gst_v4l2_probe_probe_property (GstPropertyProbe * probe, guint prop_id,
208 const GParamSpec * pspec,
209 GList ** klass_devices);
210 gboolean gst_v4l2_probe_needs_probe (GstPropertyProbe * probe, guint prop_id,
211 const GParamSpec * pspec,
212 GList ** klass_devices);
213 GValueArray* gst_v4l2_probe_get_values (GstPropertyProbe * probe, guint prop_id,
214 const GParamSpec * pspec,
215 GList ** klass_devices);
217 GstCaps* gst_v4l2_object_probe_caps_for_format (GstV4l2Object *v4l2object, guint32 pixelformat,
218 const GstStructure * template);
220 GSList* gst_v4l2_object_get_format_list (GstV4l2Object *v4l2object);
222 GstCaps* gst_v4l2_object_get_all_caps (void);
224 GstStructure* gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);
226 gboolean gst_v4l2_object_set_format (GstV4l2Object *v4l2object, GstCaps * caps);
228 gboolean gst_v4l2_object_unlock (GstV4l2Object *v4l2object);
229 gboolean gst_v4l2_object_unlock_stop (GstV4l2Object *v4l2object);
231 gboolean gst_v4l2_object_stop (GstV4l2Object *v4l2object);
234 gboolean gst_v4l2_object_copy (GstV4l2Object * v4l2object,
235 GstBuffer * dest, GstBuffer *src);
238 #define GST_IMPLEMENT_V4L2_PROBE_METHODS(Type_Class, interface_as_function) \
241 interface_as_function ## _probe_probe_property (GstPropertyProbe * probe, \
243 const GParamSpec * pspec) \
245 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
246 gst_v4l2_probe_probe_property (probe, prop_id, pspec, \
247 &this_class->v4l2_class_devices); \
251 interface_as_function ## _probe_needs_probe (GstPropertyProbe * probe, \
253 const GParamSpec * pspec) \
255 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
256 return gst_v4l2_probe_needs_probe (probe, prop_id, pspec, \
257 &this_class->v4l2_class_devices); \
260 static GValueArray * \
261 interface_as_function ## _probe_get_values (GstPropertyProbe * probe, \
263 const GParamSpec * pspec) \
265 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
266 return gst_v4l2_probe_get_values (probe, prop_id, pspec, \
267 &this_class->v4l2_class_devices); \
271 interface_as_function ## _property_probe_interface_init (GstPropertyProbeInterface * iface) \
273 iface->get_properties = gst_v4l2_probe_get_properties; \
274 iface->probe_property = interface_as_function ## _probe_probe_property; \
275 iface->needs_probe = interface_as_function ## _probe_needs_probe; \
276 iface->get_values = interface_as_function ## _probe_get_values; \
281 #endif /* __GST_V4L2_OBJECT_H__ */