Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / sys / v4l2 / gstv4l2object.h
1 /* GStreamer
2  *
3  * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *               2006 Edgard Lima <edgard.lima@indt.org.br>
5  *
6  * gstv4l2object.h: base class for V4L2 elements
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #ifndef __GST_V4L2_OBJECT_H__
25 #define __GST_V4L2_OBJECT_H__
26
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.
38  */
39 #include <sys/ioctl.h>
40 #include <sys/types.h>
41 #ifndef __sun
42 #include <linux/types.h>
43 #define _LINUX_TIME_H
44 #define __user
45 #include <linux/videodev2.h>
46 #else
47 #include <sys/videodev2.h>
48 #endif
49
50 #include <gst/gst.h>
51 #include <gst/base/gstpushsrc.h>
52 #include <gst/controller/gstcontroller.h>
53
54 #include <gst/interfaces/propertyprobe.h>
55
56
57 /* size of v4l2 buffer pool in streaming case */
58 #define GST_V4L2_MAX_BUFFERS 16
59 #define GST_V4L2_MIN_BUFFERS 1
60
61 /* max frame width/height */
62 #define GST_V4L2_MAX_SIZE (1<<15) /* 2^15 == 32768 */
63
64
65
66 G_BEGIN_DECLS
67
68 #define GST_V4L2_OBJECT(obj) (GstV4l2Object *)(obj)
69
70 typedef struct _GstV4l2Object GstV4l2Object;
71 typedef struct _GstV4l2ObjectClassHelper GstV4l2ObjectClassHelper;
72 typedef struct _GstV4l2Xv GstV4l2Xv;
73
74 typedef gboolean  (*GstV4l2GetInOutFunction)  (GstV4l2Object * v4l2object, gint * input);
75 typedef gboolean  (*GstV4l2SetInOutFunction)  (GstV4l2Object * v4l2object, gint input);
76 typedef gboolean  (*GstV4l2UpdateFpsFunction) (GstV4l2Object * v4l2object);
77
78 struct _GstV4l2Object {
79   GstElement * element;
80
81   /* the video device */
82   char *videodev;
83
84   /* the video-device's file descriptor */
85   gint video_fd;
86   GstPoll * poll;
87   gboolean can_poll_device;
88
89   /* the video buffer (mmap()'ed) */
90   guint8 **buffer;
91
92   enum v4l2_buf_type type;   /* V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_OUTPUT */
93
94   /* the video device's capabilities */
95   struct v4l2_capability vcap;
96
97   /* the video device's window properties */
98   struct v4l2_window vwin;
99
100   /* some more info about the current input's capabilities */
101   struct v4l2_input vinput;
102
103   /* lists... */
104   GSList *formats;              /* list of available capture formats */
105
106   GList *colors;
107   GList *norms;
108   GList *channels;
109
110   /* properties */
111   v4l2_std_id tv_norm;
112   gchar *channel;
113   gulong frequency;
114
115   /* X-overlay */
116   GstV4l2Xv *xv;
117   gulong xwindow_id;
118
119   /* funcs */
120   GstV4l2GetInOutFunction  get_in_out_func;
121   GstV4l2SetInOutFunction  set_in_out_func;
122   GstV4l2UpdateFpsFunction update_fps_func;
123 };
124
125 struct _GstV4l2ObjectClassHelper {
126   /* probed devices */
127   GList *devices;
128 };
129
130 GType gst_v4l2_object_get_type (void);
131
132 #define V4L2_STD_OBJECT_PROPS           \
133     PROP_DEVICE,                        \
134     PROP_DEVICE_NAME,                   \
135     PROP_DEVICE_FD,                     \
136     PROP_FLAGS,                         \
137     PROP_BRIGHTNESS,                    \
138     PROP_CONTRAST,                      \
139     PROP_SATURATION,                    \
140     PROP_HUE,                           \
141     PROP_TV_NORM
142
143 /* create/destroy */
144 GstV4l2Object * gst_v4l2_object_new              (GstElement * element,
145                                                   enum v4l2_buf_type  type,
146                                                   const char *default_device,
147                                                   GstV4l2GetInOutFunction get_in_out_func,
148                                                   GstV4l2SetInOutFunction set_in_out_func,
149                                                   GstV4l2UpdateFpsFunction   update_fps_func);
150 void            gst_v4l2_object_destroy          (GstV4l2Object * v4l2object);
151
152 /* properties */
153
154 void      gst_v4l2_object_install_properties_helper (GObjectClass *gobject_class, const char *default_device);
155
156 gboolean  gst_v4l2_object_set_property_helper       (GstV4l2Object *v4l2object,
157                                                      guint prop_id, const GValue * value,
158                                                      GParamSpec * pspec);
159 gboolean  gst_v4l2_object_get_property_helper       (GstV4l2Object *v4l2object,
160                                                      guint prop_id, GValue * value,
161                                                      GParamSpec * pspec);
162 /* starting/stopping */
163 gboolean  gst_v4l2_object_start             (GstV4l2Object *v4l2object);
164 gboolean  gst_v4l2_object_stop              (GstV4l2Object *v4l2object);
165
166 /* probing */
167 const GList* gst_v4l2_probe_get_properties  (GstPropertyProbe * probe);
168
169 void         gst_v4l2_probe_probe_property  (GstPropertyProbe * probe, guint prop_id,
170                                              const GParamSpec * pspec,
171                                              GList ** klass_devices);
172 gboolean     gst_v4l2_probe_needs_probe     (GstPropertyProbe * probe, guint prop_id,
173                                              const GParamSpec * pspec,
174                                              GList ** klass_devices);
175 GValueArray* gst_v4l2_probe_get_values      (GstPropertyProbe * probe, guint prop_id,
176                                              const GParamSpec * pspec,
177                                              GList ** klass_devices);
178
179 GstCaps*      gst_v4l2_object_probe_caps_for_format (GstV4l2Object *v4l2object, guint32 pixelformat,
180                                              const GstStructure * template);
181
182 gboolean      gst_v4l2_object_get_caps_info (GstV4l2Object *v4l2object, GstCaps *caps,
183                                              struct v4l2_fmtdesc **format, gint *w, gint *h,
184                                              gboolean * interlaced, guint *fps_n, guint *fps_d, guint *size);
185
186
187 GSList*       gst_v4l2_object_get_format_list  (GstV4l2Object *v4l2object);
188
189 GstCaps*      gst_v4l2_object_get_all_caps (void);
190
191 GstStructure* gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);
192
193 gboolean      gst_v4l2_object_set_format (GstV4l2Object *v4l2object, guint32 pixelformat, guint32 width, guint32 height, gboolean interlaced);
194
195 gboolean      gst_v4l2_object_start_streaming (GstV4l2Object *v4l2object);
196 gboolean      gst_v4l2_object_stop_streaming (GstV4l2Object *v4l2object);
197
198
199 #define GST_IMPLEMENT_V4L2_PROBE_METHODS(Type_Class, interface_as_function)                 \
200                                                                                             \
201 static void                                                                                 \
202 interface_as_function ## _probe_probe_property (GstPropertyProbe * probe,                   \
203                                                 guint prop_id,                              \
204                                                 const GParamSpec * pspec)                   \
205 {                                                                                           \
206   Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
207   gst_v4l2_probe_probe_property (probe, prop_id, pspec,                                     \
208                                         &this_class->v4l2_class_devices);                   \
209 }                                                                                           \
210                                                                                             \
211 static gboolean                                                                             \
212 interface_as_function ## _probe_needs_probe (GstPropertyProbe * probe,                      \
213                                              guint prop_id,                                 \
214                                              const GParamSpec * pspec)                      \
215 {                                                                                           \
216   Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
217   return gst_v4l2_probe_needs_probe (probe, prop_id, pspec,                                 \
218                                         &this_class->v4l2_class_devices);                   \
219 }                                                                                           \
220                                                                                             \
221 static GValueArray *                                                                        \
222 interface_as_function ## _probe_get_values (GstPropertyProbe * probe,                       \
223                                             guint prop_id,                                  \
224                                             const GParamSpec * pspec)                       \
225 {                                                                                           \
226   Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
227   return gst_v4l2_probe_get_values (probe, prop_id, pspec,                                  \
228                                     &this_class->v4l2_class_devices);                       \
229 }                                                                                           \
230                                                                                             \
231 static void                                                                                 \
232 interface_as_function ## _property_probe_interface_init (GstPropertyProbeInterface * iface) \
233 {                                                                                           \
234   iface->get_properties = gst_v4l2_probe_get_properties;                                    \
235   iface->probe_property = interface_as_function ## _probe_probe_property;                   \
236   iface->needs_probe = interface_as_function ## _probe_needs_probe;                         \
237   iface->get_values = interface_as_function ## _probe_get_values;                                            \
238 }
239
240 G_END_DECLS
241
242 #endif /* __GST_V4L2_OBJECT_H__ */