Patch Detail
Show a patch.
GET /api/1.1/patches/16637/?format=api
{ "id": 16637, "url": "https://patchwork.libcamera.org/api/1.1/patches/16637/?format=api", "web_url": "https://patchwork.libcamera.org/patch/16637/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20220715113604.10131-1-ecurtin@redhat.com>", "date": "2022-07-15T11:36:05", "name": "[libcamera-devel,v2] cam: sdl_sink: Use libjpeg over SDL2_image", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "94e50d0f7801eab60f0fefa7b5c8eb013c080c3f", "submitter": { "id": 101, "url": "https://patchwork.libcamera.org/api/1.1/people/101/?format=api", "name": "Eric Curtin", "email": "ecurtin@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/16637/mbox/", "series": [ { "id": 3287, "url": "https://patchwork.libcamera.org/api/1.1/series/3287/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3287", "date": "2022-07-15T11:36:05", "name": "[libcamera-devel,v2] cam: sdl_sink: Use libjpeg over SDL2_image", "version": 2, "mbox": "https://patchwork.libcamera.org/series/3287/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/16637/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/16637/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8114FBE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 15 Jul 2022 11:42:48 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 486D163312;\n\tFri, 15 Jul 2022 13:42:48 +0200 (CEST)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 536456330A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Jul 2022 13:42:47 +0200 (CEST)", "from mail-wm1-f72.google.com (mail-wm1-f72.google.com\n\t[209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-465-kN2-VBg1NLK2yR9ypUappg-1; Fri, 15 Jul 2022 07:42:45 -0400", "by mail-wm1-f72.google.com with SMTP id\n\tv18-20020a05600c215200b003a2fea66b7cso1781630wml.4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 15 Jul 2022 04:42:45 -0700 (PDT)", "from localhost.localdomain\n\t([2001:8a0:6ed9:ab01:85de:1e25:70ef:ff9e])\n\tby smtp.gmail.com with ESMTPSA id\n\tm65-20020a1ca344000000b0039c5a765388sm4923933wme.28.2022.07.15.04.42.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 15 Jul 2022 04:42:42 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657885368;\n\tbh=nbXzclAiXC2DFTKOjABoK5xci9vnQrLGw2hzLvQFs0k=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=BJpKuUHmMyVP6zDlcS+xuXLp1RsojSQjuCFMfkPotieYGpTrAeztMzUZkcD6itOQb\n\tB5sfzAVdxmLq5oLA0bkiA63RJS1twdB6HTU7N1FNHhL+H6+eKn9Cs/pwZ6fVLHg1Nv\n\t1/MG/nocCXMv0J8EUNDh+X//L8iG+Z4GXmIjjeRlcG42l0GbGZbjMXkKn6zi1Tab6b\n\t6BaLj3PiT3Hpl4Sd1/9JHm+PJRhGviyzN2C96PQkAppnVgLr5NCXq2yJVeaYxdF7EU\n\tc9pyQpUcT3g7f+t7m1jj+YsYhR+ytaGPq1kY+BwX3KrVC42m5fm1/G5YtWd2aAGJ4C\n\tfulNTgGSU+jxg==", "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1657885366;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding;\n\tbh=LEZeDKetc+/u9TutSq6Yk2Y3UBYnvu1ZHom0mHkNUa0=;\n\tb=FugJInLWXJA3QFTRMPKE059quIfRe/oTMyihFzeheulIM/waDs71yRWezStL+R2nkEyKPt\n\t4p/7teFv4ldWt8UQzhpqkOey+GbPhgSDy9ZohLJiojYZwdhTvOJsB2h5SERmfjiYHc3o1F\n\tzOi+d9+RTfN1bQG/YJGO3eYlrIoTgt0=" ], "Authentication-Results": [ "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"FugJInLW\"; \n\tdkim-atps=neutral", "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com" ], "X-MC-Unique": "kN2-VBg1NLK2yR9ypUappg-1", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=LEZeDKetc+/u9TutSq6Yk2Y3UBYnvu1ZHom0mHkNUa0=;\n\tb=Za7ufcqDVIKBkGNFrt0gYdb7KyeeY2QSPcuZDXYsunv0EdwMkWuVapEaGv/TO3s/Kw\n\tJSz+SI2MXElKRBiPlFfvhhTo7TNuICNYXfQ1vp1g5Z61euVxXRNXRtr2bmceyahBeDHv\n\t2EaHXwyZrNXcpJlFRlaT+L3c2ajts9OvvwrI3Xa/tBk/ecniyKU5j0DkHBahNKovV1N5\n\txZqk3eK5JgcYWyhKgz6zZb4S6BDoW8sqf4kfDHsZHd45RhSmmR3CMWkJ1HFuL3kRc334\n\t0f5CuBrouV9ZoyAFgz7U+OrHzlPLPRb1lP/u13lQgIdCHVLtYpeUElWgI7IGFbIYiQp1\n\trA+w==", "X-Gm-Message-State": "AJIora+2mL/rzTgj9ykoFFVuwfnMM0cKqu+tJl+Z7vDCFeDnPPZD/fnF\n\tlmnUmabysZ5JisxRvcJhQAw38mH58K6IwUsoUtP6ggtkuBhK/IeXwYHvExmuysWTASVEVhCrIQm\n\t0qzE96USsA5w8evNIXe0fOnWlfwaxQhthl+5RyhlTO0/ebCesxwfcjp43Ht+YXO2oFND1TcMH9M\n\tcj32FT0d4D", "X-Received": [ "by 2002:a5d:55d0:0:b0:21d:cf5a:7617 with SMTP id\n\ti16-20020a5d55d0000000b0021dcf5a7617mr2406973wrw.368.1657885363748; \n\tFri, 15 Jul 2022 04:42:43 -0700 (PDT)", "by 2002:a5d:55d0:0:b0:21d:cf5a:7617 with SMTP id\n\ti16-20020a5d55d0000000b0021dcf5a7617mr2406959wrw.368.1657885363517; \n\tFri, 15 Jul 2022 04:42:43 -0700 (PDT)" ], "X-Google-Smtp-Source": "AGRyM1tf9v7Aq/kbYjjC3g6dV50iq8tWv+WzwBTjXAg84BDYvhbwlE9hBpk+Z9AfRFPvvP3vM3PVEg==", "To": "libcamera-devel@lists.libcamera.org", "Date": "Fri, 15 Jul 2022 12:36:05 +0100", "Message-Id": "<20220715113604.10131-1-ecurtin@redhat.com>", "X-Mailer": "git-send-email 2.35.3", "MIME-Version": "1.0", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true", "Subject": "[libcamera-devel] [PATCH v2] cam: sdl_sink: Use libjpeg over\n\tSDL2_image", "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>", "From": "Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Eric Curtin <ecurtin@redhat.com>", "Cc": "Ian Mullins <imullins@redhat.com>, jozef@mlich.cz", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "We were using the libjpeg functionality of SDL2_image only, instead just\nuse libjpeg directly to reduce our dependancy count, it is a more\ncommonly available library.\n\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\n---\nChanges in v2:\n- alphabetically sorted various orderings\n- pitch_ is const again\n- added setjmp logic for error handling in libjpeg\n- rgbdata_ to unique_ptr and renamed to rgb_\n- removed a copy from buffer to rgb_\n- removed a destructor\n---\n README.rst | 2 +-\n src/cam/meson.build | 8 ++---\n src/cam/sdl_sink.cpp | 4 +--\n src/cam/sdl_texture_mjpg.cpp | 63 ++++++++++++++++++++++++++++++++----\n src/cam/sdl_texture_mjpg.h | 6 ++++\n 5 files changed, 70 insertions(+), 13 deletions(-)", "diff": "diff --git a/README.rst b/README.rst\nindex b9e72d81..47b914f0 100644\n--- a/README.rst\n+++ b/README.rst\n@@ -92,8 +92,8 @@ for cam: [optional]\n tool:\n \n - libdrm-dev: Enables the KMS sink\n+ - libjpeg-dev: Enables MJPEG on the SDL sink\n - libsdl2-dev: Enables the SDL sink\n- - libsdl2-image-dev: Supports MJPEG on the SDL sink\n \n for qcam: [optional]\n qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 5957ce14..4dfa7b22 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -24,8 +24,8 @@ cam_sources = files([\n cam_cpp_args = []\n \n libdrm = dependency('libdrm', required : false)\n+libjpeg = dependency('libjpeg', required : false)\n libsdl2 = dependency('SDL2', required : false)\n-libsdl2_image = dependency('SDL2_image', required : false)\n \n if libdrm.found()\n cam_cpp_args += [ '-DHAVE_KMS' ]\n@@ -43,8 +43,8 @@ if libsdl2.found()\n 'sdl_texture_yuyv.cpp'\n ])\n \n- if libsdl2_image.found()\n- cam_cpp_args += ['-DHAVE_SDL_IMAGE']\n+ if libjpeg.found()\n+ cam_cpp_args += ['-DHAVE_LIBJPEG']\n cam_sources += files([\n 'sdl_texture_mjpg.cpp'\n ])\n@@ -57,8 +57,8 @@ cam = executable('cam', cam_sources,\n libcamera_public,\n libdrm,\n libevent,\n+ libjpeg,\n libsdl2,\n- libsdl2_image,\n libyaml,\n ],\n cpp_args : cam_cpp_args,\ndiff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp\nindex f8e3e95d..19fdfd6d 100644\n--- a/src/cam/sdl_sink.cpp\n+++ b/src/cam/sdl_sink.cpp\n@@ -21,7 +21,7 @@\n \n #include \"event_loop.h\"\n #include \"image.h\"\n-#ifdef HAVE_SDL_IMAGE\n+#ifdef HAVE_LIBJPEG\n #include \"sdl_texture_mjpg.h\"\n #endif\n #include \"sdl_texture_yuyv.h\"\n@@ -62,7 +62,7 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config)\n \trect_.h = cfg.size.height;\n \n \tswitch (cfg.pixelFormat) {\n-#ifdef HAVE_SDL_IMAGE\n+#ifdef HAVE_LIBJPEG\n \tcase libcamera::formats::MJPEG:\n \t\ttexture_ = std::make_unique<SDLTextureMJPG>(rect_);\n \t\tbreak;\ndiff --git a/src/cam/sdl_texture_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp\nindex 69e99ad3..a064e6e5 100644\n--- a/src/cam/sdl_texture_mjpg.cpp\n+++ b/src/cam/sdl_texture_mjpg.cpp\n@@ -7,19 +7,70 @@\n \n #include \"sdl_texture_mjpg.h\"\n \n-#include <SDL2/SDL_image.h>\n+#include <iostream>\n+#include <setjmp.h>\n+\n+#include <jpeglib.h>\n \n using namespace libcamera;\n \n SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect)\n-\t: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, 0)\n+\t: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, rect.w * 3),\n+\t rgb_(std::make_unique<unsigned char[]>(pitch_ * rect.h))\n+{\n+}\n+\n+struct error_mgr {\n+\tstruct jpeg_error_mgr errmgr;\n+\tjmp_buf escape;\n+};\n+\n+static void error_exit(j_common_ptr cinfo)\n+{\n+\tstruct error_mgr *err = (struct error_mgr *)cinfo->err;\n+\tlongjmp(err->escape, 1);\n+}\n+\n+static void output_no_message(j_common_ptr cinfo)\n+{\n+\t(void)cinfo;\n+}\n+\n+void SDLTextureMJPG::decompress(const unsigned char *jpeg,\n+\t\t\t\tunsigned long jpeg_size)\n {\n+\tstruct error_mgr jerr;\n+\tstruct jpeg_decompress_struct cinfo;\n+\tcinfo.err = jpeg_std_error(&jerr.errmgr);\n+\tjerr.errmgr.error_exit = error_exit;\n+\tjerr.errmgr.output_message = output_no_message;\n+\tif (setjmp(jerr.escape)) {\n+\t\t/* libjpeg found an error */\n+\t\tjpeg_destroy_decompress(&cinfo);\n+\t\tstd::cerr << \"JPEG decompression error\" << std::endl;\n+\t\treturn;\n+\t}\n+\n+\tjpeg_create_decompress(&cinfo);\n+\n+\tjpeg_mem_src(&cinfo, jpeg, jpeg_size);\n+\n+\tjpeg_read_header(&cinfo, TRUE);\n+\n+\tjpeg_start_decompress(&cinfo);\n+\n+\tfor (int i = 0; cinfo.output_scanline < cinfo.output_height; ++i) {\n+\t\tJSAMPROW rowptr = rgb_.get() + i * pitch_;\n+\t\tjpeg_read_scanlines(&cinfo, &rowptr, 1);\n+\t}\n+\n+\tjpeg_finish_decompress(&cinfo);\n+\n+\tjpeg_destroy_decompress(&cinfo);\n }\n \n void SDLTextureMJPG::update(const Span<uint8_t> &data)\n {\n-\tSDL_RWops *bufferStream = SDL_RWFromMem(data.data(), data.size());\n-\tSDL_Surface *frame = IMG_Load_RW(bufferStream, 0);\n-\tSDL_UpdateTexture(ptr_, nullptr, frame->pixels, frame->pitch);\n-\tSDL_FreeSurface(frame);\n+\tdecompress(data.data(), data.size());\n+\tSDL_UpdateTexture(ptr_, nullptr, rgb_.get(), pitch_);\n }\ndiff --git a/src/cam/sdl_texture_mjpg.h b/src/cam/sdl_texture_mjpg.h\nindex b103f801..c68b03b0 100644\n--- a/src/cam/sdl_texture_mjpg.h\n+++ b/src/cam/sdl_texture_mjpg.h\n@@ -13,5 +13,11 @@ class SDLTextureMJPG : public SDLTexture\n {\n public:\n \tSDLTextureMJPG(const SDL_Rect &rect);\n+\n \tvoid update(const libcamera::Span<uint8_t> &data) override;\n+\n+private:\n+\tvoid decompress(const unsigned char *jpeg, unsigned long jpeg_size);\n+\n+\tstd::unique_ptr<unsigned char[]> rgb_;\n };\n", "prefixes": [ "libcamera-devel", "v2" ] }