void PipelineManager::addFiltersToWorkerEvent(Jzon::Node* params, Jzon::Object &outputNode) { int workerId; if(!params) { outputNode.Add("error", "Error adding slaves to worker. Invalid JSON format..."); return; } if (!params->Has("worker")) { outputNode.Add("error", "Error adding filters to worker. Invalid JSON format..."); return; } if (!params->Has("filters") || !params->Get("filters").IsArray()) { outputNode.Add("error", "Error adding filters to worker. Invalid JSON format..."); return; } workerId = params->Get("worker").ToInt(); Jzon::Array& jsonFiltersIds = params->Get("filters").AsArray(); for (Jzon::Array::iterator it = jsonFiltersIds.begin(); it != jsonFiltersIds.end(); ++it) { if (!addFilterToWorker(workerId, (*it).ToInt())) { outputNode.Add("error", "Error adding filters to worker. Invalid internal error..."); return; } } startWorkers(); outputNode.Add("error", Jzon::null); }
//TODO: avoid void functions void Worker::getState(Jzon::Object &workerNode) { Jzon::Array pList; std::map<int, Runnable*> runnables; Runnable* current; { std::lock_guard<std::mutex> guard(mtx); while (!processors.empty()){ current = processors.top(); processors.pop(); runnables[current->getId()] = current; } for (auto it : runnables){ processors.push(it.second); } } for (auto it : runnables) { pList.Add(it.first); } workerNode.Add("type", utils::getWorkerTypeAsString(type)); workerNode.Add("processors", pList); }
void PipelineManager::createFilterEvent(Jzon::Node* params, Jzon::Object &outputNode) { int id; FilterType fType; BaseFilter* filter; if(!params) { outputNode.Add("error", "Error creating filter. Invalid JSON format..."); return; } if (!params->Has("id") || !params->Has("type")) { outputNode.Add("error", "Error creating filter. Invalid JSON format..."); return; } id = params->Get("id").ToInt(); fType = utils::getFilterTypeFromString(params->Get("type").ToString()); filter = createFilter(fType, params); if (!filter) { outputNode.Add("error", "Error creating filter. Specified type is not correct.."); return; } if (!addFilter(id, filter)) { outputNode.Add("error", "Error registering filter. Specified ID already exists.."); return; } outputNode.Add("error", Jzon::null); }
void PipelineManager::stopEvent(Jzon::Node* params, Jzon::Object &outputNode) { if (!stop()) { outputNode.Add("error", "Error stopping pipe. Internal error..."); return; } outputNode.Add("error", Jzon::null); }
std::vector<CCL_MocapJoint> loadMotionCaptureFromSite( int skip) { vector<CCL_MocapJoint> mJoints; try{ //LOAD JSON FILE CONTAINING UUIDs of each stream under specified channel const JsonTree json( loadUrl(URL_STREAM_JSON) ); //LOOP THROUGH STREAMS for( auto &stream : json.getChildren() ){ const string &uuid = stream["uuid"].getValue(); string title = stream["title"].getValue(); if( stream.hasChild("group")){ string group = stream["group"].getValue(); // std::cout << "group:"<< group << " title:" << title << " uuid[" << i << "] = " << uuid << std::endl; addUUIDtoJoint(group, title, uuid, skip, mJoints); } } // create json file Jzon::Object root; root.Add("URL", URL_STREAM_JSON); Jzon::Array joints; for( int i = 0 ; i < mJoints.size() ; i++){ CCL_MocapJoint theJoint = mJoints[i]; Jzon::Object joint; joint.Add("name", theJoint.jointName ); Jzon::Array xPoslist; Jzon::Array yPoslist; Jzon::Array zPoslist; for( int j = 0 ; j < theJoint.jointPositions.size(); j++){ xPoslist.Add(theJoint.jointPositions[j].x); yPoslist.Add(theJoint.jointPositions[j].y); zPoslist.Add(theJoint.jointPositions[j].z); } joint.Add("xPos", xPoslist); joint.Add("yPos", yPoslist); joint.Add("zPos", zPoslist); joints.Add(joint); } root.Add("joints", joints); cout << "Start writing file as CCL_JOINT.json" <<endl; Jzon::FileWriter::WriteFile("CCL_JOINT.json", root, Jzon::StandardFormat); cout << "Ended writing file" <<endl; } catch( ci::Exception &exc ) { std::cout << "Failed to parse json, what: " << exc.what() << std::endl; } return mJoints; };
int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } const char* path=argv[1]; Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path); assert(image.get() != 0); image->readMetadata(); Jzon::Object root; const char* FS="FS"; Jzon::Object fs ; root.Add (FS,fs) ; fileSystemPush(path,root.Get(FS)); Exiv2::ExifData &exifData = image->exifData(); for ( ExifData::const_iterator i = exifData.begin(); i != exifData.end() ; ++i ) { std::string key ; push(objectForKey(i->key(),key,root),key,i); } Exiv2::IptcData &iptcData = image->iptcData(); for (Exiv2::IptcData::const_iterator i = iptcData.begin(); i != iptcData.end(); ++i) { std::string key ; push(objectForKey(i->key(),key,root),key,i); } Exiv2::XmpData &xmpData = image->xmpData(); for (Exiv2::XmpData::const_iterator i = xmpData.begin(); i != xmpData.end(); ++i) { std::string key ; push(objectForKey(i->key(),key,root),key,i); } /* This is only for testing long paths { ExifData::const_iterator i = exifData.begin(); std::string key; push(objectForKey("This.Is.A.Rather.Long.Path.Key",key,root),key,i); } */ Jzon::Writer writer(root,Jzon::StandardFormat); writer.Write(); std::cout << writer.GetResult() << std::endl; return 0; } //catch (std::exception& e) { //catch (Exiv2::AnyError& e) { catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e.what() << "'\n"; return -1; }
void PipelineManager::createPathEvent(Jzon::Node* params, Jzon::Object &outputNode) { std::vector<int> filtersIds; int id, orgFilterId, dstFilterId; int orgWriterId = -1; int dstReaderId = -1; Path* path; if(!params) { outputNode.Add("error", "Error creating path. Invalid JSON format..."); return; } if (!params->Has("id") || !params->Has("orgFilterId") || !params->Has("dstFilterId") || !params->Has("orgWriterId") || !params->Has("dstReaderId")) { outputNode.Add("error", "Error creating path. Invalid JSON format..."); return; } id = params->Get("id").ToInt(); orgFilterId = params->Get("orgFilterId").ToInt(); dstFilterId = params->Get("dstFilterId").ToInt(); orgWriterId = params->Get("orgWriterId").ToInt(); dstReaderId = params->Get("dstReaderId").ToInt(); if (!params->Has("midFiltersIds") || !params->Get("midFiltersIds").IsArray()){ outputNode.Add("error", "Invalid midfilters array"); return; } Jzon::Array& jsonFiltersIds = params->Get("midFiltersIds").AsArray(); for (Jzon::Array::iterator it = jsonFiltersIds.begin(); it != jsonFiltersIds.end(); ++it) { filtersIds.push_back((*it).ToInt()); } path = createPath(orgFilterId, dstFilterId, orgWriterId, dstReaderId, filtersIds); if (!path) { outputNode.Add("error", "Error creating path. Check introduced filter IDs..."); return; } if (!connectPath(path)) { outputNode.Add("error", "Error connecting path. Better pray Jesus..."); return; } if (!addPath(id, path)) { outputNode.Add("error", "Error registering path. Path ID already exists..."); return; } outputNode.Add("error", Jzon::null); }
void push(Jzon::Object& json,const std::string& key,T i) { std::string value = i->value().toString(); switch ( i->typeId() ) { case Exiv2::xmpText: case Exiv2::asciiString : case Exiv2::string: case Exiv2::comment: json.Add(key,value); break; case Exiv2::unsignedByte: case Exiv2::unsignedShort: case Exiv2::unsignedLong: case Exiv2::signedByte: case Exiv2::signedShort: case Exiv2::signedLong: json.Add(key,(int)i->value().toLong()); break; case Exiv2::tiffFloat: case Exiv2::tiffDouble: json.Add(key,i->value().toFloat()); break; case Exiv2::unsignedRational: case Exiv2::signedRational: { Jzon::Array arr; Rational rat = i->value().toRational(); arr.Add (rat.first ); arr.Add (rat.second); json.Add(key,arr); } break; case Exiv2::date: case Exiv2::time: json.Add(key,i->value().toString()); break; default: case Exiv2::undefined: case Exiv2::tiffIfd: case Exiv2::directory: case Exiv2::xmpAlt: case Exiv2::xmpBag: case Exiv2::xmpSeq: case Exiv2::langAlt: // http://dev.exiv2.org/boards/3/topics/1367#message-1373 if ( key == "UserComment" ) { size_t pos = value.find('\0') ; if ( pos != string::npos ) value = value.substr(0,pos); } if ( key != "MakerNote") json.Add(key,value); break; } }
void PipelineManager::removeWorkerEvent(Jzon::Node* params, Jzon::Object &outputNode) { int id; if(!params) { outputNode.Add("error", "Error removing worker. Invalid JSON format..."); return; } if (!params->Has("id")) { outputNode.Add("error", "Error removing worker. Invalid JSON format..."); return; } id = params->Get("id").ToInt(); if (!removeWorker(id)) { outputNode.Add("error", "Error removing worker. Internal error..."); return; } outputNode.Add("error", Jzon::null); }
void PipelineManager::addWorkerEvent(Jzon::Node* params, Jzon::Object &outputNode) { int id; std::string type; Worker* worker = NULL; if(!params) { outputNode.Add("error", "Error creating worker. Invalid JSON format..."); return; } if (!params->Has("id") || !params->Has("type")) { outputNode.Add("error", "Error creating worker. Invalid JSON format..."); return; } id = params->Get("id").ToInt(); type = params->Get("type").ToString(); if (type.compare("livemedia") == 0){ worker = new LiveMediaWorker(); } else { worker = new Worker(); } if (!worker) { outputNode.Add("error", "Error creating worker. Check type..."); return; } if (!addWorker(id, worker)) { outputNode.Add("error", "Error adding worker to filter. Check filter ID..."); return; } outputNode.Add("error", Jzon::null); }
void VideoEncoderX264or5::doGetState(Jzon::Object &filterNode) { filterNode.Add("bitrate", std::to_string(bitrate)); filterNode.Add("fps", std::to_string(fps)); filterNode.Add("gop", std::to_string(gop)); filterNode.Add("lookahead", std::to_string(lookahead)); filterNode.Add("threads", std::to_string(threads)); filterNode.Add("annexb", std::to_string(annexB)); filterNode.Add("preset", preset); }
void PipelineManager::addSlavesToFilterEvent(Jzon::Node* params, Jzon::Object &outputNode) { BaseFilter *slave, *master; int masterId; if(!params) { outputNode.Add("error", "Error adding slaves to worker. Invalid JSON format..."); return; } if (!params->Has("master")) { outputNode.Add("error", "Error adding slaves to filter. Invalid JSON format..."); return; } if (!params->Has("slaves") || !params->Get("slaves").IsArray()) { outputNode.Add("error", "Error adding slaves to filter. Invalid JSON format..."); return; } masterId = params->Get("master").ToInt(); Jzon::Array& jsonSlavesIds = params->Get("slaves").AsArray(); master = getFilter(masterId); if (!master) { outputNode.Add("error", "Error adding slaves to filter. Invalid Master ID..."); return; } for (Jzon::Array::iterator it = jsonSlavesIds.begin(); it != jsonSlavesIds.end(); ++it) { if ((slave = getFilter((*it).ToInt())) && slave->getRole() == SLAVE){ if (!master->addSlave((*it).ToInt(), slave)){ outputNode.Add("error", "Error, either master or slave do not have the appropriate role!"); } } else { outputNode.Add("error", "Error adding slaves to filter. Invalid Slave..."); } } outputNode.Add("error", Jzon::null); }
void PipelineManager::getStateEvent(Jzon::Node* params, Jzon::Object &outputNode) { Jzon::Array filterList; Jzon::Array pathList; Jzon::Array workersList; for (auto it : filters) { Jzon::Object filter; filter.Add("id", it.first); it.second->getState(filter); filterList.Add(filter); } outputNode.Add("filters", filterList); for (auto it : paths) { Jzon::Object path; Jzon::Array pathFilters; std::vector<int> pFilters = it.second->getFilters(); path.Add("id", it.first); path.Add("originFilter", it.second->getOriginFilterID()); path.Add("destinationFilter", it.second->getDestinationFilterID()); path.Add("originWriter", it.second->getOrgWriterID()); path.Add("destinationReader", it.second->getDstReaderID()); for (auto it : pFilters) { pathFilters.Add(it); } path.Add("filters", pathFilters); pathList.Add(path); } outputNode.Add("paths", pathList); for (auto it : workers) { Jzon::Object worker; worker.Add("id", it.first); it.second->getState(worker); workersList.Add(worker); } outputNode.Add("workers", workersList); }
void VideoMixer::doGetState(Jzon::Object &filterNode) { Jzon::Array jsonChannelConfigs; filterNode.Add("width", outputWidth); filterNode.Add("height", outputHeight); filterNode.Add("maxChannels", maxChannels); for (auto it : channelsConfig) { Jzon::Object chConfig; chConfig.Add("id", it.first); chConfig.Add("width", it.second->getWidth()); chConfig.Add("height", it.second->getHeight()); chConfig.Add("x", it.second->getX()); chConfig.Add("y", it.second->getY()); chConfig.Add("layer", it.second->getLayer()); chConfig.Add("enabled", it.second->isEnabled()); chConfig.Add("opacity", it.second->getOpacity()); jsonChannelConfigs.Add(chConfig); } filterNode.Add("channels", jsonChannelConfigs); }