logreader.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include "cereal/gen/cpp/log.capnp.h"
  5. #include "tools/replay/util.h"
  6. const CameraType ALL_CAMERAS[] = {RoadCam, DriverCam, WideRoadCam};
  7. const int MAX_CAMERAS = std::size(ALL_CAMERAS);
  8. class Event {
  9. public:
  10. Event(cereal::Event::Which which, uint64_t mono_time, const kj::ArrayPtr<const capnp::word> &data, int eidx_segnum = -1)
  11. : which(which), mono_time(mono_time), data(data), eidx_segnum(eidx_segnum) {}
  12. bool operator<(const Event &other) const {
  13. return mono_time < other.mono_time || (mono_time == other.mono_time && which < other.which);
  14. }
  15. uint64_t mono_time;
  16. cereal::Event::Which which;
  17. kj::ArrayPtr<const capnp::word> data;
  18. int32_t eidx_segnum;
  19. };
  20. class LogReader {
  21. public:
  22. LogReader(const std::vector<bool> &filters = {}) { filters_ = filters; }
  23. bool load(const std::string &url, std::atomic<bool> *abort = nullptr,
  24. bool local_cache = false, int chunk_size = -1, int retries = 0);
  25. bool load(const char *data, size_t size, std::atomic<bool> *abort = nullptr);
  26. std::vector<Event> events;
  27. private:
  28. void migrateOldEvents();
  29. std::string raw_;
  30. bool requires_migration = true;
  31. std::vector<bool> filters_;
  32. MonotonicBuffer buffer_{1024 * 1024};
  33. };