DTSC push input working...?
This commit is contained in:
		
							parent
							
								
									88227730fe
								
							
						
					
					
						commit
						38a0448a8e
					
				
					 2 changed files with 75 additions and 20 deletions
				
			
		|  | @ -14,20 +14,11 @@ namespace Mist { | ||||||
|     JSON::Value prep; |     JSON::Value prep; | ||||||
|     prep["cmd"] = "hi"; |     prep["cmd"] = "hi"; | ||||||
|     prep["version"] = "MistServer " PACKAGE_VERSION; |     prep["version"] = "MistServer " PACKAGE_VERSION; | ||||||
| #ifdef BIGMETA |  | ||||||
|     prep["pack_method"] = 2ll; |     prep["pack_method"] = 2ll; | ||||||
| #else |  | ||||||
|     prep["pack_method"] = 1ll; |  | ||||||
| #endif |  | ||||||
|     salt = Secure::md5("mehstuff"+JSON::Value((long long)time(0)).asString()); |     salt = Secure::md5("mehstuff"+JSON::Value((long long)time(0)).asString()); | ||||||
|     prep["salt"] = salt; |     prep["salt"] = salt; | ||||||
|     /// \todo Make this securererer.
 |     /// \todo Make this securererer.
 | ||||||
|     unsigned long sendSize = prep.packedSize(); |     sendCmd(prep); | ||||||
|     myConn.SendNow("DTCM"); |  | ||||||
|     char sSize[4] = {0, 0, 0, 0}; |  | ||||||
|     Bit::htobl(sSize, prep.packedSize()); |  | ||||||
|     myConn.SendNow(sSize, 4); |  | ||||||
|     prep.sendTo(myConn); |  | ||||||
|     lastActive = Util::epoch(); |     lastActive = Util::epoch(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -37,20 +28,38 @@ namespace Mist { | ||||||
|   void OutDTSC::stats(bool force){ |   void OutDTSC::stats(bool force){ | ||||||
|     unsigned long long int now = Util::epoch(); |     unsigned long long int now = Util::epoch(); | ||||||
|     if (now - lastActive > 1 && !pushing){ |     if (now - lastActive > 1 && !pushing){ | ||||||
|       MEDIUM_MSG("Ping!"); |  | ||||||
|       JSON::Value prep; |       JSON::Value prep; | ||||||
|       prep["cmd"] = "ping"; |       prep["cmd"] = "ping"; | ||||||
|       unsigned long sendSize = prep.packedSize(); |       sendCmd(prep); | ||||||
|       myConn.SendNow("DTCM"); |  | ||||||
|       char sSize[4] = {0, 0, 0, 0}; |  | ||||||
|       Bit::htobl(sSize, prep.packedSize()); |  | ||||||
|       myConn.SendNow(sSize, 4); |  | ||||||
|       prep.sendTo(myConn); |  | ||||||
|       lastActive = now; |       lastActive = now; | ||||||
|     } |     } | ||||||
|     Output::stats(force); |     Output::stats(force); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   void OutDTSC::sendCmd(const JSON::Value &data){ | ||||||
|  |     MEDIUM_MSG("Sending DTCM: %s", data.toString().c_str()); | ||||||
|  |     unsigned long sendSize = data.packedSize(); | ||||||
|  |     myConn.SendNow("DTCM"); | ||||||
|  |     char sSize[4] = {0, 0, 0, 0}; | ||||||
|  |     Bit::htobl(sSize, data.packedSize()); | ||||||
|  |     myConn.SendNow(sSize, 4); | ||||||
|  |     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"; | ||||||
|  |     err["msg"] = msg; | ||||||
|  |     sendCmd(err); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   void OutDTSC::init(Util::Config * cfg){ |   void OutDTSC::init(Util::Config * cfg){ | ||||||
|     Output::init(cfg); |     Output::init(cfg); | ||||||
|     capa["name"] = "DTSC"; |     capa["name"] = "DTSC"; | ||||||
|  | @ -151,12 +160,53 @@ namespace Mist { | ||||||
|         myConn.Received().remove(8); |         myConn.Received().remove(8); | ||||||
|         std::string dataPacket = myConn.Received().remove(rSize); |         std::string dataPacket = myConn.Received().remove(rSize); | ||||||
|         DTSC::Scan dScan((char*)dataPacket.data(), rSize); |         DTSC::Scan dScan((char*)dataPacket.data(), rSize); | ||||||
|  |         INFO_MSG("Received DTCM: %s", dScan.asJSON().toString().c_str()); | ||||||
|         if (dScan.getMember("cmd").asString() == "push"){handlePush(dScan); continue;} |         if (dScan.getMember("cmd").asString() == "push"){handlePush(dScan); continue;} | ||||||
|         if (dScan.getMember("cmd").asString() == "play"){handlePlay(dScan); continue;} |         if (dScan.getMember("cmd").asString() == "play"){handlePlay(dScan); continue;} | ||||||
|  |         if (dScan.getMember("cmd").asString() == "ping"){sendOk("Pong!"); continue;} | ||||||
|  |         if (dScan.getMember("cmd").asString() == "ok"){INFO_MSG("Ok: %s", dScan.getMember("msg").asString().c_str()); continue;} | ||||||
|  |         if (dScan.getMember("cmd").asString() == "error"){ERROR_MSG("%s", dScan.getMember("msg").asString().c_str()); continue;} | ||||||
|  |         if (dScan.getMember("cmd").asString() == "reset"){myMeta.reset(); sendOk("Internal state reset"); continue;} | ||||||
|         WARN_MSG("Unhandled DTCM command: '%s'", dScan.getMember("cmd").asString().c_str()); |         WARN_MSG("Unhandled DTCM command: '%s'", dScan.getMember("cmd").asString().c_str()); | ||||||
|  |       }else if (myConn.Received().copy(4) == "DTSC"){ | ||||||
|  |         //Header packet
 | ||||||
|  |         if (!isPushing()){ | ||||||
|  |           sendError("DTSC_HEAD ignored: you are not cleared for pushing data!"); | ||||||
|  |           onFail(); | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  |         std::string toRec = myConn.Received().copy(8); | ||||||
|  |         unsigned long rSize = Bit::btohl(toRec.c_str()+4); | ||||||
|  |         if (!myConn.Received().available(8+rSize)){return;}//abort - not enough data yet
 | ||||||
|  |         std::string dataPacket = myConn.Received().remove(8+rSize); | ||||||
|  |         DTSC::Packet metaPack(dataPacket.data(), dataPacket.size()); | ||||||
|  |         myMeta.reinit(metaPack); | ||||||
|  |         std::stringstream rep; | ||||||
|  |         rep << "DTSC_HEAD received with " << myMeta.tracks.size() << " tracks. Bring on those data packets!"; | ||||||
|  |         sendOk(rep.str()); | ||||||
|  |       }else if (myConn.Received().copy(4) == "DTP2"){ | ||||||
|  |         if (!isPushing()){ | ||||||
|  |           sendError("DTSC_V2 ignored: you are not cleared for pushing data!"); | ||||||
|  |           onFail(); | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  |         // Data packet
 | ||||||
|  |         std::string toRec = myConn.Received().copy(8); | ||||||
|  |         unsigned long rSize = Bit::btohl(toRec.c_str()+4); | ||||||
|  |         if (!myConn.Received().available(8+rSize)){return;}//abort - not enough data yet
 | ||||||
|  |         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(); | ||||||
|  |           return; | ||||||
|  |         } | ||||||
|  |         bufferLivePacket(inPack); | ||||||
|       }else{ |       }else{ | ||||||
|         // Non-command message
 |         //Invalid
 | ||||||
|         //
 |         sendError("Invalid packet header received. Aborting."); | ||||||
|  |         onFail(); | ||||||
|  |         return; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | @ -174,9 +224,11 @@ namespace Mist { | ||||||
|     std::string passString = dScan.getMember("password").asString(); |     std::string passString = dScan.getMember("password").asString(); | ||||||
|     Util::sanitizeName(streamName); |     Util::sanitizeName(streamName); | ||||||
|     if (!allowPush(passString)){ |     if (!allowPush(passString)){ | ||||||
|       myConn.close(); |       sendError("Push not allowed - stream and/or password incorrect"); | ||||||
|  |       onFail(); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |     sendOk("You're cleared for pushing! DTSC_HEAD please?"); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -12,6 +12,9 @@ namespace Mist { | ||||||
|       void sendHeader(); |       void sendHeader(); | ||||||
|       void initialSeek(); |       void initialSeek(); | ||||||
|       void stats(bool force = 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: |     private: | ||||||
|       unsigned int lastActive;///<Time of last sending of data.
 |       unsigned int lastActive;///<Time of last sending of data.
 | ||||||
|       std::string getStatsName(); |       std::string getStatsName(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma