From patchwork Sun Aug 7 02:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 17007 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 C6181BE173 for ; Sun, 7 Aug 2022 02:17:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 54EAB63331; Sun, 7 Aug 2022 04:17:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659838653; bh=KywZ2FwG3Kb8AKYbTiz4EFReY9hHPxCG4Lx3eN52FWE=; 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=WttK2fA6+W9EhC6tPfj82VrHE5Be27ZtK4+VY8MMB0++7oe9qMycxcID8cwBkyra8 R3HYKcdIJlYlR1ojpXDJgiaIaVJFCLY6Sx27tWc081TJLi0u4lmixO7+cVDH7skVmZ +L0dKEgqALCPZ901+0JXoNTpgnIGc25dOrrXn+3X7dGz8QvrwBQo//TTpQhX3zeUDF katgqKEJBnFbsQijn94pHUrAkNmvN2znITBoW75c0lDWhfmtz8Q5WKC4EqJiKf2Nj+ 5XTW92aP0t6H0zEGZQfhVTuUKELZuDs0B6qU94zsrRP6NjmNcWTEzu33kfnchaBjuf gDD+vh/UP6wNA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E76946332A for ; Sun, 7 Aug 2022 04:17:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KkKL70kG"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 83EDF896; Sun, 7 Aug 2022 04:17:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1659838650; bh=KywZ2FwG3Kb8AKYbTiz4EFReY9hHPxCG4Lx3eN52FWE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KkKL70kGNNAPFHdniT18NyWo2w3h0MeU0/C0P3eMTt+tjtMXMtYAiEXGaEkPTxa+6 phHfSUF5tEIazg5EPowXFeL8kMZ93jC3X3SxXWMbP9ipIn2MJHByCYlHD49f2+NbbL cOPtJZrqGPfLB/WI1yn+OLlWr/mBLzKKbWQMatRE= To: libcamera-devel@lists.libcamera.org Date: Sun, 7 Aug 2022 05:17:17 +0300 Message-Id: <20220807021718.9789-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220807021718.9789-1-laurent.pinchart@ideasonboard.com> References: <20220807021718.9789-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] cam: sdl_sink: Support multi-planar formats 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: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to prepare for NV12 support, implement support for multi-planar formats in the SDL sink. This mainly consists in passing a vector of plane data to the SDLTexture::update() function instead of a single value. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi Reviewed-by: Eric Curtin --- src/cam/sdl_sink.cpp | 21 +++++++++++++-------- src/cam/sdl_texture.h | 4 +++- src/cam/sdl_texture_mjpg.cpp | 4 ++-- src/cam/sdl_texture_mjpg.h | 2 +- src/cam/sdl_texture_yuv.cpp | 4 ++-- src/cam/sdl_texture_yuv.h | 2 +- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index 04350bd5365b..9675cf275186 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -185,16 +185,21 @@ void SDLSink::renderBuffer(FrameBuffer *buffer) { Image *image = mappedBuffers_[buffer].get(); - /* \todo Implement support for multi-planar formats. */ - const FrameMetadata::Plane &meta = buffer->metadata().planes()[0]; + std::vector> planes; + unsigned int i = 0; - Span data = image->data(0); - if (meta.bytesused > data.size()) - std::cerr << "payload size " << meta.bytesused - << " larger than plane size " << data.size() - << std::endl; + for (const FrameMetadata::Plane &meta : buffer->metadata().planes()) { + Span data = image->data(i); + if (meta.bytesused > data.size()) + std::cerr << "payload size " << meta.bytesused + << " larger than plane size " << data.size() + << std::endl; - texture_->update(data); + planes.push_back(data); + i++; + } + + texture_->update(planes); SDL_RenderClear(renderer_); SDL_RenderCopy(renderer_, texture_->get(), nullptr, nullptr); diff --git a/src/cam/sdl_texture.h b/src/cam/sdl_texture.h index f523fa5ebf51..e4d3fb2bcf39 100644 --- a/src/cam/sdl_texture.h +++ b/src/cam/sdl_texture.h @@ -7,6 +7,8 @@ #pragma once +#include + #include #include "image.h" @@ -17,7 +19,7 @@ public: SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int pitch); virtual ~SDLTexture(); int create(SDL_Renderer *renderer); - virtual void update(libcamera::Span data) = 0; + virtual void update(const std::vector> &data) = 0; SDL_Texture *get() const { return ptr_; } protected: diff --git a/src/cam/sdl_texture_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp index 7542efd75d96..8dd5ee3eb6bc 100644 --- a/src/cam/sdl_texture_mjpg.cpp +++ b/src/cam/sdl_texture_mjpg.cpp @@ -76,8 +76,8 @@ int SDLTextureMJPG::decompress(Span data) return 0; } -void SDLTextureMJPG::update(Span data) +void SDLTextureMJPG::update(const std::vector> &data) { - decompress(data); + decompress(data[0]); SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), pitch_); } diff --git a/src/cam/sdl_texture_mjpg.h b/src/cam/sdl_texture_mjpg.h index 5141ed73bf70..814ca79ac193 100644 --- a/src/cam/sdl_texture_mjpg.h +++ b/src/cam/sdl_texture_mjpg.h @@ -14,7 +14,7 @@ class SDLTextureMJPG : public SDLTexture public: SDLTextureMJPG(const SDL_Rect &rect); - void update(libcamera::Span data) override; + void update(const std::vector> &data) override; private: int decompress(libcamera::Span data); diff --git a/src/cam/sdl_texture_yuv.cpp b/src/cam/sdl_texture_yuv.cpp index 07df4961a1ab..a5721182a68b 100644 --- a/src/cam/sdl_texture_yuv.cpp +++ b/src/cam/sdl_texture_yuv.cpp @@ -14,7 +14,7 @@ SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride) { } -void SDLTextureYUYV::update(Span data) +void SDLTextureYUYV::update(const std::vector> &data) { - SDL_UpdateTexture(ptr_, &rect_, data.data(), pitch_); + SDL_UpdateTexture(ptr_, &rect_, data[0].data(), pitch_); } diff --git a/src/cam/sdl_texture_yuv.h b/src/cam/sdl_texture_yuv.h index 81e51381ec62..c9130298b91d 100644 --- a/src/cam/sdl_texture_yuv.h +++ b/src/cam/sdl_texture_yuv.h @@ -13,5 +13,5 @@ class SDLTextureYUYV : public SDLTexture { public: SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride); - void update(libcamera::Span data) override; + void update(const std::vector> &data) override; };