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
#include <string>
#include <vector>
#include <set>
#include <iostream>
#include <iomanip>
#include <cstdio>
@ -13,6 +14,17 @@
/// Contains all MP4 format related code.
namespace MP4 {
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 size;
long long int time;
@ -27,7 +39,7 @@ namespace MP4 {
void parseDTSC(JSON::Value mediaPart);
bool sendReady();
std::string sendString();
std::vector <keyPart> keyParts;
std::set <keyPart> keyParts;
private:
//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

View file

@ -2,9 +2,9 @@
#include <sstream>
namespace MP4{
bool keyPartSort(keyPart i, keyPart j){
/*bool keyPartSort(keyPart i, keyPart j){
return (i.time < j.time);
}
}*/
std::string DTSC2MP4Converter::DTSCMeta2MP4Header(JSON::Value metaData){
std::stringstream header;
@ -56,12 +56,12 @@ namespace MP4{
temp.len = (*keyIt)["len"].asInt();
temp.parts = (*keyIt)["parts"].asString();
temp.partsize = (*keyIt)["partsize"].asInt();
keyParts.push_back(temp);
keyParts.insert(temp);
}
}
}
//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
int boxOffset = 1;
@ -237,17 +237,17 @@ namespace MP4{
uint64_t totalByteOffset = 0;
//Inserting wrong values on purpose here, will be fixed later.
//Current values are actual byte offset without header-sized offset
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
for (std::set<keyPart>::iterator i = keyParts.begin(); i != keyParts.end(); i++){//for all keypart size
if(i->trackID == it->second["trackid"].asInt()){//if keypart is of current trackID
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
stcoBox.setChunkOffset(totalByteOffset, total);
total++;
totalByteOffset += parsedParts[o];
}
}else{
totalByteOffset += keyParts[i].size;
totalByteOffset += i->size;
}
}
//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){
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
//mdat output here
//output cleanout buffer first
//while there are requested packets in the trackBuffer:...
while (!trackBuffer[keyParts[curKey].trackID].empty()){
while (!trackBuffer[curKey->trackID].empty()){
//output requested packages
stringBuffer += trackBuffer[keyParts[curKey].trackID].front()["data"].asString();
trackBuffer[keyParts[curKey].trackID].pop_front();
stringBuffer += trackBuffer[curKey->trackID].front()["data"].asString();
trackBuffer[curKey->trackID].pop_front();
curPart++;
if(curPart >= keyParts[curKey].partsize){
if(curPart >= curKey->partsize){
curPart = 0;
curKey++;
}
}
//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
stringBuffer += mediaPart["data"].asStringRef();
curPart++;
if(curPart >= keyParts[curKey].partsize){
if(curPart >= curKey->partsize){
curPart = 0;
curKey++;
}