Skip to content

Commit

Permalink
Merge pull request #341 from Sensing-Dev/update/two-feature
Browse files Browse the repository at this point in the history
Update/add time out time to 30s
  • Loading branch information
xinyuli1204 authored Nov 20, 2024
2 parents 229c27b + 28de5fb commit c9289f1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/bb/image-io/rt_u3v.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace ion {
namespace bb {
namespace image_io {

#define TIMEOUT_IN_US_SHORTER 3 * 1000 * 1000
#define TIMEOUT_IN_US_LONGER 30 * 1000 * 1000

class U3V {
protected:
struct GError
Expand Down Expand Up @@ -630,7 +633,7 @@ class U3VFakeCam : public U3V{
return *instances_[id].get();
}
void get(std::vector<Halide::Buffer<>>& outs) override {
auto timeout_us = 30 * 1000 * 1000;
auto timeout_us = TIMEOUT_IN_US_LONGER;
std::vector<ArvBuffer *> bufs(num_sensor_);
for (int i = 0;i< num_sensor_;i++){
auto size = devices_[i].u3v_payload_size_;
Expand Down Expand Up @@ -729,7 +732,7 @@ class U3VRealCam: public U3V{
}

void get(std::vector<Halide::Buffer<>>& outs) override{
auto timeout_us = 30 * 1000 * 1000;
auto timeout_us = TIMEOUT_IN_US_LONGER;
int32_t num_device = devices_.size();
if (sim_mode_){
std::vector<ArvBuffer *> bufs(num_device);
Expand Down Expand Up @@ -796,7 +799,7 @@ class U3VRealCam: public U3V{

//first buffer
device_idx_ = (device_idx_ + 1) >= num_device ? 0 : device_idx_ + 1;
bufs[device_idx_] = arv_stream_timeout_pop_buffer(devices_[device_idx_].stream_, 30 * 1000 * 1000);
bufs[device_idx_] = arv_stream_timeout_pop_buffer(devices_[device_idx_].stream_, timeout_us);
if (bufs[device_idx_] == nullptr) {
log::error("pop_buffer(L4) failed due to timeout ({}s)", timeout_us * 1e-6f);
throw ::std::runtime_error("buffer is null");
Expand All @@ -820,7 +823,7 @@ class U3VRealCam: public U3V{

while (frame_cnt_ >= latest_cnt) {
arv_stream_push_buffer(devices_[device_idx_].stream_, bufs[device_idx_]);
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, 30 * 1000 * 1000);
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, timeout_us);
if (bufs[device_idx_] == nullptr){
log::error("pop_buffer(L4) failed due to timeout ({}s)", timeout_us*1e-6f);
throw ::std::runtime_error("buffer is null");
Expand Down Expand Up @@ -1186,7 +1189,7 @@ class U3VRealCam: public U3V{
}
}

void consume_old_buffer(std::vector<ArvBuffer *> &bufs, int timeout_us = 3 * 1000 * 1000){
void consume_old_buffer(std::vector<ArvBuffer *> &bufs, int timeout_us = TIMEOUT_IN_US_SHORTER){
std::vector<int32_t> N_output_buffers(num_sensor_);
for (auto i = 0; i < num_sensor_; ++i) {
int32_t num_input_buffer;
Expand Down Expand Up @@ -1240,7 +1243,7 @@ class U3VGenDC: public U3V{

void get(std::vector<void *>& outs) override{
// TODO: Is 3 second fine?
auto timeout_us = 3 * 1000 * 1000;
auto timeout_us = TIMEOUT_IN_US_LONGER;

int32_t num_device = devices_.size();
std::vector<ArvBuffer *> bufs(num_device);
Expand Down Expand Up @@ -1302,7 +1305,7 @@ class U3VGenDC: public U3V{

//first buffer
device_idx_ = (device_idx_+1) >= num_device ? 0 : device_idx_+1;
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, 30 * 1000 * 1000);
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, timeout_us);
if (bufs[device_idx_] == nullptr){
log::error("pop_buffer(L4) failed due to timeout ({}s)", timeout_us*1e-6f);
throw ::std::runtime_error("buffer is null");
Expand All @@ -1326,10 +1329,9 @@ class U3VGenDC: public U3V{

while (frame_cnt_ >= latest_cnt) {
arv_stream_push_buffer(devices_[device_idx_].stream_, bufs[device_idx_]);
auto timeout2_us = 30 * 1000 * 1000;
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, timeout2_us);
bufs[device_idx_] = arv_stream_timeout_pop_buffer (devices_[device_idx_].stream_, timeout_us);
if (bufs[device_idx_] == nullptr){
log::error("pop_buffer(L8) failed due to timeout ({}s)", timeout2_us*1e-6f);
log::error("pop_buffer(L8) failed due to timeout ({}s)", timeout_us*1e-6f);
throw ::std::runtime_error("buffer is null");
}
devices_[device_idx_].frame_count_ = frame_count_method_ == FrameCountMethod::TYPESPECIFIC3
Expand Down Expand Up @@ -1643,7 +1645,7 @@ class U3VGenDC: public U3V{
}
};

void consume_old_buffer(std::vector<ArvBuffer *> &bufs, int timeout_us = 3 * 1000 * 1000){
void consume_old_buffer(std::vector<ArvBuffer *> &bufs, int timeout_us = TIMEOUT_IN_US_SHORTER){
std::vector<int32_t> N_output_buffers(num_sensor_);
for (auto i = 0; i < num_sensor_; ++i) {
int32_t num_input_buffer;
Expand Down

0 comments on commit c9289f1

Please sign in to comment.