1 /* $NetBSD: video_if.h,v 1.4 2008/09/18 05:35:05 dogcow Exp $ */
4 * Copyright (c) 2008 Patrick Mahoney <pat@polycrystal.org>
7 * This code was written by Patrick Mahoney (pat@polycrystal.org) as
8 * part of Google Summer of Code 2008.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * This ia a Video4Linux 2 compatible /dev/video driver for NetBSD
35 * See http://v4l2spec.bytesex.org/ for Video4Linux 2 specifications
38 #ifndef _SYS_DEV_VIDEO_IF_H_
39 #define _SYS_DEV_VIDEO_IF_H_
41 #include <sys/types.h>
42 #include <sys/videoio.h>
44 #if defined(_KERNEL_OPT)
48 #error "No 'video* at videobus?' configured"
51 #endif /* _KERNEL_OPT */
55 /* Controls provide a way to query and set controls in the camera
56 * hardware. The control structure is the primitive unit. Control
57 * groups are arrays of controls that must be set together (e.g. pan
58 * direction and pan speed). Control descriptors describe a control
59 * including minimum and maximum values, read-only state, etc. A
60 * control group descriptor is an array of control descriptors
61 * corresponding to a control group array of controls.
63 * A control_group is made up of multiple controls meant to be set
64 * together and is identified by a 16 bit group_id. Each control is
65 * identified by a group_id and a control_id. Controls that are the
66 * sole member of a control_group may ignore the control_id or
67 * redundantly have the control_id equal to the group_id.
69 * The hardware driver only handles control_group's, many of which
70 * will only have a single control.
72 * Some id's are defined here (closely following the USB Video Class
73 * controls) with room for unspecified extended controls. These id's
74 * may be used for group_id's or control_id's as appropriate.
77 enum video_control_id
{
78 VIDEO_CONTROL_UNDEFINED
,
80 VIDEO_CONTROL_SCANNING_MODE
,
81 VIDEO_CONTROL_AE_MODE
,
82 VIDEO_CONTROL_EXPOSURE_TIME_ABSOLUTE
,
83 VIDEO_CONTROL_EXPOSURE_TIME_RELATIVE
,
84 VIDEO_CONTROL_FOCUS_ABSOLUTE
,
85 VIDEO_CONTROL_FOCUS_RELATIVE
,
86 VIDEO_CONTROL_IRIS_ABSOLUTE
,
87 VIDEO_CONTROL_IRIS_RELATIVE
,
88 VIDEO_CONTROL_ZOOM_ABSOLUTE
,
89 VIDEO_CONTROL_ZOOM_RELATIVE
,
90 VIDEO_CONTROL_PANTILT_ABSOLUTE
,
91 VIDEO_CONTROL_PANTILT_RELATIVE
,
92 VIDEO_CONTROL_ROLL_ABSOLUTE
,
93 VIDEO_CONTROL_ROLL_RELATIVE
,
94 VIDEO_CONTROL_PRIVACY
,
95 /* video processing */
96 VIDEO_CONTROL_BACKLIGHT_COMPENSATION
,
97 VIDEO_CONTROL_BRIGHTNESS
,
98 VIDEO_CONTROL_CONTRAST
,
100 VIDEO_CONTROL_GAIN_AUTO
, /* not in UVC */
101 VIDEO_CONTROL_POWER_LINE_FREQUENCY
,
103 VIDEO_CONTROL_SATURATION
,
104 VIDEO_CONTROL_SHARPNESS
,
106 /* Generic WHITE_BALANCE controls applies to whichever type of
107 * white balance the hardware implements to either perform one
108 * white balance action or enable auto white balance. */
109 VIDEO_CONTROL_WHITE_BALANCE_ACTION
,
110 VIDEO_CONTROL_WHITE_BALANCE_AUTO
,
111 VIDEO_CONTROL_WHITE_BALANCE_TEMPERATURE
,
112 VIDEO_CONTROL_WHITE_BALANCE_TEMPERATURE_AUTO
,
113 VIDEO_CONTROL_WHITE_BALANCE_COMPONENT
,
114 VIDEO_CONTROL_WHITE_BALANCE_COMPONENT_AUTO
,
115 VIDEO_CONTROL_DIGITAL_MULTIPLIER
,
116 VIDEO_CONTROL_DIGITAL_MULTIPLIER_LIMIT
,
117 VIDEO_CONTROL_HUE_AUTO
,
118 VIDEO_CONTROL_ANALOG_VIDEO_STANDARD
,
119 VIDEO_CONTROL_ANALOG_LOCK_STATUS
,
121 VIDEO_CONTROL_GENERATE_KEY_FRAME
,
122 VIDEO_CONTROL_UPDATE_FRAME_SEGMENT
,
123 /* misc, not in UVC */
126 /* Custom controls start here; any controls beyond this are
127 * valid and condsidered "extended". */
128 VIDEO_CONTROL_EXTENDED
131 enum video_control_type
{
132 VIDEO_CONTROL_TYPE_INT
, /* signed 32 bit integer */
133 VIDEO_CONTROL_TYPE_BOOL
,
134 VIDEO_CONTROL_TYPE_LIST
, /* V4L2 MENU */
135 VIDEO_CONTROL_TYPE_ACTION
/* V4L2 BUTTON */
138 #define VIDEO_CONTROL_FLAG_READ (1<<0)
139 #define VIDEO_CONTROL_FLAG_WRITE (1<<1)
140 #define VIDEO_CONTROL_FLAG_DISABLED (1<<2) /* V4L2 INACTIVE */
141 #define VIDEO_CONTROL_FLAG_AUTOUPDATE (1<<3)
142 #define VIDEO_CONTROL_FLAG_ASYNC (1<<4)
144 struct video_control_desc
{
149 enum video_control_type type
;
156 /* array of struct video_control_value_info belonging to the same control */
157 struct video_control_desc_group
{
160 struct video_control_desc
*desc
;
163 struct video_control
{
169 /* array of struct video_control_value belonging to the same control */
170 struct video_control_group
{
173 struct video_control
*control
;
176 struct video_control_iter
{
177 struct video_control_desc
*desc
;
180 /* format of video data in a video sample */
181 enum video_pixel_format
{
182 VIDEO_FORMAT_UNDEFINED
,
184 /* uncompressed frame-based formats */
185 VIDEO_FORMAT_YUY2
, /* packed 4:2:2 */
186 VIDEO_FORMAT_NV12
, /* planar 4:2:0 */
194 /* compressed frame-based formats */
195 VIDEO_FORMAT_MJPEG
, /* frames of JPEG images */
198 /* stream-based formats */
202 /* interlace_flags bits are allocated like this:
204 \_/ | | |interlaced or progressive
205 | | |packing style of fields (interlaced or planar)
206 | |fields per sample (1 or 2)
207 |pattern (F1 only, F2 only, F12, RND)
211 #define VIDEO_INTERLACED(iflags) (iflags & 1)
212 enum video_interlace_presence
{
213 VIDEO_INTERLACE_OFF
= 0, /* progressive */
214 VIDEO_INTERLACE_ON
= 1,
215 VIDEO_INTERLACE_ANY
= 2 /* in requests, accept any interlacing */
218 /* one bit, not in UVC */
219 #define VIDEO_INTERLACE_PACKING(iflags) ((iflags >> 2) & 1)
220 enum video_interlace_packing
{
221 VIDEO_INTERLACE_INTERLACED
= 0, /* F1 and F2 are interlaced */
222 VIDEO_INTERLACE_PLANAR
= 1 /* entire F1 is followed by F2 */
225 /* one bit, not in V4L2; Is this not redundant with PATTERN below?
226 * For now, I'm assuming it describes where the "end-of-frame" markers
227 * appear in the stream data: after every field or after every two
229 #define VIDEO_INTERLACE_FIELDS_PER_SAMPLE(iflags) ((iflags >> 3) & 1)
230 enum video_interlace_fields_per_sample
{
231 VIDEO_INTERLACE_TWO_FIELDS_PER_SAMPLE
= 0,
232 VIDEO_INTERLACE_ONE_FIELD_PER_SAMPLE
= 1
236 #define VIDEO_INTERLACE_PATTERN(iflags) ((iflags >> 4) & 3)
237 enum video_interlace_pattern
{
238 VIDEO_INTERLACE_PATTERN_F1
= 0,
239 VIDEO_INTERLACE_PATTERN_F2
= 1,
240 VIDEO_INTERLACE_PATTERN_F12
= 2,
241 VIDEO_INTERLACE_PATTERN_RND
= 3
244 enum video_color_primaries
{
245 VIDEO_COLOR_PRIMARIES_UNSPECIFIED
,
246 VIDEO_COLOR_PRIMARIES_BT709
, /* identical to sRGB */
247 VIDEO_COLOR_PRIMARIES_BT470_2_M
,
248 VIDEO_COLOR_PRIMARIES_BT470_2_BG
,
249 VIDEO_COLOR_PRIMARIES_SMPTE_170M
,
250 VIDEO_COLOR_PRIMARIES_SMPTE_240M
,
251 VIDEO_COLOR_PRIMARIES_BT878
/* in V4L2 as broken BT878 chip */
254 enum video_gamma_function
{
255 VIDEO_GAMMA_FUNCTION_UNSPECIFIED
,
256 VIDEO_GAMMA_FUNCTION_BT709
,
257 VIDEO_GAMMA_FUNCTION_BT470_2_M
,
258 VIDEO_GAMMA_FUNCTION_BT470_2_BG
,
259 VIDEO_GAMMA_FUNCTION_SMPTE_170M
,
260 VIDEO_GAMMA_FUNCTION_SMPTE_240M
,
261 VIDEO_GAMMA_FUNCTION_LINEAR
,
262 VIDEO_GAMMA_FUNCTION_sRGB
, /* similar but not identical to BT709 */
263 VIDEO_GAMMA_FUNCTION_BT878
/* in V4L2 as broken BT878 chip */
266 /* Matrix coefficients for converting YUV to RGB */
267 enum video_matrix_coeff
{
268 VIDEO_MATRIX_COEFF_UNSPECIFIED
,
269 VIDEO_MATRIX_COEFF_BT709
,
270 VIDEO_MATRIX_COEFF_FCC
,
271 VIDEO_MATRIX_COEFF_BT470_2_BG
,
272 VIDEO_MATRIX_COEFF_SMPTE_170M
,
273 VIDEO_MATRIX_COEFF_SMPTE_240M
,
274 VIDEO_MATRIX_COEFF_BT878
/* in V4L2 as broken BT878 chip */
277 /* UVC spec separates these into three categories. V4L2 does not. */
278 struct video_colorspace
{
279 enum video_color_primaries primaries
;
280 enum video_gamma_function gamma_function
;
281 enum video_matrix_coeff matrix_coeff
;
285 /* Stucts for future split into format/frame/interval. All functions
286 * interacting with the hardware layer will deal with these structs.
287 * This video layer will handle translating them to V4L2 structs as
290 struct video_format
{
291 enum video_pixel_format vfo_pixel_format
;
292 uint8_t vfo_aspect_x
; /* aspect ratio x and y */
293 uint8_t vfo_aspect_y
;
294 struct video_colorspace vfo_color
;
295 uint8_t vfo_interlace_flags
;
299 uint32_t vfr_width
; /* dimensions in pixels */
301 uint32_t vfr_sample_size
; /* max sample size */
302 uint32_t vfr_stride
; /* length of one row of pixels in
303 * bytes; uncompressed formats
307 enum video_frame_interval_type
{
308 VIDEO_FRAME_INTERVAL_TYPE_CONTINUOUS
,
309 VIDEO_FRAME_INTERVAL_TYPE_DISCRETE
312 /* UVC spec frame interval units are 100s of nanoseconds. V4L2 spec
313 * uses a {32/32} bit struct fraction in seconds. We use 100ns units
315 #define VIDEO_FRAME_INTERVAL_UNITS_PER_US (10)
316 #define VIDEO_FRAME_INTERVAL_UNITS_PER_MS (10 * 1000)
317 #define VIDEO_FRAME_INTERVAL_UNITS_PER_S (10 * 1000 * 1000)
318 struct video_frame_interval
{
319 enum video_frame_interval_type vfi_type
;
327 uint32_t vfi_discrete
;
332 /* Describes a video format. For frame based formats, one sample is
333 * equivalent to one frame. For stream based formats such as MPEG, a
334 * sample is logical unit of that streaming format.
336 struct video_format
{
337 enum video_pixel_format pixel_format
;
338 uint32_t width
; /* dimensions in pixels */
340 uint8_t aspect_x
; /* aspect ratio x and y */
342 uint32_t sample_size
; /* max sample size */
343 uint32_t stride
; /* length of one row of pixels in
344 * bytes; uncompressed formats
346 struct video_colorspace color
;
347 uint8_t interlace_flags
;
348 uint32_t priv
; /* For private use by hardware driver.
349 * Must be set to zero if not used. */
352 /* A payload is the smallest unit transfered from the hardware driver
353 * to the video layer. Multiple video payloads make up one video
355 struct video_payload
{
357 size_t size
; /* size in bytes of this payload */
358 int frameno
; /* toggles between 0 and 1 */
359 bool end_of_frame
; /* set if this is the last
360 * payload in the frame. */
364 int (*open
)(void *, int); /* open hardware */
365 void (*close
)(void *); /* close hardware */
367 const char * (*get_devname
)(void *);
369 int (*enum_format
)(void *, uint32_t, struct video_format
*);
370 int (*get_format
)(void *, struct video_format
*);
371 int (*set_format
)(void *, struct video_format
*);
372 int (*try_format
)(void *, struct video_format
*);
374 int (*start_transfer
)(void *);
375 int (*stop_transfer
)(void *);
377 int (*control_iter_init
)(void *, struct video_control_iter
*);
378 int (*control_iter_next
)(void *, struct video_control_iter
*);
379 int (*get_control_desc_group
)(void *,
380 struct video_control_desc_group
*);
381 int (*get_control_group
)(void *, struct video_control_group
*);
382 int (*set_control_group
)(void *, const struct video_control_group
*);
385 struct video_attach_args
{
386 const struct video_hw_if
*hw_if
;
389 device_t
video_attach_mi(const struct video_hw_if
*, device_t
);
390 void video_submit_payload(device_t
, const struct video_payload
*);
392 #endif /* _SYS_DEV_VIDEO_IF_H_ */