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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Eric Curtin <ecurtin@redhat.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
3e0b3a1077
commit
d4a42894b1
6 changed files with 24 additions and 15 deletions
|
@ -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<Span<const uint8_t>> planes;
|
||||
unsigned int i = 0;
|
||||
|
||||
Span<uint8_t> 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());
|
||||
|
||||
texture_->update(data);
|
||||
for (const FrameMetadata::Plane &meta : buffer->metadata().planes()) {
|
||||
Span<uint8_t> 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(planes);
|
||||
|
||||
SDL_RenderClear(renderer_);
|
||||
SDL_RenderCopy(renderer_, texture_->get(), nullptr, nullptr);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#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<const uint8_t> data) = 0;
|
||||
virtual void update(const std::vector<libcamera::Span<const uint8_t>> &data) = 0;
|
||||
SDL_Texture *get() const { return ptr_; }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -76,8 +76,8 @@ int SDLTextureMJPG::decompress(Span<const uint8_t> data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void SDLTextureMJPG::update(Span<const uint8_t> data)
|
||||
void SDLTextureMJPG::update(const std::vector<libcamera::Span<const uint8_t>> &data)
|
||||
{
|
||||
decompress(data);
|
||||
decompress(data[0]);
|
||||
SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), pitch_);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ class SDLTextureMJPG : public SDLTexture
|
|||
public:
|
||||
SDLTextureMJPG(const SDL_Rect &rect);
|
||||
|
||||
void update(libcamera::Span<const uint8_t> data) override;
|
||||
void update(const std::vector<libcamera::Span<const uint8_t>> &data) override;
|
||||
|
||||
private:
|
||||
int decompress(libcamera::Span<const uint8_t> data);
|
||||
|
|
|
@ -14,7 +14,7 @@ SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride)
|
|||
{
|
||||
}
|
||||
|
||||
void SDLTextureYUYV::update(Span<const uint8_t> data)
|
||||
void SDLTextureYUYV::update(const std::vector<libcamera::Span<const uint8_t>> &data)
|
||||
{
|
||||
SDL_UpdateTexture(ptr_, &rect_, data.data(), pitch_);
|
||||
SDL_UpdateTexture(ptr_, &rect_, data[0].data(), pitch_);
|
||||
}
|
||||
|
|
|
@ -13,5 +13,5 @@ class SDLTextureYUYV : public SDLTexture
|
|||
{
|
||||
public:
|
||||
SDLTextureYUYV(const SDL_Rect &rect, unsigned int stride);
|
||||
void update(libcamera::Span<const uint8_t> data) override;
|
||||
void update(const std::vector<libcamera::Span<const uint8_t>> &data) override;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue