From patchwork Tue Nov 3 10:16:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junghak Sung X-Patchwork-Id: 7541361 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D152E9F399 for ; Tue, 3 Nov 2015 10:17:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A950C20528 for ; Tue, 3 Nov 2015 10:17:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B98020524 for ; Tue, 3 Nov 2015 10:17:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbbKCKQ5 (ORCPT ); Tue, 3 Nov 2015 05:16:57 -0500 Received: from mailout3.samsung.com ([203.254.224.33]:60378 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751715AbbKCKQu (ORCPT ); Tue, 3 Nov 2015 05:16:50 -0500 Received: from epcpsbgr1.samsung.com (u141.gpu120.samsung.co.kr [203.254.230.141]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NX800923HVW7220@mailout3.samsung.com> for linux-media@vger.kernel.org; Tue, 03 Nov 2015 19:16:44 +0900 (KST) Received: from epcpsbgm2new.samsung.com ( [172.20.52.112]) by epcpsbgr1.samsung.com (EPCPMTA) with SMTP id 7E.66.05274.C8988365; Tue, 3 Nov 2015 19:16:44 +0900 (KST) X-AuditID: cbfee68d-f79ae6d00000149a-76-5638898cd8dd Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id CD.D3.18629.C8988365; Tue, 3 Nov 2015 19:16:44 +0900 (KST) Received: from localhost.localdomain ([10.252.83.96]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NX8008Z8HVVS340@mmp2.samsung.com>; Tue, 03 Nov 2015 19:16:44 +0900 (KST) From: Junghak Sung To: linux-media@vger.kernel.org, mchehab@osg.samsung.com, hverkuil@xs4all.nl, laurent.pinchart@ideasonboard.com, sakari.ailus@iki.fi, pawel@osciak.com Cc: inki.dae@samsung.com, sw0312.kim@samsung.com, nenggun.kim@samsung.com, sangbae90.lee@samsung.com, rany.kwon@samsung.com, Junghak Sung Subject: [RFC PATCH v9 5/6] media: videobuf2: Refactor vb2_fileio_data and vb2_thread Date: Tue, 03 Nov 2015 19:16:41 +0900 Message-id: <1446545802-28496-6-git-send-email-jh1009.sung@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1446545802-28496-1-git-send-email-jh1009.sung@samsung.com> References: <1446545802-28496-1-git-send-email-jh1009.sung@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRmVeSWpSXmKPExsWyRsSkQLen0yLMYP0uLYtTk58xWUy6P4HF YvvxV+wWnROXsFv0bNjKarH6WYXFgb5dTBZT3v5kt/g37SmzxZn9K9ksjn86yGIxY/JLNgce j9kdM1k9Dn9dyOLx+NdLNo8t/XfZPfq2rGL0+LxJzuPU18/sAexRXDYpqTmZZalF+nYJXBnv 755lLphrXfH9W3wD41+9LkZODgkBE4mmf7/ZIWwxiQv31rN1MXJxCAmsYJTY8HcSE0zR09lX oBKzGCXmXmtmhnC+M0r0TlvI2MXIwcEmoCMxebMhSFxEYAZQ/PgqJhCHWWA5o8Tp16fAdggL hEv839zKBmKzCKhKzPm/CCzOK+Au8WL5FCaQQRICChJzJtmAmJwCHhL9f0tBKoRAKqYfYYM4 6BK7xKFGZogpAhLfJh9igeiUldh0gBmiRFLi4IobLBMYhRcwMqxiFE0tSC4oTkovMtQrTsw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+pg4OKUaGPmb/ot8bPwu e7ns9JRd16OmnDp/W/a3PnMk73GBk8wMP87yn1vDz6vC43VCuP/xYx4L16e/vV+4BB3dPCeo zjuV8ZyjI8/Jl3mCfLfCj4mevv+Y0fe17+aIxWs23pVYLZlVp/qJoVheXuT67AWn06/8vai6 9YBc+kr5oEN6hk9kem6dk7qg6KLEUpyRaKjFXFScCABapw7F3AIAAA== DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Replace v4l2-stuffs with common things in struct vb2_fileio_data and vb2_thread(). Signed-off-by: Junghak Sung Signed-off-by: Geunyoung Kim Acked-by: Seung-Woo Kim Acked-by: Inki Dae Acked-by: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-v4l2.c | 104 ++++++++++++++---------------- 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index b0293df..f806ef4 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -920,9 +920,10 @@ struct vb2_fileio_buf { * or write function. */ struct vb2_fileio_data { - struct v4l2_requestbuffers req; - struct v4l2_plane p; - struct v4l2_buffer b; + unsigned int count; + unsigned int type; + unsigned int memory; + struct vb2_buffer *b; struct vb2_fileio_buf bufs[VB2_MAX_FRAME]; unsigned int cur_index; unsigned int initial_index; @@ -975,6 +976,10 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) if (fileio == NULL) return -ENOMEM; + fileio->b = kzalloc(q->buf_struct_size, GFP_KERNEL); + if (fileio->b == NULL) + return -ENOMEM; + fileio->read_once = q->fileio_read_once; fileio->write_immediately = q->fileio_write_immediately; @@ -982,11 +987,11 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Request buffers and use MMAP type to force driver * to allocate buffers by itself. */ - fileio->req.count = count; - fileio->req.memory = VB2_MEMORY_MMAP; - fileio->req.type = q->type; + fileio->count = count; + fileio->memory = VB2_MEMORY_MMAP; + fileio->type = q->type; q->fileio = fileio; - ret = vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count); + ret = vb2_core_reqbufs(q, fileio->memory, &fileio->count); if (ret) goto err_kfree; @@ -1015,24 +1020,17 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Read mode requires pre queuing of all buffers. */ if (read) { - bool is_multiplanar = q->is_multiplanar; - /* * Queue all buffers. */ for (i = 0; i < q->num_buffers; i++) { - struct v4l2_buffer *b = &fileio->b; + struct vb2_buffer *b = fileio->b; - memset(b, 0, sizeof(*b)); + memset(b, 0, q->buf_struct_size); b->type = q->type; - if (is_multiplanar) { - memset(&fileio->p, 0, sizeof(fileio->p)); - b->m.planes = &fileio->p; - b->length = 1; - } b->memory = q->memory; b->index = i; - ret = vb2_internal_qbuf(q, b); + ret = vb2_core_qbuf(q, i, b); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; @@ -1055,8 +1053,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) return ret; err_reqbufs: - fileio->req.count = 0; - vb2_core_reqbufs(q, fileio->req.memory, &fileio->req.count); + fileio->count = 0; + vb2_core_reqbufs(q, fileio->memory, &fileio->count); err_kfree: q->fileio = NULL; @@ -1075,8 +1073,9 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q) if (fileio) { vb2_core_streamoff(q, q->type); q->fileio = NULL; - fileio->req.count = 0; - vb2_reqbufs(q, &fileio->req); + fileio->count = 0; + vb2_core_reqbufs(q, fileio->memory, &fileio->count); + kfree(fileio->b); kfree(fileio); dprintk(3, "file io emulator closed\n"); } @@ -1129,24 +1128,21 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ */ index = fileio->cur_index; if (index >= q->num_buffers) { + struct vb2_buffer *b = fileio->b; + /* * Call vb2_dqbuf to get buffer back. */ - memset(&fileio->b, 0, sizeof(fileio->b)); - fileio->b.type = q->type; - fileio->b.memory = q->memory; - if (is_multiplanar) { - memset(&fileio->p, 0, sizeof(fileio->p)); - fileio->b.m.planes = &fileio->p; - fileio->b.length = 1; - } - ret = vb2_internal_dqbuf(q, &fileio->b, nonblock); + memset(b, 0, q->buf_struct_size); + b->type = q->type; + b->memory = q->memory; + ret = vb2_core_dqbuf(q, b, nonblock); dprintk(5, "vb2_dqbuf result: %d\n", ret); if (ret) return ret; fileio->dq_count += 1; - fileio->cur_index = index = fileio->b.index; + fileio->cur_index = index = b->index; buf = &fileio->bufs[index]; /* @@ -1158,8 +1154,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ : vb2_plane_size(q->bufs[index], 0); /* Compensate for data_offset on read in the multiplanar case. */ if (is_multiplanar && read && - fileio->b.m.planes[0].data_offset < buf->size) { - buf->pos = fileio->b.m.planes[0].data_offset; + b->planes[0].data_offset < buf->size) { + buf->pos = b->planes[0].data_offset; buf->size -= buf->pos; } } else { @@ -1198,6 +1194,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ * Queue next buffer if required. */ if (buf->pos == buf->size || (!read && fileio->write_immediately)) { + struct vb2_buffer *b = fileio->b; + /* * Check if this is the last buffer to read. */ @@ -1209,20 +1207,15 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ /* * Call vb2_qbuf and give buffer to the driver. */ - memset(&fileio->b, 0, sizeof(fileio->b)); - fileio->b.type = q->type; - fileio->b.memory = q->memory; - fileio->b.index = index; - fileio->b.bytesused = buf->pos; - if (is_multiplanar) { - memset(&fileio->p, 0, sizeof(fileio->p)); - fileio->p.bytesused = buf->pos; - fileio->b.m.planes = &fileio->p; - fileio->b.length = 1; - } + memset(b, 0, q->buf_struct_size); + b->type = q->type; + b->memory = q->memory; + b->index = index; + b->planes[0].bytesused = buf->pos; + if (set_timestamp) - v4l2_get_timestamp(&fileio->b.timestamp); - ret = vb2_internal_qbuf(q, &fileio->b); + b->timestamp = ktime_get_ns(); + ret = vb2_core_qbuf(q, index, b); dprintk(5, "vb2_dbuf result: %d\n", ret); if (ret) return ret; @@ -1299,20 +1292,21 @@ static int vb2_thread(void *data) for (;;) { struct vb2_buffer *vb; + struct vb2_buffer *b = fileio->b; /* * Call vb2_dqbuf to get buffer back. */ - memset(&fileio->b, 0, sizeof(fileio->b)); - fileio->b.type = q->type; - fileio->b.memory = q->memory; + memset(b, 0, q->buf_struct_size); + b->type = q->type; + b->memory = q->memory; if (prequeue) { - fileio->b.index = index++; + b->index = index++; prequeue--; } else { call_void_qop(q, wait_finish, q); if (!threadio->stop) - ret = vb2_internal_dqbuf(q, &fileio->b, 0); + ret = vb2_core_dqbuf(q, b, 0); call_void_qop(q, wait_prepare, q); dprintk(5, "file io: vb2_dqbuf result: %d\n", ret); } @@ -1320,15 +1314,15 @@ static int vb2_thread(void *data) break; try_to_freeze(); - vb = q->bufs[fileio->b.index]; - if (!(fileio->b.flags & V4L2_BUF_FLAG_ERROR)) + vb = q->bufs[b->index]; + if (b->state == VB2_BUF_STATE_DONE) if (threadio->fnc(vb, threadio->priv)) break; call_void_qop(q, wait_finish, q); if (set_timestamp) - v4l2_get_timestamp(&fileio->b.timestamp); + b->timestamp = ktime_get_ns(); if (!threadio->stop) - ret = vb2_internal_qbuf(q, &fileio->b); + ret = vb2_core_qbuf(q, b->index, b); call_void_qop(q, wait_prepare, q); if (ret || threadio->stop) break;