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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #ifndef __GST_V4L2_OBJECT_H__
25 #define __GST_V4L2_OBJECT_H__
27 #include "ext/videodev2.h"
30 #include <gst/base/gstpushsrc.h>
32 #include <gst/video/video.h>
34 typedef struct _GstV4l2Object GstV4l2Object;
35 typedef struct _GstV4l2ObjectClassHelper GstV4l2ObjectClassHelper;
36 typedef struct _GstV4l2Xv GstV4l2Xv;
38 #include <gstv4l2bufferpool.h>
40 /* size of v4l2 buffer pool in streaming case */
41 #define GST_V4L2_MIN_BUFFERS 1
43 /* max frame width/height */
44 #define GST_V4L2_MAX_SIZE (1<<15) /* 2^15 == 32768 */
48 #define GST_TYPE_V4L2_IO_MODE (gst_v4l2_io_mode_get_type ())
49 GType gst_v4l2_io_mode_get_type (void);
51 #define GST_V4L2_OBJECT(obj) (GstV4l2Object *)(obj)
57 GST_V4L2_IO_USERPTR = 3,
58 GST_V4L2_IO_DMABUF = 4
61 typedef gboolean (*GstV4l2GetInOutFunction) (GstV4l2Object * v4l2object, gint * input);
62 typedef gboolean (*GstV4l2SetInOutFunction) (GstV4l2Object * v4l2object, gint input);
63 typedef gboolean (*GstV4l2UpdateFpsFunction) (GstV4l2Object * v4l2object);
65 #define GST_V4L2_WIDTH(o) (GST_VIDEO_INFO_WIDTH (&(o)->info))
66 #define GST_V4L2_HEIGHT(o) (GST_VIDEO_INFO_HEIGHT (&(o)->info))
67 #define GST_V4L2_PIXELFORMAT(o) ((o)->fmtdesc->pixelformat)
68 #define GST_V4L2_FPS_N(o) (GST_VIDEO_INFO_FPS_N (&(o)->info))
69 #define GST_V4L2_FPS_D(o) (GST_VIDEO_INFO_FPS_D (&(o)->info))
71 /* simple check whether the device is open */
72 #define GST_V4L2_IS_OPEN(o) ((o)->video_fd > 0)
74 /* check whether the device is 'active' */
75 #define GST_V4L2_IS_ACTIVE(o) ((o)->active)
76 #define GST_V4L2_SET_ACTIVE(o) ((o)->active = TRUE)
77 #define GST_V4L2_SET_INACTIVE(o) ((o)->active = FALSE)
79 struct _GstV4l2Object {
82 enum v4l2_buf_type type; /* V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_OUTPUT */
84 /* the video device */
87 /* the video-device's file descriptor */
91 gboolean can_poll_device;
96 /* the current format */
97 struct v4l2_fmtdesc *fmtdesc;
98 struct v4l2_format format;
100 GstVideoAlignment align;
103 gboolean need_video_meta;
104 gboolean need_crop_meta;
105 gboolean has_alpha_component;
107 /* only used if the device supports MPLANE
108 * nb planes is meaning of v4l2 planes
109 * the gstreamer equivalent is gst_buffer_n_memory
113 guint32 bytesperline[GST_VIDEO_MAX_PLANES];
115 GstClockTime duration;
117 /* if the MPLANE device support both contiguous and non contiguous
118 * it allows to select which one we want. But we prefered_non_contiguous
119 * non contiguous mode.
121 gboolean prefered_non_contiguous;
123 /* This will be set if supported in decide_allocation. It can be used to
124 * calculate the minimum latency of a m2m decoder. */
125 guint32 min_buffers_for_capture;
128 GstV4l2IOMode req_mode;
133 /* the video device's capabilities */
134 struct v4l2_capability vcap;
136 /* the video device's window properties */
137 struct v4l2_window vwin;
139 /* some more info about the current input's capabilities */
140 struct v4l2_input vinput;
143 GSList *formats; /* list of available capture formats */
144 GstCaps *probed_caps;
155 GstStructure *extra_controls;
156 gboolean keep_aspect;
164 GstV4l2GetInOutFunction get_in_out_func;
165 GstV4l2SetInOutFunction set_in_out_func;
166 GstV4l2UpdateFpsFunction update_fps_func;
169 /* Skips interlacing probes */
170 gboolean never_interlaced;
171 /* Allow to skip reading initial format through G_FMT. Some devices
172 * just fails if you don't call S_FMT first. (ex: M2M decoders) */
173 gboolean no_initial_format;
176 struct _GstV4l2ObjectClassHelper {
181 GType gst_v4l2_object_get_type (void);
183 #define V4L2_STD_OBJECT_PROPS \
194 PROP_EXTRA_CONTROLS, \
195 PROP_PIXEL_ASPECT_RATIO, \
196 PROP_FORCE_ASPECT_RATIO
199 GstV4l2Object* gst_v4l2_object_new (GstElement * element,
200 enum v4l2_buf_type type,
201 const char * default_device,
202 GstV4l2GetInOutFunction get_in_out_func,
203 GstV4l2SetInOutFunction set_in_out_func,
204 GstV4l2UpdateFpsFunction update_fps_func);
206 void gst_v4l2_object_destroy (GstV4l2Object * v4l2object);
210 void gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
211 const char * default_device);
213 gboolean gst_v4l2_object_set_property_helper (GstV4l2Object * v4l2object,
215 const GValue * value,
217 gboolean gst_v4l2_object_get_property_helper (GstV4l2Object *v4l2object,
218 guint prop_id, GValue * value,
221 gboolean gst_v4l2_object_open (GstV4l2Object *v4l2object);
222 gboolean gst_v4l2_object_open_shared (GstV4l2Object *v4l2object, GstV4l2Object *other);
223 gboolean gst_v4l2_object_close (GstV4l2Object *v4l2object);
227 const GList* gst_v4l2_probe_get_properties (GstPropertyProbe * probe);
229 void gst_v4l2_probe_probe_property (GstPropertyProbe * probe, guint prop_id,
230 const GParamSpec * pspec,
231 GList ** klass_devices);
232 gboolean gst_v4l2_probe_needs_probe (GstPropertyProbe * probe, guint prop_id,
233 const GParamSpec * pspec,
234 GList ** klass_devices);
235 GValueArray* gst_v4l2_probe_get_values (GstPropertyProbe * probe, guint prop_id,
236 const GParamSpec * pspec,
237 GList ** klass_devices);
240 GstCaps* gst_v4l2_object_get_all_caps (void);
242 GstCaps* gst_v4l2_object_get_raw_caps (void);
244 GstCaps* gst_v4l2_object_get_codec_caps (void);
246 gboolean gst_v4l2_object_set_format (GstV4l2Object * v4l2object, GstCaps * caps);
248 gboolean gst_v4l2_object_caps_equal (GstV4l2Object * v4l2object, GstCaps * caps);
250 gboolean gst_v4l2_object_unlock (GstV4l2Object * v4l2object);
251 gboolean gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object);
253 gboolean gst_v4l2_object_stop (GstV4l2Object * v4l2object);
256 gboolean gst_v4l2_object_copy (GstV4l2Object * v4l2object,
257 GstBuffer * dest, GstBuffer * src);
259 GstCaps * gst_v4l2_object_get_caps (GstV4l2Object * v4l2object,
262 gboolean gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object,
263 GstVideoInfo * info);
265 gboolean gst_v4l2_object_set_crop (GstV4l2Object * obj);
267 gboolean gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
270 gboolean gst_v4l2_object_propose_allocation (GstV4l2Object * obj,
273 GstStructure * gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);
276 #define GST_IMPLEMENT_V4L2_PROBE_METHODS(Type_Class, interface_as_function) \
279 interface_as_function ## _probe_probe_property (GstPropertyProbe * probe, \
281 const GParamSpec * pspec) \
283 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
284 gst_v4l2_probe_probe_property (probe, prop_id, pspec, \
285 &this_class->v4l2_class_devices); \
289 interface_as_function ## _probe_needs_probe (GstPropertyProbe * probe, \
291 const GParamSpec * pspec) \
293 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
294 return gst_v4l2_probe_needs_probe (probe, prop_id, pspec, \
295 &this_class->v4l2_class_devices); \
298 static GValueArray * \
299 interface_as_function ## _probe_get_values (GstPropertyProbe * probe, \
301 const GParamSpec * pspec) \
303 Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe); \
304 return gst_v4l2_probe_get_values (probe, prop_id, pspec, \
305 &this_class->v4l2_class_devices); \
309 interface_as_function ## _property_probe_interface_init (GstPropertyProbeInterface * iface) \
311 iface->get_properties = gst_v4l2_probe_get_properties; \
312 iface->probe_property = interface_as_function ## _probe_probe_property; \
313 iface->needs_probe = interface_as_function ## _probe_needs_probe; \
314 iface->get_values = interface_as_function ## _probe_get_values; \
319 #endif /* __GST_V4L2_OBJECT_H__ */