gstv4l2object.h 10.2 KB
Newer Older
1 2 3
/* GStreamer
 *
 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 5 6
 *               2006 Edgard Lima <edgard.lima@indt.org.br>
 *
 * gstv4l2object.h: base class for V4L2 elements
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

24 25
#ifndef __GST_V4L2_OBJECT_H__
#define __GST_V4L2_OBJECT_H__
26 27 28 29 30 31 32 33 34 35 36 37 38

/* Because of some really cool feature in video4linux1, also known as
 * 'not including sys/types.h and sys/time.h', we had to include it
 * ourselves. In all their intelligence, these people decided to fix
 * this in the next version (video4linux2) in such a cool way that it
 * breaks all compilations of old stuff...
 * The real problem is actually that linux/time.h doesn't use proper
 * macro checks before defining types like struct timeval. The proper
 * fix here is to either fuck the kernel header (which is what we do
 * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it
 * upstream, which I'll consider doing later on. If you get compiler
 * errors here, check your linux/time.h && sys/time.h header setup.
 */
39
#include <sys/ioctl.h>
40
#include <sys/types.h>
41
#ifndef __sun
42 43 44 45
#include <linux/types.h>
#define _LINUX_TIME_H
#define __user
#include <linux/videodev2.h>
46 47 48
#else
#include <sys/videodev2.h>
#endif
49 50 51 52 53 54

#include <gst/gst.h>
#include <gst/base/gstpushsrc.h>

#include <gst/interfaces/propertyprobe.h>

Rob Clark's avatar
Rob Clark committed
55 56 57 58 59 60 61 62 63 64

/* size of v4l2 buffer pool in streaming case */
#define GST_V4L2_MAX_BUFFERS 16
#define GST_V4L2_MIN_BUFFERS 1

/* max frame width/height */
#define GST_V4L2_MAX_SIZE (1<<15) /* 2^15 == 32768 */



65 66
G_BEGIN_DECLS

67
#define GST_V4L2_OBJECT(obj) (GstV4l2Object *)(obj)
Stefan Kost's avatar
Stefan Kost committed
68

69 70 71 72
typedef struct _GstV4l2Object GstV4l2Object;
typedef struct _GstV4l2ObjectClassHelper GstV4l2ObjectClassHelper;
typedef struct _GstV4l2Xv GstV4l2Xv;

73 74
typedef gboolean  (*GstV4l2GetInOutFunction)  (GstV4l2Object * v4l2object, gint * input);
typedef gboolean  (*GstV4l2SetInOutFunction)  (GstV4l2Object * v4l2object, gint input);
75
typedef gboolean  (*GstV4l2UpdateFpsFunction) (GstV4l2Object * v4l2object);
76 77 78 79 80 81 82 83 84

struct _GstV4l2Object {
  GstElement * element;

  /* the video device */
  char *videodev;

  /* the video-device's file descriptor */
  gint video_fd;
85
  GstPoll * poll;
86
  gboolean can_poll_device;
87 88 89 90

  /* the video buffer (mmap()'ed) */
  guint8 **buffer;

Rob Clark's avatar
Rob Clark committed
91 92
  enum v4l2_buf_type type;   /* V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_OUTPUT */

93 94 95 96 97 98 99 100 101 102
  /* the video device's capabilities */
  struct v4l2_capability vcap;

  /* the video device's window properties */
  struct v4l2_window vwin;

  /* some more info about the current input's capabilities */
  struct v4l2_input vinput;

  /* lists... */
Rob Clark's avatar
Rob Clark committed
103 104
  GSList *formats;              /* list of available capture formats */

105
  GList *colors;
106 107
  GList *norms;
  GList *channels;
108 109

  /* properties */
110 111
  gchar *norm;
  gchar *channel;
112 113 114 115 116 117 118
  gulong frequency;

  /* X-overlay */
  GstV4l2Xv *xv;
  gulong xwindow_id;

  /* funcs */
119 120
  GstV4l2GetInOutFunction  get_in_out_func;
  GstV4l2SetInOutFunction  set_in_out_func;
121
  GstV4l2UpdateFpsFunction update_fps_func;
122 123 124 125 126 127 128
};

struct _GstV4l2ObjectClassHelper {
  /* probed devices */
  GList *devices;
};

129
GType gst_v4l2_object_get_type (void);
130

131 132 133
#define V4L2_STD_OBJECT_PROPS		\
    PROP_DEVICE,			\
    PROP_DEVICE_NAME,			\
134
    PROP_DEVICE_FD,			\
135
    PROP_FLAGS
136

137 138
/* create/destroy */
GstV4l2Object *	gst_v4l2_object_new 		 (GstElement * element,
139 140
                                                  enum v4l2_buf_type  type,
                                                  const char *default_device,
141
                   				  GstV4l2GetInOutFunction get_in_out_func,
142 143
                   				  GstV4l2SetInOutFunction set_in_out_func,
		   				  GstV4l2UpdateFpsFunction   update_fps_func);
