diff --git a/lib/dtsc.cpp b/lib/dtsc.cpp index f9cd821f..e3b4a811 100644 --- a/lib/dtsc.cpp +++ b/lib/dtsc.cpp @@ -384,7 +384,39 @@ void DTSC::Stream::updateRingHeaders(){ } } +/// Returns 0 if seeking is possible, -1 if the wanted frame is too old, 1 if the wanted frame is too new. +int DTSC::Stream::canSeekms(unsigned int ms){ + if ( !metadata["keytime"].size()){ + return 1; + } + if (ms > metadata["keytime"][metadata["keytime"].size() - 1].asInt()){ + return 1; + } + if (ms < metadata["keytime"][0u].asInt()){ + return -1; + } + return 0; +} + +/// Returns 0 if seeking is possible, -1 if the wanted frame is too old, 1 if the wanted frame is too new. +int DTSC::Stream::canSeekFrame(unsigned int frameno){ + if ( !metadata["keynum"].size()){ + return 1; + } + if (frameno > metadata["keynum"][metadata["keynum"].size() - 1].asInt()){ + return 1; + } + if (frameno < metadata["keynum"][0u].asInt()){ + return -1; + } + return 0; +} + unsigned int DTSC::Stream::msSeek(unsigned int ms){ + if (ms > buffers[keyframes[0u].b]["time"].asInt()){ + std::cerr << "Warning: seeking past ingest! (" << ms << "ms > " << buffers[keyframes[0u].b]["time"].asInt() << "ms)" << std::endl; + return keyframes[0u].b; + } for (std::deque::iterator it = keyframes.begin(); it != keyframes.end(); it++){ if (buffers[it->b]["time"].asInt() <= ms){ return it->b; @@ -395,6 +427,10 @@ unsigned int DTSC::Stream::msSeek(unsigned int ms){ } unsigned int DTSC::Stream::frameSeek(unsigned int frameno){ + if (frameno > buffers[keyframes[0u].b]["fragnum"].asInt()){ + std::cerr << "Warning: seeking past ingest! (F" << frameno << " > F" << buffers[keyframes[0u].b]["fragnum"].asInt() << ")" << std::endl; + return keyframes[0u].b; + } for (std::deque::iterator it = keyframes.begin(); it != keyframes.end(); it++){ if (buffers[it->b]["fragnum"].asInt() == frameno){ return it->b; diff --git a/lib/dtsc.h b/lib/dtsc.h index de199ebb..64304346 100644 --- a/lib/dtsc.h +++ b/lib/dtsc.h @@ -127,6 +127,8 @@ namespace DTSC { unsigned int getTime(); void dropRing(Ring * ptr); void updateHeaders(); + int canSeekms(unsigned int ms); + int canSeekFrame(unsigned int frameno); unsigned int msSeek(unsigned int ms); unsigned int frameSeek(unsigned int frameno); void setBufferTime(unsigned int ms); diff --git a/lib/mp4.cpp b/lib/mp4.cpp index dec687d2..c94dacbb 100644 --- a/lib/mp4.cpp +++ b/lib/mp4.cpp @@ -2180,7 +2180,7 @@ namespace MP4 { if (uuid_string[j] == '-'){ continue; } - data[8+i/2] |= (c2hex(uuid_string[j]) << (4-(4*(i%2)))); + data[8+i/2] |= (c2hex(uuid_string[j]) << ((~i & 1) << 2)); ++i; } }