Skip to content

Commit

Permalink
Merging Release v4.6.2 changes (SHA: 53b3618~).
Browse files Browse the repository at this point in the history
  • Loading branch information
coashby committed Jul 17, 2024
2 parents cd47184 + 53b3618 commit c579bf1
Show file tree
Hide file tree
Showing 20 changed files with 276 additions and 369 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option(BUILD_TESTING "Build OpenEB's test suite" OFF)

cmake_minimum_required(VERSION 3.5)

project(metavision VERSION 4.6.1)
project(metavision VERSION 4.6.2)
set(PROJECT_VERSION_SUFFIX "")

if(PROJECT_VERSION_SUFFIX STREQUAL "")
Expand Down
4 changes: 2 additions & 2 deletions cmake/custom_functions/add_library_version_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# See the License for the specific language governing permissions and limitations under the License.

set(GIT_BRANCH "main")
set(GIT_COMMIT_ID "4bade2b1aeb57e36ba22a68e4270470d9d4d8715")
set(GIT_COMMIT_DATE "2024-06-14 10:34:56 +0000")
set(GIT_COMMIT_ID "9c0f658666f1927050f21407f6c0f5ae2e120f1f")
set(GIT_COMMIT_DATE "2024-07-01 15:48:10 +0200")

find_program(GIT_SCM git DOC "Git version control" HINTS "C:\\Program Files\\Git\\bin\\")

Expand Down
4 changes: 2 additions & 2 deletions cmake/custom_targets/README_metavision_open.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ python3 -m pip install "numba==0.56.3" "profilehooks==1.12.0" "pytorch_lightning

### Compilation

1. Retrieve the code: `git clone https://github.com/prophesee-ai/openeb.git --branch 4.6.1`.
1. Retrieve the code: `git clone https://github.com/prophesee-ai/openeb.git --branch 4.6.2`.
(If you choose to download an archive of OpenEB from GitHub rather than cloning the repository,
you need to ensure that you select a ``Full.Source.Code.*`` archive instead of using
the automatically generated ``Source.Code.*`` archives. This is because the latter do not include
Expand Down Expand Up @@ -324,7 +324,7 @@ python -m pip install "numba==0.56.3" "profilehooks==1.12.0" "pytorch_lightning=
First, retrieve the codebase:
```bash
git clone https://github.com/prophesee-ai/openeb.git --branch 4.6.1
git clone https://github.com/prophesee-ai/openeb.git --branch 4.6.2
```
Note that if you choose to download an archive of OpenEB from GitHub rather than cloning the repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function(copy_cpp_sample path)
endif ()
endfunction()

function(copy_python_sample path)
function(copy_python_sample path exclude_files)
set(sample_path ${PROJECT_SOURCE_DIR}/${path})
if (EXISTS ${sample_path})
get_filename_component(dest_folder_name "${sample_path}" NAME)
Expand All @@ -59,14 +59,19 @@ function(copy_python_sample path)
PATTERN __pycache__ EXCLUDE
)
file (REMOVE ${dest_path}${dest_folder_name}/CMakeLists.txt)
foreach (file ${exclude_files})
if (EXISTS "${sample_path}/${file}")
file (REMOVE "${dest_path}${dest_folder_name}/${file}")
endif ()
endforeach(file)
else()
message(FATAL_ERROR "The requested sample does not exist: ${sample_path}")
endif ()
endfunction()

# Add some Metavision Python samples to the metavision-get-started folder
copy_python_sample("sdk/modules/core/python/samples/metavision_time_surface")
copy_python_sample("sdk/modules/ml/python_extended/samples/flow_inference")
copy_python_sample("sdk/modules/core/python/samples/metavision_time_surface" "")
copy_python_sample("sdk/modules/ml/python_extended/samples/flow_inference" "flow_viz.py")

# Add some Metavision C++ samples to the metavision-get-started folder
copy_cpp_sample("sdk/modules/core/cpp/samples/metavision_time_surface")
Expand Down
5 changes: 5 additions & 0 deletions hal/cpp/include/metavision/hal/utils/data_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ class DataTransfer {
/// to do so in the scope of the run_impl method to avoid concurrent calls
virtual void stop_impl();

/// @brief Notify the internal thread that it shall stop
///
/// This method makes a thread-safe update of should_stop() return value
void notify_stop();

/// @brief Trigger all registered callbacks
/// @param buffer The data to be carried forward
void fire_callbacks(const BufferPtr buffer) const;
Expand Down
4 changes: 3 additions & 1 deletion hal/cpp/src/facilities/i_events_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@ I_EventsStream::~I_EventsStream() {
abort_index_building_ = true;
index_build_thread_.join();
}
stop();
try {
stop();
} catch (const std::exception &e) { MV_LOG_ERROR() << "I_EventsStream::stop() raised an exception : " << e.what(); }
data_transfer_.reset(nullptr);
data_transfer_connection_error_ = nullptr;
}
Expand Down
28 changes: 16 additions & 12 deletions hal/cpp/src/utils/data_transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,13 @@ void DataTransfer::start() {
suspend_cond_.wait(lock, [this] { return !suspend_ || stop_; });
}
}
} catch (std::exception &e) {
} catch (const std::exception &) {
for (auto cb : transfer_error_cbs_) {
cb.second(std::current_exception());
}
}

