Added Meta and Edit list boxes

This commit is contained in:
Oswald de Bruin 2013-05-03 13:42:13 +02:00 committed by Erik Zandvliet
parent 4cb5d5a5ab
commit 7b6eb6ad26
2 changed files with 188 additions and 9 deletions

View file

@ -256,6 +256,12 @@ namespace MP4 {
case 0x73747373: case 0x73747373:
return ((STSS*)this)->toPrettyString(indent); return ((STSS*)this)->toPrettyString(indent);
break; break;
case 0x6D657461:
return ((META*)this)->toPrettyString(indent);
break;
case 0x656C7374:
return ((ELST*)this)->toPrettyString(indent);
break;
case 0x75647461: case 0x75647461:
return ((UDTA*)this)->toPrettyString(indent); return ((UDTA*)this)->toPrettyString(indent);
break; break;
@ -565,6 +571,14 @@ namespace MP4 {
uint32_t fullBox::getFlags(){ uint32_t fullBox::getFlags(){
return getInt24(1); return getInt24(1);
} }
std::string fullBox::toPrettyString(uint32_t indent){
std::stringstream r;
r << std::string(indent + 1, ' ') << "Version: " << (int)getVersion() << std::endl;
r << std::string(indent + 1, ' ') << "Flags: " << getFlags() << std::endl;
return r.str();
}
uint32_t containerBox::getContentCount(){ uint32_t containerBox::getContentCount(){
int res = 0; int res = 0;
int tempLoc = 0; int tempLoc = 0;
@ -575,13 +589,6 @@ namespace MP4 {
return res; return res;
} }
std::string fullBox::toPrettyString(uint32_t indent){
std::stringstream r;
r << std::string(indent + 1, ' ') << "Version: " << (int)getVersion() << std::endl;
r << std::string(indent + 1, ' ') << "Flags: " << getFlags() << std::endl;
return r.str();
}
void containerBox::setContent(Box & newContent, uint32_t no){ void containerBox::setContent(Box & newContent, uint32_t no){
int tempLoc = 0; int tempLoc = 0;
int contentCount = getContentCount(); int contentCount = getContentCount();
@ -628,6 +635,63 @@ namespace MP4 {
return r.str(); return r.str();
} }
uint32_t containerFullBox::getContentCount(){
int res = 0;
int tempLoc = 4;
while (tempLoc < boxedSize() - 8){
res++;
tempLoc += getBoxLen(tempLoc);
}
return res;
}
void containerFullBox::setContent(Box & newContent, uint32_t no){
int tempLoc = 4;
int contentCount = getContentCount();
for (int i = 0; i < no; i++){
if (i < contentCount){
tempLoc += getBoxLen(tempLoc);
}else{
if ( !reserve(tempLoc, 0, (no - contentCount) * 8)){
return;
};
memset(data + tempLoc, 0, (no - contentCount) * 8);
tempLoc += (no - contentCount) * 8;
break;
}
}
setBox(newContent, tempLoc);
}
Box & containerFullBox::getContent(uint32_t no){
static Box ret = Box((char*)"\000\000\000\010erro", false);
if (no > getContentCount()){
return ret;
}
int i = 0;
int tempLoc = 4;
while (i < no){
tempLoc += getBoxLen(tempLoc);
i++;
}
return getBox(tempLoc);
}
std::string containerFullBox::toPrettyCFBString(uint32_t indent, std::string boxName){
std::stringstream r;
r << std::string(indent, ' ') << boxName <<" (" << boxedSize() << ")" << std::endl;
r << fullBox::toPrettyString(indent);
Box curBox;
int tempLoc = 4;
int contentCount = getContentCount();
for (int i = 0; i < contentCount; i++){
curBox = getContent(i);
r << curBox.toPrettyString(indent + 1);
tempLoc += getBoxLen(tempLoc);
}
return r.str();
}
ABST::ABST(){ ABST::ABST(){
memcpy(data + 4, "abst", 4); memcpy(data + 4, "abst", 4);
setVersion(0); setVersion(0);
@ -4051,7 +4115,7 @@ namespace MP4 {
getInt32(4); getInt32(4);
} }
void STSS::setSampleNumber(uint32 newVal, uint32_t index){ void STSS::setSampleNumber(uint32_t newVal, uint32_t index){
if (index+1 > getEntryCount()){ if (index+1 > getEntryCount()){
setEntryCount(index); setEntryCount(index);
} }
@ -4076,6 +4140,93 @@ namespace MP4 {
return r.str(); return r.str();
} }
META::META(){
memcpy(data + 4, "meta", 4);
}
std::string META::toPrettyString(uint32_t indent){
return toPrettyCFBString(indent, "[meta] Meta Box");
}
ELST::ELST(){
memcpy(data + 4, "elst", 4);
}
void ELST::setSegmentDuration(uint64_t newVal){
if (getVersion() == 1){
setInt64(newVal, 4);
}else{
setInt32(newVal, 4);
}
}
uint64_t ELST::getSegmentDuration(){
if (getVersion() == 1){
return getInt64(4);
}else{
return getInt32(4);
}
}
void ELST::setMediaTime(uint64_t newVal){
if (getVersion() == 1){
setInt64(newVal, 12);
}else{
setInt32(newVal, 8);
}
}
uint64_t ELST::getMediaTime(){
if (getVersion() == 1){
return getInt64(12);
}else{
return getInt32(8);
}
}
void ELST::setMediaRateInteger(uint16_t newVal){
if (getVersion() == 1){
setInt16(newVal, 20);
}else{
setInt16(newVal, 12);
}
}
uint16_t ELST::getMediaRateInteger(){
if (getVersion() == 1){
return getInt16(20);
}else{
return getInt16(12);
}
}
void ELST::setMediaRateFraction(uint16_t newVal){
if (getVersion() == 1){
setInt16(newVal, 22);
}else{
setInt16(newVal, 14);
}
}
uint16_t ELST::getMediaRateFraction(){
if (getVersion() == 1){
return getInt16(22);
}else{
return getInt16(14);
}
}
std::string ELST::toPrettyString(uint32_t indent){
std::stringstream r;
r << std::string(indent, ' ') << "[elst] Edit List Box (" << boxedSize() << ")" << std::endl;
r << fullBox::toPrettyString(indent);
r << std::string(indent + 1, ' ') << "SegmentDuration: " << getSegmentDuration() << std::endl;
r << std::string(indent + 1, ' ') << "MediaTime: " << getMediaTime() << std::endl;
r << std::string(indent + 1, ' ') << "MediaRateInteger: " << getMediaRateInteger() << std::endl;
r << std::string(indent + 1, ' ') << "MediaRateFraction: " << getMediaRateFraction() << std::endl;
return r.str();
}
static char c2hex(int c){ static char c2hex(int c){
if (c >= '0' && c <= '9') return c - '0'; if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return c - 'a' + 10; if (c >= 'a' && c <= 'f') return c - 'a' + 10;

View file

@ -75,6 +75,14 @@ namespace MP4 {
std::string toPrettyContainerString(uint32_t indent, std::string boxName); std::string toPrettyContainerString(uint32_t indent, std::string boxName);
}; };
class containerFullBox: public fullBox{
public:
uint32_t getContentCount();
void setContent(Box & newContent, uint32_t no);
Box & getContent(uint32_t no);
std::string toPrettyCFBString(uint32_t indent, std::string boxName);
};
struct afrt_runtable{ struct afrt_runtable{
uint32_t firstFragment; uint32_t firstFragment;
uint64_t firstTimestamp; uint64_t firstTimestamp;
@ -803,11 +811,31 @@ namespace MP4 {
STSS(); STSS();
void setEntryCount(uint32_t newVal); void setEntryCount(uint32_t newVal);
uint32_t getEntryCount(); uint32_t getEntryCount();
void setSampleNumber(uint32 newVal, uint32_t index); void setSampleNumber(uint32_t newVal, uint32_t index);
uint32_t getSampleNumber(uint32_t index); uint32_t getSampleNumber(uint32_t index);
std::string toPrettyString(uint32_t indent = 0); std::string toPrettyString(uint32_t indent = 0);
}; };
class META: public containerFullBox{
public:
META();
std::string toPrettyString(uint32_t indent = 0);
};
class ELST: public fullBox{
public:
ELST();
void setSegmentDuration(uint64_t newVal);
uint64_t getSegmentDuration();
void setMediaTime(uint64_t newVal);
uint64_t getMediaTime();
void setMediaRateInteger(uint16_t newVal);
uint16_t getMediaRateInteger();
void setMediaRateFraction(uint16_t newVal);
uint16_t getMediaRateFraction();
std::string toPrettyString(uint32_t indent = 0);
};
class UUID: public Box{ class UUID: public Box{
public: public:
UUID(); UUID();