#pragma once #include #include "cereal/gen/cpp/log.capnp.h" #include "selfdrive/camerad/cameras/camera_common.h" const CameraType ALL_CAMERAS[] = {RoadCam, DriverCam, WideRoadCam}; const int MAX_CAMERAS = std::size(ALL_CAMERAS); const int DEFAULT_EVENT_MEMORY_POOL_BLOCK_SIZE = 65000; class Event { public: Event(cereal::Event::Which which, uint64_t mono_time) : reader(kj::ArrayPtr{}) { // construct a dummy Event for binary search, e.g std::upper_bound this->which = which; this->mono_time = mono_time; } Event(const kj::ArrayPtr &amsg, bool frame = false); inline kj::ArrayPtr bytes() const { return words.asBytes(); } struct lessThan { inline bool operator()(const Event *l, const Event *r) { return l->mono_time < r->mono_time || (l->mono_time == r->mono_time && l->which < r->which); } }; void *operator new(size_t size, std::pmr::monotonic_buffer_resource *mbr) { return mbr->allocate(size); } void operator delete(void *ptr) { // No-op. memory used by EventMemoryPool increases monotonically until the logReader is destroyed. } uint64_t mono_time; cereal::Event::Which which; cereal::Event::Reader event; capnp::FlatArrayMessageReader reader; kj::ArrayPtr words; bool frame; }; class LogReader { public: LogReader(size_t memory_pool_block_size = DEFAULT_EVENT_MEMORY_POOL_BLOCK_SIZE); ~LogReader(); bool load(const std::string &file); std::vector events; private: std::string raw_; std::pmr::monotonic_buffer_resource *mbr_ = nullptr; void *pool_buffer_ = nullptr; };