{
std::lock(suspend_mutex_, running_mutex_);
std::unique_lock<std::mutex> lock1(suspend_mutex_, std::adopt_lock);
std::unique_lock<std::mutex> lock2(running_mutex_, std::adopt_lock);
stop_ = true;
}
suspend_cond_.notify_all();
running_cond_.notify_all();
notify_stop();

for (auto cb : status_change_cbs_) {
cb.second(Status::Stopped);
Expand All @@ -111,7 +104,20 @@ void DataTransfer::stop() {
return;
}

stop_impl();
try {
stop_impl();
} catch (const HalConnectionException &) {
notify_stop();
// We can't be sure the thread will terminate
run_transfers_thread_.detach();
throw;
}

notify_stop();
run_transfers_thread_.join();
}

void DataTransfer::notify_stop() {
{
std::lock(suspend_mutex_, running_mutex_);
std::unique_lock<std::mutex> lock1(suspend_mutex_, std::adopt_lock);
Expand All @@ -120,8 +126,6 @@ void DataTransfer::stop() {
}
suspend_cond_.notify_all();
running_cond_.notify_all();

run_transfers_thread_.join();
}

void DataTransfer::suspend() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class LibUSBDevice {
void interrupt_transfer(unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout);

void force_release();

friend void libusb_fill_control_transfer(struct libusb_transfer *transfer, std::shared_ptr<LibUSBDevice> dev,
unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
unsigned int timeout) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,31 @@
namespace Metavision {

class PseeLibUSBDataTransfer : public Metavision::DataTransfer {
using EpId = unsigned char;

public:
static DataTransfer::BufferPool make_buffer_pool(size_t max_pool_byte_size = 0);

PseeLibUSBDataTransfer(const std::shared_ptr<LibUSBDevice> dev, int endpoint, uint32_t raw_event_size_bytes,
PseeLibUSBDataTransfer(const std::shared_ptr<LibUSBDevice> dev, EpId endpoint, uint32_t raw_event_size_bytes,
const DataTransfer::BufferPool &buffer_pool = make_buffer_pool());
~PseeLibUSBDataTransfer() override;

private:
void start_impl(BufferPtr buffer) override final;
void run_impl() override final;
void stop_impl() override final;
void flush();

class UserParamForAsyncBulkCallback;

void preprocess_transfer(libusb_transfer *transfer);
void initiate_async_transfers();
void release_async_transfers();
void run_transfers();

std::shared_ptr<LibUSBDevice> dev_;
int bEpCommAddress_;

std::mutex protect_vtransfert_;
std::vector<std::unique_ptr<UserParamForAsyncBulkCallback>> vtransfer_;

std::atomic<uint32_t> active_bulks_transfers_{0};
EpId bEpCommAddress_;

// USB Commands
libusb_transfer *construct_async_bulk_transfer(unsigned char *buf, int packet_size,
libusb_transfer_cb_fn async_bulk_cb, void *user_data,
unsigned int timeout);
static void free_async_bulk_transfer(libusb_transfer *transfer);
static int submit_transfer(libusb_transfer *transfer);
void prepare_async_bulk_transfer(libusb_transfer *transfer, unsigned char *buf, int packet_size,
libusb_transfer_cb_fn async_bulk_cb, void *user_data, unsigned int timeout);
class AsyncTransfer;
std::vector<AsyncTransfer> vtransfer_;
uint32_t timeout_cnt_;

static const size_t packet_size_;
static const size_t async_transfer_num_;
static const unsigned int timeout_;
};

} // namespace Metavision
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class StreamFormat;

class TzDevice : public std::enable_shared_from_this<TzDevice> {
public:
std::string get_name();
std::string get_name(); // get the name on from the device
const std::string &name() const; // get the local copy of the name
std::vector<std::string> get_compatible();
virtual void get_device_info(I_HW_Identification::SystemInfo &info, std::string prefix);
virtual DeviceConfigOptionMap get_device_config_options() const;
Expand All @@ -57,11 +58,13 @@ class TzDevice : public std::enable_shared_from_this<TzDevice> {
virtual void initialize();
virtual void destroy();

std::string name;
std::shared_ptr<TzDevice> parent;
std::weak_ptr<TzDevice> child;
std::shared_ptr<Metavision::TzLibUSBBoardCommand> cmd;
uint32_t tzID;

private:
std::string name_;
};

} // namespace Metavision
Expand Down
60 changes: 1 addition & 59 deletions hal_psee_plugins/src/boards/utils/psee_libusb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,117 +54,67 @@ LibUSBDevice::LibUSBDevice(std::shared_ptr<LibUSBContext> libusb_ctx, uint16_t v
}

LibUSBDevice::~LibUSBDevice() {
if (dev_handle_) {
libusb_close(dev_handle_);
}
libusb_close(dev_handle_);
}

libusb_context *LibUSBDevice::ctx() {
return libusb_ctx_->ctx();
}

libusb_device *LibUSBDevice::get_device() {
if (!dev_handle_) {
return nullptr;
}
return libusb_get_device(dev_handle_);
}

int LibUSBDevice::get_configuration(int *config) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_get_configuration(dev_handle_, config);
}

int LibUSBDevice::set_configuration(int configuration) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_set_configuration(dev_handle_, configuration);
}

int LibUSBDevice::claim_interface(int interface_number) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_claim_interface(dev_handle_, interface_number);
}

