diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 2daf2b2..2ab45ca 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -154,7 +154,7 @@ hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, i , 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_(""), dump_img_(&hg_scanner::dump_image_empty) - , memory_size_(4000/*USB+JPEG压缩及图像处理图队列,总共1GB*/), isx86_Advan_(true), stop_fatal_(SCANNER_ERR_OK), is_auto_paper_scan(false) + , memory_size_(600/*USB+JPEG压缩及图像处理图队列,总共600MB*/), wait_mem_seconds_(60), isx86_Advan_(true), stop_fatal_(SCANNER_ERR_OK), is_auto_paper_scan(false) , size_check(false), save_sleeptime_type_(false), is_checksum_strat_scan(false), is_cis_image(false) , is_dpi_color_check(false), save_dpi_color_check_val(0.0f), is_auto_falt(false), HGVersion_mgr_(NULL), HGVersion_Init_(NULL) , HGVersion_Islock_(NULL), HGVersion_Postlog_(NULL), HGVersion_Free_(NULL), Dynamicopen_HGVersion_pHandle_(NULL), pid_(pid), fetching_id_(-1), color_correction_(false) @@ -183,13 +183,20 @@ hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, i if (!mem.empty()) { memory_size_ = std::stoi(mem); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get the config file --->memory_size_ set is :%lld", memory_size_); + VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get the config file --->memory_size_ set is :%lld\n", memory_size_); } + mem = hg_log::ini_get("mem", "wait"); + if (!mem.empty()) + { + wait_mem_seconds_ = std::stoi(mem); + VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get the config file --->wait_mem_seconds_ set is :%d\n", wait_mem_seconds_); + } + std::string adv = hg_log::ini_get("cpu", "advanced"); if (!adv.empty()) { isx86_Advan_ = adv == "0" ? false : true; - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get the config file --->isx86_Advan_ set is :%d", isx86_Advan_); + VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get the config file --->isx86_Advan_ set is :%d\n", isx86_Advan_); } if (hg_log::create_folder(final_path_.c_str())) @@ -3508,18 +3515,23 @@ int hg_scanner::save_usb_data(std::shared_ptr data) } else { - int num = 0; - float Memoryusae = .0f; // hg_log::GetAppMemoryUsage();; + if(wait_mem_seconds_ == -1) + std::this_thread::sleep_for(std::chrono::milliseconds(30 * 1000)); + + int num = 0, gap = 500, max_wait = wait_mem_seconds_ * 1000 / gap; + float mem0 = .0f, Memoryusae = .0f; // hg_log::GetAppMemoryUsage();; size_t que_size = 0; imgs_.Size(&que_size); - Memoryusae = que_size / 1024.0f / 1024.0f; + mem0 = que_size / 1024.0f / 1024.0f; if (async_io_) - Memoryusae *= 10; + mem0 *= 10; else - Memoryusae += final_imgs_.mem_usage() / 1024.0f / 1024.0f; - while (Memoryusae >= memory_size_ && !user_cancel_ && num < 20)//三个条件以防止卡死 + mem0 += final_imgs_.mem_usage() / 1024.0f / 1024.0f; + Memoryusae = mem0; + while (Memoryusae >= memory_size_ && Memoryusae >= mem0 && + !user_cancel_ && num < max_wait)//三个条件以防止卡死 + 取走一张图即可存入一张图的条件 { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::this_thread::sleep_for(std::chrono::milliseconds(gap)); //Memoryusae = hg_log::GetAppMemoryUsage(); imgs_.Size(&que_size); Memoryusae = que_size / 1024.0f / 1024.0f; diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index 6850662..3c1ee39 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -393,7 +393,8 @@ protected: unsigned int usb_img_index_; unsigned int final_img_index_; std::string final_path_; - unsigned long long memory_size_; + unsigned long memory_size_; // MB + unsigned long wait_mem_seconds_; // wait up to wait_mem_seconds_ if memory usage is great than memory_size_ bool isx86_Advan_; int stop_fatal_; BlockingQueue> imgs_;