Fixed newlines in debug messages. Also, backported various Pro edition fixes that belonged in OS edition.
This commit is contained in:
		
							parent
							
								
									3c409d4b42
								
							
						
					
					
						commit
						c20b8f2081
					
				
					 8 changed files with 57 additions and 25 deletions
				
			
		
							
								
								
									
										16
									
								
								lib/dtsc.cpp
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								lib/dtsc.cpp
									
										
									
									
									
								
							|  | @ -764,16 +764,13 @@ void DTSC::File::seekNext() { | |||
|     myPack.null(); | ||||
|     return; | ||||
|   } | ||||
|   fseek(F, currentPositions.begin()->bytePos, SEEK_SET); | ||||
|   seekPos thisPos = *currentPositions.begin(); | ||||
|   fseek(F, thisPos.bytePos, SEEK_SET); | ||||
|   if (reachedEOF()) { | ||||
|     myPack.null(); | ||||
|     return; | ||||
|   } | ||||
|   clearerr(F); | ||||
|   if (!metadata.merged) { | ||||
|     seek_time(currentPositions.begin()->seekTime + 1, currentPositions.begin()->trackID); | ||||
|     fseek(F, currentPositions.begin()->bytePos, SEEK_SET); | ||||
|   } | ||||
|   currentPositions.erase(currentPositions.begin()); | ||||
|   lastreadpos = ftell(F); | ||||
|   if (fread(buffer, 4, 1, F) != 1) { | ||||
|  | @ -786,7 +783,7 @@ void DTSC::File::seekNext() { | |||
|     return; | ||||
|   } | ||||
|   if (memcmp(buffer, DTSC::Magic_Header, 4) == 0) { | ||||
|     seek_time(myPack.getTime() + 1, myPack.getTrackId(), true); | ||||
|     seek_time(myPack.getTime(), myPack.getTrackId(), true); | ||||
|     return seekNext(); | ||||
|   } | ||||
|   long long unsigned int version = 0; | ||||
|  | @ -864,9 +861,12 @@ void DTSC::File::seekNext() { | |||
|       } | ||||
|       currentPositions.insert(tmpPos); | ||||
|     } else { | ||||
|       seek_time(myPack.getTime() + 1, myPack.getTrackId(), true); | ||||
|       seek_time(myPack.getTime(), myPack.getTrackId(), true); | ||||
|     } | ||||
|     seek_bpos(tempLoc); | ||||
|   }else{ | ||||
|     seek_time(thisPos.seekTime, thisPos.trackID); | ||||
|     fseek(F, thisPos.bytePos, SEEK_SET); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | @ -954,7 +954,7 @@ DTSC::Packet & DTSC::File::getPacket() { | |||
| bool DTSC::File::seek_time(unsigned int ms, unsigned int trackNo, bool forceSeek) { | ||||
|   seekPos tmpPos; | ||||
|   tmpPos.trackID = trackNo; | ||||
|   if (!forceSeek && myPack && ms > myPack.getTime() && trackNo >= myPack.getTrackId()) { | ||||
|   if (!forceSeek && myPack && ms >= myPack.getTime() && trackNo >= myPack.getTrackId()) { | ||||
|     tmpPos.seekTime = myPack.getTime(); | ||||
|     tmpPos.bytePos = getBytePos(); | ||||
|   } else { | ||||
|  |  | |||
|  | @ -108,7 +108,7 @@ namespace DTSC { | |||
|       operator bool() const; | ||||
|       packType getVersion() const; | ||||
|       void reInit(const char * data_, unsigned int len, bool noCopy = false); | ||||
|       void genericFill(long long packTime, long long packOffset, long long packTrack, char * packData, long long packDataSize, long long packBytePos, bool isKeyframe); | ||||
|       void genericFill(long long packTime, long long packOffset, long long packTrack, const char * packData, long long packDataSize, long long packBytePos, bool isKeyframe); | ||||
|       void getString(const char * identifier, char *& result, unsigned int & len) const; | ||||
|       void getString(const char * identifier, std::string & result) const; | ||||
|       void getInt(const char * identifier, int & result) const; | ||||
|  |  | |||
|  | @ -19,7 +19,10 @@ namespace DTSC { | |||
| 
 | ||||
|   /// Copy constructor for packets, copies an existing packet with same noCopy flag as original.
 | ||||
|   Packet::Packet(const Packet & rhs) { | ||||
|     Packet(rhs.data, rhs.dataLen, !rhs.master); | ||||
|     master = false; | ||||
|     bufferLen = 0; | ||||
|     data = NULL; | ||||
|     reInit(rhs.data, rhs.dataLen, !rhs.master); | ||||
|   } | ||||
| 
 | ||||
|   /// Data constructor for packets, either references or copies a packet from raw data.
 | ||||
|  | @ -112,7 +115,7 @@ namespace DTSC { | |||
|   ///\param noCopy Determines whether to make a copy or not
 | ||||
|   void Packet::reInit(const char * data_, unsigned int len, bool noCopy) { | ||||
|     if (!data_) { | ||||
|       DEBUG_MSG(DLVL_DEVEL, "ReInit received a null pointer with len %d, ignoring", len); | ||||
|       HIGH_MSG("ReInit received a null pointer with len %d, ignoring", len); | ||||
|       null(); | ||||
|       return; | ||||
|     } | ||||
|  | @ -168,7 +171,8 @@ namespace DTSC { | |||
|   } | ||||
|    | ||||
|   /// Re-initializes this Packet to contain a generic DTSC packet with the given data fields.
 | ||||
|   void Packet::genericFill(long long packTime, long long packOffset, long long packTrack, char * packData, long long packDataSize, long long packBytePos, bool isKeyframe){ | ||||
|   /// When given a NULL pointer, the data is reserved and memset to 0
 | ||||
|   void Packet::genericFill(long long packTime, long long packOffset, long long packTrack, const char * packData, long long packDataSize, long long packBytePos, bool isKeyframe){ | ||||
|     null(); | ||||
|     master = true; | ||||
|     //time and trackID are part of the 20-byte header.
 | ||||
|  | @ -177,7 +181,7 @@ namespace DTSC { | |||
|     //bpos, if >= 0, adds 9 bytes (integer type) and 6 bytes (2+namelen)
 | ||||
|     //keyframe, if true, adds 9 bytes (integer type) and 10 bytes (2+namelen)
 | ||||
|     //data adds packDataSize+5 bytes (string type) and 6 bytes (2+namelen)
 | ||||
|     unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos>=0?15:0) + (isKeyframe?19:0) + packDataSize+11; | ||||
|     unsigned int sendLen = 24 + (packOffset?17:0) + (packBytePos?15:0) + (isKeyframe?19:0) + packDataSize+11; | ||||
|     resize(sendLen); | ||||
|     //set internal variables
 | ||||
|     version = DTSC_V2; | ||||
|  | @ -217,7 +221,11 @@ namespace DTSC { | |||
|     memcpy(data+offset, "\000\004data\002", 7); | ||||
|     tmpLong = htonl(packDataSize); | ||||
|     memcpy(data+offset+7, (char *)&tmpLong, 4); | ||||
|     if (packData){ | ||||
|       memcpy(data+offset+11, packData, packDataSize); | ||||
|     }else{ | ||||
|       memset(data+offset+11, 0, packDataSize); | ||||
|     } | ||||
|     //finish container with 0x0000EE
 | ||||
|     memcpy(data+offset+11+packDataSize, "\000\000\356", 3); | ||||
|   } | ||||
|  | @ -1133,7 +1141,7 @@ namespace DTSC { | |||
|   unsigned int Track::timeToKeynum(unsigned int timestamp){ | ||||
|     unsigned int result = 0; | ||||
|     for (std::deque<Key>::iterator it = keys.begin(); it != keys.end(); it++){ | ||||
|       if (it->getTime() >= timestamp){ | ||||
|       if (it->getTime() > timestamp){ | ||||
|         break; | ||||
|       } | ||||
|       result = it->getNumber(); | ||||
|  |  | |||
							
								
								
									
										35
									
								
								src/io.cpp
									
										
									
									
									
								
							
							
						
						
									
										35
									
								
								src/io.cpp
									
										
									
									
									
								
							|  | @ -1,3 +1,4 @@ | |||
| #include <mist/bitfields.h> | ||||
| #include "io.h" | ||||
| 
 | ||||
| namespace Mist { | ||||
|  | @ -79,12 +80,12 @@ namespace Mist { | |||
|     //Open the correct page for the data
 | ||||
|     char pageId[NAME_BUFFER_SIZE]; | ||||
|     snprintf(pageId, NAME_BUFFER_SIZE, SHM_TRACK_DATA, streamName.c_str(), mapTid, pageNumber); | ||||
|     std::string pageName(pageId); | ||||
|     int pageSize = pagesByTrack[tid][pageNumber].dataSize; | ||||
| #ifdef __CYGWIN__ | ||||
|     curPage[tid].init(pageName, 26 * 1024 * 1024, true); | ||||
| #else | ||||
|     curPage[tid].init(pageName, pagesByTrack[tid][pageNumber].dataSize, true); | ||||
|     pageSize = 26 * 1024 * 1024; | ||||
| #endif | ||||
|     std::string pageName(pageId); | ||||
|     curPage[tid].init(pageName, pageSize, true); | ||||
|     //Make sure the data page is not destroyed when we are done buffering it later on.
 | ||||
|     curPage[tid].master = false; | ||||
|     //Store the pagenumber of the currently buffer page
 | ||||
|  | @ -128,6 +129,10 @@ namespace Mist { | |||
|       return; | ||||
|     } | ||||
|     unsigned long mapTid = trackMap[tid]; | ||||
|     if (!pagesByTrack.count(tid)){ | ||||
|       //The buffer does not control the datapages, indicated by no pagesByTrack entry.
 | ||||
|       return; | ||||
|     } | ||||
|     //If the given pagenumber is not a valid page on this track, do nothing
 | ||||
|     if (!pagesByTrack[tid].count(pageNumber)){ | ||||
|       INFO_MSG("Can't remove page %lu on track %lu~>%lu as it is not a valid page number.", pageNumber, tid, mapTid); | ||||
|  | @ -143,7 +148,7 @@ namespace Mist { | |||
| #else | ||||
|     toErase.init(pageName, pagesByTrack[tid][pageNumber].dataSize, false); | ||||
| #endif | ||||
|     //Set the master flag so that the page will be destoryed once it leaves scope
 | ||||
|     //Set the master flag so that the page will be destroyed once it leaves scope
 | ||||
| #if defined(__CYGWIN__) || defined(_WIN32) | ||||
|     IPC::releasePage(pageName); | ||||
| #endif | ||||
|  | @ -324,6 +329,21 @@ namespace Mist { | |||
|   ///Initiates/continues negotiation with the buffer as well
 | ||||
|   ///\param packet The packet to buffer
 | ||||
|   void InOutBase::bufferLivePacket(JSON::Value & packet) { | ||||
|     DTSC::Packet realPacket; | ||||
|     realPacket.genericFill(packet["time"].asInt(), packet["offset"].asInt(), packet["trackid"].asInt(), packet["data"].asStringRef().c_str(), packet["data"].asStringRef().size(), packet["bpos"].asInt(), packet["keyframe"].asInt()); | ||||
|     bufferLivePacket(realPacket); | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   ///Buffers a live packet to a page.
 | ||||
|   ///
 | ||||
|   ///Handles both buffering and creation of new pages
 | ||||
|   ///
 | ||||
|   ///Initiates/continues negotiation with the buffer as well
 | ||||
|   ///\param packet The packet to buffer
 | ||||
|   void InOutBase::bufferLivePacket(DTSC::Packet & packet){ | ||||
|     myMeta.vod = false; | ||||
|     myMeta.live = true; | ||||
|     //Store the trackid for easier access
 | ||||
|     unsigned long tid = packet.getTrackId(); | ||||
|     //Do nothing if the trackid is invalid
 | ||||
|  | @ -467,6 +487,11 @@ namespace Mist { | |||
|     } | ||||
|     //Now we either returned or the track has an offset for the user page.
 | ||||
|     //Get the data from the userPage
 | ||||
|     if (!userClient.getData()){ | ||||
|       char userPageName[100]; | ||||
|       sprintf(userPageName, SHM_USERS, streamName.c_str()); | ||||
|       userClient = IPC::sharedClient(userPageName, 30, true); | ||||
|     } | ||||
|     char * tmp = userClient.getData(); | ||||
|     if (!tmp) { | ||||
|       DEBUG_MSG(DLVL_FAIL, "Failed to negotiate for incoming track %lu, there does not seem to be a connection with the buffer", tid); | ||||
|  |  | |||
							
								
								
									
										3
									
								
								src/io.h
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								src/io.h
									
										
									
									
									
								
							|  | @ -35,6 +35,7 @@ namespace Mist { | |||
|       void bufferFinalize(unsigned long tid); | ||||
|       void bufferRemove(unsigned long tid, unsigned long pageNumber); | ||||
|       void bufferLivePacket(JSON::Value & packet); | ||||
|       void bufferLivePacket(DTSC::Packet & packet); | ||||
|       bool isBuffered(unsigned long tid, unsigned long keyNum); | ||||
|       unsigned long bufferedOnPage(unsigned long tid, unsigned long keyNum); | ||||
|     protected: | ||||
|  | @ -58,8 +59,6 @@ namespace Mist { | |||
|       std::map<unsigned long, unsigned long> trackOffset; ///< Offset of data on user page
 | ||||
|       std::map<unsigned long, negotiationState> trackState; ///< State of the negotiation for tracks
 | ||||
|       std::map<unsigned long, unsigned long> trackMap;///<Determines which input track maps onto which "final" track
 | ||||
| 
 | ||||
|       //Using mapped tid's
 | ||||
|       std::map<unsigned long, IPC::sharedPage> metaPages;///< For each track, holds the page that describes which dataPages are mapped
 | ||||
|       std::map<unsigned long, unsigned long> curPageNum;///< For each track, holds the number page that is currently being written.
 | ||||
|       std::map<unsigned long, IPC::sharedPage> curPage;///< For each track, holds the page that is currently being written.
 | ||||
|  |  | |||
|  | @ -120,7 +120,7 @@ namespace Mist { | |||
|     metaPages.clear(); | ||||
|     metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE); | ||||
|     if (!metaPages[0].mapped){ | ||||
|       DEBUG_MSG(DLVL_FAIL, "Could not connect to server for %s\n", streamName.c_str()); | ||||
|       FAIL_MSG("Could not connect to server for %s", streamName.c_str()); | ||||
|       onFail(); | ||||
|       return; | ||||
|     } | ||||
|  |  | |||
|  | @ -200,7 +200,7 @@ namespace Mist { | |||
|       temp = H.url.find("Seg") + 3; | ||||
|       temp = H.url.find("Frag") + 4; | ||||
|       fragNum = atoi(H.url.substr(temp).c_str()) - 1; | ||||
|       DEBUG_MSG(DLVL_MEDIUM, "Video track %d, fragment %d\n", tid, fragNum); | ||||
|       DEBUG_MSG(DLVL_MEDIUM, "Video track %d, fragment %d", tid, fragNum); | ||||
|       if (!audioTrack){getTracks();} | ||||
|       unsigned int mstime = 0; | ||||
|       unsigned int mslen = 0; | ||||
|  |  | |||
|  | @ -824,7 +824,7 @@ namespace Mist { | |||
|         case 18: {//meta data
 | ||||
|           static std::map<unsigned int, AMF::Object> pushMeta; | ||||
|           if (!isInitialized) { | ||||
|             DEBUG_MSG(DLVL_MEDIUM, "Received useless media data\n"); | ||||
|             MEDIUM_MSG("Received useless media data"); | ||||
|             myConn.close(); | ||||
|             break; | ||||
|           } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma