{"id":15801,"url":"https://patchwork.libcamera.org/api/patches/15801/?format=json","web_url":"https://patchwork.libcamera.org/patch/15801/","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":"<20220505151851.2421-3-ecurtin@redhat.com>","date":"2022-05-05T15:18:50","name":"[libcamera-devel,v8,3/4] cam: sdl_sink: Add SDL sink with initial YUYV support","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"7fc0ae5df4250a0317858aa2ad547a806e9eee38","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/15801/mbox/","series":[{"id":3095,"url":"https://patchwork.libcamera.org/api/series/3095/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3095","date":"2022-05-05T15:18:48","name":"[libcamera-devel,v8,1/4] cam: event_loop: Add timer events to event loop","version":8,"mbox":"https://patchwork.libcamera.org/series/3095/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15801/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15801/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 E76CBC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 May 2022 15:19:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 943956564C;\n\tThu,  5 May 2022 17:19:20 +0200 (CEST)","from us-smtp-delivery-74.mimecast.com\n\t(us-smtp-delivery-74.mimecast.com [170.10.133.74])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ADD7860424\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 May 2022 17:19:18 +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-656-Y_1DYaG_Mtmai2enAtdn3A-1; Thu, 05 May 2022 11:19:16 -0400","by mail-wr1-f72.google.com with SMTP id\n\to13-20020adfa10d000000b0020c6fa5a77cso1577313wro.23\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 05 May 2022 08:19:16 -0700 (PDT)","from localhost.localdomain\n\t([2001:bb6:9634:7100:33b0:c1b1:8875:4adb])\n\tby smtp.gmail.com with ESMTPSA id\n\tz6-20020a056000110600b0020ad05214d5sm1434819wrw.2.2022.05.05.08.19.13\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 05 May 2022 08:19:14 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1651763960;\n\tbh=XDNlXpuJP0v9ny+9VUZFDkUVY2ZMrZkRKjCRG+cakmw=;\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=eUpzUo/5/LWOy/a9YljxOSMGTpETqWT9WN1b5ysdRi0o9AiIPaEPPI5EKbtQNsO/8\n\tmSwpTy1yyvLsJxmTmmFNQvDj+fY+V8nhr+1W0QKDpenIxBkPklTQmRR27Zi1Dg1wsM\n\tx8sGfBZREAJBEaxLm3TWEWOF+8wDQ0o3fwHIHppxCgMwUhAFmG9swP3VPrFzF6Blyl\n\tlkoZMdDF3MqMXP4RVPrqhHo6cF8NDJSQejIzYCqJUo5/1TY/u1JkAPCUC9KCnweyYI\n\tAFpDx5D2WES++rvlAdQOgzIvNQNvzlsSwXwstzbpxPkL7WXmDaCIDFRdMpOVq0gdiP\n\t+qDU+1BthSY5w==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1651763957;\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=B9Ps2ABkfKYA90JWqdEc93XHx2W/OPs84CLEMF2jatc=;\n\tb=bjCT/aCb1F+FDj650Kw0+tqHG+Crl2Gq0qFYL2eqdcJrazexTY40/ZfdzUsKEd3EQ8Zzqr\n\tZcLZdhOf7VjduyaIeQlNOix7LPmNyFqavYwlEdzNMXAOfZ6ZiAWBO8gDcGF5J/if/j1hYH\n\tLac/gDzScnVqJkiLT9og/GmsZS+VQw8="],"Authentication-Results":["lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"bjCT/aCb\"; \n\tdkim-atps=neutral","relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"],"X-MC-Unique":"Y_1DYaG_Mtmai2enAtdn3A-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=B9Ps2ABkfKYA90JWqdEc93XHx2W/OPs84CLEMF2jatc=;\n\tb=KwUGE4mLfpi0NCIlx+O83zuK4Dqx5UmUr5d6Jzk6t/xzyZ1+wHtOGzpMTtqQrz1fum\n\thV3zK16TTdxujzbadSrHPY/Bk2FVvAWLFV0P0hLvXo14YfUEtc5tZdnFDsLU/+qQjjR2\n\tol/JzmIP87+0aD51GJWdTXuEc+z/0z6S01zBsUSuIiT5UZ/L7BB4ecQ9KN2LXuFyCpLs\n\t40YHFIkTEZ5qnL5z/AI2kbNnI/mjhvxBBu9FEIxQ0F4VWTN3ZhyeTGBnLbHvFcvNZ2GG\n\tmk5iHojinwGMgt44o9zn78cgfGtNNVVIlXKK9hpjw3iPATfD0DfeTk4GGCFcR1VB3gys\n\tDWPQ==","X-Gm-Message-State":"AOAM533VqlMS3MsVXhi/H8IbQ1bgtDavCrGxosDn278tbtXqocZ1L0wS\n\tnd9egSzst9XiuaHhQA8Ww6pWZTqNEpIO8YzQOqoSs9X7H6JwXACthBxyFpuY8VvQGGLMVaiwTuS\n\tpYa/92ZRh843NkNvq0hM1WIwFF+qXI9jgxycxeYLNENvPxI9oK/CReEnc91Sugn1WCaoCGoHRI6\n\talqSaxNVRd","X-Received":["by 2002:a7b:c74f:0:b0:394:1ce3:cc42 with SMTP id\n\tw15-20020a7bc74f000000b003941ce3cc42mr5374624wmk.153.1651763954819; \n\tThu, 05 May 2022 08:19:14 -0700 (PDT)","by 2002:a7b:c74f:0:b0:394:1ce3:cc42 with SMTP id\n\tw15-20020a7bc74f000000b003941ce3cc42mr5374579wmk.153.1651763954381; \n\tThu, 05 May 2022 08:19:14 -0700 (PDT)"],"X-Google-Smtp-Source":"ABdhPJyMPHDLg7erjUZAPisQSYmQBbwM08Wf3rDrCHXN5enrDN+5atmF9sYQWK6tYSEcQbEDtgRdYQ==","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  5 May 2022 16:18:50 +0100","Message-Id":"<20220505151851.2421-3-ecurtin@redhat.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220505151851.2421-1-ecurtin@redhat.com>","References":"<20220505151851.2421-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 v8 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>\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         | 192 +++++++++++++++++++++++++++++++++++\n src/cam/sdl_sink.h           |  48 +++++++++\n src/cam/sdl_texture.cpp      |  32 ++++++\n src/cam/sdl_texture.h        |  23 +++++\n src/cam/sdl_texture_yuyv.cpp |  13 +++\n src/cam/sdl_texture_yuyv.h   |  10 ++\n 10 files changed, 343 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..71e6bd60 100644\n--- a/src/cam/camera_session.cpp\n+++ b/src/cam/camera_session.cpp\n@@ -19,6 +19,9 @@\n #ifdef HAVE_KMS\n #include \"kms_sink.h\"\n #endif\n+#ifdef HAVE_SDL\n+#include \"sdl_sink.h\"\n+#endif\n #include \"main.h\"\n #include \"stream_options.h\"\n \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..fd3108b0 100644\n--- a/src/cam/main.cpp\n+++ b/src/cam/main.cpp\n@@ -137,6 +137,10 @@ int CamApp::parseOptions(int argc, char *argv[])\n \t\t\t \"Display viewfinder through DRM/KMS on specified connector\",\n \t\t\t \"display\", ArgumentOptional, \"connector\", false,\n \t\t\t OptCamera);\n+#endif\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(OptFile, OptionString,\n \t\t\t \"Write captured frames to disk\\n\"\ndiff --git a/src/cam/main.h b/src/cam/main.h\nindex 62f7bbc9..2b285808 100644\n--- a/src/cam/main.h\n+++ b/src/cam/main.h\n@@ -18,6 +18,7 @@ enum {\n \tOptListProperties = 'p',\n \tOptMonitor = 'm',\n \tOptStream = 's',\n+\tOptSDL = 'S',\n \tOptListControls = 256,\n \tOptStrictFormats = 257,\n \tOptMetadata = 258,\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 5bab8c9e..3032730b 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -32,11 +32,23 @@ 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+                      libsdl2,\n                       libevent,\n                   ],\n                   cpp_args : cam_cpp_args,\ndiff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp\nnew file mode 100644\nindex 00000000..6fbeaf56\n--- /dev/null\n+++ b/src/cam/sdl_sink.cpp\n@@ -0,0 +1,192 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * sdl_sink.cpp - 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 \"sdl_texture_yuyv.h\"\n+\n+#include \"event_loop.h\"\n+#include \"image.h\"\n+\n+using namespace libcamera;\n+\n+SDLSink::SDLSink()\n+\t: sdlWindow_(nullptr), sdlRenderer_(nullptr), sdlRect_({}),\n+\t  sdlInit_(false)\n+{\n+}\n+\n+SDLSink::~SDLSink()\n+{\n+\tstop();\n+}\n+\n+int SDLSink::configure(const libcamera::CameraConfiguration &config)\n+{\n+\tint 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+\tsdlRect_.w = cfg.size.width;\n+\tsdlRect_.h = cfg.size.height;\n+\n+\tswitch (cfg.pixelFormat) {\n+\tcase libcamera::formats::YUYV:\n+\t\tsdlTexture_ = std::make_unique<SDLTextureYUYV>(sdlRect_);\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+\tsdlInit_ = true;\n+\tsdlWindow_ = SDL_CreateWindow(\"\", SDL_WINDOWPOS_UNDEFINED,\n+\t\t\t\t      SDL_WINDOWPOS_UNDEFINED, sdlRect_.w,\n+\t\t\t\t      sdlRect_.h,\n+\t\t\t\t      SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);\n+\tif (!sdlWindow_) {\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+\tsdlRenderer_ = SDL_CreateRenderer(sdlWindow_, -1, 0);\n+\tif (!sdlRenderer_) {\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(sdlRenderer_, sdlRect_.w, sdlRect_.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 = sdlTexture_->create(sdlRenderer_);\n+\tif (ret) {\n+\t\treturn ret;\n+\t}\n+\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 (sdlTexture_) {\n+\t\tsdlTexture_->destroy();\n+\t\tsdlTexture_ = nullptr;\n+\t}\n+\n+\tif (sdlRenderer_) {\n+\t\tSDL_DestroyRenderer(sdlRenderer_);\n+\t\tsdlRenderer_ = nullptr;\n+\t}\n+\n+\tif (sdlWindow_) {\n+\t\tSDL_DestroyWindow(sdlWindow_);\n+\t\tsdlWindow_ = nullptr;\n+\t}\n+\n+\tif (sdlInit_) {\n+\t\tSDL_Quit();\n+\t\tsdlInit_ = 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+\tfor (unsigned int i = 0; i < buffer->planes().size(); ++i) {\n+\t\tconst FrameMetadata::Plane &meta =\n+\t\t\tbuffer->metadata().planes()[i];\n+\n+\t\tSpan<uint8_t> data = image->data(i);\n+\t\tif (meta.bytesused > data.size())\n+\t\t\tstd::cerr << \"payload size \" << meta.bytesused\n+\t\t\t\t  << \" larger than plane size \" << data.size()\n+\t\t\t\t  << std::endl;\n+\n+\t\tsdlTexture_->update(data);\n+\t}\n+\n+\tSDL_RenderClear(sdlRenderer_);\n+\tSDL_RenderCopy(sdlRenderer_, sdlTexture_->ptr_, nullptr, nullptr);\n+\tSDL_RenderPresent(sdlRenderer_);\n+}\ndiff --git a/src/cam/sdl_sink.h b/src/cam/sdl_sink.h\nnew file mode 100644\nindex 00000000..37dd9f7e\n--- /dev/null\n+++ b/src/cam/sdl_sink.h\n@@ -0,0 +1,48 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * sdl_sink.h - SDL Sink\n+ */\n+\n+#pragma once\n+\n+#include <map>\n+#include <memory>\n+#include <string>\n+\n+#include <libcamera/stream.h>\n+\n+#include <SDL2/SDL.h>\n+\n+#include \"frame_sink.h\"\n+#include \"sdl_texture.h\"\n+\n+class Image;\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> sdlTexture_;\n+\n+\tSDL_Window *sdlWindow_;\n+\tSDL_Renderer *sdlRenderer_;\n+\tSDL_Rect sdlRect_;\n+\tSDL_PixelFormatEnum pixelFormat_;\n+\tbool sdlInit_;\n+};\ndiff --git a/src/cam/sdl_texture.cpp b/src/cam/sdl_texture.cpp\nnew file mode 100644\nindex 00000000..b39080c9\n--- /dev/null\n+++ b/src/cam/sdl_texture.cpp\n@@ -0,0 +1,32 @@\n+#include \"sdl_texture.h\"\n+\n+#include <iostream>\n+\n+SDLTexture::SDLTexture(const SDL_Rect &sdlRect, SDL_PixelFormatEnum pixelFormat,\n+\t\t       const int pitch)\n+\t: sdlRect_(sdlRect), pixelFormat_(pixelFormat), pitch_(pitch)\n+{\n+}\n+\n+SDLTexture::~SDLTexture()\n+{\n+}\n+\n+int SDLTexture::create(SDL_Renderer *sdlRenderer_)\n+{\n+\tptr_ = SDL_CreateTexture(sdlRenderer_, pixelFormat_,\n+\t\t\t\t SDL_TEXTUREACCESS_STREAMING, sdlRect_.w,\n+\t\t\t\t sdlRect_.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+}\n+\n+void SDLTexture::destroy()\n+{\n+\tSDL_DestroyTexture(ptr_);\n+}\ndiff --git a/src/cam/sdl_texture.h b/src/cam/sdl_texture.h\nnew file mode 100644\nindex 00000000..f9525f7f\n--- /dev/null\n+++ b/src/cam/sdl_texture.h\n@@ -0,0 +1,23 @@\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 &sdlRect, SDL_PixelFormatEnum pixelFormat,\n+\t\t   const int pitch);\n+\tvirtual ~SDLTexture();\n+\tint create(SDL_Renderer *sdlRenderer_);\n+\tvoid destroy();\n+\tvirtual void update(const libcamera::Span<uint8_t> &data) = 0;\n+\n+\tSDL_Texture *ptr_;\n+\n+protected:\n+\tconst SDL_Rect &sdlRect_;\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..cf519a5d\n--- /dev/null\n+++ b/src/cam/sdl_texture_yuyv.cpp\n@@ -0,0 +1,13 @@\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_, &sdlRect_, 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..ad70f14f\n--- /dev/null\n+++ b/src/cam/sdl_texture_yuyv.h\n@@ -0,0 +1,10 @@\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","v8","3/4"]}