diff --git a/MP4/box_stsc.cpp b/MP4/box_stsc.cpp new file mode 100644 index 00000000..f6abf930 --- /dev/null +++ b/MP4/box_stsc.cpp @@ -0,0 +1,42 @@ +#include "box_stsc.h" + +Box_stsc::Box_stsc( ) { + Container = new Box( 0x73747363 ); + SetReserved(); +} + +Box_stsc::~Box_stsc() { + delete Container; +} + +Box * Box_stsc::GetBox() { + return Container; +} + +void Box_stsc::SetReserved( ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0)); +} + +void Box_stsc::AddEntry( uint32_t FirstChunk, uint32_t SamplesPerChunk, uint32_t SampleDescIndex, uint32_t Offset = 0 ) { + if(Offset >= Entries.size()) { + Entries.resize(Offset+1); + } + Entries[Offset].FirstChunk = FirstChunk; + Entries[Offset].SamplesPerChunk = SamplesPerChunk; + Entries[Offset].SampleDescIndex = SampleDescIndex; + WriteEntries( ); +} + + +void Box_stsc::WriteEntries( ) { + Container->ResetPayload(); + SetReserved( ); + if(!Offsets.empty()) { + for(int32_t i = Offsets.size() -1; i >= 0; i--) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].SampleDescIndex),(i*12)+16); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].SamplesPerChunk),(i*12)+12); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].FirstChunk),(i*12)+8); + } + } + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Offsets.size()),4); +} diff --git a/MP4/box_stsc.h b/MP4/box_stsc.h new file mode 100644 index 00000000..53e7ba9e --- /dev/null +++ b/MP4/box_stsc.h @@ -0,0 +1,24 @@ +#include "box.h" +#include +#include + +struct stsc_record { + uint32_t FirstChunk; + uint32_t SamplesPerChunk; + uint32_t SampleDescIndex; +};//stsc_record + +class Box_stsc { + public: + Box_stsc( ); + ~Box_stsc(); + Box * GetBox(); + void SetReserved( ); + void AddEntry( uint32_t FirstChunk, uint32_t SamplesPerChunk, uint32_t SampleDescIndex, uint32_t Offset = 0 ); + private: + Box * Container; + + void WriteEntries( ); + std::vector Entries; +};//Box_ftyp Class + diff --git a/MP4/box_stts.cpp b/MP4/box_stts.cpp new file mode 100644 index 00000000..da9269c4 --- /dev/null +++ b/MP4/box_stts.cpp @@ -0,0 +1,40 @@ +#include "box_stts.h" + +Box_stts::Box_stts( ) { + Container = new Box( 0x73747473 ); + SetReserved(); +} + +Box_stts::~Box_stsc() { + delete Container; +} + +Box * Box_stts::GetBox() { + return Container; +} + +void Box_stts::SetReserved( ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0)); +} + +void Box_stts::AddEntry( uint32_t SampleCount, uint32_t SamplesDelta, uint32_t Offset = 0 ) { + if(Offset >= Entries.size()) { + Entries.resize(Offset+1); + } + Entries[Offset].SampleCount = SampleCount; + Entries[Offset].SampleDelta = SampleDelta; + WriteEntries( ); +} + + +void Box_stts::WriteEntries( ) { + Container->ResetPayload(); + SetReserved( ); + if(!Offsets.empty()) { + for(int32_t i = Offsets.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(Offsets.size()),4); +} diff --git a/MP4/box_stts.h b/MP4/box_stts.h new file mode 100644 index 00000000..c368a78e --- /dev/null +++ b/MP4/box_stts.h @@ -0,0 +1,23 @@ +#include "box.h" +#include +#include + +struct stts_record { + uint32_t SampleCount; + uint32_t SampleDelta; +};//stsc_record + +class Box_stts { + public: + Box_stsc( ); + ~Box_stsc(); + Box * GetBox(); + void SetReserved( ); + void AddEntry( uint32_t SampleCount, uint32_t SampleDelta, uint32_t Offset = 0 ); + private: + Box * Container; + + void WriteEntries( ); + std::vector Entries; +};//Box_ftyp Class +