mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-08-05 08:16:06 +08:00
camerad: close file descriptors (#2065)
* close file descriptors * fix struct indent * add some new lines
This commit is contained in:
@@ -548,7 +548,7 @@ static void imx298_ois_calibration(int ois_fd, uint8_t* eeprom) {
|
||||
static void sensors_init(MultiCameraState *s) {
|
||||
int err;
|
||||
|
||||
int sensorinit_fd = -1;
|
||||
unique_fd sensorinit_fd;
|
||||
if (s->device == DEVICE_LP3) {
|
||||
sensorinit_fd = open("/dev/v4l-subdev11", O_RDWR | O_NONBLOCK);
|
||||
} else {
|
||||
@@ -1866,13 +1866,13 @@ void cameras_open(MultiCameraState *s, VisionBuf *camera_bufs_rear, VisionBuf *c
|
||||
assert(camera_bufs_rear);
|
||||
assert(camera_bufs_front);
|
||||
|
||||
int msmcfg_fd = open("/dev/media0", O_RDWR | O_NONBLOCK);
|
||||
assert(msmcfg_fd >= 0);
|
||||
s->msmcfg_fd = open("/dev/media0", O_RDWR | O_NONBLOCK);
|
||||
assert(s->msmcfg_fd >= 0);
|
||||
|
||||
sensors_init(s);
|
||||
|
||||
int v4l_fd = open("/dev/video0", O_RDWR | O_NONBLOCK);
|
||||
assert(v4l_fd >= 0);
|
||||
s->v4l_fd = open("/dev/video0", O_RDWR | O_NONBLOCK);
|
||||
assert(s->v4l_fd >= 0);
|
||||
|
||||
if (s->device == DEVICE_LP3) {
|
||||
s->ispif_fd = open("/dev/v4l-subdev15", O_RDWR | O_NONBLOCK);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "common/mat.h"
|
||||
#include "common/visionbuf.h"
|
||||
#include "common/buffering.h"
|
||||
#include "common/utilpp.h"
|
||||
|
||||
#include "camera_common.h"
|
||||
|
||||
@@ -69,13 +70,13 @@ typedef struct CameraState {
|
||||
uint32_t line_length_pclk;
|
||||
unsigned int max_gain;
|
||||
|
||||
int csid_fd;
|
||||
int csiphy_fd;
|
||||
int sensor_fd;
|
||||
int isp_fd;
|
||||
int eeprom_fd;
|
||||
unique_fd csid_fd;
|
||||
unique_fd csiphy_fd;
|
||||
unique_fd sensor_fd;
|
||||
unique_fd isp_fd;
|
||||
unique_fd eeprom_fd;
|
||||
// rear only
|
||||
int ois_fd, actuator_fd;
|
||||
unique_fd ois_fd, actuator_fd;
|
||||
uint16_t infinity_dac;
|
||||
|
||||
struct msm_vfe_axi_stream_cfg_cmd stream_cfg;
|
||||
@@ -126,7 +127,9 @@ typedef struct CameraState {
|
||||
typedef struct MultiCameraState {
|
||||
int device;
|
||||
|
||||
int ispif_fd;
|
||||
unique_fd ispif_fd;
|
||||
unique_fd msmcfg_fd;
|
||||
unique_fd v4l_fd;
|
||||
|
||||
CameraState rear;
|
||||
CameraState front;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "common/mat.h"
|
||||
#include "common/visionbuf.h"
|
||||
#include "common/buffering.h"
|
||||
#include "common/utilpp.h"
|
||||
|
||||
#include "camera_common.h"
|
||||
|
||||
@@ -40,12 +41,12 @@ typedef struct CameraState {
|
||||
int device_iommu;
|
||||
int cdm_iommu;
|
||||
|
||||
int video0_fd;
|
||||
int video1_fd;
|
||||
int isp_fd;
|
||||
unique_fd video0_fd;
|
||||
unique_fd video1_fd;
|
||||
unique_fd isp_fd;
|
||||
|
||||
int sensor_fd;
|
||||
int csiphy_fd;
|
||||
unique_fd sensor_fd;
|
||||
unique_fd csiphy_fd;
|
||||
|
||||
int camera_num;
|
||||
|
||||
@@ -75,9 +76,9 @@ typedef struct CameraState {
|
||||
typedef struct MultiCameraState {
|
||||
int device;
|
||||
|
||||
int video0_fd;
|
||||
int video1_fd;
|
||||
int isp_fd;
|
||||
unique_fd video0_fd;
|
||||
unique_fd video1_fd;
|
||||
unique_fd isp_fd;
|
||||
|
||||
CameraState rear;
|
||||
CameraState front;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef UTILPP_H
|
||||
#define UTILPP_H
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
@@ -63,4 +62,16 @@ inline std::string readlink(std::string path) {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
struct unique_fd {
|
||||
unique_fd(int fd = -1) : fd_(fd) {}
|
||||
unique_fd& operator=(unique_fd&& uf) {
|
||||
fd_ = uf.fd_;
|
||||
uf.fd_ = -1;
|
||||
return *this;
|
||||
}
|
||||
~unique_fd() {
|
||||
if (fd_ != -1) close(fd_);
|
||||
}
|
||||
operator int() const { return fd_; }
|
||||
int fd_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user