You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.5 KiB
56 lines
1.5 KiB
4 years ago
|
#pragma once
|
||
5 years ago
|
|
||
4 years ago
|
#include <unordered_map>
|
||
|
#include <vector>
|
||
4 years ago
|
|
||
5 years ago
|
#include <capnp/serialize.h>
|
||
4 years ago
|
#include "cereal/gen/cpp/log.capnp.h"
|
||
4 years ago
|
#include "selfdrive/camerad/cameras/camera_common.h"
|
||
|
|
||
4 years ago
|
const CameraType ALL_CAMERAS[] = {RoadCam, DriverCam, WideRoadCam};
|
||
|
const int MAX_CAMERAS = std::size(ALL_CAMERAS);
|
||
|
struct EncodeIdx {
|
||
|
int segmentNum;
|
||
|
uint32_t frameEncodeId;
|
||
|
};
|
||
|
class Event {
|
||
5 years ago
|
public:
|
||
4 years ago
|
Event(cereal::Event::Which which, uint64_t mono_time) : reader(kj::ArrayPtr<capnp::word>{}) {
|
||
|
// construct a dummy Event for binary search, e.g std::upper_bound
|
||
|
this->which = which;
|
||
|
this->mono_time = mono_time;
|
||
|
}
|
||
4 years ago
|
Event(const kj::ArrayPtr<const capnp::word> &amsg) : reader(amsg) {
|
||
|
words = kj::ArrayPtr<const capnp::word>(amsg.begin(), reader.getEnd());
|
||
|
event = reader.getRoot<cereal::Event>();
|
||
|
which = event.which();
|
||
|
mono_time = event.getLogMonoTime();
|
||
|
}
|
||
|
inline kj::ArrayPtr<const capnp::byte> bytes() const { return words.asBytes(); }
|
||
|
|
||
4 years ago
|
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);
|
||
|
}
|
||
|
};
|
||
|
|
||
4 years ago
|
uint64_t mono_time;
|
||
|
cereal::Event::Which which;
|
||
|
cereal::Event::Reader event;
|
||
|
capnp::FlatArrayMessageReader reader;
|
||
|
kj::ArrayPtr<const capnp::word> words;
|
||
|
};
|
||
|
|
||
4 years ago
|
class LogReader {
|
||
4 years ago
|
public:
|
||
4 years ago
|
LogReader() = default;
|
||
4 years ago
|
~LogReader();
|
||
4 years ago
|
bool load(const std::string &file);
|
||
4 years ago
|
|
||
4 years ago
|
std::vector<Event*> events;
|
||
4 years ago
|
std::unordered_map<uint32_t, EncodeIdx> eidx[MAX_CAMERAS] = {};
|
||
4 years ago
|
|
||
4 years ago
|
private:
|
||
|
std::vector<uint8_t> raw_;
|
||
5 years ago
|
};
|