Boxed updates

This commit is contained in:
Erik Zandvliet 2011-01-12 13:40:08 +01:00
parent 0fcc1c483d
commit 4738624b3e
17 changed files with 269 additions and 17 deletions

View file

@ -1,4 +1,4 @@
SRC = main.cpp box.cpp box_h264.cpp box_stsd.cpp
SRC = box.cpp box_ftyp.cpp box_h264.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_url.cpp box_dref.cpp box_dinf.cpp box_minf.cpp main.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Boxtest
INCLUDES =

View file

@ -65,6 +65,19 @@ uint8_t * Box::GetPayload(uint32_t Index, uint32_t & Size) {
return temp;
}
uint32_t Box::GetBoxedDataSize() {
return header.TotalSize;
}
uint8_t * Box::GetBoxedData( ) {
uint8_t * temp = new uint8_t[header.TotalSize];
memcpy( temp, uint32_to_uint8(header.TotalSize), 4 );
memcpy( &temp[4], uint32_to_uint8(header.BoxType), 4 );
memcpy( &temp[8], Payload, PayloadSize );
return temp;
}
uint8_t * Box::uint32_to_uint8( uint32_t data ) {
uint8_t * temp = new uint8_t[4];
temp[0] = (data >> 24) & 0x000000FF;

View file

@ -19,6 +19,9 @@ class Box {
uint8_t * GetPayload();
uint8_t * GetPayload(uint32_t Index, uint32_t & Size);
uint32_t GetBoxedDataSize();
uint8_t * GetBoxedData( );
static uint8_t * uint32_to_uint8( uint32_t data );
static uint8_t * uint16_to_uint8( uint16_t data );
BoxHeader GetHeader( );

29
MP4/box_dinf.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "box_dinf.h"
Box_dinf::Box_dinf( ) {
Container = new Box( 0x64696E66 );
}
Box_dinf::~Box_dinf() {
delete Container;
}
Box * Box_dinf::GetBox() {
return Container;
}
void Box_dinf::AddContent( Box * newcontent, uint32_t offset ) {
if(Content) {
delete Content;
Content = NULL;
}
Content = newcontent;
WriteContent();
}
void Box_dinf::WriteContent( ) {
Container->ResetPayload( );
std::string serializedbox = "";
serializedbox.append((char*)Content->GetBoxedData(),Content->GetBoxedDataSize());
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_dinf.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_dinf {
public:
Box_dinf();
~Box_dinf();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
Box * Content;
};//Box_ftyp Class

43
MP4/box_dref.cpp Normal file
View file

@ -0,0 +1,43 @@
#include "box_dref.h"
Box_dref::Box_dref( ) {
Container = new Box( 0x64726566 );
SetReserved( );
}
Box_dref::~Box_dref() {
delete Container;
}
Box * Box_dref::GetBox() {
return Container;
}
void Box_dref::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_dref::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),4);
SetReserved( );
}
void Box_dref::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}

18
MP4/box_dref.h Normal file
View file

