From 998184140619ed7b86dfb3278ccca5318ee6152f Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Sun, 6 Feb 2011 22:37:05 +0100 Subject: [PATCH] AFRA box created, RTMP box updated --- MP4/box_afra.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ MP4/box_afra.h | 24 ++++++++++++++++++++++++ MP4/box_rtmp.cpp | 12 ++++++++++-- MP4/box_rtmp.h | 4 ++++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 MP4/box_afra.cpp create mode 100644 MP4/box_afra.h diff --git a/MP4/box_afra.cpp b/MP4/box_afra.cpp new file mode 100644 index 00000000..97684abf --- /dev/null +++ b/MP4/box_afra.cpp @@ -0,0 +1,44 @@ +#include "box_afra.h" + +Box_afra::Box_afra( ) { + Container = new Box( 0x61667261 ); + SetReserved( ); + SetDefaults( ); +} + +Box_afra::~Box_afra() { + delete Container; +} + +Box * Box_afra::GetBox() { + return Container; +} + +void Box_afra::SetDefaults( ) { + SetTimeScale( ); +} + +void Box_afra::SetReserved( ) { + uint8_t * temp = new uint8_t[1]; + temp[0] = 0; + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),1); + Container->SetPayload((uint32_t)1,temp); +} + +void Box_afra::SetTimeScale( uint32_t Scale ) { + CurrentTimeScale = Scale; + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Scale),5); +} + +void Box_afra::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*12)+21); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries[i].SampleCount),(i*12)+17); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),(i*12)+13); + } + } + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),9); +} diff --git a/MP4/box_afra.h b/MP4/box_afra.h new file mode 100644 index 00000000..2115cb89 --- /dev/null +++ b/MP4/box_afra.h @@ -0,0 +1,24 @@ +#include "box.h" +#include + +struct afra_record { + uint32_t Time; + uint32_t Offset; +};//afra_record + +class Box_afra { + public: + Box_afra( ); + ~Box_afra(); + Box * GetBox(); + void SetTimeScale( uint32_t Scale = 1 ); + void AddEntry( uint32_t Time = 0, uint32_t SampleOffset = 0, uint32_t Offset = 0 ); + void WriteContent( ); + private: + void SetReserved( ); + void SetDefaults( ); + + Box * Container; + uint32_t CurrentTimeScale; + std::vector Entries; +};//Box_ftyp Class diff --git a/MP4/box_rtmp.cpp b/MP4/box_rtmp.cpp index 9f6e442f..9b628c07 100644 --- a/MP4/box_rtmp.cpp +++ b/MP4/box_rtmp.cpp @@ -15,7 +15,11 @@ Box * Box_rtmp::GetBox() { } void Box_rtmp::SetReserved( ) { - Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0)); + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(CurrentMaxPacketSize),12); + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(CurrentHighestCompatibleVersion),10); + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(CurrentHintTrackVersion),8); + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(CurrentReferenceIndex),6); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),2); Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(0)); } @@ -27,16 +31,20 @@ void Box_rtmp::SetDefaults( ) { } void Box_rtmp::SetDataReferenceIndex( uint16_t NewIndex ) { + CurrentReferenceIndex = NewIndex; Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewIndex),6); } void Box_rtmp::SetHintTrackVersion( uint16_t NewVersion ) { + CurrentHintTrackVersion = NewVersion; Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),8); } void Box_rtmp::SetHighestCompatibleVersion( uint16_t NewVersion ) { + CurrentHighestCompatibleVersion = NewVersion; Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),10); } void Box_rtmp::SetMaxPacketSize( uint16_t NewSize ) { + CurrentMaxPacketSize = NewSize; Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewSize),12); } @@ -50,7 +58,7 @@ void Box_rtmp::AddContent( Box * newcontent ) { void Box_rtmp::WriteContent( ) { Container->ResetPayload( ); - SetDefaults( ); + SetReserved( ); 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 index 3a0df967..4693b203 100644 --- a/MP4/box_rtmp.h +++ b/MP4/box_rtmp.h @@ -15,6 +15,10 @@ class Box_rtmp { private: void SetReserved( ); void SetDefaults( ); + uint16_t CurrentReferenceIndex; + uint16_t CurrentHintTrackVersion; + uint16_t CurrentHighestCompatibleVersion; + uint16_t CurrentMaxPacketSize; Box * Container; Box * Content;