removed trailing white spaces in code
Change-Id: Ifec57ab7278a6b63fd2465e32ba82c7805c359ab
This commit is contained in:
174
mkvparser.cpp
174
mkvparser.cpp
@@ -1949,8 +1949,8 @@ long Track::GetNext(const BlockEntry* pCurrEntry, const BlockEntry*& pNextEntry)
|
|||||||
//we want at all; we want the next call to PopulateSample to
|
//we want at all; we want the next call to PopulateSample to
|
||||||
//return end-of-stream, not (re)start from the beginning.
|
//return end-of-stream, not (re)start from the beginning.
|
||||||
//
|
//
|
||||||
//One work-around is to send EOS immediately. We would send
|
//One work-around is to send EOS immediately. We would send
|
||||||
//the EOS the next pass anyway, so maybe it's no great loss. The
|
//the EOS the next pass anyway, so maybe it's no great loss. The
|
||||||
//only problem is that if this the stream really does end one
|
//only problem is that if this the stream really does end one
|
||||||
//cluster early (relative to other tracks), or the last frame
|
//cluster early (relative to other tracks), or the last frame
|
||||||
//happens to be a keyframe ("CanSeekToEnd").
|
//happens to be a keyframe ("CanSeekToEnd").
|
||||||
@@ -1960,7 +1960,7 @@ long Track::GetNext(const BlockEntry* pCurrEntry, const BlockEntry*& pNextEntry)
|
|||||||
//We need to give pCurr some value that means "you've reached EOS".
|
//We need to give pCurr some value that means "you've reached EOS".
|
||||||
//We can't synthesize the special EOS Cluster immediately
|
//We can't synthesize the special EOS Cluster immediately
|
||||||
//(when we first open the file, say), because we use the existance
|
//(when we first open the file, say), because we use the existance
|
||||||
//of that special cluster value to mean that we've read all of
|
//of that special cluster value to mean that we've read all of
|
||||||
//the clusters (this is a network download, so we can't know apriori
|
//the clusters (this is a network download, so we can't know apriori
|
||||||
//how many we have).
|
//how many we have).
|
||||||
//
|
//
|
||||||
@@ -1968,13 +1968,13 @@ long Track::GetNext(const BlockEntry* pCurrEntry, const BlockEntry*& pNextEntry)
|
|||||||
//object itself, to indicate that it should send EOS earlier
|
//object itself, to indicate that it should send EOS earlier
|
||||||
//than when (pCurr=pStop).
|
//than when (pCurr=pStop).
|
||||||
//
|
//
|
||||||
//Or, probably the best solution, when we actually load the
|
//Or, probably the best solution, when we actually load the
|
||||||
//blocks into a cluster: if we notice that there's no block
|
//blocks into a cluster: if we notice that there's no block
|
||||||
//for a track, we synthesize a nonce EOS block for that track.
|
//for a track, we synthesize a nonce EOS block for that track.
|
||||||
//That way we always have something to return. But that will
|
//That way we always have something to return. But that will
|
||||||
//only work for sequential scan???
|
//only work for sequential scan???
|
||||||
|
|
||||||
//pNext = NULL;
|
//pNext = NULL;
|
||||||
//return E_FAIL;
|
//return E_FAIL;
|
||||||
pNextEntry = GetEOS();
|
pNextEntry = GetEOS();
|
||||||
return 1L;
|
return 1L;
|
||||||
@@ -2590,41 +2590,41 @@ void Cluster::LoadBlockEntries()
|
|||||||
if (m_pEntries)
|
if (m_pEntries)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Load();
|
Load();
|
||||||
assert(m_timecode >= 0);
|
assert(m_timecode >= 0);
|
||||||
assert(m_start > 0);
|
assert(m_start > 0);
|
||||||
assert(m_size > 0);
|
assert(m_size > 0);
|
||||||
|
|
||||||
IMkvReader* const pReader = m_pSegment->m_pReader;
|
IMkvReader* const pReader = m_pSegment->m_pReader;
|
||||||
|
|
||||||
long long pos = m_start;
|
long long pos = m_start;
|
||||||
const long long stop = m_start + m_size;
|
const long long stop = m_start + m_size;
|
||||||
long long timecode = -1;
|
long long timecode = -1;
|
||||||
|
|
||||||
long long idx = pos;
|
long long idx = pos;
|
||||||
|
|
||||||
m_entriesCount = 0;
|
m_entriesCount = 0;
|
||||||
|
|
||||||
while (idx < stop)
|
while (idx < stop)
|
||||||
{
|
{
|
||||||
if (Match(pReader, idx, 0x67, timecode))
|
if (Match(pReader, idx, 0x67, timecode))
|
||||||
assert(timecode == m_timecode);
|
assert(timecode == m_timecode);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
const long long id = ReadUInt(pReader, idx, len);
|
const long long id = ReadUInt(pReader, idx, len);
|
||||||
assert(id >= 0); //TODO
|
assert(id >= 0); //TODO
|
||||||
assert((idx + len) <= stop);
|
assert((idx + len) <= stop);
|
||||||
|
|
||||||
idx += len; //consume id
|
idx += len; //consume id
|
||||||
|
|
||||||
const long long size = ReadUInt(pReader, idx, len);
|
const long long size = ReadUInt(pReader, idx, len);
|
||||||
assert(size >= 0); //TODO
|
assert(size >= 0); //TODO
|
||||||
assert((idx + len) <= stop);
|
assert((idx + len) <= stop);
|
||||||
|
|
||||||
idx += len; //consume size
|
idx += len; //consume size
|
||||||
|
|
||||||
if (id == 0x20) //BlockGroup ID
|
if (id == 0x20) //BlockGroup ID
|
||||||
++m_entriesCount;
|
++m_entriesCount;
|
||||||
else if (id == 0x23) //SimpleBlock ID
|
else if (id == 0x23) //SimpleBlock ID
|
||||||
@@ -2633,15 +2633,15 @@ void Cluster::LoadBlockEntries()
|
|||||||
idx += size; //consume payload
|
idx += size; //consume payload
|
||||||
|
|
||||||
assert(idx <= stop);
|
assert(idx <= stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_entriesCount == 0)
|
if (m_entriesCount == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_pEntries = new BlockEntry*[m_entriesCount];
|
m_pEntries = new BlockEntry*[m_entriesCount];
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (pos < stop)
|
while (pos < stop)
|
||||||
{
|
{
|
||||||
if (Match(pReader, pos, 0x67, timecode))
|
if (Match(pReader, pos, 0x67, timecode))
|
||||||
@@ -2652,15 +2652,15 @@ void Cluster::LoadBlockEntries()
|
|||||||
const long long id = ReadUInt(pReader, pos, len);
|
const long long id = ReadUInt(pReader, pos, len);
|
||||||
assert(id >= 0); //TODO
|
assert(id >= 0); //TODO
|
||||||
assert((pos + len) <= stop);
|
assert((pos + len) <= stop);
|
||||||
|
|
||||||
pos += len; //consume id
|
pos += len; //consume id
|
||||||
|
|
||||||
const long long size = ReadUInt(pReader, pos, len);
|
const long long size = ReadUInt(pReader, pos, len);
|
||||||
assert(size >= 0); //TODO
|
assert(size >= 0); //TODO
|
||||||
assert((pos + len) <= stop);
|
assert((pos + len) <= stop);
|
||||||
|
|
||||||
pos += len; //consume size
|
pos += len; //consume size
|
||||||
|
|
||||||
if (id == 0x20) //BlockGroup ID
|
if (id == 0x20) //BlockGroup ID
|
||||||
ParseBlockGroup(pos, size, index++);
|
ParseBlockGroup(pos, size, index++);
|
||||||
else if (id == 0x23) //SimpleBlock ID
|
else if (id == 0x23) //SimpleBlock ID
|
||||||
@@ -2670,7 +2670,7 @@ void Cluster::LoadBlockEntries()
|
|||||||
assert(pos <= stop);
|
assert(pos <= stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pos == stop);
|
assert(pos == stop);
|
||||||
assert(timecode >= 0);
|
assert(timecode >= 0);
|
||||||
assert(index == m_entriesCount);
|
assert(index == m_entriesCount);
|
||||||
@@ -2689,13 +2689,13 @@ long long Cluster::GetTime()
|
|||||||
{
|
{
|
||||||
const long long tc = GetTimeCode();
|
const long long tc = GetTimeCode();
|
||||||
assert(tc >= 0);
|
assert(tc >= 0);
|
||||||
|
|
||||||
const SegmentInfo* const pInfo = m_pSegment->GetInfo();
|
const SegmentInfo* const pInfo = m_pSegment->GetInfo();
|
||||||
assert(pInfo);
|
assert(pInfo);
|
||||||
|
|
||||||
const long long scale = pInfo->GetTimeCodeScale();
|
const long long scale = pInfo->GetTimeCodeScale();
|
||||||
assert(scale >= 1);
|
assert(scale >= 1);
|
||||||
|
|
||||||
const long long t = m_timecode * scale;
|
const long long t = m_timecode * scale;
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
@@ -2707,10 +2707,10 @@ void Cluster::ParseBlockGroup(long long start, long long size, size_t index)
|
|||||||
assert(m_pEntries);
|
assert(m_pEntries);
|
||||||
assert(m_entriesCount);
|
assert(m_entriesCount);
|
||||||
assert(index < m_entriesCount);
|
assert(index < m_entriesCount);
|
||||||
|
|
||||||
BlockGroup* const pGroup = new BlockGroup(this, index, start, size);
|
BlockGroup* const pGroup = new BlockGroup(this, index, start, size);
|
||||||
assert(pGroup); //TODO
|
assert(pGroup); //TODO
|
||||||
|
|
||||||
m_pEntries[index] = pGroup;
|
m_pEntries[index] = pGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2724,7 +2724,7 @@ void Cluster::ParseSimpleBlock(long long start, long long size, size_t index)
|
|||||||
|
|
||||||
SimpleBlock* const pSimpleBlock = new SimpleBlock(this, index, start, size);
|
SimpleBlock* const pSimpleBlock = new SimpleBlock(this, index, start, size);
|
||||||
assert(pSimpleBlock); //TODO
|
assert(pSimpleBlock); //TODO
|
||||||
|
|
||||||
m_pEntries[index] = pSimpleBlock;
|
m_pEntries[index] = pSimpleBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2732,29 +2732,29 @@ void Cluster::ParseSimpleBlock(long long start, long long size, size_t index)
|
|||||||
const BlockEntry* Cluster::GetFirst()
|
const BlockEntry* Cluster::GetFirst()
|
||||||
{
|
{
|
||||||
LoadBlockEntries();
|
LoadBlockEntries();
|
||||||
|
|
||||||
return m_pEntries[0];
|
return m_pEntries[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const BlockEntry* Cluster::GetLast()
|
const BlockEntry* Cluster::GetLast()
|
||||||
{
|
{
|
||||||
if (m_entriesCount == 0)
|
if (m_entriesCount == 0)
|
||||||
return m_pEntries[0];
|
return m_pEntries[0];
|
||||||
|
|
||||||
return m_pEntries[m_entriesCount-1];
|
return m_pEntries[m_entriesCount-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const BlockEntry* Cluster::GetNext(const BlockEntry* pEntry) const
|
const BlockEntry* Cluster::GetNext(const BlockEntry* pEntry) const
|
||||||
{
|
{
|
||||||
assert(pEntry);
|
assert(pEntry);
|
||||||
|
|
||||||
size_t idx = pEntry->GetIndex();
|
size_t idx = pEntry->GetIndex();
|
||||||
|
|
||||||
++idx;
|
++idx;
|
||||||
|
|
||||||
if (idx == m_entriesCount)
|
if (idx == m_entriesCount)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return m_pEntries[idx];
|
return m_pEntries[idx];
|
||||||
@@ -2766,12 +2766,12 @@ const BlockEntry* Cluster::GetEntry(const Track* pTrack)
|
|||||||
{
|
{
|
||||||
|
|
||||||
assert(pTrack);
|
assert(pTrack);
|
||||||
|
|
||||||
if (m_pSegment == NULL) //EOS
|
if (m_pSegment == NULL) //EOS
|
||||||
return pTrack->GetEOS();
|
return pTrack->GetEOS();
|
||||||
|
|
||||||
LoadBlockEntries();
|
LoadBlockEntries();
|
||||||
|
|
||||||
BlockEntry* i = *m_pEntries;
|
BlockEntry* i = *m_pEntries;
|
||||||
BlockEntry* j = *m_pEntries + m_entriesCount;
|
BlockEntry* j = *m_pEntries + m_entriesCount;
|
||||||
while (i != j)
|
while (i != j)
|
||||||
@@ -2780,17 +2780,17 @@ const BlockEntry* Cluster::GetEntry(const Track* pTrack)
|
|||||||
i++;
|
i++;
|
||||||
assert(pEntry);
|
assert(pEntry);
|
||||||
assert(!pEntry->EOS());
|
assert(!pEntry->EOS());
|
||||||
|
|
||||||
const Block* const pBlock = pEntry->GetBlock();
|
const Block* const pBlock = pEntry->GetBlock();
|
||||||
assert(pBlock);
|
assert(pBlock);
|
||||||
|
|
||||||
if (pBlock->GetTrackNumber() != pTrack->GetNumber())
|
if (pBlock->GetTrackNumber() != pTrack->GetNumber())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pTrack->VetEntry(pEntry))
|
if (pTrack->VetEntry(pEntry))
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pTrack->GetEOS(); //no satisfactory block found
|
return pTrack->GetEOS(); //no satisfactory block found
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2807,9 +2807,9 @@ BlockEntry::~BlockEntry()
|
|||||||
|
|
||||||
|
|
||||||
SimpleBlock::SimpleBlock(
|
SimpleBlock::SimpleBlock(
|
||||||
Cluster* pCluster,
|
Cluster* pCluster,
|
||||||
size_t idx,
|
size_t idx,
|
||||||
long long start,
|
long long start,
|
||||||
long long size) :
|
long long size) :
|
||||||
m_pCluster(pCluster),
|
m_pCluster(pCluster),
|
||||||
m_index(idx),
|
m_index(idx),
|
||||||
@@ -2849,9 +2849,9 @@ bool SimpleBlock::IsBFrame() const
|
|||||||
|
|
||||||
|
|
||||||
BlockGroup::BlockGroup(
|
BlockGroup::BlockGroup(
|
||||||
Cluster* pCluster,
|
Cluster* pCluster,
|
||||||
size_t idx,
|
size_t idx,
|
||||||
long long start,
|
long long start,
|
||||||
long long size_) :
|
long long size_) :
|
||||||
m_pCluster(pCluster),
|
m_pCluster(pCluster),
|
||||||
m_index(idx),
|
m_index(idx),
|
||||||
@@ -2860,18 +2860,18 @@ BlockGroup::BlockGroup(
|
|||||||
m_pBlock(NULL) //TODO: accept multiple blocks within a block group
|
m_pBlock(NULL) //TODO: accept multiple blocks within a block group
|
||||||
{
|
{
|
||||||
IMkvReader* const pReader = m_pCluster->m_pSegment->m_pReader;
|
IMkvReader* const pReader = m_pCluster->m_pSegment->m_pReader;
|
||||||
|
|
||||||
long long pos = start;
|
long long pos = start;
|
||||||
const long long stop = start + size_;
|
const long long stop = start + size_;
|
||||||
|
|
||||||
bool bSimpleBlock = false;
|
bool bSimpleBlock = false;
|
||||||
|
|
||||||
while (pos < stop)
|
while (pos < stop)
|
||||||
{
|
{
|
||||||
short t;
|
short t;
|
||||||
|
|
||||||
if (Match(pReader, pos, 0x7B, t))
|
if (Match(pReader, pos, 0x7B, t))
|
||||||
{
|
{
|
||||||
if (t < 0)
|
if (t < 0)
|
||||||
m_prevTimeCode = t;
|
m_prevTimeCode = t;
|
||||||
else if (t > 0)
|
else if (t > 0)
|
||||||
@@ -2885,15 +2885,15 @@ BlockGroup::BlockGroup(
|
|||||||
const long long id = ReadUInt(pReader, pos, len);
|
const long long id = ReadUInt(pReader, pos, len);
|
||||||
assert(id >= 0); //TODO
|
assert(id >= 0); //TODO
|
||||||
assert((pos + len) <= stop);
|
assert((pos + len) <= stop);
|
||||||
|
|
||||||
pos += len; //consume ID
|
pos += len; //consume ID
|
||||||
|
|
||||||
const long long size = ReadUInt(pReader, pos, len);
|
const long long size = ReadUInt(pReader, pos, len);
|
||||||
assert(size >= 0); //TODO
|
assert(size >= 0); //TODO
|
||||||
assert((pos + len) <= stop);
|
assert((pos + len) <= stop);
|
||||||
|
|
||||||
pos += len; //consume size
|
pos += len; //consume size
|
||||||
|
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case 0x23: //SimpleBlock ID
|
case 0x23: //SimpleBlock ID
|
||||||
@@ -2901,21 +2901,21 @@ BlockGroup::BlockGroup(
|
|||||||
//YES, FALL THROUGH TO NEXT CASE
|
//YES, FALL THROUGH TO NEXT CASE
|
||||||
|
|
||||||
case 0x21: //Block ID
|
case 0x21: //Block ID
|
||||||
ParseBlock(pos, size);
|
ParseBlock(pos, size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += size; //consume payload
|
pos += size; //consume payload
|
||||||
assert(pos <= stop);
|
assert(pos <= stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pos == stop);
|
assert(pos == stop);
|
||||||
assert(m_pBlock);
|
assert(m_pBlock);
|
||||||
|
|
||||||
if (!bSimpleBlock)
|
if (!bSimpleBlock)
|
||||||
m_pBlock->SetKey(m_prevTimeCode >= 0);
|
m_pBlock->SetKey(m_prevTimeCode >= 0);
|
||||||
}
|
}
|
||||||
@@ -2928,18 +2928,18 @@ BlockGroup::~BlockGroup()
|
|||||||
|
|
||||||
|
|
||||||
void BlockGroup::ParseBlock(long long start, long long size)
|
void BlockGroup::ParseBlock(long long start, long long size)
|
||||||
{
|
{
|
||||||
IMkvReader* const pReader = m_pCluster->m_pSegment->m_pReader;
|
IMkvReader* const pReader = m_pCluster->m_pSegment->m_pReader;
|
||||||
|
|
||||||
Block* const pBlock = new Block(start, size, pReader);
|
Block* const pBlock = new Block(start, size, pReader);
|
||||||
assert(pBlock); //TODO
|
assert(pBlock); //TODO
|
||||||
|
|
||||||
//TODO: the Matroska spec says you have multiple blocks within the
|
//TODO: the Matroska spec says you have multiple blocks within the
|
||||||
//same block group, with blocks ranked by priority (the flag bits).
|
//same block group, with blocks ranked by priority (the flag bits).
|
||||||
//I haven't ever seen such a file (mkvmux certainly doesn't make
|
//I haven't ever seen such a file (mkvmux certainly doesn't make
|
||||||
//one), so until then I'll just assume block groups contain a single
|
//one), so until then I'll just assume block groups contain a single
|
||||||
//block.
|
//block.
|
||||||
#if 0
|
#if 0
|
||||||
m_blocks.push_back(pBlock);
|
m_blocks.push_back(pBlock);
|
||||||
#else
|
#else
|
||||||
assert(m_pBlock == NULL);
|
assert(m_pBlock == NULL);
|
||||||
@@ -2949,7 +2949,7 @@ void BlockGroup::ParseBlock(long long start, long long size)
|
|||||||
#if 0
|
#if 0
|
||||||
Track* const pTrack = pBlock->GetTrack();
|
Track* const pTrack = pBlock->GetTrack();
|
||||||
assert(pTrack);
|
assert(pTrack);
|
||||||
|
|
||||||
pTrack->Insert(pBlock);
|
pTrack->Insert(pBlock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -2988,7 +2988,7 @@ short BlockGroup::GetPrevTimeCode() const
|
|||||||
short BlockGroup::GetNextTimeCode() const
|
short BlockGroup::GetNextTimeCode() const
|
||||||
{
|
{
|
||||||
return m_nextTimeCode;
|
return m_nextTimeCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BlockGroup::IsBFrame() const
|
bool BlockGroup::IsBFrame() const
|
||||||
@@ -3006,31 +3006,31 @@ Block::Block(long long start, long long size_, IMkvReader* pReader) :
|
|||||||
const long long stop = start + size_;
|
const long long stop = start + size_;
|
||||||
|
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
m_track = ReadUInt(pReader, pos, len);
|
m_track = ReadUInt(pReader, pos, len);
|
||||||
assert(m_track > 0);
|
assert(m_track > 0);
|
||||||
assert((pos + len) <= stop);
|
assert((pos + len) <= stop);
|
||||||
|
|
||||||
pos += len; //consume track number
|
pos += len; //consume track number
|
||||||
assert((stop - pos) >= 2);
|
assert((stop - pos) >= 2);
|
||||||
|
|
||||||
m_timecode = Unserialize2SInt(pReader, pos);
|
m_timecode = Unserialize2SInt(pReader, pos);
|
||||||
|
|
||||||
pos += 2;
|
pos += 2;
|
||||||
assert((stop - pos) >= 1);
|
assert((stop - pos) >= 1);
|
||||||
|
|
||||||
const long hr = pReader->Read(pos, 1, &m_flags);
|
const long hr = pReader->Read(pos, 1, &m_flags);
|
||||||
assert(hr == 0L);
|
assert(hr == 0L);
|
||||||
|
|
||||||
++pos;
|
++pos;
|
||||||
assert(pos <= stop);
|
assert(pos <= stop);
|
||||||
|
|
||||||
m_frameOff = pos;
|
m_frameOff = pos;
|
||||||
|
|
||||||
const long long frame_size = stop - pos;
|
const long long frame_size = stop - pos;
|
||||||
|
|
||||||
assert(frame_size <= 2147483647L);
|
assert(frame_size <= 2147483647L);
|
||||||
|
|
||||||
m_frameSize = static_cast<long>(frame_size);
|
m_frameSize = static_cast<long>(frame_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3038,13 +3038,13 @@ Block::Block(long long start, long long size_, IMkvReader* pReader) :
|
|||||||
long long Block::GetTimeCode(Cluster* pCluster) const
|
long long Block::GetTimeCode(Cluster* pCluster) const
|
||||||
{
|
{
|
||||||
assert(pCluster);
|
assert(pCluster);
|
||||||
|
|
||||||
const long long tc0 = pCluster->GetTimeCode();
|
const long long tc0 = pCluster->GetTimeCode();
|
||||||
assert(tc0 >= 0);
|
assert(tc0 >= 0);
|
||||||
|
|
||||||
const long long tc = tc0 + static_cast<long long>(m_timecode);
|
const long long tc = tc0 + static_cast<long long>(m_timecode);
|
||||||
assert(tc >= 0);
|
assert(tc >= 0);
|
||||||
|
|
||||||
return tc; //unscaled timecode units
|
return tc; //unscaled timecode units
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3052,16 +3052,16 @@ long long Block::GetTimeCode(Cluster* pCluster) const
|
|||||||
long long Block::GetTime(Cluster* pCluster) const
|
long long Block::GetTime(Cluster* pCluster) const
|
||||||
{
|
{
|
||||||
assert(pCluster);
|
assert(pCluster);
|
||||||
|
|
||||||
const long long tc = GetTimeCode(pCluster);
|
const long long tc = GetTimeCode(pCluster);
|
||||||
|
|
||||||
const Segment* const pSegment = pCluster->m_pSegment;
|
const Segment* const pSegment = pCluster->m_pSegment;
|
||||||
const SegmentInfo* const pInfo = pSegment->GetInfo();
|
const SegmentInfo* const pInfo = pSegment->GetInfo();
|
||||||
assert(pInfo);
|
assert(pInfo);
|
||||||
|
|
||||||
const long long scale = pInfo->GetTimeCodeScale();
|
const long long scale = pInfo->GetTimeCodeScale();
|
||||||
assert(scale >= 1);
|
assert(scale >= 1);
|
||||||
|
|
||||||
const long long ns = tc * scale;
|
const long long ns = tc * scale;
|
||||||
|
|
||||||
return ns;
|
return ns;
|
||||||
@@ -3071,7 +3071,7 @@ long long Block::GetTime(Cluster* pCluster) const
|
|||||||
unsigned long Block::GetTrackNumber() const
|
unsigned long Block::GetTrackNumber() const
|
||||||
{
|
{
|
||||||
assert(m_track > 0);
|
assert(m_track > 0);
|
||||||
|
|
||||||
return static_cast<unsigned long>(m_track);
|
return static_cast<unsigned long>(m_track);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3102,9 +3102,9 @@ long Block::Read(IMkvReader* pReader, unsigned char* buf) const
|
|||||||
|
|
||||||
assert(pReader);
|
assert(pReader);
|
||||||
assert(buf);
|
assert(buf);
|
||||||
|
|
||||||
const long hr = pReader->Read(m_frameOff, m_frameSize, buf);
|
const long hr = pReader->Read(m_frameOff, m_frameSize, buf);
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
128
mkvparser.hpp
128
mkvparser.hpp
@@ -22,7 +22,7 @@ class IMkvReader
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual int Read(long long position, long length, unsigned char* buffer) = 0;
|
virtual int Read(long long position, long length, unsigned char* buffer) = 0;
|
||||||
virtual int Length(long long* total, long long* available) = 0;
|
virtual int Length(long long* total, long long* available) = 0;
|
||||||
protected:
|
protected:
|
||||||
virtual ~IMkvReader();
|
virtual ~IMkvReader();
|
||||||
};
|
};
|
||||||
@@ -45,7 +45,7 @@ bool Match(IMkvReader*, long long&, unsigned long, short&);
|
|||||||
struct EBMLHeader
|
struct EBMLHeader
|
||||||
{
|
{
|
||||||
EBMLHeader();
|
EBMLHeader();
|
||||||
~EBMLHeader();
|
~EBMLHeader();
|
||||||
long long m_version;
|
long long m_version;
|
||||||
long long m_readVersion;
|
long long m_readVersion;
|
||||||
long long m_maxIdLength;
|
long long m_maxIdLength;
|
||||||
@@ -53,7 +53,7 @@ struct EBMLHeader
|
|||||||
char* m_docType;
|
char* m_docType;
|
||||||
long long m_docTypeVersion;
|
long long m_docTypeVersion;
|
||||||
long long m_docTypeReadVersion;
|
long long m_docTypeReadVersion;
|
||||||
|
|
||||||
long long Parse(IMkvReader*, long long&);
|
long long Parse(IMkvReader*, long long&);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,11 +70,11 @@ class Block
|
|||||||
public:
|
public:
|
||||||
const long long m_start;
|
const long long m_start;
|
||||||
const long long m_size;
|
const long long m_size;
|
||||||
|
|
||||||
Block(long long start, long long size, IMkvReader*);
|
Block(long long start, long long size, IMkvReader*);
|
||||||
|
|
||||||
unsigned long GetTrackNumber() const;
|
unsigned long GetTrackNumber() const;
|
||||||
|
|
||||||
long long GetTimeCode(Cluster*) const; //absolute, but not scaled
|
long long GetTimeCode(Cluster*) const; //absolute, but not scaled
|
||||||
long long GetTime(Cluster*) const; //absolute, and scaled (nanosecond units)
|
long long GetTime(Cluster*) const; //absolute, and scaled (nanosecond units)
|
||||||
bool IsKey() const;
|
bool IsKey() const;
|
||||||
@@ -82,13 +82,13 @@ public:
|
|||||||
|
|
||||||
long GetSize() const;
|
long GetSize() const;
|
||||||
long Read(IMkvReader*, unsigned char*) const;
|
long Read(IMkvReader*, unsigned char*) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long m_track; //Track::Number()
|
long long m_track; //Track::Number()
|
||||||
short m_timecode; //relative to cluster
|
short m_timecode; //relative to cluster
|
||||||
unsigned char m_flags;
|
unsigned char m_flags;
|
||||||
long long m_frameOff;
|
long long m_frameOff;
|
||||||
long m_frameSize;
|
long m_frameSize;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ class BlockEntry
|
|||||||
{
|
{
|
||||||
BlockEntry(const BlockEntry&);
|
BlockEntry(const BlockEntry&);
|
||||||
BlockEntry& operator=(const BlockEntry&);
|
BlockEntry& operator=(const BlockEntry&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BlockEntry();
|
virtual ~BlockEntry();
|
||||||
virtual bool EOS() const = 0;
|
virtual bool EOS() const = 0;
|
||||||
@@ -105,7 +105,7 @@ public:
|
|||||||
virtual size_t GetIndex() const = 0;
|
virtual size_t GetIndex() const = 0;
|
||||||
virtual const Block* GetBlock() const = 0;
|
virtual const Block* GetBlock() const = 0;
|
||||||
virtual bool IsBFrame() const = 0;
|
virtual bool IsBFrame() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BlockEntry();
|
BlockEntry();
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ public:
|
|||||||
SimpleBlock(Cluster*, size_t, long long start, long long size);
|
SimpleBlock(Cluster*, size_t, long long start, long long size);
|
||||||
|
|
||||||
bool EOS() const;
|
bool EOS() const;
|
||||||
Cluster* GetCluster() const;
|
Cluster* GetCluster() const;
|
||||||
size_t GetIndex() const;
|
size_t GetIndex() const;
|
||||||
const Block* GetBlock() const;
|
const Block* GetBlock() const;
|
||||||
bool IsBFrame() const;
|
bool IsBFrame() const;
|
||||||
@@ -130,7 +130,7 @@ protected:
|
|||||||
Cluster* const m_pCluster;
|
Cluster* const m_pCluster;
|
||||||
const size_t m_index;
|
const size_t m_index;
|
||||||
Block m_block;
|
Block m_block;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -142,28 +142,28 @@ class BlockGroup : public BlockEntry
|
|||||||
public:
|
public:
|
||||||
BlockGroup(Cluster*, size_t, long long, long long);
|
BlockGroup(Cluster*, size_t, long long, long long);
|
||||||
~BlockGroup();
|
~BlockGroup();
|
||||||
|
|
||||||
bool EOS() const;
|
bool EOS() const;
|
||||||
Cluster* GetCluster() const;
|
Cluster* GetCluster() const;
|
||||||
size_t GetIndex() const;
|
size_t GetIndex() const;
|
||||||
const Block* GetBlock() const;
|
const Block* GetBlock() const;
|
||||||
bool IsBFrame() const;
|
bool IsBFrame() const;
|
||||||
|
|
||||||
short GetPrevTimeCode() const; //relative to block's time
|
short GetPrevTimeCode() const; //relative to block's time
|
||||||
short GetNextTimeCode() const; //as above
|
short GetNextTimeCode() const; //as above
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Cluster* const m_pCluster;
|
Cluster* const m_pCluster;
|
||||||
const size_t m_index;
|
const size_t m_index;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlockGroup(Cluster*, size_t, unsigned long);
|
BlockGroup(Cluster*, size_t, unsigned long);
|
||||||
void ParseBlock(long long start, long long size);
|
void ParseBlock(long long start, long long size);
|
||||||
|
|
||||||
short m_prevTimeCode;
|
short m_prevTimeCode;
|
||||||
short m_nextTimeCode;
|
short m_nextTimeCode;
|
||||||
|
|
||||||
//TODO: the Matroska spec says you can have multiple blocks within the
|
//TODO: the Matroska spec says you can have multiple blocks within the
|
||||||
//same block group, with blocks ranked by priority (the flag bits).
|
//same block group, with blocks ranked by priority (the flag bits).
|
||||||
//For now we just cache a single block.
|
//For now we just cache a single block.
|
||||||
#if 0
|
#if 0
|
||||||
@@ -172,7 +172,7 @@ private:
|
|||||||
#else
|
#else
|
||||||
Block* m_pBlock;
|
Block* m_pBlock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -181,25 +181,25 @@ class Track
|
|||||||
Track(const Track&);
|
Track(const Track&);
|
||||||
Track& operator=(const Track&);
|
Track& operator=(const Track&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Segment* const m_pSegment;
|
Segment* const m_pSegment;
|
||||||
virtual ~Track();
|
virtual ~Track();
|
||||||
|
|
||||||
long long GetType() const;
|
long long GetType() const;
|
||||||
unsigned long GetNumber() const;
|
unsigned long GetNumber() const;
|
||||||
const char* GetNameAsUTF8() const;
|
const char* GetNameAsUTF8() const;
|
||||||
const char* GetCodecNameAsUTF8() const;
|
const char* GetCodecNameAsUTF8() const;
|
||||||
const char* GetCodecId() const;
|
const char* GetCodecId() const;
|
||||||
const unsigned char* GetCodecPrivate(size_t&) const;
|
const unsigned char* GetCodecPrivate(size_t&) const;
|
||||||
|
|
||||||
const BlockEntry* GetEOS() const;
|
const BlockEntry* GetEOS() const;
|
||||||
|
|
||||||
struct Settings
|
struct Settings
|
||||||
{
|
{
|
||||||
long long start;
|
long long start;
|
||||||
long long size;
|
long long size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Info
|
struct Info
|
||||||
{
|
{
|
||||||
long long type;
|
long long type;
|
||||||
@@ -214,13 +214,13 @@ public:
|
|||||||
Info();
|
Info();
|
||||||
void Clear();
|
void Clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
long GetFirst(const BlockEntry*&) const;
|
long GetFirst(const BlockEntry*&) const;
|
||||||
long GetNext(const BlockEntry* pCurr, const BlockEntry*& pNext) const;
|
long GetNext(const BlockEntry* pCurr, const BlockEntry*& pNext) const;
|
||||||
virtual bool VetEntry(const BlockEntry*) const = 0;
|
virtual bool VetEntry(const BlockEntry*) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Track(Segment*, const Info&);
|
Track(Segment*, const Info&);
|
||||||
const Info m_info;
|
const Info m_info;
|
||||||
|
|
||||||
class EOSBlock : public BlockEntry
|
class EOSBlock : public BlockEntry
|
||||||
@@ -228,15 +228,15 @@ protected:
|
|||||||
public:
|
public:
|
||||||
EOSBlock();
|
EOSBlock();
|
||||||
|
|
||||||
bool EOS() const;
|
bool EOS() const;
|
||||||
Cluster* GetCluster() const;
|
Cluster* GetCluster() const;
|
||||||
size_t GetIndex() const;
|
size_t GetIndex() const;
|
||||||
const Block* GetBlock() const;
|
const Block* GetBlock() const;
|
||||||
bool IsBFrame() const;
|
bool IsBFrame() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
EOSBlock m_eos;
|
EOSBlock m_eos;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -244,20 +244,20 @@ class VideoTrack : public Track
|
|||||||
{
|
{
|
||||||
VideoTrack(const VideoTrack&);
|
VideoTrack(const VideoTrack&);
|
||||||
VideoTrack& operator=(const VideoTrack&);
|
VideoTrack& operator=(const VideoTrack&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoTrack(Segment*, const Info&);
|
VideoTrack(Segment*, const Info&);
|
||||||
long long GetWidth() const;
|
long long GetWidth() const;
|
||||||
long long GetHeight() const;
|
long long GetHeight() const;
|
||||||
double GetFrameRate() const;
|
double GetFrameRate() const;
|
||||||
|
|
||||||
bool VetEntry(const BlockEntry*) const;
|
bool VetEntry(const BlockEntry*) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long m_width;
|
long long m_width;
|
||||||
long long m_height;
|
long long m_height;
|
||||||
double m_rate;
|
double m_rate;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -267,10 +267,10 @@ class AudioTrack : public Track
|
|||||||
AudioTrack& operator=(const AudioTrack&);
|
AudioTrack& operator=(const AudioTrack&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioTrack(Segment*, const Info&);
|
AudioTrack(Segment*, const Info&);
|
||||||
double GetSamplingRate() const;
|
double GetSamplingRate() const;
|
||||||
long long GetChannels() const;
|
long long GetChannels() const;
|
||||||
long long GetBitDepth() const;
|
long long GetBitDepth() const;
|
||||||
bool VetEntry(const BlockEntry*) const;
|
bool VetEntry(const BlockEntry*) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -289,19 +289,19 @@ public:
|
|||||||
Segment* const m_pSegment;
|
Segment* const m_pSegment;
|
||||||
const long long m_start;
|
const long long m_start;
|
||||||
const long long m_size;
|
const long long m_size;
|
||||||
|
|
||||||
Tracks(Segment*, long long start, long long size);
|
Tracks(Segment*, long long start, long long size);
|
||||||
virtual ~Tracks();
|
virtual ~Tracks();
|
||||||
|
|
||||||
Track* GetTrackByNumber(unsigned long tn) const;
|
Track* GetTrackByNumber(unsigned long tn) const;
|
||||||
Track* GetTrackByIndex(unsigned long idx) const;
|
Track* GetTrackByIndex(unsigned long idx) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Track** m_trackEntries;
|
Track** m_trackEntries;
|
||||||
Track** m_trackEntriesEnd;
|
Track** m_trackEntriesEnd;
|
||||||
|
|
||||||
void ParseTrackEntry(long long, long long, Track*&);
|
void ParseTrackEntry(long long, long long, Track*&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned long GetTracksCount() const;
|
unsigned long GetTracksCount() const;
|
||||||
};
|
};
|
||||||
@@ -311,12 +311,12 @@ class SegmentInfo
|
|||||||
{
|
{
|
||||||
SegmentInfo(const SegmentInfo&);
|
SegmentInfo(const SegmentInfo&);
|
||||||
SegmentInfo& operator=(const SegmentInfo&);
|
SegmentInfo& operator=(const SegmentInfo&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Segment* const m_pSegment;
|
Segment* const m_pSegment;
|
||||||
const long long m_start;
|
const long long m_start;
|
||||||
const long long m_size;
|
const long long m_size;
|
||||||
|
|
||||||
SegmentInfo(Segment*, long long start, long long size);
|
SegmentInfo(Segment*, long long start, long long size);
|
||||||
~SegmentInfo();
|
~SegmentInfo();
|
||||||
long long GetTimeCodeScale() const;
|
long long GetTimeCodeScale() const;
|
||||||
@@ -324,7 +324,7 @@ public:
|
|||||||
const char* GetMuxingAppAsUTF8() const;
|
const char* GetMuxingAppAsUTF8() const;
|
||||||
const char* GetWritingAppAsUTF8() const;
|
const char* GetWritingAppAsUTF8() const;
|
||||||
const char* GetTitleAsUTF8() const;
|
const char* GetTitleAsUTF8() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long m_timecodeScale;
|
long long m_timecodeScale;
|
||||||
double m_duration;
|
double m_duration;
|
||||||
@@ -342,37 +342,37 @@ class Cluster
|
|||||||
public:
|
public:
|
||||||
Segment* const m_pSegment;
|
Segment* const m_pSegment;
|
||||||
const size_t m_index;
|
const size_t m_index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Cluster* Parse(Segment*, size_t, long long off);
|
static Cluster* Parse(Segment*, size_t, long long off);
|
||||||
|
|
||||||
Cluster(); //EndOfStream
|
Cluster(); //EndOfStream
|
||||||
~Cluster();
|
~Cluster();
|
||||||
|
|
||||||
bool EOS() const;
|
bool EOS() const;
|
||||||
|
|
||||||
long long GetTimeCode(); //absolute, but not scaled
|
long long GetTimeCode(); //absolute, but not scaled
|
||||||
long long GetTime(); //absolute, and scaled (nanosecond units)
|
long long GetTime(); //absolute, and scaled (nanosecond units)
|
||||||
|
|
||||||
const BlockEntry* GetFirst();
|
const BlockEntry* GetFirst();
|
||||||
const BlockEntry* GetLast();
|
const BlockEntry* GetLast();
|
||||||
const BlockEntry* GetNext(const BlockEntry*) const;
|
const BlockEntry* GetNext(const BlockEntry*) const;
|
||||||
const BlockEntry* GetEntry(const Track*);
|
const BlockEntry* GetEntry(const Track*);
|
||||||
protected:
|
protected:
|
||||||
Cluster(Segment*, size_t, long long off);
|
Cluster(Segment*, size_t, long long off);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long m_start;
|
long long m_start;
|
||||||
long long m_size;
|
long long m_size;
|
||||||
long long m_timecode;
|
long long m_timecode;
|
||||||
BlockEntry** m_pEntries;
|
BlockEntry** m_pEntries;
|
||||||
size_t m_entriesCount;
|
size_t m_entriesCount;
|
||||||
|
|
||||||
void Load();
|
void Load();
|
||||||
void LoadBlockEntries();
|
void LoadBlockEntries();
|
||||||
void ParseBlockGroup(long long, long long, size_t);
|
void ParseBlockGroup(long long, long long, size_t);
|
||||||
void ParseSimpleBlock(long long, long long, size_t);
|
void ParseSimpleBlock(long long, long long, size_t);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -389,37 +389,37 @@ public:
|
|||||||
const long long m_start; //posn of segment payload
|
const long long m_start; //posn of segment payload
|
||||||
const long long m_size; //size of segment payload
|
const long long m_size; //size of segment payload
|
||||||
Cluster m_eos; //TODO: make private?
|
Cluster m_eos; //TODO: make private?
|
||||||
|
|
||||||
static long long CreateInstance(IMkvReader*, long long, Segment*&);
|
static long long CreateInstance(IMkvReader*, long long, Segment*&);
|
||||||
~Segment();
|
~Segment();
|
||||||
|
|
||||||
//for big-bang loading (source filter)
|
//for big-bang loading (source filter)
|
||||||
long Load();
|
long Load();
|
||||||
|
|
||||||
//for incremental loading (splitter)
|
//for incremental loading (splitter)
|
||||||
long long Unparsed() const;
|
long long Unparsed() const;
|
||||||
long long ParseHeaders();
|
long long ParseHeaders();
|
||||||
long ParseCluster(Cluster*&, long long& newpos) const;
|
long ParseCluster(Cluster*&, long long& newpos) const;
|
||||||
bool AddCluster(Cluster*, long long);
|
bool AddCluster(Cluster*, long long);
|
||||||
|
|
||||||
Tracks* GetTracks() const;
|
Tracks* GetTracks() const;
|
||||||
const SegmentInfo* const GetInfo() const;
|
const SegmentInfo* const GetInfo() const;
|
||||||
long long GetDuration() const;
|
long long GetDuration() const;
|
||||||
|
|
||||||
//NOTE: this turned out to be too inefficient.
|
//NOTE: this turned out to be too inefficient.
|
||||||
//long long Load(long long time_nanoseconds);
|
//long long Load(long long time_nanoseconds);
|
||||||
|
|
||||||
Cluster* GetFirst();
|
Cluster* GetFirst();
|
||||||
Cluster* GetLast();
|
Cluster* GetLast();
|
||||||
unsigned long GetCount() const;
|
unsigned long GetCount() const;
|
||||||
|
|
||||||
Cluster* GetNext(const Cluster*);
|
Cluster* GetNext(const Cluster*);
|
||||||
Cluster* GetCluster(long long time_nanoseconds);
|
Cluster* GetCluster(long long time_nanoseconds);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long m_pos; //absolute file posn; what has been consumed so far
|
long long m_pos; //absolute file posn; what has been consumed so far
|
||||||
SegmentInfo* m_pInfo;
|
SegmentInfo* m_pInfo;
|
||||||
Tracks* m_pTracks;
|
Tracks* m_pTracks;
|
||||||
Cluster** m_clusters;
|
Cluster** m_clusters;
|
||||||
size_t m_clusterCount;
|
size_t m_clusterCount;
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ int MkvReader::Open(const char* fileName)
|
|||||||
{
|
{
|
||||||
if (fileName == NULL)
|
if (fileName == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (m_file)
|
if (m_file)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
const errno_t e = fopen_s(&m_file, fileName, "rb");
|
const errno_t e = fopen_s(&m_file, fileName, "rb");
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
return -1; //error
|
return -1; //error
|
||||||
#else
|
#else
|
||||||
@@ -40,29 +40,29 @@ int MkvReader::Open(const char* fileName)
|
|||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int status = _fseeki64(m_file, 0L, SEEK_END);
|
int status = _fseeki64(m_file, 0L, SEEK_END);
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
return -1; //error
|
return -1; //error
|
||||||
|
|
||||||
m_length = _ftelli64(m_file);
|
m_length = _ftelli64(m_file);
|
||||||
#else
|
#else
|
||||||
fseek(m_file, 0L, SEEK_END);
|
fseek(m_file, 0L, SEEK_END);
|
||||||
m_length = ftell(m_file);
|
m_length = ftell(m_file);
|
||||||
#endif
|
#endif
|
||||||
assert(m_length >= 0);
|
assert(m_length >= 0);
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
status = _fseeki64(m_file, 0L, SEEK_SET);
|
status = _fseeki64(m_file, 0L, SEEK_SET);
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
return -1; //error
|
return -1; //error
|
||||||
#else
|
#else
|
||||||
fseek(m_file, 0L, SEEK_SET);
|
fseek(m_file, 0L, SEEK_SET);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MkvReader::Close()
|
void MkvReader::Close()
|
||||||
@@ -81,10 +81,10 @@ int MkvReader::Length(long long* total, long long* available)
|
|||||||
|
|
||||||
if (total)
|
if (total)
|
||||||
*total = m_length;
|
*total = m_length;
|
||||||
|
|
||||||
if (available)
|
if (available)
|
||||||
*available = m_length;
|
*available = m_length;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,29 +95,29 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer)
|
|||||||
|
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (offset >= m_length)
|
if (offset >= m_length)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
const int status = _fseeki64(m_file, offset, SEEK_SET);
|
const int status = _fseeki64(m_file, offset, SEEK_SET);
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
return -1; //error
|
return -1; //error
|
||||||
#else
|
#else
|
||||||
fseek(m_file, offset, SEEK_SET);
|
fseek(m_file, offset, SEEK_SET);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const size_t size = fread(buffer, 1, len, m_file);
|
const size_t size = fread(buffer, 1, len, m_file);
|
||||||
|
|
||||||
if (size < size_t(len))
|
if (size < size_t(len))
|
||||||
return -1; //error
|
return -1; //error
|
||||||
|
|
||||||
return 0; //success
|
return 0; //success
|
||||||
}
|
}
|
||||||
|
|||||||
120
sample.cpp
120
sample.cpp
@@ -17,41 +17,41 @@ static const wchar_t* utf8towcs(const char* str)
|
|||||||
{
|
{
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
//TODO: this probably requires that the locale be
|
//TODO: this probably requires that the locale be
|
||||||
//configured somehow:
|
//configured somehow:
|
||||||
|
|
||||||
const size_t size = mbstowcs(NULL, str, 0);
|
const size_t size = mbstowcs(NULL, str, 0);
|
||||||
|
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wchar_t* const val = new wchar_t[size+1];
|
wchar_t* const val = new wchar_t[size+1];
|
||||||
|
|
||||||
mbstowcs(val, str, size);
|
mbstowcs(val, str, size);
|
||||||
val[size] = L'\0';
|
val[size] = L'\0';
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc == 1)
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
printf("\t\t\tMkv Parser Sample Application\n");
|
printf("\t\t\tMkv Parser Sample Application\n");
|
||||||
printf("\t\t\tUsage: \n");
|
printf("\t\t\tUsage: \n");
|
||||||
printf("\t\t\t ./sample [input file] \n");
|
printf("\t\t\t ./sample [input file] \n");
|
||||||
printf("\t\t\t ./sample sample.mkv \n");
|
printf("\t\t\t ./sample sample.mkv \n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace mkvparser;
|
using namespace mkvparser;
|
||||||
|
|
||||||
MkvReader reader;
|
MkvReader reader;
|
||||||
|
|
||||||
if (reader.Open(argv[1]))
|
if (reader.Open(argv[1]))
|
||||||
{
|
{
|
||||||
printf("\n Filename is invalid or error while opening.\n");
|
printf("\n Filename is invalid or error while opening.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -62,31 +62,31 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
ebmlHeader.Parse(&reader, pos);
|
ebmlHeader.Parse(&reader, pos);
|
||||||
|
|
||||||
printf("\t\t\t EBML Header\n");
|
printf("\t\t\t EBML Header\n");
|
||||||
printf("\t\tEBML Version\t\t: %lld\n", ebmlHeader.m_version);
|
printf("\t\tEBML Version\t\t: %lld\n", ebmlHeader.m_version);
|
||||||
printf("\t\tEBML MaxIDLength\t: %lld\n", ebmlHeader.m_maxIdLength);
|
printf("\t\tEBML MaxIDLength\t: %lld\n", ebmlHeader.m_maxIdLength);
|
||||||
printf("\t\tEBML MaxSizeLength\t: %lld\n", ebmlHeader.m_maxSizeLength);
|
printf("\t\tEBML MaxSizeLength\t: %lld\n", ebmlHeader.m_maxSizeLength);
|
||||||
printf("\t\tDoc Type\t\t: %s\n", ebmlHeader.m_docType);
|
printf("\t\tDoc Type\t\t: %s\n", ebmlHeader.m_docType);
|
||||||
printf("\t\tPos\t\t\t: %lld\n", pos);
|
printf("\t\tPos\t\t\t: %lld\n", pos);
|
||||||
|
|
||||||
mkvparser::Segment* pSegment;
|
mkvparser::Segment* pSegment;
|
||||||
|
|
||||||
long long ret = mkvparser::Segment::CreateInstance(&reader, pos, pSegment);
|
long long ret = mkvparser::Segment::CreateInstance(&reader, pos, pSegment);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
printf("\n Segment::CreateInstance() failed.");
|
printf("\n Segment::CreateInstance() failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = pSegment->Load();
|
ret = pSegment->Load();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
printf("\n Segment::Load() failed.");
|
printf("\n Segment::Load() failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SegmentInfo* const pSegmentInfo = pSegment->GetInfo();
|
const SegmentInfo* const pSegmentInfo = pSegment->GetInfo();
|
||||||
|
|
||||||
const long long timeCodeScale = pSegmentInfo->GetTimeCodeScale();
|
const long long timeCodeScale = pSegmentInfo->GetTimeCodeScale();
|
||||||
const long long duration_ns = pSegmentInfo->GetDuration();
|
const long long duration_ns = pSegmentInfo->GetDuration();
|
||||||
const wchar_t* const pTitle = utf8towcs(pSegmentInfo->GetTitleAsUTF8());
|
const wchar_t* const pTitle = utf8towcs(pSegmentInfo->GetTitleAsUTF8());
|
||||||
@@ -97,7 +97,7 @@ int main(int argc, char* argv[])
|
|||||||
printf("\t\t\t Segment Info\n");
|
printf("\t\t\t Segment Info\n");
|
||||||
printf("\t\tTimeCodeScale\t\t: %lld \n", timeCodeScale);
|
printf("\t\tTimeCodeScale\t\t: %lld \n", timeCodeScale);
|
||||||
printf("\t\tDuration\t\t: %lld\n", duration_ns);
|
printf("\t\tDuration\t\t: %lld\n", duration_ns);
|
||||||
|
|
||||||
const double duration_sec = double(duration_ns) / 1000000000;
|
const double duration_sec = double(duration_ns) / 1000000000;
|
||||||
printf("\t\tDuration(secs)\t\t: %7.3f\n", duration_sec);
|
printf("\t\tDuration(secs)\t\t: %7.3f\n", duration_sec);
|
||||||
|
|
||||||
@@ -105,39 +105,39 @@ int main(int argc, char* argv[])
|
|||||||
printf("\t\tTrack Name\t\t: NULL\n");
|
printf("\t\tTrack Name\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tTrack Name\t\t: %ls\n", pTitle);
|
printf("\t\tTrack Name\t\t: %ls\n", pTitle);
|
||||||
|
|
||||||
if (pMuxingApp == NULL)
|
if (pMuxingApp == NULL)
|
||||||
printf("\t\tMuxing App\t\t: NULL\n");
|
printf("\t\tMuxing App\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tMuxing App\t\t: %ls\n", pMuxingApp);
|
printf("\t\tMuxing App\t\t: %ls\n", pMuxingApp);
|
||||||
|
|
||||||
if (pWritingApp == NULL)
|
if (pWritingApp == NULL)
|
||||||
printf("\t\tWriting App\t\t: NULL\n");
|
printf("\t\tWriting App\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tWriting App\t\t: %ls\n", pWritingApp);
|
printf("\t\tWriting App\t\t: %ls\n", pWritingApp);
|
||||||
|
|
||||||
printf("\t\tPosition(Segment)\t: %lld\n", pSegment->m_start); // position of segment payload
|
printf("\t\tPosition(Segment)\t: %lld\n", pSegment->m_start); // position of segment payload
|
||||||
printf("\t\tSize(Segment)\t\t: %lld\n", pSegment->m_size); // size of segment payload
|
printf("\t\tSize(Segment)\t\t: %lld\n", pSegment->m_size); // size of segment payload
|
||||||
|
|
||||||
mkvparser::Tracks* const pTracks = pSegment->GetTracks();
|
mkvparser::Tracks* const pTracks = pSegment->GetTracks();
|
||||||
|
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
const unsigned long j = pTracks->GetTracksCount();
|
const unsigned long j = pTracks->GetTracksCount();
|
||||||
|
|
||||||
enum { VIDEO_TRACK = 1, AUDIO_TRACK = 2 };
|
enum { VIDEO_TRACK = 1, AUDIO_TRACK = 2 };
|
||||||
|
|
||||||
printf("\n\t\t\t Track Info\n");
|
printf("\n\t\t\t Track Info\n");
|
||||||
|
|
||||||
while (i != j)
|
while (i != j)
|
||||||
{
|
{
|
||||||
const Track* const pTrack = pTracks->GetTrackByIndex(i++);
|
const Track* const pTrack = pTracks->GetTrackByIndex(i++);
|
||||||
|
|
||||||
if (pTrack == NULL)
|
if (pTrack == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const long long trackType_ = pTrack->GetType();
|
const long long trackType_ = pTrack->GetType();
|
||||||
unsigned long trackType = static_cast<unsigned long>(trackType_);
|
unsigned long trackType = static_cast<unsigned long>(trackType_);
|
||||||
|
|
||||||
unsigned long trackNumber = pTrack->GetNumber();
|
unsigned long trackNumber = pTrack->GetNumber();
|
||||||
const wchar_t* const pTrackName = utf8towcs(pTrack->GetNameAsUTF8());
|
const wchar_t* const pTrackName = utf8towcs(pTrack->GetNameAsUTF8());
|
||||||
|
|
||||||
@@ -146,22 +146,22 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
if (pTrackName == NULL)
|
if (pTrackName == NULL)
|
||||||
printf("\t\tTrack Name\t\t: NULL\n");
|
printf("\t\tTrack Name\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tTrack Name\t\t: %ls \n", pTrackName);
|
printf("\t\tTrack Name\t\t: %ls \n", pTrackName);
|
||||||
|
|
||||||
const char* const pCodecId = pTrack->GetCodecId();
|
const char* const pCodecId = pTrack->GetCodecId();
|
||||||
|
|
||||||
if (pCodecId == NULL)
|
if (pCodecId == NULL)
|
||||||
printf("\t\tCodec Id\t\t: NULL\n");
|
printf("\t\tCodec Id\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tCodec Id\t\t: %s\n", pCodecId);
|
printf("\t\tCodec Id\t\t: %s\n", pCodecId);
|
||||||
|
|
||||||
const wchar_t* const pCodecName = utf8towcs(pTrack->GetCodecNameAsUTF8());
|
const wchar_t* const pCodecName = utf8towcs(pTrack->GetCodecNameAsUTF8());
|
||||||
|
|
||||||
if (pCodecName == NULL)
|
if (pCodecName == NULL)
|
||||||
printf("\t\tCodec Name\t\t: NULL\n");
|
printf("\t\tCodec Name\t\t: NULL\n");
|
||||||
else
|
else
|
||||||
printf("\t\tCodec Name\t\t: %ls\n", pCodecName);
|
printf("\t\tCodec Name\t\t: %ls\n", pCodecName);
|
||||||
|
|
||||||
if (trackType == VIDEO_TRACK)
|
if (trackType == VIDEO_TRACK)
|
||||||
{
|
{
|
||||||
@@ -174,7 +174,7 @@ int main(int argc, char* argv[])
|
|||||||
printf("\t\tVideo Height\t\t: %lld\n", height);
|
printf("\t\tVideo Height\t\t: %lld\n", height);
|
||||||
printf("\t\tVideo Rate\t\t: %f\n",rate);
|
printf("\t\tVideo Rate\t\t: %f\n",rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackType == AUDIO_TRACK)
|
if (trackType == AUDIO_TRACK)
|
||||||
{
|
{
|
||||||
const AudioTrack* const pAudioTrack = static_cast<const AudioTrack* const>(pTrack);
|
const AudioTrack* const pAudioTrack = static_cast<const AudioTrack* const>(pTrack);
|
||||||
@@ -187,12 +187,12 @@ int main(int argc, char* argv[])
|
|||||||
printf("\t\tAddio Sample Rate\t: %.3f\n", sampleRate);
|
printf("\t\tAddio Sample Rate\t: %.3f\n", sampleRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n\n\t\t\t Cluster Info\n");
|
printf("\n\n\t\t\t Cluster Info\n");
|
||||||
const unsigned long clusterCount = pSegment->GetCount();
|
const unsigned long clusterCount = pSegment->GetCount();
|
||||||
|
|
||||||
printf("\t\tCluster Count\t: %ld\n\n", clusterCount);
|
printf("\t\tCluster Count\t: %ld\n\n", clusterCount);
|
||||||
|
|
||||||
if (clusterCount == 0)
|
if (clusterCount == 0)
|
||||||
{
|
{
|
||||||
printf("\t\tSegment has no clusters.\n");
|
printf("\t\tSegment has no clusters.\n");
|
||||||
@@ -201,32 +201,32 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
mkvparser::Cluster* pCluster = pSegment->GetFirst();
|
mkvparser::Cluster* pCluster = pSegment->GetFirst();
|
||||||
|
|
||||||
while ((pCluster != NULL) && !pCluster->EOS())
|
while ((pCluster != NULL) && !pCluster->EOS())
|
||||||
{
|
{
|
||||||
const long long timeCode = pCluster->GetTimeCode();
|
const long long timeCode = pCluster->GetTimeCode();
|
||||||
printf("\t\tCluster Time Code\t: %lld\n", timeCode);
|
printf("\t\tCluster Time Code\t: %lld\n", timeCode);
|
||||||
|
|
||||||
const long long time_ns = pCluster->GetTime();
|
const long long time_ns = pCluster->GetTime();
|
||||||
printf("\t\tCluster Time (ns)\t: %lld\n", time_ns);
|
printf("\t\tCluster Time (ns)\t: %lld\n", time_ns);
|
||||||
|
|
||||||
const BlockEntry* pBlockEntry = pCluster->GetFirst();
|
const BlockEntry* pBlockEntry = pCluster->GetFirst();
|
||||||
|
|
||||||
while ((pBlockEntry != NULL) && !pBlockEntry->EOS())
|
while ((pBlockEntry != NULL) && !pBlockEntry->EOS())
|
||||||
{
|
{
|
||||||
const Block* const pBlock = pBlockEntry->GetBlock();
|
const Block* const pBlock = pBlockEntry->GetBlock();
|
||||||
const unsigned long trackNum = pBlock->GetTrackNumber();
|
const unsigned long trackNum = pBlock->GetTrackNumber();
|
||||||
const long size = pBlock->GetSize();
|
const long size = pBlock->GetSize();
|
||||||
const long long time_ns = pBlock->GetTime(pCluster);
|
const long long time_ns = pBlock->GetTime(pCluster);
|
||||||
|
|
||||||
printf("\t\t\tBlock\t\t:%s,%15ld,%s,%15lld\n",
|
printf("\t\t\tBlock\t\t:%s,%15ld,%s,%15lld\n",
|
||||||
(trackNum == VIDEO_TRACK) ? "V" : "A",
|
(trackNum == VIDEO_TRACK) ? "V" : "A",
|
||||||
size,
|
size,
|
||||||
pBlock->IsKey() ? "I" : "P",
|
pBlock->IsKey() ? "I" : "P",
|
||||||
time_ns);
|
time_ns);
|
||||||
|
|
||||||
pBlockEntry = pCluster->GetNext(pBlockEntry);
|
pBlockEntry = pCluster->GetNext(pBlockEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
pCluster = pSegment->GetNext(pCluster);
|
pCluster = pSegment->GetNext(pCluster);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user