RTMP box en AMHP box deels

This commit is contained in:
Erik Zandvliet 2011-02-03 15:01:40 +01:00
parent 88d0f63379
commit d62de77182
8 changed files with 147 additions and 1 deletions

View file

@ -1,4 +1,4 @@
SRC = box_avcC.cpp box.cpp box_dinf.cpp box_dref.cpp box_esds.cpp box_ftyp.cpp box_hdlr.cpp box_hmhd.cpp box_mdhd.cpp box_mdia.cpp box_minf.cpp box_moov.cpp box_mvhd.cpp box_nmhd.cpp box_smhd.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_tkhd.cpp box_trak.cpp box_url.cpp box_vmhd.cpp main.cpp interface.cpp box_mdat.cpp
SRC = box_avcC.cpp box.cpp box_dinf.cpp box_dref.cpp box_esds.cpp box_ftyp.cpp box_hdlr.cpp box_hmhd.cpp box_mdhd.cpp box_mdia.cpp box_minf.cpp box_moov.cpp box_mvhd.cpp box_nmhd.cpp box_smhd.cpp box_stbl.cpp box_stco.cpp box_stsc.cpp box_stsd.cpp box_stts.cpp box_tkhd.cpp box_trak.cpp box_url.cpp box_vmhd.cpp main.cpp interface.cpp box_mdat.cpp box_rtmp.cpp
OBJ = $(SRC:.cpp=.o)
OUT = Boxtest
INCLUDES =

39
MP4/box_amhp.cpp Normal file
View file

@ -0,0 +1,39 @@
#include "box_amhp.h"
Box_amhp::Box_amhp( ) {
Container = new Box( 0x616D6870 );
SetReserved();
}
Box_amhp::~Box_amhp() {
delete Container;
}
Box * Box_amhp::GetBox() {
return Container;
}
void Box_amhp::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
}
void Box_stts::AddEntry( uint32_t SampleCount, uint32_t SampleDelta, uint32_t Offset ) {
if(Offset >= Entries.size()) {
Entries.resize(Offset+1);
}
Entries[Offset].SampleCount = SampleCount;
Entries[Offset].SampleDelta = SampleDelta;
}
void Box_stts::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*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(Entries.size()),4);
}

24
MP4/box_amhp.h Normal file
View file

@ -0,0 +1,24 @@
#include "box.h"
#include <string>
#include <vector>
struct amhp_record {
uint8_t HintTrackMode;
uint8_t Settings;
uint8_t TrailerDefaultSize;
};//stsc_record
class Box_amhp {
public:
Box_amhp( );
~Box_amhp();
Box * GetBox();
void SetReserved( );
void AddEntry( uint8_t NewHintTrackMode, uint8_t NewSettings, uint8_t NewTrailerDefaultSize, uint32_t Offset = 0 );
void WriteContent( );
private:
Box * Container;
std::vector<amhp_record> Entries;
};//Box_ftyp Class

View file

@ -22,3 +22,4 @@
#include "box_url.h"
#include "box_vmhd.h"
#include "box_mdat.h"
#include "box_rtmp.h"

57
MP4/box_rtmp.cpp Normal file
View file

@ -0,0 +1,57 @@
#include "box_rtmp.h"
Box_rtmp::Box_rtmp( ) {
Container = new Box( 0x72746D70 );
SetReserved();
SetDefaults();
}
Box_rtmp::~Box_rtmp() {
delete Container;
}
Box * Box_rtmp::GetBox() {
return Container;
}
void Box_rtmp::SetReserved( ) {
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(0));
}
void Box_rtmp::SetDefaults( ) {
SetDataReferenceIndex( );
SetHintTrackVersion( );
SetHighestCompatibleVersion( );
SetMaxPacketSize( );
}
void Box_rtmp::SetDataReferenceIndex( uint16_t NewIndex ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewIndex),6);
}
void Box_rtmp::SetHintTrackVersion( uint16_t NewVersion ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),8);
}
void Box_rtmp::SetHighestCompatibleVersion( uint16_t NewVersion ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewVersion),10);
}
void Box_rtmp::SetMaxPacketSize( uint16_t NewSize ) {
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8(NewSize),12);
}
void Box_rtmp::AddContent( Box * newcontent ) {
if(Content) {
delete Content;
Content = NULL;
}
Content = newcontent;
}
void Box_rtmp::WriteContent( ) {
Container->ResetPayload( );
SetDefaults( );
std::string serializedbox = "";
serializedbox.append((char*)Content->GetBoxedData(),Content->GetBoxedDataSize());
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),14);
}

22
MP4/box_rtmp.h Normal file
View file

@ -0,0 +1,22 @@
#include "box.h"
#include <string>
class Box_rtmp {
public:
Box_rtmp( );
~Box_rtmp();
Box * GetBox();
void SetDataReferenceIndex( uint16_t NewIndex = 0 );
void SetHintTrackVersion( uint16_t NewVersion = 1 );
void SetHighestCompatibleVersion( uint16_t NewVersion = 1 );
void SetMaxPacketSize( uint16_t NewSize = 0xFFFF );
void AddContent( Box * newcontent );
void WriteContent( );
private:
void SetReserved( );
void SetDefaults( );
Box * Container;
Box * Content;
};//Box_ftyp Class

View file

@ -40,12 +40,14 @@ Interface::Interface() {
stco_soun = new Box_stco();
stsd_soun = new Box_stsd();
esds_soun = new Box_esds();
rtmp = new Box_rtmp();
//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( rtmp ) { delete rtmp; rtmp = NULL; }
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; }

View file

@ -67,5 +67,6 @@ class Interface {
Box_stco * stco_soun;
Box_stsd * stsd_soun;
Box_esds * esds_soun;
Box_rtmp * rtmp;
};//Interface class