[MPlayer-dev-eng] [PATCH] cosmetic patch for v4l1 driver
Trent Piepho
xyzzy at speakeasy.org
Sat Apr 28 12:38:32 CEST 2007
mplayer's v4l1 driver didn't work with my cx88 card (v4l2) using the kernel
v4l1 compat module. There were some bugs in the kernel v4l1 compat system,
which I've fixed, but also some bugs in mplayer.
The tvi_v4l.c has mostly 4 space indention, but there was a lot of code
that used 3, 2, 1, or 0 spaces. I hate trying to read code with RanDoM
indention, so here is a cosmetic patch that should make it 4 spaces
everywhere. I didn't re-format everything, just fix some things to make it
more readable.
-------------- next part --------------
--- stream/tvi_v4l.c.svn-base 2007-03-29 18:40:11.000000000 -0700
+++ stream/tvi_v4l.c 2007-04-28 01:31:46.000000000 -0700
@@ -483,70 +483,69 @@
/* initialize if necessary */
if ( tv_param_mjpeg )
- {
+ {
struct mjpeg_params bparm;
struct mjpeg_requestbuffers breq; /* buffer requests */
if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0)
{
- mp_msg(MSGT_TV, MSGL_ERR,
- " MJP: Error getting video parameters: %s\n", strerror(errno));
- goto err;
+ mp_msg(MSGT_TV, MSGL_ERR,
+ " MJP: Error getting video parameters: %s\n", strerror(errno));
+ goto err;
}
mp_msg(MSGT_TV, MSGL_INFO,
" MJP: previous params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n",
- bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
- bparm.decimation, bparm.field_per_buff);
+ bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
+ bparm.decimation, bparm.field_per_buff);
mp_msg(MSGT_TV, MSGL_INFO,
" MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n",
- bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
+ bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
bparm.input = tv_param_input; /* tv */
if (!strcasecmp(tv_param_norm, "pal"))
- bparm.norm = 0; /* PAL */
+ bparm.norm = 0; /* PAL */
else if (!strcasecmp(tv_param_norm, "ntsc"))
- bparm.norm = 1; /* NTSC */
+ bparm.norm = 1; /* NTSC */
else if (!strcasecmp(tv_param_norm, "secam"))
- bparm.norm = 2; /* SECAM */
+ bparm.norm = 2; /* SECAM */
bparm.quality = tv_param_quality;
bparm.decimation = tv_param_decimation;
mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting params to decimation: %d, quality: %d\n",
- bparm.decimation, bparm.quality);
+ bparm.decimation, bparm.quality);
if (ioctl(priv->video_fd, MJPIOC_S_PARAMS, &bparm) < 0)
- {
+ {
mp_msg(MSGT_TV, MSGL_ERR,
- " MJP: Error setting video parameters: %s\n", strerror(errno));
+ " MJP: Error setting video parameters: %s\n", strerror(errno));
goto err;
- }
+ }
if (ioctl(priv->video_fd, MJPIOC_G_PARAMS, &bparm) < 0)
{
- mp_msg(MSGT_TV, MSGL_ERR,
- " MJP: Error getting video parameters: %s\n", strerror(errno));
- goto err;
+ mp_msg(MSGT_TV, MSGL_ERR,
+ " MJP: Error getting video parameters: %s\n", strerror(errno));
+ goto err;
}
mp_msg(MSGT_TV, MSGL_INFO,
" MJP: current params: x: %d, y: %d, w: %d, h: %d, decim: %d, fields: %d,\n",
- bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
- bparm.decimation, bparm.field_per_buff);
+ bparm.img_x, bparm.img_y, bparm.img_width, bparm.img_height,
+ bparm.decimation, bparm.field_per_buff);
mp_msg(MSGT_TV, MSGL_INFO,
" MJP: HorDcm: %d, VerDcm: %d, TmpDcm: %d\n",
- bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
+ bparm.HorDcm, bparm.VerDcm, bparm.TmpDcm);
breq.count = 64;
priv -> nbuf = breq.count;
priv->mbuf.frames = priv -> nbuf;
priv->mjpeg_bufsize = 256*1024;
- if (tv_param_buffer_size >= 0) {
- priv->mjpeg_bufsize = tv_param_buffer_size*1024;
- }
+ if (tv_param_buffer_size >= 0)
+ priv->mjpeg_bufsize = tv_param_buffer_size*1024;
breq.size = priv -> mjpeg_bufsize;
if (ioctl(priv->video_fd, MJPIOC_REQBUFS,&(breq)) < 0)
{
@@ -555,18 +554,18 @@
goto err;
}
mp_msg(MSGT_TV, MSGL_INFO,
- " MJP: Got %ld buffers of size %ld KB\n",
- breq.count, breq.size/1024);
+ " MJP: Got %ld buffers of size %ld KB\n",
+ breq.count, breq.size/1024);
priv -> mmap = mmap(0, breq.count * breq.size,
- PROT_READ|PROT_WRITE, MAP_SHARED, priv->video_fd, 0);
+ PROT_READ|PROT_WRITE, MAP_SHARED, priv->video_fd, 0);
if (priv -> mmap == MAP_FAILED)
{
- mp_msg(MSGT_TV, MSGL_INFO,
- " MJP: Error mapping video buffers: %s\n", strerror(errno));
- goto err;
+ mp_msg(MSGT_TV, MSGL_INFO,
+ " MJP: Error mapping video buffers: %s\n", strerror(errno));
+ goto err;
}
- }
+ }
mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
priv->channels = calloc(priv->capability.channels, sizeof(struct video_channel));
@@ -600,32 +599,32 @@
if ( !tv_param_mjpeg )
{
- /* map grab buffer */
- if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1)
- {
- mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
- goto err;
- }
+ /* map grab buffer */
+ if (ioctl(priv->video_fd, VIDIOCGMBUF, &priv->mbuf) == -1)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR, "ioctl get mbuf failed: %s\n", strerror(errno));
+ goto err;
+ }
- mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
- priv->mbuf.size, priv->mbuf.frames);
- priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
- MAP_SHARED, priv->video_fd, 0);
- if (priv->mmap == (unsigned char *)-1)
- {
- mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno));
- goto err;
- }
- mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
+ mp_msg(MSGT_TV, MSGL_V, "mbuf: size=%d, frames=%d\n",
+ priv->mbuf.size, priv->mbuf.frames);
+ priv->mmap = mmap(0, priv->mbuf.size, PROT_READ|PROT_WRITE,
+ MAP_SHARED, priv->video_fd, 0);
+ if (priv->mmap == (unsigned char *)-1)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR, "Unable to map memory for buffers: %s\n", strerror(errno));
+ goto err;
+ }
+ mp_msg(MSGT_TV, MSGL_DBG2, "our buffer: %p\n", priv->mmap);
- /* num of buffers */
- priv->nbuf = priv->mbuf.frames;
+ /* num of buffers */
+ priv->nbuf = priv->mbuf.frames;
- /* video buffers */
- priv->buf = calloc(priv->nbuf, sizeof(struct video_mmap));
- if (!priv->buf)
- goto malloc_failed;
- memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
+ /* video buffers */
+ priv->buf = calloc(priv->nbuf, sizeof(struct video_mmap));
+ if (!priv->buf)
+ goto malloc_failed;
+ memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
}
/* init v4l audio even when we don't capture */
@@ -700,23 +699,23 @@
ioctl(priv->video_fd, VIDIOCSAUDIO, &priv->audio[priv->audio_id]);
}
- if ( tv_param_mjpeg )
- {
+ if (tv_param_mjpeg)
+ {
num = -1;
if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
- {
+ {
mp_msg(MSGT_TV, MSGL_ERR, "\n MJP: ioctl MJPIOC_QBUF_CAPT failed: %s\n", strerror(errno));
- }
- }
+ }
+ }
else
- {
+ {
// We need to munmap as close don't close mem mappings
if(munmap(priv->mmap,priv->mbuf.size))
- mp_msg(MSGT_TV, MSGL_ERR, "Munmap failed: %s\n",strerror(errno));
- }
+ mp_msg(MSGT_TV, MSGL_ERR, "Munmap failed: %s\n",strerror(errno));
+ }
if(close(priv->video_fd))
- mp_msg(MSGT_TV, MSGL_ERR, "Close tv failed: %s\n",strerror(errno));
+ mp_msg(MSGT_TV, MSGL_ERR, "Close tv failed: %s\n",strerror(errno));
audio_in_uninit(&priv->audio_in);
@@ -795,7 +794,6 @@
mp_msg(MSGT_TV, MSGL_V, " Brightness: %d, Hue: %d, Colour: %d, Contrast: %d\n",
priv->picture.brightness, priv->picture.hue,
priv->picture.colour, priv->picture.contrast);
-
if (ioctl(priv->video_fd, VIDIOCSPICT, &priv->picture) == -1)
{
@@ -804,15 +802,15 @@
if ( !tv_param_mjpeg )
{
- priv->nbuf = priv->mbuf.frames;
- for (i=0; i < priv->nbuf; i++)
- {
- priv->buf[i].format = priv->picture.palette;
- priv->buf[i].frame = i;
- priv->buf[i].width = priv->width;
- priv->buf[i].height = priv->height;
- mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
- }
+ priv->nbuf = priv->mbuf.frames;
+ for (i=0; i < priv->nbuf; i++)
+ {
+ priv->buf[i].format = priv->picture.palette;
+ priv->buf[i].frame = i;
+ priv->buf[i].width = priv->width;
+ priv->buf[i].height = priv->height;
+ mp_msg(MSGT_TV, MSGL_DBG2, "buffer: %d => %p\n", i, &priv->buf[i]);
+ }
}
#if 0
@@ -845,7 +843,7 @@
ioctl(priv->video_fd, VIDIOCSWIN, &win);
}
- // initialize video capture
+ // initialize video sub-capture
if (ioctl(priv->video_fd, VIDIOCCAPTURE, &one) == -1)
{
mp_msg(MSGT_TV, MSGL_ERR, "FATAL: ioctl ccapture failed: %s\n", strerror(errno));
@@ -1002,16 +1000,16 @@
output_fmt = priv->format;
if ( tv_param_mjpeg )
{
- mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting sh_video->format to mjpg\n");
- output_fmt = 0x47504a4d;
- output_fmt = 0x67706a6d;
- *(int *)arg = output_fmt;
- mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", "mjpg");
+ mp_msg(MSGT_TV, MSGL_INFO, " MJP: setting sh_video->format to mjpg\n");
+ output_fmt = 0x47504a4d;
+ output_fmt = 0x67706a6d;
+ *(int *)arg = output_fmt;
+ mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", "mjpg");
}
else
{
- *(int *)arg = output_fmt;
- mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt));
+ *(int *)arg = output_fmt;
+ mp_msg(MSGT_TV, MSGL_V, "Output format: %s\n", vo_format_name(output_fmt));
}
return(TVI_CONTROL_TRUE);
}
@@ -1436,25 +1434,25 @@
/* start the capture process */
if ( tv_param_mjpeg )
- {
+ {
mp_msg(MSGT_TV, MSGL_INFO, " MJP: gonna capture ! \n");
for (i=0; i < priv->nbuf; i++) {
- num = i;
- if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
- {
- mp_msg(MSGT_TV, MSGL_ERR,
- "\n MJP: ioctl MJPIOC_QBUF_CAPT b failed: %s\n", strerror(errno));
- }
- }
- }
+ num = i;
+ if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR,
+ "\n MJP: ioctl MJPIOC_QBUF_CAPT b failed: %s\n", strerror(errno));
+ }
+ }
+ }
else
- {
- for (i=0; i < priv->nbuf; i++) {
- if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[i]) == -1)
- {
- mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
+ {
+ for (i=0; i < priv->nbuf; i++) {
+ if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[i]) == -1)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
+ }
}
- }
}
gettimeofday(&curtime, NULL);
@@ -1478,7 +1476,7 @@
while (priv->video_cnt == priv->video_buffer_size_max) {
usleep(10000);
if (priv->shutdown) {
- return NULL;
+ return NULL;
}
}
}
@@ -1487,14 +1485,13 @@
if ( tv_param_mjpeg )
{
- while (ioctl(priv->video_fd, MJPIOC_SYNC, &priv->buf[frame].frame) < 0 &&
- (errno == EAGAIN || errno == EINTR));
-
+ while (ioctl(priv->video_fd, MJPIOC_SYNC, &priv->buf[frame].frame) < 0 &&
+ (errno == EAGAIN || errno == EINTR));
}
else
{
- while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
- (errno == EAGAIN || errno == EINTR));
+ while (ioctl(priv->video_fd, VIDIOCSYNC, &priv->buf[frame].frame) < 0 &&
+ (errno == EAGAIN || errno == EINTR));
}
mp_dbg(MSGT_TV, MSGL_DBG3, "\npicture sync failed\n");
@@ -1609,25 +1606,23 @@
if ( tv_param_mjpeg )
{
- num = frame;
- if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
+ num = frame;
+ if (ioctl(priv->video_fd, MJPIOC_QBUF_CAPT, &num) < 0)
{
- mp_msg(MSGT_TV, MSGL_ERR, "\n MJP: ioctl MJPIOC_QBUF_CAPT end failed: %s\n",
- strerror(errno));
- continue;
+ mp_msg(MSGT_TV, MSGL_ERR, "\n MJP: ioctl MJPIOC_QBUF_CAPT end failed: %s\n",
+ strerror(errno));
+ continue;
}
}
else
{
- if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[frame]) == -1)
- {
- mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
- continue;
- }
+ if (ioctl(priv->video_fd, VIDIOCMCAPTURE, &priv->buf[frame]) == -1)
+ {
+ mp_msg(MSGT_TV, MSGL_ERR, "\nioctl mcapture failed: %s\n", strerror(errno));
+ continue;
+ }
}
-
}
-
}
mp_msg(MSGT_TV, MSGL_INFO, " MJP: returning! \n");
return NULL;
More information about the MPlayer-dev-eng
mailing list