From: "Frank Schäfer" <fschaefer.oss@googlemail.com>
To: mchehab@redhat.com
Cc: linux-media@vger.kernel.org,
"Frank Schäfer" <fschaefer.oss@googlemail.com>
Subject: [PATCH 9/9] em28xx: clean up and unify functions em28xx_copy_vbi() em28xx_copy_video()
Date: Sat, 8 Dec 2012 16:31:32 +0100 [thread overview]
Message-ID: <1354980692-3791-10-git-send-email-fschaefer.oss@googlemail.com> (raw)
In-Reply-To: <1354980692-3791-1-git-send-email-fschaefer.oss@googlemail.com>
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>
---
drivers/media/usb/em28xx/em28xx-video.c | 65 ++++++++++---------------------
1 Datei geändert, 20 Zeilen hinzugefügt(+), 45 Zeilen entfernt(-)
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index fb40d0b..bd168de 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_usbdbg("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 *)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_usbdbg("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_usbdbg("dev is null\n");
- return;
- }
- bytesperline = dev->vbi_width;
-
- if (buf == NULL) {
- return;
- }
- if (p == NULL) {
- em28xx_usbdbg("p is null\n");
- return;
- }
- outp = buf->vb_buf;
- if (outp == NULL) {
- em28xx_usbdbg("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;
}
--
1.7.10.4
next prev parent reply other threads:[~2012-12-08 15:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-08 15:31 [PATCH 0/9] em28xx: refactor the frame data processing code Frank Schäfer
2012-12-08 15:31 ` [PATCH 1/9] em28xx: refactor get_next_buf() and use it for vbi data, too Frank Schäfer
2012-12-08 15:31 ` [PATCH 2/9] em28xx: use common function for video and vbi buffer completion Frank Schäfer
2012-12-08 15:31 ` [PATCH 3/9] em28xx: remove obsolete field 'frame' from struct em28xx_buffer Frank Schäfer
2012-12-08 15:31 ` [PATCH 4/9] em28xx: move field 'pos' from struct em28xx_dmaqueue to " Frank Schäfer
2012-12-08 15:31 ` [PATCH 5/9] em28xx: refactor VBI data processing code in em28xx_urb_data_copy() Frank Schäfer
2012-12-08 15:31 ` [PATCH 6/9] em28xx: move caching of pointer to vmalloc memory in videobuf to struct em28xx_buffer Frank Schäfer
2012-12-08 15:31 ` [PATCH 7/9] em28xx: em28xx_urb_data_copy(): move duplicate code for capture_type=0 and capture_type=2 to a function Frank Schäfer
2012-12-08 15:31 ` [PATCH 8/9] em28xx: move the em2710/em2750/em28xx specific frame data processing code to a separate function Frank Schäfer
2012-12-08 15:31 ` Frank Schäfer [this message]
[not found] ` <CAGoCfiw1wN+KgvNLqDSmbz5AwswPT9K48XOM4RnfKvHkmmR59g@mail.gmail.com>
2012-12-13 17:56 ` [PATCH 0/9] em28xx: refactor the frame data processing code Frank Schäfer
2012-12-13 18:16 ` Devin Heitmueller
2012-12-14 15:24 ` Frank Schäfer
2012-12-14 15:29 ` Devin Heitmueller
2012-12-14 15:45 ` Frank Schäfer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1354980692-3791-10-git-send-email-fschaefer.oss@googlemail.com \
--to=fschaefer.oss@googlemail.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.