gstv4l2object.h 9 KB
Newer Older
1 2 3
/* GStreamer
 *
 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
Edgard Lima's avatar
Edgard Lima committed
4
 *               2006 Edgard Lima <edgard.lima@gmail.com>
5 6
 *
 * gstv4l2object.h: base class for V4L2 elements
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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
Tim-Philipp Müller's avatar
Tim-Philipp Müller committed
20 21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
22 23
 */

24 25
#ifndef __GST_V4L2_OBJECT_H__
#define __GST_V4L2_OBJECT_H__
26

27
#include "ext/videodev2.h"
28
#include "v4l2-utils.h"
29 30 31 32

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

Wim Taymans's avatar
Wim Taymans committed
33
#include <gst/video/video.h>
34

35 36 37 38 39
typedef struct _GstV4l2Object GstV4l2Object;
typedef struct _GstV4l2ObjectClassHelper GstV4l2ObjectClassHelper;
typedef struct _GstV4l2Xv GstV4l2Xv;

#include <gstv4l2bufferpool.h>
Rob Clark's avatar
Rob Clark committed
40 41

/* size of v4l2 buffer pool in streaming case */
42
#define GST_V4L2_MIN_BUFFERS 2
Rob Clark's avatar
Rob Clark committed
43 44 45 46

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

47 48
G_BEGIN_DECLS

49 50 51
#define GST_TYPE_V4L2_IO_MODE (gst_v4l2_io_mode_get_type ())
GType gst_v4l2_io_mode_get_type (void);

52
#define GST_V4L2_OBJECT(obj) (GstV4l2Object *)(obj)
Stefan Kost's avatar
Stefan Kost committed
53

Wim Taymans's avatar
Wim Taymans committed
54
typedef enum {
55 56 57 58 59 60
  GST_V4L2_IO_AUTO          = 0,
  GST_V4L2_IO_RW            = 1,
  GST_V4L2_IO_MMAP          = 2,
  GST_V4L2_IO_USERPTR       = 3,
  GST_V4L2_IO_DMABUF        = 4,
  GST_V4L2_IO_DMABUF_IMPORT = 5
Wim Taymans's avatar
Wim Taymans committed
61
} GstV4l2IOMode;
62

63 64
typedef gboolean  (*GstV4l2GetInOutFunction)  (GstV4l2Object * v4l2object, gint * input);
typedef gboolean  (*GstV4l2SetInOutFunction)  (GstV4l2Object * v4l2object, gint input);
65
typedef gboolean  (*GstV4l2UpdateFpsFunction) (GstV4l2Object * v4l2object);
66

Wim Taymans's avatar
Wim Taymans committed
67 68 69 70 71
#define GST_V4L2_WIDTH(o)        (GST_VIDEO_INFO_WIDTH (&(o)->info))
#define GST_V4L2_HEIGHT(o)       (GST_VIDEO_INFO_HEIGHT (&(o)->info))
#define GST_V4L2_PIXELFORMAT(o)  ((o)->fmtdesc->pixelformat)
#define GST_V4L2_FPS_N(o)        (GST_VIDEO_INFO_FPS_N (&(o)->info))
#define GST_V4L2_FPS_D(o)        (GST_VIDEO_INFO_FPS_D (&(o)->info))
72 73 74 75 76 77 78 79 80

/* simple check whether the device is open */
#define GST_V4L2_IS_OPEN(o)      ((o)->video_fd > 0)

/* check whether the device is 'active' */
#define GST_V4L2_IS_ACTIVE(o)    ((o)->active)
#define GST_V4L2_SET_ACTIVE(o)   ((o)->active = TRUE)
#define GST_V4L2_SET_INACTIVE(o) ((o)->active = FALSE)

81 82 83
struct _GstV4l2Object {
  GstElement * element;

84 85
  enum v4l2_buf_type type;   /* V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_OUTPUT */

86 87 88 89 90
  /* the video device */
  char *videodev;

  /* the video-device's file descriptor */
  gint video_fd;
Wim Taymans's avatar
Wim Taymans committed
91
  GstV4l2IOMode mode;
92

93
  gboolean active;
94
  gboolean streaming;
Rob Clark's avatar
Rob Clark committed
95

96
  /* the current format */
Wim Taymans's avatar
Wim Taymans committed
97
  struct v4l2_fmtdesc *fmtdesc;
98
  struct v4l2_format format;
Wim Taymans's avatar
Wim Taymans committed
99
  GstVideoInfo info;
100 101
  GstVideoAlignment align;

102
  /* Features */
103
  gboolean need_video_meta;
104
  gboolean has_alpha_component;
Wim Taymans's avatar
Wim Taymans committed
105

106 107 108 109 110 111
  /* only used if the device supports MPLANE
   * nb planes is meaning of v4l2 planes
   * the gstreamer equivalent is gst_buffer_n_memory
   */
  gint n_v4l2_planes;

112
  /* We cache the frame duration if known */
113
  GstClockTime duration;
114

Nicolas Dufresne's avatar
Nicolas Dufresne committed
115
  /* if the MPLANE device support both contiguous and non contiguous
116 117 118 119 120
   * it allows to select which one we want. But we prefered_non_contiguous
   * non contiguous mode.
   */
  gboolean prefered_non_contiguous;

121
  /* This will be set if supported in decide_allocation. It can be used to
122 123
   * calculate the minimum latency. */
  guint32 min_buffers;
124

125 126 127
  /* This will be set if supported in propose allocation. */
  guint32 min_buffers_for_output;

Wim Taymans's avatar
Wim Taymans committed
128 129 130
  /* wanted mode */
  GstV4l2IOMode req_mode;

131
  /* optional pool */
132
  GstBufferPool *pool;
133

134 135
  /* the video device's capabilities */
  struct v4l2_capability vcap;
136 137
  /* opened device specific capabilities */
  guint32 device_caps;
138 139 140 141 142 143 144 145

