Fixed newlines in debug messages. Also, backported various Pro edition fixes that belonged in OS edition.

This commit is contained in:
Thulinma 2015-10-08 13:54:54 +02:00
parent 3c409d4b42
commit c20b8f2081
8 changed files with 57 additions and 25 deletions

View file

@ -764,16 +764,13 @@ void DTSC::File::seekNext() {
myPack.null(); myPack.null();
return; return;
} }
fseek(F, currentPositions.begin()->bytePos, SEEK_SET); seekPos thisPos = *currentPositions.begin();
fseek(F, thisPos.bytePos, SEEK_SET);
if (reachedEOF()) { if (reachedEOF()) {
myPack.null(); myPack.null();
return; return;
} }
clearerr(F); 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()); currentPositions.erase(currentPositions.begin());
lastreadpos = ftell(F); lastreadpos = ftell(F);
if (fread(buffer, 4, 1, F) != 1) { if (fread(buffer, 4, 1, F) != 1) {
@ -786,7 +783,7 @@ void DTSC::File::seekNext() {
return; return;
} }
if (memcmp(buffer, DTSC::Magic_Header, 4) == 0) { 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(); return seekNext();
} }
long long unsigned int version = 0; long long unsigned int version = 0;
@ -864,9 +861,12 @@ void DTSC::File::seekNext() {
} }
currentPositions.insert(tmpPos); currentPositions.insert(tmpPos);
} else { } else {
seek_time(myPack.getTime() + 1, myPack.getTrackId(), true); seek_time(myPack.getTime(), myPack.getTrackId(), true);
} }
seek_bpos(tempLoc); 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) { bool DTSC::File::seek_time(unsigned int ms, unsigned int trackNo, bool forceSeek) {
seekPos tmpPos; seekPos tmpPos;
tmpPos.trackID = trackNo; 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.seekTime = myPack.getTime();
tmpPos.bytePos = getBytePos(); tmpPos.bytePos = getBytePos();
} else { } else {

View file

@ -108,7 +108,7 @@ namespace DTSC {
operator bool() const; operator bool() const;
packType getVersion() const; packType getVersion() const;
void reInit(const char * data_, unsigned int len, bool noCopy = false); 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, char *& result, unsigned int & len) const;
void getString(const char * identifier, std::string & result) const; void getString(const char * identifier, std::string & result) const;
void getInt(const char * identifier, int & result) const; void getInt(const char * identifier, int & result) const;

View file

@ -19,7 +19,10 @@ namespace DTSC {
/// Copy constructor for packets, copies an existing packet with same noCopy flag as original. /// Copy constructor for packets, copies an existing packet with same noCopy flag as original.
Packet::Packet(const Packet & rhs) { 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. /// 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 ///\param noCopy Determines whether to make a copy or not
void Packet::reInit(const char * data_, unsigned int len, bool noCopy) { void Packet::reInit(const char * data_, unsigned int len, bool noCopy) {
if (!data_) { 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(); null();
return; return;
} }
@ -168,7 +171,8 @@ namespace DTSC {
} }
/// Re-initializes this Packet to contain a generic DTSC packet with the given data fields. /// 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(); null();
master = true; master = true;
//time and trackID are part of the 20-byte header. //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) //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) //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) //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); resize(sendLen);
//set internal variables //set internal variables
version = DTSC_V2; version = DTSC_V2;
@ -217,7 +221,11 @@ namespace DTSC {
memcpy(data+offset, "\000\004data\002", 7); memcpy(data+offset, "\000\004data\002", 7);
tmpLong = htonl(packDataSize); tmpLong = htonl(packDataSize);
memcpy(data+offset+7, (char *)&tmpLong, 4); memcpy(data+offset+7, (char *)&tmpLong, 4);
if (packData){
memcpy(data+offset+11, packData, packDataSize); memcpy(data+offset+11, packData, packDataSize);
}else{
memset(data+offset+11, 0, packDataSize);
}
//finish container with 0x0000EE //finish container with 0x0000EE
memcpy(data+offset+11+packDataSize, "\000\000\356", 3); memcpy(data+offset+11+packDataSize, "\000\000\356", 3);
} }
@ -1133,7 +1141,7 @@ namespace DTSC {
unsigned int Track::timeToKeynum(unsigned int timestamp){ unsigned int Track::timeToKeynum(unsigned int timestamp){
unsigned int result = 0; unsigned int result = 0;
for (std::deque<Key>::iterator it = keys.begin(); it != keys.end(); it++){ for (std::deque<Key>::iterator it = keys.begin(); it != keys.end(); it++){
if (it->getTime() >= timestamp){ if (it->getTime() > timestamp){
break; break;
} }
result = it->getNumber(); result = it->getNumber();

View file

@ -1,3 +1,4 @@
#include <mist/bitfields.h>
#include "io.h" #include "io.h"
namespace Mist { namespace Mist {
@ -79,12 +80,12 @@ namespace Mist {
//Open the correct page for the data //Open the correct page for the data
char pageId[NAME_BUFFER_SIZE]; char pageId[NAME_BUFFER_SIZE];
snprintf(pageId, NAME_BUFFER_SIZE, SHM_TRACK_DATA, streamName.c_str(), mapTid, pageNumber); 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__ #ifdef __CYGWIN__
curPage[tid].init(pageName, 26 * 1024 * 1024, true); pageSize = 26 * 1024 * 1024;
#else
curPage[tid].init(pageName, pagesByTrack[tid][pageNumber].dataSize, true);
#endif #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. //Make sure the data page is not destroyed when we are done buffering it later on.
curPage[tid].master = false; curPage[tid].master = false;
//Store the pagenumber of the currently buffer page //Store the pagenumber of the currently buffer page
@ -128,6 +129,10 @@ namespace Mist {
return; return;
} }
unsigned long mapTid = trackMap[tid]; 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 the given pagenumber is not a valid page on this track, do nothing
if (!pagesByTrack[tid].count(pageNumber)){ 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); 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 #else
toErase.init(pageName, pagesByTrack[tid][pageNumber].dataSize, false); toErase.init(pageName, pagesByTrack[tid][pageNumber].dataSize, false);
#endif #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) #if defined(__CYGWIN__) || defined(_WIN32)
IPC::releasePage(pageName); IPC::releasePage(pageName);
#endif #endif
@ -324,6 +329,21 @@ namespace Mist {
///Initiates/continues negotiation with the buffer as well ///Initiates/continues negotiation with the buffer as well
///\param packet The packet to buffer ///\param packet The packet to buffer
void InOutBase::bufferLivePacket(JSON::Value & packet) { 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 //Store the trackid for easier access
unsigned long tid = packet.getTrackId(); unsigned long tid = packet.getTrackId();
//Do nothing if the trackid is invalid //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. //Now we either returned or the track has an offset for the user page.
//Get the data from the userPage //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(); char * tmp = userClient.getData();
if (!tmp) { 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); DEBUG_MSG(DLVL_FAIL, "Failed to negotiate for incoming track %lu, there does not seem to be a connection with the buffer", tid);

View file

@ -35,6 +35,7 @@ namespace Mist {
void bufferFinalize(unsigned long tid); void bufferFinalize(unsigned long tid);
void bufferRemove(unsigned long tid, unsigned long pageNumber); void bufferRemove(unsigned long tid, unsigned long pageNumber);
void bufferLivePacket(JSON::Value & packet); void bufferLivePacket(JSON::Value & packet);
void bufferLivePacket(DTSC::Packet & packet);
bool isBuffered(unsigned long tid, unsigned long keyNum); bool isBuffered(unsigned long tid, unsigned long keyNum);
unsigned long bufferedOnPage(unsigned long tid, unsigned long keyNum); unsigned long bufferedOnPage(unsigned long tid, unsigned long keyNum);
protected: protected:
@ -58,8 +59,6 @@ namespace Mist {
std::map<unsigned long, unsigned long> trackOffset; ///< Offset of data on user page 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, negotiationState> trackState; ///< State of the negotiation for tracks
std::map<unsigned long, unsigned long> trackMap;///<Determines which input track maps onto which "final" track 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, 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, 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. std::map<unsigned long, IPC::sharedPage> curPage;///< For each track, holds the page that is currently being written.

View file

@ -120,7 +120,7 @@ namespace Mist {
metaPages.clear(); metaPages.clear();
metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE); metaPages[0].init(pageId, DEFAULT_META_PAGE_SIZE);
if (!metaPages[0].mapped){ 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(); onFail();
return; return;
} }

View file

@ -200,7 +200,7 @@ namespace Mist {
temp = H.url.find("Seg") + 3; temp = H.url.find("Seg") + 3;
temp = H.url.find("Frag") + 4; temp = H.url.find("Frag") + 4;
fragNum = atoi(H.url.substr(temp).c_str()) - 1; 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();} if (!audioTrack){getTracks();}
unsigned int mstime = 0; unsigned int mstime = 0;
unsigned int mslen = 0; unsigned int mslen = 0;

View file

@ -824,7 +824,7 @@ namespace Mist {
case 18: {//meta data case 18: {//meta data
static std::map<unsigned int, AMF::Object> pushMeta; static std::map<unsigned int, AMF::Object> pushMeta;
if (!isInitialized) { if (!isInitialized) {
DEBUG_MSG(DLVL_MEDIUM, "Received useless media data\n"); MEDIUM_MSG("Received useless media data");
myConn.close(); myConn.close();
break; break;
} }