Improved track selection logic for JSON output
This commit is contained in:
parent
e442bde5a6
commit
1451b64e00
3 changed files with 33 additions and 41 deletions
|
@ -277,28 +277,22 @@ namespace Mist{
|
||||||
unsigned int bestSoFarCount = 0;
|
unsigned int bestSoFarCount = 0;
|
||||||
unsigned int index = 0;
|
unsigned int index = 0;
|
||||||
jsonForEach(capa["codecs"], it){
|
jsonForEach(capa["codecs"], it){
|
||||||
unsigned int genCounter = 0;
|
|
||||||
unsigned int selCounter = 0;
|
unsigned int selCounter = 0;
|
||||||
if ((*it).size() > 0){
|
if ((*it).size() > 0){
|
||||||
jsonForEach((*it), itb){
|
jsonForEach((*it), itb){
|
||||||
if ((*itb).size() > 0){
|
if ((*itb).size() > 0){
|
||||||
bool found = false;
|
|
||||||
jsonForEach(*itb, itc){
|
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++){
|
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++;
|
selCounter++;
|
||||||
found = true;
|
if (!multiSel){
|
||||||
break;
|
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;}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,10 +300,10 @@ namespace Mist{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selCounter == selectedTracks.size()){
|
if (selCounter == selectedTracks.size()){
|
||||||
if (selCounter + genCounter > bestSoFarCount){
|
if (selCounter > bestSoFarCount){
|
||||||
bestSoFarCount = selCounter + genCounter;
|
bestSoFarCount = selCounter;
|
||||||
bestSoFar = index;
|
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{
|
}else{
|
||||||
VERYHIGH_MSG("Not a match for currently selected tracks: %s", (*it).toString().c_str());
|
VERYHIGH_MSG("Not a match for currently selected tracks: %s", (*it).toString().c_str());
|
||||||
|
@ -324,31 +318,43 @@ namespace Mist{
|
||||||
jsonForEach(capa["codecs"][bestSoFar], itb){
|
jsonForEach(capa["codecs"][bestSoFar], itb){
|
||||||
if ((*itb).size() && myMeta.tracks.size()){
|
if ((*itb).size() && myMeta.tracks.size()){
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
bool multiFind = false;
|
||||||
jsonForEach((*itb), itc){
|
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++){
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found){
|
if (!found || multiFind){
|
||||||
jsonForEach((*itb), itc){
|
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){
|
if (myMeta.live){
|
||||||
for (std::map<unsigned int, DTSC::Track>::reverse_iterator trit = myMeta.tracks.rbegin(); trit != myMeta.tracks.rend(); trit++){
|
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);
|
selectedTracks.insert(trit->first);
|
||||||
found = true;
|
found = true;
|
||||||
if ((*itc).asStringRef() != "*"){break;}
|
if (!multiSel){break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
|
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);
|
selectedTracks.insert(trit->first);
|
||||||
found = true;
|
found = true;
|
||||||
if ((*itc).asStringRef() != "*"){break;}
|
if (!multiSel){break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@ namespace Mist {
|
||||||
capa["name"] = "JSON";
|
capa["name"] = "JSON";
|
||||||
capa["desc"] = "Enables HTTP protocol JSON streaming.";
|
capa["desc"] = "Enables HTTP protocol JSON streaming.";
|
||||||
capa["url_match"] = "/$.json";
|
capa["url_match"] = "/$.json";
|
||||||
capa["codecs"][0u][0u].append("srt");
|
capa["codecs"][0u][0u].append("@+meta");
|
||||||
capa["codecs"][0u][0u].append("TTXT");
|
|
||||||
capa["methods"][0u]["handler"] = "http";
|
capa["methods"][0u]["handler"] = "http";
|
||||||
capa["methods"][0u]["type"] = "html5/text/javascript";
|
capa["methods"][0u]["type"] = "html5/text/javascript";
|
||||||
capa["methods"][0u]["priority"] = 0ll;
|
capa["methods"][0u]["priority"] = 0ll;
|
||||||
|
@ -74,10 +73,6 @@ namespace Mist {
|
||||||
jsonp = "";
|
jsonp = "";
|
||||||
if (H.GetVar("callback") != ""){jsonp = H.GetVar("callback");}
|
if (H.GetVar("callback") != ""){jsonp = H.GetVar("callback");}
|
||||||
if (H.GetVar("jsonp") != ""){jsonp = H.GetVar("jsonp");}
|
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"){
|
if (H.GetHeader("Upgrade") == "websocket"){
|
||||||
ws = new HTTP::Websocket(myConn, H);
|
ws = new HTTP::Websocket(myConn, H);
|
||||||
|
@ -101,16 +96,7 @@ namespace Mist {
|
||||||
H.Clean();
|
H.Clean();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
first = true;
|
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;
|
parseData = true;
|
||||||
wantRequest = false;
|
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"]["help"] = "The time in milliseconds to seek to, 0 by default.";
|
||||||
capa["optional"]["seek"]["type"] = "int";
|
capa["optional"]["seek"]["type"] = "int";
|
||||||
capa["optional"]["seek"]["option"] = "--seek";
|
capa["optional"]["seek"]["option"] = "--seek";
|
||||||
capa["codecs"][0u][0u].append("*");
|
capa["codecs"][0u][0u].append("+*");
|
||||||
cfg->addOption("streamname",
|
cfg->addOption("streamname",
|
||||||
JSON::fromString("{\"arg\":\"string\",\"short\":\"s\",\"long\":\"stream\",\"help\":\"The name of the stream that this connector will transmit.\"}"));
|
JSON::fromString("{\"arg\":\"string\",\"short\":\"s\",\"long\":\"stream\",\"help\":\"The name of the stream that this connector will transmit.\"}"));
|
||||||
cfg->addOption("tracks",
|
cfg->addOption("tracks",
|
||||||
|
|
Loading…
Add table
Reference in a new issue