From 11554a259f4e8df3cc2ddce0217d35fd7797cfc5 Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Fri, 20 May 2022 20:01:05 +0100 Subject: 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 Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Tested-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- src/cam/sdl_texture.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/cam/sdl_texture.cpp (limited to 'src/cam/sdl_texture.cpp') diff --git a/src/cam/sdl_texture.cpp b/src/cam/sdl_texture.cpp new file mode 100644 index 00000000..2ca2add2 --- /dev/null +++ b/src/cam/sdl_texture.cpp @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Ideas on Board Oy + * + * sdl_texture.cpp - SDL Texture + */ + +#include "sdl_texture.h" + +#include + +SDLTexture::SDLTexture(const SDL_Rect &rect, SDL_PixelFormatEnum pixelFormat, + const int pitch) + : ptr_(nullptr), rect_(rect), pixelFormat_(pixelFormat), pitch_(pitch) +{ +} + +SDLTexture::~SDLTexture() +{ + if (ptr_) + SDL_DestroyTexture(ptr_); +} + +int SDLTexture::create(SDL_Renderer *renderer) +{ + ptr_ = SDL_CreateTexture(renderer, pixelFormat_, + SDL_TEXTUREACCESS_STREAMING, rect_.w, + rect_.h); + if (!ptr_) { + std::cerr << "Failed to create SDL texture: " << SDL_GetError() + << std::endl; + return -ENOMEM; + } + + return 0; +} -- cgit v1.2.1