22 _outputDir = outputDir;
29 std::unique_lock<std::mutex> lock(_mutex);
32 _condVar.notify_one();
34 if (_thread.joinable())
48 std::string fileName = _outputDir + _name +
".txt";
53 writeHeaderToFile(file);
56 std::unique_lock<std::mutex> lock(_mutex);
58 _condVar.wait(lock, [&]
59 {
return (_stop ==
true || _queue.size() != 0); });
63 SENS_DEBUG(
"SENSRecorderDataHandler: queue size: %d", _queue.size());
65 std::deque<T> localQueue;
68 localQueue.push_back(_queue.front());
75 if (localQueue.size())
77 writeLineToFile(file, localQueue.front());
78 localQueue.pop_front();
81 if (localQueue.size())
84 ss <<
"Data writing is too slow. Skipping " << localQueue.size() <<
" values from queue!";
85 SENS_WARN(
"SENSRecorderDataHandler store: %s", ss.str().c_str());
88 std::lock_guard<std::mutex> lock(_msgMutex);
95 writeOnThreadFinish();
103 std::unique_lock<std::mutex> lock(_mutex);
104 _queue.push_back(std::move(item));
106 _condVar.notify_one();
112 std::lock_guard<std::mutex> lock(_msgMutex);
113 if (_errorMsg.empty())
135 file << std::chrono::time_point_cast<SENSMicroseconds>(data.second).time_since_epoch().count() <<
" "
136 << data.first.latitudeDEG <<
" "
137 << data.first.longitudeDEG <<
" "
138 << data.first.altitudeM <<
" "
139 << data.first.accuracyM <<
"\n";
155 file << std::chrono::time_point_cast<SENSMicroseconds>(data.second).time_since_epoch().count() <<
" "
156 << data.first.quatX <<
" "
157 << data.first.quatY <<
" "
158 << data.first.quatZ <<
" "
159 << data.first.quatW <<
"\n";
175 if (data.first.empty())
177 SENS_WARN(
"SENSCameraRecorderDataHandler::writeLineToFile: frame is empty");
183 std::string filename =
_outputDir +
"video.avi";
184 _videoWriter.open(filename, cv::VideoWriter::fourcc(
'M',
'J',
'P',
'G'), 30, data.first.size(),
true);
186 SENS_DEBUG(
"Opening video for writing: %s", filename.c_str());
191 SENS_WARN(
"SENSCameraRecorderDataHandler::writeLineToFile: video writer not opened");
195 long long timePt = std::chrono::time_point_cast<SENSMicroseconds>(data.second).time_since_epoch().count();
214 std::string fileName =
_outputDir +
"cameraConfig.json";
219 fs.open(fileName, cv::FileStorage::WRITE);
222 fs <<
"deviceId" <<
config.deviceId;
223 fs <<
"widthPix" <<
config.streamConfig.widthPix;
224 fs <<
"heightPix" <<
config.streamConfig.heightPix;
225 fs <<
"focalLengthPix" <<
config.streamConfig.focalLengthPix;
226 fs <<
"focusMode" << (int)
config.focusMode;
227 fs <<
"facing" << (
int)
config.facing;
std::pair< SENSOrientation::Quat, SENSTimePt > OrientationInfo
std::pair< SENSGps::Location, SENSTimePt > GpsInfo
std::pair< cv::Mat, SENSTimePt > FrameInfo
cv::VideoWriter _videoWriter
void updateConfig(const SENSCameraConfig &config)
void writeLineToFile(ofstream &file, const FrameInfo &data) override
called in thread store routine for every new line
void writeOnThreadFinish() override
called in thread store routine when thread finished
void writeOnThreadStart() override
called in thread store routine when thread starts
SENSCameraRecorderDataHandler()
SENSGpsRecorderDataHandler()
void writeLineToFile(ofstream &file, const GpsInfo &data) override
called in thread store routine for every new line
SENSOrientationRecorderDataHandler()
void writeLineToFile(ofstream &file, const OrientationInfo &data) override
called in thread store routine for every new line
void add(T &&item)
add new value to store queue
SENSRecorderDataHandler(const std::string &name)
bool getErrorMsg(std::string &msg)
get error msg (valid if function returns true)
void stop()
stop the store thread and clear values in queue
virtual ~SENSRecorderDataHandler()
std::string _outputDir
output directory
void start(const std::string &outputDir)
start the store thread
Config config
The configuration set in App::run.
bool fileExists(const string &pathfilename)
Returns true if a file exists.
void removeFile(const string &path)
RemoveFile deletes a file with given path.