-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"meta": "/home/jo/git/SomeSense-App/tmp/rec_2022-09-30T16:04:10.240Z.somesense.json", | ||
"pb_bin": "/home/jo/git/SomeSense-App/tmp/rec_2022-09-30T16:04:10.240Z.somesense.pb" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "pb_rec.h" | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <iostream> | ||
#include <chrono> | ||
#include "util/json.hpp" | ||
#include <google/protobuf/io/zero_copy_stream.h> | ||
|
||
|
||
data::PbRec::PbRec(std::string binPath, std::string metaPath) | ||
{ | ||
std::ifstream ifs(metaPath); | ||
if (!ifs.good()) { | ||
std::runtime_error("Could not open file: " + metaPath); | ||
} | ||
std::cout << "Loading metadata from file: " << metaPath << std::endl; | ||
auto jsonData = nlohmann::json::parse(ifs); | ||
_msgStart = jsonData["msgStart"].get<std::vector<off64_t>>(); | ||
_timestamp = jsonData["timestamp"].get<std::vector<int64_t>>(); | ||
_recLength = _timestamp.back() - _timestamp.front(); | ||
|
||
_msgSize = jsonData["msgSize"].get<size_t>(); | ||
_buffer = new char[_msgSize]; | ||
_stream = std::ifstream(binPath); | ||
} | ||
|
||
void data::PbRec::reset() { | ||
_stream.seekg(0); | ||
} | ||
|
||
void data::PbRec::setRelTs(int64_t newRelTs) { | ||
int frameNr = (static_cast<double>(newRelTs) / static_cast<double>(_recLength)) * _timestamp.size(); | ||
bool found = false; | ||
int64_t startTs = _timestamp[0]; | ||
while (!found) { | ||
int64_t tsDiff = std::abs(_timestamp[frameNr] - startTs - newRelTs); | ||
int64_t tsDiffNext = tsDiff + 1; | ||
int64_t tsDiffPrevious = tsDiff + 1; | ||
if (frameNr + 1 < _timestamp.size()) { | ||
tsDiffNext = std::abs(_timestamp[frameNr+1]- startTs - newRelTs); | ||
} | ||
if (frameNr - 1 >= 0) { | ||
tsDiffPrevious = std::abs(_timestamp[frameNr-1] - startTs - newRelTs); | ||
} | ||
if (tsDiff < tsDiffNext && tsDiff < tsDiffPrevious) { | ||
found = true; | ||
} | ||
else if (tsDiffNext < tsDiffPrevious){ | ||
frameNr++; | ||
} | ||
else { | ||
frameNr--; | ||
} | ||
} | ||
auto newMsgPos = _msgStart[frameNr]; | ||
_stream.seekg(newMsgPos); | ||
} | ||
|
||
void data::PbRec::fillFrame(proto::Frame& frame) { | ||
_stream.read(_buffer, _msgSize); | ||
frame.ParseFromArray(_buffer, _msgSize); | ||
// Adapt the relative timestamp | ||
auto x = frame.absts(); | ||
auto newRelTs = frame.absts() - _timestamp.front(); | ||
frame.set_relts(newRelTs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <fstream> | ||
#include <atomic> | ||
#include <tuple> | ||
#include "irec.h" | ||
#include "opencv2/opencv.hpp" | ||
#include "frame.pb.h" | ||
|
||
|
||
namespace data { | ||
class PbRec : public IRec { | ||
public: | ||
PbRec(std::string binPath, std::string metaPath); | ||
void fillFrame(proto::Frame& frame) override; | ||
int64_t getRecLength() const override { return _recLength; } | ||
void reset() override; | ||
void setRelTs(int64_t newRelTs) override; | ||
|
||
private: | ||
std::vector<off64_t> _msgStart; // protobuf msg starts in bytes | ||
std::vector<int64_t> _timestamp; // absTs in [us] | ||
int64_t _recLength; // length of recording in [us] | ||
|
||
size_t _msgSize; | ||
char* _buffer; | ||
std::ifstream _stream; | ||
|
||
std::mutex _readLock; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters