diff --git a/MP4/box_avcC.cpp b/MP4/box_avcC.cpp index 0bcb15eb..354312c7 100644 --- a/MP4/box_avcC.cpp +++ b/MP4/box_avcC.cpp @@ -18,11 +18,14 @@ void Box_avcC::SetDataReferenceIndex( uint16_t DataReferenceIndex ) { Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( DataReferenceIndex ),6); } -void Box_avcC::SetDimensions ( uint16_t Width, uint16_t Height ) { - Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Height ),26); +void Box_avcC::SetWidth( uint16_t Width ) { Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Width ),24); } +void Box_avcC::SetHeight( uint16_t Height ) { + Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Height ),26); +} + void Box_avcC::SetResolution ( uint32_t Horizontal, uint32_t Vertical ) { Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( Vertical ),32); Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( Horizontal ),28); @@ -55,6 +58,7 @@ void Box_avcC::SetReserved( ) { } void Box_avcC::SetDefaults( ) { + SetDimensions( ); SetDepth ( ); SetFrameCount ( ); SetResolution ( ); diff --git a/MP4/box_avcC.h b/MP4/box_avcC.h index 51d7dbd7..ba465832 100644 --- a/MP4/box_avcC.h +++ b/MP4/box_avcC.h @@ -7,7 +7,8 @@ class Box_avcC { ~Box_avcC(); Box * GetBox(); void SetDataReferenceIndex( uint16_t DataReferenceIndex = 0 ); - void SetDimensions ( uint16_t Width = 0, uint16_t Height = 0); + void SetWidth( uint16_t Width = 0 ); + void SetHeight( uint16_t Height = 0 ); void SetResolution ( uint32_t Horizontal = 0x00480000, uint32_t Vertical = 0x00480000 ); void SetFrameCount ( uint16_t FrameCount = 1 ); void SetCompressorName ( std::string CompressorName = ""); diff --git a/MP4/box_mvhd.h b/MP4/box_mvhd.h index 28caa169..b84a446d 100644 --- a/MP4/box_mvhd.h +++ b/MP4/box_mvhd.h @@ -14,7 +14,7 @@ class Box_mvhd { void SetDurationTime( uint32_t TimeUnits = 0 ); void SetRate( uint32_t Rate = 0x00010000 ); void SetVolume( uint16_t Volume = 0x0100 ); - void SetNextTrackID( uint32_t TrackID = 0 ); + void SetNextTrackID( uint32_t TrackID = 0xFFFFFFFF ); private: void SetReserved(); void SetDefaults(); diff --git a/MP4/box_tkhd.cpp b/MP4/box_tkhd.cpp index b274f832..06900356 100644 --- a/MP4/box_tkhd.cpp +++ b/MP4/box_tkhd.cpp @@ -70,12 +70,14 @@ void Box_tkhd::SetTrackID( uint32_t TrackID ) { Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(TrackID),12); } -void Box_tkhd::SetWidth( uint32_t Width ) { - Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Width),72); +void Box_tkhd::SetWidth( uint16_t Width ) { + uint32_t ResultWidth = ( Width << 16 ); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(ResultWidth),72); } -void Box_tkhd::SetHeight( uint32_t Height ) { - Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Height),76); +void Box_tkhd::SetHeight( uint16_t Height ) { + uint32_t ResultHeight = ( Height << 16 ); + Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(ResultHeight),76); } void Box_tkhd::SetDefaults() { diff --git a/MP4/box_tkhd.h b/MP4/box_tkhd.h index e326ba16..3a9e2bc4 100644 --- a/MP4/box_tkhd.h +++ b/MP4/box_tkhd.h @@ -11,8 +11,8 @@ class Box_tkhd { void SetCreationTime( uint32_t TimeStamp = 0 ); void SetModificationTime( uint32_t TimeStamp = 0 ); void SetDurationTime( uint32_t TimeUnits = 0 ); - void SetWidth( uint32_t Width = 0 ); - void SetHeight( uint32_t Height = 0 ); + void SetWidth( uint16_t Width = 0 ); + void SetHeight( uint16_t Height = 0 ); void SetFlags( bool Bit0 = true, bool Bit1 = true, bool Bit2 = true ); void SetVersion( uint32_t Version = 0 ); void SetTrackID( uint32_t TrackID = 0 ); diff --git a/MP4/interface.cpp b/MP4/interface.cpp index 884ca01a..b67618b5 100644 --- a/MP4/interface.cpp +++ b/MP4/interface.cpp @@ -1,6 +1,10 @@ #include "interface.h" Interface::Interface() { + //Initializing local data + Width = 0; + Height = 0; + //Creating the boxes ftyp = new Box_ftyp(); moov = new Box_moov(); mvhd = new Box_mvhd(); @@ -36,9 +40,12 @@ Interface::Interface() { stco_soun = new Box_stco(); stsd_soun = new Box_stsd(); esds_soun = new Box_esds(); + //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( 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; } @@ -126,8 +133,9 @@ uint8_t * Interface::GetContents( ) { return Result; } - void Interface::UpdateContents( ) { + if( !Width ) { std::cerr << "WARNING: Width not set!\n"; } + if( !Height ) { std::cerr << "WARNING: Height not set!\n"; } stsd_vide->WriteContent( ); stco_vide->WriteContent( ); stsc_vide->WriteContent( ); @@ -152,3 +160,30 @@ void Interface::UpdateContents( ) { moov->WriteContent( ); } + +bool Interface::AllBoxesExist() { + return ( ftyp && moov && mvhd && trak_vide && tkhd_vide && mdia_vide && mdhd_vide && hdlr_vide && + minf_vide && vmhd_vide && dinf_vide && dref_vide && url_vide && stbl_vide && stts_vide && stsc_vide && + stco_vide && stsd_vide && avcC_vide && trak_soun && tkhd_soun && mdia_soun && mdhd_soun && hdlr_soun && + minf_soun && smhd_soun && dinf_soun && dref_soun && url_soun && stbl_soun && stts_soun && stsc_soun && + stco_soun && stsd_soun && esds_soun ); +} + +void Interface::SetWidth( uint16_t NewWidth ) { + Width = NewWidth; + avcC_vide->SetWidth( Width ); + tkhd_vide->SetWidth( Width ); +} + +void Interface::SetHeight( uint16_t NewHeight ) { + Height = NewHeight; + avcC_vide->SetHeight( Height ); + tkhd_vide->SetHeight( Height ); +} + +void Interface::SetStaticDefaults() { +// 'vide' = 0x76696465 + hdlr_vide->SetHandlerType( 0x76696465 ); +// 'soun' = 0x736F756E + hdlr_soun->SetHandlerType( 0x736F756E ); +} diff --git a/MP4/interface.h b/MP4/interface.h index 0125ddf4..70f6b068 100644 --- a/MP4/interface.h +++ b/MP4/interface.h @@ -7,8 +7,15 @@ class Interface { void link(); uint32_t GetContentSize(); uint8_t * GetContents(); + + void SetWidth( uint16_t NewWidth ); + void SetHeight( uint16_t NewHeight ); private: + void SetStaticDefaults(); void UpdateContents(); + bool AllBoxesExist(); + uint16_t Width; + uint16_t Height; Box_ftyp * ftyp; Box_moov * moov; Box_mvhd * mvhd;