{"id":8407,"url":"https://patchwork.libcamera.org/api/1.1/patches/8407/?format=json","web_url":"https://patchwork.libcamera.org/patch/8407/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200624145256.48266-10-paul.elder@ideasonboard.com>","date":"2020-06-24T14:52:43","name":"[libcamera-devel,v4,09/22] v4l2: v4l2_camera_proxy: Implement VIDIOC_G/S_PRIORITY","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"23e5cf4c8139ba983d14f52a771beabe0fd794db","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/8407/mbox/","series":[{"id":1041,"url":"https://patchwork.libcamera.org/api/1.1/series/1041/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1041","date":"2020-06-24T14:52:34","name":"Support v4l2-compliance","version":4,"mbox":"https://patchwork.libcamera.org/series/1041/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/8407/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/8407/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C37A8609A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Jun 2020 16:53:37 +0200 (CEST)","from jade.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:8147:f2a2:a8c6:9087])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A43FE2A8;\n\tWed, 24 Jun 2020 16:53:35 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"CLAvEjr3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593010417;\n\tbh=amBAHxtTzJeRczpGy1Dv9gTWz1UaDzCb7r4PFA5PcuY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=CLAvEjr3DuBj+szJV4enULzihFPneUhg90/LoFP2J52Qn8sEP9oQlC5LLjCNuS0s/\n\tQXrotHaMkz4Yt8EHEdOYgQCiJJpqcsd8Z+y24ILbkFjE6Pe86vNJnWzQqLP7eBmmWk\n\tOlk5mVV89xXOVeqYJ7z8vFkcnYOYaT9/KEsVvMpM=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 24 Jun 2020 23:52:43 +0900","Message-Id":"<20200624145256.48266-10-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20200624145256.48266-1-paul.elder@ideasonboard.com>","References":"<20200624145256.48266-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 09/22] v4l2: v4l2_camera_proxy:\n\tImplement VIDIOC_G/S_PRIORITY","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 24 Jun 2020 14:53:38 -0000"},"content":"Implement VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY. The behaviour\ndocumented in the V4L2 specification doesn't match the implementation in\nthe Linux kernel, implement the latter.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v4:\n- cosmetic changes\n\nChanges in v3:\n- save the priorities of every file\n  - they're saved in V4L2CameraFile, so save a set of these in V4L2CameraProxy\n    - they're unique from the perspective of the proxy so set is fine\n- actually check the priority for s_fmt, reqbufs, streamon, streamoff,\n  s_input, and s_priority\n\nChanges in v2:\n- use V4L2CameraFile instead of fd and priorities map\n---\n src/v4l2/v4l2_camera_proxy.cpp | 62 +++++++++++++++++++++++++++++++++-\n src/v4l2/v4l2_camera_proxy.h   |  5 +++\n 2 files changed, 66 insertions(+), 1 deletion(-)","diff":"diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp\nindex ad9fa84..99586c3 100644\n--- a/src/v4l2/v4l2_camera_proxy.cpp\n+++ b/src/v4l2/v4l2_camera_proxy.cpp\n@@ -45,8 +45,10 @@ int V4L2CameraProxy::open(V4L2CameraFile *file)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing open fd = \" << file->efd();\n \n-\tif (refcount_++)\n+\tif (refcount_++) {\n+\t\tfiles_.insert(file);\n \t\treturn 0;\n+\t}\n \n \t/*\n \t * We open the camera here, once, and keep it open until the last\n@@ -68,6 +70,8 @@ int V4L2CameraProxy::open(V4L2CameraFile *file)\n \tsetFmtFromConfig(streamConfig_);\n \tsizeimage_ = calculateSizeImage(streamConfig_);\n \n+\tfiles_.insert(file);\n+\n \treturn 0;\n }\n \n@@ -75,6 +79,8 @@ void V4L2CameraProxy::close(V4L2CameraFile *file)\n {\n \tLOG(V4L2Compat, Debug) << \"Servicing close fd = \" << file->efd();\n \n+\tfiles_.erase(file);\n+\n \trelease(file);\n \n \tif (--refcount_ > 0)\n@@ -304,6 +310,9 @@ int V4L2CameraProxy::vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg)\n \tif (!validateBufferType(arg->type))\n \t\treturn -EINVAL;\n \n+\tif (file->priority() < maxPriority())\n+\t\treturn -EBUSY;\n+\n \tint ret = acquire(file);\n \tif (ret < 0)\n \t\treturn ret;\n@@ -340,6 +349,40 @@ int V4L2CameraProxy::vidioc_try_fmt(V4L2CameraFile *file, struct v4l2_format *ar\n \treturn 0;\n }\n \n+enum v4l2_priority V4L2CameraProxy::maxPriority()\n+{\n+\tauto max = std::max_element(files_.begin(), files_.end(),\n+\t\t\t\t    [](const V4L2CameraFile *a, const V4L2CameraFile *b) {\n+\t\t\t\t\t    return a->priority() < b->priority();\n+\t\t\t\t    });\n+\treturn max != files_.end() ? (*max)->priority() : V4L2_PRIORITY_UNSET;\n+}\n+\n+int V4L2CameraProxy::vidioc_g_priority(V4L2CameraFile *file, enum v4l2_priority *arg)\n+{\n+\tLOG(V4L2Compat, Debug) << \"Servicing vidioc_g_priority fd = \" << file->efd();\n+\n+\t*arg = maxPriority();\n+\n+\treturn 0;\n+}\n+\n+int V4L2CameraProxy::vidioc_s_priority(V4L2CameraFile *file, enum v4l2_priority *arg)\n+{\n+\tLOG(V4L2Compat, Debug)\n+\t\t<< \"Servicing vidioc_s_priority fd = \" << file->efd();\n+\n+\tif (*arg > V4L2_PRIORITY_RECORD)\n+\t\treturn -EINVAL;\n+\n+\tif (file->priority() < maxPriority())\n+\t\treturn -EBUSY;\n+\n+\tfile->setPriority(*arg);\n+\n+\treturn 0;\n+}\n+\n void V4L2CameraProxy::freeBuffers()\n {\n \tLOG(V4L2Compat, Debug) << \"Freeing libcamera bufs\";\n@@ -362,6 +405,9 @@ int V4L2CameraProxy::vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuf\n \n \tLOG(V4L2Compat, Debug) << arg->count << \" buffers requested \";\n \n+\tif (file->priority() < maxPriority())\n+\t\treturn -EBUSY;\n+\n \tif (!hasOwnership(file) && owner_)\n \t\treturn -EBUSY;\n \n@@ -512,6 +558,9 @@ int V4L2CameraProxy::vidioc_streamon(V4L2CameraFile *file, int *arg)\n \tif (!validateBufferType(*arg))\n \t\treturn -EINVAL;\n \n+\tif (file->priority() < maxPriority())\n+\t\treturn -EBUSY;\n+\n \tif (!hasOwnership(file))\n \t\treturn -EBUSY;\n \n@@ -527,6 +576,9 @@ int V4L2CameraProxy::vidioc_streamoff(V4L2CameraFile *file, int *arg)\n \tif (!validateBufferType(*arg))\n \t\treturn -EINVAL;\n \n+\tif (file->priority() < maxPriority())\n+\t\treturn -EBUSY;\n+\n \tif (!hasOwnership(file) && owner_)\n \t\treturn -EBUSY;\n \n@@ -544,6 +596,8 @@ const std::set<unsigned long> V4L2CameraProxy::supportedIoctls_ = {\n \tVIDIOC_G_FMT,\n \tVIDIOC_S_FMT,\n \tVIDIOC_TRY_FMT,\n+\tVIDIOC_G_PRIORITY,\n+\tVIDIOC_S_PRIORITY,\n \tVIDIOC_REQBUFS,\n \tVIDIOC_QUERYBUF,\n \tVIDIOC_QBUF,\n@@ -586,6 +640,12 @@ int V4L2CameraProxy::ioctl(V4L2CameraFile *file, unsigned long request, void *ar\n \tcase VIDIOC_TRY_FMT:\n \t\tret = vidioc_try_fmt(file, static_cast<struct v4l2_format *>(arg));\n \t\tbreak;\n+\tcase VIDIOC_G_PRIORITY:\n+\t\tret = vidioc_g_priority(file, static_cast<enum v4l2_priority *>(arg));\n+\t\tbreak;\n+\tcase VIDIOC_S_PRIORITY:\n+\t\tret = vidioc_s_priority(file, static_cast<enum v4l2_priority *>(arg));\n+\t\tbreak;\n \tcase VIDIOC_REQBUFS:\n \t\tret = vidioc_reqbufs(file, static_cast<struct v4l2_requestbuffers *>(arg));\n \t\tbreak;\ndiff --git a/src/v4l2/v4l2_camera_proxy.h b/src/v4l2/v4l2_camera_proxy.h\nindex 86c1a7d..8de306b 100644\n--- a/src/v4l2/v4l2_camera_proxy.h\n+++ b/src/v4l2/v4l2_camera_proxy.h\n@@ -43,6 +43,7 @@ private:\n \tunsigned int calculateSizeImage(StreamConfiguration &streamConfig);\n \tvoid querycap(std::shared_ptr<Camera> camera);\n \tvoid tryFormat(struct v4l2_format *arg);\n+\tenum v4l2_priority maxPriority();\n \tvoid updateBuffers();\n \tvoid freeBuffers();\n \n@@ -51,6 +52,8 @@ private:\n \tint vidioc_g_fmt(V4L2CameraFile *file, struct v4l2_format *arg);\n \tint vidioc_s_fmt(V4L2CameraFile *file, struct v4l2_format *arg);\n \tint vidioc_try_fmt(V4L2CameraFile *file, struct v4l2_format *arg);\n+\tint vidioc_g_priority(V4L2CameraFile *file, enum v4l2_priority *arg);\n+\tint vidioc_s_priority(V4L2CameraFile *file, enum v4l2_priority *arg);\n \tint vidioc_reqbufs(V4L2CameraFile *file, struct v4l2_requestbuffers *arg);\n \tint vidioc_querybuf(V4L2CameraFile *file, struct v4l2_buffer *arg);\n \tint vidioc_qbuf(V4L2CameraFile *file, struct v4l2_buffer *arg);\n@@ -84,6 +87,8 @@ private:\n \tstd::vector<struct v4l2_buffer> buffers_;\n \tstd::map<void *, unsigned int> mmaps_;\n \n+\tstd::set<V4L2CameraFile *> files_;\n+\n \tstd::unique_ptr<V4L2Camera> vcam_;\n \n \t/*\n","prefixes":["libcamera-devel","v4","09/22"]}