diff --git a/mkvparser.cpp b/mkvparser.cpp index 5adab29..855a079 100644 --- a/mkvparser.cpp +++ b/mkvparser.cpp @@ -874,8 +874,10 @@ long long Segment::CreateInstance( else if ((pos + size) > total) return E_FILE_FORMAT_INVALID; - pSegment = new Segment(pReader, pos, size); - assert(pSegment); //TODO + pSegment = new (std::nothrow) Segment(pReader, pos, size); + + if (pSegment == 0) + return -1; //generic error return 0; //success } @@ -886,12 +888,7 @@ long long Segment::CreateInstance( pos += size; //consume payload } - assert(pos == total); - - pSegment = new Segment(pReader, pos, 0); - assert(pSegment); //TODO - - return 0; //success (sort of) + return E_FILE_FORMAT_INVALID; //there is no segment } @@ -1010,6 +1007,93 @@ long long Segment::ParseHeaders() } +#if 0 +long Segment::FindNextCluster(long long& pos, size& len) const +{ + //Outermost (level 0) segment object has been constructed, + //and pos designates start of payload. We need to find the + //inner (level 1) elements. + long long total, available; + + const int status = m_pReader->Length(&total, &available); + assert(status == 0); + assert(total >= 0); + assert(available <= total); + + const long long stop = m_start + m_size; + assert(stop <= total); + assert(m_pos <= stop); + + pos = m_pos; + + while (pos < stop) + { + long long result = GetUIntLength(m_pReader, pos, len); + + if (result < 0) + return static_cast(result); + + if (result > 0) + return E_BUFFER_NOT_FULL; + + if ((pos + len) > stop) + return E_FILE_FORMAT_INVALID; + + if ((pos + len) > available) + return E_BUFFER_NOT_FULL; + + const long long idpos = pos; + const long long id = ReadUInt(m_pReader, idpos, len); + + if (id < 0) //error + return static_cast(id); + + pos += len; //consume ID + + //Read Size + result = GetUIntLength(m_pReader, pos, len); + + if (result < 0) //error + return static_cast(result); + + if (result > 0) + return E_BUFFER_NOT_FULL; + + if ((pos + len) > stop) + return E_FILE_FORMAT_INVALID; + + if ((pos + len) > available) + return E_BUFFER_NOT_FULL; + + const long long size = ReadUInt(m_pReader, pos, len); + + if (size < 0) //error + return static_cast(size); + + pos += len; //consume length of size of element + + //Pos now points to start of payload + + if ((pos + size) > stop) + return E_FILE_FORMAT_INVALID; + + if ((pos + size) > available) + return E_BUFFER_NOT_FULL; + + if (id == 0x0F43B675) //Cluster ID + { + len = static_cast(size); + return 0; //success + } + + pos += size; //consume payload + } + + return E_FILE_FORMAT_INVALID; +} +#endif + + long Segment::ParseCluster(long long& off, long long& new_pos) const { off = -1; diff --git a/mkvparser.hpp b/mkvparser.hpp index c5332f4..d0d3ad4 100644 --- a/mkvparser.hpp +++ b/mkvparser.hpp @@ -532,6 +532,7 @@ public: //for incremental loading long long Unparsed() const; long long ParseHeaders(); //stops when first cluster is found + //long FindNextCluster(long long& pos, long& size) const; long LoadCluster(long long& pos, long& size); //load one cluster long LoadCluster();