From d4a42894b158f5f248ca94a8331bb8a40e051e3c Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 6 Aug 2022 17:35:56 +0300 Subject: cam: sdl_sink: Support multi-planar formats 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 Tested-by: Kieran Bingham --- src/cam/sdl_sink.cpp | 23 +++++++++++++++-------- 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, 24 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index 04350bd5..4ca97576 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -185,16 +185,23 @@ 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; + planes.reserve(buffer->metadata()->planes().size()); + + 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; + + planes.push_back(data); + i++; + } - texture_->update(data); + 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 f523fa5e..e4d3fb2b 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 7542efd7..8dd5ee3e 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 5141ed73..814ca79a 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 07df4961..a5721182 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 223453a0..137b01f8 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; }; -- cgit v1.2.1