Compare commits
4 Commits
libwebm-1.
...
libwebm-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
056b0d96a8 | ||
|
|
dbc58d0510 | ||
|
|
a131a01446 | ||
|
|
b8cb358204 |
161
mkvparser.cpp
161
mkvparser.cpp
@@ -21,7 +21,7 @@ void mkvparser::GetVersion(int& major, int& minor, int& build, int& revision)
|
||||
major = 1;
|
||||
minor = 0;
|
||||
build = 0;
|
||||
revision = 13;
|
||||
revision = 14;
|
||||
}
|
||||
|
||||
long long mkvparser::ReadUInt(IMkvReader* pReader, long long pos, long& len)
|
||||
@@ -228,13 +228,16 @@ float mkvparser::Unserialize4Float(
|
||||
assert(pReader);
|
||||
assert(pos >= 0);
|
||||
|
||||
#ifdef _DEBUG
|
||||
long long total, available;
|
||||
|
||||
long hr = pReader->Length(&total, &available);
|
||||
assert(hr >= 0);
|
||||
assert(available <= total);
|
||||
assert((pos + 4) <= available);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
float result;
|
||||
|
||||
unsigned char* const p = (unsigned char*)&result;
|
||||
@@ -250,6 +253,32 @@ float mkvparser::Unserialize4Float(
|
||||
|
||||
++pos;
|
||||
}
|
||||
#else
|
||||
union
|
||||
{
|
||||
float result;
|
||||
unsigned long buf;
|
||||
};
|
||||
|
||||
buf = 0;
|
||||
|
||||
for (int i = 0;;)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
const int status = pReader->Read(pos++, 1, &b);
|
||||
|
||||
if (status < 0) //error
|
||||
return static_cast<float>(status);
|
||||
|
||||
buf |= b;
|
||||
|
||||
if (++i >= 4)
|
||||
break;
|
||||
|
||||
buf <<= 8;
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -262,6 +291,7 @@ double mkvparser::Unserialize8Double(
|
||||
assert(pReader);
|
||||
assert(pos >= 0);
|
||||
|
||||
#if 0
|
||||
double result;
|
||||
|
||||
unsigned char* const p = (unsigned char*)&result;
|
||||
@@ -277,6 +307,32 @@ double mkvparser::Unserialize8Double(
|
||||
|
||||
++pos;
|
||||
}
|
||||
#else
|
||||
union
|
||||
{
|
||||
double result;
|
||||
long long buf;
|
||||
};
|
||||
|
||||
buf = 0;
|
||||
|
||||
for (int i = 0;;)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
const int status = pReader->Read(pos++, 1, &b);
|
||||
|
||||
if (status < 0) //error
|
||||
return static_cast<double>(status);
|
||||
|
||||
buf |= b;
|
||||
|
||||
if (++i >= 8)
|
||||
break;
|
||||
|
||||
buf <<= 8;
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -288,17 +344,20 @@ signed char mkvparser::Unserialize1SInt(
|
||||
assert(pReader);
|
||||
assert(pos >= 0);
|
||||
|
||||
#ifdef _DEBUG
|
||||
long long total, available;
|
||||
|
||||
long hr = pReader->Length(&total, &available);
|
||||
assert(hr == 0);
|
||||
assert(available <= total);
|
||||
assert(pos < available);
|
||||
#endif
|
||||
|
||||
signed char result;
|
||||
unsigned char& b = reinterpret_cast<unsigned char&>(result);
|
||||
|
||||
hr = pReader->Read(pos, 1, (unsigned char*)&result);
|
||||
assert(hr == 0);
|
||||
const int status = pReader->Read(pos, 1, &b);
|
||||
assert(status == 0); //TODO: must be handled somehow
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -310,13 +369,16 @@ short mkvparser::Unserialize2SInt(
|
||||
assert(pReader);
|
||||
assert(pos >= 0);
|
||||
|
||||
#ifdef _DEBUG
|
||||
long long total, available;
|
||||
|
||||
long hr = pReader->Length(&total, &available);
|
||||
assert(hr >= 0);
|
||||
assert(available <= total);
|
||||
assert((pos + 2) <= available);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
short result;
|
||||
|
||||
unsigned char* const p = (unsigned char*)&result;
|
||||
@@ -332,6 +394,24 @@ short mkvparser::Unserialize2SInt(
|
||||
|
||||
++pos;
|
||||
}
|
||||
#else
|
||||
short result = 0;
|
||||
|
||||
for (int i = 0;;)
|
||||
{
|
||||
unsigned char b;
|
||||
|
||||
const int status = pReader->Read(pos++, 1, &b);
|
||||
assert(status == 0); //TODO: must be handled somehow
|
||||
|
||||
result |= b;
|
||||
|
||||
if (++i >= 2)
|
||||
break;
|
||||
|
||||
result <<= 8;
|
||||
}
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1308,7 +1388,7 @@ long Segment::LoadCluster(
|
||||
{
|
||||
long long total, avail;
|
||||
|
||||
const int status = m_pReader->Length(&total, &avail);
|
||||
long status = m_pReader->Length(&total, &avail);
|
||||
|
||||
if (status < 0) //error
|
||||
return status;
|
||||
@@ -1450,11 +1530,12 @@ long Segment::LoadCluster(
|
||||
++m_clusterCount;
|
||||
--m_clusterPreloadCount;
|
||||
|
||||
pCluster->Load(); //establish invariant
|
||||
|
||||
m_pos = pos + size; //consume payload
|
||||
assert(m_pos <= stop);
|
||||
|
||||
status = pCluster->LoadBlockEntries(pos, len);
|
||||
assert(status == 0); //TODO
|
||||
|
||||
return 0; //we have a new cluster
|
||||
}
|
||||
}
|
||||
@@ -1476,7 +1557,8 @@ long Segment::LoadCluster(
|
||||
assert(idx < m_clusterSize);
|
||||
assert(m_clusters[idx] == pCluster);
|
||||
|
||||
pCluster->Load(); //establish invariant
|
||||
status = pCluster->LoadBlockEntries(pos, len);
|
||||
assert(status == 0); //TODO
|
||||
|
||||
return 0; //we have a new cluster
|
||||
}
|
||||
@@ -3261,7 +3343,7 @@ long Segment::ParseNext(
|
||||
|
||||
long long total, avail;
|
||||
|
||||
const int status = m_pReader->Length(&total, &avail);
|
||||
long status = m_pReader->Length(&total, &avail);
|
||||
|
||||
if (status < 0) //error
|
||||
return status;
|
||||
@@ -3473,10 +3555,8 @@ long Segment::ParseNext(
|
||||
|
||||
len = static_cast<long>(size);
|
||||
|
||||
#if 1 //TODO: get rid of this
|
||||
if (element_stop > avail)
|
||||
return E_BUFFER_NOT_FULL;
|
||||
#endif
|
||||
|
||||
if (Cluster::HasBlockEntries(this, idoff)) //relative
|
||||
{
|
||||
@@ -3527,6 +3607,9 @@ long Segment::ParseNext(
|
||||
j = k;
|
||||
else
|
||||
{
|
||||
status = pNext->LoadBlockEntries(pos, len);
|
||||
assert(status == 0);
|
||||
|
||||
pResult = pNext;
|
||||
return 0; //success
|
||||
}
|
||||
@@ -3548,7 +3631,8 @@ long Segment::ParseNext(
|
||||
assert(idx_next < m_clusterSize);
|
||||
assert(m_clusters[idx_next] == pNext);
|
||||
|
||||
pNext->Load(); //because we need this now
|
||||
status = pNext->LoadBlockEntries(pos, len);
|
||||
assert(status == 0); //TODO
|
||||
|
||||
pResult = pNext;
|
||||
return 0; //success
|
||||
@@ -4966,23 +5050,24 @@ void Cluster::Load() const
|
||||
}
|
||||
|
||||
|
||||
long Cluster::Load(long long& pos, long& len) const
|
||||
long Cluster::LoadBlockEntries(long long& pos, long& len) const
|
||||
{
|
||||
assert(m_pSegment);
|
||||
assert(m_pos);
|
||||
assert(m_size);
|
||||
|
||||
if (m_pos > 0) //loaded
|
||||
{
|
||||
assert(m_size > 0);
|
||||
assert(m_timecode >= 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
assert(m_pos < 0); //not loaded yet
|
||||
assert(m_size < 0);
|
||||
assert(m_timecode < 0);
|
||||
//if (m_pos > 0) //loaded
|
||||
//{
|
||||
// assert(m_size > 0);
|
||||
// assert(m_timecode >= 0);
|
||||
// assert(m_entries_count >= 0);
|
||||
//
|
||||
// return 0;
|
||||
//}
|
||||
//
|
||||
//assert(m_pos < 0); //not loaded yet
|
||||
//assert(m_size < 0);
|
||||
//assert(m_timecode < 0);
|
||||
|
||||
IMkvReader* const pReader = m_pSegment->m_pReader;
|
||||
|
||||
@@ -4998,6 +5083,28 @@ long Cluster::Load(long long& pos, long& len) const
|
||||
|
||||
const long long segment_stop = m_pSegment->m_start + m_pSegment->m_size;
|
||||
|
||||
if (m_pos > 0) //at least partially loaded
|
||||
{
|
||||
assert(m_size > 0);
|
||||
|
||||
if (m_entries_count >= 0)
|
||||
return 0;
|
||||
|
||||
pos = m_pSegment->m_start + m_pos; //absolute pos of payload
|
||||
|
||||
const long long cluster_stop = pos + m_size;
|
||||
|
||||
len = static_cast<long>(m_size);
|
||||
|
||||
if (cluster_stop > avail)
|
||||
return E_BUFFER_NOT_FULL;
|
||||
|
||||
LoadBlockEntries(); //TODO
|
||||
assert(m_entries_count >= 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//m_pos *= -1; //relative to segment
|
||||
pos = m_pSegment->m_start - m_pos; //absolute
|
||||
|
||||
@@ -5151,6 +5258,8 @@ long Cluster::Load(long long& pos, long& len) const
|
||||
m_size = size_; // m_size > 0 means we're partially loaded
|
||||
m_timecode = timecode; // m_timecode >= 0 means we're partially loaded
|
||||
|
||||
LoadBlockEntries(); //TODO
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5564,6 +5673,12 @@ const BlockEntry* Cluster::GetNext(const BlockEntry* pEntry) const
|
||||
}
|
||||
|
||||
|
||||
long Cluster::GetEntryCount() const
|
||||
{
|
||||
return m_entries_count;
|
||||
}
|
||||
|
||||
|
||||
const BlockEntry* Cluster::GetEntry(
|
||||
const Track* pTrack,
|
||||
long long time_ns) const
|
||||
|
||||
@@ -568,9 +568,11 @@ public:
|
||||
const BlockEntry* GetMaxKey(const VideoTrack*) const;
|
||||
|
||||
static bool HasBlockEntries(const Segment*, long long);
|
||||
long GetEntryCount() const;
|
||||
|
||||
void Load() const;
|
||||
long Load(long long& pos, long& size) const;
|
||||
void LoadBlockEntries() const;
|
||||
long LoadBlockEntries(long long& pos, long& size) const;
|
||||
|
||||
protected:
|
||||
Cluster(
|
||||
@@ -593,7 +595,6 @@ private:
|
||||
mutable BlockEntry** m_entries;
|
||||
mutable long m_entries_count;
|
||||
|
||||
void LoadBlockEntries() const;
|
||||
void ParseBlockGroup(long long, long long, size_t) const;
|
||||
void ParseSimpleBlock(long long, long long, size_t) const;
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ int main(int argc, char* argv[])
|
||||
// size of segment payload
|
||||
printf("\t\tSize(Segment)\t\t: %lld\n", pSegment->m_size);
|
||||
|
||||
mkvparser::Tracks* const pTracks = pSegment->GetTracks();
|
||||
const mkvparser::Tracks* pTracks = pSegment->GetTracks();
|
||||
|
||||
unsigned long i = 0;
|
||||
const unsigned long j = pTracks->GetTracksCount();
|
||||
|
||||
Reference in New Issue
Block a user