Compare commits

..

1 Commits

Author SHA1 Message Date
matthewjheaney
041a5c5811 Parse headers outside of constructor
In several cases, the parser would parse a header
(say, a track header, or the segment info header)
in the constructor for the type.  The parser had
assumed (incorrectly) that the file was well-formed,
but this turned out to be an incorrect assumption.

The parse errors triggered some assertion failures,
but this is not acceptable in a production system.

The parser solved that problem by separating the
construction of the header object from the parsing
of the file.  There is now a separate parse method
to be called after construction of the object,
which returns a status whether the parse was
successful.

This change fixes the bugs from the following
tracker issues:

http://code.google.com/p/webm/issues/detail?id=399
http://code.google.com/p/webm/issues/detail?id=400

Change-Id: Idb09154ae7008429d8613ce3b3e8294f5a12de86
2012-03-13 14:40:17 -04:00
5 changed files with 403 additions and 1215 deletions

View File

@@ -48,6 +48,7 @@
UsePrecompiledHeader="0"
WarningLevel="4"
DebugInformationFormat="1"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"

View File

@@ -830,7 +830,7 @@ bool Tracks::AddTrack(Track* track, int32 number) {
if (number < 0)
return false;
int32 track_num = number;
uint32 track_num = number;
// Check to make sure a track does not already have |track_num|.
for (uint32 i = 0; i < track_entries_size_; ++i) {

File diff suppressed because it is too large Load Diff

View File

@@ -30,19 +30,16 @@ protected:
long long GetUIntLength(IMkvReader*, long long, long&);
long long ReadUInt(IMkvReader*, long long, long&);
long long SyncReadUInt(IMkvReader*, long long pos, long long stop, long&);
long long UnserializeUInt(IMkvReader*, long long pos, long long size);
float Unserialize4Float(IMkvReader*, long long);
double Unserialize8Double(IMkvReader*, long long);
#if 0
short Unserialize2SInt(IMkvReader*, long long);
signed char Unserialize1SInt(IMkvReader*, long long);
#else
long UnserializeFloat(IMkvReader*, long long pos, long long size, double&);
long UnserializeInt(IMkvReader*, long long pos, long len, long long& result);
#endif
long UnserializeString(IMkvReader*, long long pos, long long size, char*&);
long UnserializeString(
IMkvReader*,
long long pos,
long long size,
char*& str);
long ParseElementHeader(
IMkvReader* pReader,
@@ -52,10 +49,7 @@ long ParseElementHeader(
long long& size);
bool Match(IMkvReader*, long long&, unsigned long, long long&);
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, double&);
bool Match(IMkvReader*, long long&, unsigned long, short&);
void GetVersion(int& major, int& minor, int& build, int& revision);
@@ -305,8 +299,8 @@ public:
const long long m_element_size;
virtual ~Track();
long long GetType() const;
long long GetNumber() const;
long GetType() const;
long GetNumber() const;
unsigned long long GetUid() const;
const char* GetNameAsUTF8() const;
const char* GetCodecNameAsUTF8() const;
@@ -322,21 +316,29 @@ public:
long long size;
};
struct Info
class Info
{
long long type;
long long number;
public:
Info();
~Info();
int Copy(Info&) const;
void Clear();
private:
Info(const Info&);
Info& operator=(const Info&);
public:
long type;
long number;
unsigned long long uid;
char* nameAsUTF8;
char* codecId;
char* codecNameAsUTF8;
unsigned char* codecPrivate;
size_t codecPrivateSize;
char* codecNameAsUTF8;
bool lacing;
Settings settings;
Info();
void Clear();
private:
int CopyStr(char* Info::*str, Info&) const;
};
long GetFirst(const BlockEntry*&) const;
@@ -352,11 +354,10 @@ public:
protected:
Track(
Segment*,
const Info&,
long long element_start,
long long element_size);
const Info m_info;
Info m_info;
class EOSBlock : public BlockEntry
{
@@ -382,7 +383,6 @@ class VideoTrack : public Track
VideoTrack(
Segment*,
const Info&,
long long element_start,
long long element_size);
@@ -416,7 +416,6 @@ class AudioTrack : public Track
AudioTrack(
Segment*,
const Info&,
long long element_start,
long long element_size);
public:
@@ -465,7 +464,7 @@ public:
unsigned long GetTracksCount() const;
const Track* GetTrackByNumber(unsigned long tn) const;
const Track* GetTrackByNumber(long tn) const;
const Track* GetTrackByIndex(unsigned long idx) const;
private:

View File

@@ -161,8 +161,6 @@ int main(int argc, char* argv[])
unsigned long i = 0;
const unsigned long j = pTracks->GetTracksCount();
enum { VIDEO_TRACK = 1, AUDIO_TRACK = 2 };
printf("\n\t\t\t Track Info\n");
while (i != j)
@@ -172,13 +170,13 @@ int main(int argc, char* argv[])
if (pTrack == NULL)
continue;
const long long trackType = pTrack->GetType();
const long long trackNumber = pTrack->GetNumber();
const long trackType = pTrack->GetType();
const long trackNumber = pTrack->GetNumber();
const unsigned long long trackUid = pTrack->GetUid();
const wchar_t* const pTrackName = utf8towcs(pTrack->GetNameAsUTF8());
printf("\t\tTrack Type\t\t: %lld\n", trackType);
printf("\t\tTrack Number\t\t: %lld\n", trackNumber);
printf("\t\tTrack Type\t\t: %ld\n", trackType);
printf("\t\tTrack Number\t\t: %ld\n", trackNumber);
printf("\t\tTrack Uid\t\t: %lld\n", trackUid);
if (pTrackName == NULL)
@@ -207,7 +205,7 @@ int main(int argc, char* argv[])
delete [] pCodecName;
}
if (trackType == VIDEO_TRACK)
if (trackType == mkvparser::Track::kVideo)
{
const VideoTrack* const pVideoTrack =
static_cast<const VideoTrack*>(pTrack);
@@ -222,7 +220,7 @@ int main(int argc, char* argv[])
printf("\t\tVideo Rate\t\t: %f\n",rate);
}
if (trackType == AUDIO_TRACK)
if (trackType == mkvparser::Track::kAudio)
{
const AudioTrack* const pAudioTrack =
static_cast<const AudioTrack*>(pTrack);
@@ -286,7 +284,7 @@ int main(int argc, char* argv[])
const long long time_ns = pBlock->GetTime(pCluster);
printf("\t\t\tBlock\t\t:%s,%s,%15lld\n",
(trackType == VIDEO_TRACK) ? "V" : "A",
(trackType == mkvparser::Track::kVideo) ? "V" : "A",
pBlock->IsKey() ? "I" : "P",
time_ns);