diff options
author | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-23 16:11:54 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-23 16:11:54 -0300 |
commit | 8587142fb31bbbc156e4e1ecd758e2c0fe5eb2bf (patch) | |
tree | 472c338929bdcb87f76a7824bf1602378ab34d03 | |
parent | 27db32c1fbbd03a1427f7b783dcc7eee372c953e (diff) | |
parent | 47e7619ed0e11061799a387d580aa2aa90561ead (diff) | |
download | mediapointer-dvb-s2-8587142fb31bbbc156e4e1ecd758e2c0fe5eb2bf.tar.gz mediapointer-dvb-s2-8587142fb31bbbc156e4e1ecd758e2c0fe5eb2bf.tar.bz2 |
merge: http://linuxtv.org/hg/~hverkuil/mpeg-api
From: Mauro Carvalho Chehab <mchehab@infradead.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
28 files changed, 4295 insertions, 994 deletions
diff --git a/linux/Documentation/video4linux/cx2341x/fw-encoder-api.txt b/linux/Documentation/video4linux/cx2341x/fw-encoder-api.txt index 08ee9f530..001c68644 100644 --- a/linux/Documentation/video4linux/cx2341x/fw-encoder-api.txt +++ b/linux/Documentation/video4linux/cx2341x/fw-encoder-api.txt @@ -100,13 +100,20 @@ Param[1] Name CX2341X_ENC_SET_BIT_RATE Enum 149/0x95 Description - Assign average video stream bitrate. + Assign average video stream bitrate. Note on the last three params: + Param[3] and [4] seem to be always 0, param [5] doesn't seem to be used. Param[0] 0=variable bitrate, 1=constant bitrate Param[1] bitrate in bits per second Param[2] peak bitrate in bits per second, divided by 400 +Param[3] + Mux bitrate in bits per second, divided by 400. May be 0 (default). +Param[4] + Rate Control VBR Padding +Param[5] + VBV Buffer used by encoder ------------------------------------------------------------------------------- @@ -115,10 +122,11 @@ Enum 151/0x97 Description Setup the GOP structure Param[0] - GOP size + GOP size (maximum is 34) Param[1] Number of B frames between the I and P frame, plus 1. For example: IBBPBBPBBPBB --> GOP size: 12, number of B frames: 2+1 = 3 + Note that GOP size must be a multiple of (B-frames + 1). ------------------------------------------------------------------------------- @@ -241,6 +249,9 @@ Name CX2341X_ENC_SET_STREAM_TYPE Enum 185/0xB9 Description Assign stream type + Note: Transport stream is not working in recent firmwares. + And in older firmwares the timestamps in the TS seem to be + unreliable. Param[0] 0=Program stream 1=Transport stream @@ -259,11 +270,17 @@ Param[0] Name CX2341X_ENC_SET_OUTPUT_PORT Enum 187/0xBB Description - Assign stream output port (not recommended you change setting from default) + Assign stream output port. Normally 0 when the data is copied through + the PCI bus (DMA), and 1 when the data is streamed to another chip + (pvrusb and cx88-blackbird). Param[0] 0=Memory (default) 1=Streaming 2=Serial +Param[1] + Unknown, but leaving this to 0 seems to work best. Indications are that + this might have to do with USB support, although passing anything but 0 + onl breaks things. ------------------------------------------------------------------------------- @@ -278,6 +295,8 @@ Description '01' Layer III '00' Undefined This discrepancy may indicate a possible error in the documentation. + Testing indicated that only Layer II is actually working, and that + the minimum bitrate should be 192 kbps. Param[0] Bitmask: 0:1 '00' 44.1Khz @@ -313,6 +332,9 @@ Param[0] '01'=JointStereo '10'=Dual '11'=Mono + Note: testing seems to indicate that Mono and possibly + JointStereo are not working (default to stereo). + Dual does work, though. 10:11 Mode Extension used in joint_stereo mode. In Layer I and II they indicate which subbands are in diff --git a/linux/drivers/media/Kconfig b/linux/drivers/media/Kconfig index ef52e6da0..583d151b7 100644 --- a/linux/drivers/media/Kconfig +++ b/linux/drivers/media/Kconfig @@ -82,6 +82,9 @@ config VIDEO_IR config VIDEO_TVEEPROM tristate +config VIDEO_CX2341X + tristate + config USB_DABUSB tristate "DABUSB driver" depends on USB diff --git a/linux/drivers/media/video/Makefile b/linux/drivers/media/video/Makefile index 44f84166f..572e84835 100644 --- a/linux/drivers/media/video/Makefile +++ b/linux/drivers/media/video/Makefile @@ -74,6 +74,7 @@ obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o +obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o obj-$(CONFIG_USB_DABUSB) += dabusb.o obj-$(CONFIG_USB_DSBR) += dsbr100.o diff --git a/linux/drivers/media/video/cx2341x.c b/linux/drivers/media/video/cx2341x.c new file mode 100644 index 000000000..29a5c8e5c --- /dev/null +++ b/linux/drivers/media/video/cx2341x.c @@ -0,0 +1,919 @@ +/* + * cx2341x - generic code for cx23415/6 based devices + * + * Copyright (C) 2006 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "compat.h" + +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/types.h> +#include <linux/videodev2.h> +#include <linux/i2c.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) +#include <linux/slab.h> +#endif + +#include <media/tuner.h> +#include <media/cx2341x.h> +#include <media/v4l2-common.h> + +MODULE_DESCRIPTION("cx23415/6 driver"); +MODULE_AUTHOR("Hans Verkuil"); +MODULE_LICENSE("GPL"); + +static int debug = 0; +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "Debug level (0-1)"); + +const u32 cx2341x_mpeg_ctrls[] = { + V4L2_CID_MPEG_CLASS, + V4L2_CID_MPEG_STREAM_TYPE, + V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ, + V4L2_CID_MPEG_AUDIO_ENCODING, + V4L2_CID_MPEG_AUDIO_L2_BITRATE, + V4L2_CID_MPEG_AUDIO_MODE, + V4L2_CID_MPEG_AUDIO_MODE_EXTENSION, + V4L2_CID_MPEG_AUDIO_EMPHASIS, + V4L2_CID_MPEG_AUDIO_CRC, + V4L2_CID_MPEG_VIDEO_ENCODING, + V4L2_CID_MPEG_VIDEO_ASPECT, + V4L2_CID_MPEG_VIDEO_B_FRAMES, + V4L2_CID_MPEG_VIDEO_GOP_SIZE, + V4L2_CID_MPEG_VIDEO_GOP_CLOSURE, + V4L2_CID_MPEG_VIDEO_PULLDOWN, + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, + V4L2_CID_MPEG_VIDEO_BITRATE, + V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, + V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION, + V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE, + V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER, + V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE, + V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE, + V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE, + V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER, + V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE, + V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM, + V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP, + V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM, + V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP, + 0 +}; + + +/* Map the control ID to the correct field in the cx2341x_mpeg_params + struct. Return -EINVAL if the ID is unknown, else return 0. */ +static int cx2341x_get_ctrl(struct cx2341x_mpeg_params *params, + struct v4l2_ext_control *ctrl) +{ + switch (ctrl->id) { + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + ctrl->value = params->audio_sampling_freq; + break; + case V4L2_CID_MPEG_AUDIO_ENCODING: + ctrl->value = params->audio_encoding; + break; + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + ctrl->value = params->audio_l2_bitrate; + break; + case V4L2_CID_MPEG_AUDIO_MODE: + ctrl->value = params->audio_mode; + break; + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + ctrl->value = params->audio_mode_extension; + break; + case V4L2_CID_MPEG_AUDIO_EMPHASIS: + ctrl->value = params->audio_emphasis; + break; + case V4L2_CID_MPEG_AUDIO_CRC: + ctrl->value = params->audio_crc; + break; + case V4L2_CID_MPEG_VIDEO_ENCODING: + ctrl->value = params->video_encoding; + break; + case V4L2_CID_MPEG_VIDEO_ASPECT: + ctrl->value = params->video_aspect; + break; + case V4L2_CID_MPEG_VIDEO_B_FRAMES: + ctrl->value = params->video_b_frames; + break; + case V4L2_CID_MPEG_VIDEO_GOP_SIZE: + ctrl->value = params->video_gop_size; + break; + case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: + ctrl->value = params->video_gop_closure; + break; + case V4L2_CID_MPEG_VIDEO_PULLDOWN: + ctrl->value = params->video_pulldown; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + ctrl->value = params->video_bitrate_mode; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: + ctrl->value = params->video_bitrate; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + ctrl->value = params->video_bitrate_peak; + break; + case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: + ctrl->value = params->video_temporal_decimation; + break; + case V4L2_CID_MPEG_STREAM_TYPE: + ctrl->value = params->stream_type; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + ctrl->value = params->video_spatial_filter_mode; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: + ctrl->value = params->video_spatial_filter; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + ctrl->value = params->video_luma_spatial_filter_type; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + ctrl->value = params->video_chroma_spatial_filter_type; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + ctrl->value = params->video_temporal_filter_mode; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: + ctrl->value = params->video_temporal_filter; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + ctrl->value = params->video_median_filter_type; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: + ctrl->value = params->video_luma_median_filter_top; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: + ctrl->value = params->video_luma_median_filter_bottom; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: + ctrl->value = params->video_chroma_median_filter_top; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: + ctrl->value = params->video_chroma_median_filter_bottom; + break; + default: + return -EINVAL; + } + return 0; +} + +/* Map the control ID to the correct field in the cx2341x_mpeg_params + struct. Return -EINVAL if the ID is unknown, else return 0. */ +static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, + struct v4l2_ext_control *ctrl) +{ + switch (ctrl->id) { + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + params->audio_sampling_freq = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_ENCODING: + params->audio_encoding = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + params->audio_l2_bitrate = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_MODE: + params->audio_mode = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + params->audio_mode_extension = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_EMPHASIS: + params->audio_emphasis = ctrl->value; + break; + case V4L2_CID_MPEG_AUDIO_CRC: + params->audio_crc = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_ASPECT: + params->video_aspect = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_B_FRAMES: { + int b = ctrl->value + 1; + int gop = params->video_gop_size; + params->video_b_frames = ctrl->value; + params->video_gop_size = b * ((gop + b - 1) / b); + /* Max GOP size = 34 */ + while (params->video_gop_size > 34) + params->video_gop_size -= b; + break; + } + case V4L2_CID_MPEG_VIDEO_GOP_SIZE: { + int b = params->video_b_frames + 1; + int gop = ctrl->value; + params->video_gop_size = b * ((gop + b - 1) / b); + /* Max GOP size = 34 */ + while (params->video_gop_size > 34) + params->video_gop_size -= b; + ctrl->value = params->video_gop_size; + break; + } + case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: + params->video_gop_closure = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_PULLDOWN: + params->video_pulldown = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + /* MPEG-1 only allows CBR */ + if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 && + ctrl->value != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) + return -EINVAL; + params->video_bitrate_mode = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: + params->video_bitrate = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + params->video_bitrate_peak = ctrl->value; + break; + case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: + params->video_temporal_decimation = ctrl->value; + break; + case V4L2_CID_MPEG_STREAM_TYPE: + params->stream_type = ctrl->value; + params->video_encoding = + (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS || + params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_VCD) ? + V4L2_MPEG_VIDEO_ENCODING_MPEG_1 : V4L2_MPEG_VIDEO_ENCODING_MPEG_2; + if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) { + /* MPEG-1 implies CBR */ + params->video_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR; + } + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + params->video_spatial_filter_mode = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: + params->video_spatial_filter = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + params->video_luma_spatial_filter_type = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + params->video_chroma_spatial_filter_type = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + params->video_temporal_filter_mode = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: + params->video_temporal_filter = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + params->video_median_filter_type = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: + params->video_luma_median_filter_top = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: + params->video_luma_median_filter_bottom = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: + params->video_chroma_median_filter_top = ctrl->value; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: + params->video_chroma_median_filter_bottom = ctrl->value; + break; + default: + return -EINVAL; + } + return 0; +} + +static int cx2341x_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) +{ + const char *name; + + qctrl->flags = 0; + switch (qctrl->id) { + /* MPEG controls */ + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + name = "Spatial Filter Mode"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: + name = "Spatial Filter"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + name = "Spatial Luma Filter Type"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + name = "Spatial Chroma Filter Type"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + name = "Temporal Filter Mode"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: + name = "Temporal Filter"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + name = "Median Filter Type"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: + name = "Median Luma Filter Maximum"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: + name = "Median Luma Filter Minimum"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: + name = "Median Chroma Filter Maximum"; + break; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: + name = "Median Chroma Filter Minimum"; + break; + + default: + return v4l2_ctrl_query_fill(qctrl, min, max, step, def); + } + switch (qctrl->id) { + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + qctrl->type = V4L2_CTRL_TYPE_MENU; + min = 0; + step = 1; + break; + default: + qctrl->type = V4L2_CTRL_TYPE_INTEGER; + break; + } + switch (qctrl->id) { + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + qctrl->flags |= V4L2_CTRL_FLAG_UPDATE; + break; + } + qctrl->minimum = min; + qctrl->maximum = max; + qctrl->step = step; + qctrl->default_value = def; + qctrl->reserved[0] = qctrl->reserved[1] = 0; + snprintf(qctrl->name, sizeof(qctrl->name), name); + return 0; +} + +int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, struct v4l2_queryctrl *qctrl) +{ + int err; + + switch (qctrl->id) { + case V4L2_CID_MPEG_AUDIO_ENCODING: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2); + + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_L2_BITRATE_192K, + V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1, + V4L2_MPEG_AUDIO_L2_BITRATE_224K); + + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: + return -EINVAL; + + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + err = v4l2_ctrl_query_fill_std(qctrl); + if (err == 0 && params->audio_mode != V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return err; + + case V4L2_CID_MPEG_VIDEO_ENCODING: + /* this setting is read-only for the cx2341x since the + V4L2_CID_MPEG_STREAM_TYPE really determines the + MPEG-1/2 setting */ + err = v4l2_ctrl_query_fill_std(qctrl); + if (err == 0) + qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + return err; + + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + err = v4l2_ctrl_query_fill_std(qctrl); + if (err == 0 && params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return err; + + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + err = v4l2_ctrl_query_fill_std(qctrl); + if (err == 0 && params->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return err; + + /* CX23415/6 specific */ + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + return cx2341x_ctrl_query_fill(qctrl, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO, 1, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL); + + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER: + cx2341x_ctrl_query_fill(qctrl, 0, 15, 1, 0); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + cx2341x_ctrl_query_fill(qctrl, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE, 1, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF); + if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + cx2341x_ctrl_query_fill(qctrl, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, 1, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF); + if (params->video_spatial_filter_mode == V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + return cx2341x_ctrl_query_fill(qctrl, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO, 1, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL); + + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER: + cx2341x_ctrl_query_fill(qctrl, 0, 31, 1, 0); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_temporal_filter_mode == V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + return cx2341x_ctrl_query_fill(qctrl, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG, 1, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF); + + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP: + cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM: + cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP: + cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 255); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM: + cx2341x_ctrl_query_fill(qctrl, 0, 255, 1, 0); + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + if (params->video_median_filter_type == V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF) + qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE; + return 0; + + default: + return v4l2_ctrl_query_fill_std(qctrl); + + } +} + +const char **cx2341x_ctrl_get_menu(u32 id) +{ + static const char *mpeg_stream_type[] = { + "MPEG-2 Program Stream", + "", + "MPEG-1 System Stream", + "MPEG-2 DVD-compatible Stream", + "MPEG-1 VCD-compatible Stream", + "MPEG-2 SVCD-compatible Stream", + NULL + }; + + static const char *cx2341x_video_spatial_filter_mode_menu[] = { + "Manual", + "Auto", + NULL + }; + + static const char *cx2341x_video_luma_spatial_filter_type_menu[] = { + "Off", + "1D Horizontal", + "1D Vertical", + "2D H/V Separable", + "2D Symmetric non-separable", + NULL + }; + + static const char *cx2341x_video_chroma_spatial_filter_type_menu[] = { + "Off", + "1D Horizontal", + NULL + }; + + static const char *cx2341x_video_temporal_filter_mode_menu[] = { + "Manual", + "Auto", + NULL + }; + + static const char *cx2341x_video_median_filter_type_menu[] = { + "Off", + "Horizontal", + "Vertical", + "Horizontal/Vertical", + "Diagonal", + NULL + }; + + switch (id) { + case V4L2_CID_MPEG_STREAM_TYPE: + return mpeg_stream_type; + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: + return NULL; + case V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE: + return cx2341x_video_spatial_filter_mode_menu; + case V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE: + return cx2341x_video_luma_spatial_filter_type_menu; + case V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE: + return cx2341x_video_chroma_spatial_filter_type_menu; + case V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE: + return cx2341x_video_temporal_filter_mode_menu; + case V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE: + return cx2341x_video_median_filter_type_menu; + default: + return v4l2_ctrl_get_menu(id); + } +} + +static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params) +{ + params->audio_properties = (params->audio_sampling_freq << 0) | + ((3 - params->audio_encoding) << 2) | + ((1 + params->audio_l2_bitrate) << 4) | + (params->audio_mode << 8) | + (params->audio_mode_extension << 10) | + (((params->audio_emphasis == V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17) ? + 3 : + params->audio_emphasis) << 12) | + (params->audio_crc << 14); +} + +int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, + struct v4l2_ext_controls *ctrls, int cmd) +{ + int err = 0; + int i; + + if (cmd == VIDIOC_G_EXT_CTRLS) { + for (i = 0; i < ctrls->count; i++) { + struct v4l2_ext_control *ctrl = ctrls->controls + i; + + err = cx2341x_get_ctrl(params, ctrl); + if (err) { + ctrls->error_idx = i; + break; + } + } + return err; + } + for (i = 0; i < ctrls->count; i++) { + struct v4l2_ext_control *ctrl = ctrls->controls + i; + struct v4l2_queryctrl qctrl; + const char **menu_items = NULL; + + qctrl.id = ctrl->id; + err = cx2341x_ctrl_query(params, &qctrl); + if (err) + break; + if (qctrl.type == V4L2_CTRL_TYPE_MENU) + menu_items = cx2341x_ctrl_get_menu(qctrl.id); + err = v4l2_ctrl_check(ctrl, &qctrl, menu_items); + if (err) + break; + err = cx2341x_set_ctrl(params, ctrl); + if (err) + break; + } + if (err == 0 && params->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && + params->video_bitrate_peak < params->video_bitrate) { + err = -ERANGE; + ctrls->error_idx = ctrls->count; + } + if (err) { + ctrls->error_idx = i; + } + else { + cx2341x_calc_audio_properties(params); + } + return err; +} + +void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p) +{ + static struct cx2341x_mpeg_params default_params = { + /* misc */ + .port = CX2341X_PORT_MEMORY, + .width = 720, + .height = 480, + .is_50hz = 0, + + /* stream */ + .stream_type = V4L2_MPEG_STREAM_TYPE_MPEG2_PS, + + /* audio */ + .audio_sampling_freq = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, + .audio_encoding = V4L2_MPEG_AUDIO_ENCODING_LAYER_2, + .audio_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_224K, + .audio_mode = V4L2_MPEG_AUDIO_MODE_STEREO, + .audio_mode_extension = V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4, + .audio_emphasis = V4L2_MPEG_AUDIO_EMPHASIS_NONE, + .audio_crc = V4L2_MPEG_AUDIO_CRC_NONE, + + /* video */ + .video_encoding = V4L2_MPEG_VIDEO_ENCODING_MPEG_2, + .video_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3, + .video_b_frames = 2, + .video_gop_size = 12, + .video_gop_closure = 1, + .video_pulldown = 0, + .video_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, + .video_bitrate = 6000000, + .video_bitrate_peak = 8000000, + .video_temporal_decimation = 0, + + /* encoding filters */ + .video_spatial_filter_mode = V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL, + .video_spatial_filter = 0, + .video_luma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR, + .video_chroma_spatial_filter_type = V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, + .video_temporal_filter_mode = V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, + .video_temporal_filter = 0, + .video_median_filter_type = V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, + .video_luma_median_filter_top = 255, + .video_luma_median_filter_bottom = 0, + .video_chroma_median_filter_top = 255, + .video_chroma_median_filter_bottom = 0, + }; + + *p = default_params; + cx2341x_calc_audio_properties(p); +} + +static int cx2341x_api(void *priv, cx2341x_mbox_func func, int cmd, int args, ...) +{ + u32 data[CX2341X_MBOX_MAX_DATA]; + va_list vargs; + int i; + + va_start(vargs, args); + + for (i = 0; i < args; i++) { + data[i] = va_arg(vargs, int); + } + va_end(vargs); + return func(priv, cmd, args, 0, data); +} + +int cx2341x_update(void *priv, cx2341x_mbox_func func, + const struct cx2341x_mpeg_params *old, const struct cx2341x_mpeg_params *new) +{ + static int mpeg_stream_type[] = { + 0, /* MPEG-2 PS */ + 1, /* MPEG-2 TS */ + 2, /* MPEG-1 SS */ + 14, /* DVD */ + 11, /* VCD */ + 12, /* SVCD */ + }; + + int err = 0; + + cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0); + + if (old == NULL || old->is_50hz != new->is_50hz) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_RATE, 1, new->is_50hz); + if (err) return err; + } + + if (old == NULL || old->width != new->width || old->height != new->height || + old->video_encoding != new->video_encoding) { + u16 w = new->width; + u16 h = new->height; + + if (new->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1) { + w /= 2; + h /= 2; + } + err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w); + if (err) return err; + } + + if (old == NULL || old->stream_type != new->stream_type) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_STREAM_TYPE, 1, mpeg_stream_type[new->stream_type]); + if (err) return err; + } + if (old == NULL || old->video_aspect != new->video_aspect) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_ASPECT_RATIO, 1, 1 + new->video_aspect); + if (err) return err; + } + if (old == NULL || old->video_b_frames != new->video_b_frames || + old->video_gop_size != new->video_gop_size) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_PROPERTIES, 2, + new->video_gop_size, new->video_b_frames + 1); + if (err) return err; + } + if (old == NULL || old->video_gop_closure != new->video_gop_closure) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1, new->video_gop_closure); + if (err) return err; + } + if (old == NULL || old->video_pulldown != new->video_pulldown) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_3_2_PULLDOWN, 1, new->video_pulldown); + if (err) return err; + } + if (old == NULL || old->audio_properties != new->audio_properties) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, new->audio_properties); + if (err) return err; + } + if (old == NULL || old->video_bitrate_mode != new->video_bitrate_mode || + old->video_bitrate != new->video_bitrate || + old->video_bitrate_peak != new->video_bitrate_peak) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_BIT_RATE, 5, + new->video_bitrate_mode, new->video_bitrate, + new->video_bitrate_peak / 400, 0, 0); + if (err) return err; + } + if (old == NULL || old->video_spatial_filter_mode != new->video_spatial_filter_mode || + old->video_temporal_filter_mode != new->video_temporal_filter_mode || + old->video_median_filter_type != new->video_median_filter_type) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, + new->video_spatial_filter_mode | (new->video_temporal_filter_mode << 1), + new->video_median_filter_type); + if (err) return err; + } + if (old == NULL || + old->video_luma_median_filter_bottom != new->video_luma_median_filter_bottom || + old->video_luma_median_filter_top != new->video_luma_median_filter_top || + old->video_chroma_median_filter_bottom != new->video_chroma_median_filter_bottom || + old->video_chroma_median_filter_top != new->video_chroma_median_filter_top) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_CORING_LEVELS, 4, + new->video_luma_median_filter_bottom, + new->video_luma_median_filter_top, + new->video_chroma_median_filter_bottom, + new->video_chroma_median_filter_top); + if (err) return err; + } + if (old == NULL || + old->video_luma_spatial_filter_type != new->video_luma_spatial_filter_type || + old->video_chroma_spatial_filter_type != new->video_chroma_spatial_filter_type) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2, + new->video_luma_spatial_filter_type, new->video_chroma_spatial_filter_type); + if (err) return err; + } + if (old == NULL || + old->video_spatial_filter != new->video_spatial_filter || + old->video_temporal_filter != new->video_temporal_filter) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, + new->video_spatial_filter, new->video_temporal_filter); + if (err) return err; + } + if (old == NULL || old->video_temporal_decimation != new->video_temporal_decimation) { + err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_DROP_RATE, 1, + new->video_temporal_decimation); + if (err) return err; + } + return 0; +} + +static const char *cx2341x_menu_item(struct cx2341x_mpeg_params *p, u32 id) +{ + const char **menu = cx2341x_ctrl_get_menu(id); + struct v4l2_ext_control ctrl; + + if (menu == NULL) + goto invalid; + ctrl.id = id; + if (cx2341x_get_ctrl(p, &ctrl)) + goto invalid; + while (ctrl.value-- && *menu) menu++; + if (*menu == NULL) + goto invalid; + return *menu; + +invalid: + return "<invalid>"; +} + +void cx2341x_log_status(struct cx2341x_mpeg_params *p, int card_id) +{ + int is_mpeg1 = p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; + + /* Stream */ + printk(KERN_INFO "cx2341x-%d: Stream: %s\n", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_STREAM_TYPE)); + + /* Video */ + printk(KERN_INFO "cx2341x-%d: Video: %dx%d, %d fps\n", + card_id, + p->width / (is_mpeg1 ? 2 : 1), p->height / (is_mpeg1 ? 2 : 1), + p->is_50hz ? 25 : 30); + printk(KERN_INFO "cx2341x-%d: Video: %s, %s, %s, %d", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_ENCODING), + cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_ASPECT), + cx2341x_menu_item(p, V4L2_CID_MPEG_VIDEO_BITRATE_MODE), + p->video_bitrate); + if (p->video_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { + printk(", Peak %d", p->video_bitrate_peak); + } + printk("\n"); + printk(KERN_INFO "cx2341x-%d: Video: GOP Size %d, %d B-Frames, %sGOP Closure, %s3:2 Pulldown\n", + card_id, + p->video_gop_size, p->video_b_frames, + p->video_gop_closure ? "" : "No ", + p->video_pulldown ? "" : "No "); + if (p->video_temporal_decimation) { + printk(KERN_INFO "cx2341x-%d: Video: Temporal Decimation %d\n", + card_id, p->video_temporal_decimation); + } + + /* Audio */ + printk(KERN_INFO "cx2341x-%d: Audio: %s, %s, %s, %s", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ), + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_ENCODING), + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_L2_BITRATE), + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE)); + if (p->audio_mode == V4L2_MPEG_AUDIO_MODE_JOINT_STEREO) { + printk(", %s", + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_MODE_EXTENSION)); + } + printk(", %s, %s\n", + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_EMPHASIS), + cx2341x_menu_item(p, V4L2_CID_MPEG_AUDIO_CRC)); + + /* Encoding filters */ + printk(KERN_INFO "cx2341x-%d: Spatial Filter: %s, Luma %s, Chroma %s, %d\n", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE), + cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE), + cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE), + p->video_spatial_filter); + printk(KERN_INFO "cx2341x-%d: Temporal Filter: %s, %d\n", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE), + p->video_temporal_filter); + printk(KERN_INFO "cx2341x-%d: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n", + card_id, + cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE), + p->video_luma_median_filter_bottom, + p->video_luma_median_filter_top, + p->video_chroma_median_filter_bottom, + p->video_chroma_median_filter_top); +} + +EXPORT_SYMBOL(cx2341x_fill_defaults); +EXPORT_SYMBOL(cx2341x_ctrl_query); +EXPORT_SYMBOL(cx2341x_ctrl_get_menu); +EXPORT_SYMBOL(cx2341x_ext_ctrls); +EXPORT_SYMBOL(cx2341x_update); +EXPORT_SYMBOL(cx2341x_log_status); +EXPORT_SYMBOL(cx2341x_mpeg_ctrls); + +/* + * Local variables: + * c-basic-offset: 8 + * End: + */ + diff --git a/linux/drivers/media/video/cx25840/cx25840-core.c b/linux/drivers/media/video/cx25840/cx25840-core.c index 16c8f9366..6558e317a 100644 --- a/linux/drivers/media/video/cx25840/cx25840-core.c +++ b/linux/drivers/media/video/cx25840/cx25840-core.c @@ -628,95 +628,6 @@ static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) /* ----------------------------------------------------------------------- */ -static struct v4l2_queryctrl cx25836_qctrl[] = { - { - .id = V4L2_CID_BRIGHTNESS, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Brightness", - .minimum = 0, - .maximum = 255, - .step = 1, - .default_value = 128, - .flags = 0, - }, { - .id = V4L2_CID_CONTRAST, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Contrast", - .minimum = 0, - .maximum = 127, - .step = 1, - .default_value = 64, - .flags = 0, - }, { - .id = V4L2_CID_SATURATION, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Saturation", - .minimum = 0, - .maximum = 127, - .step = 1, - .default_value = 64, - .flags = 0, - }, { - .id = V4L2_CID_HUE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Hue", - .minimum = -128, - .maximum = 127, - .step = 1, - .default_value = 0, - .flags = 0, - }, -}; - -static struct v4l2_queryctrl cx25840_qctrl[] = { - { - .id = V4L2_CID_AUDIO_VOLUME, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Volume", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 58880, - .flags = 0, - }, { - .id = V4L2_CID_AUDIO_BALANCE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Balance", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - .flags = 0, - }, { - .id = V4L2_CID_AUDIO_MUTE, - .type = V4L2_CTRL_TYPE_BOOLEAN, - .name = "Mute", - .minimum = 0, - .maximum = 1, - .step = 1, - .default_value = 1, - .flags = 0, - }, { - .id = V4L2_CID_AUDIO_BASS, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Bass", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - }, { - .id = V4L2_CID_AUDIO_TREBLE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Treble", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - }, -}; - -/* ----------------------------------------------------------------------- */ - static int cx25840_command(struct i2c_client *client, unsigned int cmd, void *arg) { @@ -784,21 +695,29 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd, case VIDIOC_QUERYCTRL: { struct v4l2_queryctrl *qc = arg; - int i; - for (i = 0; i < ARRAY_SIZE(cx25836_qctrl); i++) - if (qc->id && qc->id == cx25836_qctrl[i].id) { - memcpy(qc, &cx25836_qctrl[i], sizeof(*qc)); - return 0; - } + switch (qc->id) { + case V4L2_CID_BRIGHTNESS: + case V4L2_CID_CONTRAST: + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + return v4l2_ctrl_query_fill_std(qc); + default: + break; + } if (state->is_cx25836) return -EINVAL; - for (i = 0; i < ARRAY_SIZE(cx25840_qctrl); i++) - if (qc->id && qc->id == cx25840_qctrl[i].id) { - memcpy(qc, &cx25840_qctrl[i], sizeof(*qc)); - return 0; - } + switch (qc->id) { + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_MUTE: + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + return v4l2_ctrl_query_fill_std(qc); + default: + return -EINVAL; + } return -EINVAL; } diff --git a/linux/drivers/media/video/cx88/Kconfig b/linux/drivers/media/video/cx88/Kconfig index c092d2219..91e1c481a 100644 --- a/linux/drivers/media/video/cx88/Kconfig +++ b/linux/drivers/media/video/cx88/Kconfig @@ -11,6 +11,7 @@ config VIDEO_CX88 select VIDEO_BUF select VIDEO_TUNER select VIDEO_TVEEPROM + select VIDEO_CX2341X select VIDEO_IR ---help--- This is a video4linux driver for Conexant 2388x based diff --git a/linux/drivers/media/video/cx88/cx88-blackbird.c b/linux/drivers/media/video/cx88/cx88-blackbird.c index 05904b655..d6d19a71e 100644 --- a/linux/drivers/media/video/cx88/cx88-blackbird.c +++ b/linux/drivers/media/video/cx88/cx88-blackbird.c @@ -90,163 +90,11 @@ enum blackbird_framerate { BLACKBIRD_FRAMERATE_NTSC_30, /* NTSC: 30fps */ BLACKBIRD_FRAMERATE_PAL_25 /* PAL: 25fps */ }; -enum blackbird_video_bitrate_type { - BLACKBIRD_VIDEO_VBR, - BLACKBIRD_VIDEO_CBR -}; -#define BLACKBIRD_PEAK_RATE_DIVISOR 400 -enum blackbird_mux_rate { - BLACKBIRD_MUX_RATE_DEFAULT, - /* dvd mux rate: multiply by 400 to get the actual rate */ - BLACKBIRD_MUX_RATE_DVD = 25200 -}; -enum blackbird_aspect_ratio { - BLACKBIRD_ASPECT_RATIO_FORBIDDEN, - BLACKBIRD_ASPECT_RATIO_1_1_SQUARE, - BLACKBIRD_ASPECT_RATIO_4_3, - BLACKBIRD_ASPECT_RATIO_16_9, - BLACKBIRD_ASPECT_RATIO_221_100, - BLACKBIRD_ASPECT_RATIO_RESERVED -}; -enum blackbird_dnr_bits { - BLACKBIRD_DNR_BITS_MANUAL, - BLACKBIRD_DNR_BITS_AUTO_SPATIAL, - BLACKBIRD_DNR_BITS_AUTO_TEMPORAL, - BLACKBIRD_DNR_BITS_AUTO -}; -enum blackbird_median_filter { - BLACKBIRD_MEDIAN_FILTER_DISABLED, - BLACKBIRD_MEDIAN_FILTER_HORIZONTAL, - BLACKBIRD_MEDIAN_FILTER_VERTICAL, - BLACKBIRD_MEDIAN_FILTER_HV, - BLACKBIRD_MEDIAN_FILTER_DIAGONAL -}; -enum blackbird_spatial_filter_luma { - BLACKBIRD_SPATIAL_FILTER_LUMA_DISABLED, - BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ, - BLACKBIRD_SPATIAL_FILTER_LUMA_1D_VERT, - BLACKBIRD_SPATIAL_FILTER_LUMA_2D_HV, /* separable, default */ - BLACKBIRD_SPATIAL_FILTER_LUMA_2D_SYMM /* symmetric non-separable */ -}; -enum blackbird_spatial_filter_chroma { - BLACKBIRD_SPATIAL_FILTER_CHROMA_DISABLED, - BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ /* default */ -}; -enum blackbird_pulldown { - BLACKBIRD_3_2_PULLDOWN_DISABLED, - BLACKBIRD_3_2_PULLDOWN_ENABLED -}; -enum blackbird_vbi_line_bits { - BLACKBIRD_VBI_LINE_BITS_TOP_FIELD, - BLACKBIRD_VBI_LINE_BITS_BOT_FIELD = (1 << 31), - BLACKBIRD_VBI_LINE_BITS_ALL_LINES = 0xFFFFFFFF -}; -enum blackbird_vbi_line { - BLACKBIRD_VBI_LINE_DISABLED, - BLACKBIRD_VBI_LINE_ENABLED -}; -enum blackbird_vbi_slicing { - BLACKBIRD_VBI_SLICING_NONE, - BLACKBIRD_VBI_SLICING_CLOSED_CAPTION -}; -enum blackbird_stream_type { - BLACKBIRD_STREAM_PROGRAM, - BLACKBIRD_STREAM_TRANSPORT, - BLACKBIRD_STREAM_MPEG1, - BLACKBIRD_STREAM_PES_AV, - BLACKBIRD_STREAM_UNKNOWN4, - BLACKBIRD_STREAM_PES_VIDEO, - BLACKBIRD_STREAM_UNKNOWN6, - BLACKBIRD_STREAM_PES_AUDIO, - BLACKBIRD_STREAM_UNKNOWN8, - BLACKBIRD_STREAM_UNKNOWN9, /* audio/pcm ? */ - BLACKBIRD_STREAM_DVD, - BLACKBIRD_STREAM_VCD, - BLACKBIRD_STREAM_UNKNOWN12 /* svcd/xvcd ? */ -}; enum blackbird_stream_port { BLACKBIRD_OUTPUT_PORT_MEMORY, BLACKBIRD_OUTPUT_PORT_STREAMING, BLACKBIRD_OUTPUT_PORT_SERIAL }; -enum blackbird_audio_bits_sample_rate { - BLACKBIRD_AUDIO_BITS_44100HZ, - BLACKBIRD_AUDIO_BITS_48000HZ, - BLACKBIRD_AUDIO_BITS_32000HZ, - BLACKBIRD_AUDIO_BITS_RESERVED_HZ, -}; -enum blackbird_audio_bits_encoding { - BLACKBIRD_AUDIO_BITS_LAYER_1 = 0x1 << 2, - BLACKBIRD_AUDIO_BITS_LAYER_2 = 0x2 << 2, -}; -enum blackbird_audio_bits_bitrate_layer_1 { - BLACKBIRD_AUDIO_BITS_LAYER_1_FREE_FORMAT, - BLACKBIRD_AUDIO_BITS_LAYER_1_32 = 0x01 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_64 = 0x02 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_96 = 0x03 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_128 = 0x04 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_160 = 0x05 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_192 = 0x06 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_224 = 0x07 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_256 = 0x08 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_288 = 0x09 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_320 = 0x0A << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_352 = 0x0B << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_384 = 0x0C << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_416 = 0x0D << 4, - BLACKBIRD_AUDIO_BITS_LAYER_1_448 = 0x0E << 4, -}; -enum blackbird_audio_bits_bitrate_layer_2 { - BLACKBIRD_AUDIO_BITS_LAYER_2_FREE_FORMAT, - BLACKBIRD_AUDIO_BITS_LAYER_2_32 = 0x01 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_48 = 0x02 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_56 = 0x03 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_64 = 0x04 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_80 = 0x05 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_96 = 0x06 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_112 = 0x07 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_128 = 0x08 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_160 = 0x09 << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_192 = 0x0A << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_224 = 0x0B << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_256 = 0x0C << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_320 = 0x0D << 4, - BLACKBIRD_AUDIO_BITS_LAYER_2_384 = 0x0E << 4, -}; -enum blackbird_audio_bits_mode { - BLACKBIRD_AUDIO_BITS_STEREO, - BLACKBIRD_AUDIO_BITS_JOINT_STEREO = 0x1 << 8, - BLACKBIRD_AUDIO_BITS_DUAL = 0x2 << 8, - BLACKBIRD_AUDIO_BITS_MONO = 0x3 << 8, -}; -enum blackbird_audio_bits_mode_extension { - BLACKBIRD_AUDIO_BITS_BOUND_4, - BLACKBIRD_AUDIO_BITS_BOUND_8 = 0x1 << 10, - BLACKBIRD_AUDIO_BITS_BOUND_12 = 0x2 << 10, - BLACKBIRD_AUDIO_BITS_BOUND_16 = 0x3 << 10, -}; -enum blackbird_audio_bits_emphasis { - BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE, - BLACKBIRD_AUDIO_BITS_EMPHASIS_50_15 = 0x1 << 12, - BLACKBIRD_AUDIO_BITS_EMPHASIS_RESERVED = 0x2 << 12, - BLACKBIRD_AUDIO_BITS_EMPHASIS_CCITT_J17 = 0x3 << 12, -}; -enum blackbird_audio_bits_crc { - BLACKBIRD_AUDIO_BITS_CRC_OFF, - BLACKBIRD_AUDIO_BITS_CRC_ON = 0x1 << 14, -}; -enum blackbird_audio_bits_copyright { - BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF, - BLACKBIRD_AUDIO_BITS_COPYRIGHT_ON = 0x1 << 15, -}; -enum blackbird_audio_bits_original { - BLACKBIRD_AUDIO_BITS_COPY, - BLACKBIRD_AUDIO_BITS_ORIGINAL = 0x1 << 16, -}; -enum blackbird_gop_closure { - BLACKBIRD_GOP_CLOSURE_OFF, - BLACKBIRD_GOP_CLOSURE_ON, -}; enum blackbird_data_xfer_status { BLACKBIRD_MORE_BUFFERS_FOLLOW, BLACKBIRD_LAST_BUFFER, @@ -464,15 +312,12 @@ static int register_read(struct cx88_core *core, u32 address, u32 *value) /* ------------------------------------------------------------------ */ -/* We don't need to call the API often, so using just one mailbox will probably suffice */ -static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, - u32 inputcnt, u32 outputcnt, ...) +static int blackbird_mbox_func(void *priv, int command, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]) { + struct cx8802_dev *dev = priv; unsigned long timeout; u32 value, flag, retval; int i; - va_list args; - va_start(args, outputcnt); dprintk(1,"%s: 0x%X\n", __FUNCTION__, command); @@ -496,12 +341,11 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, /* write command + args + fill remaining with zeros */ memory_write(dev->core, dev->mailbox + 1, command); /* command code */ memory_write(dev->core, dev->mailbox + 3, IVTV_API_STD_TIMEOUT); /* timeout */ - for (i = 0; i < inputcnt ; i++) { - value = va_arg(args, int); - memory_write(dev->core, dev->mailbox + 4 + i, value); - dprintk(1, "API Input %d = %d\n", i, value); + for (i = 0; i < in; i++) { + memory_write(dev->core, dev->mailbox + 4 + i, data[i]); + dprintk(1, "API Input %d = %d\n", i, data[i]); } - for (; i < 16 ; i++) + for (; i < CX2341X_MBOX_MAX_DATA; i++) memory_write(dev->core, dev->mailbox + 4 + i, 0); flag |= 3; /* tell 'em we're done writing */ @@ -521,12 +365,10 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, } /* read output values */ - for (i = 0; i < outputcnt ; i++) { - int *vptr = va_arg(args, int *); - memory_read(dev->core, dev->mailbox + 4 + i, vptr); - dprintk(1, "API Output %d = %d\n", i, *vptr); + for (i = 0; i < out; i++) { + memory_read(dev->core, dev->mailbox + 4 + i, data + i); + dprintk(1, "API Output %d = %d\n", i, data[i]); } - va_end(args); memory_read(dev->core, dev->mailbox + 2, &retval); dprintk(1, "API result = %d\n",retval); @@ -535,7 +377,29 @@ static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, memory_write(dev->core, dev->mailbox, flag); return retval; } +/* ------------------------------------------------------------------ */ + +/* We don't need to call the API often, so using just one mailbox will probably suffice */ +static int blackbird_api_cmd(struct cx8802_dev *dev, u32 command, + u32 inputcnt, u32 outputcnt, ...) +{ + u32 data[CX2341X_MBOX_MAX_DATA]; + va_list vargs; + int i, err; + va_start(vargs, outputcnt); + + for (i = 0; i < inputcnt; i++) { + data[i] = va_arg(vargs, int); + } + err = blackbird_mbox_func(dev, command, inputcnt, outputcnt, data); + for (i = 0; i < outputcnt; i++) { + int *vptr = va_arg(vargs, int *); + *vptr = data[i]; + } + va_end(vargs); + return err; +} static int blackbird_find_mailbox(struct cx8802_dev *dev) { @@ -657,12 +521,19 @@ DB* DVD | MPEG2 | 720x576PAL | CBR | 600 :Good | 6000 Kbps | 25fps | M *DB: "DirectBurn" */ -static struct blackbird_dnr default_dnr_params = { - .mode = BLACKBIRD_DNR_BITS_MANUAL, - .type = BLACKBIRD_MEDIAN_FILTER_DISABLED, - .spatial = 0, - .temporal = 0 -}; +static void blackbird_codec_settings(struct cx8802_dev *dev) +{ + /* assign frame size */ + blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, + dev->height, dev->width); + + dev->params.width = dev->width; + dev->params.height = dev->height; + dev->params.is_50hz = (dev->core->tvnorm->id & V4L2_STD_625_50) != 0; + + cx2341x_update(dev, blackbird_mbox_func, NULL, &dev->params); +} + static struct v4l2_mpeg_compression default_mpeg_params = { .st_type = V4L2_MPEG_PS_2, .st_bitrate = { @@ -683,7 +554,7 @@ static struct v4l2_mpeg_compression default_mpeg_params = { .target = 224, .max = 224 }, - .au_sample_rate = 44100, + .au_sample_rate = 48000, .au_pesid = 0, .vi_type = V4L2_MPEG_VI_2, .vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3, @@ -694,524 +565,13 @@ static struct v4l2_mpeg_compression default_mpeg_params = { .max = 6000 }, .vi_frame_rate = 25, - .vi_frames_per_gop = 15, + .vi_frames_per_gop = 12, .vi_bframes_count = 2, .vi_pesid = 0, - .closed_gops = 0, + .closed_gops = 1, .pulldown = 0 }; -static enum blackbird_stream_type mpeg_stream_types[] = { - [V4L2_MPEG_SS_1] = BLACKBIRD_STREAM_MPEG1, - [V4L2_MPEG_PS_2] = BLACKBIRD_STREAM_PROGRAM, - [V4L2_MPEG_TS_2] = BLACKBIRD_STREAM_TRANSPORT, - [V4L2_MPEG_PS_DVD] = BLACKBIRD_STREAM_DVD, -}; -static enum blackbird_aspect_ratio mpeg_stream_ratios[] = { - [V4L2_MPEG_ASPECT_SQUARE] = BLACKBIRD_ASPECT_RATIO_1_1_SQUARE, - [V4L2_MPEG_ASPECT_4_3] = BLACKBIRD_ASPECT_RATIO_4_3, - [V4L2_MPEG_ASPECT_16_9] = BLACKBIRD_ASPECT_RATIO_16_9, - [V4L2_MPEG_ASPECT_1_221] = BLACKBIRD_ASPECT_RATIO_221_100, -}; -static enum blackbird_video_bitrate_type mpeg_video_bitrates[] = { - [V4L2_BITRATE_NONE] = BLACKBIRD_VIDEO_CBR, - [V4L2_BITRATE_CBR] = BLACKBIRD_VIDEO_CBR, - [V4L2_BITRATE_VBR] = BLACKBIRD_VIDEO_VBR, -}; -/* find the best layer I/II bitrate to fit a given numeric value */ -struct bitrate_bits { - u32 bits; /* layer bits for the best fit */ - u32 rate; /* actual numeric value for the layer best fit */ -}; -struct bitrate_approximation { - u32 target; /* numeric value of the rate we want */ - struct bitrate_bits layer[2]; -}; -static struct bitrate_approximation mpeg_audio_bitrates[] = { - /* target layer[0].bits layer[0].rate layer[1].bits layer[1].rate */ - { 0, { { 0, 0, }, { 0, 0, }, }, }, - { 32, { { BLACKBIRD_AUDIO_BITS_LAYER_1_32 , 32, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_32 , 32, }, }, }, - { 48, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_48 , 48, }, }, }, - { 56, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_56 , 56, }, }, }, - { 64, { { BLACKBIRD_AUDIO_BITS_LAYER_1_64 , 64, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_64 , 64, }, }, }, - { 80, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_80 , 80, }, }, }, - { 96, { { BLACKBIRD_AUDIO_BITS_LAYER_1_96 , 96, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_96 , 96, }, }, }, - { 112, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_112, 112, }, }, }, - { 128, { { BLACKBIRD_AUDIO_BITS_LAYER_1_128, 128, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_128, 128, }, }, }, - { 160, { { BLACKBIRD_AUDIO_BITS_LAYER_1_160, 160, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_160, 160, }, }, }, - { 192, { { BLACKBIRD_AUDIO_BITS_LAYER_1_192, 192, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_192, 192, }, }, }, - { 224, { { BLACKBIRD_AUDIO_BITS_LAYER_1_224, 224, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_224, 224, }, }, }, - { 256, { { BLACKBIRD_AUDIO_BITS_LAYER_1_256, 256, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_256, 256, }, }, }, - { 288, { { BLACKBIRD_AUDIO_BITS_LAYER_1_288, 288, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, }, - { 320, { { BLACKBIRD_AUDIO_BITS_LAYER_1_320, 320, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_320, 320, }, }, }, - { 352, { { BLACKBIRD_AUDIO_BITS_LAYER_1_352, 352, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, - { 384, { { BLACKBIRD_AUDIO_BITS_LAYER_1_384, 384, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, - { 416, { { BLACKBIRD_AUDIO_BITS_LAYER_1_416, 416, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, - { 448, { { BLACKBIRD_AUDIO_BITS_LAYER_1_448, 448, }, { BLACKBIRD_AUDIO_BITS_LAYER_2_384, 384, }, }, }, -}; -static const int BITRATES_SIZE = ARRAY_SIZE(mpeg_audio_bitrates); - -static void blackbird_set_default_params(struct cx8802_dev *dev) -{ - struct v4l2_mpeg_compression *params = &dev->params; - u32 au_params; - - /* assign stream type */ - if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) ) - params->st_type = V4L2_MPEG_PS_2; - if( params->st_type == V4L2_MPEG_SS_1 ) - params->vi_type = V4L2_MPEG_VI_1; - else - params->vi_type = V4L2_MPEG_VI_2; - blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]); - - /* assign framerate */ - if( params->vi_frame_rate <= 25 ) - { - params->vi_frame_rate = 25; - blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25); - } - else - { - params->vi_frame_rate = 30; - blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30); - } - - /* assign aspect ratio */ - if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) ) - params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3; - blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]); - - /* assign gop properties */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1); - - /* assign gop closure */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops); - - /* assign 3 2 pulldown */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown); - - /* make sure the params are within bounds */ - if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->vi_bitrate.mode = V4L2_BITRATE_NONE; - if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->vi_bitrate.mode = V4L2_BITRATE_NONE; - if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->au_bitrate.mode = V4L2_BITRATE_NONE; - - /* assign audio properties */ - /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */ - au_params = BLACKBIRD_AUDIO_BITS_STEREO | - /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */ - BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE | - BLACKBIRD_AUDIO_BITS_CRC_OFF | - BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF | - BLACKBIRD_AUDIO_BITS_COPY | - 0; - if( params->au_sample_rate <= 32000 ) - { - params->au_sample_rate = 32000; - au_params |= BLACKBIRD_AUDIO_BITS_32000HZ; - } - else if( params->au_sample_rate <= 44100 ) - { - params->au_sample_rate = 44100; - au_params |= BLACKBIRD_AUDIO_BITS_44100HZ; - } - else - { - params->au_sample_rate = 48000; - au_params |= BLACKBIRD_AUDIO_BITS_48000HZ; - } - if( params->au_type == V4L2_MPEG_AU_2_I ) - { - au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1; - } - else - { - /* TODO: try to handle the other formats more gracefully */ - params->au_type = V4L2_MPEG_AU_2_II; - au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2; - } - if( params->au_bitrate.mode ) - { - int layer; - - if( params->au_bitrate.mode == V4L2_BITRATE_CBR ) - params->au_bitrate.max = params->vi_bitrate.target; - else - params->au_bitrate.target = params->vi_bitrate.max; - - layer = params->au_type; - if( params->au_bitrate.target == 0 ) - { - /* TODO: use the minimum possible bitrate instead of 0 ? */ - au_params |= 0; - } - else if( params->au_bitrate.target >= - mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate ) - { - /* clamp the bitrate to the max supported by the standard */ - params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate; - params->au_bitrate.max = params->au_bitrate.target; - au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits; - } - else - { - /* round up to the nearest supported bitrate */ - int i; - for(i = 1; i < BITRATES_SIZE; i++) - { - if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate && - params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate ) - { - params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate; - params->au_bitrate.max = params->au_bitrate.target; - au_params |= mpeg_audio_bitrates[i].layer[layer].bits; - break; - } - } - } - } - else - { - /* TODO: ??? */ - params->au_bitrate.target = params->au_bitrate.max = 0; - au_params |= 0; - } - blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params ); - - /* assign bitrates */ - if( params->vi_bitrate.mode ) - { - /* bitrate is set, let's figure out the cbr/vbr mess */ - if( params->vi_bitrate.max < params->vi_bitrate.target ) - { - if( params->vi_bitrate.mode == V4L2_BITRATE_CBR ) - params->vi_bitrate.max = params->vi_bitrate.target; - else - params->vi_bitrate.target = params->vi_bitrate.max; - } - } - else - { - if( params->st_bitrate.max < params->st_bitrate.target ) - { - if( params->st_bitrate.mode == V4L2_BITRATE_VBR ) - params->st_bitrate.target = params->st_bitrate.max; - else - params->st_bitrate.max = params->st_bitrate.target; - } - /* calculate vi_bitrate = st_bitrate - au_bitrate */ - params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max; - params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target; - } - blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0, - mpeg_video_bitrates[params->vi_bitrate.mode], - params->vi_bitrate.target * 1000, /* kbps -> bps */ - params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */ - BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */ - - /* TODO: implement the stream ID stuff: - ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr, - ps_size, au_pesid, vi_pesid - */ -} -#define CHECK_PARAM( name ) ( dev->params.name != params->name ) -#define IF_PARAM( name ) if( CHECK_PARAM( name ) ) -#define UPDATE_PARAM( name ) dev->params.name = params->name -void blackbird_set_params(struct cx8802_dev *dev, struct v4l2_mpeg_compression *params) -{ - u32 au_params; - - /* assign stream type */ - if( params->st_type >= ARRAY_SIZE(mpeg_stream_types) ) - params->st_type = V4L2_MPEG_PS_2; - if( params->st_type == V4L2_MPEG_SS_1 ) - params->vi_type = V4L2_MPEG_VI_1; - else - params->vi_type = V4L2_MPEG_VI_2; - if( CHECK_PARAM( st_type ) || CHECK_PARAM( vi_type ) ) - { - UPDATE_PARAM( st_type ); - UPDATE_PARAM( vi_type ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_STREAM_TYPE, 1, 0, mpeg_stream_types[params->st_type]); - } - - /* assign framerate */ - if( params->vi_frame_rate <= 25 ) - params->vi_frame_rate = 25; - else - params->vi_frame_rate = 30; - IF_PARAM( vi_frame_rate ) - { - UPDATE_PARAM( vi_frame_rate ); - if( params->vi_frame_rate == 25 ) - blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_PAL_25); - else - blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_RATE, 1, 0, BLACKBIRD_FRAMERATE_NTSC_30); - } - - /* assign aspect ratio */ - if( params->vi_aspect_ratio >= ARRAY_SIZE(mpeg_stream_ratios) ) - params->vi_aspect_ratio = V4L2_MPEG_ASPECT_4_3; - IF_PARAM( vi_aspect_ratio ) - { - UPDATE_PARAM( vi_aspect_ratio ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_ASPECT_RATIO, 1, 0, mpeg_stream_ratios[params->vi_aspect_ratio]); - } - - /* assign gop properties */ - if( CHECK_PARAM( vi_frames_per_gop ) || CHECK_PARAM( vi_bframes_count ) ) - { - UPDATE_PARAM( vi_frames_per_gop ); - UPDATE_PARAM( vi_bframes_count ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_PROPERTIES, 2, 0, params->vi_frames_per_gop, params->vi_bframes_count+1); - } - - /* assign gop closure */ - IF_PARAM( closed_gops ) - { - UPDATE_PARAM( closed_gops ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_GOP_CLOSURE, 1, 0, params->closed_gops); - } - - /* assign 3 2 pulldown */ - IF_PARAM( pulldown ) - { - UPDATE_PARAM( pulldown ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_3_2_PULLDOWN, 1, 0, params->pulldown); - } - - /* make sure the params are within bounds */ - if( params->st_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->vi_bitrate.mode = V4L2_BITRATE_NONE; - if( params->vi_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->vi_bitrate.mode = V4L2_BITRATE_NONE; - if( params->au_bitrate.mode >= ARRAY_SIZE(mpeg_video_bitrates) ) - params->au_bitrate.mode = V4L2_BITRATE_NONE; - - /* assign audio properties */ - /* note: it's not necessary to set the samplerate, the mpeg encoder seems to autodetect/adjust */ - au_params = BLACKBIRD_AUDIO_BITS_STEREO | - /* BLACKBIRD_AUDIO_BITS_BOUND_4 | */ - BLACKBIRD_AUDIO_BITS_EMPHASIS_NONE | - BLACKBIRD_AUDIO_BITS_CRC_OFF | - BLACKBIRD_AUDIO_BITS_COPYRIGHT_OFF | - BLACKBIRD_AUDIO_BITS_COPY | - 0; - if( params->au_sample_rate < 32000 ) - { - params->au_sample_rate = 32000; - au_params |= BLACKBIRD_AUDIO_BITS_32000HZ; - } - else if( params->au_sample_rate < 44100 ) - { - params->au_sample_rate = 44100; - au_params |= BLACKBIRD_AUDIO_BITS_44100HZ; - } - else - { - params->au_sample_rate = 48000; - au_params |= BLACKBIRD_AUDIO_BITS_48000HZ; - } - if( params->au_type == V4L2_MPEG_AU_2_I ) - { - au_params |= BLACKBIRD_AUDIO_BITS_LAYER_1; - } - else - { - /* TODO: try to handle the other formats more gracefully */ - params->au_type = V4L2_MPEG_AU_2_II; - au_params |= BLACKBIRD_AUDIO_BITS_LAYER_2; - } - if( params->au_bitrate.mode ) - { - int layer; - - if( params->au_bitrate.mode == V4L2_BITRATE_CBR ) - params->au_bitrate.max = params->vi_bitrate.target; - else - params->au_bitrate.target = params->vi_bitrate.max; - - layer = params->au_type; - if( params->au_bitrate.target == 0 ) - { - /* TODO: use the minimum possible bitrate instead of 0 ? */ - au_params |= 0; - } - else if( params->au_bitrate.target >= - mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate ) - { - /* clamp the bitrate to the max supported by the standard */ - params->au_bitrate.target = mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].rate; - params->au_bitrate.max = params->au_bitrate.target; - au_params |= mpeg_audio_bitrates[BITRATES_SIZE-1].layer[layer].bits; - } - else - { - /* round up to the nearest supported bitrate */ - int i; - for(i = 1; i < BITRATES_SIZE; i++) - { - if( params->au_bitrate.target > mpeg_audio_bitrates[i-1].layer[layer].rate && - params->au_bitrate.target <= mpeg_audio_bitrates[i].layer[layer].rate ) - { - params->au_bitrate.target = mpeg_audio_bitrates[i].layer[layer].rate; - params->au_bitrate.max = params->au_bitrate.target; - au_params |= mpeg_audio_bitrates[i].layer[layer].bits; - break; - } - } - } - } - else - { - /* TODO: ??? */ - params->au_bitrate.target = params->au_bitrate.max = 0; - au_params |= 0; - } - if( CHECK_PARAM( au_type ) || CHECK_PARAM( au_sample_rate ) - || CHECK_PARAM( au_bitrate.mode ) || CHECK_PARAM( au_bitrate.max ) - || CHECK_PARAM( au_bitrate.target ) - ) - { - UPDATE_PARAM( au_type ); - UPDATE_PARAM( au_sample_rate ); - UPDATE_PARAM( au_bitrate ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_AUDIO_PROPERTIES, 1, 0, au_params ); - } - - /* assign bitrates */ - if( params->vi_bitrate.mode ) - { - /* bitrate is set, let's figure out the cbr/vbr mess */ - if( params->vi_bitrate.max < params->vi_bitrate.target ) - { - if( params->vi_bitrate.mode == V4L2_BITRATE_CBR ) - params->vi_bitrate.max = params->vi_bitrate.target; - else - params->vi_bitrate.target = params->vi_bitrate.max; - } - } - else - { - if( params->st_bitrate.max < params->st_bitrate.target ) - { - if( params->st_bitrate.mode == V4L2_BITRATE_VBR ) - params->st_bitrate.target = params->st_bitrate.max; - else - params->st_bitrate.max = params->st_bitrate.target; - } - /* calculate vi_bitrate = st_bitrate - au_bitrate */ - params->vi_bitrate.max = params->st_bitrate.max - params->au_bitrate.max; - params->vi_bitrate.target = params->st_bitrate.target - params->au_bitrate.target; - } - UPDATE_PARAM( st_bitrate ); - if( CHECK_PARAM( vi_bitrate.mode ) || CHECK_PARAM( vi_bitrate.max ) - || CHECK_PARAM( vi_bitrate.target ) - ) - { - UPDATE_PARAM( vi_bitrate ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_BIT_RATE, 4, 0, - mpeg_video_bitrates[params->vi_bitrate.mode], - params->vi_bitrate.target * 1000, /* kbps -> bps */ - params->vi_bitrate.max * 1000 / BLACKBIRD_PEAK_RATE_DIVISOR, /* peak/400 */ - BLACKBIRD_MUX_RATE_DEFAULT /*, 0x70*/); /* encoding buffer, ckennedy */ - } - - /* TODO: implement the stream ID stuff: - ts_pid_pmt, ts_pid_audio, ts_pid_video, ts_pid_pcr, - ps_size, au_pesid, vi_pesid - */ - UPDATE_PARAM( ts_pid_pmt ); - UPDATE_PARAM( ts_pid_audio ); - UPDATE_PARAM( ts_pid_video ); - UPDATE_PARAM( ts_pid_pcr ); - UPDATE_PARAM( ps_size ); - UPDATE_PARAM( au_pesid ); - UPDATE_PARAM( vi_pesid ); -} - -static void blackbird_set_default_dnr_params(struct cx8802_dev *dev) -{ - /* assign dnr filter mode */ - if( dev->dnr_params.mode > BLACKBIRD_DNR_BITS_AUTO ) - dev->dnr_params.mode = BLACKBIRD_DNR_BITS_MANUAL; - if( dev->dnr_params.type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL ) - dev->dnr_params.type = BLACKBIRD_MEDIAN_FILTER_DISABLED; - blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0, - dev->dnr_params.mode, - dev->dnr_params.type - ); - - /* assign dnr filter props*/ - if( dev->dnr_params.spatial > 15 ) - dev->dnr_params.spatial = 15; - if( dev->dnr_params.temporal > 31 ) - dev->dnr_params.temporal = 31; - blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0, - dev->dnr_params.spatial, - dev->dnr_params.temporal - ); -} -#define CHECK_DNR_PARAM( name ) ( dev->dnr_params.name != dnr_params->name ) -#define UPDATE_DNR_PARAM( name ) dev->dnr_params.name = dnr_params->name -void blackbird_set_dnr_params(struct cx8802_dev *dev, struct blackbird_dnr* dnr_params) -{ - /* assign dnr filter mode */ - /* clamp values */ - if( dnr_params->mode > BLACKBIRD_DNR_BITS_AUTO ) - dnr_params->mode = BLACKBIRD_DNR_BITS_MANUAL; - if( dnr_params->type > BLACKBIRD_MEDIAN_FILTER_DIAGONAL ) - dnr_params->type = BLACKBIRD_MEDIAN_FILTER_DISABLED; - /* check if the params actually changed */ - if( CHECK_DNR_PARAM( mode ) || CHECK_DNR_PARAM( type ) ) - { - UPDATE_DNR_PARAM( mode ); - UPDATE_DNR_PARAM( type ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_MODE, 2, 0, dnr_params->mode, dnr_params->type); - } - - /* assign dnr filter props*/ - if( dnr_params->spatial > 15 ) - dnr_params->spatial = 15; - if( dnr_params->temporal > 31 ) - dnr_params->temporal = 31; - if( CHECK_DNR_PARAM( spatial ) || CHECK_DNR_PARAM( temporal ) ) - { - UPDATE_DNR_PARAM( spatial ); - UPDATE_DNR_PARAM( temporal ); - blackbird_api_cmd(dev, CX2341X_ENC_SET_DNR_FILTER_PROPS, 2, 0, dnr_params->spatial, dnr_params->temporal); - } -} - -static void blackbird_codec_settings(struct cx8802_dev *dev) -{ - - /* assign output port */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_OUTPUT_PORT, 1, 0, BLACKBIRD_OUTPUT_PORT_STREAMING); /* Host */ - - /* assign frame size */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0, - dev->height, dev->width); - - /* assign coring levels (luma_h, luma_l, chroma_h, chroma_l) */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_CORING_LEVELS, 4, 0, 0, 255, 0, 255); - - /* assign spatial filter type: luma_t: horiz_only, chroma_t: horiz_only */ - blackbird_api_cmd(dev, CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, 2, 0, - BLACKBIRD_SPATIAL_FILTER_LUMA_1D_HORIZ, - BLACKBIRD_SPATIAL_FILTER_CHROMA_1D_HORIZ - ); - - /* assign frame drop rate */ - /* blackbird_api_cmd(dev, IVTV_API_ASSIGN_FRAME_DROP_RATE, 1, 0, 0); */ - - blackbird_set_default_params(dev); - blackbird_set_default_dnr_params(dev); -} - static int blackbird_initialize_codec(struct cx8802_dev *dev) { struct cx88_core *core = dev->core; @@ -1478,15 +838,39 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file, { struct v4l2_mpeg_compression *f = arg; - memcpy(f,&dev->params,sizeof(*f)); + printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. " + "Replace with VIDIOC_G_EXT_CTRLS!"); + memcpy(f,&default_mpeg_params,sizeof(*f)); return 0; } case VIDIOC_S_MPEGCOMP: + printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. " + "Replace with VIDIOC_S_EXT_CTRLS!"); + return 0; + case VIDIOC_G_EXT_CTRLS: { - struct v4l2_mpeg_compression *f = arg; + struct v4l2_ext_controls *f = arg; - blackbird_set_params(dev, f); - return 0; + if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + return cx2341x_ext_ctrls(&dev->params, f, cmd); + } + case VIDIOC_S_EXT_CTRLS: + case VIDIOC_TRY_EXT_CTRLS: + { + struct v4l2_ext_controls *f = arg; + struct cx2341x_mpeg_params p; + int err; + + if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + p = dev->params; + err = cx2341x_ext_ctrls(&p, f, cmd); + if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) { + err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p); + dev->params = p; + } + return err; } case VIDIOC_S_FREQUENCY: { @@ -1691,26 +1075,22 @@ static int __devinit blackbird_probe(struct pci_dev *pci_dev, dev->core = core; dev->width = 720; dev->height = 576; - memcpy(&dev->params,&default_mpeg_params,sizeof(default_mpeg_params)); - memcpy(&dev->dnr_params,&default_dnr_params,sizeof(default_dnr_params)); + cx2341x_fill_defaults(&dev->params); + dev->params.port = CX2341X_PORT_STREAMING; switch (core->board) { case CX88_BOARD_HAUPPAUGE_ROSLYN: if (core->tuner_formats & V4L2_STD_525_60) { dev->height = 480; - dev->params.vi_frame_rate = 30; } else { dev->height = 576; - dev->params.vi_frame_rate = 25; } break; case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT: if (core->tvnorm->id & V4L2_STD_525_60) { dev->height = 480; - dev->params.vi_frame_rate = 30; } else { dev->height = 576; - dev->params.vi_frame_rate = 25; } break; } @@ -1818,8 +1198,6 @@ module_exit(blackbird_fini); EXPORT_SYMBOL(cx88_ioctl_hook); EXPORT_SYMBOL(cx88_ioctl_translator); -EXPORT_SYMBOL(blackbird_set_params); -EXPORT_SYMBOL(blackbird_set_dnr_params); /* ----------------------------------------------------------- */ /* diff --git a/linux/drivers/media/video/cx88/cx88.h b/linux/drivers/media/video/cx88/cx88.h index efeef4b47..c8049ec2b 100644 --- a/linux/drivers/media/video/cx88/cx88.h +++ b/linux/drivers/media/video/cx88/cx88.h @@ -29,6 +29,7 @@ #include <media/tuner.h> #include <media/tveeprom.h> #include <media/video-buf.h> +#include <media/cx2341x.h> #ifdef HAVE_VIDEO_BUF_DVB #include <media/video-buf-dvb.h> #endif @@ -432,14 +433,6 @@ struct cx8802_suspend_state { int disabled; }; -/* TODO: move this to struct v4l2_mpeg_compression ? */ -struct blackbird_dnr { - u32 mode; - u32 type; - u32 spatial; - u32 temporal; -}; - struct cx8802_dev { struct cx88_core *core; #if 0 @@ -479,8 +472,7 @@ struct cx8802_dev { unsigned char ts_gen_cntrl; /* mpeg params */ - struct v4l2_mpeg_compression params; - struct blackbird_dnr dnr_params; + struct cx2341x_mpeg_params params; }; /* ----------------------------------------------------------- */ @@ -645,10 +637,6 @@ extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio, extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file, unsigned int cmd, void *arg); extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd); -void blackbird_set_params(struct cx8802_dev *dev, - struct v4l2_mpeg_compression *params); -void blackbird_set_dnr_params(struct cx8802_dev *dev, - struct blackbird_dnr* dnr_params); /* * Local variables: diff --git a/linux/drivers/media/video/msp3400-driver.c b/linux/drivers/media/video/msp3400-driver.c index 837894adb..5e209a36b 100644 --- a/linux/drivers/media/video/msp3400-driver.c +++ b/linux/drivers/media/video/msp3400-driver.c @@ -437,67 +437,6 @@ static int msp_mode_v4l1_to_v4l2(int mode) return V4L2_TUNER_MODE_MONO; } -static struct v4l2_queryctrl msp_qctrl_std[] = { - { - .id = V4L2_CID_AUDIO_VOLUME, - .name = "Volume", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 58880, - .flags = 0, - .type = V4L2_CTRL_TYPE_INTEGER, - },{ - .id = V4L2_CID_AUDIO_MUTE, - .name = "Mute", - .minimum = 0, - .maximum = 1, - .step = 1, - .default_value = 1, - .flags = 0, - .type = V4L2_CTRL_TYPE_BOOLEAN, - }, -}; - -static struct v4l2_queryctrl msp_qctrl_sound_processing[] = { - { - .id = V4L2_CID_AUDIO_BALANCE, - .name = "Balance", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - .flags = 0, - .type = V4L2_CTRL_TYPE_INTEGER, - },{ - .id = V4L2_CID_AUDIO_BASS, - .name = "Bass", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - .type = V4L2_CTRL_TYPE_INTEGER, - },{ - .id = V4L2_CID_AUDIO_TREBLE, - .name = "Treble", - .minimum = 0, - .maximum = 65535, - .step = 65535/100, - .default_value = 32768, - .type = V4L2_CTRL_TYPE_INTEGER, - },{ - .id = V4L2_CID_AUDIO_LOUDNESS, - .name = "Loudness", - .minimum = 0, - .maximum = 1, - .step = 1, - .default_value = 1, - .flags = 0, - .type = V4L2_CTRL_TYPE_BOOLEAN, - }, -}; - - static int msp_get_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) { struct msp_state *state = i2c_get_clientdata(client); @@ -805,21 +744,25 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg) case VIDIOC_QUERYCTRL: { struct v4l2_queryctrl *qc = arg; - int i; - for (i = 0; i < ARRAY_SIZE(msp_qctrl_std); i++) - if (qc->id && qc->id == msp_qctrl_std[i].id) { - memcpy(qc, &msp_qctrl_std[i], sizeof(*qc)); - return 0; - } + switch (qc->id) { + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_MUTE: + return v4l2_ctrl_query_fill_std(qc); + default: + break; + } if (!state->has_sound_processing) return -EINVAL; - for (i = 0; i < ARRAY_SIZE(msp_qctrl_sound_processing); i++) - if (qc->id && qc->id == msp_qctrl_sound_processing[i].id) { - memcpy(qc, &msp_qctrl_sound_processing[i], sizeof(*qc)); - return 0; - } - return -EINVAL; + switch (qc->id) { + case V4L2_CID_AUDIO_LOUDNESS: + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + return v4l2_ctrl_query_fill_std(qc); + default: + return -EINVAL; + } } case VIDIOC_G_CTRL: diff --git a/linux/drivers/media/video/pvrusb2/Kconfig b/linux/drivers/media/video/pvrusb2/Kconfig index 4a7f88484..298b1c71a 100644 --- a/linux/drivers/media/video/pvrusb2/Kconfig +++ b/linux/drivers/media/video/pvrusb2/Kconfig @@ -4,6 +4,7 @@ config VIDEO_PVRUSB2 select FW_LOADER select VIDEO_TUNER select VIDEO_TVEEPROM + select VIDEO_CX2341X select VIDEO_SAA711X select VIDEO_MSP3400 ---help--- diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c index 6c66e258f..958500466 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c @@ -20,8 +20,10 @@ * */ +#include "compat.h" #include <linux/device.h> // for linux/firmware.h #include <linux/firmware.h> +#include <linux/videodev2.h> #include <media/cx2341x.h> #include "pvrusb2-util.h" #include "pvrusb2-encoder.h" diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c index 333419d6f..409343097 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c @@ -25,6 +25,7 @@ #include <linux/slab.h> #include <linux/firmware.h> #include <asm/semaphore.h> +#include <linux/videodev2.h> #include <media/cx2341x.h> #include "pvrusb2.h" #include "pvrusb2-std.h" diff --git a/linux/drivers/media/video/saa7115.c b/linux/drivers/media/video/saa7115.c index ea7c7c65b..fdfea3f16 100644 --- a/linux/drivers/media/video/saa7115.c +++ b/linux/drivers/media/video/saa7115.c @@ -1103,48 +1103,6 @@ static void saa7115_decode_vbi_line(struct i2c_client *client, /* ============ SAA7115 AUDIO settings (end) ============= */ -static struct v4l2_queryctrl saa7115_qctrl[] = { - { - .id = V4L2_CID_BRIGHTNESS, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Brightness", - .minimum = 0, - .maximum = 255, - .step = 1, - .default_value = 128, - .flags = 0, - }, { - .id = V4L2_CID_CONTRAST, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Contrast", - .minimum = 0, - .maximum = 127, - .step = 1, - .default_value = 64, - .flags = 0, - }, { - .id = V4L2_CID_SATURATION, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Saturation", - .minimum = 0, - .maximum = 127, - .step = 1, - .default_value = 64, - .flags = 0, - }, { - .id = V4L2_CID_HUE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Hue", - .minimum = -128, - .maximum = 127, - .step = 1, - .default_value = 0, - .flags = 0, - }, -}; - -/* ----------------------------------------------------------------------- */ - static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *arg) { struct saa7115_state *state = i2c_get_clientdata(client); @@ -1188,14 +1146,16 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar case VIDIOC_QUERYCTRL: { struct v4l2_queryctrl *qc = arg; - int i; - for (i = 0; i < ARRAY_SIZE(saa7115_qctrl); i++) - if (qc->id && qc->id == saa7115_qctrl[i].id) { - memcpy(qc, &saa7115_qctrl[i], sizeof(*qc)); - return 0; - } - return -EINVAL; + switch (qc->id) { + case V4L2_CID_BRIGHTNESS: + case V4L2_CID_CONTRAST: + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + return v4l2_ctrl_query_fill_std(qc); + default: + return -EINVAL; + } } case VIDIOC_G_STD: diff --git a/linux/drivers/media/video/saa7134/saa6752hs.c b/linux/drivers/media/video/saa7134/saa6752hs.c index 16685386c..0422e10e6 100644 --- a/linux/drivers/media/video/saa7134/saa6752hs.c +++ b/linux/drivers/media/video/saa7134/saa6752hs.c @@ -46,6 +46,23 @@ enum saa6752hs_videoformat { SAA6752HS_VF_UNKNOWN, }; +struct saa6752hs_mpeg_params { + /* transport streams */ + __u16 ts_pid_pmt; + __u16 ts_pid_audio; + __u16 ts_pid_video; + __u16 ts_pid_pcr; + + /* audio */ + enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate; + + /* video */ + enum v4l2_mpeg_video_aspect vi_aspect; + enum v4l2_mpeg_video_bitrate_mode vi_bitrate_mode; + __u32 vi_bitrate; + __u32 vi_bitrate_peak; +}; + static const struct v4l2_format v4l2_format_table[] = { [SAA6752HS_VF_D1] = @@ -62,7 +79,8 @@ static const struct v4l2_format v4l2_format_table[] = struct saa6752hs_state { struct i2c_client client; - struct v4l2_mpeg_compression params; + struct v4l2_mpeg_compression old_params; + struct saa6752hs_mpeg_params params; enum saa6752hs_videoformat video_format; v4l2_std_id standard; }; @@ -136,7 +154,22 @@ static u8 PMT[] = { 0x00, 0x00, 0x00, 0x00 /* CRC32 */ }; -static struct v4l2_mpeg_compression param_defaults = +static struct saa6752hs_mpeg_params param_defaults = +{ + .ts_pid_pmt = 16, + .ts_pid_video = 260, + .ts_pid_audio = 256, + .ts_pid_pcr = 259, + + .vi_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3, + .vi_bitrate = 4000, + .vi_bitrate_peak = 6000, + .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, + + .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K, +}; + +static struct v4l2_mpeg_compression old_param_defaults = { .st_type = V4L2_MPEG_TS_2, .st_bitrate = { @@ -239,45 +272,57 @@ static int saa6752hs_chip_command(struct i2c_client* client, static int saa6752hs_set_bitrate(struct i2c_client* client, - struct v4l2_mpeg_compression* params) + struct saa6752hs_mpeg_params* params) { u8 buf[3]; + int tot_bitrate; /* set the bitrate mode */ buf[0] = 0x71; - buf[1] = (params->vi_bitrate.mode == V4L2_BITRATE_VBR) ? 0 : 1; + buf[1] = (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) ? 0 : 1; i2c_master_send(client, buf, 2); /* set the video bitrate */ - if (params->vi_bitrate.mode == V4L2_BITRATE_VBR) { + if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { /* set the target bitrate */ buf[0] = 0x80; - buf[1] = params->vi_bitrate.target >> 8; - buf[2] = params->vi_bitrate.target & 0xff; + buf[1] = params->vi_bitrate >> 8; + buf[2] = params->vi_bitrate & 0xff; i2c_master_send(client, buf, 3); /* set the max bitrate */ buf[0] = 0x81; - buf[1] = params->vi_bitrate.max >> 8; - buf[2] = params->vi_bitrate.max & 0xff; + buf[1] = params->vi_bitrate_peak >> 8; + buf[2] = params->vi_bitrate_peak & 0xff; i2c_master_send(client, buf, 3); + tot_bitrate = params->vi_bitrate_peak; } else { /* set the target bitrate (no max bitrate for CBR) */ buf[0] = 0x81; - buf[1] = params->vi_bitrate.target >> 8; - buf[2] = params->vi_bitrate.target & 0xff; + buf[1] = params->vi_bitrate >> 8; + buf[2] = params->vi_bitrate & 0xff; i2c_master_send(client, buf, 3); + tot_bitrate = params->vi_bitrate; } /* set the audio bitrate */ buf[0] = 0x94; - buf[1] = (256 == params->au_bitrate.target) ? 0 : 1; + buf[1] = (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 0 : 1; i2c_master_send(client, buf, 2); + tot_bitrate += (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 256 : 384; + + /* Note: the total max bitrate is determined by adding the video and audio + bitrates together and also adding an extra 768kbit/s to stay on the + safe side. If more control should be required, then an extra MPEG control + should be added. */ + tot_bitrate += 768; + if (tot_bitrate > MPEG_TOTAL_TARGET_BITRATE_MAX) + tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX; /* set the total bitrate */ buf[0] = 0xb1; - buf[1] = params->st_bitrate.target >> 8; - buf[2] = params->st_bitrate.target & 0xff; + buf[1] = tot_bitrate >> 8; + buf[2] = tot_bitrate & 0xff; i2c_master_send(client, buf, 3); return 0; @@ -329,50 +374,188 @@ static void saa6752hs_set_subsampling(struct i2c_client* client, } -static void saa6752hs_set_params(struct i2c_client* client, +static void saa6752hs_old_set_params(struct i2c_client* client, struct v4l2_mpeg_compression* params) { struct saa6752hs_state *h = i2c_get_clientdata(client); /* check PIDs */ - if (params->ts_pid_pmt <= MPEG_PID_MAX) + if (params->ts_pid_pmt <= MPEG_PID_MAX) { + h->old_params.ts_pid_pmt = params->ts_pid_pmt; h->params.ts_pid_pmt = params->ts_pid_pmt; - if (params->ts_pid_pcr <= MPEG_PID_MAX) + } + if (params->ts_pid_pcr <= MPEG_PID_MAX) { + h->old_params.ts_pid_pcr = params->ts_pid_pcr; h->params.ts_pid_pcr = params->ts_pid_pcr; - if (params->ts_pid_video <= MPEG_PID_MAX) + } + if (params->ts_pid_video <= MPEG_PID_MAX) { + h->old_params.ts_pid_video = params->ts_pid_video; h->params.ts_pid_video = params->ts_pid_video; - if (params->ts_pid_audio <= MPEG_PID_MAX) + } + if (params->ts_pid_audio <= MPEG_PID_MAX) { + h->old_params.ts_pid_audio = params->ts_pid_audio; h->params.ts_pid_audio = params->ts_pid_audio; + } /* check bitrate parameters */ if ((params->vi_bitrate.mode == V4L2_BITRATE_CBR) || - (params->vi_bitrate.mode == V4L2_BITRATE_VBR)) - h->params.vi_bitrate.mode = params->vi_bitrate.mode; + (params->vi_bitrate.mode == V4L2_BITRATE_VBR)) { + h->old_params.vi_bitrate.mode = params->vi_bitrate.mode; + h->params.vi_bitrate_mode = (params->vi_bitrate.mode == V4L2_BITRATE_VBR) ? + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR : V4L2_MPEG_VIDEO_BITRATE_MODE_CBR; + } if (params->vi_bitrate.mode != V4L2_BITRATE_NONE) - h->params.st_bitrate.target = params->st_bitrate.target; + h->old_params.st_bitrate.target = params->st_bitrate.target; if (params->vi_bitrate.mode != V4L2_BITRATE_NONE) - h->params.vi_bitrate.target = params->vi_bitrate.target; + h->old_params.vi_bitrate.target = params->vi_bitrate.target; if (params->vi_bitrate.mode == V4L2_BITRATE_VBR) - h->params.vi_bitrate.max = params->vi_bitrate.max; + h->old_params.vi_bitrate.max = params->vi_bitrate.max; if (params->au_bitrate.mode != V4L2_BITRATE_NONE) - h->params.au_bitrate.target = params->au_bitrate.target; + h->old_params.au_bitrate.target = params->au_bitrate.target; /* aspect ratio */ if (params->vi_aspect_ratio == V4L2_MPEG_ASPECT_4_3 || - params->vi_aspect_ratio == V4L2_MPEG_ASPECT_16_9) - h->params.vi_aspect_ratio = params->vi_aspect_ratio; + params->vi_aspect_ratio == V4L2_MPEG_ASPECT_16_9) { + h->old_params.vi_aspect_ratio = params->vi_aspect_ratio; + if (params->vi_aspect_ratio == V4L2_MPEG_ASPECT_4_3) + h->params.vi_aspect = V4L2_MPEG_VIDEO_ASPECT_4x3; + else + h->params.vi_aspect = V4L2_MPEG_VIDEO_ASPECT_16x9; + } /* range checks */ - if (h->params.st_bitrate.target > MPEG_TOTAL_TARGET_BITRATE_MAX) - h->params.st_bitrate.target = MPEG_TOTAL_TARGET_BITRATE_MAX; - if (h->params.vi_bitrate.target > MPEG_VIDEO_TARGET_BITRATE_MAX) - h->params.vi_bitrate.target = MPEG_VIDEO_TARGET_BITRATE_MAX; - if (h->params.vi_bitrate.max > MPEG_VIDEO_MAX_BITRATE_MAX) - h->params.vi_bitrate.max = MPEG_VIDEO_MAX_BITRATE_MAX; - if (h->params.au_bitrate.target <= 256) - h->params.au_bitrate.target = 256; + if (h->old_params.st_bitrate.target > MPEG_TOTAL_TARGET_BITRATE_MAX) + h->old_params.st_bitrate.target = MPEG_TOTAL_TARGET_BITRATE_MAX; + if (h->old_params.vi_bitrate.target > MPEG_VIDEO_TARGET_BITRATE_MAX) + h->old_params.vi_bitrate.target = MPEG_VIDEO_TARGET_BITRATE_MAX; + if (h->old_params.vi_bitrate.max > MPEG_VIDEO_MAX_BITRATE_MAX) + h->old_params.vi_bitrate.max = MPEG_VIDEO_MAX_BITRATE_MAX; + h->params.vi_bitrate = params->vi_bitrate.target; + h->params.vi_bitrate_peak = params->vi_bitrate.max; + if (h->old_params.au_bitrate.target <= 256) { + h->old_params.au_bitrate.target = 256; + h->params.au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K; + } + else { + h->old_params.au_bitrate.target = 384; + h->params.au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_384K; + } +} + +static int handle_ctrl(struct saa6752hs_mpeg_params *params, + struct v4l2_ext_control *ctrl, int cmd) +{ + int old = 0, new; + int set = cmd == VIDIOC_S_EXT_CTRLS; + + new = ctrl->value; + switch (ctrl->id) { + case V4L2_CID_MPEG_STREAM_TYPE: + old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS; + if (set && new != old) + return -ERANGE; + new = old; + break; + case V4L2_CID_MPEG_STREAM_PID_PMT: + old = params->ts_pid_pmt; + if (set && new > MPEG_PID_MAX) + return -ERANGE; + if (new > MPEG_PID_MAX) + new = MPEG_PID_MAX; + params->ts_pid_pmt = new; + break; + case V4L2_CID_MPEG_STREAM_PID_AUDIO: + old = params->ts_pid_audio; + if (set && new > MPEG_PID_MAX) + return -ERANGE; + if (new > MPEG_PID_MAX) + new = MPEG_PID_MAX; + params->ts_pid_audio = new; + break; + case V4L2_CID_MPEG_STREAM_PID_VIDEO: + old = params->ts_pid_video; + if (set && new > MPEG_PID_MAX) + return -ERANGE; + if (new > MPEG_PID_MAX) + new = MPEG_PID_MAX; + params->ts_pid_video = new; + break; + case V4L2_CID_MPEG_STREAM_PID_PCR: + old = params->ts_pid_pcr; + if (set && new > MPEG_PID_MAX) + return -ERANGE; + if (new > MPEG_PID_MAX) + new = MPEG_PID_MAX; + params->ts_pid_pcr = new; + break; + case V4L2_CID_MPEG_AUDIO_ENCODING: + old = V4L2_MPEG_AUDIO_ENCODING_LAYER_2; + if (set && new != old) + return -ERANGE; + new = old; + break; + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + old = params->au_l2_bitrate; + if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K && + new != V4L2_MPEG_AUDIO_L2_BITRATE_384K) + return -ERANGE; + if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K) + new = V4L2_MPEG_AUDIO_L2_BITRATE_256K; + else + new = V4L2_MPEG_AUDIO_L2_BITRATE_384K; + params->au_l2_bitrate = new; + break; + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000; + if (set && new != old) + return -ERANGE; + new = old; + break; + case V4L2_CID_MPEG_VIDEO_ENCODING: + old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2; + if (set && new != old) + return -ERANGE; + new = old; + break; + case V4L2_CID_MPEG_VIDEO_ASPECT: + old = params->vi_aspect; + if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 && + new != V4L2_MPEG_VIDEO_ASPECT_4x3) + return -ERANGE; + if (new != V4L2_MPEG_VIDEO_ASPECT_16x9) + new = V4L2_MPEG_VIDEO_ASPECT_4x3; + params->vi_aspect = new; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: + old = params->vi_bitrate * 1000; + new = 1000 * (new / 1000); + if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000) + return -ERANGE; + if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000) + new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000; + params->vi_bitrate = new / 1000; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + old = params->vi_bitrate_peak * 1000; + new = 1000 * (new / 1000); + if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000) + return -ERANGE; + if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000) + new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000; + params->vi_bitrate_peak = new / 1000; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + old = params->vi_bitrate_mode; + params->vi_bitrate_mode = new; + break; + default: + return -EINVAL; + } + if (cmd == VIDIOC_G_EXT_CTRLS) + ctrl->value = old; else - h->params.au_bitrate.target = 384; + ctrl->value = new; + return 0; } static int saa6752hs_init(struct i2c_client* client) @@ -500,11 +683,11 @@ static int saa6752hs_init(struct i2c_client* client) buf[3] = 0x82; buf[4] = 0xB0; buf[5] = buf2[0]; - switch(h->params.vi_aspect_ratio) { - case V4L2_MPEG_ASPECT_16_9: + switch(h->params.vi_aspect) { + case V4L2_MPEG_VIDEO_ASPECT_16x9: buf[6] = buf2[1] | 0x40; break; - case V4L2_MPEG_ASPECT_4_3: + case V4L2_MPEG_VIDEO_ASPECT_4x3: default: buf[6] = buf2[1] & 0xBF; break; @@ -530,6 +713,7 @@ static int saa6752hs_attach(struct i2c_adapter *adap, int addr, unsigned short f return -ENOMEM; h->client = client_template; h->params = param_defaults; + h->old_params = old_param_defaults; h->client.adapter = adap; h->client.addr = addr; @@ -572,20 +756,45 @@ static int saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg) { struct saa6752hs_state *h = i2c_get_clientdata(client); - struct v4l2_mpeg_compression *params = arg; + struct v4l2_ext_controls *ctrls = arg; + struct v4l2_mpeg_compression *old_params = arg; + struct saa6752hs_mpeg_params params; int err = 0; + int i; switch (cmd) { case VIDIOC_S_MPEGCOMP: - if (NULL == params) { + if (NULL == old_params) { /* apply settings and start encoder */ saa6752hs_init(client); break; } - saa6752hs_set_params(client, params); + saa6752hs_old_set_params(client, old_params); /* fall through */ case VIDIOC_G_MPEGCOMP: - *params = h->params; + *old_params = h->old_params; + break; + case VIDIOC_S_EXT_CTRLS: + if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + if (ctrls->count == 0) { + /* apply settings and start encoder */ + saa6752hs_init(client); + break; + } + /* fall through */ + case VIDIOC_TRY_EXT_CTRLS: + case VIDIOC_G_EXT_CTRLS: + if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + params = h->params; + for (i = 0; i < ctrls->count; i++) { + if ((err = handle_ctrl(¶ms, ctrls->controls + i, cmd))) { + ctrls->error_idx = i; + return err; + } + } + h->params = params; break; case VIDIOC_G_FMT: { diff --git a/linux/drivers/media/video/saa7134/saa7134-empress.c b/linux/drivers/media/video/saa7134/saa7134-empress.c index 5c311210e..690891588 100644 --- a/linux/drivers/media/video/saa7134/saa7134-empress.c +++ b/linux/drivers/media/video/saa7134/saa7134-empress.c @@ -74,8 +74,10 @@ static void ts_reset_encoder(struct saa7134_dev* dev) static int ts_init_encoder(struct saa7134_dev* dev) { + struct v4l2_ext_controls ctrls = { V4L2_CTRL_CLASS_MPEG, 0 }; + ts_reset_encoder(dev); - saa7134_i2c_call_clients(dev, VIDIOC_S_MPEGCOMP, NULL); + saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, &ctrls); dev->empress_started = 1; return 0; } @@ -172,6 +174,7 @@ static int ts_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg) { struct saa7134_dev *dev = file->private_data; + struct v4l2_ext_controls *ctrls = arg; if (debug > 1) v4l_print_ioctl(dev->name,cmd); @@ -288,12 +291,31 @@ static int ts_do_ioctl(struct inode *inode, struct file *file, return saa7134_common_ioctl(dev, cmd, arg); case VIDIOC_S_MPEGCOMP: + printk(KERN_WARNING "VIDIOC_S_MPEGCOMP is obsolete. " + "Replace with VIDIOC_S_EXT_CTRLS!"); saa7134_i2c_call_clients(dev, VIDIOC_S_MPEGCOMP, arg); ts_init_encoder(dev); return 0; case VIDIOC_G_MPEGCOMP: + printk(KERN_WARNING "VIDIOC_G_MPEGCOMP is obsolete. " + "Replace with VIDIOC_G_EXT_CTRLS!"); saa7134_i2c_call_clients(dev, VIDIOC_G_MPEGCOMP, arg); return 0; + case VIDIOC_S_EXT_CTRLS: + /* count == 0 is abused in saa6752hs.c, so that special + case is handled here explicitly. */ + if (ctrls->count == 0) + return 0; + if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, arg); + ts_init_encoder(dev); + return 0; + case VIDIOC_G_EXT_CTRLS: + if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) + return -EINVAL; + saa7134_i2c_call_clients(dev, VIDIOC_G_EXT_CTRLS, arg); + return 0; default: return -ENOIOCTLCMD; diff --git a/linux/drivers/media/video/v4l2-common.c b/linux/drivers/media/video/v4l2-common.c index c701982cf..f722ab390 100644 --- a/linux/drivers/media/video/v4l2-common.c +++ b/linux/drivers/media/video/v4l2-common.c @@ -314,7 +314,10 @@ static const char *v4l2_ioctls[] = { #if 1 /*KEEP*/ [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP", #endif - [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS" + [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS", + [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS", + [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS", + [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS" }; #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) @@ -531,6 +534,23 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg) printk ("%s: id=%d, value=%d\n", s, p->id, p->value); break; } + case VIDIOC_G_EXT_CTRLS: + case VIDIOC_S_EXT_CTRLS: + case VIDIOC_TRY_EXT_CTRLS: + { + struct v4l2_ext_controls *p = arg; + int i; + + printk("%s: ctrl_class=%d, count=%d\n", s, p->ctrl_class, p->count); + for (i = 0; i < p->count; i++) { + struct v4l2_ext_control *c = &p->controls[i]; + if (cmd == VIDIOC_G_EXT_CTRLS) + printk("%s: id=%d\n", s, c->id); + else + printk("%s: id=%d, value=%d\n", s, c->id, c->value); + } + break; + } case VIDIOC_G_CROP: case VIDIOC_S_CROP: { @@ -966,6 +986,484 @@ void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg) /* ----------------------------------------------------------------- */ +/* Helper functions for control handling */ + +/* Check for correctness of the ctrl's value based on the data from + struct v4l2_queryctrl and the available menu items. Note that + menu_items may be NULL, in that case it is ignored. */ +int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, + const char **menu_items) +{ + if (qctrl->flags & V4L2_CTRL_FLAG_DISABLED) + return -EINVAL; + if (qctrl->flags & V4L2_CTRL_FLAG_GRABBED) + return -EBUSY; + if (qctrl->type == V4L2_CTRL_TYPE_BUTTON || + qctrl->type == V4L2_CTRL_TYPE_INTEGER64 || + qctrl->type == V4L2_CTRL_TYPE_CTRL_CLASS) + return 0; + if (ctrl->value < qctrl->minimum || ctrl->value > qctrl->maximum) + return -ERANGE; + if (qctrl->type == V4L2_CTRL_TYPE_MENU && menu_items != NULL) { + if (menu_items[ctrl->value] == NULL || + menu_items[ctrl->value][0] == '\0') + return -EINVAL; + } + return 0; +} + +/* 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 **v4l2_ctrl_get_menu(u32 id) +{ + static const char *mpeg_audio_sampling_freq[] = { + "44.1 kHz", + "48 kHz", + "32 kHz", + NULL + }; + static const char *mpeg_audio_encoding[] = { + "Layer I", + "Layer II", + "Layer III", + NULL + }; + static const char *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 *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 *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 *mpeg_audio_mode[] = { + "Stereo", + "Joint Stereo", + "Dual", + "Mono", + NULL + }; + static const char *mpeg_audio_mode_extension[] = { + "Bound 4", + "Bound 8", + "Bound 12", + "Bound 16", + NULL + }; + static const char *mpeg_audio_emphasis[] = { + "No Emphasis", + "50/15 us", + "CCITT J17", + NULL + }; + static const char *mpeg_audio_crc[] = { + "No CRC", + "16-bit CRC", + NULL + }; + static const char *mpeg_video_encoding[] = { + "MPEG-1", + "MPEG-2", + NULL + }; + static const char *mpeg_video_aspect[] = { + "1x1", + "4x3", + "16x9", + "2.21x1", + NULL + }; + static const char *mpeg_video_bitrate_mode[] = { + "Variable Bitrate", + "Constant Bitrate", + NULL + }; + static const char *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 + }; + + switch (id) { + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + return mpeg_audio_sampling_freq; + case V4L2_CID_MPEG_AUDIO_ENCODING: + return mpeg_audio_encoding; + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: + return mpeg_audio_l1_bitrate; + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + return mpeg_audio_l2_bitrate; + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: + return mpeg_audio_l3_bitrate; + case V4L2_CID_MPEG_AUDIO_MODE: + return mpeg_audio_mode; + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + return mpeg_audio_mode_extension; + case V4L2_CID_MPEG_AUDIO_EMPHASIS: + return mpeg_audio_emphasis; + case V4L2_CID_MPEG_AUDIO_CRC: + return mpeg_audio_crc; + case V4L2_CID_MPEG_VIDEO_ENCODING: + return mpeg_video_encoding; + case V4L2_CID_MPEG_VIDEO_ASPECT: + return mpeg_video_aspect; + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + return mpeg_video_bitrate_mode; + case V4L2_CID_MPEG_STREAM_TYPE: + return mpeg_stream_type; + default: + return NULL; + } +} + +/* Fill in a struct v4l2_queryctrl */ +int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) +{ + const char *name; + + qctrl->flags = 0; + switch (qctrl->id) { + /* USER controls */ + case V4L2_CID_USER_CLASS: name = "User Controls"; break; + case V4L2_CID_AUDIO_VOLUME: name = "Volume"; break; + case V4L2_CID_AUDIO_MUTE: name = "Mute"; break; + case V4L2_CID_AUDIO_BALANCE: name = "Balance"; break; + case V4L2_CID_AUDIO_BASS: name = "Bass"; break; + case V4L2_CID_AUDIO_TREBLE: name = "Treble"; break; + case V4L2_CID_AUDIO_LOUDNESS: name = "Loudness"; break; + case V4L2_CID_BRIGHTNESS: name = "Brightness"; break; + case V4L2_CID_CONTRAST: name = "Contrast"; break; + case V4L2_CID_SATURATION: name = "Saturation"; break; + case V4L2_CID_HUE: name = "Hue"; break; + + /* MPEG controls */ + case V4L2_CID_MPEG_CLASS: name = "MPEG Encoder Controls"; break; + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break; + case V4L2_CID_MPEG_AUDIO_ENCODING: name = "Audio Encoding Layer"; break; + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: name = "Audio Layer I Bitrate"; break; + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: name = "Audio Layer II Bitrate"; break; + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: name = "Audio Layer III Bitrate"; break; + case V4L2_CID_MPEG_AUDIO_MODE: name = "Audio Stereo Mode"; break; + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break; + case V4L2_CID_MPEG_AUDIO_EMPHASIS: name = "Audio Emphasis"; break; + case V4L2_CID_MPEG_AUDIO_CRC: name = "Audio CRC"; break; + case V4L2_CID_MPEG_VIDEO_ENCODING: name = "Video Encoding"; break; + case V4L2_CID_MPEG_VIDEO_ASPECT: name = "Video Aspect"; break; + case V4L2_CID_MPEG_VIDEO_B_FRAMES: name = "Video B Frames"; break; + case V4L2_CID_MPEG_VIDEO_GOP_SIZE: name = "Video GOP Size"; break; + case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: name = "Video GOP Closure"; break; + case V4L2_CID_MPEG_VIDEO_PULLDOWN: name = "Video Pulldown"; break; + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: name = "Video Bitrate Mode"; break; + case V4L2_CID_MPEG_VIDEO_BITRATE: name = "Video Bitrate"; break; + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: name = "Video Peak Bitrate"; break; + case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break; + case V4L2_CID_MPEG_STREAM_TYPE: name = "Stream Type"; break; + case V4L2_CID_MPEG_STREAM_PID_PMT: name = "Stream PMT Program ID"; break; + case V4L2_CID_MPEG_STREAM_PID_AUDIO: name = "Stream Audio Program ID"; break; + case V4L2_CID_MPEG_STREAM_PID_VIDEO: name = "Stream Video Program ID"; break; + case V4L2_CID_MPEG_STREAM_PID_PCR: name = "Stream PCR Program ID"; break; + case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break; + case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break; + + default: + return -EINVAL; + } + switch (qctrl->id) { + case V4L2_CID_AUDIO_MUTE: + case V4L2_CID_AUDIO_LOUDNESS: + case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: + case V4L2_CID_MPEG_VIDEO_PULLDOWN: + qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; + min = 0; + max = step = 1; + break; + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + case V4L2_CID_MPEG_AUDIO_ENCODING: + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: + case V4L2_CID_MPEG_AUDIO_MODE: + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + case V4L2_CID_MPEG_AUDIO_EMPHASIS: + case V4L2_CID_MPEG_AUDIO_CRC: + case V4L2_CID_MPEG_VIDEO_ENCODING: + case V4L2_CID_MPEG_VIDEO_ASPECT: + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + case V4L2_CID_MPEG_STREAM_TYPE: + qctrl->type = V4L2_CTRL_TYPE_MENU; + step = 1; + break; + case V4L2_CID_USER_CLASS: + case V4L2_CID_MPEG_CLASS: + qctrl->type = V4L2_CTRL_TYPE_CTRL_CLASS; + qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + min = max = step = def = 0; + break; + default: + qctrl->type = V4L2_CTRL_TYPE_INTEGER; + break; + } + switch (qctrl->id) { + case V4L2_CID_MPEG_AUDIO_ENCODING: + case V4L2_CID_MPEG_AUDIO_MODE: + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + case V4L2_CID_MPEG_VIDEO_B_FRAMES: + case V4L2_CID_MPEG_STREAM_TYPE: + qctrl->flags |= V4L2_CTRL_FLAG_UPDATE; + break; + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + case V4L2_CID_BRIGHTNESS: + case V4L2_CID_CONTRAST: + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; + break; + } + qctrl->minimum = min; + qctrl->maximum = max; + qctrl->step = step; + qctrl->default_value = def; + qctrl->reserved[0] = qctrl->reserved[1] = 0; + snprintf(qctrl->name, sizeof(qctrl->name), name); + return 0; +} + +/* Fill in a struct v4l2_queryctrl with standard values based on + the control ID. */ +int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl) +{ + switch (qctrl->id) { + /* USER controls */ + case V4L2_CID_USER_CLASS: + case V4L2_CID_MPEG_CLASS: + return v4l2_ctrl_query_fill(qctrl, 0, 0, 0, 0); + case V4L2_CID_AUDIO_VOLUME: + return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 58880); + case V4L2_CID_AUDIO_MUTE: + case V4L2_CID_AUDIO_LOUDNESS: + return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0); + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + return v4l2_ctrl_query_fill(qctrl, 0, 65535, 65535 / 100, 32768); + case V4L2_CID_BRIGHTNESS: + return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 128); + case V4L2_CID_CONTRAST: + case V4L2_CID_SATURATION: + return v4l2_ctrl_query_fill(qctrl, 0, 127, 1, 64); + case V4L2_CID_HUE: + return v4l2_ctrl_query_fill(qctrl, -128, 127, 1, 0); + + /* MPEG controls */ + case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, 1, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000); + case V4L2_CID_MPEG_AUDIO_ENCODING: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_ENCODING_LAYER_1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2); + case V4L2_CID_MPEG_AUDIO_L1_BITRATE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_L1_BITRATE_32K, + V4L2_MPEG_AUDIO_L1_BITRATE_448K, 1, + V4L2_MPEG_AUDIO_L1_BITRATE_256K); + case V4L2_CID_MPEG_AUDIO_L2_BITRATE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_L2_BITRATE_32K, + V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1, + V4L2_MPEG_AUDIO_L2_BITRATE_224K); + case V4L2_CID_MPEG_AUDIO_L3_BITRATE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_L3_BITRATE_32K, + V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1, + V4L2_MPEG_AUDIO_L3_BITRATE_192K); + case V4L2_CID_MPEG_AUDIO_MODE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_MODE_STEREO, + V4L2_MPEG_AUDIO_MODE_MONO, 1, + V4L2_MPEG_AUDIO_MODE_STEREO); + case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, 1, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4); + case V4L2_CID_MPEG_AUDIO_EMPHASIS: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_EMPHASIS_NONE, + V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, 1, + V4L2_MPEG_AUDIO_EMPHASIS_NONE); + case V4L2_CID_MPEG_AUDIO_CRC: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_AUDIO_CRC_NONE, + V4L2_MPEG_AUDIO_CRC_CRC16, 1, + V4L2_MPEG_AUDIO_CRC_NONE); + case V4L2_CID_MPEG_VIDEO_ENCODING: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_VIDEO_ENCODING_MPEG_1, + V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1, + V4L2_MPEG_VIDEO_ENCODING_MPEG_2); + case V4L2_CID_MPEG_VIDEO_ASPECT: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_VIDEO_ASPECT_1x1, + V4L2_MPEG_VIDEO_ASPECT_221x100, 1, + V4L2_MPEG_VIDEO_ASPECT_4x3); + case V4L2_CID_MPEG_VIDEO_B_FRAMES: + return v4l2_ctrl_query_fill(qctrl, 0, 33, 1, 2); + case V4L2_CID_MPEG_VIDEO_GOP_SIZE: + return v4l2_ctrl_query_fill(qctrl, 1, 34, 1, 12); + case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: + return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 1); + case V4L2_CID_MPEG_VIDEO_PULLDOWN: + return v4l2_ctrl_query_fill(qctrl, 0, 1, 1, 0); + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1, + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR); + case V4L2_CID_MPEG_VIDEO_BITRATE: + return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 6000000); + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + return v4l2_ctrl_query_fill(qctrl, 0, 27000000, 1, 8000000); + case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: + return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0); + case V4L2_CID_MPEG_STREAM_TYPE: + return v4l2_ctrl_query_fill(qctrl, + V4L2_MPEG_STREAM_TYPE_MPEG2_PS, + V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, 1, + V4L2_MPEG_STREAM_TYPE_MPEG2_PS); + case V4L2_CID_MPEG_STREAM_PID_PMT: + return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 16); + case V4L2_CID_MPEG_STREAM_PID_AUDIO: + return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 260); + case V4L2_CID_MPEG_STREAM_PID_VIDEO: + return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 256); + case V4L2_CID_MPEG_STREAM_PID_PCR: + return v4l2_ctrl_query_fill(qctrl, 0, (1 << 14) - 1, 1, 259); + case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: + return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0); + case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: + return v4l2_ctrl_query_fill(qctrl, 0, 255, 1, 0); + default: + return -EINVAL; + } +} + +/* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and + the menu. The qctrl pointer may be NULL, in which case it is ignored. */ +int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl, + const char **menu_items) +{ + int i; + + if (menu_items == NULL || + (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum))) + return -EINVAL; + for (i = 0; i < qmenu->index && menu_items[i]; i++) ; + if (menu_items[i] == NULL || menu_items[i][0] == '\0') + return -EINVAL; + snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]); + qmenu->reserved = 0; + return 0; +} + +/* ctrl_classes points to an array of u32 pointers, the last element is + a NULL pointer. Each u32 array is a 0-terminated array of control IDs. + Each array must be sorted low to high and belong to the same control + class. The array of u32 pointer must also be sorted, from low class IDs + to high class IDs. + + This function returns the first ID that follows after the given ID. + When no more controls are available 0 is returned. */ +u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id) +{ + u32 ctrl_class; + const u32 *pctrl; + + /* if no query is desired, then just return the control ID */ + if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) + return id; + if (ctrl_classes == NULL) + return 0; + id &= V4L2_CTRL_ID_MASK; + ctrl_class = V4L2_CTRL_ID2CLASS(id); + id++; /* select next control */ + /* find first class that matches (or is greater than) the class of + the ID */ + while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) < ctrl_class) + ctrl_classes++; + /* no more classes */ + if (*ctrl_classes == NULL) + return 0; + pctrl = *ctrl_classes; + /* find first ctrl within the class that is >= ID */ + while (*pctrl && *pctrl < id) pctrl++; + if (*pctrl) + return *pctrl; + /* we are at the end of the controls of the current class. */ + /* continue with next class if available */ + ctrl_classes++; + if (*ctrl_classes == NULL) + return 0; + return **ctrl_classes; +} + +/* ----------------------------------------------------------------- */ + EXPORT_SYMBOL(v4l2_video_std_construct); EXPORT_SYMBOL(v4l2_prio_init); @@ -980,6 +1478,13 @@ EXPORT_SYMBOL(v4l2_type_names); EXPORT_SYMBOL(v4l_printk_ioctl); EXPORT_SYMBOL(v4l_printk_ioctl_arg); +EXPORT_SYMBOL(v4l2_ctrl_next); +EXPORT_SYMBOL(v4l2_ctrl_check); +EXPORT_SYMBOL(v4l2_ctrl_get_menu); +EXPORT_SYMBOL(v4l2_ctrl_query_menu); +EXPORT_SYMBOL(v4l2_ctrl_query_fill); +EXPORT_SYMBOL(v4l2_ctrl_query_fill_std); + /* * Local variables: * c-basic-offset: 8 diff --git a/linux/drivers/media/video/videodev.c b/linux/drivers/media/video/videodev.c index 976ce381b..c12f88fe3 100644 --- a/linux/drivers/media/video/videodev.c +++ b/linux/drivers/media/video/videodev.c @@ -209,10 +209,15 @@ video_usercopy(struct inode *inode, struct file *file, void *mbuf = NULL; void *parg = NULL; int err = -EINVAL; + int is_ext_ctrl; + size_t ctrls_size = 0; + void __user *user_ptr = NULL; #ifdef __OLD_VIDIOC_ cmd = video_fix_command(cmd); #endif + is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || + cmd == VIDIOC_TRY_EXT_CTRLS); /* Copy arguments into temp kernel buffer */ switch (_IOC_DIR(cmd)) { @@ -234,19 +239,47 @@ video_usercopy(struct inode *inode, struct file *file, err = -EFAULT; if (_IOC_DIR(cmd) & _IOC_WRITE) - if (copy_from_user(parg, (void __user *)arg, - _IOC_SIZE(cmd))) + if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) goto out; break; } + if (is_ext_ctrl) { + struct v4l2_ext_controls *p = parg; + + /* In case of an error, tell the caller that it wasn't + a specific control that caused it. */ + p->error_idx = p->count; + user_ptr = (void __user *)p->controls; + if (p->count) { + ctrls_size = sizeof(struct v4l2_ext_control) * p->count; + /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ + mbuf = kmalloc(ctrls_size, GFP_KERNEL); + err = -ENOMEM; + if (NULL == mbuf) + goto out_ext_ctrl; + err = -EFAULT; + if (copy_from_user(mbuf, user_ptr, ctrls_size)) + goto out_ext_ctrl; + p->controls = mbuf; + } + } /* call driver */ err = func(inode, file, cmd, parg); if (err == -ENOIOCTLCMD) err = -EINVAL; + if (is_ext_ctrl) { + struct v4l2_ext_controls *p = parg; + + p->controls = (void *)user_ptr; + if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) + err = -EFAULT; + goto out_ext_ctrl; + } if (err < 0) goto out; +out_ext_ctrl: /* Copy results into user buffer */ switch (_IOC_DIR(cmd)) { @@ -1012,6 +1045,39 @@ static int __video_do_ioctl(struct inode *inode, struct file *file, ret=vfd->vidioc_s_ctrl(file, fh, p); break; } + case VIDIOC_G_EXT_CTRLS: + { + struct v4l2_ext_controls *p = arg; + + if (vfd->vidioc_g_ext_ctrls) { + dbgarg(cmd, "count=%d\n", p->count); + + ret=vfd->vidioc_g_ext_ctrls(file, fh, p); + } + break; + } + case VIDIOC_S_EXT_CTRLS: + { + struct v4l2_ext_controls *p = arg; + + if (vfd->vidioc_s_ext_ctrls) { + dbgarg(cmd, "count=%d\n", p->count); + + ret=vfd->vidioc_s_ext_ctrls(file, fh, p); + } + break; + } + case VIDIOC_TRY_EXT_CTRLS: + { + struct v4l2_ext_controls *p = arg; + + if (vfd->vidioc_try_ext_ctrls) { + dbgarg(cmd, "count=%d\n", p->count); + + ret=vfd->vidioc_try_ext_ctrls(file, fh, p); + } + break; + } case VIDIOC_QUERYMENU: { struct v4l2_querymenu *p=arg; @@ -1169,6 +1235,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file, case VIDIOC_G_MPEGCOMP: { struct v4l2_mpeg_compression *p=arg; + /*FIXME: Several fields not shown */ if (!vfd->vidioc_g_mpegcomp) break; @@ -1345,10 +1412,15 @@ int video_ioctl2 (struct inode *inode, struct file *file, void *mbuf = NULL; void *parg = NULL; int err = -EINVAL; + int is_ext_ctrl; + size_t ctrls_size = 0; + void __user *user_ptr = NULL; #ifdef __OLD_VIDIOC_ cmd = video_fix_command(cmd); #endif + is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || + cmd == VIDIOC_TRY_EXT_CTRLS); /* Copy arguments into temp kernel buffer */ switch (_IOC_DIR(cmd)) { @@ -1375,13 +1447,43 @@ int video_ioctl2 (struct inode *inode, struct file *file, break; } + if (is_ext_ctrl) { + struct v4l2_ext_controls *p = parg; + + /* In case of an error, tell the caller that it wasn't + a specific control that caused it. */ + p->error_idx = p->count; + user_ptr = (void __user *)p->controls; + if (p->count) { + ctrls_size = sizeof(struct v4l2_ext_control) * p->count; + /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ + mbuf = kmalloc(ctrls_size, GFP_KERNEL); + err = -ENOMEM; + if (NULL == mbuf) + goto out_ext_ctrl; + err = -EFAULT; + if (copy_from_user(mbuf, user_ptr, ctrls_size)) + goto out_ext_ctrl; + p->controls = mbuf; + } + } + /* Handles IOCTL */ err = __video_do_ioctl(inode, file, cmd, parg); if (err == -ENOIOCTLCMD) err = -EINVAL; + if (is_ext_ctrl) { + struct v4l2_ext_controls *p = parg; + + p->controls = (void *)user_ptr; + if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) + err = -EFAULT; + goto out_ext_ctrl; + } if (err < 0) goto out; +out_ext_ctrl: /* Copy results into user buffer */ switch (_IOC_DIR(cmd)) { diff --git a/linux/include/linux/videodev2.h b/linux/include/linux/videodev2.h index 26dc9c62d..952fcd831 100644 --- a/linux/include/linux/videodev2.h +++ b/linux/include/linux/videodev2.h @@ -105,6 +105,8 @@ enum v4l2_ctrl_type { V4L2_CTRL_TYPE_BOOLEAN = 2, V4L2_CTRL_TYPE_MENU = 3, V4L2_CTRL_TYPE_BUTTON = 4, + V4L2_CTRL_TYPE_INTEGER64 = 5, + V4L2_CTRL_TYPE_CTRL_CLASS = 6, }; enum v4l2_tuner_type { @@ -251,7 +253,7 @@ struct v4l2_pix_format #define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */ #define V4L2_PIX_FMT_JPEG v4l2_fourcc('J','P','E','G') /* JFIF JPEG */ #define V4L2_PIX_FMT_DV v4l2_fourcc('d','v','s','d') /* 1394 */ -#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG */ +#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG-1/2/4 */ /* Vendor-specific formats */ #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */ @@ -304,12 +306,13 @@ struct v4l2_timecode #define V4L2_TC_USERBITS_8BITCHARS 0x0008 /* The above is based on SMPTE timecodes */ -#if 1 +#ifdef __KERNEL__ /* * M P E G C O M P R E S S I O N P A R A M E T E R S * - * ### WARNING: this is still work-in-progress right now, most likely - * ### there will be some incompatible changes. + * ### WARNING: This experimental MPEG compression API is obsolete. + * ### It is replaced by the MPEG controls API. + * ### This old API will disappear in the near future! * */ enum v4l2_bitrate_mode { @@ -703,6 +706,34 @@ struct v4l2_control __s32 value; }; +struct v4l2_ext_control +{ + __u32 id; + __u32 reserved2[2]; + union { + __s32 value; + __s64 value64; + void *reserved; + }; +}; + +struct v4l2_ext_controls +{ + __u32 ctrl_class; + __u32 count; + __u32 error_idx; + __u32 reserved[2]; + struct v4l2_ext_control *controls; +}; + +/* Values for ctrl_class field */ +#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ +#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ + +#define V4L2_CTRL_ID_MASK (0x0fffffff) +#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) +#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000) + /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ struct v4l2_queryctrl { @@ -729,12 +760,21 @@ struct v4l2_querymenu /* Control flags */ #define V4L2_CTRL_FLAG_DISABLED 0x0001 #define V4L2_CTRL_FLAG_GRABBED 0x0002 +#define V4L2_CTRL_FLAG_READ_ONLY 0x0004 +#define V4L2_CTRL_FLAG_UPDATE 0x0008 +#define V4L2_CTRL_FLAG_INACTIVE 0x0010 +#define V4L2_CTRL_FLAG_SLIDER 0x0020 -/* Control IDs defined by V4L2 */ -#define V4L2_CID_BASE 0x00980900 +/* Query flag, to be ORed with the control ID */ +#define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000 + +/* User-class control IDs defined by V4L2 */ +#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900) +#define V4L2_CID_USER_BASE V4L2_CID_BASE /* IDs reserved for driver specific controls */ #define V4L2_CID_PRIVATE_BASE 0x08000000 +#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1) #define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) #define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) #define V4L2_CID_SATURATION (V4L2_CID_BASE+2) @@ -761,6 +801,183 @@ struct v4l2_querymenu #define V4L2_CID_VCENTER (V4L2_CID_BASE+23) #define V4L2_CID_LASTP1 (V4L2_CID_BASE+24) /* last CID + 1 */ +/* MPEG-class control IDs defined by V4L2 */ +#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900) +#define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1) + +/* MPEG streams */ +#define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0) +enum v4l2_mpeg_stream_type { + V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */ + V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */ +}; +#define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1) +#define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2) +#define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3) +#define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4) +#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5) +#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6) + +/* MPEG audio */ +#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100) +enum v4l2_mpeg_audio_sampling_freq { + V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1, + V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101) +enum v4l2_mpeg_audio_encoding { + V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0, + V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1, + V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102) +enum v4l2_mpeg_audio_l1_bitrate { + V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1, + V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2, + V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3, + V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4, + V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5, + V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6, + V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7, + V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8, + V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9, + V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10, + V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11, + V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12, + V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103) +enum v4l2_mpeg_audio_l2_bitrate { + V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1, + V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2, + V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3, + V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4, + V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5, + V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6, + V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7, + V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8, + V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9, + V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10, + V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11, + V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12, + V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104) +enum v4l2_mpeg_audio_l3_bitrate { + V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0, + V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1, + V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2, + V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3, + V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4, + V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5, + V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6, + V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7, + V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8, + V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9, + V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10, + V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11, + V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12, + V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13, +}; +#define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105) +enum v4l2_mpeg_audio_mode { + V4L2_MPEG_AUDIO_MODE_STEREO = 0, + V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1, + V4L2_MPEG_AUDIO_MODE_DUAL = 2, + V4L2_MPEG_AUDIO_MODE_MONO = 3, +}; +#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106) +enum v4l2_mpeg_audio_mode_extension { + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2, + V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3, +}; +#define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107) +enum v4l2_mpeg_audio_emphasis { + V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0, + V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1, + V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2, +}; +#define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108) +enum v4l2_mpeg_audio_crc { + V4L2_MPEG_AUDIO_CRC_NONE = 0, + V4L2_MPEG_AUDIO_CRC_CRC16 = 1, +}; + +/* MPEG video */ +#define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200) +enum v4l2_mpeg_video_encoding { + V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0, + V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1, +}; +#define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201) +enum v4l2_mpeg_video_aspect { + V4L2_MPEG_VIDEO_ASPECT_1x1 = 0, + V4L2_MPEG_VIDEO_ASPECT_4x3 = 1, + V4L2_MPEG_VIDEO_ASPECT_16x9 = 2, + V4L2_MPEG_VIDEO_ASPECT_221x100 = 3, +}; +#define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202) +#define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203) +#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204) +#define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205) +#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206) +enum v4l2_mpeg_video_bitrate_mode { + V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1, +}; +#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207) +#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208) +#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209) + +/* MPEG-class control IDs specific to the CX2584x driver as defined by V4L2 */ +#define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000) +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0) +enum v4l2_mpeg_cx2341x_video_spatial_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2) +enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3, + V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3) +enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type { + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4) +enum v4l2_mpeg_cx2341x_video_temporal_filter_mode { + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0, + V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5) +#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6) +enum v4l2_mpeg_cx2341x_video_median_filter_type { + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3, + V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4, +}; +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7) +#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9) +#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10) + /* * T U N I N G */ @@ -1037,7 +1254,7 @@ struct v4l2_streamparm #define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct v4l2_fmtdesc) #define VIDIOC_G_FMT _IOWR ('V', 4, struct v4l2_format) #define VIDIOC_S_FMT _IOWR ('V', 5, struct v4l2_format) -#if 1 /* experimental */ +#ifdef __KERNEL__ #define VIDIOC_G_MPEGCOMP _IOR ('V', 6, struct v4l2_mpeg_compression) #define VIDIOC_S_MPEGCOMP _IOW ('V', 7, struct v4l2_mpeg_compression) #endif @@ -1090,6 +1307,9 @@ struct v4l2_streamparm #define VIDIOC_G_SLICED_VBI_CAP _IOR ('V', 69, struct v4l2_sliced_vbi_cap) #endif #define VIDIOC_LOG_STATUS _IO ('V', 70) +#define VIDIOC_G_EXT_CTRLS _IOWR ('V', 71, struct v4l2_ext_controls) +#define VIDIOC_S_EXT_CTRLS _IOWR ('V', 72, struct v4l2_ext_controls) +#define VIDIOC_TRY_EXT_CTRLS _IOWR ('V', 73, struct v4l2_ext_controls) #ifdef __OLD_VIDIOC_ /* for compatibility, will go away some day */ diff --git a/linux/include/media/cx2341x.h b/linux/include/media/cx2341x.h index 7e7dcc072..51fb06b4c 100644 --- a/linux/include/media/cx2341x.h +++ b/linux/include/media/cx2341x.h @@ -19,6 +19,74 @@ #ifndef CX2341X_H #define CX2341X_H +enum cx2341x_port { + CX2341X_PORT_MEMORY = 0, + CX2341X_PORT_STREAMING = 1, + CX2341X_PORT_SERIAL = 2 +}; + +struct cx2341x_mpeg_params { + /* misc */ + enum cx2341x_port port; + u16 width; + u16 height; + u16 is_50hz; + + /* stream */ + enum v4l2_mpeg_stream_type stream_type; + + /* audio */ + enum v4l2_mpeg_audio_sampling_freq audio_sampling_freq; + enum v4l2_mpeg_audio_encoding audio_encoding; + enum v4l2_mpeg_audio_l2_bitrate audio_l2_bitrate; + enum v4l2_mpeg_audio_mode audio_mode; + enum v4l2_mpeg_audio_mode_extension audio_mode_extension; + enum v4l2_mpeg_audio_emphasis audio_emphasis; + enum v4l2_mpeg_audio_crc audio_crc; + u8 audio_properties; + + /* video */ + enum v4l2_mpeg_video_encoding video_encoding; + enum v4l2_mpeg_video_aspect video_aspect; + u16 video_b_frames; + u16 video_gop_size; + u16 video_gop_closure; + u16 video_pulldown; + enum v4l2_mpeg_video_bitrate_mode video_bitrate_mode; + u32 video_bitrate; + u32 video_bitrate_peak; + u16 video_temporal_decimation; + + /* encoding filters */ + enum v4l2_mpeg_cx2341x_video_spatial_filter_mode video_spatial_filter_mode; + u16 video_spatial_filter; + enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type video_luma_spatial_filter_type; + enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type video_chroma_spatial_filter_type; + enum v4l2_mpeg_cx2341x_video_temporal_filter_mode video_temporal_filter_mode; + u16 video_temporal_filter; + enum v4l2_mpeg_cx2341x_video_median_filter_type video_median_filter_type; + u16 video_luma_median_filter_top; + u16 video_luma_median_filter_bottom; + u16 video_chroma_median_filter_top; + u16 video_chroma_median_filter_bottom; +}; + +#define CX2341X_MBOX_MAX_DATA 16 + +extern const u32 cx2341x_mpeg_ctrls[]; +typedef int (*cx2341x_mbox_func)(void *priv, int cmd, int in, int out, + u32 data[CX2341X_MBOX_MAX_DATA]); +int cx2341x_update(void *priv, cx2341x_mbox_func func, + const struct cx2341x_mpeg_params *old, + const struct cx2341x_mpeg_params *new); +int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, + struct v4l2_queryctrl *qctrl); +const char **cx2341x_ctrl_get_menu(u32 id); +int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, + struct v4l2_ext_controls *ctrls, int cmd); +void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p); +void cx2341x_log_status(struct cx2341x_mpeg_params *p, int cardid); + /* Firmware names */ #define CX2341X_FIRM_ENC_FILENAME "v4l-cx2341x-enc.fw" /* Decoder firmware for the cx23415 only */ diff --git a/linux/include/media/v4l2-common.h b/linux/include/media/v4l2-common.h index f1d7a063a..98976fd3b 100644 --- a/linux/include/media/v4l2-common.h +++ b/linux/include/media/v4l2-common.h @@ -90,6 +90,19 @@ extern void v4l_printk_ioctl_arg(char *s,unsigned int cmd, void *arg); /* ------------------------------------------------------------------------- */ +/* Control helper functions */ + +int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl, + const char **menu_items); +const char **v4l2_ctrl_get_menu(u32 id); +int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def); +int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl); +int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, + struct v4l2_queryctrl *qctrl, const char **menu_items); +u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id); + +/* ------------------------------------------------------------------------- */ + /* Internal ioctls */ /* VIDIOC_INT_G_REGISTER and VIDIOC_INT_S_REGISTER */ diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 18f1bd706..39f4b7c69 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -245,6 +245,12 @@ struct video_device struct v4l2_control *a); int (*vidioc_s_ctrl) (struct file *file, void *fh, struct v4l2_control *a); + int (*vidioc_g_ext_ctrls) (struct file *file, void *fh, + struct v4l2_ext_controls *a); + int (*vidioc_s_ext_ctrls) (struct file *file, void *fh, + struct v4l2_ext_controls *a); + int (*vidioc_try_ext_ctrls) (struct file *file, void *fh, + struct v4l2_ext_controls *a); int (*vidioc_querymenu) (struct file *file, void *fh, struct v4l2_querymenu *a); diff --git a/test/Makefile b/test/Makefile index b8bb9b55c..30c3edff6 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,11 +1,19 @@ -FILES = ioctl-test sliced-vbi-test sliced-vbi-detect vbi-test v4lgrab +FILES = ioctl-test sliced-vbi-test sliced-vbi-detect vbi-test v4lgrab v4l2-ctl CC = gcc LIBS = CFLAGS = -O3 -Wall -fomit-frame-pointer -funroll-loops -g -I ../linux/include +CXXFLAGS = $(CFLAGS) LDFLAGS = -all: $(FILES) +all: $(FILES) qv4l2 clean: -rm -f core core.[0123456789]* *~ *.o $(FILES) + -if [ -f qv4l2/Makefile ]; then make -C qv4l2 $@; fi + -rm -f qv4l2/qv4l2 qv4l2/Makefile +qv4l2: + if [ ! -f qv4l2/Makefile ]; then (cd qv4l2; qmake); fi + make -C qv4l2 + +.PHONY: qv4l2 diff --git a/test/qv4l2/fileopen.xpm b/test/qv4l2/fileopen.xpm new file mode 100644 index 000000000..880417eee --- /dev/null +++ b/test/qv4l2/fileopen.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static const char *fileopen[] = { +" 16 13 5 1", +". c #040404", +"# c #808304", +"a c None", +"b c #f3f704", +"c c #f3f7f3", +"aaaaaaaaa...aaaa", +"aaaaaaaa.aaa.a.a", +"aaaaaaaaaaaaa..a", +"a...aaaaaaaa...a", +".bcb.......aaaaa", +".cbcbcbcbc.aaaaa", +".bcbcbcbcb.aaaaa", +".cbcb...........", +".bcb.#########.a", +".cb.#########.aa", +".b.#########.aaa", +"..#########.aaaa", +"...........aaaaa" +}; diff --git a/test/qv4l2/qv4l2.cpp b/test/qv4l2/qv4l2.cpp new file mode 100644 index 000000000..e3d6bf775 --- /dev/null +++ b/test/qv4l2/qv4l2.cpp @@ -0,0 +1,649 @@ + +#include "qv4l2.h" + +#include <qimage.h> +#include <qpixmap.h> +#include <qtoolbar.h> +#include <qtoolbutton.h> +#include <qpopupmenu.h> +#include <qmenubar.h> +#include <qfile.h> +#include <qfiledialog.h> +#include <qstatusbar.h> +#include <qmessagebox.h> +#include <qapplication.h> +#include <qaccel.h> +#include <qlineedit.h> +#include <qvalidator.h> +#include <qlayout.h> +#include <qvbox.h> +#include <qhbox.h> +#include <qlabel.h> +#include <qslider.h> +#include <qspinbox.h> +#include <qcombobox.h> +#include <qcheckbox.h> +#include <qpushbutton.h> +#include <qpainter.h> +#include <qpaintdevicemetrics.h> +#include <qwhatsthis.h> + +#include <fcntl.h> +#include <sys/ioctl.h> +#include <errno.h> + +#include "fileopen.xpm" + +ApplicationWindow::ApplicationWindow() + : QMainWindow( 0, "V4L2 main window", WDestructiveClose | WGroupLeader ) +{ + QPixmap openIcon, saveIcon; + + fd = -1; + + sigMapper = NULL; + QToolBar * fileTools = new QToolBar( this, "file operations" ); + fileTools->setLabel( "File Operations" ); + + openIcon = QPixmap( fileopen ); + QToolButton * fileOpen + = new QToolButton( openIcon, "Open File", QString::null, + this, SLOT(choose()), fileTools, "open file" ); + + (void)QWhatsThis::whatsThisButton( fileTools ); + + const char * fileOpenText = "<p><img source=\"fileopen\"> " + "Click this button to open a <em>new v4l device</em>.<br>" + "You can also select the <b>Open</b> command " + "from the <b>File</b> menu.</p>"; + + QWhatsThis::add( fileOpen, fileOpenText ); + + QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", openIcon ); + + QPopupMenu * file = new QPopupMenu( this ); + menuBar()->insertItem( "&File", file ); + + + int id; + id = file->insertItem( openIcon, "&Open...", + this, SLOT(choose()), CTRL+Key_O ); + file->setWhatsThis( id, fileOpenText ); + + file->insertSeparator(); + + file->insertItem( "&Close", this, SLOT(close()), CTRL+Key_W ); + + file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); + + menuBar()->insertSeparator(); + + QPopupMenu * help = new QPopupMenu( this ); + menuBar()->insertItem( "&Help", help ); + + help->insertItem( "&About", this, SLOT(about()), Key_F1 ); + help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 ); + + statusBar()->message( "Ready", 2000 ); + + tabs = new QTabWidget(this); + tabs->setMargin(3); + + //resize( 450, 600 ); +} + + +ApplicationWindow::~ApplicationWindow() +{ + if (fd >= 0) ::close(fd); +} + + +void ApplicationWindow::setDevice(const QString &device) +{ + if (fd >= 0) ::close(fd); + while (QWidget *page = tabs->page(0)) { + tabs->removePage(page); + delete page; + } + delete tabs; + delete sigMapper; + tabs = new QTabWidget(this); + tabs->setMargin(3); + sigMapper = new QSignalMapper(this); + connect(sigMapper, SIGNAL(mapped(int)), this, SLOT(ctrlAction(int))); + ctrlMap.clear(); + widgetMap.clear(); + classMap.clear(); + + fd = ::open(device, O_RDONLY); + if (fd >= 0) { + addTabs(); + } + if (QWidget *current = tabs->currentPage()) { + current->show(); + } + tabs->show(); + tabs->setFocus(); + setCentralWidget(tabs); +} + +void ApplicationWindow::addTabs() +{ + struct v4l2_queryctrl qctrl; + unsigned ctrl_class; + unsigned i; + int id; + + memset(&qctrl, 0, sizeof(qctrl)); + qctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL; + while (::ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { + if ((qctrl.flags & V4L2_CTRL_FLAG_DISABLED) == 0) { + ctrlMap[qctrl.id] = qctrl; + if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS) + classMap[V4L2_CTRL_ID2CLASS(qctrl.id)].push_back(qctrl.id); + } + qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + } + if (qctrl.id == V4L2_CTRL_FLAG_NEXT_CTRL) { + strcpy((char *)qctrl.name, "User Controls"); + qctrl.id = V4L2_CTRL_CLASS_USER | 1; + qctrl.type = V4L2_CTRL_TYPE_CTRL_CLASS; + ctrlMap[qctrl.id] = qctrl; + for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { + qctrl.id = id; + if (::ioctl(fd, VIDIOC_QUERYCTRL, &qctrl)) + continue; + if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) + continue; + ctrlMap[qctrl.id] = qctrl; + classMap[V4L2_CTRL_CLASS_USER].push_back(qctrl.id); + } + for (qctrl.id = V4L2_CID_PRIVATE_BASE; + ::ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { + if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) + continue; + ctrlMap[qctrl.id] = qctrl; + classMap[V4L2_CTRL_CLASS_USER].push_back(qctrl.id); + } + } + + for (ClassMap::iterator iter = classMap.begin(); iter != classMap.end(); ++iter) { + ctrl_class = V4L2_CTRL_ID2CLASS(iter->second[0]); + id = ctrl_class | 1; + const struct v4l2_queryctrl &qctrl = ctrlMap[id]; + QVBox *vbox = new QVBox(tabs); + QGrid *grid = new QGrid(4, vbox); + grid->setSpacing(3); + tabs->addTab(vbox, (char *)qctrl.name); + for (i = 0; i < iter->second.size(); i++) { + if (i & 1) + id = iter->second[(1+iter->second.size()) / 2 + i / 2]; + else + id = iter->second[i / 2]; + addCtrl(grid, ctrlMap[id]); + } + finishGrid(vbox, grid, ctrl_class, i & 1); + } +} + +void ApplicationWindow::finishGrid(QWidget *vbox, QGrid *grid, unsigned ctrl_class, bool odd) +{ + if (odd) { + new QWidget(grid); + new QWidget(grid); + } + QWidget *stretch = new QWidget(grid); + stretch->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); + + QFrame *frame = new QFrame(vbox); + frame->setFrameShape(QFrame::HLine); + frame->setFrameShadow(QFrame::Sunken); + frame->setMargin(3); + + QHBox *hbox = new QHBox(vbox); + hbox->setSpacing(3); + + QCheckBox *cbox = new QCheckBox("Update on change", hbox); + widgetMap[ctrl_class | CTRL_UPDATE_ON_CHANGE] = cbox; + connect(cbox, SIGNAL(clicked()), sigMapper, SLOT(map())); + sigMapper->setMapping(cbox, ctrl_class | CTRL_UPDATE_ON_CHANGE); + + stretch = new QWidget(hbox); + stretch->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); + + QPushButton *defBut = new QPushButton("Set Defaults", hbox); + widgetMap[ctrl_class | CTRL_DEFAULTS] = defBut; + connect(defBut, SIGNAL(clicked()), sigMapper, SLOT(map())); + sigMapper->setMapping(defBut, ctrl_class | CTRL_DEFAULTS); + + QPushButton *refreshBut = new QPushButton("Refresh", hbox); + widgetMap[ctrl_class | CTRL_REFRESH] = refreshBut; + connect(refreshBut, SIGNAL(clicked()), sigMapper, SLOT(map())); + sigMapper->setMapping(refreshBut, ctrl_class | CTRL_REFRESH); + + QPushButton *button = new QPushButton("Update", hbox); + widgetMap[ctrl_class | CTRL_UPDATE] = button; + connect(button, SIGNAL(clicked()), sigMapper, SLOT(map())); + sigMapper->setMapping(button, ctrl_class | CTRL_UPDATE); + connect(cbox, SIGNAL(toggled(bool)), button, SLOT(setDisabled(bool))); + + cbox->setChecked(ctrl_class == V4L2_CTRL_CLASS_USER); + + refresh(ctrl_class); +} + +void ApplicationWindow::addCtrl(QGrid *grid, const struct v4l2_queryctrl &qctrl) +{ + QIntValidator *val; + QLineEdit *edit; + QString name((char *)qctrl.name); + QComboBox *combo; + struct v4l2_querymenu qmenu; + + QLabel *label = new QLabel(name, grid); + label->setAlignment(Qt::AlignRight); + + switch (qctrl.type) { + case V4L2_CTRL_TYPE_INTEGER: + if (qctrl.flags & V4L2_CTRL_FLAG_SLIDER) { + widgetMap[qctrl.id] = + new QSlider(qctrl.minimum, qctrl.maximum, + qctrl.step, qctrl.default_value, + Horizontal, grid); + connect(widgetMap[qctrl.id], SIGNAL(valueChanged(int)), + sigMapper, SLOT(map())); + break; + } + + if (qctrl.maximum - qctrl.minimum <= 255) { + widgetMap[qctrl.id] = + new QSpinBox(qctrl.minimum, qctrl.maximum, 1, grid); + connect(widgetMap[qctrl.id], SIGNAL(valueChanged(int)), + sigMapper, SLOT(map())); + break; + } + + val = new QIntValidator(qctrl.minimum, qctrl.maximum, grid); + edit = new QLineEdit(grid); + edit->setValidator(val); + widgetMap[qctrl.id] = edit; + connect(widgetMap[qctrl.id], SIGNAL(lostFocus()), + sigMapper, SLOT(map())); + connect(widgetMap[qctrl.id], SIGNAL(returnPressed()), + sigMapper, SLOT(map())); + break; + + case V4L2_CTRL_TYPE_INTEGER64: + widgetMap[qctrl.id] = new QLineEdit(grid); + connect(widgetMap[qctrl.id], SIGNAL(lostFocus()), + sigMapper, SLOT(map())); + connect(widgetMap[qctrl.id], SIGNAL(returnPressed()), + sigMapper, SLOT(map())); + break; + + case V4L2_CTRL_TYPE_BOOLEAN: + label->setText(""); + widgetMap[qctrl.id] = new QCheckBox(name, grid); + connect(widgetMap[qctrl.id], SIGNAL(clicked()), + sigMapper, SLOT(map())); + break; + + case V4L2_CTRL_TYPE_BUTTON: + label->setText(""); + widgetMap[qctrl.id] = new QPushButton((char *)qctrl.name, grid); + connect(widgetMap[qctrl.id], SIGNAL(clicked()), + sigMapper, SLOT(map())); + break; + + case V4L2_CTRL_TYPE_MENU: + combo = new QComboBox(grid); + widgetMap[qctrl.id] = combo; + for (int i = qctrl.minimum; i <= qctrl.maximum; i++) { + qmenu.id = qctrl.id; + qmenu.index = i; + if (::ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) + continue; + combo->insertItem((char *)qmenu.name); + } + connect(widgetMap[qctrl.id], SIGNAL(activated(int)), + sigMapper, SLOT(map())); + break; + + default: + return; + } + sigMapper->setMapping(widgetMap[qctrl.id], qctrl.id); + if (qctrl.flags & (V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_INACTIVE)) + widgetMap[qctrl.id]->setDisabled(true); +} + +void ApplicationWindow::ctrlAction(int id) +{ + unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id); + if (ctrl_class == V4L2_CID_PRIVATE_BASE) + ctrl_class = V4L2_CTRL_CLASS_USER; + unsigned ctrl = id & 0xffff; + QCheckBox *cbox = static_cast<QCheckBox *>(widgetMap[ctrl_class | CTRL_UPDATE_ON_CHANGE]); + bool update = cbox->isChecked(); + bool all = (ctrl == CTRL_UPDATE || (update && ctrl == CTRL_UPDATE_ON_CHANGE)); + + if (ctrl == CTRL_DEFAULTS) { + setDefaults(ctrl_class); + return; + } + if (ctrl == CTRL_REFRESH) { + refresh(ctrl_class); + return; + } + if (!update && !all && ctrlMap[id].type != V4L2_CTRL_TYPE_BUTTON) + return; + if (ctrl_class == V4L2_CTRL_CLASS_USER) { + if (!all) { + updateCtrl(id); + return; + } + for (unsigned i = 0; i < classMap[ctrl_class].size(); i++) { + updateCtrl(classMap[ctrl_class][i]); + } + return; + } + if (!all) { + updateCtrl(id); + return; + } + unsigned count = classMap[ctrl_class].size(); + struct v4l2_ext_control *c = new v4l2_ext_control[count]; + struct v4l2_ext_controls ctrls; + int idx = 0; + + for (unsigned i = 0; i < count; i++) { + unsigned id = classMap[ctrl_class][i]; + + if (ctrlMap[id].flags & (V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_INACTIVE)) + continue; + c[idx].id = id; + if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64) + c[idx].value64 = getVal64(id); + else + c[idx].value = getVal(id); + idx++; + } + memset(&ctrls, 0, sizeof(ctrls)); + ctrls.count = idx; + ctrls.ctrl_class = ctrl_class; + ctrls.controls = c; + if (::ioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls)) { + int err = errno; + + if (ctrls.error_idx >= ctrls.count) { + printf("error: %s\n", strerror(err)); + } + else { + id = c[ctrls.error_idx].id; + printf("error %08x (%s): %s\n", id, + ctrlMap[id].name, strerror(err)); + } + } + delete [] c; + refresh(ctrl_class); +} + +long long ApplicationWindow::getVal64(unsigned id) +{ + const v4l2_queryctrl &qctrl = ctrlMap[id]; + QWidget *w = widgetMap[qctrl.id]; + + switch (qctrl.type) { + case V4L2_CTRL_TYPE_INTEGER64: + return static_cast<QLineEdit *>(w)->text().toLongLong(); + default: + return 0; + } +} + +int ApplicationWindow::getVal(unsigned id) +{ + const v4l2_queryctrl &qctrl = ctrlMap[id]; + QWidget *w = widgetMap[qctrl.id]; + v4l2_querymenu qmenu; + int i, idx; + + switch (qctrl.type) { + case V4L2_CTRL_TYPE_INTEGER: + if (qctrl.flags & V4L2_CTRL_FLAG_SLIDER) { + return static_cast<QSlider *>(w)->value(); + } + + if (qctrl.maximum - qctrl.minimum <= 255) { + return static_cast<QSpinBox *>(w)->value(); + } + return static_cast<QLineEdit *>(w)->text().toInt(); + + case V4L2_CTRL_TYPE_BOOLEAN: + return static_cast<QCheckBox *>(w)->isChecked(); + + case V4L2_CTRL_TYPE_MENU: + idx = static_cast<QComboBox *>(w)->currentItem(); + for (i = qctrl.minimum; i <= qctrl.maximum; i++) { + qmenu.id = qctrl.id; + qmenu.index = i; + if (::ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) + continue; + if (idx-- == 0) + break; + } + return i; + + default: + break; + } + return 0; +} + +void ApplicationWindow::updateCtrl(unsigned id) +{ + unsigned ctrl_class = V4L2_CTRL_ID2CLASS(id); + if (ctrl_class == V4L2_CID_PRIVATE_BASE) + ctrl_class = V4L2_CTRL_CLASS_USER; + + if (ctrlMap[id].flags & (V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_INACTIVE)) + return; + + if (ctrl_class == V4L2_CTRL_CLASS_USER) { + struct v4l2_control c; + + c.id = id; + c.value = getVal(id); + if (::ioctl(fd, VIDIOC_S_CTRL, &c)) { + int err = errno; + + printf("error %08x (%s): %s\n", id, + ctrlMap[id].name, strerror(err)); + } + return; + } + struct v4l2_ext_control c; + struct v4l2_ext_controls ctrls; + + memset(&c, 0, sizeof(c)); + memset(&ctrls, 0, sizeof(ctrls)); + c.id = id; + if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64) + c.value64 = getVal64(id); + else + c.value = getVal(id); + ctrls.count = 1; + ctrls.ctrl_class = ctrl_class; + ctrls.controls = &c; + if (::ioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls)) { + int err = errno; + + printf("error %08x (%s): %s\n", id, + ctrlMap[id].name, strerror(err)); + } + else if (ctrlMap[id].flags & V4L2_CTRL_FLAG_UPDATE) + refresh(ctrl_class); + else { + if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64) + setVal64(id, c.value64); + else + setVal(id, c.value); + } +} + +void ApplicationWindow::refresh(unsigned ctrl_class) +{ + if (ctrl_class == V4L2_CTRL_CLASS_USER) { + for (unsigned i = 0; i < classMap[ctrl_class].size(); i++) { + unsigned id = classMap[ctrl_class][i]; + + v4l2_control c; + + c.id = id; + if (::ioctl(fd, VIDIOC_G_CTRL, &c)) { + int err = errno; + + printf("error %08x (%s): %s\n", id, + ctrlMap[id].name, strerror(err)); + } + setVal(id, c.value); + } + return; + } + unsigned count = classMap[ctrl_class].size(); + struct v4l2_ext_control *c = new v4l2_ext_control[count]; + struct v4l2_ext_controls ctrls; + + for (unsigned i = 0; i < count; i++) { + c[i].id = classMap[ctrl_class][i]; + } + memset(&ctrls, 0, sizeof(ctrls)); + ctrls.count = count; + ctrls.ctrl_class = ctrl_class; + ctrls.controls = c; + if (::ioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls)) { + int err = errno; + + if (ctrls.error_idx >= ctrls.count) { + printf("error: %s\n", strerror(err)); + } + else { + unsigned id = c[ctrls.error_idx].id; + printf("error %08x (%s): %s\n", id, + ctrlMap[id].name, strerror(err)); + } + } + else { + for (unsigned i = 0; i < ctrls.count; i++) { + unsigned id = c[i].id; + if (ctrlMap[id].type == V4L2_CTRL_TYPE_INTEGER64) + setVal64(id, c[i].value64); + else + setVal(id, c[i].value); + ::ioctl(fd, VIDIOC_QUERYCTRL, &ctrlMap[id]); + widgetMap[id]->setDisabled(ctrlMap[id].flags & + (V4L2_CTRL_FLAG_READ_ONLY | V4L2_CTRL_FLAG_INACTIVE)); + } + } + delete [] c; +} + +void ApplicationWindow::setVal(unsigned id, int v) +{ + const v4l2_queryctrl &qctrl = ctrlMap[id]; + v4l2_querymenu qmenu; + QWidget *w = widgetMap[qctrl.id]; + int i, idx; + + switch (qctrl.type) { + case V4L2_CTRL_TYPE_INTEGER: + if (qctrl.flags & V4L2_CTRL_FLAG_SLIDER) + static_cast<QSlider *>(w)->setValue(v); + else if (qctrl.maximum - qctrl.minimum <= 255) + static_cast<QSpinBox *>(w)->setValue(v); + else + static_cast<QLineEdit *>(w)->setText(QString::number(v)); + break; + + case V4L2_CTRL_TYPE_BOOLEAN: + static_cast<QCheckBox *>(w)->setChecked(v); + break; + + case V4L2_CTRL_TYPE_MENU: + idx = 0; + for (i = qctrl.minimum; i <= v; i++) { + qmenu.id = id; + qmenu.index = i; + if (::ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) + continue; + idx++; + } + static_cast<QComboBox *>(w)->setCurrentItem(idx - 1); + break; + default: + break; + } +} + +void ApplicationWindow::setVal64(unsigned id, long long v) +{ + const v4l2_queryctrl &qctrl = ctrlMap[id]; + QWidget *w = widgetMap[qctrl.id]; + + switch (qctrl.type) { + case V4L2_CTRL_TYPE_INTEGER64: + static_cast<QLineEdit *>(w)->setText(QString::number(v)); + break; + default: + break; + } +} + +void ApplicationWindow::setDefaults(unsigned ctrl_class) +{ + for (unsigned i = 0; i < classMap[ctrl_class].size(); i++) { + unsigned id = classMap[ctrl_class][i]; + + if (ctrlMap[id].type != V4L2_CTRL_TYPE_INTEGER64 && + ctrlMap[id].type != V4L2_CTRL_TYPE_BUTTON) + setVal(id, ctrlMap[id].default_value); + } + ctrlAction(ctrl_class | CTRL_UPDATE); +} + +void ApplicationWindow::choose() +{ + QString fn = QFileDialog::getOpenFileName( "/dev/v4l", QString::null, + this); + if ( !fn.isEmpty() ) { + setDevice(fn); + } + else + statusBar()->message( "Loading aborted", 2000 ); +} + + +void ApplicationWindow::closeEvent( QCloseEvent* ce ) +{ + ce->accept(); +} + + +void ApplicationWindow::about() +{ + QMessageBox::about( this, "V4L2 Control Panel", + "This program allows easy experimenting with video4linux devices."); +} + + +int main(int argc, char **argv) +{ + QApplication a(argc, argv); + ApplicationWindow *mw = new ApplicationWindow(); + mw->setCaption( "V4L2 Control Panel" ); + mw->setDevice("/dev/video0"); + mw->show(); + a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); + return a.exec(); +} diff --git a/test/qv4l2/qv4l2.h b/test/qv4l2/qv4l2.h new file mode 100644 index 000000000..f3ecf7262 --- /dev/null +++ b/test/qv4l2/qv4l2.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** $Id: qt/application.h 3.3.6 edited Aug 31 2005 $ +** +** Copyright (C) 1992-2005 Trolltech AS. All rights reserved. +** +** This file is part of an example program for Qt. This example +** program may be used, distributed and modified without limitation. +** +*****************************************************************************/ + +#ifndef APPLICATION_H +#define APPLICATION_H + +#include <qmainwindow.h> +#include <qtabwidget.h> +#include <qsignalmapper.h> +#include <qgrid.h> +#include <map> +#include <vector> + +#define __user +#include <linux/videodev2.h> + +class QTextEdit; + +typedef std::vector<unsigned> ClassIDVec; +typedef std::map<unsigned, ClassIDVec> ClassMap; +typedef std::map<unsigned, struct v4l2_queryctrl> CtrlMap; +typedef std::map<unsigned, QWidget *> WidgetMap; + +enum { + CTRL_UPDATE_ON_CHANGE = 0x10, + CTRL_DEFAULTS, + CTRL_REFRESH, + CTRL_UPDATE +}; + +class ApplicationWindow: public QMainWindow +{ + Q_OBJECT + +public: + ApplicationWindow(); + ~ApplicationWindow(); + + void setDevice(const QString &device); + +protected: + void closeEvent( QCloseEvent* ); + +private slots: + void choose(); + void ctrlAction(int); + + void about(); + +private: + void addTabs(); + void finishGrid(QWidget *vbox, QGrid *grid, unsigned ctrl_class, bool odd); + void addCtrl(QGrid *grid, const struct v4l2_queryctrl &qctrl); + void updateCtrl(unsigned id); + void refresh(unsigned ctrl_class); + void setDefaults(unsigned ctrl_class); + int getVal(unsigned id); + long long getVal64(unsigned id); + void setVal(unsigned id, int v); + void setVal64(unsigned id, long long v); + + QString filename; + QSignalMapper *sigMapper; + QTabWidget *tabs; + int fd; + CtrlMap ctrlMap; + WidgetMap widgetMap; + ClassMap classMap; +}; + + +#endif diff --git a/test/qv4l2/qv4l2.pro b/test/qv4l2/qv4l2.pro new file mode 100644 index 000000000..62eb56b07 --- /dev/null +++ b/test/qv4l2/qv4l2.pro @@ -0,0 +1,10 @@ +###################################################################### +# Automatically generated by qmake (1.07a) Sat Jun 17 12:35:16 2006 +###################################################################### + +TEMPLATE = app +INCLUDEPATH += . ../../linux/include + +# Input +HEADERS += qv4l2.h +SOURCES += qv4l2.cpp diff --git a/test/v4l2-ctl.cpp b/test/v4l2-ctl.cpp new file mode 100644 index 000000000..deb7f3fb9 --- /dev/null +++ b/test/v4l2-ctl.cpp @@ -0,0 +1,1249 @@ +/* + Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo dot com> + + Cleanup and VBI and audio in/out options: + Copyright (C) 2004 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 <unistd.h> +#include <features.h> /* Uses _GNU_SOURCE to define getsubopt in stdlib.h */ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <inttypes.h> +#include <getopt.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/time.h> +#include <math.h> +#include <sys/klog.h> + +#define __user +#include <linux/videodev2.h> + +#include <list> +#include <vector> +#include <map> +#include <string> + +/* Short option list + + Please keep in alphabetical order. + That makes it easier to see which short options are still free. + + In general the lower case is used to set something and the upper + case is used to retrieve a setting. */ +enum Option { + OptGetAudioInput = 'A', + OptSetAudioInput = 'a', + OptGetAudioOutput = 'B', + OptSetAudioOutput = 'b', + OptGetCtrl = 'C', + OptSetCtrl = 'c', + OptSetDevice = 'd', + OptGetDriverInfo = 'D', + OptGetFreq = 'F', + OptSetFreq = 'f', + OptHelp = 'h', + OptGetInput = 'I', + OptSetInput = 'i', + OptListCtrls = 'l', + OptListCtrlsMenus = 'L', + OptListOutputs = 'N', + OptListInputs = 'n', + OptGetOutput = 'O', + OptSetOutput = 'o', + OptListAudioOutputs = 'Q', + OptListAudioInputs = 'q', + OptGetStandard = 'S', + OptSetStandard = 's', + OptGetTuner = 'T', + OptSetTuner = 't', + OptGetVideoFormat = 'V', + OptSetVideoFormat = 'v', + OptLast = 128 +}; + +static char options[OptLast]; +static int option_all = 0; +static int option_streamoff = 0; +static int option_streamon = 0; +static int option_list_stds = 0; +static int option_version = 0; +static int option_log_status = 0; +static int option_verbose = 0; + +typedef std::vector<struct v4l2_ext_control> ctrl_list; +static ctrl_list user_ctrls; +static ctrl_list mpeg_ctrls; + +typedef std::map<std::string, unsigned> ctrl_strmap; +static ctrl_strmap ctrl_str2id; +typedef std::map<unsigned, std::string> ctrl_idmap; +static ctrl_idmap ctrl_id2str; + +typedef std::list<std::string> ctrl_get_list; +static ctrl_get_list get_ctrls; + +typedef std::map<std::string,std::string> ctrl_set_map; +static ctrl_set_map set_ctrls; + +/* fmts specified */ +#define FMTWidth (1L<<0) +#define FMTHeight (1L<<1) + +static struct option long_options[] = { + {"list-audio-inputs", no_argument, 0, OptListAudioInputs}, + {"list-audio-outputs", no_argument, 0, OptListAudioOutputs}, + {"all", no_argument, &option_all, 1}, + {"device", required_argument, 0, OptSetDevice}, + {"get-format", no_argument, 0, OptGetVideoFormat}, + {"set-format", required_argument, 0, OptSetVideoFormat}, + {"help", no_argument, 0, OptHelp}, + {"get-output", no_argument, 0, OptGetOutput}, + {"set-output", required_argument, 0, OptSetOutput}, + {"list-outputs", no_argument, 0, OptListOutputs}, + {"list-inputs", no_argument, 0, OptListInputs}, + {"get-input", no_argument, 0, OptGetInput}, + {"set-input", required_argument, 0, OptSetInput}, + {"get-audio-input", no_argument, 0, OptGetAudioInput}, + {"set-audio-input", required_argument, 0, OptSetAudioInput}, + {"get-audio-output", no_argument, 0, OptGetAudioOutput}, + {"set-audio-output", required_argument, 0, OptSetAudioOutput}, + {"get-freq", no_argument, 0, OptGetFreq}, + {"set-freq", required_argument, 0, OptSetFreq}, + {"streamoff", no_argument, &option_streamoff, 1}, + {"streamon", no_argument, &option_streamon, 1}, + {"list-standards", no_argument, &option_list_stds, 1}, + {"get-standard", no_argument, 0, OptGetStandard}, + {"set-standard", required_argument, 0, OptSetStandard}, + {"info", no_argument, 0, OptGetDriverInfo}, + {"list-ctrls", no_argument, 0, OptListCtrls}, + {"list-ctrls-menus", no_argument, 0, OptListCtrlsMenus}, + {"set-ctrl", required_argument, 0, OptSetCtrl}, + {"get-ctrl", required_argument, 0, OptGetCtrl}, + {"get-tuner", no_argument, 0, OptGetTuner}, + {"set-tuner", required_argument, 0, OptSetTuner}, + {"version", no_argument, &option_version, 1}, + {"verbose", no_argument, &option_verbose, 1}, + {"log-status", no_argument, &option_log_status, 1}, + {0, 0, 0, 0} +}; + +void usage(void) +{ + printf("Usage:\n"); + printf(" --all display all information available\n"); + printf(" -A, --get-audio-input\n"); + printf(" query the current audio input [VIDIOC_G_AUDIO]\n"); + printf(" -a, --set-audio-input=<num>\n"); + printf(" set the current audio input to <num> [VIDIOC_S_AUDIO]\n"); + printf(" -B, --get-audio-output\n"); + printf(" query the current audio output [VIDIOC_G_AUDOUT]\n"); + printf(" -b, --set-audio-output=<num>\n"); + printf(" set the current audio output to <num> [VIDIOC_S_AUDOUT]\n"); + printf(" -C, --get-ctrl=<ctrl>[,<ctrl>...]\n"); + printf(" get the value of the controls [VIDIOC_G_EXT_CTRLS]\n"); + printf(" -c, --set-ctrl=<ctrl>=<val>[,<ctrl>=<val>...]\n"); + printf(" set the controls to the values specified [VIDIOC_S_EXT_CTRLS]\n"); + printf(" -D, --info show driver info [VIDIOC_QUERYCAP]\n"); + printf(" -d, --device=<dev> use device <dev> instead of /dev/video0\n"); + printf(" if <dev> is a single digit, then /dev/video<dev> is used\n"); + printf(" -F, --get-freq query the current frequency [VIDIOC_G_FREQUENCY]\n"); + printf(" -f, --set-freq=<freq>\n"); + printf(" set the current frequency to <freq> MHz [VIDIOC_S_FREQUENCY]\n"); + printf(" -h, --help display this help message\n"); + printf(" -I, --get-input query the current video input [VIDIOC_G_INPUT]\n"); + printf(" -i, --set-input=<num>\n"); + printf(" set the current video input to <num> [VIDIOC_S_INPUT]\n"); + printf(" -l, --list-ctrls display all controls and their values [VIDIOC_QUERYCTRL]\n"); + printf(" -L, --list-ctrls-menus\n"); + printf(" display all controls, their values and the menus [VIDIOC_QUERYMENU]\n"); + printf(" -N, --list-outputs display video outputs [VIDIOC_ENUMOUTPUT]\n"); + printf(" -n, --list-inputs display video inputs [VIDIOC_ENUMINPUT]\n"); + printf(" -O, --get-output query the current video output [VIDIOC_G_OUTPUT]\n"); + printf(" -o, --set-output=<num>\n"); + printf(" set the current video output to <num> [VIDIOC_S_OUTPUT]\n"); + printf(" -Q, --list-audio-outputs\n"); + printf(" display audio outputs [VIDIOC_ENUMAUDOUT]\n"); + printf(" -q, --list-audio-inputs\n"); + printf(" display audio inputs [VIDIOC_ENUMAUDIO]\n"); + printf(" -S, --get-standard\n"); + printf(" query the current video standard [VIDIOC_G_STD]\n"); + printf(" -s, --set-standard=<num>\n"); + printf(" set the current video standard to <num> [VIDIOC_S_STD]\n"); + printf(" <num> can be a numerical v4l2_std value, or it can be one of:\n"); + printf(" pal-X (X = B/G/H/N/Nc/I/D/K/M) or just 'pal' (V4L2_STD_PAL)\n"); + printf(" ntsc-X (X = M/J/K) or just 'ntsc' (V4L2_STD_NTSC)\n"); + printf(" secam-X (X = B/G/H/D/K/L/Lc) or just 'secam' (V4L2_STD_SECAM)\n"); + printf(" --list-standards display supported video standards [VIDIOC_ENUMSTD]\n"); + printf(" -T, --get-tuner query the current tuner settings [VIDIOC_G_TUNER]\n"); + printf(" -t, --set-tuner=<mode>\n"); + printf(" set the audio mode of the tuner [VIDIOC_S_TUNER]\n"); + printf(" -V, --get-format query the current data format [VIDIOC_G_FMT]\n"); + printf(" -v, --set-format=width=<x>,height=<y>\n"); + printf(" set the current data format [VIDIOC_S_FMT]\n"); + printf(" Possible values: 0 (mono), 1 (stereo), 2 (lang2), 3 (lang1), 4 (both)\n"); + printf(" --verbose turn on verbose ioctl error reporting.\n"); + printf(" --version shows the version number of this utility.\n"); + printf("\n"); + printf("Expert options:\n"); + printf(" --streamoff turn the stream off [VIDIOC_STREAMOFF]\n"); + printf(" --streamon turn the stream on [VIDIOC_STREAMOFF]\n"); + printf(" --log-status log the board status in the kernel log [VIDIOC_LOG_STATUS]\n"); + exit(0); +} + + +static std::string name2var(unsigned char *name) +{ + std::string s; + + while (*name) { + if (*name == ' ') s += "_"; + else s += std::string(1, tolower(*name)); + name++; + } + return s; +} + +static void print_qctrl(int fd, struct v4l2_queryctrl *queryctrl, + struct v4l2_ext_control *ctrl, int show_menus) +{ + struct v4l2_querymenu qmenu = { 0 }; + std::string s = name2var(queryctrl->name); + int i; + + qmenu.id = queryctrl->id; + switch (queryctrl->type) { + case V4L2_CTRL_TYPE_INTEGER: + printf("%31s (int) : min=%d max=%d step=%d default=%d value=%d", + s.c_str(), + queryctrl->minimum, queryctrl->maximum, + queryctrl->step, queryctrl->default_value, + ctrl->value); + break; + case V4L2_CTRL_TYPE_INTEGER64: + printf("%31s (int64): value=%lld", queryctrl->name, ctrl->value64); + break; + case V4L2_CTRL_TYPE_BOOLEAN: + printf("%31s (bool) : default=%d value=%d", + s.c_str(), + queryctrl->default_value, ctrl->value); + break; + case V4L2_CTRL_TYPE_MENU: + printf("%31s (menu) : min=%d max=%d default=%d value=%d", + s.c_str(), + queryctrl->minimum, queryctrl->maximum, + queryctrl->default_value, ctrl->value); + break; + case V4L2_CTRL_TYPE_BUTTON: + printf("%31s (button)\n", s.c_str()); + break; + default: break; + } + if (queryctrl->flags) { + printf(" flags="); + if (queryctrl->flags & V4L2_CTRL_FLAG_GRABBED) + printf("grabbed "); + if (queryctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) + printf("readonly "); + if (queryctrl->flags & V4L2_CTRL_FLAG_UPDATE) + printf("update "); + if (queryctrl->flags & V4L2_CTRL_FLAG_INACTIVE) + printf("inactive "); + if (queryctrl->flags & V4L2_CTRL_FLAG_SLIDER) + printf("slider "); + } + printf("\n"); + if (queryctrl->type == V4L2_CTRL_TYPE_MENU && show_menus) { + for (i = 0; i <= queryctrl->maximum; i++) { + qmenu.index = i; + if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu)) + continue; + printf("\t\t\t\t%d: %s\n", i, qmenu.name); + } + } +} + +static int print_control(int fd, struct v4l2_queryctrl &qctrl, int show_menus) +{ + struct v4l2_control ctrl = { 0 }; + struct v4l2_ext_control ext_ctrl = { 0 }; + struct v4l2_ext_controls ctrls = { 0 }; + + if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) + return 1; + if (qctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) { + printf("\n%s\n\n", qctrl.name); + return 1; + } + ext_ctrl.id = qctrl.id; + ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(qctrl.id); + ctrls.count = 1; + ctrls.controls = &ext_ctrl; + if (V4L2_CTRL_ID2CLASS(qctrl.id) != V4L2_CTRL_CLASS_USER && + qctrl.id < V4L2_CID_PRIVATE_BASE) { + if (ioctl(fd, VIDIOC_G_EXT_CTRLS, &ctrls)) { + printf("error %d getting ext_ctrl %s\n", + errno, qctrl.name); + return 0; + } + } + else { + ctrl.id = qctrl.id; + if (ioctl(fd, VIDIOC_G_CTRL, &ctrl)) { + printf("error %d getting ctrl %s\n", + errno, qctrl.name); + return 0; + } + ext_ctrl.value = ctrl.value; + } + print_qctrl(fd, &qctrl, &ext_ctrl, show_menus); + return 1; +} + +static void list_controls(int fd, int show_menus) +{ + struct v4l2_queryctrl qctrl = { V4L2_CTRL_FLAG_NEXT_CTRL }; + int id; + + while (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { + print_control(fd, qctrl, show_menus); + qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + } + if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL) + return; + for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { + qctrl.id = id; + if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) + print_control(fd, qctrl, show_menus); + } + for (qctrl.id = V4L2_CID_PRIVATE_BASE; + ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { + print_control(fd, qctrl, show_menus); + } +} + +static void find_controls(int fd) +{ + struct v4l2_queryctrl qctrl = { V4L2_CTRL_FLAG_NEXT_CTRL }; + int id; + + while (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) { + if (qctrl.type != V4L2_CTRL_TYPE_CTRL_CLASS) { + ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + ctrl_id2str[qctrl.id] = name2var(qctrl.name); + } + qctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL; + } + if (qctrl.id != V4L2_CTRL_FLAG_NEXT_CTRL) + return; + for (id = V4L2_CID_USER_BASE; id < V4L2_CID_LASTP1; id++) { + qctrl.id = id; + if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0) + ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + } + for (qctrl.id = V4L2_CID_PRIVATE_BASE; + ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == 0; qctrl.id++) { + ctrl_str2id[name2var(qctrl.name)] = qctrl.id; + } +} + +int printfmt(struct v4l2_format vfmt) +{ + printf("Format:\n"); + + switch (vfmt.type) { + case 1: + printf("\tType : Video Capture\n"); + printf("\tWidth : %d\n", vfmt.fmt.pix.width); + printf("\tHeight : %d\n", vfmt.fmt.pix.height); + break; + case 2: + printf("\tType : Video Output\n"); + break; + case 3: + printf("\tType : Video Overlay\n"); + break; + case 4: + printf("\tType : VBI Capture\n"); + break; + case 5: + printf("\tType : VBI Output\n"); + break; + case 0x80: + printf("\tType : Private\n"); + break; + default: + printf("\tType : Unknown: %d\n", vfmt.type); + return -1; + break; + } + return 0; +} + +char *pts_to_string(char *str, unsigned long pts) +{ + static char buf[256]; + int hours, minutes, seconds, fracsec; + float fps; + int frame; + char *p = (str) ? str : buf; + + static const int MPEG_CLOCK_FREQ = 90000; + seconds = pts / MPEG_CLOCK_FREQ; + fracsec = pts % MPEG_CLOCK_FREQ; + + minutes = seconds / 60; + seconds = seconds % 60; + + hours = minutes / 60; + minutes = minutes % 60; + + fps = 30; + frame = (int)ceilf(((float)fracsec / (float)MPEG_CLOCK_FREQ) * fps); + + snprintf(p, sizeof(buf), "%d:%02d:%02d:%d", hours, minutes, seconds, + frame); + return p; +} + +static const char *audmode2s(int audmode) +{ + switch (audmode) { + case V4L2_TUNER_MODE_STEREO: return "stereo"; + case V4L2_TUNER_MODE_LANG1: return "lang1"; + case V4L2_TUNER_MODE_LANG2: return "lang2"; + case V4L2_TUNER_MODE_LANG1_LANG2: return "bilingual"; + case V4L2_TUNER_MODE_MONO: return "mono"; + default: return "unknown"; + } +} + +static std::string rxsubchans2s(int rxsubchans) +{ + std::string s; + + if (rxsubchans & V4L2_TUNER_SUB_MONO) + s += "mono "; + if (rxsubchans & V4L2_TUNER_SUB_STEREO) + s += "stereo "; + if (rxsubchans & V4L2_TUNER_SUB_LANG1) + s += "lang1 "; + if (rxsubchans & V4L2_TUNER_SUB_LANG2) + s += "lang2 "; + return s; +} + +static std::string tcap2s(unsigned cap) +{ + std::string s; + + if (cap & V4L2_TUNER_CAP_LOW) + s += "62.5 Hz "; + else + s += "62.5 kHz "; + if (cap & V4L2_TUNER_CAP_NORM) + s += "multi-standard "; + if (cap & V4L2_TUNER_CAP_STEREO) + s += "stereo "; + if (cap & V4L2_TUNER_CAP_LANG1) + s += "lang1 "; + if (cap & V4L2_TUNER_CAP_LANG2) + s += "lang2 "; + return s; +} + +static std::string cap2s(unsigned cap) +{ + std::string s; + + if (cap & V4L2_CAP_VIDEO_CAPTURE) + s += "\t\tVideo Capture\n"; + if (cap & V4L2_CAP_VIDEO_OUTPUT) + s += "\t\tVideo Output\n"; + if (cap & V4L2_CAP_VIDEO_OVERLAY) + s += "\t\tVideo Overlay\n"; + if (cap & V4L2_CAP_VBI_CAPTURE) + s += "\t\tVBI Capture\n"; + if (cap & V4L2_CAP_VBI_OUTPUT) + s += "\t\tVBI Output\n"; + if (cap & V4L2_CAP_SLICED_VBI_CAPTURE) + s += "\t\tSliced VBI Capture\n"; + if (cap & V4L2_CAP_SLICED_VBI_OUTPUT) + s += "\t\tSliced VBI Output\n"; + if (cap & V4L2_CAP_RDS_CAPTURE) + s += "\t\tRDS Capture\n"; + if (cap & V4L2_CAP_TUNER) + s += "\t\tTuner\n"; + if (cap & V4L2_CAP_AUDIO) + s += "\t\tAudio\n"; + if (cap & V4L2_CAP_RADIO) + s += "\t\tRadio\n"; + if (cap & V4L2_CAP_READWRITE) + s += "\t\tRead/Write\n"; + if (cap & V4L2_CAP_ASYNCIO) + s += "\t\tAsync I/O\n"; + if (cap & V4L2_CAP_STREAMING) + s += "\t\tStreaming\n"; + return s; +} + +static v4l2_std_id parse_pal(const char *pal) +{ + if (pal[0] == '-') { + switch (pal[1]) { + case 'b': + case 'B': + case 'g': + case 'G': + return V4L2_STD_PAL_BG; + case 'h': + case 'H': + return V4L2_STD_PAL_H; + case 'n': + case 'N': + if (pal[2] == 'c' || pal[2] == 'C') + return V4L2_STD_PAL_Nc; + return V4L2_STD_PAL_N; + case 'i': + case 'I': + return V4L2_STD_PAL_I; + case 'd': + case 'D': + case 'k': + case 'K': + return V4L2_STD_PAL_DK; + case 'M': + case 'm': + return V4L2_STD_PAL_M; + case '-': + break; + } + } + fprintf(stderr, "pal specifier not recognised\n"); + return 0; +} + +static v4l2_std_id parse_secam(const char *secam) +{ + if (secam[0] == '-') { + switch (secam[1]) { + case 'b': + case 'B': + case 'g': + case 'G': + case 'h': + case 'H': + return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; + case 'd': + case 'D': + case 'k': + case 'K': + return V4L2_STD_SECAM_DK; + case 'l': + case 'L': + if (secam[2] == 'C' || secam[2] == 'c') + return V4L2_STD_SECAM_LC; + return V4L2_STD_SECAM_L; + case '-': + break; + } + } + fprintf(stderr, "secam specifier not recognised\n"); + return 0; +} + +static v4l2_std_id parse_ntsc(const char *ntsc) +{ + if (ntsc[0] == '-') { + switch (ntsc[1]) { + case 'm': + case 'M': + return V4L2_STD_NTSC_M; + case 'j': + case 'J': + return V4L2_STD_NTSC_M_JP; + case 'k': + case 'K': + return V4L2_STD_NTSC_M_KR; + case '-': + break; + } + } + fprintf(stderr, "ntsc specifier not recognised\n"); + return 0; +} + +static int doioctl(int fd, int request, void *parm, const char *name) +{ + int retVal; + + if (!option_verbose) return ioctl(fd, request, parm); + retVal = ioctl(fd, request, parm); + if (retVal < 0) + printf("failed: %s\n", strerror(errno)); + else + printf("ok\n"); + + return retVal; +} + +static int parse_subopt(char **subs, char * const *subopts, char **value) +{ + int opt = getsubopt(subs, subopts, value); + + if (opt == -1) { + fprintf(stderr, "Invalid suboptions specified\n"); + usage(); + exit(1); + } + if (value == NULL) { + fprintf(stderr, "No value given to suboption <%s>\n", + subopts[opt]); + usage(); + exit(1); + } + return opt; +} + +static void parse_next_subopt(char **subs, char **value) +{ + static char *const subopts[] = { + NULL + }; + int opt = getsubopt(subs, subopts, value); + + if (value == NULL) { + fprintf(stderr, "No value given to suboption <%s>\n", + subopts[opt]); + usage(); + exit(1); + } +} + +int main(int argc, char **argv) +{ + char *value, *subs; + int i; + + int fd = -1; + + /* bitfield for fmts */ + unsigned int set_fmts = 0; + + int mode = V4L2_TUNER_MODE_STEREO; /* set audio mode */ + + /* command args */ + char ch, *device = strdup("/dev/video0"); /* -d device */ + struct v4l2_format vfmt; /* set_format/get_format */ + struct v4l2_tuner tuner; /* set_tuner/get_tuner */ + struct v4l2_capability vcap; /* list_cap */ + struct v4l2_input vin; /* list_inputs */ + struct v4l2_output vout; /* list_outputs */ + struct v4l2_audio vaudio; /* list audio inputs */ + struct v4l2_audioout vaudout = { 0 }; /* audio outputs */ + int input; /* set_input/get_input */ + int output; /* set_output/get_output */ + v4l2_std_id std; /* get_std/set_std */ + double freq = 0; /* get/set frequency */ + struct v4l2_frequency vf; /* get_freq/set_freq */ + struct v4l2_standard vs; /* list_std */ + char short_options[26 * 2 * 2 + 1]; + int idx = 0; + + if (argc == 1) { + usage(); + return 0; + } + for (i = 0; long_options[i].name; i++) { + if (!isalpha(long_options[i].val)) + continue; + short_options[idx++] = long_options[i].val; + if (long_options[i].has_arg == required_argument) + short_options[idx++] = ':'; + } + while (1) { + int option_index = 0; + + short_options[idx] = 0; + ch = getopt_long(argc, argv, short_options, + long_options, &option_index); + if (ch == -1) + break; + + options[(int)ch] = 1; + switch (ch) { + case OptHelp: + usage(); + return 0; + case OptSetDevice: + device = strdup(optarg); + if (device[0] >= '0' && device[0] <= '9' && device[1] == 0) { + char dev = device[0]; + + sprintf(device, "/dev/video%c", dev); + } + break; + case OptSetVideoFormat: + subs = optarg; + while (*subs != '\0') { + static char *const subopts[] = { + "width", + "height", + NULL + }; + + switch (parse_subopt(&subs, subopts, &value)) { + case 0: + vfmt.fmt.pix.width = strtol(value, 0L, 0); + set_fmts |= FMTWidth; + break; + case 1: + vfmt.fmt.pix.height = strtol(value, 0L, 0); + set_fmts |= FMTHeight; + break; + } + } + break; + case OptSetInput: + input = strtol(optarg, 0L, 0); + break; + case OptSetOutput: + output = strtol(optarg, 0L, 0); + break; + case OptSetAudioInput: + vaudio.index = strtol(optarg, 0L, 0); + break; + case OptSetAudioOutput: + vaudout.index = strtol(optarg, 0L, 0); + break; + case OptSetFreq: + freq = strtod(optarg, NULL); + break; + case OptSetStandard: + if (!strncmp(optarg, "pal", 3)) { + if (optarg[3]) + std = parse_pal(optarg + 3); + else + std = V4L2_STD_PAL; + } + else if (!strncmp(optarg, "ntsc", 4)) { + if (optarg[4]) + std = parse_ntsc(optarg + 4); + else + std = V4L2_STD_NTSC; + } + else if (!strncmp(optarg, "secam", 5)) { + if (optarg[5]) + std = parse_secam(optarg + 5); + else + std = V4L2_STD_SECAM; + } + else { + std = strtol(optarg, 0L, 0); + } + break; + case OptGetCtrl: + subs = optarg; + while (*subs != '\0') { + parse_next_subopt(&subs, &value); + if (strchr(value, '=')) { + usage(); + exit(1); + } + else { + get_ctrls.push_back(value); + } + } + break; + case OptSetCtrl: + subs = optarg; + while (*subs != '\0') { + parse_next_subopt(&subs, &value); + if (const char *equal = strchr(value, '=')) { + set_ctrls[std::string(value, (equal - value))] = equal + 1; + } + else { + fprintf(stderr, "control '%s' without '='\n", value); + exit(1); + } + } + break; + case OptSetTuner: + if (!strcmp(optarg, "stereo")) + mode = V4L2_TUNER_MODE_STEREO; + else if (!strcmp(optarg, "lang1")) + mode = V4L2_TUNER_MODE_LANG1; + else if (!strcmp(optarg, "lang2")) + mode = V4L2_TUNER_MODE_LANG2; + else if (!strcmp(optarg, "bilingual")) + mode = V4L2_TUNER_MODE_LANG1_LANG2; + else if (!strcmp(optarg, "mono")) + mode = V4L2_TUNER_MODE_MONO; + else { + fprintf(stderr, "Unknown audio mode\n"); + usage(); + return 1; + } + break; + case ':': + fprintf(stderr, "Option `%s' requires a value\n", + argv[optind]); + usage(); + return 1; + case '?': + fprintf(stderr, "Unknown argument `%s'\n", + argv[optind]); + usage(); + return 1; + } + } + if (optind < argc) { + printf("unknown arguments: "); + while (optind < argc) + printf("%s ", argv[optind++]); + printf("\n"); + usage(); + return 1; + } + + if ((fd = open(device, O_RDWR)) < 0) { + fprintf(stderr, "Failed to open %s: %s\n", device, + strerror(errno)); + exit(1); + } + free(device); + + find_controls(fd); + for (ctrl_get_list::iterator iter = get_ctrls.begin(); iter != get_ctrls.end(); ++iter) { + if (ctrl_str2id.find(*iter) == ctrl_str2id.end()) { + fprintf(stderr, "unknown control '%s'\n", (*iter).c_str()); + exit(1); + } + } + for (ctrl_set_map::iterator iter = set_ctrls.begin(); iter != set_ctrls.end(); ++iter) { + if (ctrl_str2id.find(iter->first) == ctrl_str2id.end()) { + fprintf(stderr, "unknown control '%s'\n", iter->first.c_str()); + exit(1); + } + } + + if (option_all) { + options[OptGetVideoFormat] = 1; + options[OptGetDriverInfo] = 1; + options[OptGetInput] = 1; + options[OptGetOutput] = 1; + options[OptGetAudioInput] = 1; + options[OptGetAudioOutput] = 1; + options[OptGetStandard] = 1; + options[OptGetFreq] = 1; + options[OptGetTuner] = 1; + } + + + /* Setting Opts */ + + if (options[OptSetVideoFormat]) { + struct v4l2_format in_vfmt; + printf("ioctl: VIDIOC_S_FMT\n"); + in_vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(fd, VIDIOC_G_FMT, &in_vfmt) < 0) + fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n"); + else { + printf("\tBefore:\n"); + if (printfmt(in_vfmt) != 0) + fprintf(stderr, "error printing result\n"); + if (set_fmts & FMTWidth) + in_vfmt.fmt.pix.width = vfmt.fmt.pix.width; + if (set_fmts & FMTHeight) + in_vfmt.fmt.pix.height = vfmt.fmt.pix.height; + if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0) + fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n"); + vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(fd, VIDIOC_G_FMT, &vfmt) < 0) + fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n"); + else { + printf("\n\tAfter:\n"); + if (printfmt(vfmt) != 0) + fprintf(stderr, + "error printing result\n"); + } + } + } + + if (option_streamoff) { + int dummy = 0; + doioctl(fd, VIDIOC_STREAMOFF, &dummy, "VIDIOC_STREAMOFF"); + } + + if (options[OptSetFreq]) { + double fac = 16; + + if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { + fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + } + vf.tuner = 0; + vf.type = (enum v4l2_tuner_type)0; + vf.frequency = __u32(freq * fac); + if (doioctl(fd, VIDIOC_S_FREQUENCY, &vf, + "VIDIOC_S_FREQUENCY") == 0) + printf("Frequency set to %d (%f MHz)\n", vf.frequency, + vf.frequency / fac); + } + + if (options[OptSetStandard]) { + if (std < 16) { + vs.index = std; + if (ioctl(fd, VIDIOC_ENUMSTD, &vs) >= 0) { + std = vs.id; + } + } + if (doioctl(fd, VIDIOC_S_STD, &std, "VIDIOC_S_STD") == 0) + printf("Standard set to %08llx\n", (unsigned long long)std); + } + + if (options[OptSetCtrl] && !set_ctrls.empty()) { + struct v4l2_ext_controls ctrls = { 0 }; + + for (ctrl_set_map::iterator iter = set_ctrls.begin(); + iter != set_ctrls.end(); ++iter) { + struct v4l2_ext_control ctrl = { 0 }; + + ctrl.id = ctrl_str2id[iter->first]; + ctrl.value = atol(iter->second.c_str()); + if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_MPEG) + mpeg_ctrls.push_back(ctrl); + else + user_ctrls.push_back(ctrl); + } + for (unsigned i = 0; i < user_ctrls.size(); i++) { + struct v4l2_control ctrl; + + ctrl.id = user_ctrls[i].id; + ctrl.value = user_ctrls[i].value; + if (ioctl(fd, VIDIOC_S_CTRL, &ctrl)) { + fprintf(stderr, "%s: %s\n", + ctrl_id2str[ctrl.id].c_str(), + strerror(errno)); + } + } + if (mpeg_ctrls.size()) { + ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; + ctrls.count = mpeg_ctrls.size(); + ctrls.controls = &mpeg_ctrls[0]; + if (ioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls)) { + if (ctrls.error_idx >= ctrls.count) { + fprintf(stderr, "Error setting MPEG controls: %s\n", + strerror(errno)); + } + else { + fprintf(stderr, "%s: %s\n", + ctrl_id2str[mpeg_ctrls[ctrls.error_idx].id].c_str(), + strerror(errno)); + } + } + } + } + + /* informational opts */ + + if (options[OptGetDriverInfo]) { + if (doioctl(fd, VIDIOC_QUERYCAP, &vcap, "VIDIOC_QUERYCAP") == 0) { + printf("Driver info:\n"); + printf("\tDriver name : %s\n", vcap.driver); + printf("\tCard type : %s\n", vcap.card); + printf("\tBus info : %s\n", vcap.bus_info); + printf("\tDriver version: %d\n", vcap.version); + printf("\tCapabilities : 0x%08X\n", vcap.capabilities); + printf("%s", cap2s(vcap.capabilities).c_str()); + } + } + + if (options[OptGetVideoFormat]) { + vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (doioctl(fd, VIDIOC_G_FMT, &vfmt, "VIDIOC_G_FMT") == 0) + if (printfmt(vfmt) != 0) + fprintf(stderr, "error printing result\n"); + } + + if (options[OptListInputs]) { + vin.index = 0; + printf("ioctl: VIDIOC_ENUMINPUT\n"); + while (ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) { + if (vin.index) + printf("\n"); + printf("\tInput : %d\n", vin.index); + printf("\tName : %s\n", vin.name); + printf("\tType : 0x%08X\n", vin.type); + printf("\tAudioset: 0x%08X\n", vin.audioset); + printf("\tTuner : 0x%08X\n", vin.tuner); + printf("\tStandard: 0x%016llX ( ", (unsigned long long)vin.std); + if (vin.std & 0x000FFF) + printf("PAL "); // hack + if (vin.std & 0x00F000) + printf("NTSC "); // hack + if (vin.std & 0x7F0000) + printf("SECAM "); // hack + printf(")\n"); + printf("\tStatus : %d\n", vin.status); + vin.index++; + } + } + + if (options[OptSetInput]) { + if (doioctl(fd, VIDIOC_S_INPUT, &input, "VIDIOC_S_INPUT") == 0) { + printf("Video input set to %d", input); + vin.index = input; + if (ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) + printf(" (%s)", vin.name); + printf("\n"); + } + } + + if (options[OptGetInput]) { + if (doioctl(fd, VIDIOC_G_INPUT, &input, "VIDIOC_G_INPUT") == 0) { + printf("Video input : %d", input); + vin.index = input; + if (ioctl(fd, VIDIOC_ENUMINPUT, &vin) >= 0) + printf(" (%s)", vin.name); + printf("\n"); + } + } + + if (options[OptListOutputs]) { + vout.index = 0; + printf("ioctl: VIDIOC_ENUMOUTPUT\n"); + while (ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) { + if (vout.index) + printf("\n"); + printf("\tOutput : %d\n", vout.index); + printf("\tName : %s\n", vout.name); + printf("\tType : 0x%08X\n", vout.type); + printf("\tAudioset: 0x%08X\n", vout.audioset); + printf("\tStandard: 0x%016llX ( ", (unsigned long long)vout.std); + if (vout.std & 0x000FFF) + printf("PAL "); // hack + if (vout.std & 0x00F000) + printf("NTSC "); // hack + if (vout.std & 0x7F0000) + printf("SECAM "); // hack + printf(")\n"); + vout.index++; + } + } + + if (options[OptSetOutput]) { + if (doioctl(fd, VIDIOC_S_OUTPUT, &output, "VIDIOC_S_OUTPUT") == 0) + printf("Output set to %d\n", output); + } + + if (options[OptGetOutput]) { + if (doioctl(fd, VIDIOC_G_OUTPUT, &output, "VIDIOC_G_OUTPUT") == 0) { + printf("Video output: %d", output); + vout.index = output; + if (ioctl(fd, VIDIOC_ENUMOUTPUT, &vout) >= 0) { + printf(" (%s)", vout.name); + } + printf("\n"); + } + } + + if (options[OptListAudioInputs]) { + struct v4l2_audio vaudio; /* list audio inputs */ + vaudio.index = 0; + printf("ioctl: VIDIOC_ENUMAUDIO\n"); + while (ioctl(fd, VIDIOC_ENUMAUDIO, &vaudio) >= 0) { + if (vaudio.index) + printf("\n"); + printf("\tInput : %d\n", vaudio.index); + printf("\tName : %s\n", vaudio.name); + vaudio.index++; + } + } + + if (options[OptSetAudioInput]) { + if (doioctl(fd, VIDIOC_S_AUDIO, &vaudio, "VIDIOC_S_AUDIO") == 0) + printf("Audio input set to %d\n", vaudio.index); + } + + if (options[OptGetAudioInput]) { + if (doioctl(fd, VIDIOC_G_AUDIO, &vaudio, "VIDIOC_G_AUDIO") == 0) + printf("Audio input : %d (%s)\n", vaudio.index, vaudio.name); + } + + if (options[OptSetAudioOutput]) { + if (doioctl(fd, VIDIOC_S_AUDOUT, &vaudout, "VIDIOC_S_AUDOUT") == 0) + printf("Audio output set to %d\n", vaudout.index); + } + + if (options[OptGetAudioOutput]) { + if (doioctl(fd, VIDIOC_G_AUDOUT, &vaudout, "VIDIOC_G_AUDOUT") == 0) + printf("Audio output: %d (%s)\n", vaudout.index, vaudout.name); + } + + if (options[OptGetFreq]) { + double fac = 16; + + if (doioctl(fd, VIDIOC_G_TUNER, &tuner, "VIDIOC_G_TUNER") == 0) { + fac = (tuner.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + } + vf.tuner = 0; + if (doioctl(fd, VIDIOC_G_FREQUENCY, &vf, "VIDIOC_G_FREQUENCY") == 0) + printf("Frequency: %d (%f MHz)\n", vf.frequency, + vf.frequency / fac); + } + + if (option_list_stds) { + printf("ioctl: VIDIOC_ENUMSTD\n"); + vs.index = 0; + while (ioctl(fd, VIDIOC_ENUMSTD, &vs) >= 0) { + if (vs.index) + printf("\n"); + printf("\tindex : %d\n", vs.index); + printf("\tID : 0x%016llX\n", (unsigned long long)vs.id); + printf("\tName : %s\n", vs.name); + printf("\tFrame period: %d/%d\n", + vs.frameperiod.numerator, + vs.frameperiod.denominator); + printf("\tFrame lines : %d\n", vs.framelines); + vs.index++; + } + } + + if (options[OptGetStandard]) { + if (doioctl(fd, VIDIOC_G_STD, &std, "VIDIOC_G_STD") == 0) + printf("Video standard = 0x%08llx\n", (unsigned long long)std); + } + + if (options[OptListCtrlsMenus]) { + list_controls(fd, 1); + } + + if (options[OptGetCtrl] && !get_ctrls.empty()) { + struct v4l2_ext_controls ctrls = { 0 }; + + mpeg_ctrls.clear(); + user_ctrls.clear(); + for (ctrl_get_list::iterator iter = get_ctrls.begin(); + iter != get_ctrls.end(); ++iter) { + struct v4l2_ext_control ctrl = { 0 }; + + ctrl.id = ctrl_str2id[*iter]; + if (V4L2_CTRL_ID2CLASS(ctrl.id) == V4L2_CTRL_CLASS_MPEG) + mpeg_ctrls.push_back(ctrl); + else + user_ctrls.push_back(ctrl); + } + for (unsigned i = 0; i < user_ctrls.size(); i++) { + struct v4l2_control ctrl; + + ctrl.id = user_ctrls[i].id; + doioctl(fd, VIDIOC_G_CTRL, &ctrl, "VIDIOC_G_CTRL"); + printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + } + if (mpeg_ctrls.size()) { + ctrls.ctrl_class = V4L2_CTRL_CLASS_MPEG; + ctrls.count = mpeg_ctrls.size(); + ctrls.controls = &mpeg_ctrls[0]; + doioctl(fd, VIDIOC_S_EXT_CTRLS, &ctrls, "VIDIOC_S_EXT_CTRLS"); + for (unsigned i = 0; i < mpeg_ctrls.size(); i++) { + struct v4l2_ext_control ctrl = mpeg_ctrls[i]; + + printf("%s: %d\n", ctrl_id2str[ctrl.id].c_str(), ctrl.value); + } + } + } + + if (options[OptGetTuner]) { + struct v4l2_tuner vt; + memset(&vt, 0, sizeof(struct v4l2_tuner)); + if (doioctl(fd, VIDIOC_G_TUNER, &vt, "VIDIOC_G_TUNER") == 0) { + printf("Tuner:\n"); + printf("\tCapabilities : %s\n", tcap2s(vt.capability).c_str()); + if (vt.capability & V4L2_TUNER_CAP_LOW) + printf("\tFrequency range : %.1f MHz - %.1f MHz\n", + vt.rangelow / 16000.0, vt.rangehigh / 16000.0); + else + printf("\tFrequency range : %.1f MHz - %.1f MHz\n", + vt.rangelow / 16.0, vt.rangehigh / 16.0); + printf("\tSignal strength : %d%%\n", (int)(vt.signal / 655.35)); + printf("\tCurrent audio mode : %s\n", audmode2s(vt.audmode)); + printf("\tAvailable subchannels: %s\n", + rxsubchans2s(vt.rxsubchans).c_str()); + } + } + if (options[OptSetTuner]) { + struct v4l2_tuner vt; + + memset(&vt, 0, sizeof(struct v4l2_tuner)); + if (ioctl(fd, VIDIOC_G_TUNER, &vt) < 0) { + fprintf(stderr, "ioctl: VIDIOC_G_TUNER failed\n"); + exit(1); + } + vt.audmode = mode; + doioctl(fd, VIDIOC_S_TUNER, &vt, "VIDIOC_S_TUNER"); + } + + if (option_version) { + //printf("ivtvctl version " IVTV_VERSION "\n"); + } + + if (options[OptListCtrls]) { + list_controls(fd, 0); + } + + if (option_log_status) { + static char buf[40960]; + int len; + + if (doioctl(fd, VIDIOC_LOG_STATUS, NULL, "VIDIOC_LOG_STATUS") == 0) { + printf("\nStatus Log:\n\n"); + len = klogctl(3, buf, sizeof(buf) - 1); + if (len >= 0) { + char *p = buf; + char *q; + + buf[len] = 0; + while ((q = strstr(p, "START STATUS CARD #"))) { + p = q + 1; + } + if (p) { + while (p > buf && *p != '<') p--; + q = p; + while ((q = strstr(q, "<6>"))) { + memcpy(q, " ", 3); + } + printf("%s", p); + } + } + } + } + + if (option_streamon) { + int dummy = 0; + doioctl(fd, VIDIOC_STREAMON, &dummy, "VIDIOC_STREAMON"); + } + + close(fd); + exit(0); +} diff --git a/v4l/versions.txt b/v4l/versions.txt index 6da410612..706439959 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -206,3 +206,4 @@ VIDEO_BUF_DVB VIDEO_BTCX VIDEO_IR VIDEO_TVEEPROM +VIDEO_CX2341X |