Changes till now
This commit is contained in:
parent
fce97a478c
commit
c93a0bb815
8 changed files with 188 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
|||
SRC = main.cpp box.cpp box_ftyp.cpp
|
||||
SRC = main.cpp box.cpp box_h264.cpp box_stsd.cpp
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
OUT = Boxtest
|
||||
INCLUDES =
|
||||
|
|
20
MP4/box.cpp
20
MP4/box.cpp
|
@ -73,3 +73,23 @@ uint8_t * Box::uint32_to_uint8( uint32_t data ) {
|
|||
temp[3] = (data ) & 0x000000FF;
|
||||
return temp;
|
||||
}
|
||||
|
||||
uint8_t * Box::uint16_to_uint8( uint16_t data ) {
|
||||
uint8_t * temp = new uint8_t[2];
|
||||
temp[0] = (data >> 8) & 0x00FF;
|
||||
temp[1] = (data ) & 0x00FF;
|
||||
return temp;
|
||||
}
|
||||
|
||||
BoxHeader Box::GetHeader( ) {
|
||||
return header;
|
||||
}
|
||||
|
||||
void Box::ResetPayload( ) {
|
||||
header.TotalSize -= PayloadSize;
|
||||
PayloadSize = 0;
|
||||
if(Payload) {
|
||||
delete Payload;
|
||||
Payload = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#pragma once
|
||||
#include "boxheader.h"
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
class Box {
|
||||
public:
|
||||
|
@ -18,6 +20,9 @@ class Box {
|
|||
uint8_t * GetPayload(uint32_t Index, uint32_t & Size);
|
||||
|
||||
static uint8_t * uint32_to_uint8( uint32_t data );
|
||||
static uint8_t * uint16_to_uint8( uint16_t data );
|
||||
BoxHeader GetHeader( );
|
||||
void ResetPayload( );
|
||||
private:
|
||||
BoxHeader header;
|
||||
uint8_t * Payload;
|
||||
|
|
61
MP4/box_h264.cpp
Normal file
61
MP4/box_h264.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "box_h264.h"
|
||||
|
||||
Box_h264::Box_h264( ) {
|
||||
Container = new Box( 0x68323634 );
|
||||
SetReserved();
|
||||
SetDefaults();
|
||||
}
|
||||
|
||||
Box_h264::~Box_h264() {
|
||||
delete Container;
|
||||
}
|
||||
|
||||
Box * Box_h264::GetBox() {
|
||||
return Container;
|
||||
}
|
||||
|
||||
void Box_h264::SetDataReferenceIndex( uint16_t DataReferenceIndex ) {
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( DataReferenceIndex ),6);
|
||||
}
|
||||
|
||||
void Box_h264::SetDimensions ( uint16_t Width, uint16_t Height ) {
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Height ),26);
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Width ),24);
|
||||
}
|
||||
|
||||
void Box_h264::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);
|
||||
}
|
||||
|
||||
void Box_h264::SetFrameCount ( uint16_t FrameCount ) {
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( FrameCount ),40);
|
||||
}
|
||||
|
||||
void Box_h264::SetCompressorName ( std::string CompressorName ) {
|
||||
uint8_t * Printable = new uint8_t[1];
|
||||
Printable[0] = std::min( (unsigned int)31, CompressorName.size() );
|
||||
Container->SetPayload((uint32_t)Printable[0],(uint8_t*)CompressorName.c_str(),43);
|
||||
Container->SetPayload((uint32_t)1, Printable ,42);
|
||||
}
|
||||
|
||||
void Box_h264::SetDepth ( uint16_t Depth ) {
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( Depth ),74);
|
||||
}
|
||||
|
||||
void Box_h264::SetReserved( ) {
|
||||
Container->SetPayload((uint32_t)2,Box::uint16_to_uint8( (uint16_t)-1 ),76);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),36);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),20);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),16);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),12);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0),8);
|
||||
Container->SetPayload((uint32_t)4,Box::uint16_to_uint8(0),4);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(0));
|
||||
}
|
||||
|
||||
void Box_h264::SetDefaults( ) {
|
||||
SetResolution ( );
|
||||
SetFrameCount ( );
|
||||
SetDepth ( );
|
||||
}
|
20
MP4/box_h264.h
Normal file
20
MP4/box_h264.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "box.h"
|
||||
#include <string>
|
||||
|
||||
class Box_h264 {
|
||||
public:
|
||||
Box_h264( );
|
||||
~Box_h264();
|
||||
Box * GetBox();
|
||||
void SetReserved( );
|
||||
void SetDataReferenceIndex( uint16_t DataReferenceIndex );
|
||||
void SetDimensions ( uint16_t Width, uint16_t Height );
|
||||
void SetResolution ( uint32_t Horizontal = 0x00480000, uint32_t Vertical = 0x00480000 );
|
||||
void SetFrameCount ( uint16_t FrameCount = 1 );
|
||||
void SetCompressorName ( std::string CompressorName );
|
||||
void SetDepth ( uint16_t Depth = 0x0018 );
|
||||
void SetDefaults( );
|
||||
private:
|
||||
Box * Container;
|
||||
};//Box_ftyp Class
|
||||
|
48
MP4/box_stsd.cpp
Normal file
48
MP4/box_stsd.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "box_stsd.h"
|
||||
|
||||
Box_stsd::Box_stsd( ) {
|
||||
Container = new Box( 0x73747364 );
|
||||
SetDefaults();
|
||||
}
|
||||
|
||||
Box_stsd::~Box_stsd() {
|
||||
delete Container;
|
||||
}
|
||||
|
||||
Box * Box_stsd::GetBox() {
|
||||
return Container;
|
||||
}
|
||||
|
||||
void Box_stsd::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_stsd::SetDefaults( ) {
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( 1 ),4);
|
||||
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8( 0 ),0);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
Container->SetPayload((uint32_t)serializedbox.size(),(uint8_t*)serializedbox.c_str(),8);
|
||||
}
|
18
MP4/box_stsd.h
Normal file
18
MP4/box_stsd.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "box.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class Box_stsd {
|
||||
public:
|
||||
Box_stsd( );
|
||||
~Box_stsd();
|
||||
Box * GetBox();
|
||||
void AddContent( Box * newcontent, uint32_t offset = 0 );
|
||||
private:
|
||||
Box * Container;
|
||||
|
||||
void SetDefaults();
|
||||
void WriteContent();
|
||||
std::vector<Box *> Content;
|
||||
};//Box_ftyp Class
|
||||
|
24
MP4/main.cpp
24
MP4/main.cpp
|
@ -1,15 +1,19 @@
|
|||
#include <iostream>
|
||||
#include "box_ftyp.h"
|
||||
#include "box_h264.h"
|
||||
#include "box_stsd.h"
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
Box_ftyp * FileType = new Box_ftyp();
|
||||
printf("Boxtype: %x\n", FileType->GetBox()->GetBoxType());
|
||||
uint8_t * TestPayload = FileType->GetBox()->GetPayload();
|
||||
uint32_t TestPayloadSize = FileType->GetBox()->GetPayloadSize();
|
||||
printf("PayloadSize: %d\n", TestPayloadSize);
|
||||
for(uint32_t i = 0; i < TestPayloadSize; i++) {
|
||||
printf("Payload[%d]: %x\n", i, TestPayload[i]);
|
||||
}
|
||||
delete FileType;
|
||||
Box_h264 * Testing = new Box_h264();
|
||||
Testing->SetCompressorName( "Test123" );
|
||||
std::cout << "H264::Size: " << Testing->GetBox()->GetHeader().TotalSize << "\n";
|
||||
Box_stsd * Testsample = new Box_stsd();
|
||||
std::cout << "STSD::Before Content: " << Testsample->GetBox()->GetHeader().TotalSize << "\n";
|
||||
Testsample->AddContent( Testing->GetBox() );
|
||||
std::cout << "STSD::After 1 Content: " << Testsample->GetBox()->GetHeader().TotalSize << "\n";
|
||||
Testsample->AddContent( Testing->GetBox(), 1 );
|
||||
std::cout << "STSD::After 2 Content: " << Testsample->GetBox()->GetHeader().TotalSize << "\n";
|
||||
delete Testsample;
|
||||
delete Testing;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue