Commit 001e41c0 authored by John Tyner's avatar John Tyner Committed by Greg Kroah-Hartman

[PATCH] drivers/usb/media/vicam.c: simplify vicam_read

The following patch removes the old framebuf_size and framebuf_read_start
values from the cam structure and simplifes the read function. It also
moves the needs dummy read check into the read_frame function. cp and dd
should both still work.
parent a0992864
......@@ -421,9 +421,6 @@ struct vicam_camera {
u8 bulkEndpoint;
bool needsDummyRead;
u32 framebuf_size; // # of valid bytes in framebuf
u32 framebuf_read_start; // position in frame buf that a read is happening at.
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *proc_entry;
#endif
......@@ -924,6 +921,11 @@ read_frame(struct vicam_camera *cam, int framenum)
int n;
int actual_length;
if (cam->needsDummyRead) {
cam->needsDummyRead = 0;
read_frame(cam, framenum);
}
memset(request, 0, 16);
request[0] = cam->gain; // 0 = 0% gain, FF = 100% gain
......@@ -974,74 +976,33 @@ read_frame(struct vicam_camera *cam, int framenum)
vicam_decode_color(cam->raw_image,
cam->framebuf +
framenum * VICAM_MAX_FRAME_SIZE );
cam->framebuf_size =
320 * 240 * VICAM_BYTES_PER_PIXEL;
cam->framebuf_read_start = 0;
return;
}
static int
vicam_read( struct file *file, char *buf, size_t count, loff_t *ppos )
{
struct vicam_camera *cam = file->private_data;
DBG("read %d bytes.\n", (int) count);
if (!buf)
return -EINVAL;
DBG("read %d bytes.\n", (int) count);
if (!count)
return -EINVAL;
down_interruptible(&cam->busy_lock);
// This is some code that will hopefully allow us to do shell copies from
// the /dev/videoX to a file and have it actually work.
if (cam->framebuf_size != 0) {
if (cam->framebuf_read_start == cam->framebuf_size) {
cam->framebuf_size = cam->framebuf_read_start = 0;
if (*ppos >= VICAM_MAX_FRAME_SIZE) {
*ppos = 0;
return 0;
} else {
if (cam->framebuf_read_start + count <=
cam->framebuf_size) {
// count does not exceed available bytes
copy_to_user(buf,
(cam->framebuf) +
cam->framebuf_read_start, count);
cam->framebuf_read_start += count;
return count;
} else {
count =
cam->framebuf_size -
cam->framebuf_read_start;
copy_to_user(buf,
(cam->framebuf) +
cam->framebuf_read_start, count);
cam->framebuf_read_start = cam->framebuf_size;
return count;
}
}
}
down_interruptible(&cam->busy_lock);
if (cam->needsDummyRead) {
if (*ppos == 0) {
read_frame(cam, 0);
cam->needsDummyRead = 0;
}
// read_frame twice because the camera doesn't seem to take the shutter speed for the first one.
read_frame(cam, 0);
if (count > cam->framebuf_size)
count = cam->framebuf_size;
copy_to_user(buf, cam->framebuf, count);
count = min_t(size_t, count, VICAM_MAX_FRAME_SIZE - *ppos);
if (count != cam->framebuf_size)
cam->framebuf_read_start = count;
else
cam->framebuf_size = 0;
if (copy_to_user(buf, &cam->framebuf[*ppos], count)) {
count = -EFAULT;
} else {
*ppos += count;
}
up(&cam->busy_lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment