diff --git a/Makefile b/Makefile index 19f53c12..e62cc157 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,10 @@ endif CPPFLAGS = -Wall -g -O2 -fPIC override CPPFLAGS += -funsigned-char -DDEBUG="$(DEBUG)" -DPACKAGE_VERSION="\"$(PACKAGE_VERSION)\"" +ifndef NOSHM +override CPPFLAGS += -DSHM_ENABLED=1 +endif + LDLIBS = -lcrypto THREADLIB = -lpthread -lrt LDLIBS = -lcrypto $(THREADLIB) diff --git a/lib/defines.h b/lib/defines.h index 300c0dea..ee291a43 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -22,7 +22,6 @@ static const char * DBG_LVL_LIST[] = {"NONE", "FAIL", "ERROR", "WARN", "INFO", " #if !defined(__APPLE__) && !defined(__MACH__) && defined(__GNUC__) #include -extern char * program_invocation_short_name; #if DEBUG >= DLVL_DEVEL #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index c7d88e46..68d0144d 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -993,7 +993,7 @@ bool DTSC::File::seek_time(unsigned int ms, unsigned int trackNo, bool forceSeek } //check if packetID matches, if not, skip size + 8 bytes. int packSize = ntohl(((int *)header)[1]); - int packID = ntohl(((int *)header)[2]); + unsigned int packID = ntohl(((int *)header)[2]); if (memcmp(header, Magic_Packet2, 4) != 0 || packID != trackNo) { if (memcmp(header, "DT", 2) != 0) { DEBUG_MSG(DLVL_WARN, "Invalid header during seek to %u in track %d @ %lld - resetting bytePos from %lld to zero", ms, trackNo, lastreadpos, tmpPos.bytePos); diff --git a/lib/dtscmeta.cpp b/lib/dtscmeta.cpp index 43f1d729..c8bdfa75 100644 --- a/lib/dtscmeta.cpp +++ b/lib/dtscmeta.cpp @@ -1042,7 +1042,7 @@ namespace DTSC { } if (trackRef.isMember("keysizes") && trackRef["keysizes"].isString()) { std::string tmp = trackRef["keysizes"].asStringRef(); - for (int i = 0; i < tmp.size(); i += 4){ + for (unsigned int i = 0; i < tmp.size(); i += 4){ keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]); } } @@ -1127,7 +1127,7 @@ namespace DTSC { } if (trackRef.isMember("keysizes") && trackRef["keysizes"].isString()) { std::string tmp = trackRef["keysizes"].asStringRef(); - for (int i = 0; i < tmp.size(); i += 4){ + for (unsigned int i = 0; i < tmp.size(); i += 4){ keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]); } } @@ -1175,7 +1175,7 @@ namespace DTSC { char * tmp = 0; unsigned int tmplen = 0; trackRef.getMember("keysizes").getString(tmp, tmplen); - for (int i = 0; i < tmplen; i += 4){ + for (unsigned int i = 0; i < tmplen; i += 4){ keySizes.push_back((((long unsigned)tmp[i]) << 24) | (((long unsigned)tmp[i+1]) << 16) | (((long unsigned int)tmp[i+2]) << 8) | tmp[i+3]); } } @@ -1184,8 +1184,8 @@ namespace DTSC { ///\brief Updates a track and its metadata given new packet properties. ///Will also insert keyframes on non-video tracks, and creates fragments void Track::update(long long packTime, long long packOffset, long long packDataSize, long long packBytePos, bool isKeyframe, long long packSendSize, unsigned long segment_size) { - if (packTime < lastms) { - DEBUG_MSG(DLVL_WARN, "Received packets for track %d in wrong order (%lld < %d) - ignoring!", (int)trackID, packTime, (int)lastms); + if ((unsigned long long)packTime < lastms) { + DEBUG_MSG(DLVL_WARN, "Received packets for track %u in wrong order (%lld < %llu) - ignoring!", trackID, packTime, lastms); return; } Part newPart; @@ -1218,7 +1218,7 @@ namespace DTSC { keys.push_back(newKey); keySizes.push_back(0); firstms = keys[0].getTime(); - if (!fragments.size() || (packTime > segment_size && packTime - segment_size >= (unsigned long long)getKey(fragments.rbegin()->getNumber()).getTime())) { + if (!fragments.size() || ((unsigned long long)packTime > segment_size && (unsigned long long)packTime - segment_size >= (unsigned long long)getKey(fragments.rbegin()->getNumber()).getTime())) { //new fragment Fragment newFrag; newFrag.setDuration(0); @@ -1642,7 +1642,7 @@ namespace DTSC { writePointer(p, convertInt(keySizes.size() * 4), 4); std::string tmp; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)keySizes[i] >> 24); tmp += ((char)keySizes[i] >> 16); tmp += ((char)keySizes[i] >> 8); @@ -1706,7 +1706,7 @@ namespace DTSC { conn.SendNow(convertInt(keySizes.size() * 4), 4); std::string tmp; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)keySizes[i] >> 24); tmp += ((char)keySizes[i] >> 16); tmp += ((char)keySizes[i] >> 8); @@ -1774,7 +1774,7 @@ namespace DTSC { writePointer(p, convertInt(keySizes.size() * 4), 4); std::string tmp; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)keySizes[i] >> 24); tmp += ((char)keySizes[i] >> 16); tmp += ((char)keySizes[i] >> 8); @@ -1844,7 +1844,7 @@ namespace DTSC { conn.SendNow(convertInt(keySizes.size() * 4), 4); std::string tmp; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)keySizes[i] >> 24); tmp += ((char)keySizes[i] >> 16); tmp += ((char)keySizes[i] >> 8); @@ -2049,7 +2049,7 @@ namespace DTSC { if (keySizes.size()){ std::string tmp; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)(keySizes[i] >> 24)); tmp += ((char)(keySizes[i] >> 16)); tmp += ((char)(keySizes[i] >> 8)); @@ -2099,7 +2099,7 @@ namespace DTSC { result["keys"] = tmp; tmp = ""; tmp.reserve(keySizes.size() * 4); - for (int i = 0; i < keySizes.size(); i++){ + for (unsigned int i = 0; i < keySizes.size(); i++){ tmp += ((char)(keySizes[i] >> 24)); tmp += ((char)(keySizes[i] >> 16)); tmp += ((char)(keySizes[i] >> 8)); diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index e2b69902..c47da332 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -95,8 +95,6 @@ std::string & HTTP::Parser::BuildResponse(std::string code, std::string message) /// Returns a string containing a valid HTTP 1.0 or 1.1 response, ready for sending. /// The response is partly build from internal variables set before this call is made. /// To be precise, protocol, headers and body are used. -/// \param code The HTTP response code. Usually you want 200. -/// \param message The HTTP response message. Usually you want "OK". /// \return A string containing a valid HTTP 1.0 or 1.1 response, ready for sending. /// This function calls this->BuildResponse(this->method,this->url) std::string & HTTP::Parser::BuildResponse() { diff --git a/lib/mp4.cpp b/lib/mp4.cpp index b4d08f26..28719783 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -105,7 +105,7 @@ namespace MP4 { } else if (size == 0) { fseek(newData, 0, SEEK_END); } - DEBUG_MSG(DLVL_DEVEL, "skipping size 0x%0.8lX", size); + DEBUG_MSG(DLVL_DEVEL, "skipping size 0x%.8lX", size); if (fseek(newData, pos + size, SEEK_SET) == 0) { return true; } else { diff --git a/lib/ogg.cpp b/lib/ogg.cpp index 3aecdbae..24bd4180 100644 --- a/lib/ogg.cpp +++ b/lib/ogg.cpp @@ -19,7 +19,7 @@ namespace OGG { std::deque decodeXiphSize(char * data, size_t len){ std::deque res; res.push_back(0); - for (int i = 0; i < len; i++){ + for (unsigned int i = 0; i < len; i++){ *res.rbegin() += data[i]; if (data[i] != 0xFF){ res.push_back(0); @@ -98,7 +98,7 @@ namespace OGG { unsigned int Page::calcPayloadSize(){ unsigned int retVal = 0; - for (int i = 0; i < segments.size(); i++){ + for (unsigned int i = 0; i < segments.size(); i++){ retVal += segments[i].size(); } return retVal; @@ -301,7 +301,7 @@ namespace OGG { r << std::string(indent + 2, ' ') << "Checksum: " << getCRCChecksum() << std::endl; r << std::string(indent + 2, ' ') << (int)getPageSegments() << " segments:" << std::endl; r << std::string(indent + 3, ' '); - for (int i = 0; i < segments.size(); i++){ + for (unsigned int i = 0; i < segments.size(); i++){ r << " " << segments[i].size(); } r << std::endl; @@ -405,7 +405,7 @@ namespace OGG { int Page::getPayloadSize(){ size_t res = 0; - for (int i = 0; i < segments.size(); i++){ + for (unsigned int i = 0; i < segments.size(); i++){ res += segments[i].size(); } return res; @@ -536,7 +536,7 @@ namespace OGG { char tableSize = 0; //char table[255]; char * table = (char *)malloc(255); - int bytesLeft = 0; + unsigned int bytesLeft = 0; for (unsigned int i = 0; i < numSegments; i++){ //calculate amount of 255 bytes needed to store size (remainder not counted) temp = (oggSegments[i].dataString.size() / 255); diff --git a/lib/shared_memory.cpp b/lib/shared_memory.cpp index e595d246..45caf592 100644 --- a/lib/shared_memory.cpp +++ b/lib/shared_memory.cpp @@ -184,7 +184,35 @@ namespace IPC { } -#if !defined __APPLE__ + ///brief Creates a shared page + ///\param name_ The name of the page to be created + ///\param len_ The size to make the page + ///\param master_ Whether to create or merely open the page + ///\param autoBackoff When only opening the page, wait for it to appear or fail + sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff){ + handle = 0; + len = 0; + master = false; + mapped = 0; + init(name_, len_, master_, autoBackoff); + } + + ///\brief Creates a copy of a shared page + ///\param rhs The page to copy + sharedPage::sharedPage(const sharedPage & rhs) { + handle = 0; + len = 0; + master = false; + mapped = 0; + init(rhs.name, rhs.len, rhs.master); + } + + ///\brief Default destructor + sharedPage::~sharedPage() { + close(); + } + +#ifdef SHM_ENABLED ///\brief Unmaps a shared page if allowed void sharedPage::unmap() { if (mapped && len) { @@ -214,26 +242,6 @@ namespace IPC { } } - - ///brief Creates a shared page - ///\param name_ The name of the page to be created - ///\param len_ The size to make the page - ///\param master_ Whether to create or merely open the page - ///\param autoBackoff When only opening the page, wait for it to appear or fail - sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff) : handle(0), len(0), master(false), mapped(0) { - init(name_, len_, master_, autoBackoff); - } - - ///\brief Creates a copy of a shared page - ///\param rhs The page to copy - sharedPage::sharedPage(const sharedPage & rhs) { - handle = 0; - len = 0; - master = false; - mapped = 0; - init(rhs.name, rhs.len, rhs.master); - } - ///\brief Returns whether the shared page is valid or not sharedPage::operator bool() const { return mapped != 0; @@ -327,45 +335,6 @@ namespace IPC { } } - ///\brief Default destructor - sharedPage::~sharedPage() { - close(); - } - -#else - - ///brief Creates a shared page - ///\param name_ The name of the page to be created - ///\param len_ The size to make the page - ///\param master_ Whether to create or merely open the page - ///\param autoBackoff When only opening the page, wait for it to appear or fail - sharedPage::sharedPage(std::string name_, unsigned int len_, bool master_, bool autoBackoff) { - handle = 0; - len = 0; - master = false; - mapped = 0; - init(name_, len_, master_, autoBackoff); - } - - ///\brief Creates a copy of a shared page - ///\param rhs The page to copy - sharedPage::sharedPage(const sharedPage & rhs) { - handle = 0; - len = 0; - master = false; - mapped = 0; - init(rhs.name, rhs.len, rhs.master); - } - - ///\brief Default destructor - sharedPage::~sharedPage() { - unmap(); - close(handle); - if (master && name != "") { - unlink(name.c_str()); - } - } - #endif ///brief Creates a shared file @@ -413,6 +382,18 @@ namespace IPC { len = 0; } } + + /// Unmaps, closes and unlinks (if master and name is set) the shared file. + void sharedFile::close() { + unmap(); + if (handle > 0) { + ::close(handle); + if (master && name != "") { + unlink(name.c_str()); + } + handle = 0; + } + } ///\brief Initialize a page, de-initialize before if needed ///\param name_ The name of the page to be created @@ -420,14 +401,7 @@ namespace IPC { ///\param master_ Whether to create or merely open the page ///\param autoBackoff When only opening the page, wait for it to appear or fail void sharedFile::init(std::string name_, unsigned int len_, bool master_, bool autoBackoff) { - unmap(); - if (master) { - unlink(name.c_str()); - } - if (handle > 0) { - close(handle); - } - handle = 0; + close(); name = name_; len = len_; master = master_; @@ -475,13 +449,7 @@ namespace IPC { ///\brief Default destructor sharedFile::~sharedFile() { - unmap(); - if (master) { - unlink(name.c_str()); - } - if (handle > 0) { - close(handle); - } + close(); } diff --git a/lib/shared_memory.h b/lib/shared_memory.h index 744bd60d..64c146ac 100644 --- a/lib/shared_memory.h +++ b/lib/shared_memory.h @@ -83,46 +83,7 @@ namespace IPC { semaphore * mySemaphore; }; -#if !defined __APPLE__ - ///\brief A class for managing shared memory pages. - class sharedPage { - public: - sharedPage(std::string name_ = "", unsigned int len_ = 0, bool master_ = false, bool autoBackoff = true); - sharedPage(const sharedPage & rhs); - ~sharedPage(); - operator bool() const; - void init(std::string name_, unsigned int len_, bool master_ = false, bool autoBackoff = true); - void operator =(sharedPage & rhs); - bool operator < (const sharedPage & rhs) const { - return name < rhs.name; - } - void unmap(); - void close(); -#ifdef __CYGWIN__ - ///\brief The handle of the opened shared memory page - HANDLE handle; -#else - ///\brief The fd handle of the opened shared memory page - int handle; -#endif - ///\brief The name of the opened shared memory page - std::string name; - ///\brief The size in bytes of the opened shared memory page - long long int len; - ///\brief Whether this class should unlink the shared memory upon deletion or not - bool master; - ///\brief A pointer to the payload of the page - char * mapped; - }; -#else - class sharedPage; -#endif - -#if !defined __APPLE__ - ///\brief A class for managing shared files in the same form as shared memory pages -#else ///\brief A class for managing shared files. -#endif class sharedFile { public: sharedFile(std::string name_ = "", unsigned int len_ = 0, bool master_ = false, bool autoBackoff = true); @@ -134,6 +95,7 @@ namespace IPC { bool operator < (const sharedFile & rhs) const { return name < rhs.name; } + void close(); void unmap(); ///\brief The fd handle of the opened shared file int handle; @@ -147,9 +109,39 @@ namespace IPC { char * mapped; }; -#ifdef __APPLE__ +#ifdef SHM_ENABLED + ///\brief A class for managing shared memory pages. + class sharedPage { + public: + sharedPage(std::string name_ = "", unsigned int len_ = 0, bool master_ = false, bool autoBackoff = true); + sharedPage(const sharedPage & rhs); + ~sharedPage(); + operator bool() const; + void init(std::string name_, unsigned int len_, bool master_ = false, bool autoBackoff = true); + void operator =(sharedPage & rhs); + bool operator < (const sharedPage & rhs) const { + return name < rhs.name; + } + void unmap(); + void close(); + #ifdef __CYGWIN__ + ///\brief The handle of the opened shared memory page + HANDLE handle; + #else + ///\brief The fd handle of the opened shared memory page + int handle; + #endif + ///\brief The name of the opened shared memory page + std::string name; + ///\brief The size in bytes of the opened shared memory page + long long int len; + ///\brief Whether this class should unlink the shared memory upon deletion or not + bool master; + ///\brief A pointer to the payload of the page + char * mapped; + }; +#else ///\brief A class for handling shared memory pages. - /// ///Uses shared files at its backbone, defined for portability class sharedPage: public sharedFile { public: diff --git a/lib/socket.cpp b/lib/socket.cpp index 187e6e0e..6dbf9a3f 100644 --- a/lib/socket.cpp +++ b/lib/socket.cpp @@ -526,6 +526,7 @@ unsigned int Socket::Connection::iwrite(const void * buffer, int len) { /// returning the amount of bytes it actually read. /// \param buffer Location of the buffer to read to. /// \param len Amount of bytes to read. +/// \param flags Flags to use in the recv call. Ignored on fake sockets. /// \returns The amount of bytes actually read. int Socket::Connection::iread(void * buffer, int len, int flags) { if (!connected() || len < 1) { @@ -570,6 +571,7 @@ int Socket::Connection::iread(void * buffer, int len, int flags) { /// Data is read using iread (which is nonblocking if the Socket::Connection itself is), /// then appended to end of buffer. /// \param buffer Socket::Buffer to append data to. +/// \param flags Flags to use in the recv call. Ignored on fake sockets. /// \return True if new data arrived, false otherwise. bool Socket::Connection::iread(Buffer & buffer, int flags) { char cbuffer[BUFFER_BLOCKSIZE]; diff --git a/lib/theora.cpp b/lib/theora.cpp index 72f6a02c..f807cb32 100644 --- a/lib/theora.cpp +++ b/lib/theora.cpp @@ -62,7 +62,7 @@ namespace theora { return false; } if (! newData[0] & 0x80){ - DEBUG_MSG(DLVL_FAIL, "newdata != 0x80: %0.2X", newData[0]); + DEBUG_MSG(DLVL_FAIL, "newdata != 0x80: %.2X", newData[0]); return false; } if (memcmp(newData + 1, "theora", 6) != 0){