Skip to content

Commit

Permalink
Merge pull request #317 from fixstars/fix/main-acq-before-stream
Browse files Browse the repository at this point in the history
Fix/acq before stream-main-branch
  • Loading branch information
iitaku authored Aug 19, 2024
2 parents 1670002 + 1caa6f4 commit 943b26e
Showing 1 changed file with 76 additions and 55 deletions.
131 changes: 76 additions & 55 deletions src/bb/image-io/rt_u3v.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class U3V {
ARV_DEVICE_STATUS_WRITE_ERROR
}ArvDeviceStatus_t;

typedef enum ArvUvUsbMode{
ARV_UV_USB_MODE_SYNC,
ARV_UV_USB_MODE_ASYNC,
ARV_UV_USB_MODE_DEFAULT = ARV_UV_USB_MODE_ASYNC
} ArvUvUsbMode_t;

using ArvDevice_t = struct ArvDevice*;
using ArvFakeDevice_t = struct ArvFakeDevice*;
using ArvStream_t = struct ArvStream*;
Expand Down Expand Up @@ -153,6 +159,8 @@ class U3V {
using arv_camera_create_stream_t = ArvStream*(*)(ArvCamera*, ArvStreamCallback*, void*, GError**);
using arv_fake_device_get_fake_camera_t = ArvCamera*(*)(ArvFakeDevice*);

using arv_uv_device_set_usb_mode_t = void(*)(ArvDevice *, ArvUvUsbMode );

struct DeviceInfo {
const char* dev_id_;
ArvDevice* device_;
Expand Down Expand Up @@ -410,6 +418,7 @@ class U3V {
GET_SYMBOL(arv_set_fake_camera_genicam_filename, "arv_set_fake_camera_genicam_filename");
GET_SYMBOL(arv_enable_interface, "arv_enable_interface");
GET_SYMBOL(arv_fake_device_get_fake_camera, "arv_fake_device_get_fake_camera");
GET_SYMBOL(arv_uv_device_set_usb_mode, "arv_uv_device_set_usb_mode");
#undef GET_SYMBOL
}

Expand Down Expand Up @@ -531,6 +540,8 @@ class U3V {
arv_set_fake_camera_genicam_filename_t arv_set_fake_camera_genicam_filename;
arv_fake_device_get_fake_camera_t arv_fake_device_get_fake_camera;

arv_uv_device_set_usb_mode_t arv_uv_device_set_usb_mode;

static std::map<std::string, std::shared_ptr<U3V>> instances_;

int32_t num_sensor_; //SENSOR NUMBER
Expand Down Expand Up @@ -650,9 +661,8 @@ class U3VFakeCam : public U3V{
}

// Start streaming and start acquisition
devices_[0].stream_ = arv_device_create_stream (devices_[0].device_, NULL, NULL, &err_);
if (num_sensor_==2){
devices_[1].stream_ = arv_device_create_stream (devices_[1].device_, NULL, NULL, &err_);
for (auto i=0; i<devices_.size(); ++i) {
devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, NULL, NULL, &err_);
}

for (auto i=0; i<devices_.size(); ++i) {
Expand Down Expand Up @@ -858,9 +868,8 @@ class U3VRealCam: public U3V{
}

// Start streaming and start acquisition
devices_[0].stream_ = arv_device_create_stream (devices_[0].device_, NULL, NULL, &err_);
if (num_sensor_==2){
devices_[1].stream_ = arv_device_create_stream (devices_[1].device_, NULL, NULL, &err_);
for (auto i=0; i<devices_.size(); ++i) {
devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, NULL, NULL, &err_);
}

for (auto i=0; i<devices_.size(); ++i) {
Expand Down Expand Up @@ -918,14 +927,6 @@ class U3VRealCam: public U3V{
throw std::runtime_error(err_->message);
}

devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, nullptr, nullptr, &err_);
if (err_ ) {
throw std::runtime_error(err_->message);
}
if (devices_[i].stream_ == nullptr) {
throw std::runtime_error("stream is null");
}

// check it the device has gendc mode ==============================
is_gendc_ = arv_device_is_feature_available(devices_[i].device_, "GenDCDescriptor", &err_);
if (err_) {
Expand All @@ -945,6 +946,7 @@ class U3VRealCam: public U3V{
if (strcmp(device_model_name, " ")==0){
is_param_integer_ = true;
frame_count_method_ = FrameCountMethod::TIMESTAMP;
arv_uv_device_set_usb_mode(devices_[i].device_, ARV_UV_USB_MODE_SYNC); //hotfix for v1.0
}
if (is_gendc_){
frame_count_method_ = FrameCountMethod::TYPESPECIFIC3;
Expand Down Expand Up @@ -1048,6 +1050,34 @@ class U3VRealCam: public U3V{
}
log::info("\tDevice/USB {}::{} : {}", i, "OperationMode", operation_mode_in_string);
}

arv_device_set_string_feature_value(devices_[i].device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode");

arv_device_execute_command(devices_[i].device_, "AcquisitionStart", &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStart");
}
/*
* ion-kit starts the acquisition before stream creation This is a tentative fix only in ion-kit due to hardware issue
* In aravis, the acquisition should be done afterward. Since this maps better with GenAPI, where buffers
* must be pushed to DataStream objectsbefore DataStream acquisition is started.
*/

//start streaming after AcquisitionStart
for (auto i=0; i<devices_.size(); ++i) {
devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, nullptr, nullptr, &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
if (devices_[i].stream_ == nullptr) {
throw std::runtime_error("stream is null");
}
}

for (auto i=0; i<devices_.size(); ++i) {
Expand All @@ -1063,21 +1093,6 @@ class U3VRealCam: public U3V{

}

for (auto i=0; i<devices_.size(); ++i) {
arv_device_set_string_feature_value(devices_[i].device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode");
}

for (auto i=0; i<devices_.size(); ++i) {
arv_device_execute_command(devices_[i].device_, "AcquisitionStart", &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStart");
}
}
};

Expand Down Expand Up @@ -1346,9 +1361,8 @@ class U3VGenDC: public U3V{
}

// Start streaming and start acquisition
devices_[0].stream_ = arv_device_create_stream (devices_[0].device_, NULL, NULL, &err_);
if (num_sensor_==2){
devices_[1].stream_ = arv_device_create_stream (devices_[1].device_, NULL, NULL, &err_);
for (auto i=0; i<devices_.size(); ++i) {
devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, NULL, NULL, &err_);
}

for (auto i=0; i<devices_.size(); ++i) {
Expand Down Expand Up @@ -1406,14 +1420,6 @@ class U3VGenDC: public U3V{
throw std::runtime_error(err_->message);
}

devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, nullptr, nullptr, &err_);
if (err_ ) {
throw std::runtime_error(err_->message);
}
if (devices_[i].stream_ == nullptr) {
throw std::runtime_error("stream is null");
}

// check it the device has gendc mode ==============================
is_gendc_ = arv_device_is_feature_available(devices_[i].device_, "GenDCDescriptor", &err_);
if (err_) {
Expand Down Expand Up @@ -1533,6 +1539,36 @@ class U3VGenDC: public U3V{
}
log::info("\tDevice/USB {}::{} : {}", i, "OperationMode", operation_mode_in_string);
}

arv_device_set_string_feature_value(devices_[i].device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode");

arv_device_execute_command(devices_[i].device_, "AcquisitionStart", &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStart");
}

/*
* ion-kit starts the acquisition before stream creation This is a tentative fix only in ion-kit due to hardware issue
* In aravis, the acquisition should be done afterward. Since this maps better with GenAPI, where buffers
* must be pushed to DataStream objectsbefore DataStream acquisition is started.
* refer to https://github.com/AravisProject/aravis/blob/2ebaa8661761ea4bbc4df878aa67b4a9e1a9a3b9/docs/reference/aravis/porting-0.10.md
*/

//start streaming after AcquisitionStart
for (auto i=0; i<devices_.size(); ++i) {
devices_[i].stream_ = arv_device_create_stream(devices_[i].device_, nullptr, nullptr, &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
if (devices_[i].stream_ == nullptr) {
throw std::runtime_error("stream is null");
}
}

for (auto i=0; i<devices_.size(); ++i) {
Expand All @@ -1548,21 +1584,6 @@ class U3VGenDC: public U3V{

}

for (auto i=0; i<devices_.size(); ++i) {
arv_device_set_string_feature_value(devices_[i].device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionMode");
}

for (auto i=0; i<devices_.size(); ++i) {
arv_device_execute_command(devices_[i].device_, "AcquisitionStart", &err_);
if (err_) {
throw std::runtime_error(err_->message);
}
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStart");
}
}
};

Expand Down

0 comments on commit 943b26e

Please sign in to comment.