summaryrefslogtreecommitdiff
path: root/drivers/media/usb/em28xx/em28xx-video.c
diff options
context:
space:
mode:
authorFrank Schaefer <fschaefer.oss@googlemail.com>2012-12-08 14:31:32 (GMT)
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-12-22 23:09:45 (GMT)
commit36016a351d6245b2753138dff3022efba822e5e2 (patch)
tree9e85e2f1871fb9872f71681fddcf91e4085e012c /drivers/media/usb/em28xx/em28xx-video.c
parent227b7c90671624e0d143e324a3015726282981df (diff)
downloadlinux-fsl-qoriq-36016a351d6245b2753138dff3022efba822e5e2.tar.xz
[media] em28xx: clean up and unify functions em28xx_copy_vbi() em28xx_copy_video()
The code in em28xx_vbi_copy can be simplified a lot. Also rename some variables to something more meaningful and fix+add the function descriptions. Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/usb/em28xx/em28xx-video.c')
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c67
1 files changed, 21 insertions, 46 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 133e6b0..4c1726d 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -168,28 +168,27 @@ static inline void finish_buffer(struct em28xx *dev,
}
/*
- * Identify the buffer header type and properly handles
+ * Copy picture data from USB buffer to videobuf buffer
*/
static void em28xx_copy_video(struct em28xx *dev,
struct em28xx_buffer *buf,
- unsigned char *p,
+ unsigned char *usb_buf,
unsigned long len)
{
void *fieldstart, *startwrite, *startread;
int linesdone, currlinedone, offset, lencopy, remain;
int bytesperline = dev->width << 1;
- unsigned char *outp = buf->vb_buf;
if (buf->pos + len > buf->vb.size)
len = buf->vb.size - buf->pos;
- startread = p;
+ startread = usb_buf;
remain = len;
if (dev->progressive || buf->top_field)
- fieldstart = outp;
+ fieldstart = buf->vb_buf;
else /* interlaced mode, even nr. of lines */
- fieldstart = outp + bytesperline;
+ fieldstart = buf->vb_buf + bytesperline;
linesdone = buf->pos / bytesperline;
currlinedone = buf->pos % bytesperline;
@@ -203,11 +202,12 @@ static void em28xx_copy_video(struct em28xx *dev,
lencopy = bytesperline - currlinedone;
lencopy = lencopy > remain ? remain : lencopy;
- if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
+ if ((char *)startwrite + lencopy > (char *)buf->vb_buf + buf->vb.size) {
em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
- ((char *)startwrite + lencopy) -
- ((char *)outp + buf->vb.size));
- remain = (char *)outp + buf->vb.size - (char *)startwrite;
+ ((char *)startwrite + lencopy) -
+ ((char *)buf->vb_buf + buf->vb.size));
+ remain = (char *)buf->vb_buf + buf->vb.size -
+ (char *)startwrite;
lencopy = remain;
}
if (lencopy <= 0)
@@ -227,13 +227,13 @@ static void em28xx_copy_video(struct em28xx *dev,
else
lencopy = bytesperline;
- if ((char *)startwrite + lencopy > (char *)outp +
+ if ((char *)startwrite + lencopy > (char *)buf->vb_buf +
buf->vb.size) {
em28xx_isocdbg("Overflow of %zi bytes past buffer end"
"(2)\n",
((char *)startwrite + lencopy) -
- ((char *)outp + buf->vb.size));
- lencopy = remain = (char *)outp + buf->vb.size -
+ ((char *)buf->vb_buf + buf->vb.size));
+ lencopy = remain = (char *)buf->vb_buf + buf->vb.size -
(char *)startwrite;
}
if (lencopy <= 0)
@@ -247,50 +247,25 @@ static void em28xx_copy_video(struct em28xx *dev,
buf->pos += len;
}
+/*
+ * Copy VBI data from USB buffer to videobuf buffer
+ */
static void em28xx_copy_vbi(struct em28xx *dev,
struct em28xx_buffer *buf,
- unsigned char *p,
+ unsigned char *usb_buf,
unsigned long len)
{
- void *startwrite, *startread;
- int offset;
- int bytesperline;
- unsigned char *outp;
-
- if (dev == NULL) {
- em28xx_isocdbg("dev is null\n");
- return;
- }
- bytesperline = dev->vbi_width;
-
- if (buf == NULL) {
- return;
- }
- if (p == NULL) {
- em28xx_isocdbg("p is null\n");
- return;
- }
- outp = buf->vb_buf;
- if (outp == NULL) {
- em28xx_isocdbg("outp is null\n");
- return;
- }
+ unsigned int offset;
if (buf->pos + len > buf->vb.size)
len = buf->vb.size - buf->pos;
- startread = p;
-
- startwrite = outp + buf->pos;
offset = buf->pos;
-
/* Make sure the bottom field populates the second half of the frame */
- if (buf->top_field == 0) {
- startwrite += bytesperline * dev->vbi_height;
- offset += bytesperline * dev->vbi_height;
- }
+ if (buf->top_field == 0)
+ offset += dev->vbi_width * dev->vbi_height;
- memcpy(startwrite, startread, len);
+ memcpy(buf->vb_buf + offset, usb_buf, len);
buf->pos += len;
}