Skip to content

Commit

Permalink
dd
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 15, 2023
1 parent 014595c commit a52b64c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
10 changes: 5 additions & 5 deletions tools/replay/camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ std::tuple<size_t, size_t, size_t> get_nv12_info(int width, int height) {
return {nv12_width, nv12_height, nv12_buffer_size};
}

CameraServer::CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS]) {
for (int i = 0; i < MAX_CAMERAS; ++i) {
CameraServer::CameraServer(std::pair<int, int> camera_size[VISION_STREAM_MAX]) {
for (int i = 0; i < VISION_STREAM_MAX; ++i) {
std::tie(cameras_[i].width, cameras_[i].height) = camera_size[i];
}
startVipcServer();
Expand All @@ -36,7 +36,7 @@ void CameraServer::startVipcServer() {
vipc_server_.reset(new VisionIpcServer("camerad"));
for (auto &cam : cameras_) {
if (cam.width > 0 && cam.height > 0) {
rInfo("camera[%d] frame size %dx%d", cam.type, cam.width, cam.height);
rInfo("camera[%d] frame size %dx%d", cam.stream_type, cam.width, cam.height);
auto [nv12_width, nv12_height, nv12_buffer_size] = get_nv12_info(cam.width, cam.height);
vipc_server_->create_buffers_with_sizes(cam.stream_type, YUV_BUFFER_COUNT, false, cam.width, cam.height,
nv12_buffer_size, nv12_width, nv12_width * nv12_height);
Expand Down Expand Up @@ -72,7 +72,7 @@ void CameraServer::cameraThread(Camera &cam) {
yuv->set_frame_id(eidx.getFrameId());
vipc_server_->send(yuv, &extra);
} else {
rError("camera[%d] failed to get frame: %lu", cam.type, eidx.getSegmentId());
rError("camera[%d] failed to get frame: %lu", cam.stream_type, eidx.getSegmentId());
}

cam.cached_id = id + 1;
Expand All @@ -83,7 +83,7 @@ void CameraServer::cameraThread(Camera &cam) {
}
}

void CameraServer::pushFrame(CameraType type, FrameReader *fr, const cereal::EncodeIndex::Reader &eidx) {
void CameraServer::pushFrame(VisionStreamType type, FrameReader *fr, const cereal::EncodeIndex::Reader &eidx) {
auto &cam = cameras_[type];
if (cam.width != fr->width || cam.height != fr->height) {
cam.width = fr->width;
Expand Down
15 changes: 8 additions & 7 deletions tools/replay/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <unistd.h>

#include <array>
#include <memory>
#include <tuple>
#include <utility>
Expand All @@ -15,9 +16,9 @@ std::tuple<size_t, size_t, size_t> get_nv12_info(int width, int height);

class CameraServer {
public:
CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS] = nullptr);
CameraServer(std::pair<int, int> camera_size[VISION_STREAM_MAX] = nullptr);
~CameraServer();
void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
void pushFrame(VisionStreamType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
void waitForSent();

protected:
Expand All @@ -34,11 +35,11 @@ class CameraServer {
void startVipcServer();
void cameraThread(Camera &cam);

Camera cameras_[] = {
{.stream_type = VISION_STREAM_ROAD},
{.stream_type = VISION_STREAM_DRIVER},
{.stream_type = VISION_STREAM_WIDE_ROAD},
};
std::array<Camera, 3> cameras_ = {
Camera{.stream_type = VISION_STREAM_ROAD},
Camera{.stream_type = VISION_STREAM_DRIVER},
Camera{.stream_type = VISION_STREAM_WIDE_ROAD},
};
std::atomic<int> publishing_ = 0;
std::unique_ptr<VisionIpcServer> vipc_server_;
};
16 changes: 8 additions & 8 deletions tools/replay/replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ void Replay::startStream(const Segment *cur_segment) {

// start camera server
if (!hasFlag(REPLAY_FLAG_NO_VIPC)) {
std::pair<int, int> camera_size[MAX_CAMERAS] = {};
for (auto type : ALL_CAMERAS) {
std::pair<int, int> camera_size[VISION_STREAM_MAX] = {};
for (int type = 0; type < VISION_STREAM_MAX; ++type) {
if (auto &fr = cur_segment->frames[type]) {
camera_size[type] = {fr->width, fr->height};
}
Expand Down Expand Up @@ -345,19 +345,19 @@ void Replay::publishMessage(const Event *e) {
}

void Replay::publishFrame(const Event *e) {
static const std::map<cereal::Event::Which, CameraType> cam_types{
{cereal::Event::ROAD_ENCODE_IDX, RoadCam},
{cereal::Event::DRIVER_ENCODE_IDX, DriverCam},
{cereal::Event::WIDE_ROAD_ENCODE_IDX, WideRoadCam},
static const std::map<cereal::Event::Which, VisionStreamType> cam_types{
{cereal::Event::ROAD_ENCODE_IDX, VISION_STREAM_ROAD},
{cereal::Event::DRIVER_ENCODE_IDX, VISION_STREAM_DRIVER},
{cereal::Event::WIDE_ROAD_ENCODE_IDX, VISION_STREAM_WIDE_ROAD},
};
if ((e->which == cereal::Event::DRIVER_ENCODE_IDX && !hasFlag(REPLAY_FLAG_DCAM)) ||
(e->which == cereal::Event::WIDE_ROAD_ENCODE_IDX && !hasFlag(REPLAY_FLAG_ECAM))) {
return;
}
auto eidx = capnp::AnyStruct::Reader(e->event).getPointerSection()[0].getAs<cereal::EncodeIndex>();
if (eidx.getType() == cereal::EncodeIndex::Type::FULL_H_E_V_C && isSegmentMerged(eidx.getSegmentNum())) {
CameraType cam = cam_types.at(e->which);
camera_server_->pushFrame(cam, segments_[eidx.getSegmentNum()]->frames[cam].get(), eidx);
VisionStreamType steam_type = cam_types.at(e->which);
camera_server_->pushFrame(cam, segments_[eidx.getSegmentNum()]->frames[steam_type].get(), eidx);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/replay/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Segment : public QObject {

const int seg_num = 0;
std::unique_ptr<LogReader> log;
std::unique_ptr<FrameReader> frames[MAX_CAMERAS] = {};
std::unique_ptr<FrameReader> frames[VISION_STREAM_MAX] = {};

signals:
void loadFinished(bool success);
Expand Down

0 comments on commit a52b64c

Please sign in to comment.