summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--stream/tvi_v4l2.c1940
1 files changed, 970 insertions, 970 deletions
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index 16e775039e..2a791fa00e 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -68,23 +68,23 @@ struct map {
/* private data */
typedef struct {
/* video */
- char *video_dev;
- int video_fd;
+ char *video_dev;
+ int video_fd;
int mp_format;
- struct v4l2_capability capability;
+ struct v4l2_capability capability;
struct v4l2_input input;
- struct v4l2_format format;
- struct v4l2_standard standard;
- struct v4l2_tuner tuner;
- struct map *map;
- int mapcount;
- int frames;
+ struct v4l2_format format;
+ struct v4l2_standard standard;
+ struct v4l2_tuner tuner;
+ struct map *map;
+ int mapcount;
+ int frames;
volatile long long first_frame;
long long curr_frame;
/* audio video interleaving ;-) */
- volatile int streamon;
- pthread_t audio_grabber_thread;
- pthread_mutex_t skew_mutex;
+ volatile int streamon;
+ pthread_t audio_grabber_thread;
+ pthread_mutex_t skew_mutex;
/* 2nd level video buffers */
int first;
@@ -92,27 +92,27 @@ typedef struct {
int video_buffer_size_max;
volatile int video_buffer_size_current;
- unsigned char **video_ringbuffer;
+ unsigned char **video_ringbuffer;
long long *video_timebuffer;
- volatile int video_head;
- volatile int video_tail;
- volatile int video_cnt;
- pthread_t video_grabber_thread;
+ volatile int video_head;
+ volatile int video_tail;
+ volatile int video_cnt;
+ pthread_t video_grabber_thread;
pthread_mutex_t video_buffer_mutex;
/* audio */
- char *audio_dev;
+ char *audio_dev;
audio_in_t audio_in;
long long audio_start_time;
int audio_buffer_size;
int aud_skew_cnt;
- unsigned char *audio_ringbuffer;
- long long *audio_skew_buffer;
- long long *audio_skew_delta_buffer;
- volatile int audio_head;
- volatile int audio_tail;
- volatile int audio_cnt;
+ unsigned char *audio_ringbuffer;
+ long long *audio_skew_buffer;
+ long long *audio_skew_delta_buffer;
+ volatile int audio_head;
+ volatile int audio_tail;
+ volatile int audio_cnt;
volatile long long audio_skew;
volatile double audio_skew_factor;
volatile long long audio_skew_measure_time;
@@ -124,8 +124,8 @@ typedef struct {
long long audio_usecs_per_block;
long long audio_skew_total;
long long audio_skew_delta_total;
- long audio_recv_blocks_total;
- long audio_sent_blocks_total;
+ long audio_recv_blocks_total;
+ long audio_sent_blocks_total;
pthread_mutex_t audio_mutex;
int audio_insert_null_samples;
volatile long audio_null_blocks_inserted;
@@ -172,18 +172,18 @@ static void *video_grabber(void *data);
static int fcc_mp2vl(int fcc)
{
switch (fcc) {
- case IMGFMT_RGB8: return V4L2_PIX_FMT_RGB332;
- case IMGFMT_BGR15: return V4L2_PIX_FMT_RGB555;
- case IMGFMT_BGR16: return V4L2_PIX_FMT_RGB565;
- case IMGFMT_RGB24: return V4L2_PIX_FMT_RGB24;
- case IMGFMT_RGB32: return V4L2_PIX_FMT_RGB32;
- case IMGFMT_BGR24: return V4L2_PIX_FMT_BGR24;
- case IMGFMT_BGR32: return V4L2_PIX_FMT_BGR32;
- case IMGFMT_Y800: return V4L2_PIX_FMT_GREY;
- case IMGFMT_IF09: return V4L2_PIX_FMT_YUV410;
- case IMGFMT_I420: return V4L2_PIX_FMT_YUV420;
- case IMGFMT_YUY2: return V4L2_PIX_FMT_YUYV;
- case IMGFMT_YV12: return V4L2_PIX_FMT_YVU420;
+ case IMGFMT_RGB8: return V4L2_PIX_FMT_RGB332;
+ case IMGFMT_BGR15: return V4L2_PIX_FMT_RGB555;
+ case IMGFMT_BGR16: return V4L2_PIX_FMT_RGB565;
+ case IMGFMT_RGB24: return V4L2_PIX_FMT_RGB24;
+ case IMGFMT_RGB32: return V4L2_PIX_FMT_RGB32;
+ case IMGFMT_BGR24: return V4L2_PIX_FMT_BGR24;
+ case IMGFMT_BGR32: return V4L2_PIX_FMT_BGR32;
+ case IMGFMT_Y800: return V4L2_PIX_FMT_GREY;
+ case IMGFMT_IF09: return V4L2_PIX_FMT_YUV410;
+ case IMGFMT_I420: return V4L2_PIX_FMT_YUV420;
+ case IMGFMT_YUY2: return V4L2_PIX_FMT_YUYV;
+ case IMGFMT_YV12: return V4L2_PIX_FMT_YVU420;
case IMGFMT_UYVY: return V4L2_PIX_FMT_UYVY;
}
return fcc;
@@ -195,18 +195,18 @@ static int fcc_mp2vl(int fcc)
static int fcc_vl2mp(int fcc)
{
switch (fcc) {
- case V4L2_PIX_FMT_RGB332: return IMGFMT_RGB8;
- case V4L2_PIX_FMT_RGB555: return IMGFMT_BGR15;
- case V4L2_PIX_FMT_RGB565: return IMGFMT_BGR16;
- case V4L2_PIX_FMT_RGB24: return IMGFMT_RGB24;
- case V4L2_PIX_FMT_RGB32: return IMGFMT_RGB32;
- case V4L2_PIX_FMT_BGR24: return IMGFMT_BGR24;
- case V4L2_PIX_FMT_BGR32: return IMGFMT_BGR32;
- case V4L2_PIX_FMT_GREY: return IMGFMT_Y800;
- case V4L2_PIX_FMT_YUV410: return IMGFMT_IF09;
- case V4L2_PIX_FMT_YUV420: return IMGFMT_I420;
- case V4L2_PIX_FMT_YVU420: return IMGFMT_YV12;
- case V4L2_PIX_FMT_YUYV: return IMGFMT_YUY2;
+ case V4L2_PIX_FMT_RGB332: return IMGFMT_RGB8;
+ case V4L2_PIX_FMT_RGB555: return IMGFMT_BGR15;
+ case V4L2_PIX_FMT_RGB565: return IMGFMT_BGR16;
+ case V4L2_PIX_FMT_RGB24: return IMGFMT_RGB24;
+ case V4L2_PIX_FMT_RGB32: return IMGFMT_RGB32;
+ case V4L2_PIX_FMT_BGR24: return IMGFMT_BGR24;
+ case V4L2_PIX_FMT_BGR32: return IMGFMT_BGR32;
+ case V4L2_PIX_FMT_GREY: return IMGFMT_Y800;
+ case V4L2_PIX_FMT_YUV410: return IMGFMT_IF09;
+ case V4L2_PIX_FMT_YUV420: return IMGFMT_I420;
+ case V4L2_PIX_FMT_YVU420: return IMGFMT_YV12;
+ case V4L2_PIX_FMT_YUYV: return IMGFMT_YUY2;
case V4L2_PIX_FMT_UYVY: return IMGFMT_UYVY;
}
return fcc;
@@ -221,32 +221,32 @@ static const char *pixfmt2name(int pixfmt)
static char unknown[24];
switch (pixfmt) {
- case V4L2_PIX_FMT_RGB332: return "RGB332";
- case V4L2_PIX_FMT_RGB555: return "RGB555";
- case V4L2_PIX_FMT_RGB565: return "RGB565";
- case V4L2_PIX_FMT_RGB555X: return "RGB555X";
- case V4L2_PIX_FMT_RGB565X: return "RGB565X";
- case V4L2_PIX_FMT_BGR24: return "BGR24";
- case V4L2_PIX_FMT_RGB24: return "RGB24";
- case V4L2_PIX_FMT_BGR32: return "BGR32";
- case V4L2_PIX_FMT_RGB32: return "RGB32";
- case V4L2_PIX_FMT_GREY: return "GREY";
- case V4L2_PIX_FMT_YVU410: return "YVU410";
- case V4L2_PIX_FMT_YVU420: return "YVU420";
- case V4L2_PIX_FMT_YUYV: return "YUYV";
- case V4L2_PIX_FMT_UYVY: return "UYVY";
-/* case V4L2_PIX_FMT_YVU422P: return "YVU422P"; */
-/* case V4L2_PIX_FMT_YVU411P: return "YVU411P"; */
- case V4L2_PIX_FMT_YUV422P: return "YUV422P";
- case V4L2_PIX_FMT_YUV411P: return "YUV411P";
- case V4L2_PIX_FMT_Y41P: return "Y41P";
- case V4L2_PIX_FMT_NV12: return "NV12";
- case V4L2_PIX_FMT_NV21: return "NV21";
- case V4L2_PIX_FMT_YUV410: return "YUV410";
- case V4L2_PIX_FMT_YUV420: return "YUV420";
- case V4L2_PIX_FMT_YYUV: return "YYUV";
- case V4L2_PIX_FMT_HI240: return "HI240";
- case V4L2_PIX_FMT_WNVA: return "WNVA";
+ case V4L2_PIX_FMT_RGB332: return "RGB332";
+ case V4L2_PIX_FMT_RGB555: return "RGB555";
+ case V4L2_PIX_FMT_RGB565: return "RGB565";
+ case V4L2_PIX_FMT_RGB555X: return "RGB555X";
+ case V4L2_PIX_FMT_RGB565X: return "RGB565X";
+ case V4L2_PIX_FMT_BGR24: return "BGR24";
+ case V4L2_PIX_FMT_RGB24: return "RGB24";
+ case V4L2_PIX_FMT_BGR32: return "BGR32";
+ case V4L2_PIX_FMT_RGB32: return "RGB32";
+ case V4L2_PIX_FMT_GREY: return "GREY";
+ case V4L2_PIX_FMT_YVU410: return "YVU410";
+ case V4L2_PIX_FMT_YVU420: return "YVU420";
+ case V4L2_PIX_FMT_YUYV: return "YUYV";
+ case V4L2_PIX_FMT_UYVY: return "UYVY";
+/* case V4L2_PIX_FMT_YVU422P: return "YVU422P"; */
+/* case V4L2_PIX_FMT_YVU411P: return "YVU411P"; */
+ case V4L2_PIX_FMT_YUV422P: return "YUV422P";
+ case V4L2_PIX_FMT_YUV411P: return "YUV411P";
+ case V4L2_PIX_FMT_Y41P: return "Y41P";
+ case V4L2_PIX_FMT_NV12: return "NV12";
+ case V4L2_PIX_FMT_NV21: return "NV21";
+ case V4L2_PIX_FMT_YUV410: return "YUV410";
+ case V4L2_PIX_FMT_YUV420: return "YUV420";
+ case V4L2_PIX_FMT_YYUV: return "YYUV";
+ case V4L2_PIX_FMT_HI240: return "HI240";
+ case V4L2_PIX_FMT_WNVA: return "WNVA";
}
sprintf(unknown, "unknown (0x%x)", pixfmt);
return unknown;
@@ -260,41 +260,41 @@ static int pixfmt2depth(int pixfmt)
{
switch (pixfmt) {
case V4L2_PIX_FMT_RGB332:
- return 8;
+ return 8;
case V4L2_PIX_FMT_RGB555:
case V4L2_PIX_FMT_RGB565:
case V4L2_PIX_FMT_RGB555X:
case V4L2_PIX_FMT_RGB565X:
- return 16;
+ return 16;
case V4L2_PIX_FMT_BGR24:
case V4L2_PIX_FMT_RGB24:
- return 24;
+ return 24;
case V4L2_PIX_FMT_BGR32:
case V4L2_PIX_FMT_RGB32:
- return 32;
+ return 32;
case V4L2_PIX_FMT_GREY:
- return 8;
+ return 8;
case V4L2_PIX_FMT_YVU410:
- return 9;
+ return 9;
case V4L2_PIX_FMT_YVU420:
- return 12;
+ return 12;
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_UYVY:
case V4L2_PIX_FMT_YUV422P:
case V4L2_PIX_FMT_YUV411P:
- return 16;
+ return 16;
case V4L2_PIX_FMT_Y41P:
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_NV21:
- return 12;
+ return 12;
case V4L2_PIX_FMT_YUV410:
- return 9;
+ return 9;
case V4L2_PIX_FMT_YUV420:
- return 12;
+ return 12;
case V4L2_PIX_FMT_YYUV:
- return 16;
+ return 16;
case V4L2_PIX_FMT_HI240:
- return 8;
+ return 8;
}
return 0;
@@ -304,15 +304,15 @@ static int amode2v4l(int amode)
{
switch (amode) {
case 0:
- return V4L2_TUNER_MODE_MONO;
+ return V4L2_TUNER_MODE_MONO;
case 1:
- return V4L2_TUNER_MODE_STEREO;
+ return V4L2_TUNER_MODE_STEREO;
case 2:
- return V4L2_TUNER_MODE_LANG1;
+ return V4L2_TUNER_MODE_LANG1;
case 3:
- return V4L2_TUNER_MODE_LANG2;
+ return V4L2_TUNER_MODE_LANG2;
default:
- return -1;
+ return -1;
}
}
@@ -322,7 +322,7 @@ static void setup_audio_buffer_sizes(priv_t *priv)
{
int bytes_per_sample = priv->audio_in.bytes_per_sample;
double fps = (double)priv->standard.frameperiod.denominator /
- priv->standard.frameperiod.numerator;
+ priv->standard.frameperiod.numerator;
int seconds = priv->video_buffer_size_max/fps;
if (seconds < 5) seconds = 5;
@@ -330,18 +330,18 @@ static void setup_audio_buffer_sizes(priv_t *priv)
// make the audio buffer at least as the video buffer capacity (or 5 seconds) long
priv->audio_buffer_size = 1 + seconds*priv->audio_in.samplerate
- *priv->audio_in.channels
- *bytes_per_sample/priv->audio_in.blocksize;
+ *priv->audio_in.channels
+ *bytes_per_sample/priv->audio_in.blocksize;
if (priv->audio_buffer_size < 256) priv->audio_buffer_size = 256;
// make the skew buffer at least 1 second long
priv->aud_skew_cnt = 1 + 1*priv->audio_in.samplerate
- *priv->audio_in.channels
- *bytes_per_sample/priv->audio_in.blocksize;
+ *priv->audio_in.channels
+ *bytes_per_sample/priv->audio_in.blocksize;
if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16;
mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n",
- priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt);
+ priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt);
}
static void init_audio(priv_t *priv)
@@ -350,36 +350,36 @@ static void init_audio(priv_t *priv)
if (!tv_param_noaudio) {
#if defined(HAVE_ALSA9) || defined(HAVE_ALSA1X)
- if (tv_param_alsa)
- audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
- else
- audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
+ if (tv_param_alsa)
+ audio_in_init(&priv->audio_in, AUDIO_IN_ALSA);
+ else
+ audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
#else
- audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
+ audio_in_init(&priv->audio_in, AUDIO_IN_OSS);
#endif
- if (priv->audio_dev) {
- audio_in_set_device(&priv->audio_in, priv->audio_dev);
- }
-
- audio_in_set_samplerate(&priv->audio_in, 44100);
- if (priv->capability.capabilities & V4L2_CAP_TUNER) {
- if (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) {
- audio_in_set_channels(&priv->audio_in, 2);
- } else {
- audio_in_set_channels(&priv->audio_in, 1);
- }
- } else {
- if (tv_param_forcechan >= 0) {
- audio_in_set_channels(&priv->audio_in, tv_param_forcechan);
- } else {
- audio_in_set_channels(&priv->audio_in, 2);
- }
- }
-
- if (audio_in_setup(&priv->audio_in) < 0) return;
-
- priv->audio_inited = 1;
+ if (priv->audio_dev) {
+ audio_in_set_device(&priv->audio_in, priv->audio_dev);
+ }
+
+ audio_in_set_samplerate(&priv->audio_in, 44100);
+ if (priv->capability.capabilities & V4L2_CAP_TUNER) {
+ if (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) {
+ audio_in_set_channels(&priv->audio_in, 2);
+ } else {
+ audio_in_set_channels(&priv->audio_in, 1);
+ }
+ } else {
+ if (tv_param_forcechan >= 0) {
+ audio_in_set_channels(&priv->audio_in, tv_param_forcechan);
+ } else {
+ audio_in_set_channels(&priv->audio_in, 2);
+ }
+ }
+
+ if (audio_in_setup(&priv->audio_in) < 0) return;
+
+ priv->audio_inited = 1;
}
}
@@ -389,8 +389,8 @@ static void init_audio(priv_t *priv)
*/
static size_t difftv(struct timeval time1, struct timeval time0)
{
- return (time1.tv_sec - time0.tv_sec) * 1000 +
- (time1.tv_usec - time0.tv_usec) / 1000;
+ return (time1.tv_sec - time0.tv_sec) * 1000 +
+ (time1.tv_usec - time0.tv_usec) / 1000;
}
#endif
@@ -403,8 +403,8 @@ static int getfmt(priv_t *priv)
priv->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if ((i = ioctl(priv->video_fd, VIDIOC_G_FMT, &priv->format)) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get format failed: %s\n",
- info.short_name, strerror(errno));
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get format failed: %s\n",
+ info.short_name, strerror(errno));
}
return i;
}
@@ -419,25 +419,25 @@ static int getstd(priv_t *priv)
int i=0;
if (ioctl(priv->video_fd, VIDIOC_G_STD, &id) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get standard failed: %s\n",
- info.short_name, strerror(errno));
- return -1;
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get standard failed: %s\n",
+ info.short_name, strerror(errno));
+ return -1;
}
do {
- priv->standard.index = i++;
- if (ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) {
- return -1;
- }
+ priv->standard.index = i++;
+ if (ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) {
+ return -1;
+ }
} while (priv->standard.id != id);
return 0;
}
/***********************************************************************\
- * *
- * *
- * Interface to mplayer *
- * *
- * *
+ * *
+ * *
+ * Interface to mplayer *
+ * *
+ * *
\***********************************************************************/
static int set_mute(priv_t *priv, int value)
@@ -446,9 +446,9 @@ static int set_mute(priv_t *priv, int value)
control.id = V4L2_CID_AUDIO_MUTE;
control.value = value;
if (ioctl(priv->video_fd, VIDIOC_S_CTRL, &control) < 0) {
- mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set mute failed: %s\n",
- info.short_name, strerror(errno));
- return 0;
+ mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set mute failed: %s\n",
+ info.short_name, strerror(errno));
+ return 0;
}
return 1;
}
@@ -458,38 +458,38 @@ static int set_mute(priv_t *priv, int value)
** Here they are scaled to what the tv card needs and applied.
*/
static int set_control(priv_t *priv, struct v4l2_control *control, int val_signed) {
- struct v4l2_queryctrl qctrl;
+ 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",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
}
if (val_signed) {
- if (control->value < 0) {
- control->value = qctrl.default_value + control->value *
- (qctrl.default_value - qctrl.minimum) / 100;
- } else {
- control->value = qctrl.default_value + control->value *
- (qctrl.maximum - qctrl.default_value) / 100;
- }
+ if (control->value < 0) {
+ control->value = qctrl.default_value + control->value *
+ (qctrl.default_value - qctrl.minimum) / 100;
+ } else {
+ control->value = qctrl.default_value + control->value *
+ (qctrl.maximum - qctrl.default_value) / 100;
+ }
} else {
- if (control->value < 50) {
- control->value = qctrl.default_value + (control->value-50) *
- (qctrl.default_value - qctrl.minimum) / 50;
- } else {
- control->value = qctrl.default_value + (control->value-50) *
- (qctrl.maximum - qctrl.default_value) / 50;
- }
+ if (control->value < 50) {
+ control->value = qctrl.default_value + (control->value-50) *
+ (qctrl.default_value - qctrl.minimum) / 50;
+ } else {
+ control->value = qctrl.default_value + (control->value-50) *
+ (qctrl.maximum - qctrl.default_value) / 50;
+ }
}
if (ioctl(priv->video_fd, VIDIOC_S_CTRL, control) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl set %s %d failed: %s\n",
- info.short_name, qctrl.name, control->value, strerror(errno));
- return TVI_CONTROL_FALSE;
+ mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl set %s %d failed: %s\n",
+ info.short_name, qctrl.name, control->value, strerror(errno));
+ return TVI_CONTROL_FALSE;
}
mp_msg(MSGT_TV, MSGL_V, "%s: set %s: %d [%d, %d]\n", info.short_name,
qctrl.name, control->value, qctrl.minimum, qctrl.maximum);
@@ -502,39 +502,39 @@ static int set_control(priv_t *priv, struct v4l2_control *control, int val_signe
** Scale the control values back to what mplayer needs.
*/
static int get_control(priv_t *priv, struct v4l2_control *control, int val_signed) {
- struct v4l2_queryctrl qctrl;
+ 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",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
}
if (ioctl(priv->video_fd, VIDIOC_G_CTRL, control) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl get %s failed: %s\n",
- info.short_name, qctrl.name, strerror(errno));
- return TVI_CONTROL_FALSE;
+ mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl get %s failed: %s\n",
+ info.short_name, qctrl.name, strerror(errno));
+ return TVI_CONTROL_FALSE;
}
mp_msg(MSGT_TV, MSGL_V, "%s: get %s: %d [%d, %d]\n", info.short_name,
qctrl.name, control->value, qctrl.minimum, qctrl.maximum);
if (val_signed) {
- if (control->value < qctrl.default_value) {
- control->value = (control->value - qctrl.default_value) * 100 /
- (qctrl.default_value - qctrl.minimum);
- } else {
- control->value = (control->value - qctrl.default_value) * 100 /
- (qctrl.maximum - qctrl.default_value);
- }
+ if (control->value < qctrl.default_value) {
+ control->value = (control->value - qctrl.default_value) * 100 /
+ (qctrl.default_value - qctrl.minimum);
+ } else {
+ control->value = (control->value - qctrl.default_value) * 100 /
+ (qctrl.maximum - qctrl.default_value);
+ }
} else {
- if (control->value < qctrl.default_value) {
- control->value = (control->value - qctrl.default_value) * 50 /
- (qctrl.default_value - qctrl.minimum) + 50;
- } else {
- control->value = (control->value - qctrl.default_value) * 50 /
- (qctrl.maximum - qctrl.default_value) + 50;
- }
+ if (control->value < qctrl.default_value) {
+ control->value = (control->value - qctrl.default_value) * 50 /
+ (qctrl.default_value - qctrl.minimum) + 50;
+ } else {
+ control->value = (control->value - qctrl.default_value) * 50 /
+ (qctrl.maximum - qctrl.default_value) + 50;
+ }
}
return TVI_CONTROL_TRUE;
@@ -547,267 +547,267 @@ static int control(priv_t *priv, int cmd, void *arg)
switch(cmd) {
case TVI_CONTROL_IS_VIDEO:
- return priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE?
- TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
+ return priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE?
+ TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
case TVI_CONTROL_IS_AUDIO:
- if (tv_param_force_audio) return TVI_CONTROL_TRUE;
+ if (tv_param_force_audio) return TVI_CONTROL_TRUE;
case TVI_CONTROL_IS_TUNER:
- return priv->capability.capabilities & V4L2_CAP_TUNER?
- TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
+ return priv->capability.capabilities & V4L2_CAP_TUNER?
+ TVI_CONTROL_TRUE: TVI_CONTROL_FALSE;
case TVI_CONTROL_IMMEDIATE:
- priv->immediate_mode = 1;
- return TVI_CONTROL_TRUE;
+ priv->immediate_mode = 1;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_FPS:
- *(float *)arg = (float)priv->standard.frameperiod.denominator /
- priv->standard.frameperiod.numerator;
- mp_msg(MSGT_TV, MSGL_V, "%s: get fps: %f\n", info.short_name,
- *(float *)arg);
- return TVI_CONTROL_TRUE;
+ *(float *)arg = (float)priv->standard.frameperiod.denominator /
+ priv->standard.frameperiod.numerator;
+ mp_msg(MSGT_TV, MSGL_V, "%s: get fps: %f\n", info.short_name,
+ *(float *)arg);
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_BITS:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- *(int *)arg = pixfmt2depth(priv->format.fmt.pix.pixelformat);
- mp_msg(MSGT_TV, MSGL_V, "%s: get depth: %d\n", info.short_name,
- *(int *)arg);
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ *(int *)arg = pixfmt2depth(priv->format.fmt.pix.pixelformat);
+ mp_msg(MSGT_TV, MSGL_V, "%s: get depth: %d\n", info.short_name,
+ *(int *)arg);
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_FORMAT:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- *(int *)arg = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
- mp_msg(MSGT_TV, MSGL_V, "%s: get format: %s\n", info.short_name,
- pixfmt2name(priv->format.fmt.pix.pixelformat));
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ *(int *)arg = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
+ mp_msg(MSGT_TV, MSGL_V, "%s: get format: %s\n", info.short_name,
+ pixfmt2name(priv->format.fmt.pix.pixelformat));
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_FORMAT:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- priv->format.fmt.pix.pixelformat = fcc_mp2vl(*(int *)arg);
- priv->format.fmt.pix.field = V4L2_FIELD_ANY;
-
- priv->mp_format = *(int *)arg;
- mp_msg(MSGT_TV, MSGL_V, "%s: set format: %s\n", info.short_name,
- pixfmt2name(priv->format.fmt.pix.pixelformat));
- if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- /* according to the v4l2 specs VIDIOC_S_FMT should not fail, inflexible drivers
- might even always return the default parameters -> update the format here*/
- priv->mp_format = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ priv->format.fmt.pix.pixelformat = fcc_mp2vl(*(int *)arg);
+ priv->format.fmt.pix.field = V4L2_FIELD_ANY;
+
+ priv->mp_format = *(int *)arg;
+ mp_msg(MSGT_TV, MSGL_V, "%s: set format: %s\n", info.short_name,
+ pixfmt2name(priv->format.fmt.pix.pixelformat));
+ if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ /* according to the v4l2 specs VIDIOC_S_FMT should not fail, inflexible drivers
+ might even always return the default parameters -> update the format here*/
+ priv->mp_format = fcc_vl2mp(priv->format.fmt.pix.pixelformat);
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_WIDTH:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- *(int *)arg = priv->format.fmt.pix.width;
- mp_msg(MSGT_TV, MSGL_V, "%s: get width: %d\n", info.short_name,
- *(int *)arg);
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ *(int *)arg = priv->format.fmt.pix.width;
+ mp_msg(MSGT_TV, MSGL_V, "%s: get width: %d\n", info.short_name,
+ *(int *)arg);
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_CHK_WIDTH:
- return TVI_CONTROL_TRUE;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_WIDTH:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- priv->format.fmt.pix.width = *(int *)arg;
- mp_msg(MSGT_TV, MSGL_V, "%s: set width: %d\n", info.short_name,
- *(int *)arg);
- if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set width failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ priv->format.fmt.pix.width = *(int *)arg;
+ mp_msg(MSGT_TV, MSGL_V, "%s: set width: %d\n", info.short_name,
+ *(int *)arg);
+ if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set width failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_GET_HEIGHT:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- *(int *)arg = priv->format.fmt.pix.height;
- mp_msg(MSGT_TV, MSGL_V, "%s: get height: %d\n", info.short_name,
- *(int *)arg);
- return TVI_CONTROL_TRUE;
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ *(int *)arg = priv->format.fmt.pix.height;
+ mp_msg(MSGT_TV, MSGL_V, "%s: get height: %d\n", info.short_name,
+ *(int *)arg);
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_CHK_HEIGHT:
- return TVI_CONTROL_TRUE;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_VID_SET_HEIGHT:
- if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
- priv->format.fmt.pix.height = *(int *)arg;
- priv->format.fmt.pix.field = V4L2_FIELD_ANY;
- mp_msg(MSGT_TV, MSGL_V, "%s: set height: %d\n", info.short_name,
- *(int *)arg);
- if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set height failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- return TVI_CONTROL_TRUE;
- case TVI_CONTROL_VID_GET_BRIGHTNESS:
- control.id = V4L2_CID_BRIGHTNESS;
- if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
- *(int *)arg = control.value;
- return TVI_CONTROL_TRUE;
- }
- return TVI_CONTROL_FALSE;
- case TVI_CONTROL_VID_SET_BRIGHTNESS:
- control.id = V4L2_CID_BRIGHTNESS;
- control.value = *(int *)arg;
- return set_control(priv, &control, 1);
- case TVI_CONTROL_VID_GET_HUE:
- control.id = V4L2_CID_HUE;
- if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
- *(int *)arg = control.value;
- return TVI_CONTROL_TRUE;
- }
- return TVI_CONTROL_FALSE;
- case TVI_CONTROL_VID_SET_HUE:
- control.id = V4L2_CID_HUE;
- control.value = *(int *)arg;
- return set_control(priv, &control, 1);
- case TVI_CONTROL_VID_GET_SATURATION:
- control.id = V4L2_CID_SATURATION;
- if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
- *(int *)arg = control.value;
- return TVI_CONTROL_TRUE;
- }
- return TVI_CONTROL_FALSE;
- case TVI_CONTROL_VID_SET_SATURATION:
- control.id = V4L2_CID_SATURATION;
- control.value = *(int *)arg;
- return set_control(priv, &control, 1);
- case TVI_CONTROL_VID_GET_CONTRAST:
- control.id = V4L2_CID_CONTRAST;
- if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
- *(int *)arg = control.value;
- return TVI_CONTROL_TRUE;
- }
- return TVI_CONTROL_FALSE;
- case TVI_CONTROL_VID_SET_CONTRAST:
- control.id = V4L2_CID_CONTRAST;
- control.value = *(int *)arg;
- return set_control(priv, &control, 1);
+ if (getfmt(priv) < 0) return TVI_CONTROL_FALSE;
+ priv->format.fmt.pix.height = *(int *)arg;
+ priv->format.fmt.pix.field = V4L2_FIELD_ANY;
+ mp_msg(MSGT_TV, MSGL_V, "%s: set height: %d\n", info.short_name,
+ *(int *)arg);
+ if (ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set height failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ return TVI_CONTROL_TRUE;
+ case TVI_CONTROL_VID_GET_BRIGHTNESS:
+ control.id = V4L2_CID_BRIGHTNESS;
+ if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
+ *(int *)arg = control.value;
+ return TVI_CONTROL_TRUE;
+ }
+ return TVI_CONTROL_FALSE;
+ case TVI_CONTROL_VID_SET_BRIGHTNESS:
+ control.id = V4L2_CID_BRIGHTNESS;
+ control.value = *(int *)arg;
+ return set_control(priv, &control, 1);
+ case TVI_CONTROL_VID_GET_HUE:
+ control.id = V4L2_CID_HUE;
+ if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
+ *(int *)arg = control.value;
+ return TVI_CONTROL_TRUE;
+ }
+ return TVI_CONTROL_FALSE;
+ case TVI_CONTROL_VID_SET_HUE:
+ control.id = V4L2_CID_HUE;
+ control.value = *(int *)arg;
+ return set_control(priv, &control, 1);
+ case TVI_CONTROL_VID_GET_SATURATION:
+ control.id = V4L2_CID_SATURATION;
+ if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
+ *(int *)arg = control.value;
+ return TVI_CONTROL_TRUE;
+ }
+ return TVI_CONTROL_FALSE;
+ case TVI_CONTROL_VID_SET_SATURATION:
+ control.id = V4L2_CID_SATURATION;
+ control.value = *(int *)arg;
+ return set_control(priv, &control, 1);
+ case TVI_CONTROL_VID_GET_CONTRAST:
+ control.id = V4L2_CID_CONTRAST;
+ if (get_control(priv, &control, 1) == TVI_CONTROL_TRUE) {
+ *(int *)arg = control.value;
+ return TVI_CONTROL_TRUE;
+ }
+ return TVI_CONTROL_FALSE;
+ case TVI_CONTROL_VID_SET_CONTRAST:
+ control.id = V4L2_CID_CONTRAST;
+ control.value = *(int *)arg;
+ return set_control(priv, &control, 1);
case TVI_CONTROL_TUN_GET_FREQ:
- frequency.tuner = 0;
- frequency.type = V4L2_TUNER_ANALOG_TV;
- if (ioctl(priv->video_fd, VIDIOC_G_FREQUENCY, &frequency) < 0) {
- mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl get frequency failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- *(int *)arg = frequency.frequency;
- return TVI_CONTROL_TRUE;
+ frequency.tuner = 0;
+ frequency.type = V4L2_TUNER_ANALOG_TV;
+ if (ioctl(priv->video_fd, VIDIOC_G_FREQUENCY, &frequency) < 0) {
+ mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl get frequency failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ *(int *)arg = frequency.frequency;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_SET_FREQ:
#if 0
- set_mute(priv, 1);
- usleep(100000); // wait to suppress noise during switching
+ set_mute(priv, 1);
+ usleep(100000); // wait to suppress noise during switching
#endif
- frequency.tuner = 0;
- frequency.type = V4L2_TUNER_ANALOG_TV;
- frequency.frequency = *(int *)arg;
- if (ioctl(priv->video_fd, VIDIOC_S_FREQUENCY, &frequency) < 0) {
- mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set frequency failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
+ frequency.tuner = 0;
+ frequency.type = V4L2_TUNER_ANALOG_TV;
+ frequency.frequency = *(int *)arg;
+ if (ioctl(priv->video_fd, VIDIOC_S_FREQUENCY, &frequency) < 0) {
+ mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set frequency failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
#if 0
- usleep(100000); // wait to suppress noise during switching
- set_mute(priv, 0);
+ usleep(100000); // wait to suppress noise during switching
+ set_mute(priv, 0);
#endif
- return TVI_CONTROL_TRUE;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_GET_TUNER:
- mp_msg(MSGT_TV, MSGL_V, "%s: get tuner\n",info.short_name);
- if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- return TVI_CONTROL_TRUE;
+ mp_msg(MSGT_TV, MSGL_V, "%s: get tuner\n",info.short_name);
+ if (ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_SET_TUNER:
- mp_msg(MSGT_TV, MSGL_V, "%s: set tuner\n",info.short_name);
- if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- return TVI_CONTROL_TRUE;
+ mp_msg(MSGT_TV, MSGL_V, "%s: set tuner\n",info.short_name);
+ if (ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) {
+ mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n",
+ info.short_name, strerror(errno));
+ return TVI_CONTROL_FALSE;
+ }
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_GET_NORM:
- *(int *)arg = priv->standard.index;
- return TVI_CONTROL_TRUE;
+ *(int *)arg = priv->standard.index;
+ return TVI_CONTROL_TRUE;
case TVI_CONTROL_TUN_SET_NORM:
- priv->standard.index = *(int *)arg;
- if (ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl enum norm failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- mp_msg(MSGT_TV, MSGL_V, "%s: set norm: %s\n", info.short_name, priv->standard.name);
- if (ioctl(priv->video_fd, VIDIOC_S_STD, &priv->standard.id) < 0) {
- mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set norm failed: %s\n",
- info.short_name, strerror(errno));
- return TVI_CONTROL_FALSE;
- }
- return TVI_CONTROL_TRUE;
+ priv->standard.index = *(int *)arg;