  /* 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
146
  GSList *formats;              /* list of available capture formats */
147
  GstCaps *probed_caps;
Rob Clark's avatar
Rob Clark committed
148

149
  GList *colors;
150 151
  GList *norms;
  GList *channels;
152
  GData *controls;
153 154

  /* properties */
Rob Clark's avatar
Rob Clark committed
155
  v4l2_std_id tv_norm;
156
  gchar *channel;
157
  gulong frequency;
158
  GstStructure *extra_controls;
159 160
  gboolean keep_aspect;
  GValue *par;
161 162 163 164 165 166

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

  /* funcs */
167 168
  GstV4l2GetInOutFunction  get_in_out_func;
  GstV4l2SetInOutFunction  set_in_out_func;
169
  GstV4l2UpdateFpsFunction update_fps_func;
170 171 172 173

  /* Quirks */
  /* Skips interlacing probes */
  gboolean never_interlaced;
174 175 176
  /* Allow to skip reading initial format through G_FMT. Some devices
   * just fails if you don't call S_FMT first. (ex: M2M decoders) */
  gboolean no_initial_format;
177 178 179 180 181 182 183
};

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

184
GType gst_v4l2_object_get_type (void);
185

186 187 188 189 190 191 192 193 194 195 196
#define V4L2_STD_OBJECT_PROPS \
    PROP_DEVICE,              \
    PROP_DEVICE_NAME,         \
    PROP_DEVICE_FD,           \
    PROP_FLAGS,               \
    PROP_BRIGHTNESS,          \
    PROP_CONTRAST,            \
    PROP_SATURATION,          \
    PROP_HUE,                 \
    PROP_TV_NORM,             \
    PROP_IO_MODE,             \
197 198
    PROP_OUTPUT_IO_MODE,      \
    PROP_CAPTURE_IO_MODE,     \
199 200
    PROP_EXTRA_CONTROLS,      \
    PROP_PIXEL_ASPECT_RATIO,  \
201
    PROP_FORCE_ASPECT_RATIO
202

203
/* create/destroy */
204 205 206 207 208 209 210 211
GstV4l2Object*  gst_v4l2_object_new       (GstElement * element,
                                           enum v4l2_buf_type  type,
                                           const char * default_device,
                                           GstV4l2GetInOutFunction get_in_out_func,
                                           GstV4l2SetInOutFunction set_in_out_func,
                                           GstV4l2UpdateFpsFunction update_fps_func);

void            gst_v4l2_object_destroy   (GstV4l2Object * v4l2object);
212 213

/* properties */
Rob Clark's avatar
Rob Clark committed
214

215 216
void         gst_v4l2_object_install_properties_helper (GObjectClass * gobject_class,
                                                        const char * default_device);
217

218 219
void         gst_v4l2_object_install_m2m_properties_helper (GObjectClass * gobject_class);

220 221 222 223 224 225 226
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);
227
/* open/close */
228
gboolean     gst_v4l2_object_open            (GstV4l2Object *v4l2object);
229
gboolean     gst_v4l2_object_open_shared     (GstV4l2Object *v4l2object, GstV4l2Object *other);
230
gboolean     gst_v4l2_object_close           (GstV4l2Object *v4l2object);
231 232

/* probing */
233

Rob Clark's avatar
Rob Clark committed
234 235
GstCaps*      gst_v4l2_object_get_all_caps (void);

236 237 238 239
GstCaps*      gst_v4l2_object_get_raw_caps (void);

GstCaps*      gst_v4l2_object_get_codec_caps (void);

240 241 242
gint          gst_v4l2_object_extrapolate_stride (const GstVideoFormatInfo * finfo,
                                                  gint plane, gint stride);

243 244
gboolean      gst_v4l2_object_set_format  (GstV4l2Object * v4l2object, GstCaps * caps, GstV4l2Error *error);
gboolean      gst_v4l2_object_try_format  (GstV4l2Object * v4l2object, GstCaps * caps, GstV4l2Error *error);
Rob Clark's avatar
Rob Clark committed
245

246 247
gboolean      gst_v4l2_object_caps_equal  (GstV4l2Object * v4l2object, GstCaps * caps);

248 249
gboolean      gst_v4l2_object_unlock      (GstV4l2Object * v4l2object);
gboolean      gst_v4l2_object_unlock_stop (GstV4l2Object * v4l2object);
Wim Taymans's avatar
Wim Taymans committed
250

251
gboolean      gst_v4l2_object_stop        (GstV4l2Object * v4l2object);
252

253 254
GstCaps *     gst_v4l2_object_probe_caps  (GstV4l2Object * v4l2object,
                                           GstCaps * filter);
255 256 257
GstCaps *     gst_v4l2_object_get_caps    (GstV4l2Object * v4l2object,
                                           GstCaps * filter);

258
gboolean      gst_v4l2_object_acquire_format (GstV4l2Object * v4l2object,
259
                                              GstVideoInfo * info);
260 261

gboolean      gst_v4l2_object_set_crop    (GstV4l2Object * obj);
Nicolas Dufresne's avatar
Nicolas Dufresne committed
262

263 264
gboolean      gst_v4l2_object_decide_allocation (GstV4l2Object * v4l2object,
                                                 GstQuery * query);
Rob Clark's avatar
Rob Clark committed
265

266 267 268
gboolean      gst_v4l2_object_propose_allocation (GstV4l2Object * obj,
                                                  GstQuery * query);

269 270
GstStructure * gst_v4l2_object_v4l2fourcc_to_structure (guint32 fourcc);

271 272
G_END_DECLS

273
#endif /* __GST_V4L2_OBJECT_H__ */