MP4 speed optimize
This commit is contained in:
parent
7f7b35acce
commit
29669f24c4
5 changed files with 22 additions and 24 deletions
34
lib/mp4.cpp
34
lib/mp4.cpp
|
@ -84,25 +84,21 @@ namespace MP4 {
|
||||||
return std::string(retVal + 4, 4);
|
return std::string(retVal + 4, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
///\todo make good working calcBoxSize with size and payloadoffset calculation
|
/// Checks box size, offset-aware
|
||||||
unsigned long int calcBoxSize(char readVal[16]) {
|
uint64_t calcBoxSize(const char * p){
|
||||||
return (unsigned int)ntohl(((int *)readVal)[0]);
|
uint64_t r = ntohl(((int *)p)[0]);
|
||||||
|
if (r == 1){
|
||||||
|
return (((uint64_t)ntohl(((int *)p)[2])) << 32) | ntohl(((int *)p)[3]);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool skipBox(FILE * newData) {
|
bool skipBox(FILE * newData) {
|
||||||
char readVal[16];
|
char readVal[16];
|
||||||
long long unsigned int pos = ftell(newData);
|
long long unsigned int pos = ftell(newData);
|
||||||
if (fread(readVal, 4, 1, newData)) {
|
if (fread(readVal, 16, 1, newData)) {
|
||||||
uint64_t size = calcBoxSize(readVal);
|
uint64_t size = calcBoxSize(readVal);
|
||||||
if (size == 1) {
|
if (size == 0) {
|
||||||
if (fread(readVal + 4, 12, 1, newData)) {
|
|
||||||
size = 0 + ntohl(((int *)readVal)[2]);
|
|
||||||
size <<= 32;
|
|
||||||
size += ntohl(((int *)readVal)[3]);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (size == 0) {
|
|
||||||
fseek(newData, 0, SEEK_END);
|
fseek(newData, 0, SEEK_END);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -120,9 +116,9 @@ namespace MP4 {
|
||||||
bool Box::read(FILE * newData) {
|
bool Box::read(FILE * newData) {
|
||||||
char readVal[16];
|
char readVal[16];
|
||||||
long long unsigned int pos = ftell(newData);
|
long long unsigned int pos = ftell(newData);
|
||||||
if (fread(readVal, 4, 1, newData)) {
|
if (fread(readVal, 16, 1, newData)) {
|
||||||
payloadOffset = 8;
|
payloadOffset = 8;
|
||||||
uint64_t size = calcBoxSize(readVal);
|
uint64_t size = ntohl(((int *)readVal)[0]);
|
||||||
if (size == 1) {
|
if (size == 1) {
|
||||||
if (fread(readVal + 4, 12, 1, newData)) {
|
if (fread(readVal + 4, 12, 1, newData)) {
|
||||||
size = 0 + ntohl(((int *)readVal)[2]);
|
size = 0 + ntohl(((int *)readVal)[2]);
|
||||||
|
@ -182,7 +178,7 @@ namespace MP4 {
|
||||||
/// Returns the total boxed size of this box, including the header.
|
/// Returns the total boxed size of this box, including the header.
|
||||||
uint64_t Box::boxedSize() {
|
uint64_t Box::boxedSize() {
|
||||||
if (payloadOffset == 16) {
|
if (payloadOffset == 16) {
|
||||||
return ((uint64_t)ntohl(((int *)data)[2]) << 32) + ntohl(((int *)data)[3]);
|
return ((uint64_t)ntohl(((int *)data)[2]) << 32) | ntohl(((int *)data)[3]);
|
||||||
}
|
}
|
||||||
return ntohl(((int *)data)[0]);
|
return ntohl(((int *)data)[0]);
|
||||||
}
|
}
|
||||||
|
@ -621,7 +617,7 @@ namespace MP4 {
|
||||||
if ((index + payloadOffset + 8) > boxedSize()) {
|
if ((index + payloadOffset + 8) > boxedSize()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return getBox(index).boxedSize();
|
return calcBoxSize(data + index + payloadOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replaces the existing box at the given index by the new box newEntry.
|
/// Replaces the existing box at the given index by the new box newEntry.
|
||||||
|
@ -732,9 +728,9 @@ namespace MP4 {
|
||||||
setBox(newContent, tempLoc);
|
setBox(newContent, tempLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Box & containerBox::getContent(uint32_t no) {
|
Box & containerBox::getContent(uint32_t no, bool unsafe) {
|
||||||
static Box ret = Box((char *)"\000\000\000\010erro", false);
|
static Box ret = Box((char *)"\000\000\000\010erro", false);
|
||||||
if (no > getContentCount()) {
|
if (!unsafe && no > getContentCount()) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
namespace MP4 {
|
namespace MP4 {
|
||||||
std::string readBoxType(FILE * newData);
|
std::string readBoxType(FILE * newData);
|
||||||
bool skipBox(FILE * newData);
|
bool skipBox(FILE * newData);
|
||||||
|
uint64_t calcBoxSize(const char * p);
|
||||||
|
|
||||||
|
|
||||||
class Box {
|
class Box {
|
||||||
|
@ -81,7 +82,7 @@ namespace MP4 {
|
||||||
containerBox();
|
containerBox();
|
||||||
uint32_t getContentCount();
|
uint32_t getContentCount();
|
||||||
void setContent(Box & newContent, uint32_t no);
|
void setContent(Box & newContent, uint32_t no);
|
||||||
Box & getContent(uint32_t no);
|
Box & getContent(uint32_t no, bool unsafe = false);
|
||||||
std::string toPrettyString(uint32_t indent = 0);
|
std::string toPrettyString(uint32_t indent = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,9 +58,10 @@ namespace MP4 {
|
||||||
setBox(newContent, tempLoc);
|
setBox(newContent, tempLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
Box & TRAF::getContent(uint32_t no) {
|
/// Gets a reference to the given box number. If unsafe, doesn't check boundaries (getContentCount check skipped).
|
||||||
|
Box & TRAF::getContent(uint32_t no, bool unsafe) {
|
||||||
static Box ret = Box((char *)"\000\000\000\010erro", false);
|
static Box ret = Box((char *)"\000\000\000\010erro", false);
|
||||||
if (no > getContentCount()) {
|
if (!unsafe && no > getContentCount()) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace MP4 {
|
||||||
TRAF();
|
TRAF();
|
||||||
uint32_t getContentCount();
|
uint32_t getContentCount();
|
||||||
void setContent(Box & newContent, uint32_t no);
|
void setContent(Box & newContent, uint32_t no);
|
||||||
Box & getContent(uint32_t no);
|
Box & getContent(uint32_t no, bool unsafe = false);
|
||||||
std::string toPrettyString(uint32_t indent = 0);
|
std::string toPrettyString(uint32_t indent = 0);
|
||||||
};
|
};
|
||||||
//TRAF Box
|
//TRAF Box
|
||||||
|
|
|
@ -542,7 +542,7 @@ namespace Mist {
|
||||||
char * dataPointer = 0;
|
char * dataPointer = 0;
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
thisPacket.getString("data", dataPointer, len);
|
thisPacket.getString("data", dataPointer, len);
|
||||||
if ((unsigned long)thisPacket.getTrackId() != sortSet.begin()->trackID || thisPacket.getTime() != sortSet.begin()->time){
|
if ((unsigned long)thisPacket.getTrackId() != sortSet.begin()->trackID || thisPacket.getTime() != sortSet.begin()->time || len != sortSet.begin()->size) {
|
||||||
if (thisPacket.getTime() > sortSet.begin()->time || (unsigned long)thisPacket.getTrackId() > sortSet.begin()->trackID) {
|
if (thisPacket.getTime() > sortSet.begin()->time || (unsigned long)thisPacket.getTrackId() > sortSet.begin()->trackID) {
|
||||||
if (perfect){
|
if (perfect){
|
||||||
DEBUG_MSG(DLVL_WARN, "Warning: input is inconsistent. Expected %lu:%llu but got %ld:%llu - cancelling playback", sortSet.begin()->trackID, sortSet.begin()->time, thisPacket.getTrackId(), thisPacket.getTime());
|
DEBUG_MSG(DLVL_WARN, "Warning: input is inconsistent. Expected %lu:%llu but got %ld:%llu - cancelling playback", sortSet.begin()->trackID, sortSet.begin()->time, thisPacket.getTrackId(), thisPacket.getTime());
|
||||||
|
|
Loading…
Add table
Reference in a new issue