midway commit for safety
This commit is contained in:
parent
48a8534e67
commit
8178aa9e80
2 changed files with 56 additions and 142 deletions
|
@ -38,12 +38,14 @@ namespace Connector_HTTP {
|
||||||
//OGG specific variables
|
//OGG specific variables
|
||||||
OGG::headerPages oggMeta;
|
OGG::headerPages oggMeta;
|
||||||
OGG::Page curOggPage;
|
OGG::Page curOggPage;
|
||||||
//std::map <long long unsigned int, std::vector<JSON::Value> > DTSCBuffer;
|
std::map <long long unsigned int, std::vector<JSON::Value> > DTSCBuffer;
|
||||||
//std::map <long long unsigned int, long long unsigned int> prevGran;
|
//std::map <long long unsigned int, long long unsigned int> prevGran;
|
||||||
std::vector<unsigned int> curSegTable;
|
std::vector<unsigned int> curSegTable;
|
||||||
|
long long int currID = 0;
|
||||||
|
long long int currGran = 0;
|
||||||
long long int prevID = 0;
|
long long int prevID = 0;
|
||||||
long long int prevGran = 0;
|
long long int prevGran = 0;
|
||||||
std::string pageBuffer;
|
std::string sendBuffer;
|
||||||
bool OggEOS = false;
|
bool OggEOS = false;
|
||||||
bool OggCont = false;
|
bool OggCont = false;
|
||||||
|
|
||||||
|
@ -164,88 +166,34 @@ namespace Connector_HTTP {
|
||||||
oggMeta.readDTSCHeader(Strm.metadata);
|
oggMeta.readDTSCHeader(Strm.metadata);
|
||||||
conn.SendNow((char*)oggMeta.parsedPages.c_str(), oggMeta.parsedPages.size());
|
conn.SendNow((char*)oggMeta.parsedPages.c_str(), oggMeta.parsedPages.size());
|
||||||
progressive_has_sent_header = true;
|
progressive_has_sent_header = true;
|
||||||
prevID = Strm.getPacket()["trackid"].asInt();
|
//prevID = Strm.getPacket()["trackid"].asInt();
|
||||||
prevGran = Strm.getPacket()["granule"].asInt();
|
//prevGran = Strm.getPacket()["granule"].asInt();
|
||||||
}
|
}
|
||||||
//parse DTSC to Ogg here
|
//parse DTSC to Ogg here
|
||||||
if (Strm.lastType() == DTSC::AUDIO || Strm.lastType() == DTSC::VIDEO){
|
if (Strm.lastType() == DTSC::AUDIO || Strm.lastType() == DTSC::VIDEO){
|
||||||
long long int temp = Strm.getPacket()["trackid"].asInt();
|
currID = Strm.getPacket()["trackid"].asInt();
|
||||||
/*if((prevGran[temp] != Strm.getPacket()["granule"].asInt() || prevGran[temp] == -1) && DTSCBuffer[temp].size() != 0){
|
currGran = Strm.getPacket()["granule"].asInt();
|
||||||
curOggPage.readDTSCVector(DTSCBuffer[temp], oggMeta.DTSCID2OGGSerial[temp], oggMeta.DTSCID2seqNum[temp]);
|
if (prevID == 0){
|
||||||
|
prevID == currID;
|
||||||
|
}
|
||||||
|
if (DTSCBuffer.count(currID) && !DTSCBuffer[currID].empty()){
|
||||||
|
prevGran = DTSCBuffer[currID][0]["granule"].asInt();
|
||||||
|
}else{
|
||||||
|
prevGran = 0;
|
||||||
|
}
|
||||||
|
if ((prevGran != 0 && (prevGran == -1 || currGran != prevGran)) ){
|
||||||
|
curOggPage.readDTSCVector(DTSCBuffer[currID], oggMeta.DTSCID2OGGSerial[currID], oggMeta.DTSCID2seqNum[currID]);
|
||||||
conn.SendNow((char*)curOggPage.getPage(), curOggPage.getPageSize());
|
conn.SendNow((char*)curOggPage.getPage(), curOggPage.getPageSize());
|
||||||
DTSCBuffer[temp].clear();
|
DTSCBuffer[currID].clear();
|
||||||
oggMeta.DTSCID2seqNum[temp] ++;
|
oggMeta.DTSCID2seqNum[currID]++;
|
||||||
}*/
|
|
||||||
if(Strm.getPacket()["trackid"].asInt()!=prevID || Strm.getPacket()["granule"].asInt()!=prevGran || Strm.getPacket()["granule"].asInt() == -1){
|
|
||||||
curOggPage.clear();
|
|
||||||
curOggPage.setVersion();
|
|
||||||
if (OggCont){
|
|
||||||
curOggPage.setHeaderType(1);//headertype 1 = Continue Page
|
|
||||||
}else if (OggEOS){
|
|
||||||
curOggPage.setHeaderType(4);//headertype 4 = end of stream
|
|
||||||
}else{
|
|
||||||
curOggPage.setHeaderType(0);//headertype 0 = normal
|
|
||||||
}
|
|
||||||
curOggPage.setGranulePosition(prevGran);
|
|
||||||
curOggPage.setBitstreamSerialNumber(oggMeta.DTSCID2OGGSerial[prevID]);
|
|
||||||
curOggPage.setPageSequenceNumber(oggMeta.DTSCID2seqNum[prevID]++);
|
|
||||||
if(!curOggPage.setSegmentTable(curSegTable)){
|
|
||||||
std::cerr << "Troubling segTable:";
|
|
||||||
for (unsigned int i = 0; i<curSegTable.size(); i++){
|
|
||||||
std::cerr << " " << curSegTable[i];
|
|
||||||
}
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
curOggPage.setPayload((char*)pageBuffer.c_str(), pageBuffer.size());
|
|
||||||
curOggPage.setCRCChecksum(curOggPage.calcChecksum());
|
|
||||||
conn.SendNow(curOggPage.getPage(), curOggPage.getPageSize());
|
|
||||||
pageBuffer = "";
|
|
||||||
curSegTable.clear();
|
|
||||||
//write one pagebuffer as Ogg page
|
|
||||||
}
|
|
||||||
//DTSCBuffer[temp].push_back(Strm.getPacket());
|
|
||||||
//prevGran[temp] = Strm.getPacket()["granule"].asInt();
|
|
||||||
pageBuffer += Strm.getPacket()["data"].asString();
|
|
||||||
curSegTable.push_back(Strm.getPacket()["data"].asString().size());
|
|
||||||
prevID = Strm.getPacket()["trackid"].asInt();
|
|
||||||
prevGran = Strm.getPacket()["granule"].asInt();
|
|
||||||
if (Strm.getPacket()["OggEOS"]){
|
|
||||||
OggEOS=true;
|
|
||||||
}else{
|
|
||||||
OggEOS=false;
|
|
||||||
}
|
|
||||||
if (Strm.getPacket()["OggCont"]){
|
|
||||||
OggCont=true;
|
|
||||||
}else{
|
|
||||||
OggCont=false;
|
|
||||||
}
|
}
|
||||||
|
DTSCBuffer[currID].push_back(Strm.getPacket());
|
||||||
|
prevID = currID;
|
||||||
}
|
}
|
||||||
if (Strm.lastType() == DTSC::PAUSEMARK){
|
if (Strm.lastType() == DTSC::PAUSEMARK){
|
||||||
conn.close();
|
conn.close();
|
||||||
//last page output
|
//last page output
|
||||||
curOggPage.clear();
|
|
||||||
curOggPage.setVersion();
|
|
||||||
if (OggCont){
|
|
||||||
curOggPage.setHeaderType(1);//headertype 1 = Continue Page
|
|
||||||
}else if (OggEOS){
|
|
||||||
curOggPage.setHeaderType(4);//headertype 4 = end of stream
|
|
||||||
}else{
|
|
||||||
curOggPage.setHeaderType(0);//headertype 0 = normal
|
|
||||||
}
|
|
||||||
curOggPage.setGranulePosition(prevGran);
|
|
||||||
curOggPage.setBitstreamSerialNumber(oggMeta.DTSCID2OGGSerial[prevID]);
|
|
||||||
curOggPage.setPageSequenceNumber(oggMeta.DTSCID2seqNum[prevID]++);
|
|
||||||
if(!curOggPage.setSegmentTable(curSegTable)){
|
|
||||||
std::cerr << "Troubling segTable:";
|
|
||||||
for (unsigned int i = 0; i<curSegTable.size(); i++){
|
|
||||||
std::cerr << " " << curSegTable[i];
|
|
||||||
}
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
curOggPage.setPayload((char*)pageBuffer.c_str(), pageBuffer.size());
|
|
||||||
curOggPage.setCRCChecksum(curOggPage.calcChecksum());
|
|
||||||
conn.SendNow(curOggPage.getPage(), curOggPage.getPageSize());
|
|
||||||
pageBuffer = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
|
#include <queue>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <mist/timing.h>
|
#include <mist/timing.h>
|
||||||
#include <mist/dtsc.h>
|
#include <mist/dtsc.h>
|
||||||
#include <mist/ogg.h>
|
#include <mist/ogg.h>
|
||||||
|
@ -13,89 +15,53 @@ namespace Converters{
|
||||||
int DTSC2OGG(Util::Config & conf){
|
int DTSC2OGG(Util::Config & conf){
|
||||||
DTSC::File DTSCFile(conf.getString("filename"));
|
DTSC::File DTSCFile(conf.getString("filename"));
|
||||||
//JSON::Value meta = DTSCFile.getMeta();
|
//JSON::Value meta = DTSCFile.getMeta();
|
||||||
OGG::Page curOggPage;
|
|
||||||
srand (Util::getMS());//randomising with milliseconds from boot
|
srand (Util::getMS());//randomising with milliseconds from boot
|
||||||
std::vector<unsigned int> curSegTable;
|
std::vector<unsigned int> curSegTable;
|
||||||
char* curNewPayload;
|
char* curNewPayload;
|
||||||
//std::map <long long unsigned int, unsigned int> DTSCID2OGGSerial;
|
|
||||||
//std::map <long long unsigned int, unsigned int> DTSCID2seqNum;
|
|
||||||
OGG::headerPages oggMeta;
|
OGG::headerPages oggMeta;
|
||||||
//Creating ID headers for theora and vorbis
|
//Creating ID headers for theora and vorbis
|
||||||
oggMeta.readDTSCHeader(DTSCFile.getMeta());
|
oggMeta.readDTSCHeader(DTSCFile.getMeta());
|
||||||
std::cout << oggMeta.parsedPages;
|
std::cout << oggMeta.parsedPages;//outputting header pages
|
||||||
|
|
||||||
//create DTSC in OGG pages
|
//create DTSC in OGG pages
|
||||||
DTSCFile.parseNext();
|
DTSCFile.parseNext();
|
||||||
curSegTable.clear();
|
std::map< long long int, std::vector<JSON::Value> > DTSCBuffer;
|
||||||
long long int prevID = DTSCFile.getJSON()["trackid"].asInt();
|
long long unsigned int prevGran;
|
||||||
long long int prevGran = DTSCFile.getJSON()["granule"].asInt();
|
long long int currID;
|
||||||
bool OggEOS = false;
|
long long int currGran;
|
||||||
bool OggCont = false;
|
OGG::Page curOggPage;
|
||||||
bool IDChange = false;
|
|
||||||
bool GranChange = false;
|
|
||||||
std::string pageBuffer;
|
|
||||||
|
|
||||||
|
|
||||||
while(DTSCFile.getJSON()){
|
while(DTSCFile.getJSON()){
|
||||||
if(DTSCFile.getJSON()["trackid"].asInt()!=prevID || DTSCFile.getJSON()["granule"].asInt()!=prevGran || DTSCFile.getJSON()["granule"].asInt() == -1){
|
currID = DTSCFile.getJSON()["trackid"].asInt();
|
||||||
curOggPage.clear();
|
currGran = DTSCFile.getJSON()["granule"].asInt();
|
||||||
curOggPage.setVersion();
|
if (DTSCBuffer.count(currID) && !DTSCBuffer[currID].empty()){
|
||||||
if (OggCont){
|
prevGran = DTSCBuffer[currID][0]["granule"].asInt();
|
||||||
curOggPage.setHeaderType(1);//headertype 1 = Continue Page
|
|
||||||
}else if (OggEOS){
|
|
||||||
curOggPage.setHeaderType(4);//headertype 4 = end of stream
|
|
||||||
}else{
|
|
||||||
curOggPage.setHeaderType(0);//headertype 0 = normal
|
|
||||||
}
|
|
||||||
curOggPage.setGranulePosition(prevGran);
|
|
||||||
curOggPage.setBitstreamSerialNumber(oggMeta.DTSCID2OGGSerial[prevID]);
|
|
||||||
curOggPage.setPageSequenceNumber(oggMeta.DTSCID2seqNum[prevID]++);
|
|
||||||
if(!curOggPage.setSegmentTable(curSegTable)){
|
|
||||||
std::cerr << "Troubling segTable:";
|
|
||||||
for (unsigned int i = 0; i<curSegTable.size(); i++){
|
|
||||||
std::cerr << " " << curSegTable[i];
|
|
||||||
}
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
curOggPage.setPayload((char*)pageBuffer.c_str(), pageBuffer.size());
|
|
||||||
curOggPage.setCRCChecksum(curOggPage.calcChecksum());
|
|
||||||
std::cout << std::string(curOggPage.getPage(), curOggPage.getPageSize());
|
|
||||||
pageBuffer = "";
|
|
||||||
curSegTable.clear();
|
|
||||||
//write one pagebuffer as Ogg page
|
|
||||||
}
|
|
||||||
|
|
||||||
pageBuffer += DTSCFile.getJSON()["data"].asString();
|
|
||||||
curSegTable.push_back(DTSCFile.getJSON()["data"].asString().size());
|
|
||||||
prevID = DTSCFile.getJSON()["trackid"].asInt();
|
|
||||||
prevGran = DTSCFile.getJSON()["granule"].asInt();
|
|
||||||
if (DTSCFile.getJSON()["OggEOS"]){
|
|
||||||
OggEOS=true;
|
|
||||||
}else{
|
}else{
|
||||||
OggEOS=false;
|
prevGran = 0;
|
||||||
}
|
}
|
||||||
if (DTSCFile.getJSON()["OggCont"]){
|
if (prevGran != 0 && (prevGran == -1 || currGran != prevGran)){
|
||||||
OggCont=true;
|
curOggPage.readDTSCVector(DTSCBuffer[currID], oggMeta.DTSCID2OGGSerial[currID], oggMeta.DTSCID2seqNum[currID]);
|
||||||
}else{
|
std::cout << std::string((char*)curOggPage.getPage(), curOggPage.getPageSize());
|
||||||
OggCont=false;
|
DTSCBuffer[currID].clear();
|
||||||
|
oggMeta.DTSCID2seqNum[currID]++;
|
||||||
}
|
}
|
||||||
|
DTSCBuffer[currID].push_back(DTSCFile.getJSON());
|
||||||
|
|
||||||
DTSCFile.parseNext();
|
DTSCFile.parseNext();
|
||||||
}
|
}
|
||||||
//quick copy-paste fix to output the last ogg page
|
//outputting end of stream pages
|
||||||
curOggPage.clear();
|
for (
|
||||||
curOggPage.setVersion();
|
std::map< long long int, std::vector<JSON::Value> >::iterator it = DTSCBuffer.begin();
|
||||||
curOggPage.setHeaderType(4);//headertype 4 = end of stream
|
it != DTSCBuffer.end();
|
||||||
curOggPage.setGranulePosition(prevGran);
|
it++
|
||||||
curOggPage.setBitstreamSerialNumber(oggMeta.DTSCID2OGGSerial[prevID]);
|
){
|
||||||
curOggPage.setPageSequenceNumber(oggMeta.DTSCID2seqNum[prevID]++);
|
if (!DTSCBuffer[it->first].empty() && DTSCBuffer[it->first][0]["data"].asString() != ""){
|
||||||
curOggPage.setSegmentTable(curSegTable);
|
curOggPage.readDTSCVector(DTSCBuffer[it->first], oggMeta.DTSCID2OGGSerial[it->first], oggMeta.DTSCID2seqNum[it->first]);
|
||||||
curOggPage.setPayload((char*)pageBuffer.c_str(), pageBuffer.size());
|
std::cout << std::string((char*)curOggPage.getPage(), curOggPage.getPageSize());
|
||||||
curOggPage.setCRCChecksum(curOggPage.calcChecksum());
|
}
|
||||||
std::cout << std::string(curOggPage.getPage(), curOggPage.getPageSize());
|
}
|
||||||
pageBuffer = "";
|
|
||||||
curSegTable.clear();
|
|
||||||
//write one pagebuffer as Ogg page
|
|
||||||
//end quick fix
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue