Mercurial > mplayer.hg
changeset 24553:d6bba2781d01
Implement setting gain control for video devices (usually webcams)
in v4l2 tv:// driver.
author | voroshil |
---|---|
date | Tue, 18 Sep 2007 16:28:39 +0000 |
parents | c9c2e550a449 |
children | ffc2c7164bc0 |
files | DOCS/man/en/mplayer.1 cfg-common.h stream/stream_tv.c stream/tv.c stream/tv.h stream/tvi_v4l2.c |
diffstat | 6 files changed, 48 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1 Tue Sep 18 14:08:08 2007 +0000 +++ b/DOCS/man/en/mplayer.1 Tue Sep 18 16:28:39 2007 +0000 @@ -1854,6 +1854,11 @@ They will have no effect, if your card does not have one. For v4l2 50 maps to the default value of the control, as reported by the driver. +.IPs "gain=<0\-100> (v4l2)" +Set gain control for video devices (usually webcams) to the desired +value and switch off automatic control. +A value of 0 enables automatic control. +If this option is omitted, gain control will not be modified. .IPs immediatemode=<bool> A value of 0 means capture and buffer audio and video together (default for MEncoder).
--- a/cfg-common.h Tue Sep 18 14:08:08 2007 +0000 +++ b/cfg-common.h Tue Sep 18 16:28:39 2007 +0000 @@ -436,6 +436,7 @@ {"contrast", &stream_tv_defaults.contrast, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, {"hue", &stream_tv_defaults.hue, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, {"saturation", &stream_tv_defaults.saturation, CONF_TYPE_INT, CONF_RANGE, -100, 100, NULL}, + {"gain", &stream_tv_defaults.gain, CONF_TYPE_INT, CONF_RANGE, -1, 100, NULL}, #if defined(HAVE_TV_V4L) || defined(HAVE_TV_V4L2) {"amode", &stream_tv_defaults.amode, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL}, {"volume", &stream_tv_defaults.volume, CONF_TYPE_INT, CONF_RANGE, 0, 65535, NULL},
--- a/stream/stream_tv.c Tue Sep 18 14:08:08 2007 +0000 +++ b/stream/stream_tv.c Tue Sep 18 16:28:39 2007 +0000 @@ -72,6 +72,7 @@ 0, //contrast 0, //hue 0, //saturation + -1, //gain NULL, //tdevice 0, //tformat 100, //tpage
--- a/stream/tv.c Tue Sep 18 14:08:08 2007 +0000 +++ b/stream/tv.c Tue Sep 18 16:28:39 2007 +0000 @@ -759,6 +759,10 @@ tv_set_color_options(tvh, TV_COLOR_SATURATION, tvh->tv_param->saturation); tv_set_color_options(tvh, TV_COLOR_CONTRAST, tvh->tv_param->contrast); + if(tvh->tv_param->gain!=-1) + if(funcs->control(tvh->priv,TVI_CONTROL_VID_SET_GAIN,&tvh->tv_param->gain)!=TVI_CONTROL_TRUE) + mp_msg(MSGT_TV,MSGL_WARN,"Unable to set gain control!\n"); + funcs->control(tvh->priv,TV_VBI_CONTROL_RESET,tvh->tv_param); return demuxer;
--- a/stream/tv.h Tue Sep 18 14:08:08 2007 +0000 +++ b/stream/tv.h Tue Sep 18 16:28:39 2007 +0000 @@ -47,6 +47,7 @@ int contrast; int hue; int saturation; + int gain; char *tdevice; ///< teletext device int tformat; ///< teletext display format int tpage; ///< start teletext page @@ -151,6 +152,8 @@ #define TVI_CONTROL_VID_SET_CONTRAST 0x11c #define TVI_CONTROL_VID_GET_PICTURE 0x11d #define TVI_CONTROL_VID_SET_PICTURE 0x11e +#define TVI_CONTROL_VID_SET_GAIN 0x11f +#define TVI_CONTROL_VID_GET_GAIN 0x120 /* TUNER controls */ #define TVI_CONTROL_TUN_GET_FREQ 0x201
--- a/stream/tvi_v4l2.c Tue Sep 18 14:08:08 2007 +0000 +++ b/stream/tvi_v4l2.c Tue Sep 18 16:28:39 2007 +0000 @@ -478,7 +478,6 @@ */ static int set_control(priv_t *priv, struct v4l2_control *control, int val_signed) { struct v4l2_queryctrl qctrl; - qctrl.id = control->id; if (ioctl(priv->video_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n", @@ -806,6 +805,40 @@ control.id = V4L2_CID_SATURATION; control.value = *(int *)arg; return set_control(priv, &control, 1); + case TVI_CONTROL_VID_GET_GAIN: + { + + control.id = V4L2_CID_AUTOGAIN; + if(get_control(priv,&control,0)!=TVI_CONTROL_TRUE) + return TVI_CONTROL_FALSE; + + if(control.value){ //Auto Gain control is enabled + *(int*)arg=0; + return TVI_CONTROL_TRUE; + } + + //Manual Gain control + control.id = V4L2_CID_GAIN; + if(get_control(priv,&control,0)!=TVI_CONTROL_TRUE) + return TVI_CONTROL_FALSE; + + *(int*)arg=control.value?control.value:1; + + return TVI_CONTROL_TRUE; + } + case TVI_CONTROL_VID_SET_GAIN: + { + //value==0 means automatic gain control + int value=*(int*)arg; + + if (value < 0 || value>100) + return TVI_CONTROL_FALSE; + + control.id=value?V4L2_CID_GAIN:V4L2_CID_AUTOGAIN; + control.value=value?value:1; + + return set_control(priv,&control,0); + } case TVI_CONTROL_VID_GET_CONTRAST: control.id = V4L2_CID_CONTRAST; if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {