From 67cba61ed72cc9583eb7557584ee9d503a8785b9 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Sat, 30 Jun 2018 18:51:54 +0200 Subject: [PATCH] Edited JSON codec format --- src/output/output_json.cpp | 34 +++++++++++++++++++--------------- src/output/output_json.h | 2 ++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/output/output_json.cpp b/src/output/output_json.cpp index 610619b1..2a8d800f 100644 --- a/src/output/output_json.cpp +++ b/src/output/output_json.cpp @@ -34,7 +34,17 @@ namespace Mist { 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 (jPack.compareExcept(lastVal, nodup)){ return;//skip duplicates @@ -165,20 +175,17 @@ namespace Mist { myMeta.tracks[pushTrack].type = "meta"; myMeta.tracks[pushTrack].codec = "JSON"; //We have a track set correctly. Let's attempt to buffer a frame. - inJSON["trackid"] = (long long)pushTrack; - inJSON["datatype"] = "meta"; lastSendTime = Util::bootMS(); if (!inJSON.isMember("unix")){ //Base timestamp on arrival time - inJSON["time"] = (long long)(lastSendTime - bootMsOffset); + lastOutTime = (lastSendTime - bootMsOffset); }else{ //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; - lastVal = inJSON; - std::string packedJson = inJSON.toNetPacked(); - DTSC::Packet newPack(packedJson.data(), packedJson.size(), true); + lastOutData = inJSON.toString(); + static DTSC::Packet newPack; + newPack.genericFill(lastOutTime, 0, pushTrack, lastOutData.data(), lastOutData.size(), 0, true, bootMsOffset); bufferLivePacket(newPack); if (!idleInterval){idleInterval = 100;} if (isBlocking){setBlocking(false);} @@ -193,13 +200,10 @@ namespace Mist { } return; } - lastVal["time"] = (long long)(lastVal["time"].asInt() + (Util::bootMS() - lastSendTime)); + lastOutTime += (Util::bootMS() - lastSendTime); lastSendTime = Util::bootMS(); - lastVal.netPrepare(); - std::string packedJson = lastVal.toNetPacked(); - DTSC::Packet newPack(packedJson.data(), packedJson.size(), true); - myMeta.tracks[pushTrack].type = "meta"; - myMeta.tracks[pushTrack].codec = "JSON"; + static DTSC::Packet newPack; + newPack.genericFill(lastOutTime, 0, pushTrack, lastOutData.data(), lastOutData.size(), 0, true, bootMsOffset); bufferLivePacket(newPack); } diff --git a/src/output/output_json.h b/src/output/output_json.h index 3a290fc6..6010d2c5 100644 --- a/src/output/output_json.h +++ b/src/output/output_json.h @@ -18,6 +18,8 @@ namespace Mist { bool doesWebsockets(){return true;} protected: JSON::Value lastVal; + std::string lastOutData; + uint64_t lastOutTime; uint64_t lastSendTime; bool keepReselecting; std::string jsonp;