Added MOOF and TRAF boxes

This commit is contained in:
Erik Zandvliet 2012-09-25 12:46:49 +02:00 committed by Thulinma
parent 6c7eeec575
commit 5b3a53e9f5
2 changed files with 114 additions and 8 deletions

View file

@ -100,6 +100,8 @@ namespace MP4{
case 0x61627374: return ((ABST*)this)->toPrettyString(indent); break; case 0x61627374: return ((ABST*)this)->toPrettyString(indent); break;
case 0x61667274: return ((AFRT*)this)->toPrettyString(indent); break; case 0x61667274: return ((AFRT*)this)->toPrettyString(indent); break;
case 0x61737274: return ((ASRT*)this)->toPrettyString(indent); break; case 0x61737274: return ((ASRT*)this)->toPrettyString(indent); break;
case 0x7472756E: return ((TRUN*)this)->toPrettyString(indent); break;
case 0x74726166: return ((TRAF*)this)->toPrettyString(indent); break;
default: return std::string(indent, ' ')+"Unimplemented pretty-printing for box "+std::string(data+4,4)+"\n"; break; default: return std::string(indent, ' ')+"Unimplemented pretty-printing for box "+std::string(data+4,4)+"\n"; break;
} }
} }
@ -944,8 +946,43 @@ namespace MP4{
memcpy(data + 4, "moof", 4); memcpy(data + 4, "moof", 4);
} }
void MOOF::addContent( Box* newContent ) { long MOOF::getContentCount() {
content.push_back( newContent ); int res = 0;
int tempLoc = 0;
while( tempLoc < boxedSize()-8 ){
res ++;
tempLoc += Box(data+8+tempLoc, false).boxedSize();
}
return res;
}
void MOOF::setContent( Box newContent, long no ) {
int tempLoc = 0;
int contentCount = getContentCount();
for (int i = 0; i < no; i++){
if (i < contentCount){
tempLoc += Box(data+8+tempLoc,false).boxedSize();
} else {
if(!reserve(tempLoc, 0, (no - contentCount)*8)){return;};
memset(data+tempLoc, 0, (no - contentCount)*8);
tempLoc += (no - contentCount)*8;
break;
}
}
Box oldContent = Box( data+8+tempLoc, false );
if( !reserve( tempLoc, oldContent.boxedSize(), newContent.boxedSize() ) ) { return; }
memcpy( data+8+tempLoc, newContent.asBox(), newContent.boxedSize() );
}
Box MOOF::getContent( long no ){
if( no > getContentCount() ) { return Box(); }
int i = 0;
int tempLoc = 0;
while( i < no ) {
tempLoc += Box( data+8+tempLoc, false).boxedSize();
i++;
}
return Box(data+8+tempLoc, false);
} }
std::string MOOF::toPrettyString( int indent ) { std::string MOOF::toPrettyString( int indent ) {
@ -953,14 +990,75 @@ namespace MP4{
r << std::string(indent, ' ') << "[moof] Movie Fragment Box" << std::endl; r << std::string(indent, ' ') << "[moof] Movie Fragment Box" << std::endl;
Box curBox; Box curBox;
int tempLoc = 0; int tempLoc = 0;
while( tempLoc < boxedSize()-8 ){ int contentCount = getContentCount();
curBox = Box( data+8+tempLoc, false ); for( int i = 0; i < contentCount; i++ ) {
curBox = getContent(i);
r << curBox.toPrettyString(indent+1); r << curBox.toPrettyString(indent+1);
tempLoc += curBox.boxedSize(); tempLoc += curBox.boxedSize();
} }
return r.str(); return r.str();
} }
TRAF::TRAF(){
memcpy(data + 4, "traf", 4);
}
long TRAF::getContentCount() {
int res = 0;
int tempLoc = 0;
while( tempLoc < boxedSize()-8 ){
res ++;
tempLoc += Box(data+8+tempLoc, false).boxedSize();
}
return res;
}
void TRAF::setContent( Box newContent, long no ) {
int tempLoc = 0;
int contentCount = getContentCount();
for (int i = 0; i < no; i++){
if (i < contentCount){
tempLoc += Box(data+8+tempLoc,false).boxedSize();
} else {
if(!reserve(tempLoc, 0, (no - contentCount)*8)){return;};
memset(data+tempLoc, 0, (no - contentCount)*8);
tempLoc += (no - contentCount)*8;
break;
}
}
Box oldContent = Box( data+8+tempLoc, false );
if( !reserve( tempLoc, oldContent.boxedSize(), newContent.boxedSize() ) ) { return; }
memcpy( data+8+tempLoc, newContent.asBox(), newContent.boxedSize() );
}
Box TRAF::getContent( long no ){
if( no > getContentCount() ) { return Box(); }
int i = 0;
int tempLoc = 0;
while( i < no ) {
tempLoc += Box( data+8+tempLoc, false).boxedSize();
i++;
}
return Box(data+8+tempLoc, false);
}
std::string TRAF::toPrettyString( int indent ) {
std::stringstream r;
r << std::string(indent, ' ') << "[traf] Track Fragment Box" << std::endl;
Box curBox;
int tempLoc = 0;
int contentCount = getContentCount();
for( int i = 0; i < contentCount; i++ ) {
curBox = getContent(i);
r << curBox.toPrettyString(indent+1);
tempLoc += curBox.boxedSize();
}
return r.str();
}
TRUN::TRUN(){ TRUN::TRUN(){
memcpy(data + 4, "trun", 4); memcpy(data + 4, "trun", 4);
} }

View file

@ -150,13 +150,21 @@ namespace MP4{
class MOOF : public Box { class MOOF : public Box {
public: public:
MOOF(); MOOF();
void addContent( Box* newContent ); long getContentCount();
void regenerate( ); void setContent( Box newContent, long no );
Box getContent( long no );
std::string toPrettyString(int indent = 0); std::string toPrettyString(int indent = 0);
private:
std::deque<Box*> content;
};//MOOF Box };//MOOF Box
class TRAF : public Box {
public:
TRAF();
long getContentCount();
void setContent( Box newContent, long no );
Box getContent( long no );
std::string toPrettyString(int indent = 0);
};//TRAF Box
struct trunSampleInformation { struct trunSampleInformation {
long sampleDuration; long sampleDuration;
long sampleSize; long sampleSize;