Compare commits
3 Commits
main
...
sandbox/ma
Author | SHA1 | Date | |
---|---|---|---|
|
379839bedc | ||
|
484c71d875 | ||
|
a45b72d731 |
1326
mkvparser.cpp
1326
mkvparser.cpp
File diff suppressed because it is too large
Load Diff
@ -42,6 +42,15 @@ signed char Unserialize1SInt(IMkvReader*, long long);
|
|||||||
long UnserializeInt(IMkvReader*, long long pos, long len, long long& result);
|
long UnserializeInt(IMkvReader*, long long pos, long len, long long& result);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
long UnserializeString(IMkvReader*, long long pos, long long size, char*&);
|
||||||
|
|
||||||
|
long ParseElementHeader(
|
||||||
|
IMkvReader* pReader,
|
||||||
|
long long& pos, //consume id and size fields
|
||||||
|
long long stop, //if you know size of element's parent
|
||||||
|
long long& id,
|
||||||
|
long long& size);
|
||||||
|
|
||||||
bool Match(IMkvReader*, long long&, unsigned long, long long&);
|
bool Match(IMkvReader*, long long&, unsigned long, long long&);
|
||||||
bool Match(IMkvReader*, long long&, unsigned long, char*&);
|
bool Match(IMkvReader*, long long&, unsigned long, char*&);
|
||||||
bool Match(IMkvReader*, long long&, unsigned long, unsigned char*&, size_t&);
|
bool Match(IMkvReader*, long long&, unsigned long, unsigned char*&, size_t&);
|
||||||
@ -289,6 +298,8 @@ class Track
|
|||||||
Track& operator=(const Track&);
|
Track& operator=(const Track&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum Type { kVideo = 1, kAudio = 2 };
|
||||||
|
|
||||||
Segment* const m_pSegment;
|
Segment* const m_pSegment;
|
||||||
const long long m_element_start;
|
const long long m_element_start;
|
||||||
const long long m_element_size;
|
const long long m_element_size;
|
||||||
@ -344,6 +355,7 @@ protected:
|
|||||||
const Info&,
|
const Info&,
|
||||||
long long element_start,
|
long long element_start,
|
||||||
long long element_size);
|
long long element_size);
|
||||||
|
|
||||||
const Info m_info;
|
const Info m_info;
|
||||||
|
|
||||||
class EOSBlock : public BlockEntry
|
class EOSBlock : public BlockEntry
|
||||||
@ -368,12 +380,20 @@ class VideoTrack : public Track
|
|||||||
VideoTrack(const VideoTrack&);
|
VideoTrack(const VideoTrack&);
|
||||||
VideoTrack& operator=(const VideoTrack&);
|
VideoTrack& operator=(const VideoTrack&);
|
||||||
|
|
||||||
public:
|
|
||||||
VideoTrack(
|
VideoTrack(
|
||||||
Segment*,
|
Segment*,
|
||||||
const Info&,
|
const Info&,
|
||||||
long long element_start,
|
long long element_start,
|
||||||
long long element_size);
|
long long element_size);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static long Parse(
|
||||||
|
Segment*,
|
||||||
|
const Info&,
|
||||||
|
long long element_start,
|
||||||
|
long long element_size,
|
||||||
|
VideoTrack*&);
|
||||||
|
|
||||||
long long GetWidth() const;
|
long long GetWidth() const;
|
||||||
long long GetHeight() const;
|
long long GetHeight() const;
|
||||||
double GetFrameRate() const;
|
double GetFrameRate() const;
|
||||||
@ -394,12 +414,19 @@ class AudioTrack : public Track
|
|||||||
AudioTrack(const AudioTrack&);
|
AudioTrack(const AudioTrack&);
|
||||||
AudioTrack& operator=(const AudioTrack&);
|
AudioTrack& operator=(const AudioTrack&);
|
||||||
|
|
||||||
public:
|
|
||||||
AudioTrack(
|
AudioTrack(
|
||||||
Segment*,
|
Segment*,
|
||||||
const Info&,
|
const Info&,
|
||||||
long long element_start,
|
long long element_start,
|
||||||
long long element_size);
|
long long element_size);
|
||||||
|
public:
|
||||||
|
static long Parse(
|
||||||
|
Segment*,
|
||||||
|
const Info&,
|
||||||
|
long long element_start,
|
||||||
|
long long element_size,
|
||||||
|
AudioTrack*&);
|
||||||
|
|
||||||
double GetSamplingRate() const;
|
double GetSamplingRate() const;
|
||||||
long long GetChannels() const;
|
long long GetChannels() const;
|
||||||
long long GetBitDepth() const;
|
long long GetBitDepth() const;
|
||||||
@ -431,7 +458,12 @@ public:
|
|||||||
long long size,
|
long long size,
|
||||||
long long element_start,
|
long long element_start,
|
||||||
long long element_size);
|
long long element_size);
|
||||||
virtual ~Tracks();
|
|
||||||
|
~Tracks();
|
||||||
|
|
||||||
|
long Parse();
|
||||||
|
|
||||||
|
unsigned long GetTracksCount() const;
|
||||||
|
|
||||||
const Track* GetTrackByNumber(unsigned long tn) const;
|
const Track* GetTrackByNumber(unsigned long tn) const;
|
||||||
const Track* GetTrackByIndex(unsigned long idx) const;
|
const Track* GetTrackByIndex(unsigned long idx) const;
|
||||||
@ -440,15 +472,13 @@ private:
|
|||||||
Track** m_trackEntries;
|
Track** m_trackEntries;
|
||||||
Track** m_trackEntriesEnd;
|
Track** m_trackEntriesEnd;
|
||||||
|
|
||||||
void ParseTrackEntry(
|
long ParseTrackEntry(
|
||||||
long long,
|
long long payload_start,
|
||||||
long long,
|
long long payload_size,
|
||||||
Track*&,
|
|
||||||
long long element_start,
|
long long element_start,
|
||||||
long long element_size);
|
long long element_size,
|
||||||
|
Track*&) const;
|
||||||
|
|
||||||
public:
|
|
||||||
unsigned long GetTracksCount() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -473,6 +503,8 @@ public:
|
|||||||
|
|
||||||
~SegmentInfo();
|
~SegmentInfo();
|
||||||
|
|
||||||
|
long Parse();
|
||||||
|
|
||||||
long long GetTimeCodeScale() const;
|
long long GetTimeCodeScale() const;
|
||||||
long long GetDuration() const; //scaled
|
long long GetDuration() const; //scaled
|
||||||
const char* GetMuxingAppAsUTF8() const;
|
const char* GetMuxingAppAsUTF8() const;
|
||||||
@ -509,6 +541,8 @@ public:
|
|||||||
|
|
||||||
~SeekHead();
|
~SeekHead();
|
||||||
|
|
||||||
|
long Parse();
|
||||||
|
|
||||||
struct Entry
|
struct Entry
|
||||||
{
|
{
|
||||||
//the SeekHead entry payload
|
//the SeekHead entry payload
|
||||||
|
49
sample.cpp
49
sample.cpp
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "mkvreader.hpp"
|
#include "mkvreader.hpp"
|
||||||
#include "mkvparser.hpp"
|
#include "mkvparser.hpp"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// Silences these warnings:
|
// Silences these warnings:
|
||||||
@ -83,15 +84,18 @@ int main(int argc, char* argv[])
|
|||||||
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;
|
typedef mkvparser::Segment seg_t;
|
||||||
|
seg_t* pSegment_;
|
||||||
|
|
||||||
long long ret = mkvparser::Segment::CreateInstance(&reader, pos, pSegment);
|
long long ret = seg_t::CreateInstance(&reader, pos, pSegment_);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
printf("\n Segment::CreateInstance() failed.");
|
printf("\n Segment::CreateInstance() failed.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::auto_ptr<seg_t> pSegment(pSegment_);
|
||||||
|
|
||||||
ret = pSegment->Load();
|
ret = pSegment->Load();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -242,7 +246,6 @@ int main(int argc, char* argv[])
|
|||||||
if (clusterCount == 0)
|
if (clusterCount == 0)
|
||||||
{
|
{
|
||||||
printf("\t\tSegment has no clusters.\n");
|
printf("\t\tSegment has no clusters.\n");
|
||||||
delete pSegment;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +267,7 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
printf("\t\tError parsing first block of cluster\n");
|
printf("\t\tError parsing first block of cluster\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
goto done;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((pBlockEntry != NULL) && !pBlockEntry->EOS())
|
while ((pBlockEntry != NULL) && !pBlockEntry->EOS())
|
||||||
@ -273,21 +276,27 @@ int main(int argc, char* argv[])
|
|||||||
const long long trackNum = pBlock->GetTrackNumber();
|
const long long trackNum = pBlock->GetTrackNumber();
|
||||||
const unsigned long tn = static_cast<unsigned long>(trackNum);
|
const unsigned long tn = static_cast<unsigned long>(trackNum);
|
||||||
const Track* const pTrack = pTracks->GetTrackByNumber(tn);
|
const Track* const pTrack = pTracks->GetTrackByNumber(tn);
|
||||||
const long long trackType = pTrack->GetType();
|
|
||||||
const int frameCount = pBlock->GetFrameCount();
|
|
||||||
const long long time_ns = pBlock->GetTime(pCluster);
|
|
||||||
|
|
||||||
printf("\t\t\tBlock\t\t:%s,%s,%15lld\n",
|
if (pTrack == NULL)
|
||||||
(trackType == VIDEO_TRACK) ? "V" : "A",
|
printf("\t\t\tBlock\t\t:UNKNOWN TRACK TYPE\n");
|
||||||
pBlock->IsKey() ? "I" : "P",
|
else
|
||||||
time_ns);
|
|
||||||
|
|
||||||
for (int i = 0; i < frameCount; ++i)
|
|
||||||
{
|
{
|
||||||
const Block::Frame& theFrame = pBlock->GetFrame(i);
|
const long long trackType = pTrack->GetType();
|
||||||
const long size = theFrame.len;
|
const int frameCount = pBlock->GetFrameCount();
|
||||||
const long long offset = theFrame.pos;
|
const long long time_ns = pBlock->GetTime(pCluster);
|
||||||
printf("\t\t\t %15ld,%15llx\n", size, offset);
|
|
||||||
|
printf("\t\t\tBlock\t\t:%s,%s,%15lld\n",
|
||||||
|
(trackType == VIDEO_TRACK) ? "V" : "A",
|
||||||
|
pBlock->IsKey() ? "I" : "P",
|
||||||
|
time_ns);
|
||||||
|
|
||||||
|
for (int i = 0; i < frameCount; ++i)
|
||||||
|
{
|
||||||
|
const Block::Frame& theFrame = pBlock->GetFrame(i);
|
||||||
|
const long size = theFrame.len;
|
||||||
|
const long long offset = theFrame.pos;
|
||||||
|
printf("\t\t\t %15ld,%15llx\n", size, offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = pCluster->GetNext(pBlockEntry, pBlockEntry);
|
status = pCluster->GetNext(pBlockEntry, pBlockEntry);
|
||||||
@ -296,15 +305,13 @@ int main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
printf("\t\t\tError parsing next block of cluster\n");
|
printf("\t\t\tError parsing next block of cluster\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
goto done;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pCluster = pSegment->GetNext(pCluster);
|
pCluster = pSegment->GetNext(pCluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
fflush(stdout);
|
||||||
delete pSegment;
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user