Patch Detail
Show a patch.
GET /api/patches/3879/?format=api
{ "id": 3879, "url": "https://patchwork.libcamera.org/api/patches/3879/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3879/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200529110335.620503-3-jacopo@jmondi.org>", "date": "2020-05-29T11:03:32", "name": "[libcamera-devel,2/5] libcamera: v4l2_videodevice: Use ImageFormats", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "6c4cba071ec279d7f047109146e3746a238b625e", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3879/mbox/", "series": [ { "id": 938, "url": "https://patchwork.libcamera.org/api/series/938/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=938", "date": "2020-05-29T11:03:30", "name": "ImageFormats' not dead", "version": 1, "mbox": "https://patchwork.libcamera.org/series/938/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3879/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3879/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E76CD61012\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 29 May 2020 13:00:30 +0200 (CEST)", "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 62CBBE0009;\n\tFri, 29 May 2020 11:00:30 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 29 May 2020 13:03:32 +0200", "Message-Id": "<20200529110335.620503-3-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.26.2", "In-Reply-To": "<20200529110335.620503-1-jacopo@jmondi.org>", "References": "<20200529110335.620503-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 2/5] libcamera: v4l2_videodevice: Use\n\tImageFormats", "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": "Fri, 29 May 2020 11:00:31 -0000" }, "content": "ImageFormats was meant to be used not only for V4L2Subdevice but\nfor video devices as well. Since the introduction of of V4L2PixelFormat\nthe V4L2VideoDevice class and its users have been using a raw map to\nenumerate and inspect the V4L2VideoDevice formats.\n\nUse the ImageFormats<V4L2PixelFormat> specialization in place of a raw\nmap and update its usage in pipeline handlers.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n include/libcamera/internal/v4l2_videodevice.h | 2 +-\n .../pipeline/raspberrypi/raspberrypi.cpp | 17 +++++++----------\n src/libcamera/pipeline/simple/simple.cpp | 3 +--\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 3 +--\n src/libcamera/v4l2_videodevice.cpp | 4 ++--\n 5 files changed, 12 insertions(+), 17 deletions(-)", "diff": "diff --git a/include/libcamera/internal/v4l2_videodevice.h b/include/libcamera/internal/v4l2_videodevice.h\nindex dc259523599c..de4745982e94 100644\n--- a/include/libcamera/internal/v4l2_videodevice.h\n+++ b/include/libcamera/internal/v4l2_videodevice.h\n@@ -187,7 +187,7 @@ public:\n \n \tint getFormat(V4L2DeviceFormat *format);\n \tint setFormat(V4L2DeviceFormat *format);\n-\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> formats(uint32_t code = 0);\n+\tImageFormats<V4L2PixelFormat> formats(uint32_t code = 0);\n \n \tint setSelection(unsigned int target, Rectangle *rect);\n \ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex e16a9c7f10d3..64364afb3f7e 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -37,8 +37,6 @@ namespace libcamera {\n \n LOG_DEFINE_CATEGORY(RPI)\n \n-using V4L2PixFmtMap = std::map<V4L2PixelFormat, std::vector<SizeRange>>;\n-\n namespace {\n \n bool isRaw(PixelFormat &pixFmt)\n@@ -67,7 +65,7 @@ double scoreFormat(double desired, double actual)\n \treturn score;\n }\n \n-V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req)\n+V4L2DeviceFormat findBestMode(ImageFormats<V4L2PixelFormat> &formatsMap, const Size &req)\n {\n \tdouble bestScore = 9e9, score;\n \tV4L2DeviceFormat bestMode = {};\n@@ -79,12 +77,11 @@ V4L2DeviceFormat findBestMode(V4L2PixFmtMap &formatsMap, const Size &req)\n #define PENALTY_UNPACKED\t 500.0\n \n \t/* Calculate the closest/best mode from the user requested size. */\n-\tfor (const auto &iter : formatsMap) {\n-\t\tV4L2PixelFormat v4l2Format = iter.first;\n+\tfor (const auto &v4l2Format : formatsMap.formats()) {\n \t\tPixelFormat pixelFormat = v4l2Format.toPixelFormat();\n \t\tconst PixelFormatInfo &info = PixelFormatInfo::info(pixelFormat);\n \n-\t\tfor (const SizeRange &sz : iter.second) {\n+\t\tfor (const SizeRange &sz : formatsMap.sizes(v4l2Format)) {\n \t\t\tdouble modeWidth = sz.contains(req) ? req.width : sz.max.width;\n \t\t\tdouble modeHeight = sz.contains(req) ? req.height : sz.max.height;\n \t\t\tdouble reqAr = static_cast<double>(req.width) / req.height;\n@@ -427,7 +424,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t\t * Calculate the best sensor mode we can use based on\n \t\t\t * the user request.\n \t\t\t */\n-\t\t\tV4L2PixFmtMap fmts = data_->unicam_[Unicam::Image].dev()->formats();\n+\t\t\tImageFormats<V4L2PixelFormat> fmts = data_->unicam_[Unicam::Image].dev()->formats();\n \t\t\tV4L2DeviceFormat sensorFormat = findBestMode(fmts, cfg.size);\n \t\t\tPixelFormat sensorPixFormat = sensorFormat.fourcc.toPixelFormat();\n \t\t\tif (cfg.size != sensorFormat.size ||\n@@ -481,7 +478,7 @@ CameraConfiguration::Status RPiCameraConfiguration::validate()\n \t\t *\n \t\t */\n \t\tPixelFormat &cfgPixFmt = config_.at(outSize[i].first).pixelFormat;\n-\t\tV4L2PixFmtMap fmts;\n+\t\tImageFormats<V4L2PixelFormat> fmts;\n \n \t\tif (i == maxIndex)\n \t\t\tfmts = data_->isp_[Isp::Output0].dev()->formats();\n@@ -518,7 +515,7 @@ CameraConfiguration *PipelineHandlerRPi::generateConfiguration(Camera *camera,\n \tRPiCameraData *data = cameraData(camera);\n \tCameraConfiguration *config = new RPiCameraConfiguration(data);\n \tV4L2DeviceFormat sensorFormat;\n-\tV4L2PixFmtMap fmts;\n+\tImageFormats<V4L2PixelFormat> fmts;\n \n \tif (roles.empty())\n \t\treturn config;\n@@ -605,7 +602,7 @@ int PipelineHandlerRPi::configure(Camera *camera, CameraConfiguration *config)\n \t}\n \n \t/* First calculate the best sensor mode we can use based on the user request. */\n-\tV4L2PixFmtMap fmts = data->unicam_[Unicam::Image].dev()->formats();\n+\tImageFormats<V4L2PixelFormat> fmts = data->unicam_[Unicam::Image].dev()->formats();\n \tV4L2DeviceFormat sensorFormat = findBestMode(fmts, rawStream ? sensorSize : maxSize);\n \n \t/*\ndiff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 1ec8d0f7de03..f3e03ba60196 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -275,8 +275,7 @@ int SimpleCameraData::init()\n \t\t\treturn ret;\n \t\t}\n \n-\t\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> videoFormats =\n-\t\t\tvideo_->formats(format.mbus_code);\n+\t\tImageFormats<V4L2PixelFormat> videoFormats = video_->formats(format.mbus_code);\n \n \t\tLOG(SimplePipeline, Debug)\n \t\t\t<< \"Adding configuration for \" << format.size.toString()\ndiff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex a074909499f1..dbd835f5c5ef 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -159,8 +159,7 @@ CameraConfiguration *PipelineHandlerUVC::generateConfiguration(Camera *camera,\n \tif (roles.empty())\n \t\treturn config;\n \n-\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> v4l2Formats =\n-\t\tdata->video_->formats();\n+\tImageFormats<V4L2PixelFormat> v4l2Formats = data->video_->formats();\n \tstd::map<PixelFormat, std::vector<SizeRange>> deviceFormats;\n \tstd::transform(v4l2Formats.begin(), v4l2Formats.end(),\n \t\t std::inserter(deviceFormats, deviceFormats.begin()),\ndiff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\nindex 3614b2ed1cbc..ea952444e0ad 100644\n--- a/src/libcamera/v4l2_videodevice.cpp\n+++ b/src/libcamera/v4l2_videodevice.cpp\n@@ -925,9 +925,9 @@ int V4L2VideoDevice::setFormatSingleplane(V4L2DeviceFormat *format)\n *\n * \\return A list of the supported video device formats\n */\n-std::map<V4L2PixelFormat, std::vector<SizeRange>> V4L2VideoDevice::formats(uint32_t code)\n+ImageFormats<V4L2PixelFormat> V4L2VideoDevice::formats(uint32_t code)\n {\n-\tstd::map<V4L2PixelFormat, std::vector<SizeRange>> formats;\n+\tImageFormats<V4L2PixelFormat> formats;\n \n \tfor (V4L2PixelFormat pixelFormat : enumPixelformats(code)) {\n \t\tstd::vector<SizeRange> sizes = enumSizes(pixelFormat);\n", "prefixes": [ "libcamera-devel", "2/5" ] }