Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / sys / v4l2 / v4l2_calls.h
1 /* GStreamer
2  *
3  * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4  *               2006 Edgard Lima <edgard.lima@indt.org.br>
5  *
6  * v4l2_calls.h - generic V4L2 calls handling
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 __V4L2_CALLS_H__
25 #define __V4L2_CALLS_H__
26
27 #include "gstv4l2object.h"
28
29 #ifdef HAVE_LIBV4L2
30 #  include <libv4l2.h>
31 #else
32 #  include <sys/ioctl.h>
33 #  include <linux/videodev2.h>
34 #  define v4l2_fd_open(fd, flags) (fd)
35 #  define v4l2_close    close
36 #  define v4l2_dup      dup
37 #  define v4l2_ioctl    ioctl
38 #  define v4l2_read     read
39 #  define v4l2_mmap     mmap
40 #  define v4l2_munmap   munmap
41 #endif
42
43 /* simple check whether the device is open */
44 #define GST_V4L2_IS_OPEN(v4l2object) \
45   (v4l2object->video_fd > 0)
46
47 /* check whether the device is 'active' */
48 #define GST_V4L2_IS_ACTIVE(v4l2object) \
49   (v4l2object->buffer != NULL)
50
51 #define GST_V4L2_IS_OVERLAY(v4l2object) \
52   (v4l2object->vcap.capabilities & V4L2_CAP_VIDEO_OVERLAY)
53
54 /* checks whether the current v4lv4l2object has already been open()'ed or not */
55 #define GST_V4L2_CHECK_OPEN(v4l2object)                         \
56   if (!GST_V4L2_IS_OPEN(v4l2object))                            \
57   {                                                             \
58     GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
59       (_("Device is not open.")), (NULL));                      \
60     return FALSE;                                               \
61   }
62
63 /* checks whether the current v4lv4l2object is close()'ed or whether it is still open */
64 #define GST_V4L2_CHECK_NOT_OPEN(v4l2object)                     \
65   if (GST_V4L2_IS_OPEN(v4l2object))                             \
66   {                                                             \
67     GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
68       (_("Device is open.")), (NULL));                          \
69     return FALSE;                                               \
70   }
71
72 /* checks whether the current v4lv4l2object does video overlay */
73 #define GST_V4L2_CHECK_OVERLAY(v4l2object)                      \
74   if (!GST_V4L2_IS_OVERLAY(v4l2object))                         \
75   {                                                             \
76     GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
77       (NULL), ("Device cannot handle overlay"));                \
78     return FALSE;                                               \
79   }
80
81 /* checks whether we're in capture mode or not */
82 #define GST_V4L2_CHECK_ACTIVE(v4l2object)                       \
83   if (!GST_V4L2_IS_ACTIVE(v4l2object))                          \
84   {                                                             \
85     GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
86       (NULL), ("Device is not in streaming mode"));             \
87     return FALSE;                                               \
88   }
89
90 /* checks whether we're out of capture mode or not */
91 #define GST_V4L2_CHECK_NOT_ACTIVE(v4l2object)                   \
92   if (GST_V4L2_IS_ACTIVE(v4l2object))                           \
93   {                                                             \
94     GST_ELEMENT_ERROR (v4l2object->element, RESOURCE, SETTINGS, \
95       (NULL), ("Device is in streaming mode"));                 \
96     return FALSE;                                               \
97   }
98
99
100 /* open/close the device */
101 gboolean        gst_v4l2_open                   (GstV4l2Object *v4l2object);
102 gboolean        gst_v4l2_close                  (GstV4l2Object *v4l2object);
103
104 /* norm/input/output */
105 gboolean        gst_v4l2_get_norm               (GstV4l2Object *v4l2object,
106                                                  v4l2_std_id    *norm);
107 gboolean        gst_v4l2_set_norm               (GstV4l2Object *v4l2object,
108                                                  v4l2_std_id     norm);
109 gboolean        gst_v4l2_get_input              (GstV4l2Object * v4l2object,
110                                                  gint * input);
111 gboolean        gst_v4l2_set_input              (GstV4l2Object * v4l2object,
112                                                  gint input);
113 gboolean        gst_v4l2_get_output             (GstV4l2Object *v4l2object,
114                                                  gint           *output);
115 gboolean        gst_v4l2_set_output             (GstV4l2Object *v4l2object,
116                                                  gint            output);
117
118 /* frequency control */
119 gboolean        gst_v4l2_get_frequency          (GstV4l2Object *v4l2object,
120                                                  gint            tunernum,
121                                                  gulong         *frequency);
122 gboolean        gst_v4l2_set_frequency          (GstV4l2Object *v4l2object,
123                                                  gint            tunernum,
124                                                  gulong          frequency);
125 gboolean        gst_v4l2_signal_strength        (GstV4l2Object *v4l2object,
126                                                  gint            tunernum,
127                                                  gulong         *signal);
128
129 /* attribute control */
130 gboolean        gst_v4l2_get_attribute          (GstV4l2Object *v4l2object,
131                                                  int             attribute,
132                                                  int            *value);
133 gboolean        gst_v4l2_set_attribute          (GstV4l2Object *v4l2object,
134                                                  int             attribute,
135                                                  const int       value);
136
137 gboolean        gst_v4l2_get_capabilities       (GstV4l2Object * v4l2object);
138
139
140 #define LOG_CAPS(obj, caps) GST_DEBUG_OBJECT (obj, "%s: %" GST_PTR_FORMAT, #caps, caps)
141
142 #endif /* __V4L2_CALLS_H__ */