diff --git a/MP4/Makefile b/MP4/Makefile index bf582c10..6c4e47cd 100644 --- a/MP4/Makefile +++ b/MP4/Makefile @@ -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 = diff --git a/MP4/box_mdhd.cpp b/MP4/box_mdhd.cpp new file mode 100644 index 00000000..e3cf8ab1 --- /dev/null +++ b/MP4/box_mdhd.cpp @@ -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; +} diff --git a/MP4/box_mdhd.h b/MP4/box_mdhd.h new file mode 100644 index 00000000..9ba99d10 --- /dev/null +++ b/MP4/box_mdhd.h @@ -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 + diff --git a/MP4/box_mdia.cpp b/MP4/box_mdia.cpp new file mode 100644 index 00000000..dd6a73cb --- /dev/null +++ b/MP4/box_mdia.cpp @@ -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()); +} diff --git a/MP4/box_mdia.h b/MP4/box_mdia.h new file mode 100644 index 00000000..1fb05728 --- /dev/null +++ b/MP4/box_mdia.h @@ -0,0 +1,17 @@ +#include "box.h" +#include +#include + +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 Content; +};//Box_ftyp Class + diff --git a/MP4/box_moov.cpp b/MP4/box_moov.cpp new file mode 100644 index 00000000..a25ee419 --- /dev/null +++ b/MP4/box_moov.cpp @@ -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()); +} diff --git a/MP4/box_moov.h b/MP4/box_moov.h new file mode 100644 index 00000000..b384c04b --- /dev/null +++ b/MP4/box_moov.h @@ -0,0 +1,17 @@ +#include "box.h" +#include +#include + +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 Content; +};//Box_ftyp Class + diff --git a/MP4/box_trak.cpp b/MP4/box_trak.cpp new file mode 100644 index 00000000..c7fef0a3 --- /dev/null +++ b/MP4/box_trak.cpp @@ -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()); +} diff --git a/MP4/box_trak.h b/MP4/box_trak.h new file mode 100644 index 00000000..31f93a88 --- /dev/null +++ b/MP4/box_trak.h @@ -0,0 +1,17 @@ +#include "box.h" +#include +#include + +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 Content; +};//Box_ftyp Class +