summaryrefslogtreecommitdiff
path: root/src/cam/sdl_sink.h
diff options
context:
space:
mode:
authorEric Curtin <ecurtin@redhat.com>2022-05-20 20:01:05 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-05-23 12:49:44 +0300
commit11554a259f4e8df3cc2ddce0217d35fd7797cfc5 (patch)
tree935bde6e6a369ee13a5814753c8b525a9ccb8306 /src/cam/sdl_sink.h
parenta5844adb7b6b564f77fb15ec0716ac85bcb1bc42 (diff)
cam: sdl_sink: Add SDL sink with initial YUYV support
This adds more portability to existing cam sinks. You can pass a YUYV camera buffer and SDL will handle the pixel buffer conversion to the display. This allows cam reference implementation to display images on VMs, Mac M1, Raspberry Pi, etc. This also enables cam reference implementation, to run as a desktop application in Wayland or X11. SDL also has support for Android and ChromeOS which has not been tested. Also tested on simpledrm Raspberry Pi 4 framebuffer successfully where existing kms sink did not work. Can also be used as kmsdrm sink. Only supports one camera stream at present. Signed-off-by: Eric Curtin <ecurtin@redhat.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Jacopo Mondi <jacopo@jmondi.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/cam/sdl_sink.h')
-rw-r--r--src/cam/sdl_sink.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/cam/sdl_sink.h b/src/cam/sdl_sink.h
new file mode 100644
index 00000000..6c19c663
--- /dev/null
+++ b/src/cam/sdl_sink.h
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2022, Ideas on Board Oy
+ *
+ * sdl_sink.h - SDL Sink
+ */
+
+#pragma once
+
+#include <map>
+#include <memory>
+
+#include <libcamera/stream.h>
+
+#include <SDL2/SDL.h>
+
+#include "frame_sink.h"
+
+class Image;
+class SDLTexture;
+
+class SDLSink : public FrameSink
+{
+public:
+ SDLSink();
+ ~SDLSink();
+
+ int configure(const libcamera::CameraConfiguration &config) override;
+ int start() override;
+ int stop() override;
+ void mapBuffer(libcamera::FrameBuffer *buffer) override;
+
+ bool processRequest(libcamera::Request *request) override;
+
+private:
+ void renderBuffer(libcamera::FrameBuffer *buffer);
+ void processSDLEvents();
+
+ std::map<libcamera::FrameBuffer *, std::unique_ptr<Image>>
+ mappedBuffers_;
+
+ std::unique_ptr<SDLTexture> texture_;
+
+ SDL_Window *window_;
+ SDL_Renderer *renderer_;
+ SDL_Rect rect_;
+ bool init_;
+};