调整保存USB图像时,不在IO锁当中执行,以便在save_usb_image中可以通过休眠来让其它线程有机会获取IO锁。
This commit is contained in:
parent
9b10e91dba
commit
ca041a1005
|
@ -714,22 +714,21 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
|
|||
ret = status_;
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
|
||||
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
||||
if (!buf.get())
|
||||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
|
||||
// write reading command
|
||||
|
||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
||||
|
||||
buf->set_image_statu(statu);
|
||||
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
else // if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
|
||||
// write reading command
|
||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
||||
|
||||
buf->set_image_statu(statu);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
r = total;
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
|
||||
unsigned int size = r;
|
||||
|
@ -776,20 +775,19 @@ int hg_scanner_239::read_one_image_from_usb(SANE_Image_Statu statu)
|
|||
{
|
||||
VLOG_MINI_2(LOG_LEVEL_FATAL, "read_one_image_from_usb 'total' is %d, 'left' total len is:%d!!!\n", total, r);
|
||||
}
|
||||
|
||||
}
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
ret = save_usb_data(buf);
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
ret = save_usb_data(buf);
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
is_scanner_err_ok = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
|
||||
is_scanner_err_ok = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
|
||||
}
|
||||
}
|
||||
if (is_scanner_err_ok)
|
||||
{
|
||||
|
|
|
@ -576,35 +576,40 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
|
|||
ret = status_;
|
||||
else
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
||||
if (!buf.get())
|
||||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
|
||||
// write reading command
|
||||
buf->set_image_statu(statu);
|
||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
||||
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
else // if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
r = total;
|
||||
// write reading command
|
||||
buf->set_image_statu(statu);
|
||||
{
|
||||
void* buff = buf->data(off, (unsigned int*)&r);
|
||||
|
||||
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
while (buff)
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
r = total;
|
||||
if (ret == SCANNER_ERR_OK)
|
||||
{
|
||||
ret = io_->read_bulk(buff, &r);
|
||||
if (ret != SCANNER_ERR_OK)
|
||||
break;
|
||||
void* buff = buf->data(off, (unsigned int*)&r);
|
||||
|
||||
off += r;
|
||||
if (off >= total)
|
||||
break;
|
||||
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||
while (buff)
|
||||
{
|
||||
ret = io_->read_bulk(buff, &r);
|
||||
if (ret != SCANNER_ERR_OK)
|
||||
break;
|
||||
|
||||
r = total - off;
|
||||
buff = buf->data(off, (unsigned int*)&r);
|
||||
off += r;
|
||||
if (off >= total)
|
||||
break;
|
||||
|
||||
r = total - off;
|
||||
buff = buf->data(off, (unsigned int*)&r);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret));
|
||||
}
|
||||
}
|
||||
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image from USB = %s\n", hg_scanner_err_name(ret));
|
||||
|
@ -630,10 +635,6 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
|
|||
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Read image data from USB err: %s\n", hg_scanner_err_name(ret));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VLOG_MINI_1(LOG_LEVEL_FATAL, "write command SR_IM_TX failed: %s\n", hg_scanner_err_name(ret));
|
||||
}
|
||||
}
|
||||
if(popimg)
|
||||
pop_first_image();
|
||||
|
|
|
@ -461,39 +461,40 @@ int hg_scanner_306::get_img_data_7010()
|
|||
|
||||
USBCB usb{ setting3288dsp::GET_IMAGE, 0, 0 };
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
ret = writeusb(usb);
|
||||
|
||||
io_->set_timeout(800);
|
||||
setting3288dsp::HG_JpegCompressInfo info;
|
||||
StopWatch sw;
|
||||
sw.reset();
|
||||
int len = sizeof(info);
|
||||
ret = io_->read_bulk(&info, &len);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(io_lock_);
|
||||
ret = writeusb(usb);
|
||||
|
||||
if (info.first_frame)
|
||||
{
|
||||
frame_length_ = info.DataLength;
|
||||
frame_width_ = info.width;
|
||||
frame_hegiht_ = info.height;
|
||||
first_frame_total_ = info.index_frame;
|
||||
jpgdata_.clear();
|
||||
jpgdata_.resize(frame_width_ * frame_hegiht_ * first_frame_total_);
|
||||
index_ = 0;
|
||||
}
|
||||
if (info.last_frame)
|
||||
{
|
||||
std::vector<unsigned char> data_;
|
||||
data_.resize(frame_length_);
|
||||
ret = io_->read_bulk(&data_[0], &frame_length_);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = io_->read_bulk(&jpgdata_[index_], &frame_length_);
|
||||
index_ += frame_length_;
|
||||
last_frame_total_ = info.index_frame;
|
||||
}
|
||||
io_->set_timeout(800);
|
||||
sw.reset();
|
||||
int len = sizeof(info);
|
||||
ret = io_->read_bulk(&info, &len);
|
||||
|
||||
if (info.first_frame)
|
||||
{
|
||||
frame_length_ = info.DataLength;
|
||||
frame_width_ = info.width;
|
||||
frame_hegiht_ = info.height;
|
||||
first_frame_total_ = info.index_frame;
|
||||
jpgdata_.clear();
|
||||
jpgdata_.resize(frame_width_ * frame_hegiht_ * first_frame_total_);
|
||||
index_ = 0;
|
||||
}
|
||||
if (info.last_frame)
|
||||
{
|
||||
std::vector<unsigned char> data_;
|
||||
data_.resize(frame_length_);
|
||||
ret = io_->read_bulk(&data_[0], &frame_length_);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = io_->read_bulk(&jpgdata_[index_], &frame_length_);
|
||||
index_ += frame_length_;
|
||||
last_frame_total_ = info.index_frame;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.last_frame)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue