/*
V4L2 controls framework implementation.
Copyright (C) 2010 Hans Verkuil <hverkuil@xs4all.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/export.h>
#include <media/v4l2-ioctl.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-event.h>
#include <media/v4l2-dev.h>
#define has_op(master, op) \
(master->ops && master->ops->op)
#define call_op(master, op) \
(has_op(master, op) ? master->ops->op(master) : 0)
/* Internal temporary helper struct, one for each v4l2_ext_control */
struct v4l2_ctrl_helper {
/* Pointer to the control reference of the master control */
struct v4l2_ctrl_ref *mref;
/* The control corresponding to the v4l2_ext_control ID field. */
struct v4l2_ctrl *ctrl;
/* v4l2_ext_control index of the next control belonging to the
same cluster, or 0 if there isn't any. */
u32 next;
};
/* Small helper function to determine if the autocluster is set to manual
mode. */
static bool is_cur_manual(const struct v4l2_ctrl *master)
{
return master->is_auto && master->cur.val == master->manual_mode_value;
}
/* Same as above, but this checks the against the new value instead of the
current value. */
static bool is_new_manual(const struct v4l2_ctrl *master)
{
return master->is_auto && master->val == master->manual_mode_value;
}
/* Returns NULL or a character pointer array containing the menu for
the given control ID. The pointer array ends with a NULL pointer.
An empty string signifies a menu entry that is invalid. This allows
drivers to disable certain options if it is not supported. */
const char * const *v4l2_ctrl_get_menu(u32 id)
{
static const char * const mpeg_audio_sampling_freq[] = {
"44.1 kHz",
"48 kHz",
"32 kHz",
NULL
};
static const char * const mpeg_audio_encoding[] = {
"MPEG-1/2 Layer I",
"MPEG-1/2 Layer II",
"MPEG-1/2 Layer III",
"MPEG-2/4 AAC",
"AC-3",
NULL
};
static const char * const mpeg_audio_l1_bitrate[] = {
"32 kbps",
"64 kbps",
"96 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"288 kbps",
"320 kbps",
"352 kbps",
"384 kbps",
"416 kbps",
"448 kbps",
NULL
};
static const char * const mpeg_audio_l2_bitrate[] = {
"32 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
"384 kbps",
NULL
};
static const char * const mpeg_audio_l3_bitrate[] = {
"32 kbps",
"40 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
NULL
};
static const char * const mpeg_audio_ac3_bitrate[] = {
"32 kbps",
"40 kbps",
"48 kbps",
"56 kbps",
"64 kbps",
"80 kbps",
"96 kbps",
"112 kbps",
"128 kbps",
"160 kbps",
"192 kbps",
"224 kbps",
"256 kbps",
"320 kbps",
"384 kbps",
"448 kbps",
"512 kbps",
"576 kbps",
"640 kbps",
NULL
};
static const char * const mpeg_audio_mode[] = {
"Stereo",
"Joint Stereo",
"Dual",
"Mono",
NULL
};
static const char * const mpeg_audio_mode_extension[] = {
"Bound 4",
"Bound 8",
"Bound 12",
"Bound 16",
NULL
};
static const char * const mpeg_audio_emphasis[] = {
"No Emphasis",
"50/15 us",
"CCITT J17",
NULL
};
static const char * const mpeg_audio_crc[] = {
"No CRC",
"16-bit CRC",
NULL
};
static const char * const mpeg_audio_dec_playback[] = {
"Auto",
"Stereo",
"Left",
"Right",
"Mono",
"Swapped Stereo",
NULL
};
static const char * const mpeg_video_encoding[] = {
"MPEG-1",
"MPEG-2",
"MPEG-4 AVC",
NULL
};
static const char * const mpeg_video_aspect[] = {
"1x1",
"4x3",
"16x9",
"2.21x1",
NULL
};
static const char * const mpeg_video_bitrate_mode[] = {
"Variable Bitrate",
"Constant Bitrate",
NULL
};
static const char * const mpeg_stream_type[] = {
"MPEG-2 Program Stream",
"MPEG-2 Transport Stream",
"MPEG-1 System Stream",
"MPEG-2 DVD-compatible Stream",
"MPEG-1 VCD-compatible Stream",
"MPEG-2 SVCD-compatible Stream",
NULL
};
static const char * const mpeg_stream_vbi_fmt[] = {
"No VBI",
"Private Packet, IVTV Format",
NULL
};
static const char * const camera_power_line_frequency[] = {
"Disabled",
"50 Hz",
"60 Hz",
"Auto",
NULL
};
static const char * const camera_exposure_auto[] = {
"Auto Mode",
"Manual Mode",
"Shutter Priority Mode",
"Aperture Priority Mode",
NULL
};
static const char * const camera_exposure_metering[] = {
"Average",
"Center Weighted",
"Spot",
"Matrix",
NULL
};
static const char * const camera_auto_focus_range[] = {
"Auto",
"Normal",
"Macro",
"Infinity",
NULL
};
static const char * const colorfx[] = {
"None",
"Black & White",
"Sepia",
"Negative",
"Emboss",
"Sketch",
"Sky Blue",
"Grass Green",
"Skin Whiten",
"Vivid",
"Aqua",
"Art Freeze",
"Silhouette",
"Solarization",
"Antique",
"Set Cb/Cr",
NULL
};
static const char * const auto_n_preset_white_balance[] = {
"Manual",
"Auto",
"Incandescent",
"Fluorescent",
"Fluorescent H",
"Horizon",
"Daylight",
"Flash",
"Cloudy",
"Shade",
NULL,
};
static const char * const camera_iso_sensitivity_auto[] = {
"Manual",
"Auto",
NULL
};
static const char * const scene_mode[] = {
"None",
"Backlight",
"Beach/Snow",
"Candle Light",
"Dusk/Dawn",
"Fall Colors",
"Fireworks",
"Landscape",
"Night",
"Party/Indoor",
"Portrait",
"Sports",
"Sunset",
"Text",
NULL
};
static const char * const tune_emphasis[] = {
"None",
"50 Microseconds",
"75 Microseconds",
NULL,
};
static const char * const header_mode[] = {
"Separate Buffer",
"Joined With 1st Frame",
NULL,
};
static const char * const multi_slice[] = {
"Single",
"Max Macroblocks",
"Max Bytes",
NULL,
};
static const char * const entropy_mode[] = {
"CAVLC",
"CABAC",
NULL,
};
static const char * const mpeg_h264_level[] = {
"1",
"1b",
"1.1",
"1.2",
"1.3",
"2",
"2.1",
"2.2",
"3",
"3.1",
"3.2",
"4",
"4.1",
"4.2",
"5",
"5.1",
NULL,
};
static const char * const h264_loop_filter[] = {
"Enabled",
"Disabled",
"Disabled at Slice Boundary",
NULL,
};
static const char * const h264_profile[] = {
"Baseline",
"Constrained Baseline",
"Main",
"Extended",
"High",
"High 10",
"High 422",
"High 444 Predictive",
"High 10 Intra",
"High 422 Intra",
"High 444 Intra",
"CAVLC 444 Intra",
"Scalable Baseline",
"Scalable High",
"Scalable High Intra",
"Multiview High",
NULL,
};
static const char * const vui_sar_idc[] = {
"Unspecified",
"1:1",
"12:11",
"10:11",
"16:11",
"40:33",
"24:11",
"20:11",
"32:11",
"80:33",
"18:11",
"15:11",
"64:33",
"160:99",
"4:3",
"3:2",
"2:1",
"Extended SAR",
NULL,
};
static const char * const h264_fp_arrangement_type[] = {
"Checkerboard",
"Column",
"Row",
"Side by Side",
"Top Bottom",
"Temporal",
NULL,
};
static const char * const h264_fmo_map_type[] = {
"Interleaved Slices",
"Scattered Slices",
"Foreground with Leftover",
"Box Out",
"Raster Scan",
"Wipe Scan",
"Explicit