From patchwork Sat Dec 8 15:31:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Frank_Sch=C3=A4fer?= X-Patchwork-Id: 1852931 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2F349DF5B1 for ; Sat, 8 Dec 2012 15:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965366Ab2LHPbv (ORCPT ); Sat, 8 Dec 2012 10:31:51 -0500 Received: from mail-ea0-f174.google.com ([209.85.215.174]:38287 "EHLO mail-ea0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965358Ab2LHPbt (ORCPT ); Sat, 8 Dec 2012 10:31:49 -0500 Received: by mail-ea0-f174.google.com with SMTP id e13so548069eaa.19 for ; Sat, 08 Dec 2012 07:31:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=vnoSVcTesuA7VI60/WhumhgWJYwV5+1h6wnIV57HwnI=; b=e9W+rSekPLYa8wJvDgD88yM0O00HRLENaXOVe3wNUSAVNbD1bh2peQZV0WHEEUYbjp qiafT9dpXcnfJXSNNa+iLLRvYD1f3mnplmTchXFpwStv7kQDxN9/Z4/l6Ehk8SPwA0gK 1sOKxvq6tFHnSsHE9BvETXZLkFlyPNPq7dr1BJVLeuXeYCUStn5p+Sl35Br3go/hiPZ6 I57OtUT4EH8aJAyXWIiBkmmLy33i7vtRFF7+oBt3lwdbUkJNx3Op3XZVQVs8gqKqcEH9 iYW6dV3g75SEgPsBirYHAxn9cpIyzSzU5Rgu2Jtixs8RKrguOxo9VtG2ww6bxTaVttHB pE2A== Received: by 10.14.202.3 with SMTP id c3mr29724060eeo.4.1354980708841; Sat, 08 Dec 2012 07:31:48 -0800 (PST) Received: from Athlon64X2-5000.site (ip-37-24-90-62.unitymediagroup.de. [37.24.90.62]) by mx.google.com with ESMTPS id w3sm30274667eel.17.2012.12.08.07.31.46 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 08 Dec 2012 07:31:47 -0800 (PST) From: =?UTF-8?q?Frank=20Sch=C3=A4fer?= To: mchehab@redhat.com Cc: linux-media@vger.kernel.org, =?UTF-8?q?Frank=20Sch=C3=A4fer?= Subject: [PATCH 6/9] em28xx: move caching of pointer to vmalloc memory in videobuf to struct em28xx_buffer Date: Sat, 8 Dec 2012 16:31:29 +0100 Message-Id: <1354980692-3791-7-git-send-email-fschaefer.oss@googlemail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1354980692-3791-1-git-send-email-fschaefer.oss@googlemail.com> References: <1354980692-3791-1-git-send-email-fschaefer.oss@googlemail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In the current code em28xx_urb_data_copy() caches the pointer to the vmalloc memory in videobuf locally. The alternative would be to call videobuf_to_vmalloc() for each processed USB data packet (isoc USB transfers => 64 times per URB) in the em28xx_copy_*() functions. With the next commits, the data processing code will be split into functions for serveral reasons: - em28xx_urb_data_copy() is generally way to long, making it less readable - there is code duplication between VBI and video data processing - support for em25xx data processing (uses a different header and frame end signaling mechanism) will be added This would require extensive usage of pointer-pointers, which usually makes the code less readable and prone to bugs. The better solution is to cache the pointer in struct em28xx_buffer. This also improves consistency, because we already track the buffer fill count there. Signed-off-by: Frank Schäfer --- drivers/media/usb/em28xx/em28xx-video.c | 29 +++++++++-------------------- drivers/media/usb/em28xx/em28xx.h | 3 +++ 2 Dateien geändert, 12 Zeilen hinzugefügt(+), 20 Zeilen entfernt(-) diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 70bc562..60df756 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -173,11 +173,12 @@ static inline void finish_buffer(struct em28xx *dev, static void em28xx_copy_video(struct em28xx *dev, struct em28xx_buffer *buf, unsigned char *p, - unsigned char *outp, unsigned long len) + 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; @@ -249,11 +250,12 @@ static void em28xx_copy_video(struct em28xx *dev, static void em28xx_copy_vbi(struct em28xx *dev, struct em28xx_buffer *buf, unsigned char *p, - unsigned char *outp, unsigned long len) + unsigned long len) { void *startwrite, *startread; int offset; int bytesperline; + unsigned char *outp; if (dev == NULL) { em28xx_usbdbg("dev is null\n"); @@ -268,6 +270,7 @@ static void em28xx_copy_vbi(struct em28xx *dev, em28xx_usbdbg("p is null\n"); return; } + outp = buf->vb_buf; if (outp == NULL) { em28xx_usbdbg("outp is null\n"); return; @@ -350,6 +353,7 @@ static inline struct em28xx_buffer *get_next_buf(struct em28xx *dev, outp = videobuf_to_vmalloc(&buf->vb); memset(outp, 0, buf->vb.size); buf->pos = 0; + buf->vb_buf = outp; return buf; } @@ -362,7 +366,7 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) struct em28xx_dmaqueue *vbi_dma_q = &dev->vbiq; int xfer_bulk, num_packets, i, rc = 1; unsigned int actual_length, len = 0; - unsigned char *p, *outp = NULL, *vbioutp = NULL; + unsigned char *p; if (!dev) return 0; @@ -376,12 +380,7 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) xfer_bulk = usb_pipebulk(urb->pipe); buf = dev->usb_ctl.vid_buf; - if (buf != NULL) - outp = videobuf_to_vmalloc(&buf->vb); - vbi_buf = dev->usb_ctl.vbi_buf; - if (vbi_buf != NULL) - vbioutp = videobuf_to_vmalloc(&vbi_buf->vb); if (xfer_bulk) /* bulk */ num_packets = 1; @@ -455,11 +454,6 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) finish_buffer(dev, vbi_buf); vbi_buf = get_next_buf(dev, vbi_dma_q); dev->usb_ctl.vbi_buf = vbi_buf; - if (vbi_buf == NULL) - vbioutp = NULL; - else - vbioutp = - videobuf_to_vmalloc(&vbi_buf->vb); } if (vbi_buf != NULL) { vbi_buf->top_field = dev->top_field; @@ -474,8 +468,7 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) /* Copy VBI data */ if (vbi_buf != NULL) - em28xx_copy_vbi(dev, vbi_buf, p, vbioutp, - vbi_data_len); + em28xx_copy_vbi(dev, vbi_buf, p, vbi_data_len); dev->vbi_read += vbi_data_len; if (vbi_data_len < len) { @@ -493,10 +486,6 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) finish_buffer(dev, buf); buf = get_next_buf(dev, dma_q); dev->usb_ctl.vid_buf = buf; - if (buf == NULL) - outp = NULL; - else - outp = videobuf_to_vmalloc(&buf->vb); } if (buf != NULL) { buf->top_field = dev->top_field; @@ -505,7 +494,7 @@ static inline int em28xx_urb_data_copy(struct em28xx *dev, struct urb *urb) } if (buf != NULL && dev->capture_type == 3 && len > 0) - em28xx_copy_video(dev, buf, p, outp, len); + em28xx_copy_video(dev, buf, p, len); } return rc; } diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h index 7507aa6..062841e 100644 --- a/drivers/media/usb/em28xx/em28xx.h +++ b/drivers/media/usb/em28xx/em28xx.h @@ -258,6 +258,9 @@ struct em28xx_buffer { unsigned int pos; /* NOTE; in interlaced mode, this value is reset to zero at * the start of each new field (not frame !) */ + + /* pointer to vmalloc memory address in vb */ + char *vb_buf; }; struct em28xx_dmaqueue {