MP4 not fixed, but at least does not segfault
This commit is contained in:
parent
974861d993
commit
a80eeef659
2 changed files with 29 additions and 20 deletions
|
@ -17,7 +17,7 @@ namespace MP4 {
|
||||||
long long int size;
|
long long int size;
|
||||||
long long int time;
|
long long int time;
|
||||||
long long int len;
|
long long int len;
|
||||||
JSON::Value parts;
|
std::string parts;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DTSC2MP4Converter{
|
class DTSC2MP4Converter{
|
||||||
|
@ -28,8 +28,8 @@ namespace MP4 {
|
||||||
std::string sendString();
|
std::string sendString();
|
||||||
std::vector <keyPart> keyParts;
|
std::vector <keyPart> keyParts;
|
||||||
private:
|
private:
|
||||||
long long unsigned int curKey;//the key chunk we are currently searching for in keyParts
|
//long long unsigned int curKey;//the key chunk we are currently searching for in keyParts
|
||||||
long long unsigned int curPart;//current part in current key
|
//long long unsigned int curPart;//current part in current key
|
||||||
std::map <long long unsigned int, std::deque<JSON::Value> > trackBuffer;
|
std::map <long long unsigned int, std::deque<JSON::Value> > trackBuffer;
|
||||||
std::string stringBuffer;
|
std::string stringBuffer;
|
||||||
};
|
};
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace MP4{
|
||||||
temp.size = (*keyIt)["size"].asInt();
|
temp.size = (*keyIt)["size"].asInt();
|
||||||
temp.time = (*keyIt)["time"].asInt();
|
temp.time = (*keyIt)["time"].asInt();
|
||||||
temp.len = (*keyIt)["len"].asInt();
|
temp.len = (*keyIt)["len"].asInt();
|
||||||
temp.parts = (*keyIt)["parts"];
|
temp.parts = (*keyIt)["parts"].asString();
|
||||||
keyParts.push_back(temp);
|
keyParts.push_back(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ namespace MP4{
|
||||||
//Calculating media time based on sampledelta. Probably cheating, but it works...
|
//Calculating media time based on sampledelta. Probably cheating, but it works...
|
||||||
int tmpParts = 0;
|
int tmpParts = 0;
|
||||||
for (JSON::ArrIter tmpIt = it->second["keys"].ArrBegin(); tmpIt != it->second["keys"].ArrEnd(); tmpIt++){
|
for (JSON::ArrIter tmpIt = it->second["keys"].ArrBegin(); tmpIt != it->second["keys"].ArrEnd(); tmpIt++){
|
||||||
tmpParts += (*tmpIt)["parts"].size();
|
tmpParts += (*tmpIt)["partsize"].asInt();
|
||||||
}
|
}
|
||||||
timescale = ((double)(42 * tmpParts) / (it->second["lastms"].asInt() + it->second["firstms"].asInt())) * 1000;
|
timescale = ((double)(42 * tmpParts) / (it->second["lastms"].asInt() + it->second["firstms"].asInt())) * 1000;
|
||||||
mdhdBox.setTimeScale(timescale);
|
mdhdBox.setTimeScale(timescale);
|
||||||
|
@ -199,7 +199,7 @@ namespace MP4{
|
||||||
int tmpCount = 1;
|
int tmpCount = 1;
|
||||||
for (int i = 0; i < it->second["keys"].size(); i++){
|
for (int i = 0; i < it->second["keys"].size(); i++){
|
||||||
stssBox.setSampleNumber(tmpCount,i);
|
stssBox.setSampleNumber(tmpCount,i);
|
||||||
tmpCount += it->second["keys"][i]["parts"].size();
|
tmpCount += it->second["keys"][i]["partsize"].asInt();
|
||||||
}
|
}
|
||||||
stblBox.setContent(stssBox,2);
|
stblBox.setContent(stssBox,2);
|
||||||
}
|
}
|
||||||
|
@ -221,8 +221,10 @@ namespace MP4{
|
||||||
stszBox.setVersion(0);
|
stszBox.setVersion(0);
|
||||||
total = 0;
|
total = 0;
|
||||||
for (int i = 0; i < it->second["keys"].size(); i++){
|
for (int i = 0; i < it->second["keys"].size(); i++){
|
||||||
for (int o = 0; o < it->second["keys"][i]["parts"].size(); o++){
|
std::deque<long long int> parsedParts;
|
||||||
stszBox.setEntrySize(it->second["keys"][i]["parts"][o].asInt(), total);//in bytes in file
|
JSON::decodeVector(it->second["keys"][i]["parts"].asString(), parsedParts);
|
||||||
|
for (unsigned int o = 0; o < parsedParts.size(); o++){
|
||||||
|
stszBox.setEntrySize(parsedParts[o], total);//in bytes in file
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,10 +238,12 @@ namespace MP4{
|
||||||
//Current values are actual byte offset without header-sized offset
|
//Current values are actual byte offset without header-sized offset
|
||||||
for (unsigned int i = 0; i < keyParts.size(); i++){//for all keypart size
|
for (unsigned int i = 0; i < keyParts.size(); i++){//for all keypart size
|
||||||
if(keyParts[i].trackID == it->second["trackid"].asInt()){//if keypart is of current trackID
|
if(keyParts[i].trackID == it->second["trackid"].asInt()){//if keypart is of current trackID
|
||||||
for (unsigned int o = 0; o < keyParts[i].parts.size(); o++){//add all parts to STCO
|
std::deque<long long int> parsedParts;
|
||||||
|
JSON::decodeVector(keyParts[i].parts, parsedParts);
|
||||||
|
for (unsigned int o = 0; o < parsedParts.size(); o++){//add all parts to STCO
|
||||||
stcoBox.setChunkOffset(totalByteOffset, total);
|
stcoBox.setChunkOffset(totalByteOffset, total);
|
||||||
total++;
|
total++;
|
||||||
totalByteOffset += keyParts[i].parts[o].asInt();
|
totalByteOffset += parsedParts[o];
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
totalByteOffset += keyParts[i].size;
|
totalByteOffset += keyParts[i].size;
|
||||||
|
@ -315,26 +319,29 @@ namespace MP4{
|
||||||
header << (char)((mdatSize>>24) & 0x000000FF) << (char)((mdatSize>>16) & 0x000000FF) << (char)((mdatSize>>8) & 0x000000FF) << (char)(mdatSize & 0x000000FF) << "mdat";
|
header << (char)((mdatSize>>24) & 0x000000FF) << (char)((mdatSize>>16) & 0x000000FF) << (char)((mdatSize>>8) & 0x000000FF) << (char)(mdatSize & 0x000000FF) << "mdat";
|
||||||
//std::cerr << "Header Written" << std::endl;
|
//std::cerr << "Header Written" << std::endl;
|
||||||
//end of header
|
//end of header
|
||||||
std::map <long long unsigned int, std::deque<JSON::Value> > trackBuffer;
|
|
||||||
long long unsigned int curKey = 0;//the key chunk we are currently searching for in keyParts
|
|
||||||
long long unsigned int curPart = 0;//current part in current key
|
|
||||||
|
|
||||||
return header.str();
|
return header.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DTSC2MP4Converter::parseDTSC(JSON::Value mediaPart){
|
void DTSC2MP4Converter::parseDTSC(JSON::Value mediaPart){
|
||||||
|
static long long unsigned int curKey = 0;//the key chunk we are currently searching for in keyParts
|
||||||
|
static long long unsigned int curPart = 0;//current part in current key
|
||||||
//mdat output here
|
//mdat output here
|
||||||
//output cleanout buffer first
|
//output cleanout buffer first
|
||||||
//while there are requested packets in the trackBuffer:...
|
//while there are requested packets in the trackBuffer:...
|
||||||
|
//std::cerr << curPart << " " << curKey << " " << keyParts.size() << " " << keyParts[curKey].trackID << "|";
|
||||||
|
//std::cerr << trackBuffer[keyParts[curKey].trackID].empty() << std::endl;
|
||||||
while (!trackBuffer[keyParts[curKey].trackID].empty()){
|
while (!trackBuffer[keyParts[curKey].trackID].empty()){
|
||||||
//output requested packages
|
//output requested packages
|
||||||
if(keyParts[curKey].parts[curPart].asInt() != trackBuffer[keyParts[curKey].trackID].front()["data"].asString().size()){
|
std::deque<long long int> parsedParts;
|
||||||
std::cerr << "Size discrepancy in buffer packet. Size: " << mediaPart["data"].asString().size() << " Expected:" << keyParts[curKey].parts[curPart].asInt() << std::endl;
|
JSON::decodeVector(keyParts[curKey].parts, parsedParts);
|
||||||
|
if(parsedParts[curPart] != trackBuffer[keyParts[curKey].trackID].front()["data"].asString().size()){
|
||||||
|
std::cerr << "Size discrepancy in buffer packet. Size: " << mediaPart["data"].asString().size() << " Expected:" << parsedParts[curPart] << std::endl;
|
||||||
}
|
}
|
||||||
stringBuffer += trackBuffer[keyParts[curKey].trackID].front()["data"].asString();
|
stringBuffer += trackBuffer[keyParts[curKey].trackID].front()["data"].asString();
|
||||||
trackBuffer[keyParts[curKey].trackID].pop_front();
|
trackBuffer[keyParts[curKey].trackID].pop_front();
|
||||||
curPart++;
|
curPart++;
|
||||||
if(curPart >= keyParts[curKey].parts.size()){
|
if(curPart >= parsedParts.size()){
|
||||||
curPart = 0;
|
curPart = 0;
|
||||||
curKey++;
|
curKey++;
|
||||||
}
|
}
|
||||||
|
@ -342,12 +349,14 @@ namespace MP4{
|
||||||
//after that, try to put out the JSON data directly
|
//after that, try to put out the JSON data directly
|
||||||
if(keyParts[curKey].trackID == mediaPart["trackid"].asInt()){
|
if(keyParts[curKey].trackID == mediaPart["trackid"].asInt()){
|
||||||
//output JSON packet
|
//output JSON packet
|
||||||
if(keyParts[curKey].parts[curPart].asInt() != mediaPart["data"].asString().size()){
|
std::deque<long long int> parsedParts;
|
||||||
std::cerr << "Size discrepancy in JSON packet. Size: " << mediaPart["data"].asString().size() << " Expected:" << keyParts[curKey].parts[curPart].asInt() << std::endl;
|
JSON::decodeVector(keyParts[curKey].parts, parsedParts);
|
||||||
|
if(parsedParts[curPart] != mediaPart["data"].asStringRef().size()){
|
||||||
|
std::cerr << "Size discrepancy in JSON packet. Size: " << mediaPart["data"].asStringRef().size() << " Expected:" << parsedParts[curPart] << std::endl;
|
||||||
}
|
}
|
||||||
stringBuffer += mediaPart["data"].asString();
|
stringBuffer += mediaPart["data"].asStringRef();
|
||||||
curPart++;
|
curPart++;
|
||||||
if(curPart >= keyParts[curKey].parts.size()){
|
if(curPart >= parsedParts.size()){
|
||||||
curPart = 0;
|
curPart = 0;
|
||||||
curKey++;
|
curKey++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue