Memory efficiency upgrade.

This commit is contained in:
Erik Zandvliet 2013-09-19 10:03:54 +02:00
parent 5ea87a37f7
commit 974861d993
3 changed files with 32 additions and 11 deletions

View file

@ -277,6 +277,9 @@ void DTSC::Stream::addPacket(JSON::Value & newPack){
for (JSON::ArrIter it = prevKey["parts"].ArrBegin(); it != prevKey["parts"].ArrEnd(); it++){
size += it->asInt();
}
prevKey["partsize"] = prevKey["parts"].size();
std::string tmpParts = JSON::encodeVector(prevKey["parts"].ArrBegin(), prevKey["parts"].ArrEnd());
prevKey["parts"] = tmpParts;
prevKey["size"] = size;
long long int bps = (double)prevKey["size"].asInt() / ((double)prevKey["len"].asInt() / 1000.0);
if (bps > metadata["tracks"][newTrack]["maxbps"].asInt()){
@ -549,7 +552,6 @@ DTSC::File & DTSC::File::operator =(const File & rhs){
strbuffer = rhs.strbuffer;
jsonbuffer = rhs.jsonbuffer;
metadata = rhs.metadata;
firstmetadata = rhs.firstmetadata;
currtime = rhs.currtime;
lastreadpos = rhs.lastreadpos;
headerSize = rhs.headerSize;
@ -605,11 +607,6 @@ JSON::Value & DTSC::File::getMeta(){
return metadata;
}
/// Returns the header metadata for this file as JSON::Value.
JSON::Value & DTSC::File::getFirstMeta(){
return firstmetadata;
}
/// (Re)writes the given string to the header area if the size is the same as the existing header.
/// Forces a write if force is set to true.
bool DTSC::File::writeHeader(std::string & header, bool force){
@ -694,9 +691,6 @@ void DTSC::File::readHeader(int pos){
}
metadata = JSON::fromDTMI(strbuffer);
}
if (pos == 0){
firstmetadata = metadata;
}
//if there is another header, read it and replace metadata with that one.
if (metadata.isMember("moreheader") && metadata["moreheader"].asInt() > 0){
if (metadata["moreheader"].asInt() < getBytePosEOF()){

View file

@ -97,7 +97,6 @@ namespace DTSC {
File & operator = (const File & rhs);
~File();
JSON::Value & getMeta();
JSON::Value & getFirstMeta();
long long int getLastReadPos();
bool writeHeader(std::string & header, bool force = false);
long long int addHeader(std::string & header);
@ -122,7 +121,6 @@ namespace DTSC {
std::string strbuffer;
JSON::Value jsonbuffer;
JSON::Value metadata;
JSON::Value firstmetadata;
std::map<int,std::string> trackMapping;
long long int currtime;
long long int lastreadpos;

View file

@ -109,4 +109,33 @@ namespace JSON {
Value fromFile(std::string filename);
std::string encodeVector(std::vector<long long int> & toEncode);
template <typename T>
std::string encodeVector(T begin, T end){
std::string result;
for( T it = begin; it != end; it++){
long long int tmp = (*it);
while(tmp >= 0xFFFF){
result += (char)0xFF;
result += (char)0xFF;
tmp -= 0xFFFF;
}
result += (char)tmp / 255;
result += (char)tmp % 255;
}
return result;
}
template <typename T>
void decodeVector( std::string input, T & result ){
result.clear();
int tmp = 0;
for( int i = 0; i < input.size(); i += 2){
tmp += input[i] + input[i + 1];
if ((tmp % 0xFFFF) != 0 || (input[i] + input[i+1]) == 0){
result.push_back(tmp);
tmp = 0;
}
}
}
}