MP4, converted vectors to set

This commit is contained in:
Oswald Auguste de Bruin 2013-10-04 12:21:45 +02:00
parent 2d0f25b7be
commit 7ecf95e399
2 changed files with 28 additions and 16 deletions

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <vector> #include <vector>
#include <set>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <cstdio> #include <cstdio>
@ -13,6 +14,17 @@
/// Contains all MP4 format related code. /// Contains all MP4 format related code.
namespace MP4 { namespace MP4 {
struct keyPart{ struct keyPart{
bool operator < (const keyPart& rhs) const {
if (time < rhs.time){
return true;
}
if (time == rhs.time){
if (trackID < rhs.trackID){
return true;
}
}
return false;
}
long long int trackID; long long int trackID;
long long int size; long long int size;
long long int time; long long int time;
@ -27,7 +39,7 @@ namespace MP4 {
void parseDTSC(JSON::Value mediaPart); void parseDTSC(JSON::Value mediaPart);
bool sendReady(); bool sendReady();
std::string sendString(); std::string sendString();
std::vector <keyPart> keyParts; std::set <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

View file

@ -2,9 +2,9 @@
#include <sstream> #include <sstream>
namespace MP4{ namespace MP4{
bool keyPartSort(keyPart i, keyPart j){ /*bool keyPartSort(keyPart i, keyPart j){
return (i.time < j.time); return (i.time < j.time);
} }*/
std::string DTSC2MP4Converter::DTSCMeta2MP4Header(JSON::Value metaData){ std::string DTSC2MP4Converter::DTSCMeta2MP4Header(JSON::Value metaData){
std::stringstream header; std::stringstream header;
@ -56,12 +56,12 @@ namespace MP4{
temp.len = (*keyIt)["len"].asInt(); temp.len = (*keyIt)["len"].asInt();
temp.parts = (*keyIt)["parts"].asString(); temp.parts = (*keyIt)["parts"].asString();
temp.partsize = (*keyIt)["partsize"].asInt(); temp.partsize = (*keyIt)["partsize"].asInt();
keyParts.push_back(temp); keyParts.insert(temp);
} }
} }
} }
//sort by time on keyframes for interleaving //sort by time on keyframes for interleaving
std::sort(keyParts.begin(), keyParts.end(), keyPartSort); //std::sort(keyParts.begin(), keyParts.end(), keyPartSort);
//start arbitrary track addition for header //start arbitrary track addition for header
int boxOffset = 1; int boxOffset = 1;
@ -237,17 +237,17 @@ namespace MP4{
uint64_t totalByteOffset = 0; uint64_t totalByteOffset = 0;
//Inserting wrong values on purpose here, will be fixed later. //Inserting wrong values on purpose here, will be fixed later.
//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 (std::set<keyPart>::iterator i = keyParts.begin(); i != keyParts.end(); i++){//for all keypart size
if(keyParts[i].trackID == it->second["trackid"].asInt()){//if keypart is of current trackID if(i->trackID == it->second["trackid"].asInt()){//if keypart is of current trackID
std::deque<long long unsigned int> parsedParts; std::deque<long long unsigned int> parsedParts;
JSON::decodeVector(keyParts[i].parts, parsedParts); JSON::decodeVector(i->parts, parsedParts);
for (unsigned int o = 0; o < parsedParts.size(); o++){//add all parts to STCO 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 += parsedParts[o]; totalByteOffset += parsedParts[o];
} }
}else{ }else{
totalByteOffset += keyParts[i].size; totalByteOffset += i->size;
} }
} }
//calculating the offset where the STCO box will be in the main MOOV box //calculating the offset where the STCO box will be in the main MOOV box
@ -311,27 +311,27 @@ namespace MP4{
} }
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 std::set<keyPart>::iterator curKey = keyParts.begin();//the key chunk we are currently searching for in keyParts
static long long unsigned int curPart = 0;//current part in current key 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:...
while (!trackBuffer[keyParts[curKey].trackID].empty()){ while (!trackBuffer[curKey->trackID].empty()){
//output requested packages //output requested packages
stringBuffer += trackBuffer[keyParts[curKey].trackID].front()["data"].asString(); stringBuffer += trackBuffer[curKey->trackID].front()["data"].asString();
trackBuffer[keyParts[curKey].trackID].pop_front(); trackBuffer[curKey->trackID].pop_front();
curPart++; curPart++;
if(curPart >= keyParts[curKey].partsize){ if(curPart >= curKey->partsize){
curPart = 0; curPart = 0;
curKey++; curKey++;
} }
} }
//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(curKey->trackID == mediaPart["trackid"].asInt()){
//output JSON packet //output JSON packet
stringBuffer += mediaPart["data"].asStringRef(); stringBuffer += mediaPart["data"].asStringRef();
curPart++; curPart++;
if(curPart >= keyParts[curKey].partsize){ if(curPart >= curKey->partsize){
curPart = 0; curPart = 0;
curKey++; curKey++;
} }