From patchwork Wed Apr 26 10:53:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 9701093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1CC63603F7 for ; Wed, 26 Apr 2017 10:53:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11804262F2 for ; Wed, 26 Apr 2017 10:53:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 063E328459; Wed, 26 Apr 2017 10:53:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6488326E49 for ; Wed, 26 Apr 2017 10:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8RlM9KoWk4jjUjsZon8L7QVhA88iTYyCLwOqPo/FjtY=; b=FgCWpL4s1r6IB4N8c9C7BVlmi Avsyp1Ek8nDlPrQjREuHTMBe/DfyjbvlfVmNZTgFm96SXdgK/FeGzp7gPTL+YS2zsllEmy6ShTM69 F1KI9d1Ff82kv9BYcVmQT6QaXc51bdZlqv+T3UocknDU0PM8CqLKMKCKfLqpadPrapXhY+cen9MXR WheFXZEJ1lQn6fyWi0RVC5zNh+sG8kNFV64FBZcUvjVK02IuHS0Iy0n5H235RZg1aQhFxWYt0l/cj cbPU9W85VZhmJJydo9MEcpRbpf9W89qxK/jt0S8BARZ+LRK0Fwk/wAzdMyTv9r+pYgUDdzQ+pNUFi wxY6stzzA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d3KZf-0003s6-50; Wed, 26 Apr 2017 10:53:31 +0000 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d3KZZ-0003r1-TS for linux-arm-kernel@lists.infradead.org; Wed, 26 Apr 2017 10:53:28 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 9107C823B9; Wed, 26 Apr 2017 12:53:00 +0200 (CEST) Date: Wed, 26 Apr 2017 12:53:00 +0200 From: Pavel Machek To: Mauro Carvalho Chehab Subject: [patch] propagating controls in libv4l2 was Re: support autofocus / autogain in libv4l2 Message-ID: <20170426105300.GA857@amd> References: <1487074823-28274-1-git-send-email-sakari.ailus@linux.intel.com> <1487074823-28274-2-git-send-email-sakari.ailus@linux.intel.com> <20170414232332.63850d7b@vento.lan> <20170416091209.GB7456@valkosipuli.retiisi.org.uk> <20170419105118.72b8e284@vento.lan> <20170424093059.GA20427@amd> <20170424103802.00d3b554@vento.lan> <20170424212914.GA20780@amd> <20170424224724.5bb52382@vento.lan> MIME-Version: 1.0 In-Reply-To: <20170424224724.5bb52382@vento.lan> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170426_035326_290472_F302C0D2 X-CRM114-Status: GOOD ( 28.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ivo.g.dimitrov.75@gmail.com, linux-media@vger.kernel.org, khilman@kernel.org, tony@atomide.com, aaro.koskinen@iki.fi, kernel list , sre@kernel.org, abcloriens@gmail.com, Sakari Ailus , pali.rohar@gmail.com, Sakari Ailus , linux-omap@vger.kernel.org, patrikbachan@gmail.com, linux-arm-kernel , serge@hallyn.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi! > > > IMO, the best place for autofocus is at libv4l2. Putting it on a > > > separate "video server" application looks really weird for me. > > > > Well... let me see. libraries are quite limited -- it is hard to open > > files, or use threads/have custom main loop. It may be useful to > > switch resolutions -- do autofocus/autogain at lower resolution, then > > switch to high one for taking picture. It would be good to have that > > in "system" code, but I'm not at all sure libv4l2 design will allow > > that. > > I don't see why it would be hard to open files or have threads inside > a library. There are several libraries that do that already, specially > the ones designed to be used on multimidia apps. Well, This is what the libv4l2 says: This file implements libv4l2, which offers v4l2_ prefixed versions of open/close/etc. The API is 100% the same as directly opening /dev/videoX using regular open/close/etc, the big difference is that format conversion but if I open additional files in v4l2_open(), API is no longer the same, as unix open() is defined to open just one file descriptor. Now. There is autogain support in libv4lconvert, but it expects to use same fd for camera and for the gain... which does not work with subdevs. Of course, opening subdevs by name like this is not really acceptable. But can you suggest a method that is? Thanks, Pavel commit 4cf9d10ead014c0db25452e4bb9cd144632407c3 Author: Pavel Date: Wed Apr 26 11:38:04 2017 +0200 Add subdevices. diff --git a/lib/libv4l2/libv4l2-priv.h b/lib/libv4l2/libv4l2-priv.h index 343db5e..a6bc48e 100644 --- a/lib/libv4l2/libv4l2-priv.h +++ b/lib/libv4l2/libv4l2-priv.h @@ -26,6 +26,7 @@ #include "../libv4lconvert/libv4lsyscall-priv.h" #define V4L2_MAX_DEVICES 16 +#define V4L2_MAX_SUBDEVS 8 /* Warning when making this larger the frame_queued and frame_mapped members of the v4l2_dev_info struct can no longer be a bitfield, so the code needs to be adjusted! */ @@ -104,6 +105,7 @@ struct v4l2_dev_info { void *plugin_library; void *dev_ops_priv; const struct libv4l_dev_ops *dev_ops; + int subdev_fds[V4L2_MAX_SUBDEVS]; }; /* From v4l2-plugin.c */ diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c index 0ba0a88..edc9642 100644 --- a/lib/libv4l2/libv4l2.c +++ b/lib/libv4l2/libv4l2.c @@ -1,3 +1,4 @@ +/* -*- c-file-style: "linux" -*- */ /* # (C) 2008 Hans de Goede @@ -789,18 +790,25 @@ no_capture: /* Note we always tell v4lconvert to optimize src fmt selection for our default fps, the only exception is the app explicitly selecting - a fram erate using the S_PARM ioctl after a S_FMT */ + a frame rate using the S_PARM ioctl after a S_FMT */ if (devices[index].convert) v4lconvert_set_fps(devices[index].convert, V4L2_DEFAULT_FPS); v4l2_update_fps(index, &parm); + devices[index].subdev_fds[0] = SYS_OPEN("/dev/video_sensor", O_RDWR, 0); + devices[index].subdev_fds[1] = SYS_OPEN("/dev/video_focus", O_RDWR, 0); + devices[index].subdev_fds[2] = -1; + + printf("Sensor: %d, focus: %d\n", devices[index].subdev_fds[0], + devices[index].subdev_fds[1]); + V4L2_LOG("open: %d\n", fd); return fd; } /* Is this an fd for which we are emulating v4l1 ? */ -static int v4l2_get_index(int fd) +int v4l2_get_index(int fd) { int index; commit 1d6a9ce121f53e8f2e38549eed597a3c3dea5233 Author: Pavel Date: Wed Apr 26 12:34:04 2017 +0200 Enable ioctl propagation. diff --git a/lib/libv4l2/libv4l2.c b/lib/libv4l2/libv4l2.c index edc9642..6dab661 100644 --- a/lib/libv4l2/libv4l2.c +++ b/lib/libv4l2/libv4l2.c @@ -1064,6 +1064,23 @@ static int v4l2_s_fmt(int index, struct v4l2_format *dest_fmt) return 0; } +static int v4l2_propagate_ioctl(int index, unsigned long request, void *arg) +{ + int i = 0; + int result; + while (1) { + if (devices[index].subdev_fds[i] == -1) + return -1; + printf("g_ctrl failed, trying...\n"); + result = SYS_IOCTL(devices[index].subdev_fds[i], request, arg); + printf("subdev %d result %d\n", i, result); + if (result == 0) + return 0; + i++; + } + return -1; +} + int v4l2_ioctl(int fd, unsigned long int request, ...) { void *arg; @@ -1193,14 +1210,20 @@ no_capture_request: switch (request) { case VIDIOC_QUERYCTRL: result = v4lconvert_vidioc_queryctrl(devices[index].convert, arg); + if (result == -1) + result = v4l2_propagate_ioctl(index, request, arg); break; case VIDIOC_G_CTRL: result = v4lconvert_vidioc_g_ctrl(devices[index].convert, arg); + if (result == -1) + result = v4l2_propagate_ioctl(index, request, arg); break; case VIDIOC_S_CTRL: result = v4lconvert_vidioc_s_ctrl(devices[index].convert, arg); + if (result == -1) + result = v4l2_propagate_ioctl(index, request, arg); break; case VIDIOC_G_EXT_CTRLS: