cam: sdl_sink: Pass a Span<const uint8_t> to SDLTexture::update()
The SDLTexture::update() function isn't meant to modify the data it receives. Make the Span type const to ensure this at compile time. While at it, pass the Span by value instead of reference, as a Span is only a pointer and size, which will fit in registers and will avoid pointer dereferences in the callee. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
dc1f4a91df
commit
f6d6181d3c
5 changed files with 7 additions and 7 deletions
|
@ -17,7 +17,7 @@ public:
|
||||||
SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int pitch);
|
SDLTexture(const SDL_Rect &rect, uint32_t pixelFormat, const int pitch);
|
||||||
virtual ~SDLTexture();
|
virtual ~SDLTexture();
|
||||||
int create(SDL_Renderer *renderer);
|
int create(SDL_Renderer *renderer);
|
||||||
virtual void update(const libcamera::Span<uint8_t> &data) = 0;
|
virtual void update(libcamera::Span<const uint8_t> data) = 0;
|
||||||
SDL_Texture *get() const { return ptr_; }
|
SDL_Texture *get() const { return ptr_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -43,7 +43,7 @@ SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SDLTextureMJPG::decompress(const Span<uint8_t> &data)
|
int SDLTextureMJPG::decompress(Span<const uint8_t> data)
|
||||||
{
|
{
|
||||||
struct jpeg_decompress_struct cinfo;
|
struct jpeg_decompress_struct cinfo;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ int SDLTextureMJPG::decompress(const Span<uint8_t> &data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLTextureMJPG::update(const Span<uint8_t> &data)
|
void SDLTextureMJPG::update(Span<const uint8_t> data)
|
||||||
{
|
{
|
||||||
decompress(data);
|
decompress(data);
|
||||||
SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), pitch_);
|
SDL_UpdateTexture(ptr_, nullptr, rgb_.get(), pitch_);
|
||||||
|
|
|
@ -14,10 +14,10 @@ class SDLTextureMJPG : public SDLTexture
|
||||||
public:
|
public:
|
||||||
SDLTextureMJPG(const SDL_Rect &rect);
|
SDLTextureMJPG(const SDL_Rect &rect);
|
||||||
|
|
||||||
void update(const libcamera::Span<uint8_t> &data) override;
|
void update(libcamera::Span<const uint8_t> data) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int decompress(const libcamera::Span<uint8_t> &data);
|
int decompress(libcamera::Span<const uint8_t> data);
|
||||||
|
|
||||||
std::unique_ptr<unsigned char[]> rgb_;
|
std::unique_ptr<unsigned char[]> rgb_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ SDLTextureYUYV::SDLTextureYUYV(const SDL_Rect &rect)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLTextureYUYV::update(const Span<uint8_t> &data)
|
void SDLTextureYUYV::update(Span<const uint8_t> data)
|
||||||
{
|
{
|
||||||
SDL_UpdateTexture(ptr_, &rect_, data.data(), pitch_);
|
SDL_UpdateTexture(ptr_, &rect_, data.data(), pitch_);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,5 +13,5 @@ class SDLTextureYUYV : public SDLTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SDLTextureYUYV(const SDL_Rect &rect);
|
SDLTextureYUYV(const SDL_Rect &rect);
|
||||||
void update(const libcamera::Span<uint8_t> &data) override;
|
void update(libcamera::Span<const uint8_t> data) override;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue