Improved track selection logic for JSON output
This commit is contained in:
parent
3eb87bda47
commit
b352b17de8
5 changed files with 35 additions and 43 deletions
|
@ -494,39 +494,33 @@ namespace Mist{
|
|||
unsigned int bestSoFarCount = 0;
|
||||
unsigned int index = 0;
|
||||
jsonForEach(capa["codecs"], it){
|
||||
unsigned int genCounter = 0;
|
||||
unsigned int selCounter = 0;
|
||||
if ((*it).size() > 0){
|
||||
jsonForEach((*it), itb){
|
||||
if ((*itb).size() > 0){
|
||||
bool found = false;
|
||||
jsonForEach(*itb, itc){
|
||||
const std::string & strRef = (*itc).asStringRef();
|
||||
bool byType = false;
|
||||
bool multiSel = false;
|
||||
uint8_t shift = 0;
|
||||
if (strRef[shift] == '@'){byType = true; ++shift;}
|
||||
if (strRef[shift] == '+'){multiSel = true; ++shift;}
|
||||
for (std::set<unsigned long>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
|
||||
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
|
||||
if ((!byType && myMeta.tracks[*itd].codec == strRef.substr(shift)) || (byType && myMeta.tracks[*itd].type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
selCounter++;
|
||||
found = true;
|
||||
if (!multiSel){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
jsonForEach(*itb, itc){
|
||||
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
|
||||
if (trit->second.codec == (*itc).asStringRef() || (*itc).asStringRef() == "*"){
|
||||
genCounter++;
|
||||
found = true;
|
||||
if ((*itc).asStringRef() != "*"){break;}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selCounter == selectedTracks.size()){
|
||||
if (selCounter + genCounter > bestSoFarCount){
|
||||
bestSoFarCount = selCounter + genCounter;
|
||||
if (selCounter > bestSoFarCount){
|
||||
bestSoFarCount = selCounter;
|
||||
bestSoFar = index;
|
||||
HIGH_MSG("Match (%u/%u): %s", selCounter, selCounter + genCounter, (*it).toString().c_str());
|
||||
HIGH_MSG("Matched %u: %s", selCounter, (*it).toString().c_str());
|
||||
}
|
||||
}else{
|
||||
VERYHIGH_MSG("Not a match for currently selected tracks: %s", (*it).toString().c_str());
|
||||
|
@ -541,31 +535,43 @@ namespace Mist{
|
|||
jsonForEach(capa["codecs"][bestSoFar], itb){
|
||||
if ((*itb).size() && myMeta.tracks.size()){
|
||||
bool found = false;
|
||||
bool multiFind = false;
|
||||
jsonForEach((*itb), itc){
|
||||
const std::string & strRef = (*itc).asStringRef();
|
||||
bool byType = false;
|
||||
uint8_t shift = 0;
|
||||
if (strRef[shift] == '@'){byType = true; ++shift;}
|
||||
if (strRef[shift] == '+'){multiFind = true; ++shift;}
|
||||
for (std::set<unsigned long>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
|
||||
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
|
||||
if ((!byType && myMeta.tracks[*itd].codec == strRef.substr(shift)) || (byType && myMeta.tracks[*itd].type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
if (!found || multiFind){
|
||||
jsonForEach((*itb), itc){
|
||||
if (found){break;}
|
||||
const std::string & strRef = (*itc).asStringRef();
|
||||
bool byType = false;
|
||||
bool multiSel = false;
|
||||
uint8_t shift = 0;
|
||||
if (strRef[shift] == '@'){byType = true; ++shift;}
|
||||
if (strRef[shift] == '+'){multiSel = true; ++shift;}
|
||||
if (found && !multiSel){continue;}
|
||||
if (myMeta.live){
|
||||
for (std::map<unsigned int, DTSC::Track>::reverse_iterator trit = myMeta.tracks.rbegin(); trit != myMeta.tracks.rend(); trit++){
|
||||
if (trit->second.codec == (*itc).asStringRef() || (*itc).asStringRef() == "*"){
|
||||
if ((!byType && trit->second.codec == strRef.substr(shift)) || (byType && trit->second.type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
selectedTracks.insert(trit->first);
|
||||
found = true;
|
||||
if ((*itc).asStringRef() != "*"){break;}
|
||||
if (!multiSel){break;}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
|
||||
if (trit->second.codec == (*itc).asStringRef() || (*itc).asStringRef() == "*"){
|
||||
if ((!byType && trit->second.codec == strRef.substr(shift)) || (byType && trit->second.type == strRef.substr(shift)) || strRef.substr(shift) == "*"){
|
||||
selectedTracks.insert(trit->first);
|
||||
found = true;
|
||||
if ((*itc).asStringRef() != "*"){break;}
|
||||
if (!multiSel){break;}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Mist {
|
|||
capa["name"] = "DTSC";
|
||||
capa["desc"] = "Enables the DTSC protocol for efficient inter-server stream exchange.";
|
||||
capa["deps"] = "";
|
||||
capa["codecs"][0u][0u].append("*");
|
||||
capa["codecs"][0u][0u].append("+*");
|
||||
cfg->addConnectorOptions(4200, capa);
|
||||
config = cfg;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,7 @@ namespace Mist {
|
|||
capa["name"] = "JSON";
|
||||
capa["desc"] = "Enables HTTP protocol JSON streaming.";
|
||||
capa["url_match"] = "/$.json";
|
||||
capa["codecs"][0u][0u].append("srt");
|
||||
capa["codecs"][0u][0u].append("TTXT");
|
||||
capa["codecs"][0u][0u].append("@+meta");
|
||||
capa["methods"][0u]["handler"] = "http";
|
||||
capa["methods"][0u]["type"] = "html5/text/javascript";
|
||||
capa["methods"][0u]["priority"] = 0ll;
|
||||
|
@ -74,10 +73,6 @@ namespace Mist {
|
|||
jsonp = "";
|
||||
if (H.GetVar("callback") != ""){jsonp = H.GetVar("callback");}
|
||||
if (H.GetVar("jsonp") != ""){jsonp = H.GetVar("jsonp");}
|
||||
if (H.GetVar("track") != ""){
|
||||
selectedTracks.clear();
|
||||
selectedTracks.insert(JSON::Value(H.GetVar("track")).asInt());
|
||||
}
|
||||
|
||||
if (H.GetHeader("Upgrade") == "websocket"){
|
||||
ws = new HTTP::Websocket(myConn, H);
|
||||
|
@ -101,16 +96,7 @@ namespace Mist {
|
|||
H.Clean();
|
||||
return;
|
||||
}
|
||||
|
||||
first = true;
|
||||
initialize();
|
||||
if (!selectedTracks.size()){
|
||||
for (std::map<unsigned int,DTSC::Track>::iterator it = myMeta.tracks.begin(); it != myMeta.tracks.end(); it++){
|
||||
if (it->second.type == "meta" ){
|
||||
selectedTracks.insert(it->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
parseData = true;
|
||||
wantRequest = false;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Mist {
|
|||
capa["optional"]["seek"]["help"] = "The time in milliseconds to seek to, 0 by default.";
|
||||
capa["optional"]["seek"]["type"] = "int";
|
||||
capa["optional"]["seek"]["option"] = "--seek";
|
||||
capa["codecs"][0u][0u].append("*");
|
||||
capa["codecs"][0u][0u].append("+*");
|
||||
cfg->addOption("streamname",
|
||||
JSON::fromString("{\"arg\":\"string\",\"short\":\"s\",\"long\":\"stream\",\"help\":\"The name of the stream that this connector will transmit.\"}"));
|
||||
cfg->addOption("tracks",
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Mist {
|
|||
Output::init(cfg);
|
||||
capa["name"] = "SanityCheck";
|
||||
capa["desc"] = "Does sanity check on a stream";
|
||||
capa["codecs"][0u][0u].append("*");
|
||||
capa["codecs"][0u][0u].append("+*");
|
||||
cfg->addOption("streamname", JSON::fromString("{\"arg\":\"string\",\"short\":\"s\",\"long\":\"stream\",\"help\":\"The name of the stream that this connector will transmit.\"}"));
|
||||
cfg->addOption("seek", JSON::fromString("{\"arg\":\"string\",\"short\":\"S\",\"long\":\"seek\",\"help\":\"Time in ms to check from - by default start of stream\"}"));
|
||||
cfg->addBasicConnectorOptions(capa);
|
||||
|
|
Loading…
Add table
Reference in a new issue