调整内存控制:USB+图像处理队列1GB;支持异步IO的100MB
This commit is contained in:
parent
0a206f1eb2
commit
899b78523f
|
@ -763,11 +763,15 @@ int tiny_buffer::get_image_statu(void)
|
|||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// final_img_queue
|
||||
|
||||
final_img_queue::final_img_queue()
|
||||
final_img_queue::final_img_queue() : mem_usage_(0)
|
||||
{}
|
||||
final_img_queue::~final_img_queue()
|
||||
{}
|
||||
|
||||
unsigned long long final_img_queue::mem_usage(void)
|
||||
{
|
||||
return mem_usage_;
|
||||
}
|
||||
size_t final_img_queue::size(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(lock_);
|
||||
|
@ -778,6 +782,7 @@ void final_img_queue::clear(void)
|
|||
{
|
||||
std::lock_guard<std::mutex> lck(lock_);
|
||||
|
||||
mem_usage_ = 0;
|
||||
queue_.clear();
|
||||
}
|
||||
bool final_img_queue::put(int w, int h, int bpp, int channels, int line_bytes, void* data, unsigned bytes
|
||||
|
@ -813,6 +818,7 @@ bool final_img_queue::put(int w, int h, int bpp, int channels, int line_bytes, v
|
|||
{
|
||||
std::lock_guard<std::mutex> lck(lock_);
|
||||
queue_.push_back(imgd);
|
||||
mem_usage_ += bytes;
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
|
@ -869,6 +875,9 @@ void final_img_queue::fetch_front(void* buf, int* len, bool* over)
|
|||
imgd.offset += *len;
|
||||
if (imgd.offset >= imgd.header.bytes)
|
||||
{
|
||||
mem_usage_ -= imgd.header.bytes;
|
||||
if (mem_usage_ < 0)
|
||||
mem_usage_ = 0;
|
||||
if (over)
|
||||
*over = true;
|
||||
queue_.erase(queue_.begin());
|
||||
|
|
|
@ -225,12 +225,14 @@ class final_img_queue
|
|||
{
|
||||
mutable std::mutex lock_;
|
||||
std::vector<IMGDT> queue_;
|
||||
long long mem_usage_;
|
||||
|
||||
public:
|
||||
final_img_queue();
|
||||
~final_img_queue();
|
||||
|
||||
public:
|
||||
unsigned long long mem_usage(void);
|
||||
size_t size(void);
|
||||
void clear(void);
|
||||
bool put(int w, int h, int bpp, int channels, int line_bytes, void* data, unsigned bytes
|
||||
|
|
|
@ -99,7 +99,7 @@ hg_scanner::hg_scanner(ScannerSerial serial
|
|||
, async_io_(false), is_white_0_(true), isremove_left_hole(false), isremove_right_hole(false), isremove_top_hole(false), isremove_low_hole(false)
|
||||
, isremove_left_hole_threshold(0), isremove_right_hole_threshold(0), isremove_top_hole_threshold(0), isremove_low_hole_threshold(0)
|
||||
, dump_usb_path_(""),is_kernelsnap_211209_(false), pid_(0), dump_img_(&hg_scanner::dump_image_empty), is_kernelsnap_220830_(false),is_kernelsnap3288_221106_(false)
|
||||
, is_kernelsnap_221027_(false), memory_size_(200/*USB图像队列,JPEG压缩*/), isx86_Advan_(true)
|
||||
, is_kernelsnap_221027_(false), memory_size_(1024/*USB+JPEG压缩及图像处理图队列,总共1GB*/), isx86_Advan_(true), stop_fatal_(SCANNER_ERR_OK)
|
||||
{
|
||||
#if !defined(_WIN32) && !defined(_WIN64) &&defined(x86_64)
|
||||
isx86_Advan_ = false;
|
||||
|
@ -728,7 +728,7 @@ void hg_scanner::thread_handle_image_process(void)
|
|||
else
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "Get Image Process is NULL pid is %d.\n",pid_);
|
||||
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
|
@ -736,7 +736,7 @@ void hg_scanner::thread_handle_image_process(void)
|
|||
catch (...)
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "FATAL: Insufficient memory when proecss image with %d bytes.\n", tiny_buffer->size());
|
||||
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
stop();
|
||||
break;
|
||||
}
|
||||
|
@ -750,6 +750,7 @@ void hg_scanner::thread_handle_image_process(void)
|
|||
|
||||
void hg_scanner::working_begin(void*)
|
||||
{
|
||||
stop_fatal_ = SCANNER_ERR_OK;
|
||||
final_img_index_ = 0;
|
||||
status_ = SCANNER_ERR_OK;
|
||||
notify_ui_working_status(STATU_DESC_SCAN_WORKING, SANE_EVENT_WORKING, SCANNER_ERR_OK);
|
||||
|
@ -761,6 +762,9 @@ void hg_scanner::working_done(void*)
|
|||
if(user_cancel_)
|
||||
final_imgs_.clear();
|
||||
|
||||
if (status_ == SCANNER_ERR_OK && stop_fatal_)
|
||||
status_ = stop_fatal_;
|
||||
|
||||
switch (status_)
|
||||
{
|
||||
case SCANNER_ERR_OK:
|
||||
|
@ -2398,12 +2402,20 @@ int hg_scanner::save_usb_data(std::shared_ptr<tiny_buffer> data)
|
|||
size_t que_size = 0;
|
||||
imgs_.Size(&que_size);
|
||||
Memoryusae = que_size / 1024.0f / 1024.0f;
|
||||
if (async_io_)
|
||||
Memoryusae *= 10;
|
||||
else
|
||||
Memoryusae += final_imgs_.mem_usage() / 1024.0f / 1024.0f;
|
||||
while (Memoryusae >= memory_size_ && !user_cancel_ && num < 20)//三个条件以防止卡死
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
//Memoryusae = hg_log::GetAppMemoryUsage();
|
||||
imgs_.Size(&que_size);
|
||||
Memoryusae = que_size / 1024.0f / 1024.0f;
|
||||
if (async_io_)
|
||||
Memoryusae *= 10;
|
||||
else
|
||||
Memoryusae += final_imgs_.mem_usage() / 1024.0f / 1024.0f;
|
||||
if(num++ == 0)
|
||||
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Memory Usage is Too big:%f ,Please wait -_- ...\r\n", Memoryusae);
|
||||
}
|
||||
|
|
|
@ -293,6 +293,7 @@ protected:
|
|||
std::string final_path_;
|
||||
unsigned long long memory_size_;
|
||||
bool isx86_Advan_;
|
||||
int stop_fatal_;
|
||||
BlockingQueue<std::shared_ptr<tiny_buffer>> imgs_;
|
||||
|
||||
void init_settings(const char* json_setting_text);
|
||||
|
|
Loading…
Reference in New Issue