diff --git a/src/bb/image-io/rt_u3v.h b/src/bb/image-io/rt_u3v.h index 79737dbe..28e36a2e 100644 --- a/src/bb/image-io/rt_u3v.h +++ b/src/bb/image-io/rt_u3v.h @@ -143,7 +143,7 @@ class U3V { int32_t u3v_payload_size_; int32_t image_payload_size_; - uint64_t frame_count_; + uint32_t frame_count_; float gain_; float exposure_; @@ -181,16 +181,25 @@ class U3V { } void dispose(){ + log::debug("U3V::dispose() :: is called"); for (auto i=0; i(d.stream_)); + auto end = std::chrono::system_clock::now(); + log::debug("U3V::dispose() :: g_object_unref took {} ms", std::chrono::duration_cast(end-start).count()); + + start = std::chrono::system_clock::now(); g_object_unref(reinterpret_cast(d.device_)); + end = std::chrono::system_clock::now(); + log::debug("U3V::dispose() :: g_object_unref took {} ms", std::chrono::duration_cast(end-start).count()); } devices_.clear(); @@ -201,6 +210,7 @@ class U3V { // TODO: get rid of the following code; no call destructor from the member function. //------------------------------------------------------------------------------------------ instance_.reset(nullptr); + log::debug("U3V::dispose() :: Instance is deleted"); } void SetGain(int32_t sensor_idx, const std::string key, double v) { @@ -291,8 +301,11 @@ class U3V { throw ::std::runtime_error("Buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } if (realtime_display_mode_){ @@ -314,8 +327,11 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } } } @@ -347,25 +363,33 @@ class U3V { while (devices_[i].frame_count_ < max_cnt) { arv_stream_push_buffer(devices_[i].stream_, bufs[i]); bufs[i] = arv_stream_timeout_pop_buffer (devices_[i].stream_, timeout_us); + if (bufs[i] == nullptr){ log::error("pop_buffer(L3) failed due to timeout ({}s)", timeout_us*1e-6f); throw ::std::runtime_error("buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } } } } + for (int i = 0; i < num_sensor_; ++i){ ::memcpy(outs[i], arv_buffer_get_part_data(bufs[i], 0, nullptr), devices_[i].image_payload_size_); arv_stream_push_buffer(devices_[i].stream_, bufs[i]); + log::trace("Obtained Frame from USB{}: {}", i, devices_[i].frame_count_); } + } else if (operation_mode_ == OperationMode::Came1USB2) { - uint64_t latest_cnt = 0; + uint32_t latest_cnt = 0; int32_t min_frame_device_idx = 0; //first buffer @@ -376,9 +400,12 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[cameN_idx_].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) - : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) + : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); latest_cnt = devices_[cameN_idx_].frame_count_; + cameN_idx_ == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[cameN_idx_].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[cameN_idx_].frame_count_); int internal_count = 0; int max_internal_count = 1000; @@ -392,9 +419,14 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[cameN_idx_].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) - : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) + : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); latest_cnt = devices_[cameN_idx_].frame_count_; + + cameN_idx_ == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[cameN_idx_].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[cameN_idx_].frame_count_); + if (internal_count++ > max_internal_count){ log::error("pop_buffer(L9) The sequential invalid buffer is more than {}; Stop the pipeline.", max_internal_count); throw ::std::runtime_error("Invalid framecount"); @@ -404,6 +436,8 @@ class U3V { frame_cnt_ = latest_cnt; ::memcpy(outs[0], arv_buffer_get_part_data(bufs[cameN_idx_], 0, nullptr), devices_[cameN_idx_].image_payload_size_); arv_stream_push_buffer(devices_[cameN_idx_].stream_, bufs[cameN_idx_]); + + log::trace("Obtained Frame from USB{}: {}", cameN_idx_, frame_cnt_); } } @@ -425,8 +459,12 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } if (realtime_display_mode_){ @@ -448,8 +486,12 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } } } @@ -486,8 +528,11 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[i].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) - : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[i], devices_[i])) + : static_cast(arv_buffer_get_timestamp(bufs[i]) & 0x00000000FFFFFFFF); + i == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[i].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[i].frame_count_); } } } @@ -497,9 +542,10 @@ class U3V { ::memcpy(outs[i*num_sensor_], arv_buffer_get_data(bufs[i], nullptr), devices_[i].u3v_payload_size_); ::memcpy(outs[i*num_sensor_+1], &(devices_[i].header_info_), sizeof(ion::bb::image_io::rawHeader)); arv_stream_push_buffer(devices_[i].stream_, bufs[i]); + log::trace("Obtained Frame from USB{}: {}", i, devices_[i].frame_count_); } } else if (operation_mode_ == OperationMode::Came1USB2) { - uint64_t latest_cnt = 0; + uint32_t latest_cnt = 0; int32_t min_frame_device_idx = 0; //first buffer @@ -510,9 +556,12 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[cameN_idx_].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) - : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) + : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); latest_cnt = devices_[cameN_idx_].frame_count_; + cameN_idx_ == 0 ? + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", devices_[cameN_idx_].frame_count_, "") : + log::trace("All-Popped Frames (USB0, USB1)=({:20}, {:20})", "", devices_[cameN_idx_].frame_count_); int internal_count = 0; int max_internal_count = 1000; @@ -527,8 +576,8 @@ class U3V { throw ::std::runtime_error("buffer is null"); } devices_[cameN_idx_].frame_count_ = is_gendc_ - ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) - : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); + ? static_cast(get_frame_count_from_genDC_descriptor(bufs[cameN_idx_], devices_[cameN_idx_])) + : static_cast(arv_buffer_get_timestamp(bufs[cameN_idx_]) & 0x00000000FFFFFFFF); latest_cnt = devices_[cameN_idx_].frame_count_; if (internal_count++ > max_internal_count){ log::error("pop_buffer(L10) The sequential invalid buffer is more than {}; Stop the pipeline.", max_internal_count); @@ -552,12 +601,14 @@ class U3V { { init_symbols(); + log::debug("ion-kit with framecount-log for 23-11-14 Update framecount display"); log::info("Using aravis-{}.{}.{}", arv_get_major_version(), arv_get_minor_version(), arv_get_micro_version()); arv_update_device_list(); unsigned int n_devices = arv_get_n_devices (); if (n_devices < num_sensor_){ + log::info("Multiple devices are found; The first device is selected"); throw std::runtime_error("No device found"); } frame_sync_ = num_sensor_ > 1 ? frame_sync_ : false; @@ -567,6 +618,10 @@ class U3V { log::info("Multiple devices are found; The first device is selected"); } + log::info("Creating U3V instance with {} devices...", num_sensor_); + log::info("Acquisition option::{} is {}", "frame_sync_", frame_sync_); + log::info("Acquisition option::{} is {}", "realtime_display_mode_", realtime_display_mode_); + for (int i = 0; i < n_devices; ++i){ if (dev_id == arv_get_device_id (i) && dev_id != nullptr){ /* if device id is specified @@ -578,6 +633,7 @@ class U3V { /* if device id is not specified */ devices_[i].dev_id_ = arv_get_device_id (i); } + log::info("\tDevice/USB {}::{} : {}", i, "DeviceID", devices_[i].dev_id_); devices_[i].device_ = arv_open_device(devices_[i].dev_id_, &err_); if (err_ ) { @@ -592,6 +648,7 @@ class U3V { if (err_ ) { throw std::runtime_error(err_->message); } + log::info("\tDevice/USB {}::{} : {}", i, "PixelFormat", pixel_format_); // Some type of U3V Camera has integer type on gain and exposure const char* device_vender_name; @@ -606,6 +663,7 @@ class U3V { // Here PayloadSize is the one for U3V data devices_[i].u3v_payload_size_ = arv_device_get_integer_feature_value(devices_[i].device_, "PayloadSize", &err_); + log::info("\tDevice/USB {}::{} : {}", i, "PayloadSize", devices_[i].u3v_payload_size_); if (err_ ) { throw std::runtime_error(err_->message); } @@ -640,6 +698,7 @@ class U3V { // Check each parameters for GenDC device ========================== if (is_gendc_){ + log::info("\tDevice/USB {}::{} : {}", i, "GenDC", "Available"); uint64_t gendc_desc_size = arv_device_get_register_feature_length(devices_[i].device_, "GenDCDescriptor", &err_); if (err_) { throw std::runtime_error(err_->message); @@ -671,7 +730,7 @@ class U3V { }else{ devices_[i].data_offset_ = 0; devices_[i].image_payload_size_ = devices_[i].u3v_payload_size_; - log::info("The device is not GenDC supported"); + log::info("\tDevice/USB {}::{} : {}", i, "GenDC", "Not Supported"); } @@ -682,6 +741,8 @@ class U3V { if (arv_device_is_feature_available(devices_[i].device_, "AcquisitionFrameRate", &err_)){ fps = arv_device_get_float_feature_value(devices_[i].device_, "AcquisitionFrameRate", &err_); } + log::info("\tDevice/USB {}::{} : {}", i, "Width", wi); + log::info("\tDevice/USB {}::{} : {}", i, "Height", hi); int32_t px = pixel_format_ == "RGB8" ? PFNC_RGB8 : @@ -713,7 +774,7 @@ class U3V { devices_.resize(n_devices); buffers_.resize(n_devices); } - log::info("Device is running in {} operation mode", operation_mode_in_string); + log::info("\tDevice/USB {}::{} : {}", i, "OperationMode", operation_mode_in_string); } } @@ -725,30 +786,34 @@ class U3V { buffers_[i].push_back(b); arv_stream_push_buffer(devices_[i].stream_, b); } + log::info("\tDevice/USB {}::{} : {}", i, "Buffer Size", buffer_size); + log::info("\tDevice/USB {}::{} : {}", i, "Number of Buffers", n); + } - for (auto d : devices_) { - arv_device_set_string_feature_value(d.device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_); + for (auto i=0; imessage); } + log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode"); } - for (auto d : devices_) { - arv_device_execute_command(d.device_, "AcquisitionStop", &err_); + for (auto i=0; imessage); } + log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStop"); } - for (auto d : devices_) { - arv_device_execute_command(d.device_, "AcquisitionStart", &err_); + for (auto i=0; imessage); } + log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode"); } - - log::info("U3V instance is created: pixel_format({}) num_sensor({}) frame_sync({}) realtime_display_mode({}) dev_id({})", pixel_format, num_sensor, frame_sync, realtime_display_mode, dev_id); } void init_symbols_gobject() { @@ -946,7 +1011,7 @@ class U3V { bool is_param_integer_; int32_t operation_mode_; - uint64_t frame_cnt_; + uint32_t frame_cnt_; int32_t cameN_idx_; // genDC