cam: sdl_sink: Add MJPG support to SDL sink
So we have at least two supported capturing pixel formats (although many possible output pixel formats thanks to SDL conversion). MJPG support only built in if SDL2_image is available, provides decompression. 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>
This commit is contained in:
committed by
Laurent Pinchart
parent
11554a259f
commit
153b468930
@@ -25,6 +25,7 @@ cam_cpp_args = []
|
||||
|
||||
libdrm = dependency('libdrm', required : false)
|
||||
libsdl2 = dependency('SDL2', required : false)
|
||||
libsdl2_image = dependency('SDL2_image', required : false)
|
||||
|
||||
if libdrm.found()
|
||||
cam_cpp_args += [ '-DHAVE_KMS' ]
|
||||
@@ -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,
|
||||
libyaml,
|
||||
],
|
||||
cpp_args : cam_cpp_args,
|
||||
|
||||
@@ -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;
|
||||
|
||||
25
src/cam/sdl_texture_mjpg.cpp
Normal file
25
src/cam/sdl_texture_mjpg.cpp
Normal file
@@ -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 &rect)
|
||||
: SDLTexture(rect, 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);
|
||||
}
|
||||
17
src/cam/sdl_texture_mjpg.h
Normal file
17
src/cam/sdl_texture_mjpg.h
Normal file
@@ -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 &rect);
|
||||
void update(const libcamera::Span<uint8_t> &data) override;
|
||||
};
|
||||
Reference in New Issue
Block a user