diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index 62f922f8..3ea91b76 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -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()){ diff --git a/lib/dtsc.h b/lib/dtsc.h index b92d6fe5..5e0c5278 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -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 trackMapping; long long int currtime; long long int lastreadpos; diff --git a/lib/json.h b/lib/json.h index b1f6b6cc..f8b7e27e 100644 --- a/lib/json.h +++ b/lib/json.h @@ -109,4 +109,33 @@ namespace JSON { Value fromFile(std::string filename); std::string encodeVector(std::vector & toEncode); + + template + 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 + 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; + } + } + } }