Feat/row align bytes (#7)

* better bytes alignment

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* debug macos

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* debug linux

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* windows switch_rgba

Signed-off-by: fufesou <shuanglongchen@yeah.net>

* better switch_rgba

Signed-off-by: fufesou <shuanglongchen@yeah.net>

---------

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-03 09:30:05 +08:00 • committed by GitHub
parent 044bb260d9
commit 873919902e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 94 additions and 60 deletions

View file

@ -16,7 +16,7 @@ extern "C" {
FLUTTER_PLUGIN_EXPORT void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
FlutterDesktopPluginRegistrarRef registrar);
FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int width, int height);
FLUTTER_PLUGIN_EXPORT void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int len, int width, int height, int row_align_bytes);
#if defined(__cplusplus)
} // extern "C"

View file

@ -1,7 +1,6 @@
#include "texture_rgba.h"
#include <iostream>
TextureRgba::TextureRgba(flutter::TextureRegistrar *texture_registrar)
{
this->texture_registrar_ = texture_registrar;
@ -17,14 +16,36 @@ TextureRgba::~TextureRgba()
texture_registrar_->UnregisterTexture(texture_id_);
}
void TextureRgba::switch_rgba(std::vector<uint8_t> &buffer, size_t height)
{
uint8_t temp;
size_t byes_per_row = buffer.size() / height;
size_t width = byes_per_row >> 2;
for (size_t i = 0; i < height; ++i)
{
size_t row_idx_base = i * byes_per_row;
for (size_t k = 0; k < width; ++k)
{
size_t idx = row_idx_base + k * 4;
temp = buffer[idx];
buffer[idx] = buffer[idx + 2];
buffer[idx + 2] = temp;
}
}
}
void TextureRgba::MarkVideoFrameAvailable(
std::vector<uint8_t> &buffer, size_t width, size_t height)
{
if (buffer.empty() || buffer.size() != width * height * 4)
if (buffer.empty())
{
return;
}
// Do not check bellow. Because the data may have paddings per row.
// buffer.size() != width * height * 4
switch_rgba(buffer, height);
const std::lock_guard<std::mutex> lock(mutex_);
int bg_index = fg_index_ ^ 1;
buffer.swap(buffer_tmp_[bg_index]);

View file

@ -17,6 +17,9 @@ public:
const FlutterDesktopPixelBuffer* buffer();
private:
void switch_rgba(std::vector<uint8_t>& buffer, size_t height);
private:
FlutterDesktopPixelBuffer flutter_pixel_buffer_{};
flutter::TextureRegistrar* texture_registrar_ = nullptr;

View file

@ -14,7 +14,7 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
}
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int width, int height)
void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer, int len, int width, int height, int row_align_bytes)
{
assert(texture_rgba != nullptr);
assert(buffer != nullptr);
@ -25,6 +25,6 @@ void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer,
}
TextureRgba *rgba = static_cast<TextureRgba *>(texture_rgba);
std::vector<uint8_t> data(buffer, buffer + width * height * 4);
std::vector<uint8_t> data(buffer, buffer + len);
rgba->MarkVideoFrameAvailable(data, width, height);
}