Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions post_processing_stages/imx500/imx500_post_processing_stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
#include <sstream>
#include <string>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <thread>
#include <unistd.h>

#include <linux/imx500.h>

#include <boost/property_tree/ptree.hpp>

#include "imx500_post_processing_stage.hpp"
Expand All @@ -33,7 +36,6 @@ namespace
{

const unsigned int ROI_CTRL_ID = 0x00982900;
const unsigned int NETWORK_FW_CTRL_ID = 0x00982901;

inline int16_t conv_reg_signed(int16_t reg)
{
Expand Down Expand Up @@ -122,8 +124,23 @@ void IMX500PostProcessingStage::Read(boost::property_tree::ptree const &params)

int fd = open(network_file.c_str(), O_RDONLY, 0);

v4l2_control ctrl { NETWORK_FW_CTRL_ID, fd };
int ret = ioctl(device_fd_, VIDIOC_S_CTRL, &ctrl);
struct stat stat;
int ret = fstat(fd, &stat);
if (ret)
throw std::runtime_error("Failed to get file stats for " + network_file);

struct imx500_network_weights network_weights;

network_weights.size = stat.st_size;
network_weights.data = malloc(stat.st_size);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naturally, the moment I opened the PR I noticed that I never free this.

if (!network_weights.data)
throw std::runtime_error("Failed to allocate buffer for network");

ret = read(fd, network_weights.data, network_weights.size);
if (ret < 0)
throw std::runtime_error("Failed to read network weights");

ret = ioctl(device_fd_, VIDIOC_IMX500_LOAD_NETWORK, &network_weights);
if (ret)
throw std::runtime_error("failed to set network fw ioctl");

Expand Down