From patchwork Thu May 5 15:18:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Curtin X-Patchwork-Id: 15802 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 AE136C3256 for ; Thu, 5 May 2022 15:19:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5E6E060424; Thu, 5 May 2022 17:19:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651763964; bh=D+P+IMGuJSzjIrxIpKf7YEsqyDJtPhyn1Yyzkm/vWvw=; 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=uI6ZtdDnROtaYycBS7RQI3gsQMz8mZMyDUvtQIV2pCO82tRqOX1dYDC+w7JPSO23o SA6vWp6IfQDBVGw9iQzUxQvu4haDzDZAZrEiZCFoZJXOOkwk/5ZwRonZLIdyWl7ikk tWm8dWGlGeQxntttYgxEk8VM7AgfaeeTpfelvxqH2sN6nBVx80N+Oxil/JkYUlWL7p aN5HTu65OkuahXAZnwjx+VQs7Q90NO9zTfVpTdY2vRXh5mTAAmADIeIv5fbcT+WbAi UB4wcTJwN5fW2sQ/MnI5EKr6hWtofQ8rMmMqxS6oTp6bz/0/cM9+kE/3z7+3yhdVTQ EqdYdF7HkDqhg== Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [170.10.133.74]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 14A2360424 for ; Thu, 5 May 2022 17:19:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="E1apAvv+"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651763962; 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=6eHuKn7G9MDNmHaezjG84YR7jDVwdOksX6s62gQFrUc=; b=E1apAvv+RVhtlk38dSUEPWxSISQEHH0hd86NyaEVm3lZnaWLhVQGfTeB12DxWbDHX7dGCS DKcKkn+x3MgUIJbWAxW05wuSb4PQWAFa3emx/fAd6/IRrcbck2pl3aYhOjqBeV4F19ywd2 9pZxijXArniZ5jTDWpJ/cv2HtYxHoKE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-76qiXz_kNHasdTyfK3l-wA-1; Thu, 05 May 2022 11:19:18 -0400 X-MC-Unique: 76qiXz_kNHasdTyfK3l-wA-1 Received: by mail-wm1-f69.google.com with SMTP id v191-20020a1cacc8000000b0038ce818d2efso1848840wme.1 for ; Thu, 05 May 2022 08:19:18 -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=6eHuKn7G9MDNmHaezjG84YR7jDVwdOksX6s62gQFrUc=; b=CAXXc8GfKSBDnccYNG5fxzjIjr63Z9HfTOuk7KgdUIbcMUCQ5gSaojuVI2xZpeldnL pmYELBdO23BxD7Nc65soW8HPSyjWuY65zdH4ckIHsBqOiAWfaGfcYmALulzq9+VpkGgp wSInxXn0/+CPm94CQAl1MstksLtvmeR8QiXiXeAt5tAzHkWifWjeAYXaNlGnrrBRHNcQ TIEFRsA6zacOW8WZo+udpj0LvXnDu/jtzsmHoSrFFr7VjUQhbWBYMI3v/m5Y7s4T2R2b 1l7JK1dWFtWMwwcbnHtqVUADOneGiv5quN/HXP89vbxkXXcMVO90capynt/WTUWe4rWH qaXw== X-Gm-Message-State: AOAM531/pfX9jZN2tdX+XEsjsLPoyWUjyOoZ6E1NtQczd1K353VTl9Pq 240TQS1QGnYPgiFBekhFnYwHgX1rqsmPhUo1I9R1FjAFW3XX9c5T+JqU+x9HUi+Sj4AxzYEXEI6 mRNTA3CW1lVMwk6oTZK8tTFfQZBFm/oevyoy0fNe83y+CPej2sAY9/9zwYAxu3UEB9uWCQC+6vW HkKOOaDdCt X-Received: by 2002:a7b:cc12:0:b0:37c:1ae:100a with SMTP id f18-20020a7bcc12000000b0037c01ae100amr5412228wmh.54.1651763956991; Thu, 05 May 2022 08:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytCO1a/TICuJe/OW6k4ypaM3ZW0pLIRGA+IgHqGImkASG+wn2mhs+u5+fO0zFeALfsQS/Hgw== X-Received: by 2002:a7b:cc12:0:b0:37c:1ae:100a with SMTP id f18-20020a7bcc12000000b0037c01ae100amr5412198wmh.54.1651763956697; Thu, 05 May 2022 08:19:16 -0700 (PDT) Received: from localhost.localdomain ([2001:bb6:9634:7100:33b0:c1b1:8875:4adb]) by smtp.gmail.com with ESMTPSA id z6-20020a056000110600b0020ad05214d5sm1434819wrw.2.2022.05.05.08.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 08:19:16 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 5 May 2022 16:18:51 +0100 Message-Id: <20220505151851.2421-4-ecurtin@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220505151851.2421-1-ecurtin@redhat.com> References: <20220505151851.2421-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 v8 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: Kieran Bingham --- src/cam/meson.build | 9 +++++++++ src/cam/sdl_sink.cpp | 9 +++++++++ src/cam/sdl_texture_mjpg.cpp | 18 ++++++++++++++++++ src/cam/sdl_texture_mjpg.h | 10 ++++++++++ 4 files changed, 46 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 3032730b..afc0ea9f 100644 --- a/src/cam/meson.build +++ b/src/cam/meson.build @@ -41,6 +41,14 @@ if libsdl2.found() 'sdl_texture.cpp', 'sdl_texture_yuyv.cpp' ]) + + libsdl2_image = dependency('SDL2_image', required : false) + if libsdl2.found() + cam_cpp_args += ['-DHAVE_SDL_IMAGE'] + cam_sources += files([ + 'sdl_texture_mjpg.cpp' + ]) + endif endif cam = executable('cam', cam_sources, @@ -49,6 +57,7 @@ cam = executable('cam', cam_sources, libcamera_public, libdrm, libsdl2, + libsdl2_image, libevent, ], cpp_args : cam_cpp_args, diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index 6fbeaf56..f15c01cb 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -19,6 +19,10 @@ #include "sdl_texture_yuyv.h" +#ifdef HAVE_SDL_IMAGE +#include "sdl_texture_mjpg.h" +#endif + #include "event_loop.h" #include "image.h" @@ -59,6 +63,11 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) case libcamera::formats::YUYV: sdlTexture_ = std::make_unique(sdlRect_); break; +#ifdef HAVE_SDL_IMAGE + case libcamera::formats::MJPEG: + sdlTexture_ = std::make_unique(sdlRect_); + break; +#endif default: std::cerr << "Unsupported pixel format " << cfg.pixelFormat.toString() << std::endl; diff --git a/src/cam/sdl_texture_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp new file mode 100644 index 00000000..636fdbea --- /dev/null +++ b/src/cam/sdl_texture_mjpg.cpp @@ -0,0 +1,18 @@ +#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 *buffer_stream = SDL_RWFromMem(data.data(), data.size()); + SDL_Surface *frame = IMG_Load_RW(buffer_stream, 0); + SDL_UpdateTexture(ptr_, NULL, 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..fefaaeeb --- /dev/null +++ b/src/cam/sdl_texture_mjpg.h @@ -0,0 +1,10 @@ +#pragma once + +#include "sdl_texture.h" + +class SDLTextureMJPG : public SDLTexture +{ +public: + SDLTextureMJPG(const SDL_Rect &sdlRect); + void update(const libcamera::Span &data) override; +};