int LibUSBDevice::release_interface(int interface_number) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_release_interface(dev_handle_, interface_number);
}

int LibUSBDevice::set_interface_alt_setting(int interface_number, int alternate_setting) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_set_interface_alt_setting(dev_handle_, interface_number, alternate_setting);
}

int LibUSBDevice::clear_halt(unsigned char endpoint) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_clear_halt(dev_handle_, endpoint);
}

int LibUSBDevice::reset_device() {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_reset_device(dev_handle_);
}

void LibUSBDevice::force_release() {
reset_device();
dev_handle_ = nullptr;
}

int LibUSBDevice::kernel_driver_active(int interface_number) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_kernel_driver_active(dev_handle_, interface_number);
}

int LibUSBDevice::detach_kernel_driver(int interface_number) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_detach_kernel_driver(dev_handle_, interface_number);
}

int LibUSBDevice::attach_kernel_driver(int interface_number) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_attach_kernel_driver(dev_handle_, interface_number);
}

int LibUSBDevice::set_auto_detach_kernel_driver(int enable) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_set_auto_detach_kernel_driver(dev_handle_, enable);
}

int LibUSBDevice::get_string_descriptor_ascii(uint8_t desc_index, unsigned char *data, int length) {
if (!dev_handle_) {
return LIBUSB_ERROR_NO_DEVICE;
}
return libusb_get_string_descriptor_ascii(dev_handle_, desc_index, data, length);
}

void LibUSBDevice::control_transfer(uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
unsigned char *data, uint16_t wLength, unsigned int timeout) {
if (!dev_handle_) {
throw HalConnectionException(LIBUSB_ERROR_NO_DEVICE, libusb_error_category());
}

int res;
res = libusb_control_transfer(dev_handle_, bmRequestType, bRequest, wValue, wIndex, data, wLength, timeout);
if (res < 0) {
Expand All @@ -174,10 +124,6 @@ void LibUSBDevice::control_transfer(uint8_t bmRequestType, uint8_t bRequest, uin

void LibUSBDevice::bulk_transfer(unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout) {
if (!dev_handle_) {
throw HalConnectionException(LIBUSB_ERROR_NO_DEVICE, libusb_error_category());
}

int res;
res = libusb_bulk_transfer(dev_handle_, endpoint, data, length, transferred, timeout);
if (res < 0) {
Expand All @@ -187,10 +133,6 @@ void LibUSBDevice::bulk_transfer(unsigned char endpoint, unsigned char *data, in

void LibUSBDevice::interrupt_transfer(unsigned char endpoint, unsigned char *data, int length, int *transferred,
unsigned int timeout) {
if (!dev_handle_) {
throw HalConnectionException(LIBUSB_ERROR_NO_DEVICE, libusb_error_category());
}

int res;
res = libusb_interrupt_transfer(dev_handle_, endpoint, data, length, transferred, timeout);
if (res < 0) {
Expand Down
Loading

0 comments on commit c579bf1

Please sign in to comment.