Memory efficiency upgrade.
This commit is contained in:
parent
5ea87a37f7
commit
974861d993
3 changed files with 32 additions and 11 deletions
12
lib/dtsc.cpp
12
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++){
|
for (JSON::ArrIter it = prevKey["parts"].ArrBegin(); it != prevKey["parts"].ArrEnd(); it++){
|
||||||
size += it->asInt();
|
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;
|
prevKey["size"] = size;
|
||||||
long long int bps = (double)prevKey["size"].asInt() / ((double)prevKey["len"].asInt() / 1000.0);
|
long long int bps = (double)prevKey["size"].asInt() / ((double)prevKey["len"].asInt() / 1000.0);
|
||||||
if (bps > metadata["tracks"][newTrack]["maxbps"].asInt()){
|
if (bps > metadata["tracks"][newTrack]["maxbps"].asInt()){
|
||||||
|
@ -549,7 +552,6 @@ DTSC::File & DTSC::File::operator =(const File & rhs){
|
||||||
strbuffer = rhs.strbuffer;
|
strbuffer = rhs.strbuffer;
|
||||||
jsonbuffer = rhs.jsonbuffer;
|
jsonbuffer = rhs.jsonbuffer;
|
||||||
metadata = rhs.metadata;
|
metadata = rhs.metadata;
|
||||||
firstmetadata = rhs.firstmetadata;
|
|
||||||
currtime = rhs.currtime;
|
currtime = rhs.currtime;
|
||||||
lastreadpos = rhs.lastreadpos;
|
lastreadpos = rhs.lastreadpos;
|
||||||
headerSize = rhs.headerSize;
|
headerSize = rhs.headerSize;
|
||||||
|
@ -605,11 +607,6 @@ JSON::Value & DTSC::File::getMeta(){
|
||||||
return metadata;
|
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.
|
/// (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.
|
/// Forces a write if force is set to true.
|
||||||
bool DTSC::File::writeHeader(std::string & header, bool force){
|
bool DTSC::File::writeHeader(std::string & header, bool force){
|
||||||
|
@ -694,9 +691,6 @@ void DTSC::File::readHeader(int pos){
|
||||||
}
|
}
|
||||||
metadata = JSON::fromDTMI(strbuffer);
|
metadata = JSON::fromDTMI(strbuffer);
|
||||||
}
|
}
|
||||||
if (pos == 0){
|
|
||||||
firstmetadata = metadata;
|
|
||||||
}
|
|
||||||
//if there is another header, read it and replace metadata with that one.
|
//if there is another header, read it and replace metadata with that one.
|
||||||
if (metadata.isMember("moreheader") && metadata["moreheader"].asInt() > 0){
|
if (metadata.isMember("moreheader") && metadata["moreheader"].asInt() > 0){
|
||||||
if (metadata["moreheader"].asInt() < getBytePosEOF()){
|
if (metadata["moreheader"].asInt() < getBytePosEOF()){
|
||||||
|
|
|
@ -97,7 +97,6 @@ namespace DTSC {
|
||||||
File & operator = (const File & rhs);
|
File & operator = (const File & rhs);
|
||||||
~File();
|
~File();
|
||||||
JSON::Value & getMeta();
|
JSON::Value & getMeta();
|
||||||
JSON::Value & getFirstMeta();
|
|
||||||
long long int getLastReadPos();
|
long long int getLastReadPos();
|
||||||
bool writeHeader(std::string & header, bool force = false);
|
bool writeHeader(std::string & header, bool force = false);
|
||||||
long long int addHeader(std::string & header);
|
long long int addHeader(std::string & header);
|
||||||
|
@ -122,7 +121,6 @@ namespace DTSC {
|
||||||
std::string strbuffer;
|
std::string strbuffer;
|
||||||
JSON::Value jsonbuffer;
|
JSON::Value jsonbuffer;
|
||||||
JSON::Value metadata;
|
JSON::Value metadata;
|
||||||
JSON::Value firstmetadata;
|
|
||||||
std::map<int,std::string> trackMapping;
|
std::map<int,std::string> trackMapping;
|
||||||
long long int currtime;
|
long long int currtime;
|
||||||
long long int lastreadpos;
|
long long int lastreadpos;
|
||||||
|
|
29
lib/json.h
29
lib/json.h
|
@ -109,4 +109,33 @@ namespace JSON {
|
||||||
Value fromFile(std::string filename);
|
Value fromFile(std::string filename);
|
||||||
|
|
||||||
std::string encodeVector(std::vector<long long int> & toEncode);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue