remove preview_thread_, cost more time but less memory usage

This commit is contained in:
Terrence 2025-05-26 07:04:25 +08:00
parent f890220ce3
commit 9f90c7dd6a
2 changed files with 12 additions and 18 deletions

View File

@ -64,9 +64,6 @@ void Esp32Camera::SetExplainUrl(const std::string& url, const std::string& token
} }
bool Esp32Camera::Capture() { bool Esp32Camera::Capture() {
if (preview_thread_.joinable()) {
preview_thread_.join();
}
if (encoder_thread_.joinable()) { if (encoder_thread_.joinable()) {
encoder_thread_.join(); encoder_thread_.join();
} }
@ -84,20 +81,18 @@ bool Esp32Camera::Capture() {
} }
} }
preview_thread_ = std::thread([this]() { // 显示预览图片
// 显示预览图片 auto display = Board::GetInstance().GetDisplay();
auto display = Board::GetInstance().GetDisplay(); if (display != nullptr) {
if (display != nullptr) { auto src = (uint16_t*)fb_->buf;
auto src = (uint16_t*)fb_->buf; auto dst = (uint16_t*)preview_image_.data;
auto dst = (uint16_t*)preview_image_.data; size_t pixel_count = fb_->len / 2;
size_t pixel_count = fb_->len / 2; for (size_t i = 0; i < pixel_count; i++) {
for (size_t i = 0; i < pixel_count; i++) { // 交换每个16位字内的字节
// 交换每个16位字内的字节 dst[i] = __builtin_bswap16(src[i]);
dst[i] = __builtin_bswap16(src[i]);
}
display->SetPreviewImage(&preview_image_);
} }
}); display->SetPreviewImage(&preview_image_);
}
return true; return true;
} }
@ -109,7 +104,7 @@ bool Esp32Camera::Capture() {
* AI分析并返回结果 * AI分析并返回结果
* *
* *
* - 使线JPEG编码线 * - 使线JPEG线
* - (chunked transfer encoding)使 * - (chunked transfer encoding)使
* - 线线 * - 线线
* - IDID和认证令牌的HTTP头部配置 * - IDID和认证令牌的HTTP头部配置

View File

@ -22,7 +22,6 @@ private:
lv_img_dsc_t preview_image_; lv_img_dsc_t preview_image_;
std::string explain_url_; std::string explain_url_;
std::string explain_token_; std::string explain_token_;
std::thread preview_thread_;
std::thread encoder_thread_; std::thread encoder_thread_;
public: public: