More fixes to srt and vtt outputs
This commit is contained in:
parent
c78e695bad
commit
56dd4ac98c
1 changed files with 28 additions and 9 deletions
|
@ -11,22 +11,28 @@ namespace Mist {
|
||||||
void OutProgressiveSRT::init(Util::Config * cfg){
|
void OutProgressiveSRT::init(Util::Config * cfg){
|
||||||
HTTPOutput::init(cfg);
|
HTTPOutput::init(cfg);
|
||||||
capa["name"] = "SRT";
|
capa["name"] = "SRT";
|
||||||
capa["desc"] = "Enables HTTP protocol subtitle streaming.";
|
capa["desc"] = "Enables HTTP protocol subtitle streaming in subrip and WebVTT formats.";
|
||||||
capa["url_rel"] = "/$.srt";
|
capa["url_rel"] = "/$.srt";
|
||||||
capa["url_match"] = "/$.srt";
|
capa["url_match"].append("/$.srt");
|
||||||
capa["url_handler"] = "http";
|
capa["url_match"].append("/$.vtt");
|
||||||
capa["url_type"] = "subtitle";
|
|
||||||
capa["codecs"][0u][0u].append("srt");
|
capa["codecs"][0u][0u].append("srt");
|
||||||
capa["codecs"][0u][0u].append("TTXT");
|
capa["codecs"][0u][0u].append("TTXT");
|
||||||
capa["methods"][0u]["handler"] = "http";
|
capa["methods"][0u]["handler"] = "http";
|
||||||
capa["methods"][0u]["type"] = "html5/text/plain";
|
capa["methods"][0u]["type"] = "html5/text/plain";
|
||||||
capa["methods"][0u]["priority"] = 8ll;
|
capa["methods"][0u]["priority"] = 8ll;
|
||||||
|
capa["methods"][1u]["handler"] = "http";
|
||||||
|
capa["methods"][1u]["type"] = "html5/text/vtt";
|
||||||
|
capa["methods"][1u]["priority"] = 9ll;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutProgressiveSRT::sendNext(){
|
void OutProgressiveSRT::sendNext(){
|
||||||
char * dataPointer = 0;
|
char * dataPointer = 0;
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
thisPacket.getString("data", dataPointer, len);
|
thisPacket.getString("data", dataPointer, len);
|
||||||
|
//ignore empty subs
|
||||||
|
if (len == 0 || (len == 1 && dataPointer[0] == ' ')){
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::stringstream tmp;
|
std::stringstream tmp;
|
||||||
if(!webVTT) {
|
if(!webVTT) {
|
||||||
tmp << lastNum++ << std::endl;
|
tmp << lastNum++ << std::endl;
|
||||||
|
@ -38,33 +44,46 @@ namespace Mist {
|
||||||
tmp << " --> ";
|
tmp << " --> ";
|
||||||
time += thisPacket.getInt("duration");
|
time += thisPacket.getInt("duration");
|
||||||
if (time == thisPacket.getTime()){
|
if (time == thisPacket.getTime()){
|
||||||
time += len * 100 + 1000;
|
time += len * 75 + 800;
|
||||||
}
|
}
|
||||||
tmpLen = sprintf(tmpBuf, "%.2llu:%.2llu:%.2llu,%.3llu", (time / 3600000), ((time % 3600000) / 60000), (((time % 3600000) % 60000) / 1000), time % 1000);
|
tmpLen = sprintf(tmpBuf, "%.2llu:%.2llu:%.2llu,%.3llu", (time / 3600000), ((time % 3600000) / 60000), (((time % 3600000) % 60000) / 1000), time % 1000);
|
||||||
tmp.write(tmpBuf, tmpLen);
|
tmp.write(tmpBuf, tmpLen);
|
||||||
tmp << std::endl;
|
tmp << std::endl;
|
||||||
myConn.SendNow(tmp.str());
|
myConn.SendNow(tmp.str());
|
||||||
|
//prevent double newlines
|
||||||
|
if (dataPointer[len-1] == '\n'){--dataPointer;}
|
||||||
myConn.SendNow(dataPointer, len);
|
myConn.SendNow(dataPointer, len);
|
||||||
myConn.SendNow("\n");
|
myConn.SendNow("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutProgressiveSRT::sendHeader(){
|
void OutProgressiveSRT::sendHeader(){
|
||||||
H.SetHeader("Content-Type", "text/plain");
|
if (webVTT){
|
||||||
|
H.SetHeader("Content-Type", "text/vtt; charset=utf-8");
|
||||||
|
}else{
|
||||||
|
H.SetHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
}
|
||||||
H.protocol = "HTTP/1.0";
|
H.protocol = "HTTP/1.0";
|
||||||
H.SendResponse("200", "OK", myConn);
|
H.SendResponse("200", "OK", myConn);
|
||||||
|
if (webVTT){
|
||||||
|
myConn.SendNow("WEBVTT\n\n");
|
||||||
|
}
|
||||||
sentHeader = true;
|
sentHeader = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutProgressiveSRT::onHTTP(){
|
void OutProgressiveSRT::onHTTP(){
|
||||||
std::string method = H.method;
|
std::string method = H.method;
|
||||||
std::string url = H.url;
|
webVTT = (H.url.find(".vtt") != std::string::npos);
|
||||||
if (H.GetVar("track") != ""){
|
if (H.GetVar("track") != ""){
|
||||||
selectedTracks.insert(JSON::Value(H.GetVar("track")).asInt());
|
selectedTracks.insert(JSON::Value(H.GetVar("track")).asInt());
|
||||||
}
|
}
|
||||||
H.Clean();
|
H.Clean();
|
||||||
H.setCORSHeaders();
|
H.setCORSHeaders();
|
||||||
if(method == "OPTIONS" || method == "HEAD"){
|
if(method == "OPTIONS" || method == "HEAD"){
|
||||||
H.SetHeader("Content-Type", "text/plain");
|
if (webVTT){
|
||||||
|
H.SetHeader("Content-Type", "text/vtt; charset=utf-8");
|
||||||
|
}else{
|
||||||
|
H.SetHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
}
|
||||||
H.protocol = "HTTP/1.0";
|
H.protocol = "HTTP/1.0";
|
||||||
H.SendResponse("200", "OK", myConn);
|
H.SendResponse("200", "OK", myConn);
|
||||||
H.Clean();
|
H.Clean();
|
||||||
|
|
Loading…
Add table
Reference in a new issue