144
void 	        gst_v4l2_object_destroy 	 (GstV4l2Object * v4l2object);
145 146

/* properties */
Rob Clark's avatar
Rob Clark committed
147 148

void 	  gst_v4l2_object_install_properties_helper (GObjectClass *gobject_class, const char *default_device);
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

gboolean  gst_v4l2_object_set_property_helper       (GstV4l2Object *v4l2object,
				                     guint prop_id, const GValue * value,
						     GParamSpec * pspec);
gboolean  gst_v4l2_object_get_property_helper       (GstV4l2Object *v4l2object,
				                     guint prop_id, GValue * value,
						     GParamSpec * pspec);
/* starting/stopping */
gboolean  gst_v4l2_object_start             (GstV4l2Object *v4l2object);
gboolean  gst_v4l2_object_stop              (GstV4l2Object *v4l2object);

/* probing */
const GList* gst_v4l2_probe_get_properties  (GstPropertyProbe * probe);

void         gst_v4l2_probe_probe_property  (GstPropertyProbe * probe, guint prop_id,
                                             const GParamSpec * pspec,
                                             GList ** klass_devices);
gboolean     gst_v4l2_probe_needs_probe     (GstPropertyProbe * probe, guint prop_id,
                                             const GParamSpec * pspec,
                                             GList ** klass_devices);
GValueArray* gst_v4l2_probe_get_values      (GstPropertyProbe * probe, guint prop_id,
                                             const GParamSpec * pspec,
                                             GList ** klass_devices);
172

Rob Clark's avatar
Rob Clark committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
GstCaps*      gst_v4l2_object_probe_caps_for_format (GstV4l2Object *v4l2object, guint32 pixelformat,
                                             const GstStructure * template);

gboolean      gst_v4l2_object_get_caps_info (GstV4l2Object *v4l2object, GstCaps *caps,
                                             struct v4l2_fmtdesc **format, gint *w, gint *h,
                                             guint *fps_n, guint *fps_d, guint *size);


GSList*       gst_v4l2_object_get_format_list  (GstV4l2Object *v4l2object);

GstCaps*      gst_v4l2_object_get_all_caps (void);

GstStructure* gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);

gboolean      gst_v4l2_object_set_format (GstV4l2Object *v4l2object, guint32 pixelformat, guint32 width, guint32 height);

gboolean      gst_v4l2_object_start_streaming (GstV4l2Object *v4l2object);
gboolean      gst_v4l2_object_stop_streaming (GstV4l2Object *v4l2object);


193 194 195 196 197 198 199
#define GST_IMPLEMENT_V4L2_PROBE_METHODS(Type_Class, interface_as_function)                 \
                                                                                            \
static void                                                                                 \
interface_as_function ## _probe_probe_property (GstPropertyProbe * probe,                   \
			                        guint prop_id,                              \
                                                const GParamSpec * pspec)                   \
{                                                                                           \
200
  Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
201 202 203 204 205 206 207 208 209
  gst_v4l2_probe_probe_property (probe, prop_id, pspec,                                     \
                                        &this_class->v4l2_class_devices);	            \
}                                                                                           \
                                                                                            \
static gboolean                                                                             \
interface_as_function ## _probe_needs_probe (GstPropertyProbe * probe,                      \
			                     guint prop_id,                                 \
                                             const GParamSpec * pspec)                      \
{                                                                                           \
210
  Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
211 212 213 214 215 216 217 218 219
  return gst_v4l2_probe_needs_probe (probe, prop_id, pspec,                                 \
                                        &this_class->v4l2_class_devices);	            \
}                                                                                           \
                                                                                            \
static GValueArray *                                                                        \
interface_as_function ## _probe_get_values (GstPropertyProbe * probe,                       \
			                    guint prop_id,                                  \
                                            const GParamSpec * pspec)                       \
{                                                                                           \
220
  Type_Class *this_class = (Type_Class*) G_OBJECT_GET_CLASS (probe);                        \
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
  return gst_v4l2_probe_get_values (probe, prop_id, pspec,                                  \
                                    &this_class->v4l2_class_devices);	                    \
}                                                                                           \
                                                                                            \
static void								                    \
interface_as_function ## _property_probe_interface_init (GstPropertyProbeInterface * iface) \
{                                                                                           \
  iface->get_properties = gst_v4l2_probe_get_properties;                                    \
  iface->probe_property = interface_as_function ## _probe_probe_property;                   \
  iface->needs_probe = interface_as_function ## _probe_needs_probe;                         \
  iface->get_values = interface_as_function ## _probe_get_values;                                            \
}

G_END_DECLS

236
#endif /* __GST_V4L2_OBJECT_H__ */