More boxes

This commit is contained in:
Erik Zandvliet 2011-01-13 15:19:12 +01:00
parent 6d1ae13193
commit 927996365e
9 changed files with 206 additions and 1 deletions

View file

@ -1,4 +1,4 @@
SRC = box.cpp box_ftyp.cpp box_h264.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_url.cpp box_dref.cpp box_dinf.cpp box_minf.cpp box_vmhd.cpp box_hdlr.cpp main.cpp
SRC = box.cpp box_ftyp.cpp box_h264.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_url.cpp box_dref.cpp box_dinf.cpp box_minf.cpp box_vmhd.cpp box_hdlr.cpp box_trak.cpp box_moov.cpp box_mdia.cpp box_mdhd.cpp main.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Boxtest
INCLUDES =

25
MP4/box_mdhd.cpp Normal file
View file

@ -0,0 +1,25 @@
#include "box_mdhd.h"
Box_mdhd::Box_mdhd( ) {
Container = new Box( 0x6D646864 );
}
Box_mdhd::~Box_mdhd() {
delete Container;
}
Box * Box_mdhd::GetBox() {
return Container;
}
void Box_mdhd::SetLanguage( uint8_t Firstchar, uint8_t Secondchar, uint8_t Thirdchar ) {
uint8_t FirstByte = 0;
uint8_t SecondByte = 0;
Firstchar -= 0x60;
Secondchar -= 0x60;
Thirdchar -= 0x60;
FirstByte += (Firstchar << 2);
FirstByte += (Secondchar >> 3);
SecondByte += (Secondchar << 5);
SecondByte += Thirdchar;
}

18
MP4/box_mdhd.h Normal file
View file

@ -0,0 +1,18 @@
#include "box.h"
class Box_mdhd {
public:
Box_mdhd( );
~Box_mdhd();
Box * GetBox();
// void SetCreationTime( uint32_t TimeStamp = 0 );
// void SetModificationTime( uint32_t TimeStamp = 0 );
// void SetTimeScale( uint32_t TimeUnits = 0 );
// void SetDurationTime( uint32_t TimeUnits = 0 );
void SetLanguage( uint8_t Firstchar = 'n', uint8_t Secondchar = 'l', uint8_t Thirdchar = 'd' );
private:
void SetReserved();
void SetDefaults();
Box * Container;
};//Box_ftyp Class

37
MP4/box_mdia.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "box_mdia.h"
Box_mdia::Box_mdia( ) {
Container = new Box( 0x6D646961 );
}
Box_mdia::~Box_mdia() {
delete Container;
}
Box * Box_mdia::GetBox() {
return Container;
}
void Box_mdia::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_mdia::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_mdia.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_mdia {
public:
Box_mdia();
~Box_mdia();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class

37
MP4/box_moov.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "box_moov.h"
Box_moov::Box_moov( ) {
Container = new Box( 0x6D6F6F76 );
}
Box_moov::~Box_moov() {
delete Container;
}
Box * Box_moov::GetBox() {
return Container;
}
void Box_moov::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_moov::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_moov.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_moov {
public:
Box_moov();
~Box_moov();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class

37
MP4/box_trak.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "box_trak.h"
Box_trak::Box_trak( ) {
Container = new Box( 0x7472616B );
}
Box_trak::~Box_trak() {
delete Container;
}
Box * Box_trak::GetBox() {
return Container;
}
void Box_trak::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_trak::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_trak.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_trak {
public:
Box_trak();
~Box_trak();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class