调整保存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_;
|
ret = status_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
|
||||||
|
|
||||||
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
||||||
if (!buf.get())
|
if (!buf.get())
|
||||||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||||
|
else // if (ret == SCANNER_ERR_OK)
|
||||||
// write reading command
|
|
||||||
|
|
||||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
|
||||||
|
|
||||||
buf->set_image_statu(statu);
|
|
||||||
|
|
||||||
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));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
r = total;
|
r = total;
|
||||||
|
if (ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned int size = r;
|
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);
|
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)
|
if (ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
ret = save_usb_data(buf);
|
is_scanner_err_ok = true;
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
if (is_scanner_err_ok)
|
||||||
{
|
{
|
||||||
|
|
|
@ -576,35 +576,40 @@ int hg_scanner_302::read_one_image_from_usb(SANE_Image_Statu statu)
|
||||||
ret = status_;
|
ret = status_;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(io_lock_);
|
|
||||||
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
std::shared_ptr<tiny_buffer> buf(aquire_memory(total));
|
||||||
if (!buf.get())
|
if (!buf.get())
|
||||||
return SCANNER_ERR_INSUFFICIENT_MEMORY;
|
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||||
|
else // if (ret == SCANNER_ERR_OK)
|
||||||
// write reading command
|
|
||||||
buf->set_image_statu(statu);
|
|
||||||
ret = write_register(setting3399::SR_IM_TX, 1);
|
|
||||||
|
|
||||||
if (ret == SCANNER_ERR_OK)
|
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
// write reading command
|
||||||
r = total;
|
buf->set_image_statu(statu);
|
||||||
{
|
{
|
||||||
void* buff = buf->data(off, (unsigned int*)&r);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
|
ret = write_register(setting3399::SR_IM_TX, 1);
|
||||||
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
while (buff)
|
r = total;
|
||||||
|
if (ret == SCANNER_ERR_OK)
|
||||||
{
|
{
|
||||||
ret = io_->read_bulk(buff, &r);
|
void* buff = buf->data(off, (unsigned int*)&r);
|
||||||
if (ret != SCANNER_ERR_OK)
|
|
||||||
break;
|
|
||||||
|
|
||||||
off += r;
|
ret = SCANNER_ERR_INSUFFICIENT_MEMORY;
|
||||||
if (off >= total)
|
while (buff)
|
||||||
break;
|
{
|
||||||
|
ret = io_->read_bulk(buff, &r);
|
||||||
|
if (ret != SCANNER_ERR_OK)
|
||||||
|
break;
|
||||||
|
|
||||||
r = total - off;
|
off += r;
|
||||||
buff = buf->data(off, (unsigned int*)&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));
|
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));
|
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)
|
if(popimg)
|
||||||
pop_first_image();
|
pop_first_image();
|
||||||
|
|
|
@ -461,39 +461,40 @@ int hg_scanner_306::get_img_data_7010()
|
||||||
|
|
||||||
USBCB usb{ setting3288dsp::GET_IMAGE, 0, 0 };
|
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;
|
setting3288dsp::HG_JpegCompressInfo info;
|
||||||
StopWatch sw;
|
StopWatch sw;
|
||||||
sw.reset();
|
{
|
||||||
int len = sizeof(info);
|
std::lock_guard<std::mutex> lock(io_lock_);
|
||||||
ret = io_->read_bulk(&info, &len);
|
ret = writeusb(usb);
|
||||||
|
|
||||||
if (info.first_frame)
|
io_->set_timeout(800);
|
||||||
{
|
sw.reset();
|
||||||
frame_length_ = info.DataLength;
|
int len = sizeof(info);
|
||||||
frame_width_ = info.width;
|
ret = io_->read_bulk(&info, &len);
|
||||||
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.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)
|
if (info.last_frame)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue