2021-10-04 22:45:28 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include "cereal/visionipc/visionipc_server.h"
|
2022-05-18 14:11:57 -07:00
|
|
|
#include "common/queue.h"
|
2022-06-28 22:12:42 +08:00
|
|
|
#include "tools/replay/framereader.h"
|
|
|
|
|
#include "tools/replay/logreader.h"
|
2021-10-04 22:45:28 +08:00
|
|
|
|
|
|
|
|
class CameraServer {
|
|
|
|
|
public:
|
2022-05-14 19:55:12 -07:00
|
|
|
CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS] = nullptr);
|
2021-10-04 22:45:28 +08:00
|
|
|
~CameraServer();
|
2021-10-16 06:34:54 +08:00
|
|
|
void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
|
2022-05-12 21:11:04 +08:00
|
|
|
void waitForSent();
|
2021-10-04 22:45:28 +08:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
struct Camera {
|
2021-10-19 20:39:47 +08:00
|
|
|
CameraType type;
|
2022-05-14 19:55:12 -07:00
|
|
|
VisionStreamType stream_type;
|
2021-10-04 22:45:28 +08:00
|
|
|
int width;
|
|
|
|
|
int height;
|
2021-10-19 20:39:47 +08:00
|
|
|
std::thread thread;
|
|
|
|
|
SafeQueue<std::pair<FrameReader*, const cereal::EncodeIndex::Reader>> queue;
|
|
|
|
|
int cached_id = -1;
|
|
|
|
|
int cached_seg = -1;
|
2022-05-14 19:55:12 -07:00
|
|
|
VisionBuf * cached_buf;
|
2021-10-04 22:45:28 +08:00
|
|
|
};
|
2021-10-19 20:39:47 +08:00
|
|
|
void startVipcServer();
|
|
|
|
|
void cameraThread(Camera &cam);
|
2021-10-04 22:45:28 +08:00
|
|
|
|
|
|
|
|
Camera cameras_[MAX_CAMERAS] = {
|
2022-05-14 19:55:12 -07:00
|
|
|
{.type = RoadCam, .stream_type = VISION_STREAM_ROAD},
|
|
|
|
|
{.type = DriverCam, .stream_type = VISION_STREAM_DRIVER},
|
|
|
|
|
{.type = WideRoadCam, .stream_type = VISION_STREAM_WIDE_ROAD},
|
2021-10-04 22:45:28 +08:00
|
|
|
};
|
2021-10-16 06:34:54 +08:00
|
|
|
std::atomic<int> publishing_ = 0;
|
2021-10-04 22:45:28 +08:00
|
|
|
std::unique_ptr<VisionIpcServer> vipc_server_;
|
|
|
|
|
};
|