First ftyp Box Implementation
This commit is contained in:
parent
e6b0cbe634
commit
fce97a478c
7 changed files with 157 additions and 41 deletions
18
MP4/Makefile
Normal file
18
MP4/Makefile
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
SRC = main.cpp box.cpp box_ftyp.cpp
|
||||||
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
OUT = Boxtest
|
||||||
|
INCLUDES =
|
||||||
|
CCFLAGS = -Wall -Wextra -funsigned-char -g
|
||||||
|
CC = $(CROSS)g++
|
||||||
|
LD = $(CROSS)ld
|
||||||
|
AR = $(CROSS)ar
|
||||||
|
LIBS =
|
||||||
|
.SUFFIXES: .cpp
|
||||||
|
.PHONY: clean default
|
||||||
|
default: $(OUT)
|
||||||
|
.cpp.o:
|
||||||
|
$(CC) $(INCLUDES) $(CCFLAGS) $(LIBS) -c $< -o $@
|
||||||
|
$(OUT): $(OBJ)
|
||||||
|
$(CC) $(LIBS) -o $(OUT) $(OBJ)
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJ) $(OUT) Makefile.bak *~
|
75
MP4/box.cpp
Normal file
75
MP4/box.cpp
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
#include "box.h"
|
||||||
|
|
||||||
|
Box::Box() {
|
||||||
|
Payload = NULL;
|
||||||
|
PayloadSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box::Box(uint32_t BoxType) {
|
||||||
|
header.BoxType = BoxType;
|
||||||
|
Payload = NULL;
|
||||||
|
PayloadSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box::~Box() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Box::SetBoxType(uint32_t BoxType) {
|
||||||
|
header.BoxType = BoxType;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Box::GetBoxType() {
|
||||||
|
return header.BoxType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Box::SetPayload(uint32_t Size, uint8_t * Data, uint32_t Index) {
|
||||||
|
uint8_t * tempchar = NULL;
|
||||||
|
if ( Index + Size > PayloadSize ) {
|
||||||
|
if ( Payload ) {
|
||||||
|
tempchar = new uint8_t[PayloadSize];
|
||||||
|
memcpy( tempchar, Payload, PayloadSize );
|
||||||
|
delete Payload;
|
||||||
|
}
|
||||||
|
PayloadSize = Index + Size;
|
||||||
|
Payload = new uint8_t[PayloadSize];
|
||||||
|
if( tempchar ) {
|
||||||
|
memcpy( Payload, tempchar, Index );
|
||||||
|
} else {
|
||||||
|
for(uint32_t i = 0; i < Index; i++) { Payload[i] = 0; }
|
||||||
|
}
|
||||||
|
memcpy( &Payload[Index], Data, Size );
|
||||||
|
header.TotalSize = PayloadSize + 8;
|
||||||
|
if( tempchar ) {
|
||||||
|
delete tempchar;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
memcpy( &Payload[Index], Data, Size );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Box::GetPayloadSize() {
|
||||||
|
return PayloadSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t * Box::GetPayload() {
|
||||||
|
uint8_t * temp = new uint8_t[PayloadSize];
|
||||||
|
memcpy( temp, Payload, PayloadSize );
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t * Box::GetPayload(uint32_t Index, uint32_t & Size) {
|
||||||
|
if(Index > PayloadSize) { return NULL; }
|
||||||
|
if(Index + Size > PayloadSize) { Size = PayloadSize - Index; }
|
||||||
|
uint8_t * temp = new uint8_t[Size - Index];
|
||||||
|
memcpy( temp, &Payload[Index], Size - Index );
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t * Box::uint32_to_uint8( uint32_t data ) {
|
||||||
|
uint8_t * temp = new uint8_t[4];
|
||||||
|
temp[0] = (data >> 24) & 0x000000FF;
|
||||||
|
temp[1] = (data >> 16 ) & 0x000000FF;
|
||||||
|
temp[2] = (data >> 8 ) & 0x000000FF;
|
||||||
|
temp[3] = (data ) & 0x000000FF;
|
||||||
|
return temp;
|
||||||
|
}
|
51
MP4/box.h
51
MP4/box.h
|
@ -1,4 +1,7 @@
|
||||||
#include "boxheader.h"
|
#include "boxheader.h"
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
class Box {
|
class Box {
|
||||||
public:
|
public:
|
||||||
|
@ -9,50 +12,16 @@ class Box {
|
||||||
void SetBoxType(uint32_t BoxType);
|
void SetBoxType(uint32_t BoxType);
|
||||||
uint32_t GetBoxType();
|
uint32_t GetBoxType();
|
||||||
|
|
||||||
void SetPayload(uint32_t PayloadSize, uint8_t * Data);
|
void SetPayload(uint32_t Size, uint8_t * Data, uint32_t Index = 0);
|
||||||
|
uint32_t GetPayloadSize();
|
||||||
uint8_t * GetPayload();
|
uint8_t * GetPayload();
|
||||||
uint8_t * GetPayload(uint32_t Index, uint32_t Size);
|
uint8_t * GetPayload(uint32_t Index, uint32_t & Size);
|
||||||
|
|
||||||
|
static uint8_t * uint32_to_uint8( uint32_t data );
|
||||||
private:
|
private:
|
||||||
BoxHeader header;
|
BoxHeader header;
|
||||||
uint8_t * Payload;
|
uint8_t * Payload;
|
||||||
|
|
||||||
|
uint32_t PayloadSize;
|
||||||
};//Box Class
|
};//Box Class
|
||||||
|
|
||||||
Box::Box() {
|
|
||||||
Payload = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Box::Box(uint32_t BoxType) {
|
|
||||||
header.BoxType = BoxType;
|
|
||||||
Payload = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Box::~Box() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Box::SetBoxType(uint32_t BoxType) {
|
|
||||||
header.BoxType = BoxType;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t Box::GetBoxType() {
|
|
||||||
return header.BoxType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Box::SetPayload(uint32_t PayloadSize, uint8_t * Data ) {
|
|
||||||
if ( Payload != NULL ) { delete Payload; }
|
|
||||||
Payload = new uint8_t[PayloadSize];
|
|
||||||
memcpy( Payload, Data, PayloadSize );
|
|
||||||
header.TotalSize = PayloadSize + 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t * Box::GetPayload() {
|
|
||||||
uint8_t * temp = new uint8_t[header.TotalSize - 8];
|
|
||||||
memcpy( temp, Payload, header.TotalSize - 8 );
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t * Box::GetPayload(uint32_t Index, uint32_t Size) {
|
|
||||||
if(
|
|
||||||
uint8_t * temp = new uint8_t[header.TotalSize - 8];
|
|
||||||
memcpy( temp, Payload, header.TotalSize - 8 );
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
23
MP4/box_ftyp.cpp
Normal file
23
MP4/box_ftyp.cpp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#include "box_ftyp.h"
|
||||||
|
|
||||||
|
Box_ftyp::Box_ftyp( uint32_t MajorBrand, uint32_t MinorBrand ) {
|
||||||
|
Container = new Box( 0x66747970 );
|
||||||
|
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MajorBrand));
|
||||||
|
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MinorBrand),4);
|
||||||
|
}
|
||||||
|
|
||||||
|
Box_ftyp::~Box_ftyp() {
|
||||||
|
delete Container;
|
||||||
|
}
|
||||||
|
|
||||||
|
Box * Box_ftyp::GetBox() {
|
||||||
|
return Container;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Box_ftyp::SetMajorBrand( uint32_t MajorBrand ) {
|
||||||
|
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MajorBrand));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Box_ftyp::SetMinorBrand( uint32_t MinorBrand ) {
|
||||||
|
Container->SetPayload((uint32_t)4,Box::uint32_to_uint8(MinorBrand),4);
|
||||||
|
}
|
13
MP4/box_ftyp.h
Normal file
13
MP4/box_ftyp.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#include "box.h"
|
||||||
|
|
||||||
|
class Box_ftyp {
|
||||||
|
public:
|
||||||
|
Box_ftyp( uint32_t MajorBrand = 0x66347620, uint32_t MinorBrand = 0x1);
|
||||||
|
~Box_ftyp();
|
||||||
|
Box * GetBox();
|
||||||
|
void SetMajorBrand( uint32_t MajorBrand );
|
||||||
|
void SetMinorBrand( uint32_t MinorBrand );
|
||||||
|
private:
|
||||||
|
Box * Container;
|
||||||
|
};//Box_ftyp Class
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
struct BoxHeader {
|
struct BoxHeader {
|
||||||
uint32_t TotalSize;
|
uint32_t TotalSize;
|
||||||
uint32_t BoxType;
|
uint32_t BoxType;
|
||||||
|
|
15
MP4/main.cpp
Normal file
15
MP4/main.cpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include "box_ftyp.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue