diff --git a/device/gxx-linux/imgproc/imageencode.cpp b/device/gxx-linux/imgproc/imageencode.cpp index fce7394..d211eb9 100644 --- a/device/gxx-linux/imgproc/imageencode.cpp +++ b/device/gxx-linux/imgproc/imageencode.cpp @@ -71,6 +71,8 @@ MemoryPtr JpegImageEncode::encode(cv::Mat &image) type = ".png"; else if(fmt_ == "TIFF") type = ".tiff"; + else if(fmt_ == "BMP") + type = ".bmp"; else type = ".jpg"; diff --git a/device/gxx-linux/scanner/scanner.cpp b/device/gxx-linux/scanner/scanner.cpp index 821694c..4ef7136 100644 --- a/device/gxx-linux/scanner/scanner.cpp +++ b/device/gxx-linux/scanner/scanner.cpp @@ -104,10 +104,10 @@ Scanner::Scanner(std::shared_ptr capturer, std::shared_ptradd_scanevent({.From = STOPSCAN, .Code = mb_error_code}); + // imagehandler->add_scanevent({.From = STOPSCAN, .Code = mb_error_code}); }; auto mb_osmode_call = [&](unsigned int osmode) @@ -261,7 +261,7 @@ void Scanner::add_scansever(HGIntInfo event) bool Scanner::set_hgimgconfig(GScanCap config) { printf("enter config set_hgimgconfig \n"); - scancount = config.is_duplex ? config.scannum / 2 : config.scannum; + scancount = /*config.is_duplex ? config.scannum / 2 :*/ config.scannum; m_cap = config; if (config.resolution_dst < 300) m_config.g200params.dpi = 1; @@ -574,6 +574,7 @@ void Scanner::runScan() else autosizescan(); savescannerinfo(scannerinfo); + imagehandler->add_scanevent({.From = STOPSCAN, mb_error_code}); while (!imagehandler->done()) this_thread::sleep_for(chrono::milliseconds(10)); done_scan = 0; @@ -595,7 +596,7 @@ void Scanner::runScan() if ((((mb_error_code != 0) && (mb_error_code != 0xffffffff)) || imagehandler->getimgstatus().status != NO_error) && m_config.g200params.is_autopaper) mb->set_auto_paper(false, false); mb->startcapimage(false); - imagehandler->add_scanevent({.From = STOPSCAN, 0}); + // imagehandler->add_scanevent({.From = STOPSCAN, 0}); ControlFeedMode(); printf("-------scanner done-------\n"); } diff --git a/device/gxx-linux/usb/src/async_model/common/ipc_util.h b/device/gxx-linux/usb/src/async_model/common/ipc_util.h index 12d93ee..d0e1b83 100644 --- a/device/gxx-linux/usb/src/async_model/common/ipc_util.h +++ b/device/gxx-linux/usb/src/async_model/common/ipc_util.h @@ -89,7 +89,9 @@ public: if (wait && size() == 0) { wait_->wait(); +#if defined(WIN32) || defined(_WIN64) wait_->reset(); +#endif } { diff --git a/device/gxx-linux/usb/src/async_model/common/referer.h b/device/gxx-linux/usb/src/async_model/common/referer.h index 20218b7..4028dae 100644 --- a/device/gxx-linux/usb/src/async_model/common/referer.h +++ b/device/gxx-linux/usb/src/async_model/common/referer.h @@ -8,6 +8,8 @@ // #include #include #include +#include +#include #if defined(WIN32) || defined(_WIN64) #define WAIT_INFINITE INFINITE @@ -34,6 +36,7 @@ extern int gettimeofday(TIMEV* tv, struct timezone* tz); #include #include #include +#include typedef struct timeval TIMEV; #define WAIT_INFINITE 0 #define FSEEK fseek @@ -110,7 +113,7 @@ class thread_pool : public refer { typedef struct _thrd { - uint32_t id; + uint64_t id; std::shared_ptr thread; }THRD; T* obj_; @@ -122,23 +125,33 @@ public: thread_pool(T* obj) : obj_(obj), id_(1) {} + static uint64_t thread_id(std::thread* thrd) + { + std::stringstream ss; + + ss << thrd->get_id(); + + return std::stoull(ss.str()); + } + protected: virtual ~thread_pool() {} public: template - uint32_t thread_new(void(T::* thrd)(Args ...), Args ... args) // return thread ID (not pthread_t), used in thread_stop function + uint64_t thread_new(void(T::* thrd)(Args ...), Args ... args) // return thread ID (not pthread_t), used in thread_stop function { THRD t; t.id = id_++; t.thread.reset(new std::thread(thrd, obj_, args ...)); + t.id = thread_id(t.thread.get()); threads_.push_back(t); return t.id; } - bool thread_stop(uint32_t id = -1) + bool thread_stop(uint64_t id = -1) { bool ret = true; if (id == -1) diff --git a/device/gxx-linux/usb/src/async_model/common/sys_util.cpp b/device/gxx-linux/usb/src/async_model/common/sys_util.cpp index 94afd43..a0ca06c 100644 --- a/device/gxx-linux/usb/src/async_model/common/sys_util.cpp +++ b/device/gxx-linux/usb/src/async_model/common/sys_util.cpp @@ -940,8 +940,6 @@ namespace sys_util } uint64_t thread_id(const std::thread::id& tid) { - return (uint64_t)pthread_self(); - std::stringstream ss; ss << tid; diff --git a/device/gxx-linux/usb/src/async_model/img_process/algs/img_algorithm.cpp b/device/gxx-linux/usb/src/async_model/img_process/algs/img_algorithm.cpp index 1500754..b5159d1 100644 --- a/device/gxx-linux/usb/src/async_model/img_process/algs/img_algorithm.cpp +++ b/device/gxx-linux/usb/src/async_model/img_process/algs/img_algorithm.cpp @@ -567,8 +567,8 @@ bool img_color_transfer::is_enabled(std::functionhead.format = IMG_FMT_PNG; else if(fmt_ == "TIFF") img->head.format = IMG_FMT_TIFF; + else if(fmt_ == "BMP") + img->head.format = IMG_FMT_BMP; return encoder.encode(img->img); } diff --git a/device/gxx-linux/usb/src/async_model/img_process/img_process.cpp b/device/gxx-linux/usb/src/async_model/img_process/img_process.cpp index 3344bd1..9485dfa 100644 --- a/device/gxx-linux/usb/src/async_model/img_process/img_process.cpp +++ b/device/gxx-linux/usb/src/async_model/img_process/img_process.cpp @@ -4,6 +4,7 @@ #include "common/json/gb_json.h" #include "img_process/algs/img_algorithm.h" #include "common/log_util.h" +#include "common/sys_util.h" ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -184,6 +185,8 @@ uint32_t img_processor::add_busy_count(int adden) } void img_processor::worker_thread(bool first) { + log_cls::log(LOG_LEVEL_ALL, "+img_processor::worker_thread(%p) entered ...\n", sys_util::thread_id(std::this_thread::get_id())); + while(run_) { img_one_paper* img = nullptr; @@ -191,6 +194,7 @@ void img_processor::worker_thread(bool first) { if(img) { + int paper = img->images_queue()[0].head.pos.paper_ind; add_busy_count(); handle_image(img); add_busy_count(-1); @@ -200,7 +204,7 @@ void img_processor::worker_thread(bool first) else { while(add_busy_count(0)) - std::this_thread::sleep_for(std::chrono::microseconds(50)); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); img_sender_(nullptr, nullptr, nullptr, scan_staus_); set_image_process_over(true); @@ -213,15 +217,15 @@ void img_processor::worker_thread(bool first) else if(first) { for(auto& v: tids_) - worker_->thread_kill(v); + worker_->thread_stop(v); tids_.clear(); } else { - log_cls::log(LOG_LEVEL_ALL, "- Release image processing threads.\n"); break; } } + log_cls::log(LOG_LEVEL_ALL, "-img_processor::worker_thread(%p) exited.\n", sys_util::thread_id(std::this_thread::get_id())); } void img_processor::handle_image(img_one_paper* img) { @@ -380,9 +384,8 @@ int32_t img_processor::push_image(img_one_paper* img, bool over) size_t cnt = img_que_.save(img, true); - if(speed_first_ && cnt >= 6 && worker_->count() < 6) + if(speed_first_ && cnt >= 4 && worker_->count() < 2) { - log_cls::log(LOG_LEVEL_ALL, "+ Add image processing threads ...\n"); tids_.push_back(worker_->thread_new(&img_processor::worker_thread, false)); } } diff --git a/device/gxx-linux/usb/src/async_model/img_process/img_process.h b/device/gxx-linux/usb/src/async_model/img_process/img_process.h index b164d7b..e135a6c 100644 --- a/device/gxx-linux/usb/src/async_model/img_process/img_process.h +++ b/device/gxx-linux/usb/src/async_model/img_process/img_process.h @@ -34,7 +34,7 @@ class img_processor : public sane_cfg_provider safe_fifo img_que_; thread_pool* worker_; - std::vector tids_; + std::vector tids_; volatile bool speed_first_; volatile bool run_; uint32_t scan_staus_; diff --git a/device/gxx-linux/usb/src/async_model/io/usb_io.h b/device/gxx-linux/usb/src/async_model/io/usb_io.h index a996e54..39a5806 100644 --- a/device/gxx-linux/usb/src/async_model/io/usb_io.h +++ b/device/gxx-linux/usb/src/async_model/io/usb_io.h @@ -73,10 +73,10 @@ class async_usb_gadget : public refer volatile bool run_ = true; volatile bool reset_bulk_ = false; usb_gadget *gadget_ = nullptr; - int thread_ep0_id_ = -1; - int thread_bulk_in_id_ = -1; - int thread_bulk_out_id_ = -1; - int thread_restart_id_ = -1; + uint64_t thread_ep0_id_ = -1; + uint64_t thread_bulk_in_id_ = -1; + uint64_t thread_bulk_out_id_ = -1; + uint64_t thread_restart_id_ = -1; uint32_t enc_head_; uint32_t enc_payload_; uint8_t enc_data_;