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

@ -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]);