@@ -33,6 +33,7 @@ if libdrm.found()
endif
libsdl2 = dependency('SDL2', required : false)
+libsdl2_image = dependency('SDL2_image', required : false)
if libsdl2.found()
cam_cpp_args += ['-DHAVE_SDL']
@@ -41,6 +42,13 @@ if libsdl2.found()
'sdl_texture.cpp',
'sdl_texture_yuyv.cpp'
])
+
+ if libsdl2_image.found()
+ cam_cpp_args += ['-DHAVE_SDL_IMAGE']
+ cam_sources += files([
+ 'sdl_texture_mjpg.cpp'
+ ])
+ endif
endif
cam = executable('cam', cam_sources,
@@ -50,6 +58,7 @@ cam = executable('cam', cam_sources,
libdrm,
libevent,
libsdl2,
+ libsdl2_image,
],
cpp_args : cam_cpp_args,
install : true)
@@ -21,6 +21,9 @@
#include "event_loop.h"
#include "image.h"
+#ifdef HAVE_SDL_IMAGE
+#include "sdl_texture_mjpg.h"
+#endif
#include "sdl_texture_yuyv.h"
using namespace libcamera;
@@ -59,6 +62,11 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config)
rect_.h = cfg.size.height;
switch (cfg.pixelFormat) {
+#ifdef HAVE_SDL_IMAGE
+ case libcamera::formats::MJPEG:
+ texture_ = std::make_unique<SDLTextureMJPG>(rect_);
+ break;
+#endif
case libcamera::formats::YUYV:
texture_ = std::make_unique<SDLTextureYUYV>(rect_);
break;
new file mode 100644
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2022, Ideas on Board Oy
+ *
+ * sdl_texture_mjpg.cpp - SDL Texture MJPG
+ */
+
+#include "sdl_texture_mjpg.h"
+
+#include <SDL2/SDL_image.h>
+
+using namespace libcamera;
+
+SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &sdlRect)
+ : SDLTexture(sdlRect, SDL_PIXELFORMAT_RGB24, 0)
+{
+}
+
+void SDLTextureMJPG::update(const Span<uint8_t> &data)
+{
+ SDL_RWops *bufferStream = SDL_RWFromMem(data.data(), data.size());
+ SDL_Surface *frame = IMG_Load_RW(bufferStream, 0);
+ SDL_UpdateTexture(ptr_, nullptr, frame->pixels, frame->pitch);
+ SDL_FreeSurface(frame);
+}
new file mode 100644
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2022, Ideas on Board Oy
+ *
+ * sdl_texture_mjpg.h - SDL Texture MJPG
+ */
+
+#pragma once
+
+#include "sdl_texture.h"
+
+class SDLTextureMJPG : public SDLTexture
+{
+public:
+ SDLTextureMJPG(const SDL_Rect &sdlRect);
+ void update(const libcamera::Span<uint8_t> &data) override;
+};