diff --git a/src/output/output.cpp b/src/output/output.cpp index 14a9991e..a4303d79 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -208,8 +208,7 @@ namespace Mist{ if(Triggers::shouldTrigger("CONN_PLAY", streamName)){ std::string payload = streamName+"\n" + getConnectedHost() +"\n"+capa["name"].asStringRef()+"\n"+reqUrl; if (!Triggers::doTrigger("CONN_PLAY", payload, streamName)){ - INFO_MSG("Shutting down due to CONN_PLAY trigger rejection"); - onFail(); + onFail("Not allowed to play (CONN_PLAY)"); } } doSync(true); @@ -288,8 +287,7 @@ namespace Mist{ if (tmpEx.getSync() == 1){ std::string payload = streamName+"\n" + getConnectedHost() +"\n" + JSON::Value((long long)crc).asString() + "\n"+capa["name"].asStringRef()+"\n"+reqUrl+"\n"+tmpEx.getSessId(); if (!Triggers::doTrigger("USER_NEW", payload, streamName)){ - MEDIUM_MSG("Closing connection because denied by USER_NEW trigger"); - onFail(); + onFail("Not allowed to play (USER_NEW)"); tmpEx.setSync(100);//100 = denied }else{ tmpEx.setSync(10);//10 = accepted @@ -297,12 +295,10 @@ namespace Mist{ } //100 = denied if (tmpEx.getSync() == 100){ - onFail(); - MEDIUM_MSG("Closing connection because denied by USER_NEW sync byte"); + onFail("Not allowed to play (USER_NEW cache)"); } if (tmpEx.getSync() == 0 || tmpEx.getSync() == 2){ - onFail(); - FAIL_MSG("Closing connection because sync byte timeout!"); + onFail("Not allowed to play (USER_NEW timeout)", true); } //anything else = accepted }else{ @@ -1017,8 +1013,7 @@ namespace Mist{ if (targetParams.count("recstopunix")){ long long stopUnix = atoll(targetParams["recstopunix"].c_str()); if (stopUnix < unixStreamBegin){ - FAIL_MSG("Recording stop time is earlier than stream begin - aborting"); - onFail(); + onFail("Recording stop time is earlier than stream begin - aborting", true); return; }else{ targetParams["recstop"] = JSON::Value((long long)((stopUnix - unixStreamBegin)*1000)).asString(); @@ -1028,8 +1023,7 @@ namespace Mist{ if (targetParams.count("recstop")){ long long endRec = atoll(targetParams["recstop"].c_str()); if (endRec < 0 || endRec < startTime()){ - FAIL_MSG("Entire recording range is in the past"); - onFail(); + onFail("Entire recording range is in the past", true); return; } INFO_MSG("Recording will stop at %lld", endRec); @@ -1039,8 +1033,7 @@ namespace Mist{ long long startRec = atoll(targetParams["recstart"].c_str()); if (startRec > 0 && startRec > myMeta.tracks[mainTrack].lastms){ if (myMeta.vod){ - FAIL_MSG("Recording start past end of non-live source"); - onFail(); + onFail("Recording start past end of non-live source", true); return; } INFO_MSG("Waiting for stream to reach recording starting point"); @@ -1080,8 +1073,7 @@ namespace Mist{ long long stopUnix = atoll(targetParams["stopunix"].c_str()); if (stopUnix < 0){stopUnix += Util::epoch();} if (stopUnix < unixStreamBegin){ - FAIL_MSG("Stop time is earlier than stream begin - aborting"); - onFail(); + onFail("Stop time is earlier than stream begin - aborting", true); return; }else{ targetParams["stop"] = JSON::Value((long long)((stopUnix - unixStreamBegin)*1000)).asString(); @@ -1091,8 +1083,7 @@ namespace Mist{ if (targetParams.count("stop")){ long long endRec = atoll(targetParams["stop"].c_str()); if (endRec < 0 || endRec < startTime()){ - FAIL_MSG("Entire range is in the past"); - onFail(); + onFail("Entire range is in the past", true); return; } INFO_MSG("Playback will stop at %lld", endRec); @@ -1102,8 +1093,7 @@ namespace Mist{ long long startRec = atoll(targetParams["start"].c_str()); if (startRec > 0 && startRec > myMeta.tracks[mainTrack].lastms){ if (myMeta.vod){ - FAIL_MSG("Playback start past end of non-live source"); - onFail(); + onFail("Playback start past end of non-live source", true); return; } INFO_MSG("Waiting for stream to reach playback starting point"); @@ -1665,12 +1655,7 @@ namespace Mist{ if (statsPage.getData()){ /*LTS-START*/ if (!statsPage.isAlive()){ - INFO_MSG("Shutting down on controller request"); - if (!onFinish()){ - myConn.close(); - }else{ - disconnect(); - } + onFail("Shutting down on controller request"); return; } /*LTS-END*/ diff --git a/src/output/output_dtsc.cpp b/src/output/output_dtsc.cpp index c3a6f0bb..d0c2ae99 100644 --- a/src/output/output_dtsc.cpp +++ b/src/output/output_dtsc.cpp @@ -46,13 +46,6 @@ namespace Mist { data.sendTo(myConn); } - void OutDTSC::sendError(const std::string &msg){ - JSON::Value err; - err["cmd"] = "error"; - err["msg"] = msg; - sendCmd(err); - } - void OutDTSC::sendOk(const std::string &msg){ JSON::Value err; err["cmd"] = "ok"; @@ -147,6 +140,14 @@ namespace Mist { } } + void OutDTSC::onFail(const std::string & msg, bool critical){ + JSON::Value err; + err["cmd"] = "error"; + err["msg"] = msg; + sendCmd(err); + Output::onFail(msg, critical); + } + void OutDTSC::onRequest(){ while (myConn.Received().available(8)){ if (myConn.Received().copy(4) == "DTCM"){ @@ -168,8 +169,7 @@ namespace Mist { }else if (myConn.Received().copy(4) == "DTSC"){ //Header packet if (!isPushing()){ - sendError("DTSC_HEAD ignored: you are not cleared for pushing data!"); - onFail(); + onFail("DTSC_HEAD ignored: you are not cleared for pushing data!", true); return; } std::string toRec = myConn.Received().copy(8); @@ -183,8 +183,7 @@ namespace Mist { sendOk(rep.str()); }else if (myConn.Received().copy(4) == "DTP2"){ if (!isPushing()){ - sendError("DTSC_V2 ignored: you are not cleared for pushing data!"); - onFail(); + onFail("DTSC_V2 ignored: you are not cleared for pushing data!", true); return; } // Data packet @@ -194,15 +193,13 @@ namespace Mist { std::string dataPacket = myConn.Received().remove(8+rSize); DTSC::Packet inPack(dataPacket.data(), dataPacket.size(), true); if (!myMeta.tracks.count(inPack.getTrackId())){ - sendError("DTSC_V2 received for a track that was not announced in the DTSC_HEAD!"); - onFail(); + onFail("DTSC_V2 received for a track that was not announced in the DTSC_HEAD!", true); return; } bufferLivePacket(inPack); }else{ //Invalid - sendError("Invalid packet header received. Aborting."); - onFail(); + onFail("Invalid packet header received. Aborting.", true); return; } } @@ -221,8 +218,7 @@ namespace Mist { std::string passString = dScan.getMember("password").asString(); Util::sanitizeName(streamName); if (!allowPush(passString)){ - sendError("Push not allowed - stream and/or password incorrect"); - onFail(); + onFail("Push not allowed - stream and/or password incorrect", true); return; } sendOk("You're cleared for pushing! DTSC_HEAD please?"); diff --git a/src/output/output_dtsc.h b/src/output/output_dtsc.h index a47414de..336c5a56 100644 --- a/src/output/output_dtsc.h +++ b/src/output/output_dtsc.h @@ -11,9 +11,9 @@ namespace Mist { void sendNext(); void sendHeader(); void initialSeek(); + void onFail(const std::string & msg, bool critical = false); void stats(bool force = false); void sendCmd(const JSON::Value &data); - void sendError(const std::string &msg); void sendOk(const std::string &msg); private: unsigned int lastActive;///