/* Copyright 2014-2016 Jan Huwald, Stephan Richter
This file is part of HRTC.
HRTC is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HRTC is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program (see file LICENSE). If not, see
. */
#pragma once
#include "common.hpp"
#include "num_util.hpp"
struct DecompTrajState {
Time t0, dt;
int x0, dx;
template
Real get(Time t1, Real quantum) {
return dt
? quant2real(x0, quantum)
+ Real(t1 - t0) * quant2real(dx, quantum) / dt
: quant2real(x0, quantum);
}
};
template
struct DecompressorState {
TId numTraj;
Real quantum;
DecompTrajState *trajState;
priority_queue::container_type, std::greater> expectedSegment;
Time curTime;
SplitSVIBuffer buf;
uint64_t chunkSz, chunkCur;
function chunkSrc;
EncodingPtr decoder;
// statistic helpers
#ifdef HACKY_STATS
map stat_key_x, stat_dx, stat_dt;
#endif
DecompressorState(TId numTraj, Real quantum,
uint64_t maxChunkSize, EncodingPtr decoder,
function chunkSrc)
: numTraj(numTraj),
quantum(quantum),
trajState(new DecompTrajState[numTraj]),
curTime(0),
buf(decoder, maxChunkSize),
chunkSz(0),
chunkCur(0),
chunkSrc(chunkSrc),
decoder(decoder)
{}
bool readFrame(Real *trajDst) {
if (!curTime)
if (!readKeyFrame()) return false;
while ((curTime == expectedSegment.top().time) && (chunkCur < chunkSz))
readSegment();
if (expectedSegment.top().time <= curTime)
return false;
// push data to trajDst
if (trajDst) {
for (int i=0; i(curTime, quantum);
}
curTime++;
return true;
}
bool readKeyFrame() {
// init expected segements
uint8_t *raw_iv = new uint8_t[numTraj * sizeof(Real)];
ChunkSize sz = chunkSrc((char*) raw_iv);
if (!sz.raw) return false;
uint bit_count = sz.raw / numTraj;
assert(bit_count * numTraj == sz.raw);
dynamic_bitset iv(raw_iv, raw_iv + sz.compressed);
delete[] raw_iv;
for (int i=0; i(stat))
cout << get<1>(stat) << " " << i.first << " " << i.second << endl;
#endif
}
};