Edited JSON codec format

This commit is contained in:
Thulinma 2018-06-30 18:51:54 +02:00
parent 9723159592
commit 67cba61ed7
2 changed files with 21 additions and 15 deletions

View file

@ -34,7 +34,17 @@ namespace Mist {
return;//After a seek, the current packet is invalid. Do nothing and return here. return;//After a seek, the current packet is invalid. Do nothing and return here.
} }
} }
JSON::Value jPack = thisPacket.toJSON(); JSON::Value jPack;
if (myMeta.tracks[thisPacket.getTrackId()].codec == "JSON"){
char * dPtr;
unsigned int dLen;
thisPacket.getString("data", dPtr, dLen);
jPack["data"] = JSON::fromString(dPtr, dLen);
jPack["time"] = (long long)thisPacket.getTime();
jPack["track"] = (long long)thisPacket.getTrackId();
}else{
jPack = thisPacket.toJSON();
}
if (dupcheck){ if (dupcheck){
if (jPack.compareExcept(lastVal, nodup)){ if (jPack.compareExcept(lastVal, nodup)){
return;//skip duplicates return;//skip duplicates
@ -165,20 +175,17 @@ namespace Mist {
myMeta.tracks[pushTrack].type = "meta"; myMeta.tracks[pushTrack].type = "meta";
myMeta.tracks[pushTrack].codec = "JSON"; myMeta.tracks[pushTrack].codec = "JSON";
//We have a track set correctly. Let's attempt to buffer a frame. //We have a track set correctly. Let's attempt to buffer a frame.
inJSON["trackid"] = (long long)pushTrack;
inJSON["datatype"] = "meta";
lastSendTime = Util::bootMS(); lastSendTime = Util::bootMS();
if (!inJSON.isMember("unix")){ if (!inJSON.isMember("unix")){
//Base timestamp on arrival time //Base timestamp on arrival time
inJSON["time"] = (long long)(lastSendTime - bootMsOffset); lastOutTime = (lastSendTime - bootMsOffset);
}else{ }else{
//Base timestamp on unix time //Base timestamp on unix time
inJSON["time"] = (long long)((lastSendTime - bootMsOffset) + (Util::epoch() - Util::bootSecs()) * 1000); lastOutTime = (lastSendTime - bootMsOffset) + (inJSON["unix"].asInt() - Util::epoch()) * 1000;
} }
inJSON["bmo"] = (long long)bootMsOffset; lastOutData = inJSON.toString();
lastVal = inJSON; static DTSC::Packet newPack;
std::string packedJson = inJSON.toNetPacked(); newPack.genericFill(lastOutTime, 0, pushTrack, lastOutData.data(), lastOutData.size(), 0, true, bootMsOffset);
DTSC::Packet newPack(packedJson.data(), packedJson.size(), true);
bufferLivePacket(newPack); bufferLivePacket(newPack);
if (!idleInterval){idleInterval = 100;} if (!idleInterval){idleInterval = 100;}
if (isBlocking){setBlocking(false);} if (isBlocking){setBlocking(false);}
@ -193,13 +200,10 @@ namespace Mist {
} }
return; return;
} }
lastVal["time"] = (long long)(lastVal["time"].asInt() + (Util::bootMS() - lastSendTime)); lastOutTime += (Util::bootMS() - lastSendTime);
lastSendTime = Util::bootMS(); lastSendTime = Util::bootMS();
lastVal.netPrepare(); static DTSC::Packet newPack;
std::string packedJson = lastVal.toNetPacked(); newPack.genericFill(lastOutTime, 0, pushTrack, lastOutData.data(), lastOutData.size(), 0, true, bootMsOffset);
DTSC::Packet newPack(packedJson.data(), packedJson.size(), true);
myMeta.tracks[pushTrack].type = "meta";
myMeta.tracks[pushTrack].codec = "JSON";
bufferLivePacket(newPack); bufferLivePacket(newPack);
} }

View file

@ -18,6 +18,8 @@ namespace Mist {
bool doesWebsockets(){return true;} bool doesWebsockets(){return true;}
protected: protected:
JSON::Value lastVal; JSON::Value lastVal;
std::string lastOutData;
uint64_t lastOutTime;
uint64_t lastSendTime; uint64_t lastSendTime;
bool keepReselecting; bool keepReselecting;
std::string jsonp; std::string jsonp;