@ -0,0 +1,18 @@
#include "box.h"
#include <vector>
#include <string>
class Box_dref {
public:
Box_dref();
~Box_dref();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void SetReserved( );
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class

37
MP4/box_minf.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "box_minf.h"
Box_minf::Box_minf( ) {
Container = new Box( 0x7374626C );
}
Box_minf::~Box_minf() {
delete Container;
}
Box * Box_minf::GetBox() {
return Container;
}
void Box_minf::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_minf::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_minf.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_minf {
public:
Box_minf();
~Box_minf();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class

37
MP4/box_stbl.cpp Normal file
View file

@ -0,0 +1,37 @@
#include "box_stbl.h"
Box_stbl::Box_stbl( ) {
Container = new Box( 0x7374626C );
}
Box_stbl::~Box_stbl() {
delete Container;
}
Box * Box_stbl::GetBox() {
return Container;
}
void Box_stbl::AddContent( Box * newcontent, uint32_t offset ) {
if( offset >= Content.size() ) {
Content.resize(offset+1);
}
if( Content[offset] ) {
delete Content[offset];
}
Content[offset] = newcontent;
WriteContent();
}
void Box_stbl::WriteContent( ) {
Container->ResetPayload( );
Box * current;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str());
}

17
MP4/box_stbl.h Normal file
View file

@ -0,0 +1,17 @@
#include "box.h"
#include <vector>
#include <string>
class Box_stbl {
public:
Box_stbl();
~Box_stbl();
Box * GetBox();
void AddContent( Box * newcontent, uint32_t offset = 0 );
private:
Box * Container;
void WriteContent( );
std::vector<Box *> Content;
};//Box_ftyp Class

View file

@ -17,7 +17,7 @@ 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 ) {
void Box_stsc::AddEntry( uint32_t FirstChunk, uint32_t SamplesPerChunk, uint32_t SampleDescIndex, uint32_t Offset ) {
if(Offset >= Entries.size()) {
Entries.resize(Offset+1);
}
@ -31,12 +31,12 @@ void Box_stsc::AddEntry( uint32_t FirstChunk, uint32_t SamplesPerChunk, uint32_t
void Box_stsc::WriteEntries( ) {
Container->ResetPayload();
SetReserved( );
if(!Offsets.empty()) {
for(int32_t i = Offsets.size() -1; i >= 0; i--) {
if(!Entries.empty()) {
for(int32_t i = Entries.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);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),4);
}

View file

@ -33,15 +33,11 @@ void Box_stsd::WriteContent( ) {
Container->ResetPayload( );
SetDefaults( );
Box * current;
BoxHeader currentheader;
std::string serializedbox = "";
for( uint32_t i = 0; i < Content.size(); i++ ) {
current=Content[i];
if( current ) {
currentheader = current->GetHeader();
serializedbox.append((char*)Box::uint32_to_uint8(currentheader.TotalSize),4);
serializedbox.append((char*)Box::uint32_to_uint8(currentheader.BoxType),4);
serializedbox.append((char*)current->GetPayload(),current->GetPayloadSize());
serializedbox.append((char*)current->GetBoxedData(),current->GetBoxedDataSize());
}
}
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),8);

View file

@ -5,7 +5,7 @@ Box_stts::Box_stts( ) {
SetReserved();
}
Box_stts::~Box_stsc() {
Box_stts::~Box_stts() {
delete Container;
}
@ -17,7 +17,7 @@ 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 ) {
void Box_stts::AddEntry( uint32_t SampleCount, uint32_t SampleDelta, uint32_t Offset ) {
if(Offset >= Entries.size()) {
Entries.resize(Offset+1);
}
@ -30,11 +30,11 @@ void Box_stts::AddEntry( uint32_t SampleCount, uint32_t SamplesDelta, uint32_t O
void Box_stts::WriteEntries( ) {
Container->ResetPayload();
SetReserved( );
if(!Offsets.empty()) {
for(int32_t i = Offsets.size() -1; i >= 0; i--) {
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(Offsets.size()),4);
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(Entries.size()),4);
}

View file

@ -9,8 +9,8 @@ struct stts_record {
class Box_stts {
public:
Box_stsc( );
~Box_stsc();
Box_stts( );
~Box_stts();
Box * GetBox();
void SetReserved( );
void AddEntry( uint32_t SampleCount, uint32_t SampleDelta, uint32_t Offset = 0 );

14
MP4/box_url.cpp Normal file
View file

@ -0,0 +1,14 @@
#include "box_url.h"
Box_url::Box_url( ) {
Container = new Box( 0x75726C20 );
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(1));
}
Box_url::~Box_url() {
delete Container;
}
Box * Box_url::GetBox() {
return Container;
}

11
MP4/box_url.h Normal file
View file

@ -0,0 +1,11 @@
#include "box.h"
class Box_url {
public:
Box_url( );
~Box_url();
Box * GetBox();
private:
Box * Container;
};//Box_ftyp Class