Cleaned up JSON connector output and added WebVTT support in SRT connector

This commit is contained in:
ThatGuy 2013-08-27 16:11:04 +02:00
parent 4004288bdc
commit ff49f7846d
2 changed files with 11 additions and 7 deletions

View file

@ -124,7 +124,6 @@ namespace Connector_HTTP {
if (Strm.metadata["tracks"].size()){ if (Strm.metadata["tracks"].size()){
for (JSON::ObjIter objIt = Strm.metadata["tracks"].ObjBegin(); objIt != Strm.metadata["tracks"].ObjEnd(); objIt++){ for (JSON::ObjIter objIt = Strm.metadata["tracks"].ObjBegin(); objIt != Strm.metadata["tracks"].ObjEnd(); objIt++){
if ( objIt->second["type"].asStringRef() == "meta" ){ if ( objIt->second["type"].asStringRef() == "meta" ){
std::cout << "selecting track " << objIt->second["trackid"].asInt() << std::endl;
cmd << " " << objIt->second["trackid"].asInt(); cmd << " " << objIt->second["trackid"].asInt();
} }
} }
@ -139,7 +138,6 @@ namespace Connector_HTTP {
cmd << "\ns " << seek_sec << "\np " << maxTime << "\n"; cmd << "\ns " << seek_sec << "\np " << maxTime << "\n";
ss.SendNow(cmd.str().c_str(), cmd.str().size()); ss.SendNow(cmd.str().c_str(), cmd.str().size());
std::cout << "sending command " << cmd.str() << std::endl;
inited = true; inited = true;
} }

View file

@ -41,6 +41,7 @@ namespace Connector_HTTP {
int trackID = -1; // the track to be selected int trackID = -1; // the track to be selected
int curIndex; // SRT index int curIndex; // SRT index
bool subtitleTrack = false; // check whether the requested track is a srt track bool subtitleTrack = false; // check whether the requested track is a srt track
bool isWebVTT = false;
std::stringstream srtdata; // ss output data std::stringstream srtdata; // ss output data
@ -74,6 +75,11 @@ namespace Connector_HTTP {
if ( !HTTP_R.GetVar("trackid").empty()){ if ( !HTTP_R.GetVar("trackid").empty()){
trackID = atoi(HTTP_R.GetVar("trackid").c_str()); trackID = atoi(HTTP_R.GetVar("trackid").c_str());
} }
if ( !HTTP_R.GetVar("webvtt").empty()){
isWebVTT = true;
}else{
isWebVTT = false;
}
//under 3 hours we assume seconds, otherwise byte position //under 3 hours we assume seconds, otherwise byte position
if (start < 10800){ if (start < 10800){
seek_time = start * 1000; //ms, not s seek_time = start * 1000; //ms, not s
@ -94,7 +100,6 @@ namespace Connector_HTTP {
HTTP_S.SetBody("No such stream is available on the system. Please try again.\n"); HTTP_S.SetBody("No such stream is available on the system. Please try again.\n");
conn.SendNow(HTTP_S.BuildResponse("404", "Not found")); conn.SendNow(HTTP_S.BuildResponse("404", "Not found"));
inited = false; inited = false;
//std::cout << "CONTINUE? Y/N J/K" << std::endl;
continue; continue;
} }
@ -110,11 +115,9 @@ namespace Connector_HTTP {
} }
} }
}else{ }else{
std::cout << "TRACKID YO " << trackID << std::endl;
// track *was* given, but we have to check whether it's an actual srt track // track *was* given, but we have to check whether it's an actual srt track
for (JSON::ObjIter objIt = Strm.metadata["tracks"].ObjBegin(); objIt != Strm.metadata["tracks"].ObjEnd(); objIt++){ for (JSON::ObjIter objIt = Strm.metadata["tracks"].ObjBegin(); objIt != Strm.metadata["tracks"].ObjEnd(); objIt++){
if (objIt->second["trackid"].asInt() == trackID){ if (objIt->second["trackid"].asInt() == trackID){
std::cout << " trackID matches with objIt, codec = srt" << std::endl;
subtitleTrack = (objIt->second["codec"].asStringRef() == "srt"); subtitleTrack = (objIt->second["codec"].asStringRef() == "srt");
break; break;
}else{ }else{
@ -163,7 +166,10 @@ namespace Connector_HTTP {
if(Strm.lastType() == DTSC::META){ if(Strm.lastType() == DTSC::META){
srtdata << curIndex++ << std::endl; if(!isWebVTT)
{
srtdata << curIndex++ << std::endl;
}
long long unsigned int time = Strm.getPacket()["time"].asInt(); long long unsigned int time = Strm.getPacket()["time"].asInt();
srtdata << std::setfill('0') << std::setw(2) << (time / 3600000) << ":"; srtdata << std::setfill('0') << std::setw(2) << (time / 3600000) << ":";
srtdata << std::setfill('0') << std::setw(2) << ((time % 3600000) / 60000) << ":"; srtdata << std::setfill('0') << std::setw(2) << ((time % 3600000) / 60000) << ":";
@ -180,7 +186,7 @@ namespace Connector_HTTP {
if( Strm.lastType() == DTSC::PAUSEMARK){ if( Strm.lastType() == DTSC::PAUSEMARK){
HTTP_S.Clean(); //make sure no parts of old requests are left in any buffers HTTP_S.Clean(); //make sure no parts of old requests are left in any buffers
HTTP_S.SetHeader("Content-Type", "text/plain"); //Send the correct content-type for FLV files HTTP_S.SetHeader("Content-Type", "text/plain"); //Send the correct content-type for FLV files
HTTP_S.SetBody(srtdata.str()); HTTP_S.SetBody( (isWebVTT ? "WEBVTT\n\n" : "") + srtdata.str());
conn.SendNow(HTTP_S.BuildResponse("200", "OK")); //no SetBody = unknown length - this is intentional, we will stream the entire file conn.SendNow(HTTP_S.BuildResponse("200", "OK")); //no SetBody = unknown length - this is intentional, we will stream the entire file
inited = false; inited = false;