From ff93aedb985d0ec3d7965a016c9133d35dea0c30 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Tue, 8 Feb 2011 18:00:46 +0100 Subject: [PATCH] TRUN box finished --- MP4/box_tfhd.cpp | 4 ++-- MP4/box_trun.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ MP4/box_trun.h | 25 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 MP4/box_trun.cpp create mode 100644 MP4/box_trun.h diff --git a/MP4/box_tfhd.cpp b/MP4/box_tfhd.cpp index e8511291..76abb04f 100644 --- a/MP4/box_tfhd.cpp +++ b/MP4/box_tfhd.cpp @@ -40,8 +40,8 @@ void Box_tfhd::WriteContent( ) { Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curTrackId),4); curoffset = 8; if( curBaseDataOffset ) { - Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curTrackId),curoffset); - Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curTrackId),curoffset+4); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),curoffset); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curBaseDataOffset),curoffset+4); curoffset += 8; } if( curSampleDescriptionIndex ) { diff --git a/MP4/box_trun.cpp b/MP4/box_trun.cpp new file mode 100644 index 00000000..489d7cc3 --- /dev/null +++ b/MP4/box_trun.cpp @@ -0,0 +1,45 @@ +#include "box_trun.h" + +Box_trun::Box_trun( ) { + Container = new Box( 0x74666864 ); + SetDefaults( ); +} + +Box_trun::~Box_trun() { + delete Container; +} + +Box * Box_trun::GetBox() { + return Container; +} + +void Box_trun::SetDataOffset( uint32_t Offset ) { + curDataOffset = Offset; +} + +void Box_trun::WriteContent( ) { + uint32_t curoffset; + uint32_t flags = 0 & ( curDataOffset ? 0x1 : 0 ) & ( setSampleDuration ? 0x100 : 0 ) & ( setSampleSize ? 0x200 : 0 ); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(flags)); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SampleInfo.size()),4); + curoffset = 8; + if( curDataOffset ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(curDataOffset),curoffset); + curoffset += 4; + } + for( uint32_t i = 0; i < SampleInfo.size(); i++ ) { + if( setSampleDuration ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SampleInfo[i].SampleDuration),curoffset); + curoffset += 4; + } + if( setSampleSize ) { + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(SampleInfo[i].SampleSize),curoffset); + curoffset += 4; + } + } +} + +void Box_trun::SetDefaults( ) { + setSampleDuration = false; + setSampleSize = false; +} diff --git a/MP4/box_trun.h b/MP4/box_trun.h new file mode 100644 index 00000000..0424e034 --- /dev/null +++ b/MP4/box_trun.h @@ -0,0 +1,25 @@ +#include "box.h" +#include + +struct trun_sampleinformationstructure { + uint32_t SampleDuration; + uint32_t SampleSize; +} + +class Box_tfhd { + public: + Box_tfhd( ); + ~Box_tfhd(); + Box * GetBox(); + void SetDataOffset( uint32_t Offset = 0 ); + void AddSampleInformation( uint32_t SampleDuration = 0, uint32_t SampleSize = 0, uint32_t Offset = 0 ); + void WriteContent( ); + private: + void SetDefaults( ); + bool setSampleDuration; + bool setSampleSize; + uint32_t curDataOffset; + std::vector SampleInfo; + Box * Container; +};//Box_ftyp Class +