{"id":15998,"url":"https://patchwork.libcamera.org/api/patches/15998/?format=json","web_url":"https://patchwork.libcamera.org/patch/15998/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20220520190106.425386-4-ecurtin@redhat.com>","date":"2022-05-20T19:01:05","name":"[libcamera-devel,v9,3/4] cam: sdl_sink: Add SDL sink with initial YUYV support","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"bbded96fed5dfd7ecff44d722cbd796e8402b5f1","submitter":{"id":101,"url":"https://patchwork.libcamera.org/api/people/101/?format=json","name":"Eric Curtin","email":"ecurtin@redhat.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15998/mbox/","series":[{"id":3132,"url":"https://patchwork.libcamera.org/api/series/3132/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3132","date":"2022-05-20T19:01:02","name":"Add SDL Sink","version":9,"mbox":"https://patchwork.libcamera.org/series/3132/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15998/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15998/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 576C0C0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 20 May 2022 19:02:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 09A776566C;\n\tFri, 20 May 2022 21:02:12 +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 9F8A16566C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 May 2022 21:02:09 +0200 (CEST)","from mail-wr1-f72.google.com (mail-wr1-f72.google.com\n\t[209.85.221.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-433-bMkMGZtXO06QLN4hmsaPkA-1; Fri, 20 May 2022 15:02:07 -0400","by mail-wr1-f72.google.com with SMTP id\n\tl6-20020adfe586000000b0020d0ff79cecso2854802wrm.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 20 May 2022 12:02:07 -0700 (PDT)","from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tu30-20020adfa19e000000b0020d10a249eesm3337016wru.13.2022.05.20.12.02.03\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 20 May 2022 12:02:04 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653073332;\n\tbh=kuOMBE990UyKDL26DhGS/lF5uPAVQU7mbYEs+z1+2Io=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=ltsx9wb34Byc37FbGWVj5ZAbMc3kkpwg4daICah3iQbI80o2OuCUk2RmwRNvS4kCH\n\tWWmrdQd40zEYV6pOcC5/no6NYb1aRIvVEYsJ2rmC8goAdB5KZyAQJbO23q42hwFfvj\n\tqqx0Zsg7zQcP3nhyYx8/91AtgvQqmaxsxCiKsjxDyen+IZHmPRJs5aWxBWT9eepey8\n\tTqL0FZ0wY+uRz1gDXB73KuUmUgwS25pSCdLelRkYruzBoDDcd1lRVRH0y/mreMedZe\n\tn8v4RaeszUOHzT7A6JfWZQ2UD9hv5T8ZVZRcN7ibh+ALoKCpjP2R7apYg9KXT9FthO\n\t5o7yBmbSbMqjw==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1653073328;\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\tin-reply-to:in-reply-to:references:references;\n\tbh=ipc2oFQ8lFHTrRTk3ZxYK5iWN39zwTKL23ESMd260vI=;\n\tb=QVGFpqmRREH1k7AI45KaS54AdlcxvXyB4a3+tLmqim0EljAOsAnyKQAVecrCsiQMVJ36jp\n\te3/dqtIK4D96EUxbaxUohdznBd8wTM52J5WTPduyC2RMM8o1MMZBlnSG1/5zEfi0uv+e1O\n\tLovxIOJRSlsMvIRzurCLYJInMO1qOxw="],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"QVGFpqmR\"; \n\tdkim-atps=neutral","relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"],"X-MC-Unique":"bMkMGZtXO06QLN4hmsaPkA-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:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=ipc2oFQ8lFHTrRTk3ZxYK5iWN39zwTKL23ESMd260vI=;\n\tb=rqhvM1DKtYJk8Nl3uf+GsGaByQfeDRAfc4qqXt7Xt/I3/J9l65+DpgQ4Ggg2HrfxPx\n\thAmNJkComLr5lb9bb5jM0a1VvyAsZQvQHocuwiAINLn9gOCn+7oZV3nWVUNd20rr2kD3\n\t6ybY6RHlE6GTr5oAi5lOW4WBY1xNdzFJd00UdWLMwbtwuj+X0tPIvHnLGp3DxtbXitdP\n\tjuHj92NMPcijHsNyjBW1558OqjGiOiE6Ynx4t0h3CUQ2C25+kyOYtwNwSy6pb03zXHg+\n\tLOSfn+jqp5nnkw1HHfPwJS6rAZ31MakRxV50Q8GwYYBj4NrYYiJdX8+HQ90xfQVvp2tO\n\tfRLA==","X-Gm-Message-State":"AOAM532zlcezHmGkqaFyYpL9QE4CTWnqLg3mV3sMEdsnFQO12j+ast5g\n\tUOq5iJ9V8KV4S6x0qCNtTQ+HVvH+bInhv7fC0isCrvrJv7WWnJbOjFsgngcdRjJR+/6mWb5m13J\n\tjD804+3EdSyRLBoO7CXjAqOO6aWVM1us/KrXmKXinWGwuvCGM+xDb6dvgAGuLh6v3rcanGM4Ej0\n\tVABMYeqDyi","X-Received":["by 2002:a05:600c:3caa:b0:394:8fb8:716 with SMTP id\n\tbg42-20020a05600c3caa00b003948fb80716mr9800614wmb.105.1653073325556; \n\tFri, 20 May 2022 12:02:05 -0700 (PDT)","by 2002:a05:600c:3caa:b0:394:8fb8:716 with SMTP id\n\tbg42-20020a05600c3caa00b003948fb80716mr9800587wmb.105.1653073325112; \n\tFri, 20 May 2022 12:02:05 -0700 (PDT)"],"X-Google-Smtp-Source":"ABdhPJy4+uwfgR5k1+1jo/NaHdvdkrr0Ii8GThSo07Kzzd9tzddwEzkjTmxpZhWbO/VGwNmxwfbpMA==","To":"libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com, \n\tkieran.bingham@ideasonboard.com, jacopo@jmondi.org, javierm@redhat.com","Date":"Fri, 20 May 2022 20:01:05 +0100","Message-Id":"<20220520190106.425386-4-ecurtin@redhat.com>","X-Mailer":"git-send-email 2.35.3","In-Reply-To":"<20220520190106.425386-1-ecurtin@redhat.com>","References":"<20220520190106.425386-1-ecurtin@redhat.com>","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 v9 3/4] cam: sdl_sink: Add SDL sink with\n\tinitial YUYV support","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This adds more portability to existing cam sinks. You can pass a\nYUYV camera buffer and SDL will handle the pixel buffer conversion\nto the display. This allows cam reference implementation to display\nimages on VMs, Mac M1, Raspberry Pi, etc. This also enables cam\nreference implementation, to run as a desktop application in Wayland or\nX11. SDL also has support for Android and ChromeOS which has not been\ntested. Also tested on simpledrm Raspberry Pi 4 framebuffer\nsuccessfully where existing kms sink did not work. Can also be used as\nkmsdrm sink. Only supports one camera stream at present.\n\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/cam/camera_session.cpp   |   8 ++\n src/cam/main.cpp             |   4 +\n src/cam/main.h               |   1 +\n src/cam/meson.build          |  12 +++\n src/cam/sdl_sink.cpp         | 194 +++++++++++++++++++++++++++++++++++\n src/cam/sdl_sink.h           |  49 +++++++++\n src/cam/sdl_texture.cpp      |  37 +++++++\n src/cam/sdl_texture.h        |  29 ++++++\n src/cam/sdl_texture_yuyv.cpp |  20 ++++\n src/cam/sdl_texture_yuyv.h   |  17 +++\n 10 files changed, 371 insertions(+)\n create mode 100644 src/cam/sdl_sink.cpp\n create mode 100644 src/cam/sdl_sink.h\n create mode 100644 src/cam/sdl_texture.cpp\n create mode 100644 src/cam/sdl_texture.h\n create mode 100644 src/cam/sdl_texture_yuyv.cpp\n create mode 100644 src/cam/sdl_texture_yuyv.h","diff":"diff --git a/src/cam/camera_session.cpp b/src/cam/camera_session.cpp\nindex efffafbf..336ae471 100644\n--- a/src/cam/camera_session.cpp\n+++ b/src/cam/camera_session.cpp\n@@ -20,6 +20,9 @@\n #include \"kms_sink.h\"\n #endif\n #include \"main.h\"\n+#ifdef HAVE_SDL\n+#include \"sdl_sink.h\"\n+#endif\n #include \"stream_options.h\"\n \n using namespace libcamera;\n@@ -186,6 +189,11 @@ int CameraSession::start()\n \t\tsink_ = std::make_unique<KMSSink>(options_[OptDisplay].toString());\n #endif\n \n+#ifdef HAVE_SDL\n+\tif (options_.isSet(OptSDL))\n+\t\tsink_ = std::make_unique<SDLSink>();\n+#endif\n+\n \tif (options_.isSet(OptFile)) {\n \t\tif (!options_[OptFile].toString().empty())\n \t\t\tsink_ = std::make_unique<FileSink>(streamNames_,\ndiff --git a/src/cam/main.cpp b/src/cam/main.cpp\nindex c7f664b9..962262a8 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -147,6 +147,10 @@ int CamApp::parseOptions(int argc, char *argv[])\n \t\t\t \"The default file name is 'frame-#.bin'.\",\n \t\t\t \"file\", ArgumentOptional, \"filename\", false,\n \t\t\t OptCamera);\n+#ifdef HAVE_SDL\n+\tparser.addOption(OptSDL, OptionNone, \"Display viewfinder through SDL\",\n+\t\t\t \"sdl\", ArgumentNone, \"\", false, OptCamera);\n+#endif\n \tparser.addOption(OptStream, &streamKeyValue,\n \t\t\t \"Set configuration of a camera stream\", \"stream\", true,\n \t\t\t OptCamera);\ndiff --git a/src/cam/main.h b/src/cam/main.h\nindex 62f7bbc9..507a184f 100644\n--- a/src/cam/main.h\n+++ b/src/cam/main.h\n@@ -17,6 +17,7 @@ enum {\n \tOptList = 'l',\n \tOptListProperties = 'p',\n \tOptMonitor = 'm',\n+\tOptSDL = 'S',\n \tOptStream = 's',\n \tOptListControls = 256,\n \tOptStrictFormats = 257,\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 5bab8c9e..7d714152 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -32,12 +32,24 @@ if libdrm.found()\n     ])\n endif\n \n+libsdl2 = dependency('SDL2', required : false)\n+\n+if libsdl2.found()\n+    cam_cpp_args += ['-DHAVE_SDL']\n+    cam_sources += files([\n+        'sdl_sink.cpp',\n+        'sdl_texture.cpp',\n+        'sdl_texture_yuyv.cpp'\n+    ])\n+endif\n+\n cam  = executable('cam', cam_sources,\n                   dependencies : [\n                       libatomic,\n                       libcamera_public,\n                       libdrm,\n                       libevent,\n+                      libsdl2,\n                   ],\n                   cpp_args : cam_cpp_args,\n                   install : true)\ndiff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp\nnew file mode 100644\nindex 00000000..65430efb\n--- /dev/null\n+++ b/src/cam/sdl_sink.cpp\n@@ -0,0 +1,194 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_sink.h - SDL Sink\n+ */\n+\n+#include \"sdl_sink.h\"\n+\n+#include <assert.h>\n+#include <fcntl.h>\n+#include <iomanip>\n+#include <iostream>\n+#include <signal.h>\n+#include <sstream>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <libcamera/camera.h>\n+#include <libcamera/formats.h>\n+\n+#include \"event_loop.h\"\n+#include \"image.h\"\n+#include \"sdl_texture_yuyv.h\"\n+\n+using namespace libcamera;\n+\n+using namespace std::chrono_literals;\n+\n+SDLSink::SDLSink()\n+\t: window_(nullptr), renderer_(nullptr), rect_({}),\n+\t  init_(false)\n+{\n+}\n+\n+SDLSink::~SDLSink()\n+{\n+\tstop();\n+}\n+\n+int SDLSink::configure(const libcamera::CameraConfiguration &config)\n+{\n+\tconst int ret = FrameSink::configure(config);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tif (config.size() > 1) {\n+\t\tstd::cerr\n+\t\t\t<< \"SDL sink only supports one camera stream at present, streaming first camera stream\"\n+\t\t\t<< std::endl;\n+\t} else if (config.empty()) {\n+\t\tstd::cerr << \"Require at least one camera stream to process\"\n+\t\t\t  << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst libcamera::StreamConfiguration &cfg = config.at(0);\n+\trect_.w = cfg.size.width;\n+\trect_.h = cfg.size.height;\n+\n+\tswitch (cfg.pixelFormat) {\n+\tcase libcamera::formats::YUYV:\n+\t\ttexture_ = std::make_unique<SDLTextureYUYV>(rect_);\n+\t\tbreak;\n+\tdefault:\n+\t\tstd::cerr << \"Unsupported pixel format \"\n+\t\t\t  << cfg.pixelFormat.toString() << std::endl;\n+\t\treturn -EINVAL;\n+\t};\n+\n+\treturn 0;\n+}\n+\n+int SDLSink::start()\n+{\n+\tint ret = SDL_Init(SDL_INIT_VIDEO);\n+\tif (ret) {\n+\t\tstd::cerr << \"Failed to initialize SDL: \" << SDL_GetError()\n+\t\t\t  << std::endl;\n+\t\treturn ret;\n+\t}\n+\n+\tinit_ = true;\n+\twindow_ = SDL_CreateWindow(\"\", SDL_WINDOWPOS_UNDEFINED,\n+\t\t\t\t   SDL_WINDOWPOS_UNDEFINED, rect_.w,\n+\t\t\t\t   rect_.h,\n+\t\t\t\t   SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);\n+\tif (!window_) {\n+\t\tstd::cerr << \"Failed to create SDL window: \" << SDL_GetError()\n+\t\t\t  << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\trenderer_ = SDL_CreateRenderer(window_, -1, 0);\n+\tif (!renderer_) {\n+\t\tstd::cerr << \"Failed to create SDL renderer: \" << SDL_GetError()\n+\t\t\t  << std::endl;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tret = SDL_RenderSetLogicalSize(renderer_, rect_.w, rect_.h);\n+\tif (ret) { /* Not critical to set, don't return in this case, set for scaling purposes */\n+\t\tstd::cerr << \"Failed to set SDL render logical size: \"\n+\t\t\t  << SDL_GetError() << std::endl;\n+\t}\n+\n+\tret = texture_->create(renderer_);\n+\tif (ret) {\n+\t\treturn ret;\n+\t}\n+\n+\t/* \\todo Make the event cancellable to support stop/start cycles. */\n+\tEventLoop::instance()->addTimerEvent(\n+\t\t10ms, std::bind(&SDLSink::processSDLEvents, this));\n+\n+\treturn 0;\n+}\n+\n+int SDLSink::stop()\n+{\n+\tif (texture_) {\n+\t\ttexture_.reset();\n+\t}\n+\n+\tif (renderer_) {\n+\t\tSDL_DestroyRenderer(renderer_);\n+\t\trenderer_ = nullptr;\n+\t}\n+\n+\tif (window_) {\n+\t\tSDL_DestroyWindow(window_);\n+\t\twindow_ = nullptr;\n+\t}\n+\n+\tif (init_) {\n+\t\tSDL_Quit();\n+\t\tinit_ = false;\n+\t}\n+\n+\treturn FrameSink::stop();\n+}\n+\n+void SDLSink::mapBuffer(FrameBuffer *buffer)\n+{\n+\tstd::unique_ptr<Image> image =\n+\t\tImage::fromFrameBuffer(buffer, Image::MapMode::ReadOnly);\n+\tassert(image != nullptr);\n+\n+\tmappedBuffers_[buffer] = std::move(image);\n+}\n+\n+bool SDLSink::processRequest(Request *request)\n+{\n+\tfor (auto [stream, buffer] : request->buffers()) {\n+\t\trenderBuffer(buffer);\n+\t\tbreak; /* to be expanded to launch SDL window per buffer */\n+\t}\n+\n+\treturn true;\n+}\n+\n+/*\n+ * Process SDL events, required for things like window resize and quit button\n+ */\n+void SDLSink::processSDLEvents()\n+{\n+\tfor (SDL_Event e; SDL_PollEvent(&e);) {\n+\t\tif (e.type == SDL_QUIT) {\n+\t\t\t/* Click close icon then quit */\n+\t\t\tEventLoop::instance()->exit(0);\n+\t\t}\n+\t}\n+}\n+\n+void SDLSink::renderBuffer(FrameBuffer *buffer)\n+{\n+\tImage *image = mappedBuffers_[buffer].get();\n+\n+\t/* \\todo Implement support for multi-planar formats. */\n+\tconst FrameMetadata::Plane &meta =\n+\t\tbuffer->metadata().planes()[0];\n+\n+\tSpan<uint8_t> data = image->data(0);\n+\tif (meta.bytesused > data.size())\n+\t\tstd::cerr << \"payload size \" << meta.bytesused\n+\t\t\t  << \" larger than plane size \" << data.size()\n+\t\t\t  << std::endl;\n+\n+\ttexture_->update(data);\n+\n+\tSDL_RenderClear(renderer_);\n+\tSDL_RenderCopy(renderer_, texture_->get(), nullptr, nullptr);\n+\tSDL_RenderPresent(renderer_);\n+}\ndiff --git a/src/cam/sdl_sink.h b/src/cam/sdl_sink.h\nnew file mode 100644\nindex 00000000..83171cca\n--- /dev/null\n+++ b/src/cam/sdl_sink.h\n@@ -0,0 +1,49 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_sink.h - SDL Sink\n+ */\n+\n+#pragma once\n+\n+#include <map>\n+#include <memory>\n+\n+#include <libcamera/stream.h>\n+\n+#include <SDL2/SDL.h>\n+\n+#include \"frame_sink.h\"\n+\n+class Image;\n+class SDLTexture;\n+\n+class SDLSink : public FrameSink\n+{\n+public:\n+\tSDLSink();\n+\t~SDLSink();\n+\n+\tint configure(const libcamera::CameraConfiguration &config) override;\n+\tint start() override;\n+\tint stop() override;\n+\tvoid mapBuffer(libcamera::FrameBuffer *buffer) override;\n+\n+\tbool processRequest(libcamera::Request *request) override;\n+\n+private:\n+\tvoid renderBuffer(libcamera::FrameBuffer *buffer);\n+\tvoid processSDLEvents();\n+\n+\tstd::map<libcamera::FrameBuffer *, std::unique_ptr<Image>>\n+\t\tmappedBuffers_;\n+\n+\tstd::unique_ptr<SDLTexture> texture_;\n+\n+\tSDL_Window *window_;\n+\tSDL_Renderer *renderer_;\n+\tSDL_Rect rect_;\n+\tSDL_PixelFormatEnum pixelFormat_;\n+\tbool init_;\n+};\ndiff --git a/src/cam/sdl_texture.cpp b/src/cam/sdl_texture.cpp\nnew file mode 100644\nindex 00000000..ac355a97\n--- /dev/null\n+++ b/src/cam/sdl_texture.cpp\n@@ -0,0 +1,37 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_texture.cpp - SDL Texture\n+ */\n+\n+#include \"sdl_texture.h\"\n+\n+#include <iostream>\n+\n+SDLTexture::SDLTexture(const SDL_Rect &rect, SDL_PixelFormatEnum pixelFormat,\n+\t\t       const int pitch)\n+\t: ptr_(nullptr), rect_(rect), pixelFormat_(pixelFormat), pitch_(pitch)\n+{\n+}\n+\n+SDLTexture::~SDLTexture()\n+{\n+\tif (ptr_) {\n+\t\tSDL_DestroyTexture(ptr_);\n+\t}\n+}\n+\n+int SDLTexture::create(SDL_Renderer *renderer_)\n+{\n+\tptr_ = SDL_CreateTexture(renderer_, pixelFormat_,\n+\t\t\t\t SDL_TEXTUREACCESS_STREAMING, rect_.w,\n+\t\t\t\t rect_.h);\n+\tif (!ptr_) {\n+\t\tstd::cerr << \"Failed to create SDL texture: \" << SDL_GetError()\n+\t\t\t  << std::endl;\n+\t\treturn -ENOMEM;\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/src/cam/sdl_texture.h b/src/cam/sdl_texture.h\nnew file mode 100644\nindex 00000000..b04eece0\n--- /dev/null\n+++ b/src/cam/sdl_texture.h\n@@ -0,0 +1,29 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_texture.h - SDL Texture\n+ */\n+\n+#pragma once\n+\n+#include <SDL2/SDL.h>\n+\n+#include \"image.h\"\n+\n+class SDLTexture\n+{\n+public:\n+\tSDLTexture(const SDL_Rect &rect, SDL_PixelFormatEnum pixelFormat,\n+\t\t   const int pitch);\n+\tvirtual ~SDLTexture();\n+\tint create(SDL_Renderer *renderer_);\n+\tvirtual void update(const libcamera::Span<uint8_t> &data) = 0;\n+\tSDL_Texture *get() const { return ptr_; }\n+\n+protected:\n+\tSDL_Texture *ptr_;\n+\tconst SDL_Rect &rect_;\n+\tSDL_PixelFormatEnum pixelFormat_;\n+\tconst int pitch_;\n+};\ndiff --git a/src/cam/sdl_texture_yuyv.cpp b/src/cam/sdl_texture_yuyv.cpp\nnew file mode 100644\nindex 00000000..a219097b\n--- /dev/null\n+++ b/src/cam/sdl_texture_yuyv.cpp\n@@ -0,0 +1,20 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_texture_yuyv.cpp - SDL Texture YUYV\n+ */\n+\n+#include \"sdl_texture_yuyv.h\"\n+\n+using namespace libcamera;\n+\n+SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &sdlRect)\n+\t: SDLTexture(sdlRect, SDL_PIXELFORMAT_YUY2, 4 * ((sdlRect.w + 1) / 2))\n+{\n+}\n+\n+void SDLTextureYUYV::update(const Span<uint8_t> &data)\n+{\n+\tSDL_UpdateTexture(ptr_, &rect_, data.data(), pitch_);\n+}\ndiff --git a/src/cam/sdl_texture_yuyv.h b/src/cam/sdl_texture_yuyv.h\nnew file mode 100644\nindex 00000000..38c51c74\n--- /dev/null\n+++ b/src/cam/sdl_texture_yuyv.h\n@@ -0,0 +1,17 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * sdl_texture_yuyv.h - SDL Texture YUYV\n+ */\n+\n+#pragma once\n+\n+#include \"sdl_texture.h\"\n+\n+class SDLTextureYUYV : public SDLTexture\n+{\n+public:\n+\tSDLTextureYUYV(const SDL_Rect &sdlRect);\n+\tvoid update(const libcamera::Span<uint8_t> &data) override;\n+};\n","prefixes":["libcamera-devel","v9","3/4"]}