summaryrefslogtreecommitdiff
path: root/sys/v4l2/v4l2_calls.h
blob: 0437ebf397eea5cf042999d629ce543633d6f7cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* GStreamer
 *
 * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
 *               2006 Edgard Lima <edgard.lima@indt.org.br>
 *
 * v4l2_calls.h - generic V4L2 calls handling
 *
 * 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., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __V4L2_CALLS_H__
#define __V4L2_CALLS_H__

#include "gstv4l2object.h"

#ifdef HAVE_LIBV4L2
#  include <libv4l2.h>
#else
#  include "ext/videodev2.h"
#  include <sys/ioctl.h>
#  include <sys/mman.h>
#  include <unistd.h>
#  define v4l2_fd_open(fd, flags) (fd)
#  define v4l2_close    close
#  define v4l2_dup      dup
#  define v4l2_ioctl    ioctl
#  define v4l2_read     read
#  define v4l2_mmap     mmap
#  define v4l2_munmap   munmap
#endif

#define GST_V4L2_IS_OVERLAY(v4l2object) \
  (v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_OVERLAY)

/* checks whether the current v4lv4l2object has already been open()'ed or not */
#define GST_V4L2_CHECK_OPEN(v4l2object)				\
  if (!GST_V4L2_IS_OPEN(v4l2object))				\
  {								\
    GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,	\
      (_("Device is not open.")), (NULL));                      \
    return FALSE;						\
  }

/* checks whether the current v4lv4l2object is close()'ed or whether it is still open */
#define GST_V4L2_CHECK_NOT_OPEN(v4l2object)			\
  if (GST_V4L2_IS_OPEN(v4l2object))				\
  {								\
    GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS,	\
      (_("Device is open.")), (NULL));                          \
    return FALSE;						\
  }

/* checks whether the current v4lv4l2object does video overlay */
#define GST_V4L2_CHECK_OVERLAY(v4l2object)			\
  if (!GST_V4L2_IS_OVERLAY(v4l2object))				\
  {								\
    GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
      (NULL), ("Device cannot handle overlay"));                \
    return FALSE;						\
  }

/* checks whether we're in capture mode or not */
#define GST_V4L2_CHECK_ACTIVE(v4l2object)			\
  if (!GST_V4L2_IS_ACTIVE(v4l2object))				\
  {								\
    GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
      (NULL), ("Device is not in streaming mode"));             \
    return FALSE;						\
  }

/* checks whether we're out of capture mode or not */
#define GST_V4L2_CHECK_NOT_ACTIVE(v4l2object)			\
  if (GST_V4L2_IS_ACTIVE(v4l2object))				\
  {								\
    GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
      (NULL), ("Device is in streaming mode"));                 \
    return FALSE;						\
  }


/* open/close the device */
gboolean	gst_v4l2_open			(GstV4l2Object *v4l2object);
gboolean	gst_v4l2_dup			(GstV4l2Object *v4l2object, GstV4l2Object *other);
gboolean	gst_v4l2_close			(GstV4l2Object *v4l2object);

/* norm/input/output */
gboolean	gst_v4l2_get_norm		(GstV4l2Object *v4l2object,
						 v4l2_std_id    *norm);
gboolean	gst_v4l2_set_norm		(GstV4l2Object *v4l2object,
						 v4l2_std_id     norm);
gboolean        gst_v4l2_get_input              (GstV4l2Object * v4l2object,
                                                 gint * input);
gboolean        gst_v4l2_set_input              (GstV4l2Object * v4l2object,
                                                 gint input);
gboolean	gst_v4l2_get_output		(GstV4l2Object *v4l2object,
						 gint           *output);
gboolean	gst_v4l2_set_output		(GstV4l2Object *v4l2object,
						 gint            output);

/* frequency control */
gboolean	gst_v4l2_get_frequency		(GstV4l2Object *v4l2object,
						 gint            tunernum,
						 gulong         *frequency);
gboolean	gst_v4l2_set_frequency		(GstV4l2Object *v4l2object,
						 gint            tunernum,
					 	 gulong          frequency);
gboolean	gst_v4l2_signal_strength	(GstV4l2Object *v4l2object,
						 gint            tunernum,
						 gulong         *signal);

/* attribute control */
gboolean	gst_v4l2_get_attribute		(GstV4l2Object *v4l2object,
						 int             attribute,
						 int            *value);
gboolean	gst_v4l2_set_attribute		(GstV4l2Object *v4l2object,
						 int             attribute,
						 const int       value);

gboolean	gst_v4l2_set_controls		(GstV4l2Object * v4l2object,
						 GstStructure * controls);

gboolean        gst_v4l2_get_capabilities       (GstV4l2Object * v4l2object);


#define LOG_CAPS(obj, caps) GST_DEBUG_OBJECT (obj, "%s: %" GST_PTR_FORMAT, #caps, caps)

#endif /* __V4L2_CALLS_H__ */