2021-01-16 14:23:06 -08:00
|
|
|
#pragma once
|
2020-01-17 10:07:22 -08:00
|
|
|
|
2023-08-24 04:25:17 +08:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2022-10-06 12:17:22 +08:00
|
|
|
|
2021-06-13 14:31:00 +08:00
|
|
|
#include "cereal/gen/cpp/log.capnp.h"
|
2022-06-19 14:43:49 -07:00
|
|
|
#include "system/camerad/cameras/camera_common.h"
|
2024-04-23 10:21:42 +08:00
|
|
|
#include "tools/replay/util.h"
|
2021-08-31 10:33:00 +08:00
|
|
|
|
2021-06-13 14:31:00 +08:00
|
|
|
const CameraType ALL_CAMERAS[] = {RoadCam, DriverCam, WideRoadCam};
|
|
|
|
|
const int MAX_CAMERAS = std::size(ALL_CAMERAS);
|
2021-09-29 17:43:56 +02:00
|
|
|
|
2021-06-13 14:31:00 +08:00
|
|
|
class Event {
|
2020-01-17 10:07:22 -08:00
|
|
|
public:
|
2024-04-20 02:15:34 +08:00
|
|
|
Event(cereal::Event::Which which, uint64_t mono_time, const kj::ArrayPtr<const capnp::word> &data, int eidx_segnum = -1)
|
|
|
|
|
: which(which), mono_time(mono_time), data(data), eidx_segnum(eidx_segnum) {}
|
2021-06-13 14:31:00 +08:00
|
|
|
|
2024-04-22 08:09:17 +08:00
|
|
|
bool operator<(const Event &other) const {
|
|
|
|
|
return mono_time < other.mono_time || (mono_time == other.mono_time && which < other.which);
|
2021-10-18 17:10:08 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-13 14:31:00 +08:00
|
|
|
uint64_t mono_time;
|
|
|
|
|
cereal::Event::Which which;
|
2024-04-20 02:15:34 +08:00
|
|
|
kj::ArrayPtr<const capnp::word> data;
|
|
|
|
|
int32_t eidx_segnum;
|
2021-06-13 14:31:00 +08:00
|
|
|
};
|
|
|
|
|
|
2021-11-29 21:10:24 +08:00
|
|
|
class LogReader {
|
2021-06-13 14:31:00 +08:00
|
|
|
public:
|
2024-04-23 10:21:42 +08:00
|
|
|
LogReader(const std::vector<bool> &filters = {}) { filters_ = filters; }
|
2023-11-14 01:19:39 +08:00
|
|
|
bool load(const std::string &url, std::atomic<bool> *abort = nullptr,
|
2022-10-06 12:17:22 +08:00
|
|
|
bool local_cache = false, int chunk_size = -1, int retries = 0);
|
2024-04-22 08:09:17 +08:00
|
|
|
bool load(const char *data, size_t size, std::atomic<bool> *abort = nullptr);
|
|
|
|
|
std::vector<Event> events;
|
2021-01-16 14:23:06 -08:00
|
|
|
|
2021-06-13 14:31:00 +08:00
|
|
|
private:
|
2021-10-04 21:39:59 +08:00
|
|
|
std::string raw_;
|
2024-04-23 10:21:42 +08:00
|
|
|
std::vector<bool> filters_;
|
|
|
|
|
MonotonicBuffer buffer_{1024 * 1024};
|
2020-01-17 10:07:22 -08:00
|
|
|
};
|