From 623a30a8b1b6b4664773dcc6aee335798c01e430 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Wed, 6 Mar 2013 11:51:47 +0100 Subject: [PATCH] Egalized output for both ffprobe and AnalyserDTSC output, also, conversion is now working (though without much status checking) --- src/controller/controller.cpp | 29 +++++++++++++++++++++++++++-- src/info.cpp | 30 ++++++++++++------------------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 09c3a877..138d540c 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -102,6 +102,9 @@ namespace Controller { Log("CONF", std::string("New configuration value ") + jit->first); } } + if (out["config"]["basepath"].asString()[out["config"]["basepath"].asString().size() - 1] == '/'){ + out["config"]["basepath"] = out["config"]["basepath"].asString().substr(0, out["config"]["basepath"].asString().size() - 1); + } for (JSON::ObjIter jit = out.ObjBegin(); jit != out.ObjEnd(); jit++){ if (jit->first == "version" || jit->first == "time"){ continue; @@ -215,7 +218,10 @@ int main(int argc, char ** argv){ Controller::Storage["account"][uname]["password"] = Secure::md5(pword); } } - + if ( !Controller::Storage["config"].isMember("basePath")){ + Controller::Storage["config"]["basePath"] = Util::getMyPath(); + } + std::string uplink_addr = conf.getString("uplink"); std::string uplink_host = ""; int uplink_port = 0; @@ -256,6 +262,7 @@ int main(int argc, char ** argv){ Controller::CheckProtocols(Controller::Storage["config"]["protocols"]); Controller::CheckAllStreams(Controller::Storage["streams"]); Controller::CheckStats(Controller::Storage["statistics"]); + myConverter.updateStatus(); } if (uplink_port && Util::epoch() - lastuplink > UPLINK_INTERVAL){ lastuplink = Util::epoch(); @@ -456,9 +463,27 @@ int main(int argc, char ** argv){ Controller::checkCapable(Response["capabilities"]); } if (Request.isMember("conversion")){ - if (Request["conversion"].isMember("encoders")) { + if (Request["conversion"].isMember("encoders")){ Response["conversion"]["encoders"] = myConverter.getEncoders(); } + if (Request["conversion"].isMember("query")){ + if (Request["conversion"]["query"].isMember("path")){ + Response["conversion"]["query"] = myConverter.queryPath(Request["conversion"]["query"]["path"].asString()); + }else{ + Response["conversion"]["query"] = myConverter.queryPath("./"); + } + } + if (Request["conversion"].isMember("convert")){ + for (JSON::ObjIter it = Request["conversion"]["convert"].ObjBegin(); it != Request["conversion"]["convert"].ObjEnd(); it++){ + myConverter.startConversion(it->first,it->second); + } + } + if (Request["conversion"].isMember("status") || Request["conversion"].isMember("convert")){ + Response["conversion"]["status"] = myConverter.getStatus(); + if (Request["conversion"].isMember("clear")){ + myConverter.clearStatus(); + } + } } if (Request.isMember("save")){ Controller::WriteFile(conf.getString("configFile"), Controller::Storage.toString()); diff --git a/src/info.cpp b/src/info.cpp index ee007d22..8c782798 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -18,7 +18,7 @@ namespace Info { JSON::Value fileSpecs = F.getMeta(); if( !fileSpecs ) { char ** cmd = (char**)malloc(3*sizeof(char*)); - cmd[0] = "ffprobe"; + cmd[0] = (char*)"ffprobe"; cmd[1] = argv[1]; cmd[2] = NULL; int outFD = -1; @@ -30,13 +30,12 @@ namespace Info { while ( !(feof(outFile) || ferror(outFile)) && (getline(&fileBuf, &fileBufLen, outFile) != -1)){ std::string line = fileBuf; if (line.find("Input") != std::string::npos){ - std::string tmp = line.substr(line.find("'") + 1); - fileSpecs["fileName"] = tmp.substr(0, tmp.find("'")); + std::string tmp = line.substr(line.find(", ") + 2); + fileSpecs["format"] = tmp.substr(0, tmp.find(",")); } - if (line.find("Duration") != std::string::npos ){ + if (line.find("Duration") != std::string::npos){ std::string tmp = line.substr(line.find(": ", line.find("Duration")) + 2); tmp = tmp.substr(0, tmp.find(",")); - fileSpecs["duration"] = tmp; int length = (((atoi(tmp.substr(0,2).c_str()) * 60) + atoi(tmp.substr(3,2).c_str())) * 60) + atoi(tmp.substr(6,2).c_str()); fileSpecs["length"] = length; length *= 100; @@ -51,16 +50,10 @@ namespace Info { std::string tmp = line.substr(line.find(" ", line.find("Stream")) + 1); int strmIdx = fileSpecs["streams"].size(); int curPos = 0; - fileSpecs["streams"][strmIdx]["name"] = tmp.substr(curPos, tmp.find(": ", curPos) - curPos); curPos = tmp.find(": ", curPos) + 2; - - //curPos = tmp.find("(", curPos) + 1; - //fileSpecs["streams"][strmIdx]["language"] = tmp.substr(curPos, tmp.find(")", curPos) - curPos); - //curPos = tmp.find(")", curPos) + 3; - fileSpecs["streams"][strmIdx]["type"] = tmp.substr(curPos, tmp.find(":", curPos) - curPos); curPos = tmp.find(":", curPos) + 2; - fileSpecs["streams"][strmIdx]["codec"] = tmp.substr(curPos, tmp.find(" ", curPos) - curPos); + fileSpecs["streams"][strmIdx]["codec"] = tmp.substr(curPos, tmp.find_first_of(", ", curPos) - curPos); curPos = tmp.find(",", curPos) + 2; if (fileSpecs["streams"][strmIdx]["type"] == "Video"){ fileSpecs["streams"][strmIdx]["encoding"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos); @@ -72,12 +65,8 @@ namespace Info { fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128; curPos = tmp.find(",", curPos) + 2; fileSpecs["streams"][strmIdx]["fpks"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 1000); - curPos = tmp.find(",", curPos) + 2; - fileSpecs["streams"][strmIdx]["tbr"] = (int)(atof(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) + 0.5); - curPos = tmp.find(",", curPos) + 2; - fileSpecs["streams"][strmIdx]["tbn"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()); - curPos = tmp.find(",", curPos) + 2; - fileSpecs["streams"][strmIdx]["tbc"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()); + fileSpecs["streams"][strmIdx].removeMember( "type" ); + fileSpecs["video"] = fileSpecs["streams"][strmIdx]; }else if (fileSpecs["streams"][strmIdx]["type"] == "Audio"){ fileSpecs["streams"][strmIdx]["samplerate"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()); curPos = tmp.find(",", curPos) + 2; @@ -92,10 +81,15 @@ namespace Info { fileSpecs["streams"][strmIdx]["samplewidth"] = tmp.substr(curPos, tmp.find(",", curPos) - curPos); curPos = tmp.find(",", curPos) + 2; fileSpecs["streams"][strmIdx]["bps"] = atoi(tmp.substr(curPos, tmp.find(" ", curPos) - curPos).c_str()) * 128; + fileSpecs["streams"][strmIdx].removeMember( "type" ); + fileSpecs["audio"] = fileSpecs["streams"][strmIdx]; } } } fclose( outFile ); + fileSpecs.removeMember( "streams" ); + } else { + fileSpecs["format"] = "dtsc"; } if (fileSpecs.isMember("video")){ fileSpecs["video"].removeMember("init");