Box edits for parser

This commit is contained in:
Erik Zandvliet 2011-03-19 14:36:09 +01:00
parent d261bca44a
commit bc6748bf3c
2 changed files with 181 additions and 1 deletions

View file

@ -6,6 +6,8 @@
#include <cstring> #include <cstring>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
#include <string>
#include <vector>
struct BoxHeader { struct BoxHeader {
uint32_t TotalSize; uint32_t TotalSize;
@ -16,6 +18,7 @@ class Box {
public: public:
Box(); Box();
Box(uint32_t BoxType); Box(uint32_t BoxType);
Box(uint8_t * Content, uint32_t length);
~Box(); ~Box();
void SetBoxType(uint32_t BoxType); void SetBoxType(uint32_t BoxType);
uint32_t GetBoxType(); uint32_t GetBoxType();
@ -30,6 +33,7 @@ class Box {
static uint8_t * uint8_to_uint8( uint8_t data ); static uint8_t * uint8_to_uint8( uint8_t data );
BoxHeader GetHeader( ); BoxHeader GetHeader( );
void ResetPayload( ); void ResetPayload( );
void Parse( std::string PrintOffset = "" );
private: private:
BoxHeader header; BoxHeader header;
uint8_t * Payload; uint8_t * Payload;
@ -47,6 +51,21 @@ Box::Box(uint32_t BoxType) {
PayloadSize = 0; PayloadSize = 0;
} }
Box::Box(uint8_t * Content, uint32_t length) {
header.TotalSize = (Content[0] << 24) + (Content[1] << 16) + (Content[2] << 8) + (Content[3]);
if(header.TotalSize != length) { std::cerr << "Warning: length sizes differ\n"; }
header.BoxType = (Content[4] << 24) + (Content[5] << 16) + (Content[6] << 8) + (Content[7]);
std::cerr << "Created new box with type \""
<< (char)(header.BoxType >> 24)
<< (char)((header.BoxType << 8) >> 24)
<< (char)((header.BoxType << 16) >> 24)
<< (char)((header.BoxType << 24) >> 24)
<< "\"\n";
PayloadSize = length-8;
Payload = new uint8_t[PayloadSize];
memcpy( Payload, &Content[8], PayloadSize );
}
Box::~Box() { Box::~Box() {
} }
@ -148,3 +167,164 @@ void Box::ResetPayload( ) {
Payload = NULL; Payload = NULL;
} }
} }
void Box::Parse( std::string PrintOffset ) {
if( header.BoxType == 0x61627374 ) {
uint8_t Version = Payload[0];
uint32_t Flags = (Payload[1] << 16) + (Payload[2] << 8) + (Payload[3]); //uint24_t
uint32_t BootstrapInfoVersion = (Payload[4] << 24) + (Payload[5] << 16) +(Payload[6] << 8) + (Payload[7]);
uint8_t Profile = (Payload[8] >> 6); //uint2_t
uint8_t Live = (( Payload[8] >> 5 ) & 0x1); //uint1_t
uint8_t Update = (( Payload[8] >> 4 ) & 0x1); //uint1_t
uint8_t Reserved = ( Payload[8] & 0x4); //uint4_t
uint32_t Timescale = (Payload[9] << 24) + (Payload[10] << 16) +(Payload[11] << 8) + (Payload[12]);
uint32_t CurrentMediaTime_Upperhalf = (Payload[13] << 24) + (Payload[14] << 16) +(Payload[15] << 8) + (Payload[16]);
uint32_t CurrentMediaTime_Lowerhalf = (Payload[17] << 24) + (Payload[18] << 16) +(Payload[19] << 8) + (Payload[20]);
uint32_t SmpteTimeCodeOffset_Upperhalf = (Payload[21] << 24) + (Payload[22] << 16) +(Payload[23] << 8) + (Payload[24]);
uint32_t SmpteTimeCodeOffset_Lowerhalf = (Payload[25] << 24) + (Payload[26] << 16) +(Payload[27] << 8) + (Payload[28]);
std::string MovieIdentifier;
uint8_t ServerEntryCount = -1;
std::vector<std::string> ServerEntryTable;
uint8_t QualityEntryCount = -1;
std::vector<std::string> QualityEntryTable;
std::string DrmData;
std::string MetaData;
uint8_t SegmentRunTableCount = -1;
std::vector<Box*> SegmentRunTableEntries;
uint8_t FragmentRunTableCount = -1;
std::vector<Box*> FragmentRunTableEntries;
uint32_t CurrentOffset = 29;
uint32_t TempSize;
Box* TempBox;
std::string temp;
while( Payload[CurrentOffset] != '\0' ) { MovieIdentifier += Payload[CurrentOffset]; CurrentOffset ++; }
CurrentOffset ++;
ServerEntryCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < ServerEntryCount; i++ ) {
temp = "";
while( Payload[CurrentOffset] != '\0' ) { temp += Payload[CurrentOffset]; CurrentOffset ++; }
ServerEntryTable.push_back(temp);
CurrentOffset++;
}
QualityEntryCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < QualityEntryCount; i++ ) {
temp = "";
while( Payload[CurrentOffset] != '\0' ) { temp += Payload[CurrentOffset]; CurrentOffset ++; }
QualityEntryTable.push_back(temp);
CurrentOffset++;
}
while( Payload[CurrentOffset] != '\0' ) { DrmData += Payload[CurrentOffset]; CurrentOffset ++; }
CurrentOffset ++;
while( Payload[CurrentOffset] != '\0' ) { MetaData += Payload[CurrentOffset]; CurrentOffset ++; }
CurrentOffset ++;
SegmentRunTableCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < SegmentRunTableCount; i++ ) {
TempSize = (Payload[CurrentOffset] << 24) + (Payload[CurrentOffset+1]<< 16) + (Payload[CurrentOffset+2]<< 8) + (Payload[CurrentOffset+3]);
TempBox = new Box( &Payload[CurrentOffset], TempSize );
SegmentRunTableEntries.push_back(TempBox);
CurrentOffset += TempSize;
}
FragmentRunTableCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < FragmentRunTableCount; i++ ) {
TempSize = (Payload[CurrentOffset] << 24) + (Payload[CurrentOffset+1]<< 16) + (Payload[CurrentOffset+2]<< 8) + (Payload[CurrentOffset+3]);
TempBox = new Box( &Payload[CurrentOffset], TempSize );
FragmentRunTableEntries.push_back(TempBox);
CurrentOffset += TempSize;
}
std::cerr << "Box_ABST:\n";
std::cerr << PrintOffset << " Version: " << (int)Version << "\n";
std::cerr << PrintOffset << " Flags: " << (int)Flags << "\n";
std::cerr << PrintOffset << " BootstrapInfoVersion: " << (int)BootstrapInfoVersion << "\n";
std::cerr << PrintOffset << " Profile: " << (int)Profile << "\n";
std::cerr << PrintOffset << " Live: " << (int)Live << "\n";
std::cerr << PrintOffset << " Update: " << (int)Update << "\n";
std::cerr << PrintOffset << " Reserved: " << (int)Reserved << "\n";
std::cerr << PrintOffset << " Timescale: " << (int)Timescale << "\n";
std::cerr << PrintOffset << " CurrentMediaTime: " << (int)CurrentMediaTime_Upperhalf << " " << CurrentMediaTime_Lowerhalf << "\n";
std::cerr << PrintOffset << " SmpteTimeCodeOffset: " << (int)SmpteTimeCodeOffset_Upperhalf << " " << SmpteTimeCodeOffset_Lowerhalf << "\n";
std::cerr << PrintOffset << " MovieIdentifier: " << MovieIdentifier << "\n";
std::cerr << PrintOffset << " ServerEntryCount: " << (int)ServerEntryCount << "\n";
std::cerr << PrintOffset << " ServerEntryTable:\n";
for( uint32_t i = 0; i < ServerEntryTable.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ": " << ServerEntryTable[i] << "\n";
}
std::cerr << PrintOffset << " QualityEntryCount: " << (int)QualityEntryCount << "\n";
std::cerr << PrintOffset << " QualityEntryTable:\n";
for( uint32_t i = 0; i < QualityEntryTable.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ": " << QualityEntryTable[i] << "\n";
}
std::cerr << PrintOffset << " DrmData: " << DrmData << "\n";
std::cerr << PrintOffset << " MetaData: " << MetaData << "\n";
std::cerr << PrintOffset << " SegmentRunTableCount: " << (int)SegmentRunTableCount << "\n";
std::cerr << PrintOffset << " SegmentRunTableEntries:\n";
for( uint32_t i = 0; i < SegmentRunTableEntries.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ": ";
SegmentRunTableEntries[i]->Parse( PrintOffset+" ");
}
std::cerr << PrintOffset << " FragmentRunTableCount: " << (int)FragmentRunTableCount << "\n";
std::cerr << PrintOffset << " FragmentRunTableEntries:\n";
for( uint32_t i = 0; i < FragmentRunTableEntries.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ": ";
FragmentRunTableEntries[i]->Parse( PrintOffset+" ");
}
} else if ( header.BoxType == 0x61737274 ) {
uint8_t Version = Payload[0];
uint32_t Flags = (Payload[1] << 16) + (Payload[2] << 8) + (Payload[3]); //uint24_t
uint8_t QualityEntryCount;
std::vector<std::string> QualitySegmentUrlModifiers;
uint32_t SegmentRunEntryCount;
std::vector< std::pair<uint32_t,uint32_t> > SegmentRunEntryTable;
uint32_t CurrentOffset = 4;
std::string temp;
std::pair<uint32_t,uint32_t> TempPair;
QualityEntryCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < QualityEntryCount; i++ ) {
temp = "";
while( Payload[CurrentOffset] != '\0' ) { temp += Payload[CurrentOffset]; CurrentOffset ++; }
QualitySegmentUrlModifiers.push_back(temp);
CurrentOffset++;
}
SegmentRunEntryCount = Payload[CurrentOffset];
CurrentOffset ++;
for( uint8_t i = 0; i < SegmentRunEntryCount; i++ ) {
TempPair.first = (Payload[CurrentOffset] << 24) + (Payload[CurrentOffset+1] << 16) + (Payload[CurrentOffset+2] << 8) + (Payload[CurrentOffset+3]);
CurrentOffset+=4;
TempPair.second = (Payload[CurrentOffset] << 24) + (Payload[CurrentOffset+1] << 16) + (Payload[CurrentOffset+2] << 8) + (Payload[CurrentOffset+3]);
CurrentOffset+=4;
SegmentRunEntryTable.push_back(TempPair);
}
std::cerr << "Box_ASRT:\n";
std::cerr << PrintOffset << " Version: " << (int)Version << "\n";
std::cerr << PrintOffset << " Flags: " << (int)Flags << "\n";
std::cerr << PrintOffset << " QualityEntryCount: " << (int)QualityEntryCount << "\n";
std::cerr << PrintOffset << " QualitySegmentUrlModifiers:\n";
for( uint32_t i = 0; i < QualitySegmentUrlModifiers.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ": " << QualitySegmentUrlModifiers[i] << "\n";
}
std::cerr << PrintOffset << " SegmentRunEntryCount: " << (int)QualityEntryCount << "\n";
std::cerr << PrintOffset << " SegmentRunEntryTable:\n";
for( uint32_t i = 0; i < SegmentRunEntryTable.size( ); i++ ) {
std::cerr << PrintOffset << " " << i+1 << ":\n";
std::cerr << PrintOffset << " FirstSegment: " << SegmentRunEntryTable[i].first << "\n";
std::cerr << PrintOffset << " FragmentsPerSegment: " << SegmentRunEntryTable[i].second << "\n";
}
} else {
std::cerr << "BoxType '"
<< (char)(header.BoxType >> 24)
<< (char)((header.BoxType << 8) >> 24)
<< (char)((header.BoxType << 16) >> 24)
<< (char)((header.BoxType << 24) >> 24)
<< "' not yet implemented!\n";
}
}

View file

@ -152,7 +152,7 @@ void Box_abst::SetDefaults( ) {
SetVersion( ); SetVersion( );
} }
void SetVersion( bool NewVersion) { void Box_abst::SetVersion( bool NewVersion) {
Version = NewVersion; Version = NewVersion;
} }