diff --git a/lib/encode.cpp b/lib/encode.cpp index 32bd8da6..41609a6f 100644 --- a/lib/encode.cpp +++ b/lib/encode.cpp @@ -102,6 +102,16 @@ namespace Encodings { return r; } + /// Decodes a hex-encoded std::string to a raw binary std::string. + std::string Hex::decode(const std::string & in){ + std::string ret(in.size()/2, '\000'); + for (size_t i = 0; i < in.size(); ++i){ + char c = in[i]; + ret[i>>1] |= ((c&15) + (((c&64)>>6) | ((c&64)>>3))) << ((~i&1) << 2); + } + return ret; + } + /// urlencodes std::string data, leaving only the characters A-Za-z0-9~!&()' alone. std::string URL::encode(const std::string & c){ std::string escaped = ""; diff --git a/lib/encode.h b/lib/encode.h index c7fb2eac..a604bb42 100644 --- a/lib/encode.h +++ b/lib/encode.h @@ -33,6 +33,9 @@ namespace Encodings { } /// Encodes a single character as two hex digits in string form. static std::string chr(char dec); + + /// Decodes a hex-encoded std::string to a raw binary std::string. + static std::string decode(const std::string & in); }; } diff --git a/lib/h264.cpp b/lib/h264.cpp index 1a659fa8..97bd6320 100644 --- a/lib/h264.cpp +++ b/lib/h264.cpp @@ -102,13 +102,13 @@ namespace h264 { SPSMeta sequenceParameterSet::getCharacteristics() const { SPSMeta result; + result.sep_col_plane = false; //For calculating width unsigned int widthInMbs = 0; unsigned int cropHorizontal = 0; //For calculating height - bool mbsOnlyFlag = 0; unsigned int heightInMapUnits = 0; unsigned int cropVertical = 0; @@ -135,11 +135,11 @@ namespace h264 { //chroma format idc char chromaFormatIdc = bs.getUExpGolomb(); if (chromaFormatIdc == 3) { - bs.skip(1); + result.sep_col_plane = (bs.get(1) == 1); } - bs.getUExpGolomb(); - bs.getUExpGolomb(); - bs.skip(1); + bs.getUExpGolomb();//luma + bs.getUExpGolomb();//chroma + bs.skip(1);//transform bypass if (bs.get(1)) {//Scaling matrix is present char listSize = (chromaFormatIdc == 3 ? 12 : 8); for (size_t i = 0; i < listSize; i++){ @@ -154,23 +154,23 @@ namespace h264 { } } } - bs.getUExpGolomb(); - unsigned int pic_order_cnt_type = bs.getUExpGolomb(); - if (!pic_order_cnt_type) { - bs.getUExpGolomb(); - } else if (pic_order_cnt_type == 1) { + result.log2_max_frame_num = bs.getUExpGolomb() + 4; + result.cnt_type = bs.getUExpGolomb(); + if (!result.cnt_type) { + result.log2_max_order_cnt = bs.getUExpGolomb() + 4; + } else if (result.cnt_type == 1) { DEBUG_MSG(DLVL_DEVEL, "This part of the implementation is incomplete(2), to be continued. If this message is shown, contact developers immediately."); } - bs.getUExpGolomb(); - bs.skip(1); - //Stop skipping data and start doing usefull stuff + result.max_ref_frames = bs.getUExpGolomb();//max_num_ref_frames + result.gaps = (bs.get(1) == 1);//gaps in frame num allowed + //Stop skipping data and start doing useful stuff widthInMbs = bs.getUExpGolomb() + 1; heightInMapUnits = bs.getUExpGolomb() + 1; - mbsOnlyFlag = bs.get(1);//Gets used in height calculation - if (!mbsOnlyFlag) { + result.mbs_only = (bs.get(1) == 1);//Gets used in height calculation + if (!result.mbs_only) { bs.skip(1); } bs.skip(1); @@ -214,7 +214,7 @@ namespace h264 { } result.width = (widthInMbs * 16) - (cropHorizontal * 2); - result.height = ((mbsOnlyFlag ? 1 : 2) * heightInMapUnits * 16) - (cropVertical * 2); + result.height = ((result.mbs_only ? 1 : 2) * heightInMapUnits * 16) - (cropVertical * 2); return result; } diff --git a/lib/h264.h b/lib/h264.h index 48fcfcc9..0afd0540 100644 --- a/lib/h264.h +++ b/lib/h264.h @@ -14,6 +14,13 @@ namespace h264 { double fps; uint8_t profile; uint8_t level; + bool sep_col_plane; + uint8_t cnt_type; + bool gaps;///< Gaps in frame num allowed flag + bool mbs_only;///sin_family == AF_INET6) { + return ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port); + } + if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET) { + return ntohs(((struct sockaddr_in *)destAddr)->sin_port); + } + return 0; +} + /// Sets the socket to be blocking if the parameters is true. /// Sets the socket to be non-blocking otherwise. void Socket::UDPConnection::setBlocking(bool blocking) { @@ -1220,20 +1237,22 @@ bool Socket::UDPConnection::Receive() { data_size = SOCKETSIZE; } #endif - int r = recvfrom(sock, data, data_size, MSG_PEEK | MSG_TRUNC, 0, 0); + int r = recvfrom(sock, data, data_size, MSG_PEEK | MSG_TRUNC | MSG_DONTWAIT, 0, 0); if (r == -1) { if (errno != EAGAIN) { - INFO_MSG("Found an error: %d (%s)", errno, strerror(errno)); + INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno)); } data_len = 0; return false; } if (data_size < (unsigned int)r) { - data = (char *)realloc(data, r); - if (data) { + char* tmp = (char*)realloc(data, r); + if (tmp) { + data = tmp; data_size = r; - } else { - data_size = 0; + }else{ + FAIL_MSG("Could not resize socket buffer to %d bytes!", r); + return false; } } socklen_t destsize = destAddr_size; diff --git a/lib/socket.h b/lib/socket.h index 0d74cd95..fb776972 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -142,6 +142,7 @@ namespace Socket { void setBlocking(bool blocking); void SetDestination(std::string hostname, uint32_t port); void GetDestination(std::string & hostname, uint32_t & port); + uint32_t getDestPort() const; bool Receive(); void SendNow(const std::string & data); void SendNow(const char * data); diff --git a/src/io.cpp b/src/io.cpp index b3bf5853..e539621e 100644 --- a/src/io.cpp +++ b/src/io.cpp @@ -735,7 +735,7 @@ namespace Mist { break; } - MEDIUM_MSG("Buffer has indicated that incoming track %lu should start writing on track %lu, page %lu", tid, finalTid, firstPage); + MEDIUM_MSG("Buffer says %s:%lu should start writing on track %lu, page %lu", streamName.c_str(), tid, finalTid, firstPage); trackMap[tid] = finalTid; if (myMeta.tracks.count(finalTid) && myMeta.tracks[finalTid].lastms){ myMeta.tracks[finalTid].lastms = 0; diff --git a/src/output/output.cpp b/src/output/output.cpp index b292331d..5cfc3a89 100644 --- a/src/output/output.cpp +++ b/src/output/output.cpp @@ -552,14 +552,31 @@ namespace Mist { return buffer.begin()->time; } - ///Return the end time of the VoD asset, or 0 if unknown. + ///Return the start time of the selected tracks. + uint64_t Output::startTime(){ + uint64_t start = 0xFFFFFFFFFFFFFFFFull; + if (selectedTracks.size()){ + for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ + if (myMeta.tracks.count(*it)){ + if (start < myMeta.tracks[*it].firstms){ + start = myMeta.tracks[*it].firstms; + } + } + } + } + return start; + } + + ///Return the end time of the selected tracks, or 0 if unknown or live. uint64_t Output::endTime(){ if (myMeta.live){return 0;} uint64_t end = 0; - for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ - if (myMeta.tracks.count(*it)){ - if (end < myMeta.tracks[*it].lastms){ - end = myMeta.tracks[*it].lastms; + if (selectedTracks.size()){ + for (std::set::iterator it = selectedTracks.begin(); it != selectedTracks.end(); it++){ + if (myMeta.tracks.count(*it)){ + if (end < myMeta.tracks[*it].lastms){ + end = myMeta.tracks[*it].lastms; + } } } } diff --git a/src/output/output.h b/src/output/output.h index 0e2f8589..82699d09 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -59,6 +59,7 @@ namespace Mist { bool seek(unsigned int tid, unsigned long long pos, bool getNextKey = false); void stop(); uint64_t currentTime(); + uint64_t startTime(); uint64_t endTime(); void setBlocking(bool blocking); long unsigned int getMainSelectedTrack();