diff --git a/MP4/Makefile b/MP4/Makefile index b8ed4103..18f0e3ab 100644 --- a/MP4/Makefile +++ b/MP4/Makefile @@ -1,4 +1,4 @@ -SRC = box_avcC.cpp box.cpp box_dinf.cpp box_dref.cpp box_esds.cpp box_ftyp.cpp box_hdlr.cpp box_hmhd.cpp box_mdhd.cpp box_mdia.cpp box_minf.cpp box_moov.cpp box_mvhd.cpp box_nmhd.cpp box_smhd.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_tkhd.cpp box_trak.cpp box_url.cpp box_vmhd.cpp main.cpp interface.cpp box_mdat.cpp +SRC = box_avcC.cpp box.cpp box_dinf.cpp box_dref.cpp box_esds.cpp box_ftyp.cpp box_hdlr.cpp box_hmhd.cpp box_mdhd.cpp box_mdia.cpp box_minf.cpp box_moov.cpp box_mvhd.cpp box_nmhd.cpp box_smhd.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_tkhd.cpp box_trak.cpp box_url.cpp box_vmhd.cpp main.cpp interface.cpp box_mdat.cpp box_rtmp.cpp OBJ = $(SRC:.cpp=.o) OUT = Boxtest INCLUDES = diff --git a/MP4/box_amhp.cpp b/MP4/box_amhp.cpp new file mode 100644 index 00000000..a6329436 --- /dev/null +++ b/MP4/box_amhp.cpp @@ -0,0 +1,39 @@ +#include "box_amhp.h" + +Box_amhp::Box_amhp( ) { + Container = new Box( 0x616D6870 ); + SetReserved(); +} + +Box_amhp::~Box_amhp() { + delete Container; +} + +Box * Box_amhp::GetBox() { + return Container; +} + +void Box_amhp::SetReserved( ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0)); +} + +void Box_stts::AddEntry( uint32_t SampleCount, uint32_t SampleDelta, uint32_t Offset ) { + if(Offset >= Entries.size()) { + Entries.resize(Offset+1); + } + Entries[Offset].SampleCount = SampleCount; + Entries[Offset].SampleDelta = SampleDelta; +} + + +void Box_stts::WriteContent( ) { + Container->ResetPayload(); + SetReserved( ); + if(!Entries.empty()) { + for(int32_t i = Entries.size() -1; i >= 0; i--) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].SampleDelta),(i*8)+12); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].SampleCount),(i*8)+8); + } + } + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),4); +} diff --git a/MP4/box_amhp.h b/MP4/box_amhp.h new file mode 100644 index 00000000..fd5b3518 --- /dev/null +++ b/MP4/box_amhp.h @@ -0,0 +1,24 @@ +#include "box.h" +#include +#include + +struct amhp_record { + uint8_t HintTrackMode; + uint8_t Settings; + uint8_t TrailerDefaultSize; +};//stsc_record + +class Box_amhp { + public: + Box_amhp( ); + ~Box_amhp(); + Box * GetBox(); + void SetReserved( ); + void AddEntry( uint8_t NewHintTrackMode, uint8_t NewSettings, uint8_t NewTrailerDefaultSize, uint32_t Offset = 0 ); + void WriteContent( ); + private: + Box * Container; + + std::vector Entries; +};//Box_ftyp Class + diff --git a/MP4/box_includes.h b/MP4/box_includes.h index 6b28de8c..80cb9c7d 100644 --- a/MP4/box_includes.h +++ b/MP4/box_includes.h @@ -22,3 +22,4 @@ #include "box_url.h" #include "box_vmhd.h" #include "box_mdat.h" +#include "box_rtmp.h" diff --git a/MP4/box_rtmp.cpp b/MP4/box_rtmp.cpp new file mode 100644 index 00000000..9f6e442f --- /dev/null +++ b/MP4/box_rtmp.cpp @@ -0,0 +1,57 @@ +#include "box_rtmp.h" + +Box_rtmp::Box_rtmp( ) { + Container = new Box( 0x72746D70 ); + SetReserved(); + SetDefaults(); +} + +Box_rtmp::~Box_rtmp() { + delete Container; +} + +Box * Box_rtmp::GetBox() { + return Container; +} + +void Box_rtmp::SetReserved( ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0)); + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(0)); +} + +void Box_rtmp::SetDefaults( ) { + SetDataReferenceIndex( ); + SetHintTrackVersion( ); + SetHighestCompatibleVersion( ); + SetMaxPacketSize( ); +} + +void Box_rtmp::SetDataReferenceIndex( uint16_t NewIndex ) { + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewIndex),6); +} +void Box_rtmp::SetHintTrackVersion( uint16_t NewVersion ) { + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),8); +} +void Box_rtmp::SetHighestCompatibleVersion( uint16_t NewVersion ) { + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),10); +} + +void Box_rtmp::SetMaxPacketSize( uint16_t NewSize ) { + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewSize),12); +} + +void Box_rtmp::AddContent( Box * newcontent ) { + if(Content) { + delete Content; + Content = NULL; + } + Content = newcontent; +} + +void Box_rtmp::WriteContent( ) { + Container->ResetPayload( ); + SetDefaults( ); + std::string serializedbox = ""; + serializedbox.append((char*)Content->GetBoxedData(),Content->GetBoxedDataSize()); + Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),14); +} diff --git a/MP4/box_rtmp.h b/MP4/box_rtmp.h new file mode 100644 index 00000000..3a0df967 --- /dev/null +++ b/MP4/box_rtmp.h @@ -0,0 +1,22 @@ +#include "box.h" +#include + +class Box_rtmp { + public: + Box_rtmp( ); + ~Box_rtmp(); + Box * GetBox(); + void SetDataReferenceIndex( uint16_t NewIndex = 0 ); + void SetHintTrackVersion( uint16_t NewVersion = 1 ); + void SetHighestCompatibleVersion( uint16_t NewVersion = 1 ); + void SetMaxPacketSize( uint16_t NewSize = 0xFFFF ); + void AddContent( Box * newcontent ); + void WriteContent( ); + private: + void SetReserved( ); + void SetDefaults( ); + + Box * Container; + Box * Content; +};//Box_ftyp Class + diff --git a/MP4/interface.cpp b/MP4/interface.cpp index 1d8fdd58..1ea6e8f7 100644 --- a/MP4/interface.cpp +++ b/MP4/interface.cpp @@ -40,12 +40,14 @@ Interface::Interface() { stco_soun = new Box_stco(); stsd_soun = new Box_stsd(); esds_soun = new Box_esds(); + rtmp = new Box_rtmp(); //Set some values we already know won't change once the boxes have been created SetStaticDefaults(); } Interface::~Interface() { //Deleting the boxes if they still exist. + if( rtmp ) { delete rtmp; rtmp = NULL; } if( esds_soun ) { delete esds_soun; esds_soun = NULL; } if( stsd_soun ) { delete stsd_soun; stsd_soun = NULL; } if( stco_soun ) { delete stco_soun; stco_soun = NULL; } diff --git a/MP4/interface.h b/MP4/interface.h index 7cc28366..beb6c162 100644 --- a/MP4/interface.h +++ b/MP4/interface.h @@ -67,5 +67,6 @@ class Interface { Box_stco * stco_soun; Box_stsd * stsd_soun; Box_esds * esds_soun; + Box_rtmp * rtmp; };//Interface class