From patchwork Fri May 20 19:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 15999 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id AA5D6C0F2A for ; Fri, 20 May 2022 19:02:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72BF165673; Fri, 20 May 2022 21:02:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653073333; bh=JEZ17N5MMZQ2R9emqpby71KoEsu1ox4SILeP4cBF8VA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mFvs7ezk7mcNYyq4KzZwE5qqBbCSkNDlNjZ1mNCNn7hohUhXXCEZtTq+SxRyKhRp+ rW0xPdNM5O/Jq19dcv/BGFSu6DCsVAt0TLZi825TY9XNvDI2aIwm9Ez+Qy04r8jxKj zxqhh+U5rHNW3G+cqcGyP6PKXwVbe5Nvl3CaEVdQwLktHtnoBYxEs65MV3s+BLhDhQ G6h6HNuFr3Dd4KmBQDbM3TtdOxZ+E9aENh6tDpghEPYJAlybnWAqpDe0MyuitletMR 0rGRhZ4ioyqoWkgFS5xXUBdNmtRIq4wI91JbR0W2Mhylo+CfiSYK9VrYCgCLS7szoU Lqk+WOPzcwRQQ== Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C27A65670 for ; Fri, 20 May 2022 21:02:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="AGiHH8U8"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653073331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+SXzNYyNmAeGgcWQqAMwnTK/agL9lKQH3a0+73LkUpc=; b=AGiHH8U8doqrGnpNvhysrNolBG5Qb9Z064ZsxLPYpHUav/ZMVFnXwV3Cl0tCapJHSFRcfW htH6WjQwq9c3KZAhG8GicmE/yQIOp9Cow0OIx8h62hmSzjBUKrl//vej1vyeNjeE/WspBv y/juQG6MUU/tx2Dl8l7cAXw14bT2A60= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-52-8lnyKZfANMOuqtp0sVrcxg-1; Fri, 20 May 2022 15:02:09 -0400 X-MC-Unique: 8lnyKZfANMOuqtp0sVrcxg-1 Received: by mail-wm1-f70.google.com with SMTP id o11-20020a05600c510b00b003973d4d37d3so727592wms.9 for ; Fri, 20 May 2022 12:02:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+SXzNYyNmAeGgcWQqAMwnTK/agL9lKQH3a0+73LkUpc=; b=6d5U7mz6WvL+qGXQI5/FPplLF0etD8Us/L2A363tI0RCBJPi9GtzBt5XrZN4ct7inX VKychJXTvCMT1Vk/2RAv+LW7ZC+RitcQGIXICdZAXegQcQudIxYXs7DgK/SXz97vuLEO diFkyhL4kTU0TuSb6d7YoBOlBy8ONEnwUkWdj5oBCpTT7oRMmeiBjRGvgF8EHgl4jScR UBHXZ+zUqBBU51R0odfIf71oeeUCFzgGel0WznEkJAqocEO/6KarsPJjIQEcCg7jixBc fYfzu+KXiQtor0K3xL/NVzQTIdoCZnoMVTTXIMjZ0wTj96QYFNDmVj6O3i2KQLc8vb1e vN8g== X-Gm-Message-State: AOAM530IQN0UBnEcNhki07JMsnlvmyh7Yz2SRd3WoBIJFgUwhv5pPCDn 4W+B/wWloAf9h9rQpxueqOIDSa1cDArRu1dfi8gr0+h0iD+EuOxf+Z9fHymSrcQJ2uzuOihj13v J4pMgpjcuZ9Jymq4A2wQH8iR6bs8hB30QV501uy6QkE/b03xjNgoLoeTlpCT6n8WN83DRSwD9kg qu/lUxqDaL X-Received: by 2002:a5d:48ce:0:b0:20a:bb9b:62a3 with SMTP id p14-20020a5d48ce000000b0020abb9b62a3mr9490013wrs.307.1653073327182; Fri, 20 May 2022 12:02:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQBfeUH4ZYGBxWmWmcfJEszUSJlxO2rm+5ylqlEb19UMUoWG9rO1FWvf8BjSAY7v3e6Ml92w== X-Received: by 2002:a5d:48ce:0:b0:20a:bb9b:62a3 with SMTP id p14-20020a5d48ce000000b0020abb9b62a3mr9489987wrs.307.1653073326711; Fri, 20 May 2022 12:02:06 -0700 (PDT) Received: from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340]) by smtp.gmail.com with ESMTPSA id u30-20020adfa19e000000b0020d10a249eesm3337016wru.13.2022.05.20.12.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 12:02:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com, jacopo@jmondi.org, javierm@redhat.com Date: Fri, 20 May 2022 20:01:06 +0100 Message-Id: <20220520190106.425386-5-ecurtin@redhat.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220520190106.425386-1-ecurtin@redhat.com> References: <20220520190106.425386-1-ecurtin@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [libcamera-devel] [PATCH v9 4/4] cam: sdl_sink: Add MJPG support to SDL sink X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Eric Curtin via libcamera-devel From: Eric Curtin Reply-To: Eric Curtin Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Tested-by: Jacopo Mondi --- src/cam/meson.build | 9 +++++++++ src/cam/sdl_sink.cpp | 8 ++++++++ src/cam/sdl_texture_mjpg.cpp | 25 +++++++++++++++++++++++++ src/cam/sdl_texture_mjpg.h | 17 +++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/cam/sdl_texture_mjpg.cpp create mode 100644 src/cam/sdl_texture_mjpg.h diff --git a/src/cam/meson.build b/src/cam/meson.build index 7d714152..a3c776d3 100644 --- a/src/cam/meson.build +++ b/src/cam/meson.build @@ -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) diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index 65430efb..e0dd235a 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -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(rect_); + break; +#endif case libcamera::formats::YUYV: texture_ = std::make_unique(rect_); break; diff --git a/src/cam/sdl_texture_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp new file mode 100644 index 00000000..12f26c0b --- /dev/null +++ b/src/cam/sdl_texture_mjpg.cpp @@ -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 + +using namespace libcamera; + +SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &sdlRect) + : SDLTexture(sdlRect, SDL_PIXELFORMAT_RGB24, 0) +{ +} + +void SDLTextureMJPG::update(const Span &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); +} diff --git a/src/cam/sdl_texture_mjpg.h b/src/cam/sdl_texture_mjpg.h new file mode 100644 index 00000000..113ffb55 --- /dev/null +++ b/src/cam/sdl_texture_mjpg.h @@ -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 &data) override; +};